Merge lp:~widelands-dev/widelands/economy-target-profiles into lp:widelands
- economy-target-profiles
- Merge into trunk
Status: | Superseded | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Proposed branch: | lp:~widelands-dev/widelands/economy-target-profiles | ||||||||||||||||
Merge into: | lp:widelands | ||||||||||||||||
Diff against target: |
1603 lines (+937/-169) 17 files modified
data/tribes/economy_profiles/atlanteans (+89/-0) data/tribes/economy_profiles/barbarians (+81/-0) data/tribes/economy_profiles/empire (+89/-0) data/tribes/economy_profiles/frisians (+93/-0) src/logic/filesystem_constants.h (+2/-0) src/logic/map_objects/tribes/tribe_descr.cc (+0/-40) src/logic/map_objects/tribes/tribe_descr.h (+0/-11) src/logic/map_objects/tribes/tribes.cc (+1/-6) src/logic/map_objects/tribes/ware_descr.h (+2/-4) src/logic/playercommand.h (+2/-0) src/wui/CMakeLists.txt (+2/-0) src/wui/economy_options_window.cc (+382/-52) src/wui/economy_options_window.h (+38/-1) src/wui/inputqueuedisplay.cc (+6/-6) src/wui/inputqueuedisplay.h (+1/-1) src/wui/waresdisplay.cc (+121/-46) src/wui/waresdisplay.h (+28/-2) |
||||||||||||||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/economy-target-profiles | ||||||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Widelands Developers | Pending | ||
Review via email: mp+366952@code.launchpad.net |
This proposal has been superseded by a proposal from 2019-05-06.
Commit message
Users can define and save their own profiles of economy target quantities. Redesigned the economy options menu.
Description of the change
For each tribe, I added two profiles: "Efficiency" is equal to the changes proposed previously, and "Stockpile" is for people who, well, like to stockpile stuff. Additionally there is an unchangeable "Default" profile that resets stuff to the default settings.
To apply a profile, select the profile and the wares you wish to change and click Apply (replaces Reset). Use "Save" to save your current settings as a profile. The save window also allows you to delete profiles.
bunnybot (widelandsofficial) wrote : | # |
GunChleoc (gunchleoc) wrote : | # |
2 Comments. Will do some testing.
Benedikt Straub (nordfriese) wrote : | # |
Addressed the reviews: The panels now set hgaps to fill the entire available space, and the profiles are stored in tribes/
GunChleoc (gunchleoc) wrote : | # |
New code LGTM.
I am wondering whether we want to save this as Lua tables? I already have the code finished in the spritesheets branch and could pull it out into a separate branch, since spritesheets aren't ready yet.
Benedikt Straub (nordfriese) wrote : | # |
Is there a reason why you prefer LuaTables over profile? Personally I find Profile much easier to use for configs that the user has no reason to manually edit.
Regarding the suggestion in the bug report – A spinbox would make sense, but what value should it display when several wares with different settings are selected?
GunChleoc (gunchleoc) wrote : | # |
All the tribe's configuration is in LuaTables, so I guess mainly for consistency - I don't feel strongly about this though.
Good point about the value in the spinbox - I still think we should have the possibility of having steps of 10 though. Maybe fake it with 4 buttons and make them look like the spinbox buttons?
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4901. State: failed. Details: https:/
Appveyor build 4682. State: failed. Details: https:/
Preview Diff
1 | === added file 'data/images/ui_basic/scrollbar_down_fast.png' | |||
2 | 0 | Binary files data/images/ui_basic/scrollbar_down_fast.png 1970-01-01 00:00:00 +0000 and data/images/ui_basic/scrollbar_down_fast.png 2019-05-06 13:51:46 +0000 differ | 0 | Binary files data/images/ui_basic/scrollbar_down_fast.png 1970-01-01 00:00:00 +0000 and data/images/ui_basic/scrollbar_down_fast.png 2019-05-06 13:51:46 +0000 differ |
3 | === added file 'data/images/ui_basic/scrollbar_up_fast.png' | |||
4 | 1 | Binary files data/images/ui_basic/scrollbar_up_fast.png 1970-01-01 00:00:00 +0000 and data/images/ui_basic/scrollbar_up_fast.png 2019-05-06 13:51:46 +0000 differ | 1 | Binary files data/images/ui_basic/scrollbar_up_fast.png 1970-01-01 00:00:00 +0000 and data/images/ui_basic/scrollbar_up_fast.png 2019-05-06 13:51:46 +0000 differ |
5 | === added directory 'data/tribes/economy_profiles' | |||
6 | === added file 'data/tribes/economy_profiles/atlanteans' | |||
7 | --- data/tribes/economy_profiles/atlanteans 1970-01-01 00:00:00 +0000 | |||
8 | +++ data/tribes/economy_profiles/atlanteans 2019-05-06 13:51:46 +0000 | |||
9 | @@ -0,0 +1,89 @@ | |||
10 | 1 | # Automatically created by Widelands bzr9094[economy-target-profiles] (Debug) | ||
11 | 2 | |||
12 | 3 | [Default] | ||
13 | 4 | 0=_"Efficiency" | ||
14 | 5 | 1=_"Stockpile" | ||
15 | 6 | |||
16 | 7 | [0] | ||
17 | 8 | blackroot_flour="1" | ||
18 | 9 | atlanteans_bread="20" | ||
19 | 10 | bread_paddle="0" | ||
20 | 11 | buckets="0" | ||
21 | 12 | coal="5" | ||
22 | 13 | cornmeal="3" | ||
23 | 14 | diamond="3" | ||
24 | 15 | fire_tongs="1" | ||
25 | 16 | fishing_net="2" | ||
26 | 17 | gold="1" | ||
27 | 18 | gold_ore="1" | ||
28 | 19 | gold_thread="0" | ||
29 | 20 | granite="10" | ||
30 | 21 | hammer="0" | ||
31 | 22 | hook_pole="0" | ||
32 | 23 | hunting_bow="1" | ||
33 | 24 | iron="5" | ||
34 | 25 | iron_ore="1" | ||
35 | 26 | milking_tongs="0" | ||
36 | 27 | pick="1" | ||
37 | 28 | planks="1" | ||
38 | 29 | quartz="3" | ||
39 | 30 | saw="0" | ||
40 | 31 | scythe="0" | ||
41 | 32 | shield_advanced="0" | ||
42 | 33 | shield_steel="0" | ||
43 | 34 | shovel="0" | ||
44 | 35 | smoked_fish="5" | ||
45 | 36 | smoked_meat="3" | ||
46 | 37 | spidercloth="5" | ||
47 | 38 | spider_silk="5" | ||
48 | 39 | tabard="1" | ||
49 | 40 | tabard_golden="0" | ||
50 | 41 | trident_double="0" | ||
51 | 42 | trident_heavy_double="0" | ||
52 | 43 | trident_light="1" | ||
53 | 44 | trident_long="0" | ||
54 | 45 | trident_steel="0" | ||
55 | 46 | atlanteans_horse="1" | ||
56 | 47 | atlanteans_soldier="10" | ||
57 | 48 | |||
58 | 49 | [1] | ||
59 | 50 | blackroot_flour="20" | ||
60 | 51 | atlanteans_bread="30" | ||
61 | 52 | bread_paddle="1" | ||
62 | 53 | buckets="2" | ||
63 | 54 | coal="25" | ||
64 | 55 | cornmeal="20" | ||
65 | 56 | diamond="10" | ||
66 | 57 | fire_tongs="1" | ||
67 | 58 | fishing_net="2" | ||
68 | 59 | gold="20" | ||
69 | 60 | gold_ore="15" | ||
70 | 61 | gold_thread="5" | ||
71 | 62 | granite="30" | ||
72 | 63 | hammer="2" | ||
73 | 64 | hook_pole="1" | ||
74 | 65 | hunting_bow="1" | ||
75 | 66 | iron="25" | ||
76 | 67 | iron_ore="20" | ||
77 | 68 | milking_tongs="1" | ||
78 | 69 | pick="3" | ||
79 | 70 | planks="40" | ||
80 | 71 | quartz="10" | ||
81 | 72 | saw="2" | ||
82 | 73 | scythe="1" | ||
83 | 74 | shield_advanced="1" | ||
84 | 75 | shield_steel="1" | ||
85 | 76 | shovel="2" | ||
86 | 77 | smoked_fish="40" | ||
87 | 78 | smoked_meat="25" | ||
88 | 79 | spidercloth="20" | ||
89 | 80 | spider_silk="15" | ||
90 | 81 | tabard="30" | ||
91 | 82 | tabard_golden="1" | ||
92 | 83 | trident_double="1" | ||
93 | 84 | trident_heavy_double="1" | ||
94 | 85 | trident_light="30" | ||
95 | 86 | trident_long="1" | ||
96 | 87 | trident_steel="1" | ||
97 | 88 | atlanteans_horse="20" | ||
98 | 89 | atlanteans_soldier="20" | ||
99 | 0 | 90 | ||
100 | === added file 'data/tribes/economy_profiles/barbarians' | |||
101 | --- data/tribes/economy_profiles/barbarians 1970-01-01 00:00:00 +0000 | |||
102 | +++ data/tribes/economy_profiles/barbarians 2019-05-06 13:51:46 +0000 | |||
103 | @@ -0,0 +1,81 @@ | |||
104 | 1 | # Automatically created by Widelands bzr9094[economy-target-profiles] (Debug) | ||
105 | 2 | |||
106 | 3 | [Default] | ||
107 | 4 | 0=_"Efficiency" | ||
108 | 5 | 1=_"Stockpile" | ||
109 | 6 | |||
110 | 7 | [0] | ||
111 | 8 | ax="1" | ||
112 | 9 | ax_battle="0" | ||
113 | 10 | ax_broad="0" | ||
114 | 11 | ax_bronze="0" | ||
115 | 12 | ax_sharp="0" | ||
116 | 13 | ax_warriors="0" | ||
117 | 14 | beer="0" | ||
118 | 15 | beer_strong="1" | ||
119 | 16 | blackwood="40" | ||
120 | 17 | barbarians_bread="5" | ||
121 | 18 | bread_paddle="0" | ||
122 | 19 | cloth="10" | ||
123 | 20 | coal="20" | ||
124 | 21 | felling_ax="0" | ||
125 | 22 | fire_tongs="1" | ||
126 | 23 | fishing_rod="0" | ||
127 | 24 | gold="1" | ||
128 | 25 | gold_ore="1" | ||
129 | 26 | granite="10" | ||
130 | 27 | grout="1" | ||
131 | 28 | hammer="1" | ||
132 | 29 | helmet="0" | ||
133 | 30 | helmet_mask="0" | ||
134 | 31 | helmet_warhelm="0" | ||
135 | 32 | hunting_spear="0" | ||
136 | 33 | iron="5" | ||
137 | 34 | iron_ore="5" | ||
138 | 35 | kitchen_tools="0" | ||
139 | 36 | meal="5" | ||
140 | 37 | pick="1" | ||
141 | 38 | ration="20" | ||
142 | 39 | scythe="0" | ||
143 | 40 | shovel="0" | ||
144 | 41 | snack="0" | ||
145 | 42 | barbarians_ox="1" | ||
146 | 43 | barbarians_soldier="10" | ||
147 | 44 | |||
148 | 45 | [1] | ||
149 | 46 | ax="30" | ||
150 | 47 | ax_battle="1" | ||
151 | 48 | ax_broad="1" | ||
152 | 49 | ax_bronze="1" | ||
153 | 50 | ax_sharp="1" | ||
154 | 51 | ax_warriors="1" | ||
155 | 52 | beer="15" | ||
156 | 53 | beer_strong="20" | ||
157 | 54 | blackwood="45" | ||
158 | 55 | barbarians_bread="25" | ||
159 | 56 | bread_paddle="1" | ||
160 | 57 | cloth="10" | ||
161 | 58 | coal="25" | ||
162 | 59 | felling_ax="5" | ||
163 | 60 | fire_tongs="1" | ||
164 | 61 | fishing_rod="1" | ||
165 | 62 | gold="20" | ||
166 | 63 | gold_ore="15" | ||
167 | 64 | granite="30" | ||
168 | 65 | grout="20" | ||
169 | 66 | hammer="2" | ||
170 | 67 | helmet="1" | ||
171 | 68 | helmet_mask="1" | ||
172 | 69 | helmet_warhelm="1" | ||
173 | 70 | hunting_spear="1" | ||
174 | 71 | iron="25" | ||
175 | 72 | iron_ore="20" | ||
176 | 73 | kitchen_tools="1" | ||
177 | 74 | meal="15" | ||
178 | 75 | pick="2" | ||
179 | 76 | ration="30" | ||
180 | 77 | scythe="1" | ||
181 | 78 | shovel="1" | ||
182 | 79 | snack="20" | ||
183 | 80 | barbarians_ox="20" | ||
184 | 81 | barbarians_soldier="20" | ||
185 | 0 | 82 | ||
186 | === added file 'data/tribes/economy_profiles/empire' | |||
187 | --- data/tribes/economy_profiles/empire 1970-01-01 00:00:00 +0000 | |||
188 | +++ data/tribes/economy_profiles/empire 2019-05-06 13:51:46 +0000 | |||
189 | @@ -0,0 +1,89 @@ | |||
190 | 1 | # Automatically created by Widelands bzr9094[economy-target-profiles] (Debug) | ||
191 | 2 | |||
192 | 3 | [Default] | ||
193 | 4 | 0=_"Efficiency" | ||
194 | 5 | 1=_"Stockpile" | ||
195 | 6 | |||
196 | 7 | [0] | ||
197 | 8 | armor="1" | ||
198 | 9 | armor_chain="1" | ||
199 | 10 | armor_gilded="1" | ||
200 | 11 | armor_helmet="30" | ||
201 | 12 | basket="1" | ||
202 | 13 | beer="1" | ||
203 | 14 | empire_bread="20" | ||
204 | 15 | bread_paddle="0" | ||
205 | 16 | cloth="15" | ||
206 | 17 | coal="5" | ||
207 | 18 | felling_ax="0" | ||
208 | 19 | fire_tongs="1" | ||
209 | 20 | fishing_rod="0" | ||
210 | 21 | flour="20" | ||
211 | 22 | gold="1" | ||
212 | 23 | gold_ore="1" | ||
213 | 24 | granite="10" | ||
214 | 25 | hammer="0" | ||
215 | 26 | hunting_spear="0" | ||
216 | 27 | iron="5" | ||
217 | 28 | iron_ore="3" | ||
218 | 29 | kitchen_tools="0" | ||
219 | 30 | marble="30" | ||
220 | 31 | marble_column="10" | ||
221 | 32 | meal="5" | ||
222 | 33 | meat="20" | ||
223 | 34 | pick="1" | ||
224 | 35 | planks="1" | ||
225 | 36 | ration="20" | ||
226 | 37 | saw="0" | ||
227 | 38 | scythe="0" | ||
228 | 39 | shovel="0" | ||
229 | 40 | spear="1" | ||
230 | 41 | spear_advanced="1" | ||
231 | 42 | spear_heavy="1" | ||
232 | 43 | spear_war="1" | ||
233 | 44 | spear_wooden="30" | ||
234 | 45 | wool="10" | ||
235 | 46 | empire_donkey="1" | ||
236 | 47 | empire_soldier="10" | ||
237 | 48 | |||
238 | 49 | [1] | ||
239 | 50 | armor="1" | ||
240 | 51 | armor_chain="1" | ||
241 | 52 | armor_gilded="1" | ||
242 | 53 | armor_helmet="30" | ||
243 | 54 | basket="1" | ||
244 | 55 | beer="20" | ||
245 | 56 | empire_bread="30" | ||
246 | 57 | bread_paddle="1" | ||
247 | 58 | cloth="15" | ||
248 | 59 | coal="25" | ||
249 | 60 | felling_ax="3" | ||
250 | 61 | fire_tongs="1" | ||
251 | 62 | fishing_rod="1" | ||
252 | 63 | flour="25" | ||
253 | 64 | gold="20" | ||
254 | 65 | gold_ore="15" | ||
255 | 66 | granite="30" | ||
256 | 67 | hammer="2" | ||
257 | 68 | hunting_spear="1" | ||
258 | 69 | iron="25" | ||
259 | 70 | iron_ore="20" | ||
260 | 71 | kitchen_tools="1" | ||
261 | 72 | marble="35" | ||
262 | 73 | marble_column="15" | ||
263 | 74 | meal="20" | ||
264 | 75 | meat="30" | ||
265 | 76 | pick="2" | ||
266 | 77 | planks="40" | ||
267 | 78 | ration="25" | ||
268 | 79 | saw="1" | ||
269 | 80 | scythe="1" | ||
270 | 81 | shovel="1" | ||
271 | 82 | spear="1" | ||
272 | 83 | spear_advanced="1" | ||
273 | 84 | spear_heavy="1" | ||
274 | 85 | spear_war="1" | ||
275 | 86 | spear_wooden="30" | ||
276 | 87 | wool="15" | ||
277 | 88 | empire_donkey="20" | ||
278 | 89 | empire_soldier="20" | ||
279 | 0 | 90 | ||
280 | === added file 'data/tribes/economy_profiles/frisians' | |||
281 | --- data/tribes/economy_profiles/frisians 1970-01-01 00:00:00 +0000 | |||
282 | +++ data/tribes/economy_profiles/frisians 2019-05-06 13:51:46 +0000 | |||
283 | @@ -0,0 +1,93 @@ | |||
284 | 1 | # Automatically created by Widelands bzr9093[economy-target-profiles] (Debug) | ||
285 | 2 | |||
286 | 3 | [Default] | ||
287 | 4 | 0=_"Efficiency" | ||
288 | 5 | 1=_"Stockpile" | ||
289 | 6 | |||
290 | 7 | [0] | ||
291 | 8 | clay="30" | ||
292 | 9 | brick="40" | ||
293 | 10 | bread_frisians="20" | ||
294 | 11 | honey_bread="20" | ||
295 | 12 | mead="15" | ||
296 | 13 | fur="10" | ||
297 | 14 | fur_garment="30" | ||
298 | 15 | fur_garment_studded="2" | ||
299 | 16 | fur_garment_golden="2" | ||
300 | 17 | helmet_golden="2" | ||
301 | 18 | sword_short="30" | ||
302 | 19 | sword_long="2" | ||
303 | 20 | sword_broad="2" | ||
304 | 21 | sword_double="2" | ||
305 | 22 | needles="1" | ||
306 | 23 | basket="1" | ||
307 | 24 | beer="1" | ||
308 | 25 | bread_paddle="1" | ||
309 | 26 | cloth="10" | ||
310 | 27 | coal="20" | ||
311 | 28 | felling_ax="0" | ||
312 | 29 | fire_tongs="1" | ||
313 | 30 | fish="20" | ||
314 | 31 | fishing_net="2" | ||
315 | 32 | gold="1" | ||
316 | 33 | gold_ore="1" | ||
317 | 34 | granite="10" | ||
318 | 35 | hammer="1" | ||
319 | 36 | helmet="0" | ||
320 | 37 | hunting_spear="0" | ||
321 | 38 | iron="5" | ||
322 | 39 | iron_ore="3" | ||
323 | 40 | kitchen_tools="0" | ||
324 | 41 | meal="1" | ||
325 | 42 | pick="1" | ||
326 | 43 | ration="20" | ||
327 | 44 | scythe="0" | ||
328 | 45 | shovel="0" | ||
329 | 46 | smoked_fish="20" | ||
330 | 47 | smoked_meat="10" | ||
331 | 48 | frisians_reindeer="1" | ||
332 | 49 | frisians_soldier="10" | ||
333 | 50 | |||
334 | 51 | [1] | ||
335 | 52 | clay="35" | ||
336 | 53 | brick="50" | ||
337 | 54 | bread_frisians="30" | ||
338 | 55 | honey_bread="30" | ||
339 | 56 | mead="30" | ||
340 | 57 | fur="20" | ||
341 | 58 | fur_garment="30" | ||
342 | 59 | fur_garment_studded="2" | ||
343 | 60 | fur_garment_golden="2" | ||
344 | 61 | helmet_golden="2" | ||
345 | 62 | sword_short="30" | ||
346 | 63 | sword_long="2" | ||
347 | 64 | sword_broad="2" | ||
348 | 65 | sword_double="2" | ||
349 | 66 | needles="1" | ||
350 | 67 | basket="1" | ||
351 | 68 | beer="30" | ||
352 | 69 | bread_paddle="1" | ||
353 | 70 | cloth="10" | ||
354 | 71 | coal="35" | ||
355 | 72 | felling_ax="3" | ||
356 | 73 | fire_tongs="2" | ||
357 | 74 | fish="40" | ||
358 | 75 | fishing_net="2" | ||
359 | 76 | gold="20" | ||
360 | 77 | gold_ore="15" | ||
361 | 78 | granite="35" | ||
362 | 79 | hammer="3" | ||
363 | 80 | helmet="2" | ||
364 | 81 | hunting_spear="1" | ||
365 | 82 | iron="25" | ||
366 | 83 | iron_ore="20" | ||
367 | 84 | kitchen_tools="2" | ||
368 | 85 | meal="10" | ||
369 | 86 | pick="3" | ||
370 | 87 | ration="30" | ||
371 | 88 | scythe="2" | ||
372 | 89 | shovel="5" | ||
373 | 90 | smoked_fish="30" | ||
374 | 91 | smoked_meat="20" | ||
375 | 92 | frisians_reindeer="20" | ||
376 | 93 | frisians_soldier="20" | ||
377 | 0 | 94 | ||
378 | === modified file 'src/logic/filesystem_constants.h' | |||
379 | --- src/logic/filesystem_constants.h 2019-04-18 16:50:35 +0000 | |||
380 | +++ src/logic/filesystem_constants.h 2019-05-06 13:51:46 +0000 | |||
381 | @@ -78,4 +78,6 @@ | |||
382 | 78 | /// Filesystem names for config | 78 | /// Filesystem names for config |
383 | 79 | const std::string kConfigFile = "config"; | 79 | const std::string kConfigFile = "config"; |
384 | 80 | 80 | ||
385 | 81 | const std::string kEconomyProfilesDir = "tribes/economy_profiles"; | ||
386 | 82 | |||
387 | 81 | #endif // end of include guard: WL_LOGIC_FILESYSTEM_CONSTANTS_H | 83 | #endif // end of include guard: WL_LOGIC_FILESYSTEM_CONSTANTS_H |
388 | 82 | 84 | ||
389 | === modified file 'src/logic/map_objects/tribes/tribe_descr.cc' | |||
390 | --- src/logic/map_objects/tribes/tribe_descr.cc 2019-05-04 10:47:44 +0000 | |||
391 | +++ src/logic/map_objects/tribes/tribe_descr.cc 2019-05-06 13:51:46 +0000 | |||
392 | @@ -89,8 +89,6 @@ | |||
393 | 89 | load_roads("busy", &busy_road_paths_); | 89 | load_roads("busy", &busy_road_paths_); |
394 | 90 | 90 | ||
395 | 91 | items_table = table.get_table("wares_order"); | 91 | items_table = table.get_table("wares_order"); |
396 | 92 | wares_order_coords_.resize(tribes_.nrwares()); | ||
397 | 93 | int columnindex = 0; | ||
398 | 94 | for (const int key : items_table->keys<int>()) { | 92 | for (const int key : items_table->keys<int>()) { |
399 | 95 | std::vector<DescriptionIndex> column; | 93 | std::vector<DescriptionIndex> column; |
400 | 96 | std::vector<std::string> warenames = | 94 | std::vector<std::string> warenames = |
401 | @@ -104,7 +102,6 @@ | |||
402 | 104 | } | 102 | } |
403 | 105 | wares_.insert(wareindex); | 103 | wares_.insert(wareindex); |
404 | 106 | column.push_back(wareindex); | 104 | column.push_back(wareindex); |
405 | 107 | wares_order_coords_[wareindex] = std::make_pair(columnindex, rowindex); | ||
406 | 108 | } catch (const WException& e) { | 105 | } catch (const WException& e) { |
407 | 109 | throw GameDataError( | 106 | throw GameDataError( |
408 | 110 | "Failed adding ware '%s: %s", warenames[rowindex].c_str(), e.what()); | 107 | "Failed adding ware '%s: %s", warenames[rowindex].c_str(), e.what()); |
409 | @@ -112,13 +109,10 @@ | |||
410 | 112 | } | 109 | } |
411 | 113 | if (!column.empty()) { | 110 | if (!column.empty()) { |
412 | 114 | wares_order_.push_back(column); | 111 | wares_order_.push_back(column); |
413 | 115 | ++columnindex; | ||
414 | 116 | } | 112 | } |
415 | 117 | } | 113 | } |
416 | 118 | 114 | ||
417 | 119 | items_table = table.get_table("workers_order"); | 115 | items_table = table.get_table("workers_order"); |
418 | 120 | workers_order_coords_.resize(tribes_.nrworkers()); | ||
419 | 121 | columnindex = 0; | ||
420 | 122 | for (const int key : items_table->keys<int>()) { | 116 | for (const int key : items_table->keys<int>()) { |
421 | 123 | std::vector<DescriptionIndex> column; | 117 | std::vector<DescriptionIndex> column; |
422 | 124 | std::vector<std::string> workernames = | 118 | std::vector<std::string> workernames = |
423 | @@ -132,7 +126,6 @@ | |||
424 | 132 | } | 126 | } |
425 | 133 | workers_.insert(workerindex); | 127 | workers_.insert(workerindex); |
426 | 134 | column.push_back(workerindex); | 128 | column.push_back(workerindex); |
427 | 135 | workers_order_coords_[workerindex] = std::make_pair(columnindex, rowindex); | ||
428 | 136 | 129 | ||
429 | 137 | const WorkerDescr& worker_descr = *tribes_.get_worker_descr(workerindex); | 130 | const WorkerDescr& worker_descr = *tribes_.get_worker_descr(workerindex); |
430 | 138 | if (worker_descr.is_buildable() && worker_descr.buildcost().empty()) { | 131 | if (worker_descr.is_buildable() && worker_descr.buildcost().empty()) { |
431 | @@ -145,7 +138,6 @@ | |||
432 | 145 | } | 138 | } |
433 | 146 | if (!column.empty()) { | 139 | if (!column.empty()) { |
434 | 147 | workers_order_.push_back(column); | 140 | workers_order_.push_back(column); |
435 | 148 | ++columnindex; | ||
436 | 149 | } | 141 | } |
437 | 150 | } | 142 | } |
438 | 151 | 143 | ||
439 | @@ -423,38 +415,6 @@ | |||
440 | 423 | return list->second.find(lowest)->second; | 415 | return list->second.find(lowest)->second; |
441 | 424 | } | 416 | } |
442 | 425 | 417 | ||
443 | 426 | void TribeDescr::resize_ware_orders(size_t maxLength) { | ||
444 | 427 | bool need_resize = false; | ||
445 | 428 | |||
446 | 429 | // Check if we actually need to resize. | ||
447 | 430 | for (WaresOrder::iterator it = wares_order_.begin(); it != wares_order_.end(); ++it) { | ||
448 | 431 | if (it->size() > maxLength) { | ||
449 | 432 | need_resize = true; | ||
450 | 433 | } | ||
451 | 434 | } | ||
452 | 435 | |||
453 | 436 | // Build new smaller wares_order. | ||
454 | 437 | if (need_resize) { | ||
455 | 438 | WaresOrder new_wares_order; | ||
456 | 439 | for (WaresOrder::iterator it = wares_order_.begin(); it != wares_order_.end(); ++it) { | ||
457 | 440 | new_wares_order.push_back(std::vector<Widelands::DescriptionIndex>()); | ||
458 | 441 | for (std::vector<Widelands::DescriptionIndex>::iterator it2 = it->begin(); | ||
459 | 442 | it2 != it->end(); ++it2) { | ||
460 | 443 | if (new_wares_order.rbegin()->size() >= maxLength) { | ||
461 | 444 | new_wares_order.push_back(std::vector<Widelands::DescriptionIndex>()); | ||
462 | 445 | } | ||
463 | 446 | new_wares_order.rbegin()->push_back(*it2); | ||
464 | 447 | wares_order_coords_[*it2].first = new_wares_order.size() - 1; | ||
465 | 448 | wares_order_coords_[*it2].second = new_wares_order.rbegin()->size() - 1; | ||
466 | 449 | } | ||
467 | 450 | } | ||
468 | 451 | |||
469 | 452 | // Remove old array. | ||
470 | 453 | wares_order_.clear(); | ||
471 | 454 | wares_order_ = new_wares_order; | ||
472 | 455 | } | ||
473 | 456 | } | ||
474 | 457 | |||
475 | 458 | void TribeDescr::add_building(const std::string& buildingname) { | 418 | void TribeDescr::add_building(const std::string& buildingname) { |
476 | 459 | try { | 419 | try { |
477 | 460 | DescriptionIndex index = tribes_.safe_building_index(buildingname); | 420 | DescriptionIndex index = tribes_.safe_building_index(buildingname); |
478 | 461 | 421 | ||
479 | === modified file 'src/logic/map_objects/tribes/tribe_descr.h' | |||
480 | --- src/logic/map_objects/tribes/tribe_descr.h 2019-03-01 04:19:53 +0000 | |||
481 | +++ src/logic/map_objects/tribes/tribe_descr.h 2019-05-06 13:51:46 +0000 | |||
482 | @@ -149,22 +149,13 @@ | |||
483 | 149 | } | 149 | } |
484 | 150 | 150 | ||
485 | 151 | using WaresOrder = std::vector<std::vector<Widelands::DescriptionIndex>>; | 151 | using WaresOrder = std::vector<std::vector<Widelands::DescriptionIndex>>; |
486 | 152 | using WaresOrderCoords = std::vector<std::pair<uint32_t, uint32_t>>; | ||
487 | 153 | const WaresOrder& wares_order() const { | 152 | const WaresOrder& wares_order() const { |
488 | 154 | return wares_order_; | 153 | return wares_order_; |
489 | 155 | } | 154 | } |
490 | 156 | const WaresOrderCoords& wares_order_coords() const { | ||
491 | 157 | return wares_order_coords_; | ||
492 | 158 | } | ||
493 | 159 | 155 | ||
494 | 160 | const WaresOrder& workers_order() const { | 156 | const WaresOrder& workers_order() const { |
495 | 161 | return workers_order_; | 157 | return workers_order_; |
496 | 162 | } | 158 | } |
497 | 163 | const WaresOrderCoords& workers_order_coords() const { | ||
498 | 164 | return workers_order_coords_; | ||
499 | 165 | } | ||
500 | 166 | |||
501 | 167 | void resize_ware_orders(size_t maxLength); | ||
502 | 168 | 159 | ||
503 | 169 | const std::vector<std::string>& get_ship_names() const { | 160 | const std::vector<std::string>& get_ship_names() const { |
504 | 170 | return ship_names_; | 161 | return ship_names_; |
505 | @@ -215,9 +206,7 @@ | |||
506 | 215 | std::vector<DescriptionIndex> trainingsites_; | 206 | std::vector<DescriptionIndex> trainingsites_; |
507 | 216 | // Order and positioning of wares in the warehouse display | 207 | // Order and positioning of wares in the warehouse display |
508 | 217 | WaresOrder wares_order_; | 208 | WaresOrder wares_order_; |
509 | 218 | WaresOrderCoords wares_order_coords_; | ||
510 | 219 | WaresOrder workers_order_; | 209 | WaresOrder workers_order_; |
511 | 220 | WaresOrderCoords workers_order_coords_; | ||
512 | 221 | 210 | ||
513 | 222 | std::vector<Widelands::TribeBasicInfo::Initialization> initializations_; | 211 | std::vector<Widelands::TribeBasicInfo::Initialization> initializations_; |
514 | 223 | 212 | ||
515 | 224 | 213 | ||
516 | === modified file 'src/logic/map_objects/tribes/tribes.cc' | |||
517 | --- src/logic/map_objects/tribes/tribes.cc 2019-03-01 04:19:53 +0000 | |||
518 | +++ src/logic/map_objects/tribes/tribes.cc 2019-05-06 13:51:46 +0000 | |||
519 | @@ -340,14 +340,9 @@ | |||
520 | 340 | // Calculate the trainingsites proportions. | 340 | // Calculate the trainingsites proportions. |
521 | 341 | postload_calculate_trainingsites_proportions(); | 341 | postload_calculate_trainingsites_proportions(); |
522 | 342 | 342 | ||
527 | 343 | // Resize the configuration of our wares if they won't fit in the current window (12 = info label | 343 | // Some final checks on the gamedata |
524 | 344 | // size). | ||
525 | 345 | // Also, do some final checks on the gamedata | ||
526 | 346 | int number = (g_gr->get_yres() - 290) / (WARE_MENU_PIC_HEIGHT + WARE_MENU_PIC_PAD_Y + 12); | ||
528 | 347 | for (DescriptionIndex i = 0; i < tribes_->size(); ++i) { | 344 | for (DescriptionIndex i = 0; i < tribes_->size(); ++i) { |
529 | 348 | TribeDescr* tribe_descr = tribes_->get_mutable(i); | 345 | TribeDescr* tribe_descr = tribes_->get_mutable(i); |
530 | 349 | tribe_descr->resize_ware_orders(number); | ||
531 | 350 | |||
532 | 351 | // Verify that the preciousness has been set for all of the tribe's wares | 346 | // Verify that the preciousness has been set for all of the tribe's wares |
533 | 352 | for (const DescriptionIndex wi : tribe_descr->wares()) { | 347 | for (const DescriptionIndex wi : tribe_descr->wares()) { |
534 | 353 | if (tribe_descr->get_ware_descr(wi)->preciousness(tribe_descr->name()) == kInvalidWare) { | 348 | if (tribe_descr->get_ware_descr(wi)->preciousness(tribe_descr->name()) == kInvalidWare) { |
535 | 354 | 349 | ||
536 | === modified file 'src/logic/map_objects/tribes/ware_descr.h' | |||
537 | --- src/logic/map_objects/tribes/ware_descr.h 2019-02-27 19:00:36 +0000 | |||
538 | +++ src/logic/map_objects/tribes/ware_descr.h 2019-05-06 13:51:46 +0000 | |||
539 | @@ -33,10 +33,8 @@ | |||
540 | 33 | class Image; | 33 | class Image; |
541 | 34 | class LuaTable; | 34 | class LuaTable; |
542 | 35 | 35 | ||
547 | 36 | #define WARE_MENU_PIC_WIDTH 24 //!< Default width for ware's menu icons | 36 | constexpr int kWareMenuPicWidth = 24; //!< Default width for ware's menu icons |
548 | 37 | #define WARE_MENU_PIC_HEIGHT 24 //!< Default height for ware's menu icons | 37 | constexpr int kWareMenuPicHeight = 24; //!< Default height for ware's menu icons |
545 | 38 | #define WARE_MENU_PIC_PAD_X 3 //!< Default padding between menu icons | ||
546 | 39 | #define WARE_MENU_PIC_PAD_Y 4 //!< Default padding between menu icons | ||
549 | 40 | 38 | ||
550 | 41 | namespace Widelands { | 39 | namespace Widelands { |
551 | 42 | 40 | ||
552 | 43 | 41 | ||
553 | === modified file 'src/logic/playercommand.h' | |||
554 | --- src/logic/playercommand.h 2019-02-23 11:00:49 +0000 | |||
555 | +++ src/logic/playercommand.h 2019-05-06 13:51:46 +0000 | |||
556 | @@ -581,6 +581,7 @@ | |||
557 | 581 | uint32_t permanent_; | 581 | uint32_t permanent_; |
558 | 582 | }; | 582 | }; |
559 | 583 | 583 | ||
560 | 584 | // TODO(Nordfriese): CmdResetWareTargetQuantity can be removed when we next break savegame compatibility | ||
561 | 584 | struct CmdResetWareTargetQuantity : public CmdChangeTargetQuantity { | 585 | struct CmdResetWareTargetQuantity : public CmdChangeTargetQuantity { |
562 | 585 | CmdResetWareTargetQuantity() : CmdChangeTargetQuantity() { | 586 | CmdResetWareTargetQuantity() : CmdChangeTargetQuantity() { |
563 | 586 | } | 587 | } |
564 | @@ -629,6 +630,7 @@ | |||
565 | 629 | uint32_t permanent_; | 630 | uint32_t permanent_; |
566 | 630 | }; | 631 | }; |
567 | 631 | 632 | ||
568 | 633 | // TODO(Nordfriese): CmdResetWorkerTargetQuantity can be removed when we next break savegame compatibility | ||
569 | 632 | struct CmdResetWorkerTargetQuantity : public CmdChangeTargetQuantity { | 634 | struct CmdResetWorkerTargetQuantity : public CmdChangeTargetQuantity { |
570 | 633 | CmdResetWorkerTargetQuantity() : CmdChangeTargetQuantity() { | 635 | CmdResetWorkerTargetQuantity() : CmdChangeTargetQuantity() { |
571 | 634 | } | 636 | } |
572 | 635 | 637 | ||
573 | === modified file 'src/wui/CMakeLists.txt' | |||
574 | --- src/wui/CMakeLists.txt 2019-05-04 15:37:33 +0000 | |||
575 | +++ src/wui/CMakeLists.txt 2019-05-06 13:51:46 +0000 | |||
576 | @@ -44,8 +44,10 @@ | |||
577 | 44 | graphic | 44 | graphic |
578 | 45 | logic | 45 | logic |
579 | 46 | logic_commands | 46 | logic_commands |
580 | 47 | logic_filesystem_constants | ||
581 | 47 | logic_map_objects | 48 | logic_map_objects |
582 | 48 | notifications | 49 | notifications |
583 | 50 | profile | ||
584 | 49 | ui_basic | 51 | ui_basic |
585 | 50 | wui_waresdisplay | 52 | wui_waresdisplay |
586 | 51 | ) | 53 | ) |
587 | 52 | 54 | ||
588 | === modified file 'src/wui/economy_options_window.cc' | |||
589 | --- src/wui/economy_options_window.cc 2019-02-23 11:00:49 +0000 | |||
590 | +++ src/wui/economy_options_window.cc 2019-05-06 13:51:46 +0000 | |||
591 | @@ -19,36 +19,98 @@ | |||
592 | 19 | 19 | ||
593 | 20 | #include "wui/economy_options_window.h" | 20 | #include "wui/economy_options_window.h" |
594 | 21 | 21 | ||
595 | 22 | #include <memory> | ||
596 | 23 | |||
597 | 22 | #include <boost/lexical_cast.hpp> | 24 | #include <boost/lexical_cast.hpp> |
598 | 23 | 25 | ||
599 | 24 | #include "graphic/graphic.h" | 26 | #include "graphic/graphic.h" |
600 | 25 | #include "logic/editor_game_base.h" | 27 | #include "logic/editor_game_base.h" |
601 | 28 | #include "logic/filesystem_constants.h" | ||
602 | 26 | #include "logic/map_objects/tribes/ware_descr.h" | 29 | #include "logic/map_objects/tribes/ware_descr.h" |
603 | 27 | #include "logic/map_objects/tribes/worker_descr.h" | 30 | #include "logic/map_objects/tribes/worker_descr.h" |
604 | 28 | #include "logic/player.h" | 31 | #include "logic/player.h" |
605 | 29 | #include "logic/playercommand.h" | 32 | #include "logic/playercommand.h" |
606 | 33 | #include "profile/profile.h" | ||
607 | 30 | #include "ui_basic/button.h" | 34 | #include "ui_basic/button.h" |
608 | 35 | #include "ui_basic/editbox.h" | ||
609 | 36 | #include "ui_basic/messagebox.h" | ||
610 | 37 | #include "ui_basic/table.h" | ||
611 | 31 | 38 | ||
612 | 32 | static const char pic_tab_wares[] = "images/wui/buildings/menu_tab_wares.png"; | 39 | static const char pic_tab_wares[] = "images/wui/buildings/menu_tab_wares.png"; |
613 | 33 | static const char pic_tab_workers[] = "images/wui/buildings/menu_tab_workers.png"; | 40 | static const char pic_tab_workers[] = "images/wui/buildings/menu_tab_workers.png"; |
614 | 34 | 41 | ||
615 | 42 | constexpr int kDesiredWidth = 216; | ||
616 | 43 | |||
617 | 44 | static inline int32_t calc_hgap(int32_t columns, int32_t total_w) { | ||
618 | 45 | return (total_w - columns * kWareMenuPicWidth) / (columns - 1); | ||
619 | 46 | } | ||
620 | 47 | |||
621 | 35 | EconomyOptionsWindow::EconomyOptionsWindow(UI::Panel* parent, | 48 | EconomyOptionsWindow::EconomyOptionsWindow(UI::Panel* parent, |
622 | 36 | Widelands::Economy* economy, | 49 | Widelands::Economy* economy, |
623 | 37 | bool can_act) | 50 | bool can_act) |
624 | 38 | : UI::Window(parent, "economy_options", 0, 0, 0, 0, _("Economy options")), | 51 | : UI::Window(parent, "economy_options", 0, 0, 0, 0, _("Economy options")), |
625 | 52 | main_box_(this, 0, 0, UI::Box::Vertical), | ||
626 | 39 | serial_(economy->serial()), | 53 | serial_(economy->serial()), |
627 | 40 | player_(&economy->owner()), | 54 | player_(&economy->owner()), |
628 | 41 | tabpanel_(this, UI::TabPanelStyle::kWuiDark), | 55 | tabpanel_(this, UI::TabPanelStyle::kWuiDark), |
630 | 42 | ware_panel_(new EconomyOptionsPanel(&tabpanel_, serial_, player_, can_act, Widelands::wwWARE)), | 56 | ware_panel_(new EconomyOptionsPanel(&tabpanel_, this, serial_, player_, can_act, Widelands::wwWARE, kDesiredWidth)), |
631 | 43 | worker_panel_( | 57 | worker_panel_( |
634 | 44 | new EconomyOptionsPanel(&tabpanel_, serial_, player_, can_act, Widelands::wwWORKER)) { | 58 | new EconomyOptionsPanel(&tabpanel_, this, serial_, player_, can_act, Widelands::wwWORKER, kDesiredWidth)), |
635 | 45 | set_center_panel(&tabpanel_); | 59 | dropdown_box_(this, 0, 0, UI::Box::Horizontal), |
636 | 60 | dropdown_(&dropdown_box_, 0, 0, 174, 200, 34, "", UI::DropdownType::kTextual, UI::PanelStyle::kWui) { | ||
637 | 61 | set_center_panel(&main_box_); | ||
638 | 46 | 62 | ||
639 | 47 | tabpanel_.add("wares", g_gr->images().get(pic_tab_wares), ware_panel_, _("Wares")); | 63 | tabpanel_.add("wares", g_gr->images().get(pic_tab_wares), ware_panel_, _("Wares")); |
640 | 48 | tabpanel_.add("workers", g_gr->images().get(pic_tab_workers), worker_panel_, _("Workers")); | 64 | tabpanel_.add("workers", g_gr->images().get(pic_tab_workers), worker_panel_, _("Workers")); |
641 | 65 | |||
642 | 66 | UI::Box* buttons = new UI::Box(this, 0, 0, UI::Box::Horizontal); | ||
643 | 67 | UI::Button* b = new UI::Button(buttons, "decrease_target_fast", 0, 0, 44, 28, UI::ButtonStyle::kWuiSecondary, | ||
644 | 68 | g_gr->images().get("images/ui_basic/scrollbar_down_fast.png"), _("Decrease target by 10")); | ||
645 | 69 | b->sigclicked.connect([this] { change_target(-10); }); | ||
646 | 70 | buttons->add(b); | ||
647 | 71 | b->set_repeating(true); | ||
648 | 72 | buttons->add_space(8); | ||
649 | 73 | b = new UI::Button(buttons, "decrease_target", 0, 0, 44, 28, UI::ButtonStyle::kWuiSecondary, | ||
650 | 74 | g_gr->images().get("images/ui_basic/scrollbar_down.png"), _("Decrease target")); | ||
651 | 75 | b->sigclicked.connect([this] { change_target(-1); }); | ||
652 | 76 | buttons->add(b); | ||
653 | 77 | b->set_repeating(true); | ||
654 | 78 | buttons->add_space(24); | ||
655 | 79 | |||
656 | 80 | b = new UI::Button(buttons, "increase_target", 0, 0, 44, 28, UI::ButtonStyle::kWuiSecondary, | ||
657 | 81 | g_gr->images().get("images/ui_basic/scrollbar_up.png"), _("Increase target")); | ||
658 | 82 | b->sigclicked.connect([this] { change_target(1); }); | ||
659 | 83 | buttons->add(b); | ||
660 | 84 | b->set_repeating(true); | ||
661 | 85 | buttons->add_space(8); | ||
662 | 86 | b = new UI::Button(buttons, "increase_target_fast", 0, 0, 44, 28, UI::ButtonStyle::kWuiSecondary, | ||
663 | 87 | g_gr->images().get("images/ui_basic/scrollbar_up_fast.png"), _("Increase target by 10")); | ||
664 | 88 | b->sigclicked.connect([this] { change_target(10); }); | ||
665 | 89 | buttons->add(b); | ||
666 | 90 | b->set_repeating(true); | ||
667 | 91 | |||
668 | 92 | dropdown_.set_tooltip(_("Profile to apply to the selected items")); | ||
669 | 93 | dropdown_box_.set_size(40, 20); // Prevent assert failures | ||
670 | 94 | dropdown_box_.add(&dropdown_, UI::Box::Resizing::kFullSize); | ||
671 | 95 | dropdown_.selected.connect([this] { reset_target(); }); | ||
672 | 96 | |||
673 | 97 | b = new UI::Button(&dropdown_box_, "save_targets", 0, 0, 34, 34, UI::ButtonStyle::kWuiMenu, | ||
674 | 98 | g_gr->images().get("images/wui/menus/menu_save_game.png"), _("Save target settings")); | ||
675 | 99 | b->sigclicked.connect([this] { create_target(); }); | ||
676 | 100 | dropdown_box_.add_space(8); | ||
677 | 101 | dropdown_box_.add(b); | ||
678 | 102 | |||
679 | 103 | main_box_.add(&tabpanel_, UI::Box::Resizing::kAlign, UI::Align::kCenter); | ||
680 | 104 | main_box_.add_space(8); | ||
681 | 105 | main_box_.add(buttons, UI::Box::Resizing::kAlign, UI::Align::kCenter); | ||
682 | 106 | main_box_.add_space(8); | ||
683 | 107 | main_box_.add(&dropdown_box_, UI::Box::Resizing::kAlign, UI::Align::kCenter); | ||
684 | 108 | |||
685 | 49 | economy->set_has_window(true); | 109 | economy->set_has_window(true); |
686 | 50 | economynotes_subscriber_ = Notifications::subscribe<Widelands::NoteEconomy>( | 110 | economynotes_subscriber_ = Notifications::subscribe<Widelands::NoteEconomy>( |
687 | 51 | [this](const Widelands::NoteEconomy& note) { on_economy_note(note); }); | 111 | [this](const Widelands::NoteEconomy& note) { on_economy_note(note); }); |
688 | 112 | |||
689 | 113 | read_targets(); | ||
690 | 52 | } | 114 | } |
691 | 53 | 115 | ||
692 | 54 | EconomyOptionsWindow::~EconomyOptionsWindow() { | 116 | EconomyOptionsWindow::~EconomyOptionsWindow() { |
693 | @@ -81,6 +143,20 @@ | |||
694 | 81 | } | 143 | } |
695 | 82 | } | 144 | } |
696 | 83 | 145 | ||
697 | 146 | void EconomyOptionsWindow::layout() { | ||
698 | 147 | int w, h; | ||
699 | 148 | tabpanel_.get_desired_size(&w, &h); | ||
700 | 149 | main_box_.set_desired_size(w, h + 78); | ||
701 | 150 | update_desired_size(); | ||
702 | 151 | UI::Window::layout(); | ||
703 | 152 | } | ||
704 | 153 | |||
705 | 154 | void EconomyOptionsWindow::EconomyOptionsPanel::update_desired_size() { | ||
706 | 155 | display_.set_hgap(std::max(3, calc_hgap(display_.get_extent().w, kDesiredWidth))); | ||
707 | 156 | Box::update_desired_size(); | ||
708 | 157 | get_parent()->layout(); | ||
709 | 158 | } | ||
710 | 159 | |||
711 | 84 | EconomyOptionsWindow::TargetWaresDisplay::TargetWaresDisplay(UI::Panel* const parent, | 160 | EconomyOptionsWindow::TargetWaresDisplay::TargetWaresDisplay(UI::Panel* const parent, |
712 | 85 | int32_t const x, | 161 | int32_t const x, |
713 | 86 | int32_t const y, | 162 | int32_t const y, |
714 | @@ -129,42 +205,26 @@ | |||
715 | 129 | * Wraps the wares/workers display together with some buttons | 205 | * Wraps the wares/workers display together with some buttons |
716 | 130 | */ | 206 | */ |
717 | 131 | EconomyOptionsWindow::EconomyOptionsPanel::EconomyOptionsPanel(UI::Panel* parent, | 207 | EconomyOptionsWindow::EconomyOptionsPanel::EconomyOptionsPanel(UI::Panel* parent, |
718 | 208 | EconomyOptionsWindow* eco_window, | ||
719 | 132 | Widelands::Serial serial, | 209 | Widelands::Serial serial, |
720 | 133 | Widelands::Player* player, | 210 | Widelands::Player* player, |
721 | 134 | bool can_act, | 211 | bool can_act, |
723 | 135 | Widelands::WareWorker type) | 212 | Widelands::WareWorker type, |
724 | 213 | int32_t min_w) | ||
725 | 136 | : UI::Box(parent, 0, 0, UI::Box::Vertical), | 214 | : UI::Box(parent, 0, 0, UI::Box::Vertical), |
726 | 137 | serial_(serial), | 215 | serial_(serial), |
727 | 138 | player_(player), | 216 | player_(player), |
728 | 139 | type_(type), | 217 | type_(type), |
729 | 140 | can_act_(can_act), | 218 | can_act_(can_act), |
731 | 141 | display_(this, 0, 0, serial_, player_, type_, can_act_) { | 219 | display_(this, 0, 0, serial_, player_, type_, can_act_), |
732 | 220 | economy_options_window_(eco_window) { | ||
733 | 142 | add(&display_, UI::Box::Resizing::kFullSize); | 221 | add(&display_, UI::Box::Resizing::kFullSize); |
734 | 143 | 222 | ||
735 | 223 | display_.set_hgap(std::max(3, calc_hgap(display_.get_extent().w, min_w))); | ||
736 | 224 | |||
737 | 144 | if (!can_act_) { | 225 | if (!can_act_) { |
738 | 145 | return; | 226 | return; |
739 | 146 | } | 227 | } |
740 | 147 | UI::Box* buttons = new UI::Box(this, 0, 0, UI::Box::Horizontal); | ||
741 | 148 | add(buttons); | ||
742 | 149 | |||
743 | 150 | UI::Button* b = new UI::Button(buttons, "decrease_target", 0, 0, 34, 34, | ||
744 | 151 | UI::ButtonStyle::kWuiMenu, "-", _("Decrease target")); | ||
745 | 152 | b->sigclicked.connect(boost::bind(&EconomyOptionsPanel::change_target, this, -1)); | ||
746 | 153 | buttons->add(b); | ||
747 | 154 | b->set_repeating(true); | ||
748 | 155 | buttons->add_space(8); | ||
749 | 156 | |||
750 | 157 | b = new UI::Button(buttons, "increase_target", 0, 0, 34, 34, UI::ButtonStyle::kWuiMenu, "+", | ||
751 | 158 | _("Increase target")); | ||
752 | 159 | b->sigclicked.connect(boost::bind(&EconomyOptionsPanel::change_target, this, 1)); | ||
753 | 160 | buttons->add(b); | ||
754 | 161 | b->set_repeating(true); | ||
755 | 162 | buttons->add_space(8); | ||
756 | 163 | |||
757 | 164 | b = new UI::Button( | ||
758 | 165 | buttons, "reset_target", 0, 0, 34, 34, UI::ButtonStyle::kWuiMenu, "R", _("Reset to default")); | ||
759 | 166 | b->sigclicked.connect(boost::bind(&EconomyOptionsPanel::reset_target, this)); | ||
760 | 167 | buttons->add(b); | ||
761 | 168 | } | 228 | } |
762 | 169 | 229 | ||
763 | 170 | void EconomyOptionsWindow::EconomyOptionsPanel::set_economy(Widelands::Serial serial) { | 230 | void EconomyOptionsWindow::EconomyOptionsPanel::set_economy(Widelands::Serial serial) { |
764 | @@ -172,7 +232,26 @@ | |||
765 | 172 | display_.set_economy(serial); | 232 | display_.set_economy(serial); |
766 | 173 | } | 233 | } |
767 | 174 | 234 | ||
769 | 175 | void EconomyOptionsWindow::EconomyOptionsPanel::change_target(int amount) { | 235 | void EconomyOptionsWindow::change_target(int amount) { |
770 | 236 | if (tabpanel_.active() == 0) { | ||
771 | 237 | ware_panel_->change_target(amount); | ||
772 | 238 | } else { | ||
773 | 239 | worker_panel_->change_target(amount); | ||
774 | 240 | } | ||
775 | 241 | } | ||
776 | 242 | |||
777 | 243 | void EconomyOptionsWindow::reset_target() { | ||
778 | 244 | if (tabpanel_.active() == 0) { | ||
779 | 245 | ware_panel_->reset_target(); | ||
780 | 246 | } else { | ||
781 | 247 | worker_panel_->reset_target(); | ||
782 | 248 | } | ||
783 | 249 | } | ||
784 | 250 | |||
785 | 251 | void EconomyOptionsWindow::EconomyOptionsPanel::change_target(int delta) { | ||
786 | 252 | if (delta == 0) { | ||
787 | 253 | return; | ||
788 | 254 | } | ||
789 | 176 | Widelands::Economy* economy = player_->get_economy(serial_); | 255 | Widelands::Economy* economy = player_->get_economy(serial_); |
790 | 177 | if (economy == nullptr) { | 256 | if (economy == nullptr) { |
791 | 178 | die(); | 257 | die(); |
792 | @@ -186,35 +265,286 @@ | |||
793 | 186 | const Widelands::Economy::TargetQuantity& tq = is_wares ? | 265 | const Widelands::Economy::TargetQuantity& tq = is_wares ? |
794 | 187 | economy->ware_target_quantity(index) : | 266 | economy->ware_target_quantity(index) : |
795 | 188 | economy->worker_target_quantity(index); | 267 | economy->worker_target_quantity(index); |
802 | 189 | // Don't allow negative new amount. | 268 | // Don't allow negative new amount |
803 | 190 | if (amount >= 0 || -amount <= static_cast<int>(tq.permanent)) { | 269 | const int old_amount = static_cast<int>(tq.permanent); |
804 | 191 | if (is_wares) { | 270 | const int new_amount = std::max(0, old_amount + delta); |
805 | 192 | game.send_player_command(*new Widelands::CmdSetWareTargetQuantity( | 271 | if (new_amount == old_amount) { |
806 | 193 | game.get_gametime(), player_->player_number(), serial_, index, | 272 | continue; |
807 | 194 | tq.permanent + amount)); | 273 | } |
808 | 274 | if (is_wares) { | ||
809 | 275 | game.send_player_command(*new Widelands::CmdSetWareTargetQuantity( | ||
810 | 276 | game.get_gametime(), player_->player_number(), serial_, index, new_amount)); | ||
811 | 277 | } else { | ||
812 | 278 | game.send_player_command(*new Widelands::CmdSetWorkerTargetQuantity( | ||
813 | 279 | game.get_gametime(), player_->player_number(), serial_, index, new_amount)); | ||
814 | 280 | } | ||
815 | 281 | } | ||
816 | 282 | } | ||
817 | 283 | } | ||
818 | 284 | |||
819 | 285 | void EconomyOptionsWindow::EconomyOptionsPanel::reset_target() { | ||
820 | 286 | Widelands::Game& game = dynamic_cast<Widelands::Game&>(player_->egbase()); | ||
821 | 287 | const bool is_wares = type_ == Widelands::wwWARE; | ||
822 | 288 | const auto& items = is_wares ? player_->tribe().wares() : player_->tribe().workers(); | ||
823 | 289 | const PredefinedTargets settings = economy_options_window_->get_selected_target(); | ||
824 | 290 | for (const Widelands::DescriptionIndex& index : items) { | ||
825 | 291 | if (display_.ware_selected(index)) { | ||
826 | 292 | if (is_wares) { | ||
827 | 293 | game.send_player_command(*new Widelands::CmdSetWareTargetQuantity( | ||
828 | 294 | game.get_gametime(), player_->player_number(), serial_, index, settings.wares.at(index))); | ||
829 | 295 | } else { | ||
830 | 296 | game.send_player_command(*new Widelands::CmdSetWorkerTargetQuantity( | ||
831 | 297 | game.get_gametime(), player_->player_number(), serial_, index, settings.workers.at(index))); | ||
832 | 298 | } | ||
833 | 299 | } | ||
834 | 300 | } | ||
835 | 301 | } | ||
836 | 302 | |||
837 | 303 | void EconomyOptionsWindow::update_profiles(const std::string& select) { | ||
838 | 304 | dropdown_.clear(); | ||
839 | 305 | for (const auto& pair : predefined_targets_) { | ||
840 | 306 | dropdown_.add(_(pair.first), pair.first, nullptr, pair.first == select); | ||
841 | 307 | } | ||
842 | 308 | } | ||
843 | 309 | |||
844 | 310 | struct SaveProfileWindow : public UI::Window { | ||
845 | 311 | void update_save_enabled() { | ||
846 | 312 | const std::string& text = profile_name_.text(); | ||
847 | 313 | if (text.empty() || text == kDefaultEconomyProfile) { | ||
848 | 314 | save_.set_enabled(false); | ||
849 | 315 | save_.set_tooltip(text.empty() ? _("The profile name cannot be empty") : | ||
850 | 316 | _("The default profile cannot be overwritten")); | ||
851 | 317 | } else { | ||
852 | 318 | save_.set_enabled(true); | ||
853 | 319 | save_.set_tooltip(_("Save the profile under this name")); | ||
854 | 320 | } | ||
855 | 321 | } | ||
856 | 322 | |||
857 | 323 | void table_selection_changed() { | ||
858 | 324 | if (!table_.has_selection()) { | ||
859 | 325 | delete_.set_enabled(false); | ||
860 | 326 | delete_.set_tooltip(""); | ||
861 | 327 | return; | ||
862 | 328 | } | ||
863 | 329 | const std::string& sel = table_[table_.selection_index()]; | ||
864 | 330 | if (sel == kDefaultEconomyProfile) { | ||
865 | 331 | delete_.set_tooltip(_("The default profile cannot be deleted")); | ||
866 | 332 | delete_.set_enabled(false); | ||
867 | 333 | } else { | ||
868 | 334 | delete_.set_tooltip(_("Delete the selected profiles")); | ||
869 | 335 | delete_.set_enabled(true); | ||
870 | 336 | } | ||
871 | 337 | profile_name_.set_text(sel); | ||
872 | 338 | update_save_enabled(); | ||
873 | 339 | } | ||
874 | 340 | |||
875 | 341 | void close(bool ok) { | ||
876 | 342 | end_modal(ok ? UI::Panel::Returncodes::kOk : UI::Panel::Returncodes::kBack); | ||
877 | 343 | die(); | ||
878 | 344 | } | ||
879 | 345 | |||
880 | 346 | void update_table() { | ||
881 | 347 | table_.clear(); | ||
882 | 348 | for (const auto& pair : economy_options_->get_predefined_targets()) { | ||
883 | 349 | table_.add(pair.first).set_string(0, _(pair.first)); | ||
884 | 350 | } | ||
885 | 351 | layout(); | ||
886 | 352 | } | ||
887 | 353 | |||
888 | 354 | void save() { | ||
889 | 355 | const std::string name = profile_name_.text(); | ||
890 | 356 | assert(!name.empty()); | ||
891 | 357 | assert(name != kDefaultEconomyProfile); | ||
892 | 358 | for (const auto& pair : economy_options_->get_predefined_targets()) { | ||
893 | 359 | if (pair.first == name) { | ||
894 | 360 | UI::WLMessageBox m(this, _("Overwrite?"), | ||
895 | 361 | _("A profile with this name already exists.\nDo you wish to replace it?"), | ||
896 | 362 | UI::WLMessageBox::MBoxType::kOkCancel); | ||
897 | 363 | if (m.run<UI::Panel::Returncodes>() != UI::Panel::Returncodes::kOk) { | ||
898 | 364 | return; | ||
899 | 365 | } | ||
900 | 366 | break; | ||
901 | 367 | } | ||
902 | 368 | } | ||
903 | 369 | economy_options_->do_create_target(name); | ||
904 | 370 | close(true); | ||
905 | 371 | } | ||
906 | 372 | |||
907 | 373 | void delete_selected() { | ||
908 | 374 | assert(table_.has_selection()); | ||
909 | 375 | auto& map = economy_options_->get_predefined_targets(); | ||
910 | 376 | const std::string& name = table_[table_.selection_index()]; | ||
911 | 377 | assert(name != kDefaultEconomyProfile); | ||
912 | 378 | for (auto it = map.begin(); it != map.end(); ++it) { | ||
913 | 379 | if (it->first == name) { | ||
914 | 380 | map.erase(it); | ||
915 | 381 | break; | ||
916 | 382 | } | ||
917 | 383 | } | ||
918 | 384 | economy_options_->save_targets(); | ||
919 | 385 | update_table(); | ||
920 | 386 | } | ||
921 | 387 | |||
922 | 388 | explicit SaveProfileWindow(UI::Panel* parent, EconomyOptionsWindow* eco) | ||
923 | 389 | : UI::Window(parent, "save_economy_options_profile", 0, 0, 0, 0, _("Save Profile")), | ||
924 | 390 | economy_options_(eco), | ||
925 | 391 | main_box_(this, 0, 0, UI::Box::Vertical), | ||
926 | 392 | table_box_(&main_box_, 0, 0, UI::Box::Vertical), | ||
927 | 393 | table_(&table_box_, 0, 0, 460, 120, UI::PanelStyle::kWui), | ||
928 | 394 | buttons_box_(&main_box_, 0, 0, UI::Box::Horizontal), | ||
929 | 395 | profile_name_(&buttons_box_, 0, 0, 240, 0, 0, UI::PanelStyle::kWui), | ||
930 | 396 | save_(&buttons_box_, "save", 0, 0, 80, 34, UI::ButtonStyle::kWuiPrimary, _("Save")), | ||
931 | 397 | cancel_(&buttons_box_, "cancel", 0, 0, 80, 34, UI::ButtonStyle::kWuiSecondary, _("Cancel")), | ||
932 | 398 | delete_(&buttons_box_, "delete", 0, 0, 80, 34, UI::ButtonStyle::kWuiSecondary, _("Delete")) { | ||
933 | 399 | table_.add_column(200, _("Existing Profiles")); | ||
934 | 400 | update_table(); | ||
935 | 401 | |||
936 | 402 | table_.selected.connect([this](uint32_t) { table_selection_changed(); }); | ||
937 | 403 | profile_name_.changed.connect([this] { update_save_enabled(); }); | ||
938 | 404 | profile_name_.ok.connect([this] { save(); }); | ||
939 | 405 | profile_name_.cancel.connect([this] { close(false); }); | ||
940 | 406 | save_.sigclicked.connect([this] { save(); }); | ||
941 | 407 | cancel_.sigclicked.connect([this] { close(false); }); | ||
942 | 408 | delete_.sigclicked.connect([this] { delete_selected(); }); | ||
943 | 409 | |||
944 | 410 | table_box_.add(&table_, UI::Box::Resizing::kFullSize); | ||
945 | 411 | buttons_box_.add(&profile_name_, UI::Box::Resizing::kFullSize); | ||
946 | 412 | buttons_box_.add(&save_); | ||
947 | 413 | buttons_box_.add(&cancel_); | ||
948 | 414 | buttons_box_.add(&delete_); | ||
949 | 415 | main_box_.add(&table_box_, UI::Box::Resizing::kFullSize); | ||
950 | 416 | main_box_.add(&buttons_box_, UI::Box::Resizing::kFullSize); | ||
951 | 417 | set_center_panel(&main_box_); | ||
952 | 418 | |||
953 | 419 | table_selection_changed(); | ||
954 | 420 | update_save_enabled(); | ||
955 | 421 | } | ||
956 | 422 | ~SaveProfileWindow() { | ||
957 | 423 | } | ||
958 | 424 | |||
959 | 425 | private: | ||
960 | 426 | EconomyOptionsWindow* economy_options_; | ||
961 | 427 | UI::Box main_box_; | ||
962 | 428 | UI::Box table_box_; | ||
963 | 429 | UI::Table<const std::string&> table_; | ||
964 | 430 | UI::Box buttons_box_; | ||
965 | 431 | UI::EditBox profile_name_; | ||
966 | 432 | UI::Button save_; | ||
967 | 433 | UI::Button cancel_; | ||
968 | 434 | UI::Button delete_; | ||
969 | 435 | }; | ||
970 | 436 | |||
971 | 437 | void EconomyOptionsWindow::create_target() { | ||
972 | 438 | std::unique_ptr<SaveProfileWindow> s (new SaveProfileWindow(get_parent(), this)); | ||
973 | 439 | s->run<UI::Panel::Returncodes>(); | ||
974 | 440 | } | ||
975 | 441 | |||
976 | 442 | void EconomyOptionsWindow::do_create_target(const std::string& name) { | ||
977 | 443 | assert(!name.empty()); | ||
978 | 444 | assert(name != kDefaultEconomyProfile); | ||
979 | 445 | const Widelands::Tribes& tribes = player_->egbase().tribes(); | ||
980 | 446 | const Widelands::TribeDescr& tribe = player_->tribe(); | ||
981 | 447 | Widelands::Economy* economy = player_->get_economy(serial_); | ||
982 | 448 | PredefinedTargets t; | ||
983 | 449 | for (Widelands::DescriptionIndex di : tribe.wares()) { | ||
984 | 450 | if (tribes.get_ware_descr(di)->has_demand_check(tribe.name())) { | ||
985 | 451 | t.wares[di] = economy->ware_target_quantity(di).permanent; | ||
986 | 452 | } | ||
987 | 453 | } | ||
988 | 454 | for (Widelands::DescriptionIndex di : tribe.workers()) { | ||
989 | 455 | if (tribes.get_worker_descr(di)->has_demand_check()) { | ||
990 | 456 | t.workers[di] = economy->worker_target_quantity(di).permanent; | ||
991 | 457 | } | ||
992 | 458 | } | ||
993 | 459 | predefined_targets_[name] = t; | ||
994 | 460 | |||
995 | 461 | save_targets(); | ||
996 | 462 | update_profiles(name); | ||
997 | 463 | } | ||
998 | 464 | |||
999 | 465 | void EconomyOptionsWindow::save_targets() { | ||
1000 | 466 | const Widelands::Tribes& tribes = player_->egbase().tribes(); | ||
1001 | 467 | Profile profile; | ||
1002 | 468 | |||
1003 | 469 | std::map<std::string, uint32_t> serials; | ||
1004 | 470 | for (const auto& pair : predefined_targets_) { | ||
1005 | 471 | if (pair.first != kDefaultEconomyProfile) { | ||
1006 | 472 | serials.emplace(pair.first, serials.size()); | ||
1007 | 473 | } | ||
1008 | 474 | } | ||
1009 | 475 | Section& global_section = profile.create_section(kDefaultEconomyProfile.c_str()); | ||
1010 | 476 | for (const auto& pair : serials) { | ||
1011 | 477 | global_section.set_string(std::to_string(pair.second).c_str(), pair.first); | ||
1012 | 478 | } | ||
1013 | 479 | |||
1014 | 480 | for (const auto& pair : predefined_targets_) { | ||
1015 | 481 | if (pair.first == kDefaultEconomyProfile) { | ||
1016 | 482 | continue; | ||
1017 | 483 | } | ||
1018 | 484 | Section& section = profile.create_section(std::to_string(serials.at(pair.first)).c_str()); | ||
1019 | 485 | for (const auto& setting : pair.second.wares) { | ||
1020 | 486 | section.set_natural(tribes.get_ware_descr(setting.first)->name().c_str(), setting.second); | ||
1021 | 487 | } | ||
1022 | 488 | for (const auto& setting : pair.second.workers) { | ||
1023 | 489 | section.set_natural(tribes.get_worker_descr(setting.first)->name().c_str(), setting.second); | ||
1024 | 490 | } | ||
1025 | 491 | } | ||
1026 | 492 | |||
1027 | 493 | g_fs->ensure_directory_exists(kEconomyProfilesDir); | ||
1028 | 494 | std::string complete_filename = kEconomyProfilesDir + g_fs->file_separator() + player_->tribe().name(); | ||
1029 | 495 | profile.write(complete_filename.c_str(), false); | ||
1030 | 496 | } | ||
1031 | 497 | |||
1032 | 498 | void EconomyOptionsWindow::read_targets(const std::string& select) { | ||
1033 | 499 | predefined_targets_.clear(); | ||
1034 | 500 | const Widelands::Tribes& tribes = player_->egbase().tribes(); | ||
1035 | 501 | const Widelands::TribeDescr& tribe = player_->tribe(); | ||
1036 | 502 | |||
1037 | 503 | { | ||
1038 | 504 | PredefinedTargets t; | ||
1039 | 505 | for (Widelands::DescriptionIndex di : tribe.wares()) { | ||
1040 | 506 | const Widelands::WareDescr* descr = tribes.get_ware_descr(di); | ||
1041 | 507 | if (descr->has_demand_check(tribe.name())) { | ||
1042 | 508 | t.wares.emplace(di, descr->default_target_quantity(tribe.name())); | ||
1043 | 509 | } | ||
1044 | 510 | } | ||
1045 | 511 | for (Widelands::DescriptionIndex di : tribe.workers()) { | ||
1046 | 512 | const Widelands::WorkerDescr* descr = tribes.get_worker_descr(di); | ||
1047 | 513 | if (descr->has_demand_check()) { | ||
1048 | 514 | t.workers.emplace(di, descr->default_target_quantity()); | ||
1049 | 515 | } | ||
1050 | 516 | } | ||
1051 | 517 | predefined_targets_.emplace(kDefaultEconomyProfile, t); | ||
1052 | 518 | } | ||
1053 | 519 | |||
1054 | 520 | std::string complete_filename = kEconomyProfilesDir + g_fs->file_separator() + player_->tribe().name(); | ||
1055 | 521 | Profile profile; | ||
1056 | 522 | profile.read(complete_filename.c_str()); | ||
1057 | 523 | |||
1058 | 524 | Section* global_section = profile.get_section(kDefaultEconomyProfile); | ||
1059 | 525 | if (global_section) { | ||
1060 | 526 | std::map<std::string, std::string> serials; | ||
1061 | 527 | while (Section::Value* v = global_section->get_next_val()) { | ||
1062 | 528 | serials.emplace(std::string(v->get_name()), v->get_string()); | ||
1063 | 529 | } | ||
1064 | 530 | |||
1065 | 531 | for (const auto& pair : serials) { | ||
1066 | 532 | Section* section = profile.get_section(pair.first); | ||
1067 | 533 | PredefinedTargets t; | ||
1068 | 534 | while (Section::Value* v = section->get_next_val()) { | ||
1069 | 535 | const std::string name = std::string(v->get_name()); | ||
1070 | 536 | Widelands::DescriptionIndex di = tribes.ware_index(name); | ||
1071 | 537 | if (di == Widelands::INVALID_INDEX) { | ||
1072 | 538 | di = tribes.worker_index(name); | ||
1073 | 539 | assert(di != Widelands::INVALID_INDEX); | ||
1074 | 540 | t.workers.emplace(di, v->get_natural()); | ||
1075 | 195 | } else { | 541 | } else { |
1079 | 196 | game.send_player_command(*new Widelands::CmdSetWorkerTargetQuantity( | 542 | t.wares.emplace(di, v->get_natural()); |
1077 | 197 | game.get_gametime(), player_->player_number(), serial_, index, | ||
1078 | 198 | tq.permanent + amount)); | ||
1080 | 199 | } | 543 | } |
1081 | 200 | } | 544 | } |
1082 | 545 | predefined_targets_.emplace(pair.second, t); | ||
1083 | 201 | } | 546 | } |
1084 | 202 | } | 547 | } |
1085 | 203 | } | ||
1086 | 204 | 548 | ||
1102 | 205 | void EconomyOptionsWindow::EconomyOptionsPanel::reset_target() { | 549 | update_profiles(select); |
1088 | 206 | Widelands::Game& game = dynamic_cast<Widelands::Game&>(player_->egbase()); | ||
1089 | 207 | const bool is_wares = type_ == Widelands::wwWARE; | ||
1090 | 208 | const auto& items = is_wares ? player_->tribe().wares() : player_->tribe().workers(); | ||
1091 | 209 | for (const Widelands::DescriptionIndex& index : items) { | ||
1092 | 210 | if (display_.ware_selected(index)) { | ||
1093 | 211 | if (is_wares) { | ||
1094 | 212 | game.send_player_command(*new Widelands::CmdResetWareTargetQuantity( | ||
1095 | 213 | game.get_gametime(), player_->player_number(), serial_, index)); | ||
1096 | 214 | } else { | ||
1097 | 215 | game.send_player_command(*new Widelands::CmdResetWorkerTargetQuantity( | ||
1098 | 216 | game.get_gametime(), player_->player_number(), serial_, index)); | ||
1099 | 217 | } | ||
1100 | 218 | } | ||
1101 | 219 | } | ||
1103 | 220 | } | 550 | } |
1104 | 221 | 551 | ||
1105 | === modified file 'src/wui/economy_options_window.h' | |||
1106 | --- src/wui/economy_options_window.h 2019-02-23 11:00:49 +0000 | |||
1107 | +++ src/wui/economy_options_window.h 2019-05-06 13:51:46 +0000 | |||
1108 | @@ -20,20 +20,48 @@ | |||
1109 | 20 | #ifndef WL_WUI_ECONOMY_OPTIONS_WINDOW_H | 20 | #ifndef WL_WUI_ECONOMY_OPTIONS_WINDOW_H |
1110 | 21 | #define WL_WUI_ECONOMY_OPTIONS_WINDOW_H | 21 | #define WL_WUI_ECONOMY_OPTIONS_WINDOW_H |
1111 | 22 | 22 | ||
1112 | 23 | #include <map> | ||
1113 | 23 | #include <memory> | 24 | #include <memory> |
1114 | 25 | #include <string> | ||
1115 | 24 | 26 | ||
1116 | 25 | #include "economy/economy.h" | 27 | #include "economy/economy.h" |
1117 | 26 | #include "logic/map_objects/tribes/tribe_descr.h" | 28 | #include "logic/map_objects/tribes/tribe_descr.h" |
1118 | 27 | #include "notifications/notifications.h" | 29 | #include "notifications/notifications.h" |
1119 | 28 | #include "ui_basic/box.h" | 30 | #include "ui_basic/box.h" |
1120 | 31 | #include "ui_basic/dropdown.h" | ||
1121 | 29 | #include "ui_basic/tabpanel.h" | 32 | #include "ui_basic/tabpanel.h" |
1122 | 30 | #include "ui_basic/window.h" | 33 | #include "ui_basic/window.h" |
1123 | 31 | #include "wui/waresdisplay.h" | 34 | #include "wui/waresdisplay.h" |
1124 | 32 | 35 | ||
1125 | 36 | const std::string kDefaultEconomyProfile = "Default"; | ||
1126 | 37 | |||
1127 | 33 | struct EconomyOptionsWindow : public UI::Window { | 38 | struct EconomyOptionsWindow : public UI::Window { |
1128 | 34 | EconomyOptionsWindow(UI::Panel* parent, Widelands::Economy* economy, bool can_act); | 39 | EconomyOptionsWindow(UI::Panel* parent, Widelands::Economy* economy, bool can_act); |
1129 | 35 | ~EconomyOptionsWindow(); | 40 | ~EconomyOptionsWindow(); |
1130 | 36 | 41 | ||
1131 | 42 | struct PredefinedTargets { | ||
1132 | 43 | using Targets = std::map<Widelands::DescriptionIndex, uint32_t>; | ||
1133 | 44 | Targets wares; | ||
1134 | 45 | Targets workers; | ||
1135 | 46 | }; | ||
1136 | 47 | |||
1137 | 48 | void create_target(); | ||
1138 | 49 | void do_create_target(const std::string&); | ||
1139 | 50 | void save_targets(); | ||
1140 | 51 | void read_targets(const std::string& = kDefaultEconomyProfile); | ||
1141 | 52 | void update_profiles(const std::string&); | ||
1142 | 53 | std::map<std::string, PredefinedTargets>& get_predefined_targets() { | ||
1143 | 54 | return predefined_targets_; | ||
1144 | 55 | } | ||
1145 | 56 | const PredefinedTargets& get_selected_target() const { | ||
1146 | 57 | return predefined_targets_.at(dropdown_.get_selected()); | ||
1147 | 58 | } | ||
1148 | 59 | |||
1149 | 60 | void change_target(int amount); | ||
1150 | 61 | void reset_target(); | ||
1151 | 62 | |||
1152 | 63 | void layout() override; | ||
1153 | 64 | |||
1154 | 37 | private: | 65 | private: |
1155 | 38 | struct TargetWaresDisplay : public AbstractWaresDisplay { | 66 | struct TargetWaresDisplay : public AbstractWaresDisplay { |
1156 | 39 | TargetWaresDisplay(UI::Panel* const parent, | 67 | TargetWaresDisplay(UI::Panel* const parent, |
1157 | @@ -59,14 +87,17 @@ | |||
1158 | 59 | */ | 87 | */ |
1159 | 60 | struct EconomyOptionsPanel : UI::Box { | 88 | struct EconomyOptionsPanel : UI::Box { |
1160 | 61 | EconomyOptionsPanel(UI::Panel* parent, | 89 | EconomyOptionsPanel(UI::Panel* parent, |
1161 | 90 | EconomyOptionsWindow* eco_window, | ||
1162 | 62 | Widelands::Serial serial, | 91 | Widelands::Serial serial, |
1163 | 63 | Widelands::Player* player, | 92 | Widelands::Player* player, |
1164 | 64 | bool can_act, | 93 | bool can_act, |
1166 | 65 | Widelands::WareWorker type); | 94 | Widelands::WareWorker type, |
1167 | 95 | int32_t min_w); | ||
1168 | 66 | 96 | ||
1169 | 67 | void set_economy(Widelands::Serial serial); | 97 | void set_economy(Widelands::Serial serial); |
1170 | 68 | void change_target(int amount); | 98 | void change_target(int amount); |
1171 | 69 | void reset_target(); | 99 | void reset_target(); |
1172 | 100 | void update_desired_size() override; | ||
1173 | 70 | 101 | ||
1174 | 71 | private: | 102 | private: |
1175 | 72 | Widelands::Serial serial_; | 103 | Widelands::Serial serial_; |
1176 | @@ -74,17 +105,23 @@ | |||
1177 | 74 | Widelands::WareWorker type_; | 105 | Widelands::WareWorker type_; |
1178 | 75 | bool can_act_; | 106 | bool can_act_; |
1179 | 76 | TargetWaresDisplay display_; | 107 | TargetWaresDisplay display_; |
1180 | 108 | EconomyOptionsWindow* economy_options_window_; | ||
1181 | 77 | }; | 109 | }; |
1182 | 78 | 110 | ||
1183 | 79 | /// Actions performed when a NoteEconomyWindow is received. | 111 | /// Actions performed when a NoteEconomyWindow is received. |
1184 | 80 | void on_economy_note(const Widelands::NoteEconomy& note); | 112 | void on_economy_note(const Widelands::NoteEconomy& note); |
1185 | 81 | 113 | ||
1186 | 114 | UI::Box main_box_; | ||
1187 | 82 | Widelands::Serial serial_; | 115 | Widelands::Serial serial_; |
1188 | 83 | Widelands::Player* player_; | 116 | Widelands::Player* player_; |
1189 | 84 | UI::TabPanel tabpanel_; | 117 | UI::TabPanel tabpanel_; |
1190 | 85 | EconomyOptionsPanel* ware_panel_; | 118 | EconomyOptionsPanel* ware_panel_; |
1191 | 86 | EconomyOptionsPanel* worker_panel_; | 119 | EconomyOptionsPanel* worker_panel_; |
1192 | 87 | std::unique_ptr<Notifications::Subscriber<Widelands::NoteEconomy>> economynotes_subscriber_; | 120 | std::unique_ptr<Notifications::Subscriber<Widelands::NoteEconomy>> economynotes_subscriber_; |
1193 | 121 | |||
1194 | 122 | std::map<std::string, PredefinedTargets> predefined_targets_; | ||
1195 | 123 | UI::Box dropdown_box_; | ||
1196 | 124 | UI::Dropdown<std::string> dropdown_; | ||
1197 | 88 | }; | 125 | }; |
1198 | 89 | 126 | ||
1199 | 90 | #endif // end of include guard: WL_WUI_ECONOMY_OPTIONS_WINDOW_H | 127 | #endif // end of include guard: WL_WUI_ECONOMY_OPTIONS_WINDOW_H |
1200 | 91 | 128 | ||
1201 | === modified file 'src/wui/inputqueuedisplay.cc' | |||
1202 | --- src/wui/inputqueuedisplay.cc 2019-04-25 06:40:24 +0000 | |||
1203 | +++ src/wui/inputqueuedisplay.cc 2019-05-06 13:51:46 +0000 | |||
1204 | @@ -71,7 +71,7 @@ | |||
1205 | 71 | 71 | ||
1206 | 72 | uint32_t priority_button_height = show_only ? 0 : 3 * PriorityButtonSize; | 72 | uint32_t priority_button_height = show_only ? 0 : 3 * PriorityButtonSize; |
1207 | 73 | uint32_t image_height = | 73 | uint32_t image_height = |
1209 | 74 | show_only ? WARE_MENU_PIC_HEIGHT : std::max<int32_t>(WARE_MENU_PIC_HEIGHT, ph); | 74 | show_only ? kWareMenuPicHeight : std::max<int32_t>(kWareMenuPicHeight, ph); |
1210 | 75 | 75 | ||
1211 | 76 | total_height_ = std::max(priority_button_height, image_height) + 2 * Border; | 76 | total_height_ = std::max(priority_button_height, image_height) + 2 * Border; |
1212 | 77 | 77 | ||
1213 | @@ -91,7 +91,7 @@ | |||
1214 | 91 | */ | 91 | */ |
1215 | 92 | void InputQueueDisplay::max_size_changed() { | 92 | void InputQueueDisplay::max_size_changed() { |
1216 | 93 | uint32_t pbs = show_only_ ? 0 : PriorityButtonSize; | 93 | uint32_t pbs = show_only_ ? 0 : PriorityButtonSize; |
1218 | 94 | uint32_t ctrl_b_size = show_only_ ? 0 : 2 * WARE_MENU_PIC_WIDTH; | 94 | uint32_t ctrl_b_size = show_only_ ? 0 : 2 * kWareMenuPicWidth; |
1219 | 95 | 95 | ||
1220 | 96 | cache_size_ = queue_.get_max_size(); | 96 | cache_size_ = queue_.get_max_size(); |
1221 | 97 | 97 | ||
1222 | @@ -140,7 +140,7 @@ | |||
1223 | 140 | 140 | ||
1224 | 141 | Vector2i point = Vector2i::zero(); | 141 | Vector2i point = Vector2i::zero(); |
1225 | 142 | point.x = Border + (show_only_ ? 0 : CellWidth + CellSpacing); | 142 | point.x = Border + (show_only_ ? 0 : CellWidth + CellSpacing); |
1227 | 143 | point.y = Border + (total_height_ - 2 * Border - WARE_MENU_PIC_HEIGHT) / 2; | 143 | point.y = Border + (total_height_ - 2 * Border - kWareMenuPicHeight) / 2; |
1228 | 144 | 144 | ||
1229 | 145 | for (; nr_inputs_to_draw; --nr_inputs_to_draw, point.x += CellWidth + CellSpacing) { | 145 | for (; nr_inputs_to_draw; --nr_inputs_to_draw, point.x += CellWidth + CellSpacing) { |
1230 | 146 | dst.blitrect(Vector2i(point.x, point.y), icon_, Recti(0, 0, icon_->width(), icon_->height()), | 146 | dst.blitrect(Vector2i(point.x, point.y), icon_, Recti(0, 0, icon_->width(), icon_->height()), |
1231 | @@ -240,12 +240,12 @@ | |||
1232 | 240 | return; | 240 | return; |
1233 | 241 | 241 | ||
1234 | 242 | uint32_t x = Border; | 242 | uint32_t x = Border; |
1236 | 243 | uint32_t y = Border + (total_height_ - 2 * Border - WARE_MENU_PIC_WIDTH) / 2; | 243 | uint32_t y = Border + (total_height_ - 2 * Border - kWareMenuPicWidth) / 2; |
1237 | 244 | 244 | ||
1238 | 245 | boost::format tooltip_format("%s<br><p><font size=%d bold=0>%s<br>%s</font></p>"); | 245 | boost::format tooltip_format("%s<br><p><font size=%d bold=0>%s<br>%s</font></p>"); |
1239 | 246 | 246 | ||
1240 | 247 | decrease_max_fill_ = new UI::Button( | 247 | decrease_max_fill_ = new UI::Button( |
1242 | 248 | this, "decrease_max_fill", x, y, WARE_MENU_PIC_WIDTH, WARE_MENU_PIC_HEIGHT, | 248 | this, "decrease_max_fill", x, y, kWareMenuPicWidth, kWareMenuPicHeight, |
1243 | 249 | UI::ButtonStyle::kWuiMenu, g_gr->images().get("images/ui_basic/scrollbar_left.png"), | 249 | UI::ButtonStyle::kWuiMenu, g_gr->images().get("images/ui_basic/scrollbar_left.png"), |
1244 | 250 | (tooltip_format | 250 | (tooltip_format |
1245 | 251 | /** TRANSLATORS: Button tooltip in in a building's wares input queue */ | 251 | /** TRANSLATORS: Button tooltip in in a building's wares input queue */ |
1246 | @@ -262,7 +262,7 @@ | |||
1247 | 262 | x = Border + (cache_size_ + 1) * (CellWidth + CellSpacing); | 262 | x = Border + (cache_size_ + 1) * (CellWidth + CellSpacing); |
1248 | 263 | 263 | ||
1249 | 264 | increase_max_fill_ = new UI::Button( | 264 | increase_max_fill_ = new UI::Button( |
1251 | 265 | this, "increase_max_fill", x, y, WARE_MENU_PIC_WIDTH, WARE_MENU_PIC_HEIGHT, | 265 | this, "increase_max_fill", x, y, kWareMenuPicWidth, kWareMenuPicHeight, |
1252 | 266 | UI::ButtonStyle::kWuiMenu, g_gr->images().get("images/ui_basic/scrollbar_right.png"), | 266 | UI::ButtonStyle::kWuiMenu, g_gr->images().get("images/ui_basic/scrollbar_right.png"), |
1253 | 267 | (tooltip_format | 267 | (tooltip_format |
1254 | 268 | /** TRANSLATORS: Button tooltip in a building's wares input queue */ | 268 | /** TRANSLATORS: Button tooltip in a building's wares input queue */ |
1255 | 269 | 269 | ||
1256 | === modified file 'src/wui/inputqueuedisplay.h' | |||
1257 | --- src/wui/inputqueuedisplay.h 2019-04-23 14:53:35 +0000 | |||
1258 | +++ src/wui/inputqueuedisplay.h 2019-05-06 13:51:46 +0000 | |||
1259 | @@ -49,7 +49,7 @@ | |||
1260 | 49 | */ | 49 | */ |
1261 | 50 | class InputQueueDisplay : public UI::Panel { | 50 | class InputQueueDisplay : public UI::Panel { |
1262 | 51 | public: | 51 | public: |
1264 | 52 | enum { CellWidth = WARE_MENU_PIC_WIDTH, CellSpacing = 2, Border = 4, PriorityButtonSize = 10 }; | 52 | enum { CellWidth = kWareMenuPicWidth, CellSpacing = 2, Border = 4, PriorityButtonSize = 10 }; |
1265 | 53 | 53 | ||
1266 | 54 | InputQueueDisplay(UI::Panel* parent, | 54 | InputQueueDisplay(UI::Panel* parent, |
1267 | 55 | int32_t x, | 55 | int32_t x, |
1268 | 56 | 56 | ||
1269 | === modified file 'src/wui/waresdisplay.cc' | |||
1270 | --- src/wui/waresdisplay.cc 2019-02-23 11:00:49 +0000 | |||
1271 | +++ src/wui/waresdisplay.cc 2019-05-06 13:51:46 +0000 | |||
1272 | @@ -35,8 +35,9 @@ | |||
1273 | 35 | #include "logic/map_objects/tribes/ware_descr.h" | 35 | #include "logic/map_objects/tribes/ware_descr.h" |
1274 | 36 | #include "logic/map_objects/tribes/worker.h" | 36 | #include "logic/map_objects/tribes/worker.h" |
1275 | 37 | #include "logic/player.h" | 37 | #include "logic/player.h" |
1276 | 38 | #include "ui_basic/window.h" | ||
1277 | 38 | 39 | ||
1279 | 39 | const int WARE_MENU_INFO_SIZE = 12; | 40 | constexpr int kWareMenuInfoSize = 12; |
1280 | 40 | 41 | ||
1281 | 41 | AbstractWaresDisplay::AbstractWaresDisplay( | 42 | AbstractWaresDisplay::AbstractWaresDisplay( |
1282 | 42 | UI::Panel* const parent, | 43 | UI::Panel* const parent, |
1283 | @@ -46,7 +47,9 @@ | |||
1284 | 46 | Widelands::WareWorker type, | 47 | Widelands::WareWorker type, |
1285 | 47 | bool selectable, | 48 | bool selectable, |
1286 | 48 | boost::function<void(Widelands::DescriptionIndex, bool)> callback_function, | 49 | boost::function<void(Widelands::DescriptionIndex, bool)> callback_function, |
1288 | 49 | bool horizontal) | 50 | bool horizontal, |
1289 | 51 | int32_t hgap, | ||
1290 | 52 | int32_t vgap) | ||
1291 | 50 | : // Size is set when add_warelist is called, as it depends on the type_. | 53 | : // Size is set when add_warelist is called, as it depends on the type_. |
1292 | 51 | UI::Panel(parent, x, y, 0, 0), | 54 | UI::Panel(parent, x, y, 0, 0), |
1293 | 52 | tribe_(tribe), | 55 | tribe_(tribe), |
1294 | @@ -57,6 +60,8 @@ | |||
1295 | 57 | 60 | ||
1296 | 58 | selectable_(selectable), | 61 | selectable_(selectable), |
1297 | 59 | horizontal_(horizontal), | 62 | horizontal_(horizontal), |
1298 | 63 | hgap_(hgap), | ||
1299 | 64 | vgap_(vgap), | ||
1300 | 60 | selection_anchor_(Widelands::INVALID_INDEX), | 65 | selection_anchor_(Widelands::INVALID_INDEX), |
1301 | 61 | callback_function_(callback_function) { | 66 | callback_function_(callback_function) { |
1302 | 62 | for (const Widelands::DescriptionIndex& index : indices_) { | 67 | for (const Widelands::DescriptionIndex& index : indices_) { |
1303 | @@ -67,22 +72,65 @@ | |||
1304 | 67 | 72 | ||
1305 | 68 | curware_.set_text(_("Stock")); | 73 | curware_.set_text(_("Stock")); |
1306 | 69 | 74 | ||
1313 | 70 | // Find out geometry from icons_order | 75 | graphic_resolution_changed_subscriber_ = Notifications::subscribe<GraphicResolutionChanged>( |
1314 | 71 | unsigned int columns = icons_order().size(); | 76 | [this](const GraphicResolutionChanged&) { |
1315 | 72 | unsigned int rows = 0; | 77 | recalc_desired_size(true); |
1316 | 73 | for (unsigned int i = 0; i < icons_order().size(); i++) | 78 | }); |
1317 | 74 | if (icons_order()[i].size() > rows) | 79 | |
1318 | 75 | rows = icons_order()[i].size(); | 80 | recalc_desired_size(false); |
1319 | 81 | } | ||
1320 | 82 | |||
1321 | 83 | Widelands::Extent AbstractWaresDisplay::get_extent() const { | ||
1322 | 84 | int16_t columns = 0; | ||
1323 | 85 | int16_t rows = 0; | ||
1324 | 86 | for (const auto& pair : icons_order_coords()) { | ||
1325 | 87 | columns = std::max(columns, pair.second.x); | ||
1326 | 88 | rows = std::max(rows, pair.second.y); | ||
1327 | 89 | } | ||
1328 | 90 | // We cound from 0 up | ||
1329 | 91 | ++columns; | ||
1330 | 92 | ++rows; | ||
1331 | 93 | |||
1332 | 76 | if (horizontal_) { | 94 | if (horizontal_) { |
1334 | 77 | unsigned int s = columns; | 95 | const int16_t s = columns; |
1335 | 78 | columns = rows; | 96 | columns = rows; |
1336 | 79 | rows = s; | 97 | rows = s; |
1337 | 80 | } | 98 | } |
1338 | 99 | return Widelands::Extent(columns, rows); | ||
1339 | 100 | } | ||
1340 | 101 | |||
1341 | 102 | void AbstractWaresDisplay::set_hgap(int32_t gap) { | ||
1342 | 103 | hgap_ = gap; | ||
1343 | 104 | recalc_desired_size(true); | ||
1344 | 105 | } | ||
1345 | 106 | |||
1346 | 107 | void AbstractWaresDisplay::set_vgap(int32_t gap) { | ||
1347 | 108 | vgap_ = gap; | ||
1348 | 109 | recalc_desired_size(true); | ||
1349 | 110 | } | ||
1350 | 111 | |||
1351 | 112 | void AbstractWaresDisplay::recalc_desired_size(bool relayout) { | ||
1352 | 113 | relayout_icons_order_coords(); | ||
1353 | 114 | |||
1354 | 115 | // Find out geometry from icons_order | ||
1355 | 116 | const Widelands::Extent size = get_extent(); | ||
1356 | 81 | 117 | ||
1357 | 82 | // 25 is height of curware_ text | 118 | // 25 is height of curware_ text |
1358 | 83 | set_desired_size( | 119 | set_desired_size( |
1361 | 84 | columns * (WARE_MENU_PIC_WIDTH + WARE_MENU_PIC_PAD_X) + 1, | 120 | size.w * (kWareMenuPicWidth + hgap_) + 1, |
1362 | 85 | rows * (WARE_MENU_PIC_HEIGHT + WARE_MENU_INFO_SIZE + WARE_MENU_PIC_PAD_Y) + 1 + 25); | 121 | size.h * (kWareMenuPicHeight + kWareMenuInfoSize + vgap_) + 1 + 25); |
1363 | 122 | |||
1364 | 123 | if (relayout) { | ||
1365 | 124 | // Since we are usually stacked deep within other panels, we need to tell our highest parent window to relayout | ||
1366 | 125 | UI::Panel* p = this; | ||
1367 | 126 | while (p->get_parent()) { | ||
1368 | 127 | p = p->get_parent(); | ||
1369 | 128 | if (dynamic_cast<UI::Window*>(p)) { | ||
1370 | 129 | p->layout(); | ||
1371 | 130 | return; | ||
1372 | 131 | } | ||
1373 | 132 | } | ||
1374 | 133 | } | ||
1375 | 86 | } | 134 | } |
1376 | 87 | 135 | ||
1377 | 88 | bool AbstractWaresDisplay::handle_mousemove(uint8_t state, int32_t x, int32_t y, int32_t, int32_t) { | 136 | bool AbstractWaresDisplay::handle_mousemove(uint8_t state, int32_t x, int32_t y, int32_t, int32_t) { |
1378 | @@ -162,21 +210,33 @@ | |||
1379 | 162 | * DescriptionIndex::null() if the given point is outside the range. | 210 | * DescriptionIndex::null() if the given point is outside the range. |
1380 | 163 | */ | 211 | */ |
1381 | 164 | Widelands::DescriptionIndex AbstractWaresDisplay::ware_at_point(int32_t x, int32_t y) const { | 212 | Widelands::DescriptionIndex AbstractWaresDisplay::ware_at_point(int32_t x, int32_t y) const { |
1387 | 165 | if (x < 0 || y < 0) | 213 | // Graphical offset |
1388 | 166 | return Widelands::INVALID_INDEX; | 214 | x -= 2; |
1389 | 167 | 215 | y -= 2; | |
1390 | 168 | unsigned int i = x / (WARE_MENU_PIC_WIDTH + WARE_MENU_PIC_PAD_X); | 216 | |
1391 | 169 | unsigned int j = y / (WARE_MENU_PIC_HEIGHT + WARE_MENU_INFO_SIZE + WARE_MENU_PIC_PAD_Y); | 217 | if (x < 0 || y < 0) { |
1392 | 218 | return Widelands::INVALID_INDEX; | ||
1393 | 219 | } | ||
1394 | 220 | |||
1395 | 221 | int i = x / (kWareMenuPicWidth + hgap_); | ||
1396 | 222 | int j = y / (kWareMenuPicHeight + kWareMenuInfoSize + vgap_); | ||
1397 | 223 | if (kWareMenuPicWidth * (i + 1) + hgap_ * i < x || | ||
1398 | 224 | (kWareMenuPicHeight + kWareMenuInfoSize) * (j + 1) + vgap_ * j < y) { | ||
1399 | 225 | // Not on the ware, but on the space between | ||
1400 | 226 | return Widelands::INVALID_INDEX; | ||
1401 | 227 | } | ||
1402 | 170 | if (horizontal_) { | 228 | if (horizontal_) { |
1404 | 171 | unsigned int s = i; | 229 | int s = i; |
1405 | 172 | i = j; | 230 | i = j; |
1406 | 173 | j = s; | 231 | j = s; |
1407 | 174 | } | 232 | } |
1413 | 175 | if (i < icons_order().size() && j < icons_order()[i].size()) { | 233 | for (const auto& pair : icons_order_coords()) { |
1414 | 176 | const Widelands::DescriptionIndex& ware = icons_order()[i][j]; | 234 | if (pair.second.x == i && pair.second.y == j) { |
1415 | 177 | assert(hidden_.count(ware) == 1); | 235 | assert(hidden_.count(pair.first) == 1); |
1416 | 178 | if (!(hidden_.find(ware)->second)) { | 236 | if (!(hidden_.find(pair.first)->second)) { |
1417 | 179 | return ware; | 237 | return pair.first; |
1418 | 238 | } | ||
1419 | 239 | break; | ||
1420 | 180 | } | 240 | } |
1421 | 181 | } | 241 | } |
1422 | 182 | 242 | ||
1423 | @@ -199,15 +259,13 @@ | |||
1424 | 199 | Vector2i anchor_pos = ware_position(selection_anchor_); | 259 | Vector2i anchor_pos = ware_position(selection_anchor_); |
1425 | 200 | // Add an offset to make sure the anchor line and column will be | 260 | // Add an offset to make sure the anchor line and column will be |
1426 | 201 | // selected when selecting in topleft direction | 261 | // selected when selecting in topleft direction |
1429 | 202 | int32_t anchor_x = anchor_pos.x + WARE_MENU_PIC_WIDTH / 2; | 262 | int32_t anchor_x = anchor_pos.x + kWareMenuPicWidth / 2; |
1430 | 203 | int32_t anchor_y = anchor_pos.y + WARE_MENU_PIC_HEIGHT / 2; | 263 | int32_t anchor_y = anchor_pos.y + kWareMenuPicHeight / 2; |
1431 | 204 | 264 | ||
1438 | 205 | unsigned int left_ware_idx = anchor_x / (WARE_MENU_PIC_WIDTH + WARE_MENU_PIC_PAD_X); | 265 | unsigned int left_ware_idx = anchor_x / (kWareMenuPicWidth + hgap_); |
1439 | 206 | unsigned int top_ware_idx = | 266 | unsigned int top_ware_idx = anchor_y / (kWareMenuPicHeight + kWareMenuInfoSize + vgap_); |
1440 | 207 | anchor_y / (WARE_MENU_PIC_HEIGHT + WARE_MENU_INFO_SIZE + WARE_MENU_PIC_PAD_Y); | 267 | unsigned int right_ware_idx = x / (kWareMenuPicWidth + hgap_); |
1441 | 208 | unsigned int right_ware_idx = x / (WARE_MENU_PIC_WIDTH + WARE_MENU_PIC_PAD_X); | 268 | unsigned int bottoware_idx_ = y / (kWareMenuPicHeight + kWareMenuInfoSize + vgap_); |
1436 | 209 | unsigned int bottoware_idx_ = | ||
1437 | 210 | y / (WARE_MENU_PIC_HEIGHT + WARE_MENU_INFO_SIZE + WARE_MENU_PIC_PAD_Y); | ||
1442 | 211 | unsigned int tmp; | 269 | unsigned int tmp; |
1443 | 212 | 270 | ||
1444 | 213 | // Reverse col/row and anchor/endpoint if needed | 271 | // Reverse col/row and anchor/endpoint if needed |
1445 | @@ -271,26 +329,43 @@ | |||
1446 | 271 | NEVER_HERE(); | 329 | NEVER_HERE(); |
1447 | 272 | } | 330 | } |
1448 | 273 | 331 | ||
1455 | 274 | const Widelands::TribeDescr::WaresOrderCoords& AbstractWaresDisplay::icons_order_coords() const { | 332 | const WaresOrderCoords& AbstractWaresDisplay::icons_order_coords() const { |
1456 | 275 | switch (type_) { | 333 | assert(!order_coords_.empty()); |
1457 | 276 | case Widelands::wwWARE: | 334 | return order_coords_; |
1458 | 277 | return tribe_.wares_order_coords(); | 335 | } |
1459 | 278 | case Widelands::wwWORKER: | 336 | |
1460 | 279 | return tribe_.workers_order_coords(); | 337 | void AbstractWaresDisplay::relayout_icons_order_coords() { |
1461 | 338 | order_coords_.clear(); | ||
1462 | 339 | const int column_number = icons_order().size(); | ||
1463 | 340 | const int column_max_size = (g_gr->get_yres() - 290) / (kWareMenuPicHeight + vgap_ + kWareMenuInfoSize); | ||
1464 | 341 | |||
1465 | 342 | int16_t column_index_to_apply = 0; | ||
1466 | 343 | for (int16_t column_index = 0; column_index < column_number; ++column_index) { | ||
1467 | 344 | const std::vector<Widelands::DescriptionIndex>& column = icons_order().at(column_index); | ||
1468 | 345 | const int row_number = column.size(); | ||
1469 | 346 | int16_t row_index_to_apply = 0; | ||
1470 | 347 | for (int16_t row_index = 0; row_index < row_number; ++row_index) { | ||
1471 | 348 | order_coords_.emplace(column.at(row_index), Widelands::Coords(column_index_to_apply, row_index_to_apply)); | ||
1472 | 349 | ++row_index_to_apply; | ||
1473 | 350 | if (row_index_to_apply > column_max_size) { | ||
1474 | 351 | row_index_to_apply = 0; | ||
1475 | 352 | ++column_index_to_apply; | ||
1476 | 353 | } | ||
1477 | 354 | } | ||
1478 | 355 | if (row_index_to_apply > 0) { | ||
1479 | 356 | ++column_index_to_apply; | ||
1480 | 357 | } | ||
1481 | 280 | } | 358 | } |
1482 | 281 | NEVER_HERE(); | ||
1483 | 282 | } | 359 | } |
1484 | 283 | 360 | ||
1485 | 284 | Vector2i AbstractWaresDisplay::ware_position(Widelands::DescriptionIndex id) const { | 361 | Vector2i AbstractWaresDisplay::ware_position(Widelands::DescriptionIndex id) const { |
1486 | 285 | Vector2i p(2, 2); | 362 | Vector2i p(2, 2); |
1487 | 286 | if (horizontal_) { | 363 | if (horizontal_) { |
1491 | 287 | p.x += icons_order_coords()[id].second * (WARE_MENU_PIC_WIDTH + WARE_MENU_PIC_PAD_X); | 364 | p.x += icons_order_coords().at(id).y * (kWareMenuPicWidth + hgap_); |
1492 | 288 | p.y += icons_order_coords()[id].first * | 365 | p.y += icons_order_coords().at(id).x * (kWareMenuPicHeight + vgap_ + kWareMenuInfoSize); |
1490 | 289 | (WARE_MENU_PIC_HEIGHT + WARE_MENU_PIC_PAD_Y + WARE_MENU_INFO_SIZE); | ||
1493 | 290 | } else { | 366 | } else { |
1497 | 291 | p.x += icons_order_coords()[id].first * (WARE_MENU_PIC_WIDTH + WARE_MENU_PIC_PAD_X); | 367 | p.x += icons_order_coords().at(id).x * (kWareMenuPicWidth + hgap_); |
1498 | 292 | p.y += icons_order_coords()[id].second * | 368 | p.y += icons_order_coords().at(id).y * (kWareMenuPicHeight + vgap_ + kWareMenuInfoSize); |
1496 | 293 | (WARE_MENU_PIC_HEIGHT + WARE_MENU_PIC_PAD_Y + WARE_MENU_INFO_SIZE); | ||
1499 | 294 | } | 369 | } |
1500 | 295 | return p; | 370 | return p; |
1501 | 296 | } | 371 | } |
1502 | @@ -326,15 +401,15 @@ | |||
1503 | 326 | const Image* icon = type_ == Widelands::wwWORKER ? tribe_.get_worker_descr(id)->icon() : | 401 | const Image* icon = type_ == Widelands::wwWORKER ? tribe_.get_worker_descr(id)->icon() : |
1504 | 327 | tribe_.get_ware_descr(id)->icon(); | 402 | tribe_.get_ware_descr(id)->icon(); |
1505 | 328 | 403 | ||
1507 | 329 | dst.blit(p + Vector2i((w - WARE_MENU_PIC_WIDTH) / 2, 1), icon); | 404 | dst.blit(p + Vector2i((w - kWareMenuPicWidth) / 2, 1), icon); |
1508 | 330 | 405 | ||
1510 | 331 | dst.fill_rect(Recti(p + Vector2i(0, WARE_MENU_PIC_HEIGHT), w, WARE_MENU_INFO_SIZE), | 406 | dst.fill_rect(Recti(p + Vector2i(0, kWareMenuPicHeight), w, kWareMenuInfoSize), |
1511 | 332 | info_color_for_ware(id)); | 407 | info_color_for_ware(id)); |
1512 | 333 | 408 | ||
1513 | 334 | std::shared_ptr<const UI::RenderedText> rendered_text = | 409 | std::shared_ptr<const UI::RenderedText> rendered_text = |
1514 | 335 | UI::g_fh->render(as_waresinfo(info_for_ware(id))); | 410 | UI::g_fh->render(as_waresinfo(info_for_ware(id))); |
1515 | 336 | rendered_text->draw(dst, Vector2i(p.x + w - rendered_text->width() - 1, | 411 | rendered_text->draw(dst, Vector2i(p.x + w - rendered_text->width() - 1, |
1517 | 337 | p.y + WARE_MENU_PIC_HEIGHT + WARE_MENU_INFO_SIZE + 1 - | 412 | p.y + kWareMenuPicHeight + kWareMenuInfoSize + 1 - |
1518 | 338 | rendered_text->height())); | 413 | rendered_text->height())); |
1519 | 339 | } | 414 | } |
1520 | 340 | 415 | ||
1521 | 341 | 416 | ||
1522 | === modified file 'src/wui/waresdisplay.h' | |||
1523 | --- src/wui/waresdisplay.h 2019-02-23 11:00:49 +0000 | |||
1524 | +++ src/wui/waresdisplay.h 2019-05-06 13:51:46 +0000 | |||
1525 | @@ -20,6 +20,7 @@ | |||
1526 | 20 | #ifndef WL_WUI_WARESDISPLAY_H | 20 | #ifndef WL_WUI_WARESDISPLAY_H |
1527 | 21 | #define WL_WUI_WARESDISPLAY_H | 21 | #define WL_WUI_WARESDISPLAY_H |
1528 | 22 | 22 | ||
1529 | 23 | #include <memory> | ||
1530 | 23 | #include <vector> | 24 | #include <vector> |
1531 | 24 | 25 | ||
1532 | 25 | #include "logic/map_objects/tribes/tribe_descr.h" | 26 | #include "logic/map_objects/tribes/tribe_descr.h" |
1533 | @@ -36,6 +37,8 @@ | |||
1534 | 36 | struct WareList; | 37 | struct WareList; |
1535 | 37 | } // namespace Widelands | 38 | } // namespace Widelands |
1536 | 38 | 39 | ||
1537 | 40 | using WaresOrderCoords = std::map<Widelands::DescriptionIndex, Widelands::Coords>; | ||
1538 | 41 | |||
1539 | 39 | /** | 42 | /** |
1540 | 40 | * Display wares or workers together with some string (typically a number) | 43 | * Display wares or workers together with some string (typically a number) |
1541 | 41 | * in the style of the @ref WarehouseWindow. | 44 | * in the style of the @ref WarehouseWindow. |
1542 | @@ -54,7 +57,9 @@ | |||
1543 | 54 | CLANG_DIAG_OFF("-Wunknown-pragmas") CLANG_DIAG_OFF("-Wzero-as-null-pointer-constant") | 57 | CLANG_DIAG_OFF("-Wunknown-pragmas") CLANG_DIAG_OFF("-Wzero-as-null-pointer-constant") |
1544 | 55 | boost::function<void(Widelands::DescriptionIndex, bool)> callback_function = 0, | 58 | boost::function<void(Widelands::DescriptionIndex, bool)> callback_function = 0, |
1545 | 56 | CLANG_DIAG_ON("-Wzero-as-null-pointer-constant") | 59 | CLANG_DIAG_ON("-Wzero-as-null-pointer-constant") |
1547 | 57 | CLANG_DIAG_ON("-Wunknown-pragmas") bool horizontal = false); | 60 | CLANG_DIAG_ON("-Wunknown-pragmas") bool horizontal = false, |
1548 | 61 | int32_t hgap = 3, | ||
1549 | 62 | int32_t vgap = 4); | ||
1550 | 58 | 63 | ||
1551 | 59 | bool | 64 | bool |
1552 | 60 | handle_mousemove(uint8_t state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff) override; | 65 | handle_mousemove(uint8_t state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff) override; |
1553 | @@ -74,6 +79,19 @@ | |||
1554 | 74 | return type_; | 79 | return type_; |
1555 | 75 | } | 80 | } |
1556 | 76 | 81 | ||
1557 | 82 | int32_t get_hgap() { | ||
1558 | 83 | return hgap_; | ||
1559 | 84 | } | ||
1560 | 85 | int32_t get_vgap() { | ||
1561 | 86 | return vgap_; | ||
1562 | 87 | } | ||
1563 | 88 | void set_hgap(int32_t); | ||
1564 | 89 | void set_vgap(int32_t); | ||
1565 | 90 | |||
1566 | 91 | Widelands::Extent get_extent() const; | ||
1567 | 92 | |||
1568 | 93 | const WaresOrderCoords& icons_order_coords() const; | ||
1569 | 94 | |||
1570 | 77 | protected: | 95 | protected: |
1571 | 78 | void layout() override; | 96 | void layout() override; |
1572 | 79 | 97 | ||
1573 | @@ -82,7 +100,6 @@ | |||
1574 | 82 | virtual RGBColor info_color_for_ware(Widelands::DescriptionIndex); | 100 | virtual RGBColor info_color_for_ware(Widelands::DescriptionIndex); |
1575 | 83 | 101 | ||
1576 | 84 | const Widelands::TribeDescr::WaresOrder& icons_order() const; | 102 | const Widelands::TribeDescr::WaresOrder& icons_order() const; |
1577 | 85 | const Widelands::TribeDescr::WaresOrderCoords& icons_order_coords() const; | ||
1578 | 86 | virtual Vector2i ware_position(Widelands::DescriptionIndex) const; | 103 | virtual Vector2i ware_position(Widelands::DescriptionIndex) const; |
1579 | 87 | void draw(RenderTarget&) override; | 104 | void draw(RenderTarget&) override; |
1580 | 88 | virtual void draw_ware(RenderTarget&, Widelands::DescriptionIndex); | 105 | virtual void draw_ware(RenderTarget&, Widelands::DescriptionIndex); |
1581 | @@ -110,6 +127,13 @@ | |||
1582 | 110 | WareListSelectionType in_selection_; // Wares in temporary anchored selection | 127 | WareListSelectionType in_selection_; // Wares in temporary anchored selection |
1583 | 111 | bool selectable_; | 128 | bool selectable_; |
1584 | 112 | bool horizontal_; | 129 | bool horizontal_; |
1585 | 130 | int32_t hgap_; | ||
1586 | 131 | int32_t vgap_; | ||
1587 | 132 | |||
1588 | 133 | WaresOrderCoords order_coords_; | ||
1589 | 134 | |||
1590 | 135 | void relayout_icons_order_coords(); | ||
1591 | 136 | void recalc_desired_size(bool); | ||
1592 | 113 | 137 | ||
1593 | 114 | /** | 138 | /** |
1594 | 115 | * The ware on which the mouse press has been performed. | 139 | * The ware on which the mouse press has been performed. |
1595 | @@ -117,6 +141,8 @@ | |||
1596 | 117 | */ | 141 | */ |
1597 | 118 | Widelands::DescriptionIndex selection_anchor_; | 142 | Widelands::DescriptionIndex selection_anchor_; |
1598 | 119 | boost::function<void(Widelands::DescriptionIndex, bool)> callback_function_; | 143 | boost::function<void(Widelands::DescriptionIndex, bool)> callback_function_; |
1599 | 144 | |||
1600 | 145 | std::unique_ptr<Notifications::Subscriber<GraphicResolutionChanged>> graphic_resolution_changed_subscriber_; | ||
1601 | 120 | }; | 146 | }; |
1602 | 121 | 147 | ||
1603 | 122 | /* | 148 | /* |
Continuous integration builds have changed state:
Travis build 4886. State: failed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 528245915. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ economy_ target_ profiles- 4667.
Appveyor build 4667. State: success. Details: https:/