Browse Source

add option menu to select troops gui

Bastien Sevajol 5 years ago
parent
commit
bb7c0ae6c0

+ 3 - 1
README.md View File

@@ -31,7 +31,9 @@ You also need a running redis server (used db number is `0`, soon configurable).
31 31
 
32 32
 ## Troops selection
33 33
 
34
-Not developed yet
34
+Start troops selection GUI with:
35
+
36
+    python select_troops.py --country URSS --country DE
35 37
 
36 38
 ## Troops Placement phase
37 39
 

+ 5 - 2
opencombat/strategy/manager.py View File

@@ -2,7 +2,7 @@
2 2
 from synergine2.config import Config
3 3
 from synergine2.log import get_logger
4 4
 
5
-from opencombat.strategy.selection.troops import TroopClassBuilder
5
+from opencombat.strategy.troops import TroopClassBuilder
6 6
 
7 7
 
8 8
 class TroopManager(object):
@@ -17,4 +17,7 @@ class TroopManager(object):
17 17
 
18 18
         builder = TroopClassBuilder(config)
19 19
         self._unit_stash = builder.get_unit_stash(units_file_path)
20
-        self._team_stash = builder.get_team_stash(teams_file_path)
20
+        self._team_stash = builder.get_team_stash(
21
+            units_file_path,
22
+            teams_file_path,
23
+        )

+ 20 - 3
opencombat/strategy/selection/gui.py View File

@@ -1,6 +1,8 @@
1 1
 # coding: utf-8
2
+import typing
2 3
 from tkinter import Tk
3
-from tkinter import Label
4
+from tkinter import StringVar
5
+from tkinter import OptionMenu
4 6
 from tkinter import W
5 7
 
6 8
 from synergine2.config import Config
@@ -15,10 +17,25 @@ class SelectTroopsGui(Gui):
15 17
         config: Config,
16 18
         master: Tk,
17 19
         troop_manager: TroopManager,
20
+        countries: typing.List[str],
18 21
     ) -> None:
19 22
         super().__init__(config, master)
20 23
         self._master.title('Troops selection')
21
-        self.label = Label(master, text="Hello")
24
+
25
+        # Widgets
26
+        self.selected_country_var = StringVar(self._master)
27
+        self.selected_country_var.set(countries[0])
28
+        self.selected_country_var.trace('w', self.change_country)
29
+        self.select_country_menu = OptionMenu(
30
+            self._master,
31
+            self.selected_country_var,
32
+            *countries,
33
+        )
22 34
 
23 35
         # Layout
24
-        self.label.grid(row=0, column=0, sticky=W)
36
+        self.select_country_menu.grid(row=0, column=0, sticky=W)
37
+
38
+    def change_country(self, *args, **kwargs) -> None:
39
+        self._logger.info('Change country to "{}"'.format(
40
+            self.selected_country_var.get(),
41
+        ))

+ 4 - 0
opencombat/strategy/troops.py View File

@@ -33,6 +33,7 @@ class TroopClassBuilder(object):
33 33
 
34 34
     def get_team_stash(
35 35
         self,
36
+        units_file_path: str,
36 37
         teams_file_path: str,
37 38
     ) -> UnitStash:
38 39
         class_address = self._config.resolve(
@@ -43,7 +44,10 @@ class TroopClassBuilder(object):
43 44
             self._config,
44 45
             class_address,
45 46
         )
47
+
48
+        unit_stash = self.get_unit_stash(units_file_path)
46 49
         return class_(
47 50
             self._config,
48 51
             teams_file_path,
52
+            unit_stash=unit_stash,
49 53
         )

+ 1 - 1
select_troops.py View File

@@ -28,6 +28,7 @@ def main(
28 28
         config,
29 29
         master=master,
30 30
         troop_manager=troop_manager,
31
+        countries=countries,
31 32
     )
32 33
     master.mainloop()
33 34
 
@@ -50,7 +51,6 @@ if __name__ == '__main__':
50 51
         '--country',
51 52
         action='append',
52 53
         dest='countries',
53
-        default=['URSS', 'DE'],
54 54
     )
55 55
     args = parser.parse_args()
56 56