Przeglądaj źródła

troops selection: add remove troop button

Bastien Sevajol 6 lat temu
rodzic
commit
e17d0b4f22
1 zmienionych plików z 31 dodań i 0 usunięć
  1. 31 0
      opencombat/strategy/selection/gui.py

+ 31 - 0
opencombat/strategy/selection/gui.py Wyświetl plik

@@ -54,6 +54,14 @@ class SelectTroopsGui(Gui):
54 54
         )
55 55
         self._add_troop_var.set('Add troop')
56 56
 
57
+        self._remove_troop_var = StringVar(self._master)
58
+        self._remove_troop_button = Button(
59
+            self._master,
60
+            textvariable=self._remove_troop_var,
61
+            command=self._remove_troop,
62
+        )
63
+        self._remove_troop_var.set('Remove troop')
64
+
57 65
         self._troops_view = Treeview(
58 66
             self._master,
59 67
             columns=('Soldiers',),
@@ -69,6 +77,7 @@ class SelectTroopsGui(Gui):
69 77
         self._teams_list.grid(row=1, column=0, sticky=W)
70 78
         self._add_troop_button.grid(row=2, column=0, sticky=W)
71 79
         self._troops_view.grid(row=3, column=0, sticky=W)
80
+        self._remove_troop_button.grid(row=4, column=0, sticky=W)
72 81
 
73 82
         # Default behaviours
74 83
         self._selected_country_var.set(countries[0])
@@ -111,6 +120,28 @@ class SelectTroopsGui(Gui):
111 120
             )
112 121
             self._update_troops_view(country)
113 122
 
123
+    def _remove_troop(self, *args, **kwargs) -> None:
124
+        selecteds = self._troops_view.selection()
125
+
126
+        for selected in selecteds:
127
+            team_name = self._troops_view.item(selected)['text']
128
+            country = self._selected_country_var.get()
129
+
130
+            self._logger.info('Remove team "{}" from country "{}"'.format(
131
+                team_name,
132
+                country,
133
+            ))
134
+
135
+            team_model = self._team_stash.get_team_by_name(
136
+                team_name=team_name,
137
+                team_country=country,
138
+            )
139
+
140
+            self._countries_troops[country].remove(team_model)
141
+
142
+        if selecteds:
143
+            self._update_troops_view(country)
144
+
114 145
     def _update_troops_view(self, country: str) -> None:
115 146
         teams = self._countries_troops.get(country, [])
116 147