|
@@ -1,4 +1,5 @@
|
1
|
1
|
# coding: utf-8
|
|
2
|
+import os
|
2
|
3
|
import typing
|
3
|
4
|
from tkinter import Tk
|
4
|
5
|
from tkinter import Button
|
|
@@ -6,12 +7,17 @@ from tkinter import YES
|
6
|
7
|
from tkinter import StringVar
|
7
|
8
|
from tkinter import OptionMenu
|
8
|
9
|
from tkinter import W
|
|
10
|
+from tkinter import E
|
|
11
|
+from tkinter import messagebox
|
9
|
12
|
from tkinter.ttk import Combobox
|
10
|
13
|
from tkinter.ttk import Treeview
|
11
|
14
|
|
|
15
|
+
|
|
16
|
+import time
|
12
|
17
|
from synergine2.config import Config
|
13
|
18
|
|
14
|
19
|
from opencombat.gui import Gui
|
|
20
|
+from opencombat.strategy.manager import TroopManager
|
15
|
21
|
from opencombat.strategy.team.stash import TeamStash
|
16
|
22
|
|
17
|
23
|
|
|
@@ -21,11 +27,16 @@ class SelectTroopsGui(Gui):
|
21
|
27
|
config: Config,
|
22
|
28
|
master: Tk,
|
23
|
29
|
team_stash: TeamStash,
|
|
30
|
+ troop_manager: TroopManager,
|
24
|
31
|
countries: typing.List[str],
|
|
32
|
+ troops_dir_path: str = '.',
|
25
|
33
|
) -> None:
|
26
|
34
|
super().__init__(config, master)
|
27
|
35
|
self._master.title('Troops selection')
|
|
36
|
+ self._countries = countries
|
28
|
37
|
self._team_stash = team_stash
|
|
38
|
+ self._troop_manager = troop_manager
|
|
39
|
+ self._troops_dir_path = troops_dir_path
|
29
|
40
|
self._countries_troops = {} # type: typing.Dict[str, typing.List[TeamModel]] # nopep8
|
30
|
41
|
|
31
|
42
|
# Widgets
|
|
@@ -72,12 +83,21 @@ class SelectTroopsGui(Gui):
|
72
|
83
|
self._troops_view.column('#0', stretch=YES)
|
73
|
84
|
self._troops_view.column('#1', stretch=YES)
|
74
|
85
|
|
|
86
|
+ self._generate_troops_var = StringVar(self._master)
|
|
87
|
+ self._generate_troops_button = Button(
|
|
88
|
+ self._master,
|
|
89
|
+ textvariable=self._generate_troops_var,
|
|
90
|
+ command=self._generate_troops,
|
|
91
|
+ )
|
|
92
|
+ self._generate_troops_var.set('Generate troops')
|
|
93
|
+
|
75
|
94
|
# Layout
|
76
|
95
|
self._select_country_menu.grid(row=0, column=0, sticky=W)
|
77
|
96
|
self._teams_list.grid(row=1, column=0, sticky=W)
|
78
|
97
|
self._add_troop_button.grid(row=2, column=0, sticky=W)
|
79
|
98
|
self._troops_view.grid(row=3, column=0, sticky=W)
|
80
|
99
|
self._remove_troop_button.grid(row=4, column=0, sticky=W)
|
|
100
|
+ self._generate_troops_button.grid(row=4, column=0, sticky=E)
|
81
|
101
|
|
82
|
102
|
# Default behaviours
|
83
|
103
|
self._selected_country_var.set(countries[0])
|
|
@@ -153,3 +173,28 @@ class SelectTroopsGui(Gui):
|
153
|
173
|
text=team.name,
|
154
|
174
|
values=('o' * len(team.units,))
|
155
|
175
|
)
|
|
176
|
+
|
|
177
|
+ def _generate_troops(self, *args, **kwargs) -> None:
|
|
178
|
+ # Must have team(s) in all countries
|
|
179
|
+ if len(self._countries_troops.keys()) == len(self._countries) \
|
|
180
|
+ and all(self._countries_troops.values()):
|
|
181
|
+
|
|
182
|
+ troops_file_path = os.path.join(
|
|
183
|
+ self._troops_dir_path,
|
|
184
|
+ 'troops_{}.xml'.format(str(time.time())),
|
|
185
|
+ )
|
|
186
|
+
|
|
187
|
+ self._logger.info('Generate troops into file "{}"'.format(
|
|
188
|
+ troops_file_path,
|
|
189
|
+ ))
|
|
190
|
+
|
|
191
|
+ troops_xml = self._troop_manager.get_troop_dump(
|
|
192
|
+ self._countries_troops,
|
|
193
|
+ )
|
|
194
|
+ with open(troops_file_path, 'w+') as file:
|
|
195
|
+ file.write(troops_xml)
|
|
196
|
+ else:
|
|
197
|
+ messagebox.showinfo(
|
|
198
|
+ 'Missing information',
|
|
199
|
+ 'All countries must have teams',
|
|
200
|
+ )
|