Browse Source

add option menu to select troops gui

Bastien Sevajol 6 years ago
parent
commit
bb7c0ae6c0

+ 3 - 1
README.md View File

31
 
31
 
32
 ## Troops selection
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
 ## Troops Placement phase
38
 ## Troops Placement phase
37
 
39
 

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

2
 from synergine2.config import Config
2
 from synergine2.config import Config
3
 from synergine2.log import get_logger
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
 class TroopManager(object):
8
 class TroopManager(object):
17
 
17
 
18
         builder = TroopClassBuilder(config)
18
         builder = TroopClassBuilder(config)
19
         self._unit_stash = builder.get_unit_stash(units_file_path)
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
 # coding: utf-8
1
 # coding: utf-8
2
+import typing
2
 from tkinter import Tk
3
 from tkinter import Tk
3
-from tkinter import Label
4
+from tkinter import StringVar
5
+from tkinter import OptionMenu
4
 from tkinter import W
6
 from tkinter import W
5
 
7
 
6
 from synergine2.config import Config
8
 from synergine2.config import Config
15
         config: Config,
17
         config: Config,
16
         master: Tk,
18
         master: Tk,
17
         troop_manager: TroopManager,
19
         troop_manager: TroopManager,
20
+        countries: typing.List[str],
18
     ) -> None:
21
     ) -> None:
19
         super().__init__(config, master)
22
         super().__init__(config, master)
20
         self._master.title('Troops selection')
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
         # Layout
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
 
33
 
34
     def get_team_stash(
34
     def get_team_stash(
35
         self,
35
         self,
36
+        units_file_path: str,
36
         teams_file_path: str,
37
         teams_file_path: str,
37
     ) -> UnitStash:
38
     ) -> UnitStash:
38
         class_address = self._config.resolve(
39
         class_address = self._config.resolve(
43
             self._config,
44
             self._config,
44
             class_address,
45
             class_address,
45
         )
46
         )
47
+
48
+        unit_stash = self.get_unit_stash(units_file_path)
46
         return class_(
49
         return class_(
47
             self._config,
50
             self._config,
48
             teams_file_path,
51
             teams_file_path,
52
+            unit_stash=unit_stash,
49
         )
53
         )

+ 1 - 1
select_troops.py View File

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