Merge lp:~widelands-dev/widelands/notifications_buildingwindows into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8308
Proposed branch: lp:~widelands-dev/widelands/notifications_buildingwindows
Merge into: lp:widelands
Diff against target: 2023 lines (+612/-408)
38 files modified
src/economy/CMakeLists.txt (+0/-1)
src/economy/expedition_bootstrap.cc (+3/-7)
src/economy/portdock.cc (+0/-1)
src/logic/editor_game_base.h (+1/-0)
src/logic/map_objects/immovable.cc (+1/-1)
src/logic/map_objects/tribes/building.cc (+3/-13)
src/logic/map_objects/tribes/building.h (+14/-18)
src/logic/map_objects/tribes/constructionsite.cc (+3/-7)
src/logic/map_objects/tribes/constructionsite.h (+0/-1)
src/logic/map_objects/tribes/dismantlesite.h (+0/-2)
src/logic/map_objects/tribes/militarysite.h (+0/-2)
src/logic/map_objects/tribes/productionsite.cc (+3/-2)
src/logic/map_objects/tribes/productionsite.h (+0/-2)
src/logic/map_objects/tribes/ship.cc (+1/-1)
src/logic/map_objects/tribes/trainingsite.h (+0/-1)
src/logic/map_objects/tribes/warehouse.h (+0/-2)
src/logic/player.cc (+6/-0)
src/notifications/note_ids.h (+1/-0)
src/wui/CMakeLists.txt (+5/-1)
src/wui/building_ui.cc (+0/-74)
src/wui/buildingwindow.cc (+82/-64)
src/wui/buildingwindow.h (+20/-9)
src/wui/constructionsitewindow.cc (+16/-31)
src/wui/constructionsitewindow.h (+46/-0)
src/wui/dismantlesitewindow.cc (+14/-32)
src/wui/dismantlesitewindow.h (+46/-0)
src/wui/interactive_gamebase.cc (+90/-0)
src/wui/interactive_gamebase.h (+12/-0)
src/wui/interactive_player.cc (+4/-2)
src/wui/interactive_spectator.cc (+7/-4)
src/wui/militarysitewindow.cc (+11/-28)
src/wui/militarysitewindow.h (+47/-0)
src/wui/productionsitewindow.cc (+27/-23)
src/wui/productionsitewindow.h (+8/-1)
src/wui/trainingsitewindow.cc (+12/-34)
src/wui/trainingsitewindow.h (+48/-0)
src/wui/warehousewindow.cc (+35/-44)
src/wui/warehousewindow.h (+46/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/notifications_buildingwindows
Reviewer Review Type Date Requested Status
Notabilis Approve
GunChleoc Needs Resubmitting
Review via email: mp+317264@code.launchpad.net

Commit message

Building windows are now handled by a new notification 'NoteBuilding', so that Map Objects and the economy no longer depend directly on wui. This also brings some improvements regarding the closing/minimizing of windows:
- Productionsites no longer close their window when the stop/start button is pressed.
- Minimized construction windows no longer get maximized when the construction is finished.
- Window is no longer closed on enhance or dismantle.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1953. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/201687798.
Appveyor build 1788. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_notifications_buildingwindows-1788.

Revision history for this message
Notabilis (notabilis27) wrote :

First of all: I like the intended change, the feature-changes as well as separating logic and wui. Unfortunately, there are two bigger problems with this branch.

The diff looks good to me so far. A small nit: The std::map wanted_building_windows_ stores the coordinates as data but they are not used (for now?), so we don't have to store them.

For testing, I tried to merge trunk which gave me to conflicts due to the kAlign changes in trunk. They should be easy to fix.

Well, the building window is no longer maximized when the construction is finished. Now it is simply closed. ;-)
The problem is with the BuildingWindow::is_dying_ variable. When the construction is finished, Building::destroy() is called, sending a NoteBuilding with Action::kDeleted. This sets is_dying_ to true. Only afterwards ConstructionSite::cleanup() is called and sends the Action::kStartWarp message. Since the building is already dying at this point, BuildingWindow::on_building_note() ignores the message and never stores the window for reopening. Moving the check for Action::kStartWarp out of the !is_dying_ check seems to fix the problem.

Minor nit (can be ignored): When the building is finished, the (minimized) window is brought to the front (!= maximized). Not really a problem in my opinion.

The other big problem is a crash on exit. When the game ends (either alt+f4 or per menu) and a headquarters or construction window is open, the game crashes with a std::bad_cast exception.

Two minor points: When upgrading or dismantling buildings the window is closed. That is not a issue of this branch but we might want to change this since the construction window stays open, too.

review: Needs Fixing
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the review!

The coordinates from std::map wanted_building_windows_ are used - I have marked up the line.

I also fixed the window warping for both construction sites and dismantle sites in all cases - having the window stay open is only 2 lines of code, so we might as well do it in this branch.

Now I'll go hunt the segfault.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Next try - should be all fixed now.

> Minor nit (can be ignored): When the building is finished, the (minimized) window is brought to the front (!= maximized). Not really a problem in my opinion.

We will probably have to dig into the UI toolkit for that, so let's leave it for later and see if it annoys anybody.

review: Needs Resubmitting
Revision history for this message
Notabilis (notabilis27) wrote :

Thanks for fixing, diffs looks good to me and it works as wanted when testing. Thanks for the change regarding upgrades and dismantling.

I don't really understand your fix for the segfault. As far as I can see, your only change is storing the parent pointer now in the BuildingWindow instead of inheriting it. Do you know what is happening there? Wild guess: A strange order of destructing the classes and using the already cleared pointer when destroying BuildingWindow?

Also, I don't believe that you are using the coord-entry (partially because I removed it without any visible complains). There isn't any call to std::get<0>() anywhere and the coords variable which is used in the marked line comes from the handled building. It's not important, though.

As far as I am concerned, the branch can be merged now.

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2011. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/205918080.
Appveyor build 1847. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_notifications_buildingwindows-1847.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Duh, I confused the coords with the pos. I have removed it now.

@bunnybot merge

Revision history for this message
GunChleoc (gunchleoc) wrote :

Regarding the segfault, it has to do with the destructor code in UI::Panel - if a panel gets destroyed, it also removes its children and is deleted from its parent's list of children. It seems like the reference from the buildingwindow to its parent was broken before it tried to access it for deleting the workarea overlay.

Revision history for this message
Notabilis (notabilis27) wrote :

Makes sense, thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/economy/CMakeLists.txt'
2--- src/economy/CMakeLists.txt 2017-02-12 09:10:57 +0000
3+++ src/economy/CMakeLists.txt 2017-02-28 09:26:14 +0000
4@@ -55,6 +55,5 @@
5 logic_widelands_geometry
6 map_io
7 notifications
8- wui
9 )
10 add_subdirectory(test)
11
12=== modified file 'src/economy/expedition_bootstrap.cc'
13--- src/economy/expedition_bootstrap.cc 2017-02-17 21:52:41 +0000
14+++ src/economy/expedition_bootstrap.cc 2017-02-28 09:26:14 +0000
15@@ -26,12 +26,12 @@
16 #include "economy/portdock.h"
17 #include "economy/wares_queue.h"
18 #include "economy/workers_queue.h"
19+#include "io/fileread.h"
20 #include "io/filewrite.h"
21 #include "logic/map_objects/tribes/warehouse.h"
22 #include "logic/player.h"
23 #include "map_io/map_object_loader.h"
24 #include "map_io/map_object_saver.h"
25-#include "wui/interactive_gamebase.h"
26
27 namespace Widelands {
28
29@@ -87,8 +87,7 @@
30 queues_[buildcost_size]->set_callback(input_callback, this);
31
32 // Update the user interface
33- if (upcast(InteractiveGameBase, igb, warehouse->owner().egbase().get_ibase()))
34- warehouse->refresh_options(*igb);
35+ Notifications::publish(NoteBuilding(warehouse->serial(), NoteBuilding::Action::kChanged));
36 }
37
38 /**
39@@ -113,10 +112,7 @@
40 queues_.clear();
41
42 // Update the user interface
43- if (upcast(InteractiveGameBase, igb, warehouse->owner().egbase().get_ibase())) {
44- warehouse->refresh_options(*igb);
45- }
46-
47+ Notifications::publish(NoteBuilding(warehouse->serial(), NoteBuilding::Action::kChanged));
48 Notifications::publish(NoteExpeditionCanceled(this));
49 }
50
51
52=== modified file 'src/economy/portdock.cc'
53--- src/economy/portdock.cc 2017-02-12 09:10:57 +0000
54+++ src/economy/portdock.cc 2017-02-28 09:26:14 +0000
55@@ -38,7 +38,6 @@
56 #include "logic/widelands_geometry_io.h"
57 #include "map_io/map_object_loader.h"
58 #include "map_io/map_object_saver.h"
59-#include "wui/interactive_gamebase.h"
60
61 namespace Widelands {
62
63
64=== modified file 'src/logic/editor_game_base.h'
65--- src/logic/editor_game_base.h 2017-01-25 18:55:59 +0000
66+++ src/logic/editor_game_base.h 2017-02-28 09:26:14 +0000
67@@ -38,6 +38,7 @@
68 }
69 struct FullscreenMenuLaunchGame;
70 class InteractiveBase;
71+class InteractiveGameBase; // TODO(GunChleoc): Get rid
72
73 namespace Widelands {
74
75
76=== modified file 'src/logic/map_objects/immovable.cc'
77--- src/logic/map_objects/immovable.cc 2017-01-25 18:55:59 +0000
78+++ src/logic/map_objects/immovable.cc 2017-02-28 09:26:14 +0000
79@@ -32,6 +32,7 @@
80 #include "config.h"
81 #include "graphic/graphic.h"
82 #include "graphic/rendertarget.h"
83+#include "graphic/text_constants.h"
84 #include "helper.h"
85 #include "io/fileread.h"
86 #include "io/filewrite.h"
87@@ -53,7 +54,6 @@
88 #include "notifications/notifications.h"
89 #include "scripting/lua_table.h"
90 #include "sound/sound_handler.h"
91-#include "wui/interactive_base.h"
92
93 namespace Widelands {
94
95
96=== modified file 'src/logic/map_objects/tribes/building.cc'
97--- src/logic/map_objects/tribes/building.cc 2017-01-25 18:55:59 +0000
98+++ src/logic/map_objects/tribes/building.cc 2017-02-28 09:26:14 +0000
99@@ -47,7 +47,6 @@
100 #include "logic/map_objects/tribes/worker.h"
101 #include "logic/player.h"
102 #include "sound/sound_handler.h"
103-#include "wui/interactive_player.h"
104
105 namespace Widelands {
106
107@@ -230,7 +229,6 @@
108
109 Building::Building(const BuildingDescr& building_descr)
110 : PlayerImmovable(building_descr),
111- optionswindow_(nullptr),
112 flag_(nullptr),
113 anim_(0),
114 animstart_(0),
115@@ -239,12 +237,6 @@
116 seeing_(false) {
117 }
118
119-Building::~Building() {
120- if (optionswindow_) {
121- hide_options();
122- }
123-}
124-
125 void Building::load_finish(EditorGameBase& egbase) {
126 auto should_be_deleted = [&egbase, this](const OPtr<Worker>& optr) {
127 Worker& worker = *optr.get(egbase);
128@@ -395,9 +387,6 @@
129 }
130
131 PlayerImmovable::cleanup(egbase);
132-
133- for (boost::signals2::connection& c : options_window_connections)
134- c.disconnect();
135 }
136
137 /*
138@@ -442,6 +431,7 @@
139 ===============
140 */
141 void Building::destroy(EditorGameBase& egbase) {
142+ Notifications::publish(NoteBuilding(serial(), NoteBuilding::Action::kDeleted));
143 const bool fire = burn_on_destroy();
144 const Coords pos = position_;
145 Player* building_owner = get_owner();
146@@ -690,14 +680,14 @@
147 }
148 }
149 PlayerImmovable::add_worker(worker);
150- workers_changed();
151+ Notifications::publish(NoteBuilding(serial(), NoteBuilding::Action::kWorkersChanged));
152 }
153
154 void Building::remove_worker(Worker& worker) {
155 PlayerImmovable::remove_worker(worker);
156 if (!get_workers().size())
157 set_seeing(false);
158- workers_changed();
159+ Notifications::publish(NoteBuilding(serial(), NoteBuilding::Action::kWorkersChanged));
160 }
161
162 /**
163
164=== modified file 'src/logic/map_objects/tribes/building.h'
165--- src/logic/map_objects/tribes/building.h 2017-01-25 18:55:59 +0000
166+++ src/logic/map_objects/tribes/building.h 2017-02-28 09:26:14 +0000
167@@ -35,13 +35,10 @@
168 #include "logic/map_objects/tribes/workarea_info.h"
169 #include "logic/message.h"
170 #include "logic/widelands.h"
171+#include "notifications/notifications.h"
172 #include "scripting/lua_table.h"
173
174-namespace UI {
175-class Window;
176-}
177 struct BuildingHints;
178-class InteractiveGameBase;
179 class Image;
180
181 namespace Widelands {
182@@ -191,6 +188,19 @@
183 DISALLOW_COPY_AND_ASSIGN(BuildingDescr);
184 };
185
186+struct NoteBuilding {
187+ CAN_BE_SENT_AS_NOTE(NoteId::Building)
188+
189+ Serial serial;
190+
191+ enum class Action { kChanged, kDeleted, kStartWarp, kFinishWarp, kWorkersChanged };
192+ const Action action;
193+
194+ NoteBuilding(Serial init_serial, const Action& init_action)
195+ : serial(init_serial), action(init_action) {
196+ }
197+};
198+
199 class Building : public PlayerImmovable {
200 friend class BuildingDescr;
201 friend class MapBuildingdataPacket;
202@@ -211,7 +221,6 @@
203 enum class InfoStringFormat { kCensus, kStatistics, kTooltip };
204
205 Building(const BuildingDescr&);
206- virtual ~Building();
207
208 void load_finish(EditorGameBase&) override;
209
210@@ -241,12 +250,6 @@
211 virtual bool burn_on_destroy();
212 void destroy(EditorGameBase&) override;
213
214- void show_options(InteractiveGameBase&,
215- bool avoid_fastclick = false,
216- Vector2i pos = Vector2i(-1, -1));
217- void hide_options();
218- void refresh_options(InteractiveGameBase&);
219-
220 virtual bool fetch_from_flag(Game&);
221 virtual bool get_building_work(Game&, Worker&, bool success);
222
223@@ -289,7 +292,6 @@
224
225 void add_worker(Worker&) override;
226 void remove_worker(Worker&) override;
227- mutable boost::signals2::signal<void()> workers_changed;
228
229 void send_message(Game& game,
230 const Message::Type msgtype,
231@@ -321,11 +323,8 @@
232 void
233 draw_info(TextToDraw draw_text, const Vector2f& point_on_dst, float scale, RenderTarget* dst);
234
235- virtual void create_options_window(InteractiveGameBase&, UI::Window*& registry) = 0;
236-
237 void set_seeing(bool see);
238
239- UI::Window* optionswindow_;
240 Coords position_;
241 Flag* flag_;
242
243@@ -346,9 +345,6 @@
244 /// Whether we see our vision_range area based on workers in the building
245 bool seeing_;
246
247- // Signals connected for the option window
248- std::vector<boost::signals2::connection> options_window_connections;
249-
250 // The former buildings names, with the current one in last position.
251 FormerBuildings old_buildings_;
252
253
254=== modified file 'src/logic/map_objects/tribes/constructionsite.cc'
255--- src/logic/map_objects/tribes/constructionsite.cc 2017-01-28 14:53:28 +0000
256+++ src/logic/map_objects/tribes/constructionsite.cc 2017-02-28 09:26:14 +0000
257@@ -37,7 +37,6 @@
258 #include "logic/map_objects/tribes/worker.h"
259 #include "sound/sound_handler.h"
260 #include "ui_basic/window.h"
261-#include "wui/interactive_gamebase.h"
262
263 namespace Widelands {
264
265@@ -150,6 +149,8 @@
266 ===============
267 */
268 void ConstructionSite::cleanup(EditorGameBase& egbase) {
269+ // Register whether the window was open
270+ Notifications::publish(NoteBuilding(serial(), NoteBuilding::Action::kStartWarp));
271 PartiallyFinishedBuilding::cleanup(egbase);
272
273 if (work_steps_ <= work_completed_) {
274@@ -162,12 +163,7 @@
275 builder->set_location(&b);
276 }
277 // Open the new building window if needed
278- if (optionswindow_) {
279- Vector2i window_position = optionswindow_->get_pos();
280- hide_options();
281- InteractiveGameBase& igbase = dynamic_cast<InteractiveGameBase&>(*egbase.get_ibase());
282- b.show_options(igbase, false, window_position);
283- }
284+ Notifications::publish(NoteBuilding(b.serial(), NoteBuilding::Action::kFinishWarp));
285 }
286 }
287
288
289=== modified file 'src/logic/map_objects/tribes/constructionsite.h'
290--- src/logic/map_objects/tribes/constructionsite.h 2017-01-25 18:55:59 +0000
291+++ src/logic/map_objects/tribes/constructionsite.h 2017-02-28 09:26:14 +0000
292@@ -110,7 +110,6 @@
293 uint32_t build_step_time() const override {
294 return CONSTRUCTIONSITE_STEP_TIME;
295 }
296- void create_options_window(InteractiveGameBase&, UI::Window*& registry) override;
297
298 static void wares_queue_callback(Game&, InputQueue*, DescriptionIndex, Worker*, void* data);
299
300
301=== modified file 'src/logic/map_objects/tribes/dismantlesite.h'
302--- src/logic/map_objects/tribes/dismantlesite.h 2017-01-25 18:55:59 +0000
303+++ src/logic/map_objects/tribes/dismantlesite.h 2017-02-28 09:26:14 +0000
304@@ -87,8 +87,6 @@
305 return DISMANTLESITE_STEP_TIME;
306 }
307
308- void create_options_window(InteractiveGameBase&, UI::Window*& registry) override;
309-
310 void draw(uint32_t gametime,
311 TextToDraw draw_text,
312 const Vector2f& point_on_dst,
313
314=== modified file 'src/logic/map_objects/tribes/militarysite.h'
315--- src/logic/map_objects/tribes/militarysite.h 2017-01-25 18:55:59 +0000
316+++ src/logic/map_objects/tribes/militarysite.h 2017-02-28 09:26:14 +0000
317@@ -134,8 +134,6 @@
318 protected:
319 void conquer_area(EditorGameBase&);
320
321- void create_options_window(InteractiveGameBase&, UI::Window*& registry) override;
322-
323 private:
324 void update_statistics_string(std::string*) override;
325
326
327=== modified file 'src/logic/map_objects/tribes/productionsite.cc'
328--- src/logic/map_objects/tribes/productionsite.cc 2017-02-15 19:35:43 +0000
329+++ src/logic/map_objects/tribes/productionsite.cc 2017-02-28 09:26:14 +0000
330@@ -643,7 +643,7 @@
331 // the last one we need to start working.
332 w->start_task_idle(game, 0, -1);
333 psite.try_start_working(game);
334- psite.workers_changed();
335+ Notifications::publish(NoteBuilding(psite.serial(), NoteBuilding::Action::kWorkersChanged));
336 }
337
338 /**
339@@ -723,6 +723,7 @@
340 void ProductionSite::set_stopped(bool const stopped) {
341 is_stopped_ = stopped;
342 get_economy()->rebalance_supply();
343+ Notifications::publish(NoteBuilding(serial(), NoteBuilding::Action::kChanged));
344 }
345
346 /**
347@@ -925,7 +926,7 @@
348 void ProductionSite::train_workers(Game& game) {
349 for (uint32_t i = descr().nr_working_positions(); i;)
350 working_positions_[--i].worker->gain_experience(game);
351- Building::workers_changed();
352+ Notifications::publish(NoteBuilding(serial(), NoteBuilding::Action::kWorkersChanged));
353 }
354
355 void ProductionSite::notify_player(Game& game, uint8_t minutes, FailNotificationType type) {
356
357=== modified file 'src/logic/map_objects/tribes/productionsite.h'
358--- src/logic/map_objects/tribes/productionsite.h 2017-02-14 20:22:29 +0000
359+++ src/logic/map_objects/tribes/productionsite.h 2017-02-28 09:26:14 +0000
360@@ -237,8 +237,6 @@
361 protected:
362 void update_statistics_string(std::string* statistics) override;
363
364- void create_options_window(InteractiveGameBase&, UI::Window*& registry) override;
365-
366 void load_finish(EditorGameBase& egbase) override;
367
368 protected:
369
370=== modified file 'src/logic/map_objects/tribes/ship.cc'
371--- src/logic/map_objects/tribes/ship.cc 2017-02-21 20:38:33 +0000
372+++ src/logic/map_objects/tribes/ship.cc 2017-02-28 09:26:14 +0000
373@@ -32,6 +32,7 @@
374 #include "economy/wares_queue.h"
375 #include "graphic/graphic.h"
376 #include "graphic/rendertarget.h"
377+#include "graphic/text_constants.h"
378 #include "io/fileread.h"
379 #include "io/filewrite.h"
380 #include "logic/findbob.h"
381@@ -48,7 +49,6 @@
382 #include "logic/widelands_geometry_io.h"
383 #include "map_io/map_object_loader.h"
384 #include "map_io/map_object_saver.h"
385-#include "wui/interactive_gamebase.h"
386
387 namespace Widelands {
388
389
390=== modified file 'src/logic/map_objects/tribes/trainingsite.h'
391--- src/logic/map_objects/tribes/trainingsite.h 2017-01-25 18:55:59 +0000
392+++ src/logic/map_objects/tribes/trainingsite.h 2017-02-28 09:26:14 +0000
393@@ -209,7 +209,6 @@
394 void training_done();
395
396 protected:
397- void create_options_window(InteractiveGameBase&, UI::Window*& registry) override;
398 void program_end(Game&, ProgramResult) override;
399
400 private:
401
402=== modified file 'src/logic/map_objects/tribes/warehouse.h'
403--- src/logic/map_objects/tribes/warehouse.h 2017-02-18 23:30:16 +0000
404+++ src/logic/map_objects/tribes/warehouse.h 2017-02-28 09:26:14 +0000
405@@ -253,8 +253,6 @@
406 protected:
407 /// Initializes the container sizes for the owner's tribe.
408 void init_containers(Player& owner);
409- /// Create the warehouse information window.
410- void create_options_window(InteractiveGameBase&, UI::Window*& registry) override;
411
412 private:
413 void init_portdock(EditorGameBase& egbase);
414
415=== modified file 'src/logic/player.cc'
416--- src/logic/player.cc 2017-02-18 14:03:02 +0000
417+++ src/logic/player.cc 2017-02-28 09:26:14 +0000
418@@ -693,6 +693,8 @@
419 workers = building->get_workers();
420 }
421
422+ // Register whether the window was open
423+ Notifications::publish(NoteBuilding(building->serial(), NoteBuilding::Action::kStartWarp));
424 building->remove(egbase()); // no fire or stuff
425 // Hereafter the old building does not exist and building is a dangling
426 // pointer.
427@@ -701,6 +703,10 @@
428 position, player_number_, index_of_new_building, false, former_buildings);
429 else
430 building = &egbase().warp_dismantlesite(position, player_number_, false, former_buildings);
431+
432+ // Open the new building window if needed
433+ Notifications::publish(NoteBuilding(building->serial(), NoteBuilding::Action::kFinishWarp));
434+
435 // Hereafter building points to the new building.
436
437 // Reassign the workers and soldiers.
438
439=== modified file 'src/notifications/note_ids.h'
440--- src/notifications/note_ids.h 2017-02-12 09:10:57 +0000
441+++ src/notifications/note_ids.h 2017-02-28 09:26:14 +0000
442@@ -36,6 +36,7 @@
443 TrainingSiteSoldierTrained,
444 ShipMessage,
445 ShipWindow,
446+ Building,
447 Economy,
448 GraphicResolutionChanged,
449 NoteExpeditionCanceled
450
451=== modified file 'src/wui/CMakeLists.txt'
452--- src/wui/CMakeLists.txt 2017-02-12 09:10:57 +0000
453+++ src/wui/CMakeLists.txt 2017-02-28 09:26:14 +0000
454@@ -145,13 +145,14 @@
455 attack_box.h
456 building_statistics_menu.cc
457 building_statistics_menu.h
458- building_ui.cc
459 buildingwindow.cc
460 buildingwindow.h
461 constructionsitewindow.cc
462+ constructionsitewindow.h
463 debugconsole.cc
464 debugconsole.h
465 dismantlesitewindow.cc
466+ dismantlesitewindow.h
467 encyclopedia_window.cc
468 encyclopedia_window.h
469 fieldaction.cc
470@@ -194,6 +195,7 @@
471 login_box.h
472 logmessage.h
473 militarysitewindow.cc
474+ militarysitewindow.h
475 minimap.cc
476 minimap.h
477 multiplayersetupgroup.cc
478@@ -217,6 +219,7 @@
479 story_message_box.cc
480 story_message_box.h
481 trainingsitewindow.cc
482+ trainingsitewindow.h
483 transport_draw.cc
484 tribal_encyclopedia.cc
485 tribal_encyclopedia.h
486@@ -225,6 +228,7 @@
487 ware_statistics_menu.cc
488 ware_statistics_menu.h
489 warehousewindow.cc
490+ warehousewindow.h
491 watchwindow.cc
492 watchwindow.h
493 USES_SDL2
494
495=== removed file 'src/wui/building_ui.cc'
496--- src/wui/building_ui.cc 2017-02-17 18:16:35 +0000
497+++ src/wui/building_ui.cc 1970-01-01 00:00:00 +0000
498@@ -1,74 +0,0 @@
499-/*
500- * Copyright (C) 2002-2017 by the Widelands Development Team
501- *
502- * This program is free software; you can redistribute it and/or
503- * modify it under the terms of the GNU General Public License
504- * as published by the Free Software Foundation; either version 2
505- * of the License, or (at your option) any later version.
506- *
507- * This program is distributed in the hope that it will be useful,
508- * but WITHOUT ANY WARRANTY; without even the implied warranty of
509- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
510- * GNU General Public License for more details.
511- *
512- * You should have received a copy of the GNU General Public License
513- * along with this program; if not, write to the Free Software
514- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
515- *
516- */
517-
518-#include "wui/buildingwindow.h"
519-
520-#include <boost/lexical_cast.hpp>
521-
522-#include "base/macros.h"
523-#include "logic/map_objects/tribes/building.h"
524-#include "ui_basic/window.h"
525-
526-using Widelands::Building;
527-
528-/**
529- * Create the building's options window if necessary and bring it to
530- * the top to be seen by the player.
531- */
532-void Building::show_options(InteractiveGameBase& igbase, bool avoid_fastclick, Vector2i pos) {
533- if (optionswindow_) {
534- if (optionswindow_->is_minimal())
535- optionswindow_->restore();
536- optionswindow_->move_to_top();
537- } else {
538- create_options_window(igbase, optionswindow_);
539- if (upcast(BuildingWindow, bw, optionswindow_)) {
540- bw->set_avoid_fastclick(avoid_fastclick);
541- }
542- // Run a first think here so that certain things like caps buttons
543- // get properly initialized
544- optionswindow_->think();
545- }
546- if (pos.x >= 0 && pos.y >= 0) {
547- optionswindow_->set_pos(pos);
548- }
549-}
550-
551-/**
552- * Remove the building's options window.
553- */
554-void Building::hide_options() {
555- for (boost::signals2::connection& c : options_window_connections)
556- c.disconnect();
557- delete optionswindow_;
558- optionswindow_ = nullptr;
559-}
560-
561-/**
562- * refreshs the option window of a building - useful if some ui elements have to be removed or added
563- */
564-void Building::refresh_options(InteractiveGameBase& igb) {
565- // Only do something if there is actually a window
566- if (optionswindow_) {
567- Vector2i window_position = optionswindow_->get_pos();
568- hide_options();
569- show_options(igb, true);
570- optionswindow_->set_pos(window_position);
571- }
572-}
573
574=== modified file 'src/wui/buildingwindow.cc'
575--- src/wui/buildingwindow.cc 2017-02-25 13:27:40 +0000
576+++ src/wui/buildingwindow.cc 2017-02-28 09:26:14 +0000
577@@ -46,58 +46,76 @@
578 static const char* pic_debug = "images/wui/fieldaction/menu_debug.png";
579
580 BuildingWindow::BuildingWindow(InteractiveGameBase& parent,
581+ UI::UniqueWindow::Registry& reg,
582 Widelands::Building& b,
583- UI::Window*& registry)
584- : UI::Window(&parent, "building_window", 0, 0, Width, 0, b.descr().descname()),
585- registry_(registry),
586+ bool avoid_fastclick)
587+ : UI::UniqueWindow(&parent, "building_window", &reg, Width, 0, b.descr().descname()),
588+ is_dying_(false),
589+ parent_(&parent),
590 building_(b),
591 workarea_overlay_id_(0),
592- avoid_fastclick_(false),
593+ avoid_fastclick_(avoid_fastclick),
594 expeditionbtn_(nullptr) {
595- delete registry_;
596- registry_ = this;
597-
598+ buildingnotes_subscriber_ = Notifications::subscribe<Widelands::NoteBuilding>(
599+ [this](const Widelands::NoteBuilding& note) { on_building_note(note); });
600+}
601+
602+BuildingWindow::~BuildingWindow() {
603+ if (workarea_overlay_id_) {
604+ igbase()->mutable_field_overlay_manager()->remove_overlay(workarea_overlay_id_);
605+ }
606+}
607+
608+void BuildingWindow::on_building_note(const Widelands::NoteBuilding& note) {
609+ if (note.serial == building_.serial()) {
610+ switch (note.action) {
611+ // The building's state has changed
612+ case Widelands::NoteBuilding::Action::kChanged:
613+ if (!is_dying_) {
614+ init(true);
615+ }
616+ break;
617+ // The building is no more
618+ case Widelands::NoteBuilding::Action::kStartWarp:
619+ igbase()->add_wanted_building_window(building().get_position(), get_pos(), is_minimal());
620+ // Fallthrough intended
621+ case Widelands::NoteBuilding::Action::kDeleted:
622+ // Stop everybody from thinking to avoid segfaults
623+ is_dying_ = true;
624+ set_thinks(false);
625+ vbox_.reset(nullptr);
626+ die();
627+ break;
628+ default:
629+ break;
630+ }
631+ }
632+}
633+
634+void BuildingWindow::init(bool avoid_fastclick) {
635 capscache_player_number_ = 0;
636 capsbuttons_ = nullptr;
637 capscache_ = 0;
638 caps_setup_ = false;
639 toggle_workarea_ = nullptr;
640-
641- UI::Box* vbox = new UI::Box(this, 0, 0, UI::Box::Vertical);
642-
643- tabs_ = new UI::TabPanel(vbox, 0, 0, nullptr);
644- vbox->add(tabs_, UI::Box::Resizing::kFullSize);
645-
646- capsbuttons_ = new UI::Box(vbox, 0, 0, UI::Box::Horizontal);
647- vbox->add(capsbuttons_, UI::Box::Resizing::kFullSize);
648+ avoid_fastclick_ = avoid_fastclick,
649+
650+ vbox_.reset(new UI::Box(this, 0, 0, UI::Box::Vertical));
651+
652+ tabs_ = new UI::TabPanel(vbox_.get(), 0, 0, nullptr);
653+ vbox_->add(tabs_, UI::Box::Resizing::kFullSize);
654+
655+ capsbuttons_ = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal);
656+ vbox_->add(capsbuttons_, UI::Box::Resizing::kFullSize);
657+
658 // actually create buttons on the first call to think(),
659 // so that overriding create_capsbuttons() works
660
661- set_center_panel(vbox);
662+ set_center_panel(vbox_.get());
663 set_thinks(true);
664 set_fastclick_panel(this);
665-
666 show_workarea();
667-
668- // Title for construction site
669- if (upcast(Widelands::ConstructionSite, csite, &building_)) {
670- // Show name in parenthesis as it may take all width already
671- const std::string title = (boost::format("(%s)") % csite->building().descname()).str();
672- set_title(title);
673- }
674-}
675-
676-BuildingWindow::~BuildingWindow() {
677- if (workarea_overlay_id_) {
678- igbase().mutable_field_overlay_manager()->remove_overlay(workarea_overlay_id_);
679- }
680- registry_ = nullptr;
681-}
682-
683-namespace Widelands {
684-class BuildingDescr;
685-}
686-using Widelands::Building;
687+}
688
689 /*
690 ===============
691@@ -122,16 +140,17 @@
692 ===============
693 */
694 void BuildingWindow::think() {
695- if (!igbase().can_see(building().owner().player_number()))
696+ if (!igbase()->can_see(building().owner().player_number()))
697 die();
698
699- if (!caps_setup_ || capscache_player_number_ != igbase().player_number() ||
700+ if (!caps_setup_ || capscache_player_number_ != igbase()->player_number() ||
701 building().get_playercaps() != capscache_) {
702 capsbuttons_->free_children();
703 create_capsbuttons(capsbuttons_);
704- move_out_of_the_way();
705- if (!avoid_fastclick_)
706+ if (!avoid_fastclick_) {
707+ move_out_of_the_way();
708 warp_mouse_to_fastclick_panel();
709+ }
710 caps_setup_ = true;
711 }
712
713@@ -147,12 +166,12 @@
714 */
715 void BuildingWindow::create_capsbuttons(UI::Box* capsbuttons) {
716 capscache_ = building().get_playercaps();
717- capscache_player_number_ = igbase().player_number();
718+ capscache_player_number_ = igbase()->player_number();
719
720 const Widelands::Player& owner = building().owner();
721 const Widelands::PlayerNumber owner_number = owner.player_number();
722- const bool can_see = igbase().can_see(owner_number);
723- const bool can_act = igbase().can_act(owner_number);
724+ const bool can_see = igbase()->can_see(owner_number);
725+ const bool can_act = igbase()->can_act(owner_number);
726
727 bool requires_destruction_separator = false;
728 if (can_act) {
729@@ -280,7 +299,7 @@
730 set_fastclick_panel(toggle_workarea_);
731 }
732
733- if (igbase().get_display_flag(InteractiveBase::dfDebug)) {
734+ if (igbase()->get_display_flag(InteractiveBase::dfDebug)) {
735 UI::Button* debugbtn = new UI::Button(
736 capsbuttons, "debug", 0, 0, 34, 34, g_gr->images().get("images/ui_basic/but4.png"),
737 g_gr->images().get(pic_debug), _("Show Debug Window"));
738@@ -305,10 +324,10 @@
739 g_gr->images().get("images/ui_basic/menu_help.png"), _("Help"));
740
741 UI::UniqueWindow::Registry& registry =
742- igbase().unique_windows().get_registry(building_.descr().name() + "_help");
743+ igbase()->unique_windows().get_registry(building_.descr().name() + "_help");
744 registry.open_window = [this, &registry] {
745- new UI::BuildingHelpWindow(&igbase(), registry, building_.descr(),
746- building_.owner().tribe(), &igbase().egbase().lua());
747+ new UI::BuildingHelpWindow(igbase(), registry, building_.descr(),
748+ building_.owner().tribe(), &igbase()->egbase().lua());
749 };
750
751 helpbtn->sigclicked.connect(
752@@ -325,9 +344,9 @@
753 void BuildingWindow::act_bulldoze() {
754 if (SDL_GetModState() & KMOD_CTRL) {
755 if (building_.get_playercaps() & Widelands::Building::PCap_Bulldoze)
756- igbase().game().send_player_bulldoze(building_);
757+ igbase()->game().send_player_bulldoze(building_);
758 } else {
759- show_bulldoze_confirm(dynamic_cast<InteractivePlayer&>(igbase()), building_);
760+ show_bulldoze_confirm(dynamic_cast<InteractivePlayer&>(*igbase()), building_);
761 }
762 }
763
764@@ -339,9 +358,9 @@
765 void BuildingWindow::act_dismantle() {
766 if (SDL_GetModState() & KMOD_CTRL) {
767 if (building_.get_playercaps() & Widelands::Building::PCap_Dismantle)
768- igbase().game().send_player_dismantle(building_);
769+ igbase()->game().send_player_dismantle(building_);
770 } else {
771- show_dismantle_confirm(dynamic_cast<InteractivePlayer&>(igbase()), building_);
772+ show_dismantle_confirm(dynamic_cast<InteractivePlayer&>(*igbase()), building_);
773 }
774 }
775
776@@ -351,10 +370,9 @@
777 ===============
778 */
779 void BuildingWindow::act_start_stop() {
780- if (dynamic_cast<const Widelands::ProductionSite*>(&building_))
781- igbase().game().send_player_start_stop_building(building_);
782-
783- die();
784+ if (dynamic_cast<const Widelands::ProductionSite*>(&building_)) {
785+ igbase()->game().send_player_start_stop_building(building_);
786+ }
787 }
788
789 /**
790@@ -366,7 +384,7 @@
791 if (upcast(Widelands::Warehouse const, warehouse, &building_)) {
792 if (warehouse->get_portdock()) {
793 expeditionbtn_->set_enabled(false);
794- igbase().game().send_player_start_or_cancel_expedition(building_);
795+ igbase()->game().send_player_start_or_cancel_expedition(building_);
796 }
797 get_tabs()->activate("expedition_wares_queue");
798 }
799@@ -383,9 +401,9 @@
800 void BuildingWindow::act_enhance(Widelands::DescriptionIndex id) {
801 if (SDL_GetModState() & KMOD_CTRL) {
802 if (building_.get_playercaps() & Widelands::Building::PCap_Enhancable)
803- igbase().game().send_player_enhance_building(building_, id);
804+ igbase()->game().send_player_enhance_building(building_, id);
805 } else {
806- show_enhance_confirm(dynamic_cast<InteractivePlayer&>(igbase()), building_, id);
807+ show_enhance_confirm(dynamic_cast<InteractivePlayer&>(*igbase()), building_, id);
808 }
809 }
810
811@@ -395,7 +413,7 @@
812 ===============
813 */
814 void BuildingWindow::act_debug() {
815- show_field_debug(igbase(), igbase().game().map().get_fcoords(building_.get_position()));
816+ show_field_debug(*igbase(), igbase()->game().map().get_fcoords(building_.get_position()));
817 }
818
819 /**
820@@ -414,7 +432,7 @@
821 if (workarea_info.empty()) {
822 return;
823 }
824- workarea_overlay_id_ = igbase().show_work_area(workarea_info, building_.get_position());
825+ workarea_overlay_id_ = igbase()->show_work_area(workarea_info, building_.get_position());
826
827 configure_workarea_button();
828 }
829@@ -424,7 +442,7 @@
830 */
831 void BuildingWindow::hide_workarea() {
832 if (workarea_overlay_id_) {
833- igbase().hide_work_area(workarea_overlay_id_);
834+ igbase()->hide_work_area(workarea_overlay_id_);
835 workarea_overlay_id_ = 0;
836
837 configure_workarea_button();
838@@ -459,7 +477,7 @@
839 Widelands::InputQueue* const iq,
840 bool show_only) {
841 // The *max* width should be larger than the default width
842- box->add(new InputQueueDisplay(box, 0, 0, igbase(), b, iq, show_only));
843+ box->add(new InputQueueDisplay(box, 0, 0, *igbase(), b, iq, show_only));
844 }
845
846 /**
847@@ -467,7 +485,7 @@
848 * for the corresponding button.
849 */
850 void BuildingWindow::clicked_goto() {
851- igbase().scroll_to_field(building().get_position(), MapView::Transition::Smooth);
852+ igbase()->scroll_to_field(building().get_position(), MapView::Transition::Smooth);
853 }
854
855 void BuildingWindow::update_expedition_button(bool expedition_was_canceled) {
856
857=== modified file 'src/wui/buildingwindow.h'
858--- src/wui/buildingwindow.h 2017-01-25 18:55:59 +0000
859+++ src/wui/buildingwindow.h 2017-02-28 09:26:14 +0000
860@@ -24,8 +24,10 @@
861 #include <memory>
862
863 #include "economy/expedition_bootstrap.h"
864+#include "logic/map_objects/tribes/building.h"
865+#include "notifications/notifications.h"
866 #include "ui_basic/button.h"
867-#include "ui_basic/window.h"
868+#include "ui_basic/unique_window.h"
869 #include "wui/field_overlay_manager.h"
870 #include "wui/interactive_gamebase.h"
871 #include "wui/waresdisplay.h"
872@@ -35,14 +37,17 @@
873 *
874 * This class is sub-classed for all building types to provide something useful.
875 */
876-struct BuildingWindow : public UI::Window {
877+struct BuildingWindow : public UI::UniqueWindow {
878 friend struct TrainingSiteWindow;
879 friend struct MilitarySiteWindow;
880 enum {
881 Width = 4 * 34 // 4 normally sized buttons
882 };
883
884- BuildingWindow(InteractiveGameBase& parent, Widelands::Building&, UI::Window*& registry);
885+ BuildingWindow(InteractiveGameBase& parent,
886+ UI::UniqueWindow::Registry& reg,
887+ Widelands::Building&,
888+ bool avoid_fastclick);
889
890 virtual ~BuildingWindow();
891
892@@ -50,17 +55,16 @@
893 return building_;
894 }
895
896- InteractiveGameBase& igbase() const {
897- return dynamic_cast<InteractiveGameBase&>(*get_parent());
898+ InteractiveGameBase* igbase() const {
899+ return parent_;
900 }
901
902 void draw(RenderTarget&) override;
903 void think() override;
904- void set_avoid_fastclick(bool afc) {
905- avoid_fastclick_ = afc;
906- }
907
908 protected:
909+ virtual void init(bool avoid_fastclick);
910+
911 UI::TabPanel* get_tabs() {
912 return tabs_;
913 }
914@@ -82,11 +86,16 @@
915
916 virtual void create_capsbuttons(UI::Box* buttons);
917
918- UI::Window*& registry_;
919+ bool is_dying_;
920
921 private:
922+ InteractiveGameBase* parent_;
923+ /// Actions performed when a NoteBuilding is received.
924+ void on_building_note(const Widelands::NoteBuilding& note);
925 Widelands::Building& building_;
926
927+ std::unique_ptr<UI::Box> vbox_;
928+
929 UI::TabPanel* tabs_;
930
931 UI::Box* capsbuttons_; ///< \ref UI::Box that contains capabilities buttons
932@@ -106,6 +115,8 @@
933 UI::Button* expeditionbtn_;
934 std::unique_ptr<Notifications::Subscriber<Widelands::NoteExpeditionCanceled>>
935 expedition_canceled_subscriber_;
936+ std::unique_ptr<Notifications::Subscriber<Widelands::NoteBuilding>> buildingnotes_subscriber_;
937+ DISALLOW_COPY_AND_ASSIGN(BuildingWindow);
938 };
939
940 #endif // end of include guard: WL_WUI_BUILDINGWINDOW_H
941
942=== modified file 'src/wui/constructionsitewindow.cc'
943--- src/wui/constructionsitewindow.cc 2017-02-26 11:00:07 +0000
944+++ src/wui/constructionsitewindow.cc 2017-02-28 09:26:14 +0000
945@@ -17,35 +17,27 @@
946 *
947 */
948
949-#include "wui/buildingwindow.h"
950+#include "wui/constructionsitewindow.h"
951
952-#include "wui/inputqueuedisplay.h"
953+#include <boost/format.hpp>
954
955 #include "graphic/graphic.h"
956-#include "logic/map_objects/tribes/constructionsite.h"
957-#include "ui_basic/progressbar.h"
958 #include "ui_basic/tabpanel.h"
959+#include "wui/inputqueuedisplay.h"
960
961 static const char pic_tab_wares[] = "images/wui/buildings/menu_tab_wares.png";
962
963-/**
964- * Status window for construction sites.
965- */
966-struct ConstructionSiteWindow : public BuildingWindow {
967- ConstructionSiteWindow(InteractiveGameBase& parent,
968- Widelands::ConstructionSite&,
969- UI::Window*& registry);
970-
971- void think() override;
972-
973-private:
974- UI::ProgressBar* progress_;
975-};
976-
977 ConstructionSiteWindow::ConstructionSiteWindow(InteractiveGameBase& parent,
978+ UI::UniqueWindow::Registry& reg,
979 Widelands::ConstructionSite& cs,
980- UI::Window*& registry)
981- : BuildingWindow(parent, cs, registry) {
982+ bool avoid_fastclick)
983+ : BuildingWindow(parent, reg, cs, avoid_fastclick) {
984+ init(avoid_fastclick);
985+}
986+
987+void ConstructionSiteWindow::init(bool avoid_fastclick) {
988+ BuildingWindow::init(avoid_fastclick);
989+ Widelands::ConstructionSite& cs = dynamic_cast<Widelands::ConstructionSite&>(building());
990 UI::Box& box = *new UI::Box(get_tabs(), 0, 0, UI::Box::Vertical);
991
992 // Add the progress bar
993@@ -58,9 +50,12 @@
994
995 // Add the wares queue
996 for (uint32_t i = 0; i < cs.get_nrwaresqueues(); ++i)
997- box.add(new InputQueueDisplay(&box, 0, 0, igbase(), cs, cs.get_waresqueue(i)));
998+ box.add(new InputQueueDisplay(&box, 0, 0, *igbase(), cs, cs.get_waresqueue(i)));
999
1000 get_tabs()->add("wares", g_gr->images().get(pic_tab_wares), &box, _("Building materials"));
1001+
1002+ set_title((boost::format("(%s)") % cs.building().descname()).str());
1003+ think();
1004 }
1005
1006 /*
1007@@ -75,13 +70,3 @@
1008
1009 progress_->set_state(cs.get_built_per64k());
1010 }
1011-
1012-/*
1013-===============
1014-Create the status window describing the construction site.
1015-===============
1016-*/
1017-void Widelands::ConstructionSite::create_options_window(InteractiveGameBase& parent,
1018- UI::Window*& registry) {
1019- new ConstructionSiteWindow(parent, *this, registry);
1020-}
1021
1022=== added file 'src/wui/constructionsitewindow.h'
1023--- src/wui/constructionsitewindow.h 1970-01-01 00:00:00 +0000
1024+++ src/wui/constructionsitewindow.h 2017-02-28 09:26:14 +0000
1025@@ -0,0 +1,46 @@
1026+/*
1027+ * Copyright (C) 2002-2016 by the Widelands Development Team
1028+ *
1029+ * This program is free software; you can redistribute it and/or
1030+ * modify it under the terms of the GNU General Public License
1031+ * as published by the Free Software Foundation; either version 2
1032+ * of the License, or (at your option) any later version.
1033+ *
1034+ * This program is distributed in the hope that it will be useful,
1035+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1036+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1037+ * GNU General Public License for more details.
1038+ *
1039+ * You should have received a copy of the GNU General Public License
1040+ * along with this program; if not, write to the Free Software
1041+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1042+ *
1043+ */
1044+
1045+#ifndef WL_WUI_CONSTRUCTIONSITEWINDOW_H
1046+#define WL_WUI_CONSTRUCTIONSITEWINDOW_H
1047+
1048+#include "logic/map_objects/tribes/constructionsite.h"
1049+#include "ui_basic/progressbar.h"
1050+#include "wui/buildingwindow.h"
1051+
1052+/**
1053+ * Status window for construction sites.
1054+ */
1055+struct ConstructionSiteWindow : public BuildingWindow {
1056+ ConstructionSiteWindow(InteractiveGameBase& parent,
1057+ UI::UniqueWindow::Registry& reg,
1058+ Widelands::ConstructionSite&,
1059+ bool avoid_fastclick);
1060+
1061+ void think() override;
1062+
1063+protected:
1064+ void init(bool avoid_fastclick) override;
1065+
1066+private:
1067+ UI::ProgressBar* progress_;
1068+ DISALLOW_COPY_AND_ASSIGN(ConstructionSiteWindow);
1069+};
1070+
1071+#endif // end of include guard: WL_WUI_CONSTRUCTIONSITEWINDOW_H
1072
1073=== modified file 'src/wui/dismantlesitewindow.cc'
1074--- src/wui/dismantlesitewindow.cc 2017-02-25 13:27:40 +0000
1075+++ src/wui/dismantlesitewindow.cc 2017-02-28 09:26:14 +0000
1076@@ -17,33 +17,24 @@
1077 *
1078 */
1079
1080-#include "logic/map_objects/tribes/dismantlesite.h"
1081+#include "wui/dismantlesitewindow.h"
1082
1083 #include "graphic/graphic.h"
1084-#include "ui_basic/progressbar.h"
1085 #include "ui_basic/tabpanel.h"
1086-#include "wui/buildingwindow.h"
1087
1088 static const char pic_tab_wares[] = "images/wui/buildings/menu_tab_wares.png";
1089
1090-/**
1091- * Status window for dismantle sites.
1092- */
1093-struct DismantleSiteWindow : public BuildingWindow {
1094- DismantleSiteWindow(InteractiveGameBase& parent,
1095- Widelands::DismantleSite&,
1096- UI::Window*& registry);
1097-
1098- void think() override;
1099-
1100-private:
1101- UI::ProgressBar* progress_;
1102-};
1103-
1104 DismantleSiteWindow::DismantleSiteWindow(InteractiveGameBase& parent,
1105- Widelands::DismantleSite& cs,
1106- UI::Window*& registry)
1107- : BuildingWindow(parent, cs, registry) {
1108+ UI::UniqueWindow::Registry& reg,
1109+ Widelands::DismantleSite& ds,
1110+ bool avoid_fastclick)
1111+ : BuildingWindow(parent, reg, ds, avoid_fastclick) {
1112+ init(avoid_fastclick);
1113+}
1114+
1115+void DismantleSiteWindow::init(bool avoid_fastclick) {
1116+ BuildingWindow::init(avoid_fastclick);
1117+ Widelands::DismantleSite& ds = dynamic_cast<Widelands::DismantleSite&>(building());
1118 UI::Box& box = *new UI::Box(get_tabs(), 0, 0, UI::Box::Vertical);
1119
1120 // Add the progress bar
1121@@ -55,10 +46,11 @@
1122 box.add_space(8);
1123
1124 // Add the wares queue
1125- for (uint32_t i = 0; i < cs.get_nrwaresqueues(); ++i)
1126- BuildingWindow::create_input_queue_panel(&box, cs, cs.get_waresqueue(i), true);
1127+ for (uint32_t i = 0; i < ds.get_nrwaresqueues(); ++i)
1128+ BuildingWindow::create_input_queue_panel(&box, ds, ds.get_waresqueue(i), true);
1129
1130 get_tabs()->add("wares", g_gr->images().get(pic_tab_wares), &box, _("Building materials"));
1131+ think();
1132 }
1133
1134 /*
1135@@ -73,13 +65,3 @@
1136
1137 progress_->set_state(ds.get_built_per64k());
1138 }
1139-
1140-/*
1141-===============
1142-Create the status window describing the site.
1143-===============
1144-*/
1145-void Widelands::DismantleSite::create_options_window(InteractiveGameBase& parent,
1146- UI::Window*& registry) {
1147- new DismantleSiteWindow(parent, *this, registry);
1148-}
1149
1150=== added file 'src/wui/dismantlesitewindow.h'
1151--- src/wui/dismantlesitewindow.h 1970-01-01 00:00:00 +0000
1152+++ src/wui/dismantlesitewindow.h 2017-02-28 09:26:14 +0000
1153@@ -0,0 +1,46 @@
1154+/*
1155+ * Copyright (C) 2002-2016 by the Widelands Development Team
1156+ *
1157+ * This program is free software; you can redistribute it and/or
1158+ * modify it under the terms of the GNU General Public License
1159+ * as published by the Free Software Foundation; either version 2
1160+ * of the License, or (at your option) any later version.
1161+ *
1162+ * This program is distributed in the hope that it will be useful,
1163+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1164+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1165+ * GNU General Public License for more details.
1166+ *
1167+ * You should have received a copy of the GNU General Public License
1168+ * along with this program; if not, write to the Free Software
1169+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1170+ *
1171+ */
1172+
1173+#ifndef WL_WUI_DISMANTLESITEWINDOW_H
1174+#define WL_WUI_DISMANTLESITEWINDOW_H
1175+
1176+#include "logic/map_objects/tribes/dismantlesite.h"
1177+#include "ui_basic/progressbar.h"
1178+#include "wui/buildingwindow.h"
1179+
1180+/**
1181+ * Status window for dismantle sites.
1182+ */
1183+struct DismantleSiteWindow : public BuildingWindow {
1184+ DismantleSiteWindow(InteractiveGameBase& parent,
1185+ UI::UniqueWindow::Registry& reg,
1186+ Widelands::DismantleSite&,
1187+ bool avoid_fastclick);
1188+
1189+ void think() override;
1190+
1191+protected:
1192+ void init(bool avoid_fastclick) override;
1193+
1194+private:
1195+ UI::ProgressBar* progress_;
1196+ DISALLOW_COPY_AND_ASSIGN(DismantleSiteWindow);
1197+};
1198+
1199+#endif // end of include guard: WL_WUI_DISMANTLESITEWINDOW_H
1200
1201=== modified file 'src/wui/interactive_gamebase.cc'
1202--- src/wui/interactive_gamebase.cc 2017-02-24 08:07:50 +0000
1203+++ src/wui/interactive_gamebase.cc 2017-02-28 09:26:14 +0000
1204@@ -33,9 +33,15 @@
1205 #include "logic/map_objects/tribes/ship.h"
1206 #include "logic/player.h"
1207 #include "profile/profile.h"
1208+#include "wui/constructionsitewindow.h"
1209+#include "wui/dismantlesitewindow.h"
1210 #include "wui/game_summary.h"
1211+#include "wui/militarysitewindow.h"
1212+#include "wui/productionsitewindow.h"
1213 #include "wui/shipwindow.h"
1214+#include "wui/trainingsitewindow.h"
1215 #include "wui/unique_window_handler.h"
1216+#include "wui/warehousewindow.h"
1217
1218 namespace {
1219
1220@@ -56,6 +62,28 @@
1221 chat_provider_(nullptr),
1222 multiplayer_(multiplayer),
1223 playertype_(pt) {
1224+ buildingnotes_subscriber_ = Notifications::subscribe<Widelands::NoteBuilding>(
1225+ [this](const Widelands::NoteBuilding& note) {
1226+ switch (note.action) {
1227+ case Widelands::NoteBuilding::Action::kFinishWarp: {
1228+ if (upcast(
1229+ Widelands::Building const, building, game().objects().get_object(note.serial))) {
1230+ const Widelands::Coords coords = building->get_position();
1231+ // Check whether the window is wanted
1232+ if (wanted_building_windows_.count(coords.hash()) == 1) {
1233+ UI::UniqueWindow* building_window = show_building_window(coords, true);
1234+ building_window->set_pos(wanted_building_windows_.at(coords.hash()).first);
1235+ if (wanted_building_windows_.at(coords.hash()).second) {
1236+ building_window->minimize();
1237+ }
1238+ wanted_building_windows_.erase(coords.hash());
1239+ }
1240+ }
1241+ } break;
1242+ default:
1243+ break;
1244+ }
1245+ });
1246 }
1247
1248 /// \return a pointer to the running \ref Game instance.
1249@@ -129,6 +157,68 @@
1250 toggle_buildhelp_->set_perm_pressed(value);
1251 }
1252
1253+void InteractiveGameBase::add_wanted_building_window(const Widelands::Coords& coords,
1254+ const Vector2i point,
1255+ bool was_minimal) {
1256+ wanted_building_windows_.insert(
1257+ std::make_pair(coords.hash(), std::make_pair(point, was_minimal)));
1258+}
1259+
1260+UI::UniqueWindow* InteractiveGameBase::show_building_window(const Widelands::Coords& coord,
1261+ bool avoid_fastclick) {
1262+ Widelands::BaseImmovable* immovable = game().map().get_immovable(coord);
1263+ upcast(Widelands::Building, building, immovable);
1264+ assert(building);
1265+ UI::UniqueWindow::Registry& registry =
1266+ unique_windows().get_registry((boost::format("building_%d") % building->serial()).str());
1267+
1268+ switch (building->descr().type()) {
1269+ case Widelands::MapObjectType::CONSTRUCTIONSITE:
1270+ registry.open_window = [this, &registry, building, avoid_fastclick] {
1271+ new ConstructionSiteWindow(*this, registry,
1272+ *dynamic_cast<Widelands::ConstructionSite*>(building),
1273+ avoid_fastclick);
1274+ };
1275+ break;
1276+ case Widelands::MapObjectType::DISMANTLESITE:
1277+ registry.open_window = [this, &registry, building, avoid_fastclick] {
1278+ new DismantleSiteWindow(
1279+ *this, registry, *dynamic_cast<Widelands::DismantleSite*>(building), avoid_fastclick);
1280+ };
1281+ break;
1282+ case Widelands::MapObjectType::MILITARYSITE:
1283+ registry.open_window = [this, &registry, building, avoid_fastclick] {
1284+ new MilitarySiteWindow(
1285+ *this, registry, *dynamic_cast<Widelands::MilitarySite*>(building), avoid_fastclick);
1286+ };
1287+ break;
1288+ case Widelands::MapObjectType::PRODUCTIONSITE:
1289+ registry.open_window = [this, &registry, building, avoid_fastclick] {
1290+ new ProductionSiteWindow(
1291+ *this, registry, *dynamic_cast<Widelands::ProductionSite*>(building), avoid_fastclick);
1292+ };
1293+ break;
1294+ case Widelands::MapObjectType::TRAININGSITE:
1295+ registry.open_window = [this, &registry, building, avoid_fastclick] {
1296+ new TrainingSiteWindow(
1297+ *this, registry, *dynamic_cast<Widelands::TrainingSite*>(building), avoid_fastclick);
1298+ };
1299+ break;
1300+ case Widelands::MapObjectType::WAREHOUSE:
1301+ registry.open_window = [this, &registry, building, avoid_fastclick] {
1302+ new WarehouseWindow(
1303+ *this, registry, *dynamic_cast<Widelands::Warehouse*>(building), avoid_fastclick);
1304+ };
1305+ break;
1306+ default:
1307+ log("Unable to show window for building '%s', type '%s'.\n", building->descr().name().c_str(),
1308+ to_string(building->descr().type()).c_str());
1309+ NEVER_HERE();
1310+ }
1311+ registry.create();
1312+ return registry.window;
1313+}
1314+
1315 /**
1316 * See if we can reasonably open a ship window at the current selection position.
1317 * If so, do it and return true; otherwise, return false.
1318
1319=== modified file 'src/wui/interactive_gamebase.h'
1320--- src/wui/interactive_gamebase.h 2017-01-25 18:55:59 +0000
1321+++ src/wui/interactive_gamebase.h 2017-02-28 09:26:14 +0000
1322@@ -20,8 +20,12 @@
1323 #ifndef WL_WUI_INTERACTIVE_GAMEBASE_H
1324 #define WL_WUI_INTERACTIVE_GAMEBASE_H
1325
1326+#include <map>
1327+#include <memory>
1328+
1329 #include "logic/game.h"
1330 #include "profile/profile.h"
1331+#include "ui_basic/unique_window.h"
1332 #include "wui/general_statistics_menu.h"
1333 #include "wui/interactive_base.h"
1334
1335@@ -69,6 +73,10 @@
1336 playertype_ = pt;
1337 }
1338
1339+ void add_wanted_building_window(const Widelands::Coords& coords,
1340+ const Vector2i point,
1341+ bool was_minimal);
1342+ UI::UniqueWindow* show_building_window(const Widelands::Coords& coords, bool avoid_fastclick);
1343 bool try_show_ship_window();
1344 bool is_multiplayer() {
1345 return multiplayer_;
1346@@ -94,6 +102,10 @@
1347
1348 private:
1349 void on_buildhelp_changed(const bool value) override;
1350+ // Building coordinates, window position, whether the window was minimized
1351+ std::map<uint32_t, std::pair<const Vector2i, bool>>
1352+ wanted_building_windows_;
1353+ std::unique_ptr<Notifications::Subscriber<Widelands::NoteBuilding>> buildingnotes_subscriber_;
1354 };
1355
1356 #endif // end of include guard: WL_WUI_INTERACTIVE_GAMEBASE_H
1357
1358=== modified file 'src/wui/interactive_player.cc'
1359--- src/wui/interactive_player.cc 2017-02-12 09:10:57 +0000
1360+++ src/wui/interactive_player.cc 2017-02-28 09:26:14 +0000
1361@@ -195,8 +195,10 @@
1362 if (1 < player().vision(Map::get_index(get_sel_pos().node, map.get_width()))) {
1363 // Special case for buildings
1364 if (upcast(Building, building, map.get_immovable(get_sel_pos().node)))
1365- if (can_see(building->owner().player_number()))
1366- return building->show_options(*this);
1367+ if (can_see(building->owner().player_number())) {
1368+ show_building_window(get_sel_pos().node, false);
1369+ return;
1370+ }
1371
1372 if (!is_building_road()) {
1373 if (try_show_ship_window())
1374
1375=== modified file 'src/wui/interactive_spectator.cc'
1376--- src/wui/interactive_spectator.cc 2017-01-25 18:55:59 +0000
1377+++ src/wui/interactive_spectator.cc 2017-02-28 09:26:14 +0000
1378@@ -142,12 +142,15 @@
1379 * Observer has clicked on the given node; bring up the context menu.
1380 */
1381 void InteractiveSpectator::node_action() {
1382- if // special case for buildings
1383- (upcast(Widelands::Building, building, egbase().map().get_immovable(get_sel_pos().node)))
1384- return building->show_options(*this);
1385+ // Special case for buildings
1386+ if (is_a(Widelands::Building, egbase().map().get_immovable(get_sel_pos().node))) {
1387+ show_building_window(get_sel_pos().node, false);
1388+ return;
1389+ }
1390
1391- if (try_show_ship_window())
1392+ if (try_show_ship_window()) {
1393 return;
1394+ }
1395
1396 // everything else can bring up the temporary dialog
1397 show_field_action(this, nullptr, &fieldaction_);
1398
1399=== modified file 'src/wui/militarysitewindow.cc'
1400--- src/wui/militarysitewindow.cc 2017-01-25 18:55:59 +0000
1401+++ src/wui/militarysitewindow.cc 2017-02-28 09:26:14 +0000
1402@@ -17,47 +17,30 @@
1403 *
1404 */
1405
1406-#include "logic/map_objects/tribes/militarysite.h"
1407+#include "wui/militarysitewindow.h"
1408
1409 #include "graphic/graphic.h"
1410 #include "ui_basic/tabpanel.h"
1411-#include "wui/buildingwindow.h"
1412 #include "wui/soldiercapacitycontrol.h"
1413 #include "wui/soldierlist.h"
1414
1415-using Widelands::MilitarySite;
1416-
1417 static char const* pic_tab_military = "images/wui/buildings/menu_tab_military.png";
1418
1419-/**
1420- * Status window for \ref MilitarySite
1421- */
1422-struct MilitarySiteWindow : public BuildingWindow {
1423- MilitarySiteWindow(InteractiveGameBase& parent, MilitarySite&, UI::Window*& registry);
1424-
1425- MilitarySite& militarysite() {
1426- return dynamic_cast<MilitarySite&>(building());
1427- }
1428-
1429-protected:
1430- void create_capsbuttons(UI::Box* buttons) override;
1431-};
1432-
1433 MilitarySiteWindow::MilitarySiteWindow(InteractiveGameBase& parent,
1434- MilitarySite& ms,
1435- UI::Window*& registry)
1436- : BuildingWindow(parent, ms, registry) {
1437- get_tabs()->add("soldiers", g_gr->images().get(pic_tab_military),
1438- create_soldier_list(*get_tabs(), parent, militarysite()), _("Soldiers"));
1439+ UI::UniqueWindow::Registry& reg,
1440+ Widelands::MilitarySite& ms,
1441+ bool avoid_fastclick)
1442+ : BuildingWindow(parent, reg, ms, avoid_fastclick) {
1443+ init(avoid_fastclick);
1444 }
1445
1446 void MilitarySiteWindow::create_capsbuttons(UI::Box* buttons) {
1447 BuildingWindow::create_capsbuttons(buttons);
1448 }
1449
1450-/**
1451- * Create the military site information window.
1452- */
1453-void MilitarySite::create_options_window(InteractiveGameBase& plr, UI::Window*& registry) {
1454- new MilitarySiteWindow(plr, *this, registry);
1455+void MilitarySiteWindow::init(bool avoid_fastclick) {
1456+ BuildingWindow::init(avoid_fastclick);
1457+ get_tabs()->add("soldiers", g_gr->images().get(pic_tab_military),
1458+ create_soldier_list(*get_tabs(), *igbase(), militarysite()), _("Soldiers"));
1459+ think();
1460 }
1461
1462=== added file 'src/wui/militarysitewindow.h'
1463--- src/wui/militarysitewindow.h 1970-01-01 00:00:00 +0000
1464+++ src/wui/militarysitewindow.h 2017-02-28 09:26:14 +0000
1465@@ -0,0 +1,47 @@
1466+/*
1467+ * Copyright (C) 2002-2016 by the Widelands Development Team
1468+ *
1469+ * This program is free software; you can redistribute it and/or
1470+ * modify it under the terms of the GNU General Public License
1471+ * as published by the Free Software Foundation; either version 2
1472+ * of the License, or (at your option) any later version.
1473+ *
1474+ * This program is distributed in the hope that it will be useful,
1475+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1476+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1477+ * GNU General Public License for more details.
1478+ *
1479+ * You should have received a copy of the GNU General Public License
1480+ * along with this program; if not, write to the Free Software
1481+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1482+ *
1483+ */
1484+
1485+#ifndef WL_WUI_MILITARYSITEWINDOW_H
1486+#define WL_WUI_MILITARYSITEWINDOW_H
1487+
1488+#include "logic/map_objects/tribes/militarysite.h"
1489+#include "wui/buildingwindow.h"
1490+
1491+/**
1492+ * Status window for \ref MilitarySite
1493+ */
1494+struct MilitarySiteWindow : public BuildingWindow {
1495+ MilitarySiteWindow(InteractiveGameBase& parent,
1496+ UI::UniqueWindow::Registry& reg,
1497+ Widelands::MilitarySite&,
1498+ bool avoid_fastclick);
1499+
1500+ Widelands::MilitarySite& militarysite() {
1501+ return dynamic_cast<Widelands::MilitarySite&>(building());
1502+ }
1503+
1504+protected:
1505+ void init(bool avoid_fastclick) override;
1506+ void create_capsbuttons(UI::Box* buttons) override;
1507+
1508+private:
1509+ DISALLOW_COPY_AND_ASSIGN(MilitarySiteWindow);
1510+};
1511+
1512+#endif // end of include guard: WL_WUI_MILITARYSITEWINDOW_H
1513
1514=== modified file 'src/wui/productionsitewindow.cc'
1515--- src/wui/productionsitewindow.cc 2017-02-25 13:27:40 +0000
1516+++ src/wui/productionsitewindow.cc 2017-02-28 09:26:14 +0000
1517@@ -24,17 +24,12 @@
1518 #include "economy/input_queue.h"
1519 #include "economy/request.h"
1520 #include "graphic/graphic.h"
1521-#include "logic/map_objects/tribes/constructionsite.h"
1522-#include "logic/map_objects/tribes/militarysite.h"
1523-#include "logic/map_objects/tribes/trainingsite.h"
1524 #include "logic/map_objects/tribes/tribe_descr.h"
1525 #include "logic/map_objects/tribes/worker.h"
1526 #include "ui_basic/tabpanel.h"
1527 #include "ui_basic/textarea.h"
1528 #include "wui/inputqueuedisplay.h"
1529
1530-using Widelands::ProductionSite;
1531-
1532 static char const* pic_tab_wares = "images/wui/buildings/menu_tab_wares.png";
1533 static char const* pic_tab_workers = "images/wui/buildings/menu_list_workers.png";
1534
1535@@ -44,10 +39,28 @@
1536 ===============
1537 */
1538 ProductionSiteWindow::ProductionSiteWindow(InteractiveGameBase& parent,
1539- ProductionSite& ps,
1540- UI::Window*& registry)
1541- : BuildingWindow(parent, ps, registry) {
1542- const std::vector<Widelands::InputQueue*>& inputqueues = ps.inputqueues();
1543+ UI::UniqueWindow::Registry& reg,
1544+ Widelands::ProductionSite& ps,
1545+ bool avoid_fastclick)
1546+ : BuildingWindow(parent, reg, ps, avoid_fastclick) {
1547+ productionsitenotes_subscriber_ = Notifications::subscribe<Widelands::NoteBuilding>(
1548+ [this](const Widelands::NoteBuilding& note) {
1549+ if (note.serial == building().serial() && !is_dying_) {
1550+ switch (note.action) {
1551+ case Widelands::NoteBuilding::Action::kWorkersChanged:
1552+ update_worker_table();
1553+ break;
1554+ default:
1555+ break;
1556+ }
1557+ }
1558+ });
1559+ init(avoid_fastclick);
1560+}
1561+
1562+void ProductionSiteWindow::init(bool avoid_fastclick) {
1563+ BuildingWindow::init(avoid_fastclick);
1564+ const std::vector<Widelands::InputQueue*>& inputqueues = productionsite().inputqueues();
1565
1566 if (inputqueues.size()) {
1567 // Add the wares tab
1568@@ -55,7 +68,8 @@
1569 get_tabs(), 0, 0, UI::Box::Vertical, g_gr->get_xres() - 80, g_gr->get_yres() - 80);
1570
1571 for (uint32_t i = 0; i < inputqueues.size(); ++i) {
1572- prod_box->add(new InputQueueDisplay(prod_box, 0, 0, igbase(), ps, inputqueues[i]));
1573+ prod_box->add(
1574+ new InputQueueDisplay(prod_box, 0, 0, *igbase(), productionsite(), inputqueues[i]));
1575 }
1576
1577 get_tabs()->add("wares", g_gr->images().get(pic_tab_wares), prod_box, _("Wares"));
1578@@ -79,7 +93,7 @@
1579 }
1580 worker_table_->fit_height();
1581
1582- if (igbase().can_act(building().owner().player_number())) {
1583+ if (igbase()->can_act(building().owner().player_number())) {
1584 worker_caps_->add_inf_space();
1585 UI::Button* evict_button = new UI::Button(
1586 worker_caps_, "evict", 0, 0, 34, 34, g_gr->images().get("images/ui_basic/but4.png"),
1587@@ -98,6 +112,7 @@
1588 (ngettext("Worker", "Workers", productionsite().descr().nr_working_positions())));
1589 update_worker_table();
1590 }
1591+ think();
1592 }
1593
1594 void ProductionSiteWindow::think() {
1595@@ -113,17 +128,6 @@
1596 }
1597 }
1598
1599-/*
1600-===============
1601-Create the production site information window.
1602-===============
1603-*/
1604-void ProductionSite::create_options_window(InteractiveGameBase& parent, UI::Window*& registry) {
1605- ProductionSiteWindow* win = new ProductionSiteWindow(parent, *this, registry);
1606- Building::options_window_connections.push_back(Building::workers_changed.connect(
1607- boost::bind(&ProductionSiteWindow::update_worker_table, boost::ref(*win))));
1608-}
1609-
1610 void ProductionSiteWindow::update_worker_table() {
1611 if (worker_table_ == nullptr) {
1612 return;
1613@@ -175,7 +179,7 @@
1614 Widelands::Worker* worker =
1615 productionsite().working_positions()[worker_table_->get_selected()].worker;
1616 if (worker) {
1617- igbase().game().send_player_evict_worker(*worker);
1618+ igbase()->game().send_player_evict_worker(*worker);
1619 }
1620 }
1621 }
1622
1623=== modified file 'src/wui/productionsitewindow.h'
1624--- src/wui/productionsitewindow.h 2017-01-25 18:55:59 +0000
1625+++ src/wui/productionsitewindow.h 2017-02-28 09:26:14 +0000
1626@@ -20,14 +20,17 @@
1627 #ifndef WL_WUI_PRODUCTIONSITEWINDOW_H
1628 #define WL_WUI_PRODUCTIONSITEWINDOW_H
1629
1630+#include <memory>
1631+
1632 #include "logic/map_objects/tribes/productionsite.h"
1633 #include "ui_basic/table.h"
1634 #include "wui/buildingwindow.h"
1635
1636 struct ProductionSiteWindow : public BuildingWindow {
1637 ProductionSiteWindow(InteractiveGameBase& parent,
1638+ UI::UniqueWindow::Registry& reg,
1639 Widelands::ProductionSite&,
1640- UI::Window*& registry);
1641+ bool avoid_fastclick);
1642
1643 Widelands::ProductionSite& productionsite() {
1644 return dynamic_cast<Widelands::ProductionSite&>(building());
1645@@ -35,12 +38,16 @@
1646 void update_worker_table();
1647
1648 protected:
1649+ void init(bool avoid_fastclick) override;
1650 void think() override;
1651 void evict_worker();
1652
1653 private:
1654 UI::Table<uintptr_t>* worker_table_;
1655 UI::Box* worker_caps_;
1656+ std::unique_ptr<Notifications::Subscriber<Widelands::NoteBuilding>>
1657+ productionsitenotes_subscriber_;
1658+ DISALLOW_COPY_AND_ASSIGN(ProductionSiteWindow);
1659 };
1660
1661 #endif // end of include guard: WL_WUI_PRODUCTIONSITEWINDOW_H
1662
1663=== modified file 'src/wui/trainingsitewindow.cc'
1664--- src/wui/trainingsitewindow.cc 2017-01-25 18:55:59 +0000
1665+++ src/wui/trainingsitewindow.cc 2017-02-28 09:26:14 +0000
1666@@ -17,56 +17,34 @@
1667 *
1668 */
1669
1670-#include "logic/map_objects/tribes/trainingsite.h"
1671+#include "wui/trainingsitewindow.h"
1672
1673 #include "graphic/graphic.h"
1674 #include "ui_basic/tabpanel.h"
1675-#include "wui/productionsitewindow.h"
1676 #include "wui/soldiercapacitycontrol.h"
1677 #include "wui/soldierlist.h"
1678
1679-using Widelands::TrainingSite;
1680-
1681 static char const* pic_tab_military = "images/wui/buildings/menu_tab_military.png";
1682
1683 /**
1684- * Status window for \ref TrainingSite
1685- */
1686-struct TrainingSiteWindow : public ProductionSiteWindow {
1687- TrainingSiteWindow(InteractiveGameBase& parent, TrainingSite&, UI::Window*& registry);
1688-
1689- TrainingSite& trainingsite() {
1690- return dynamic_cast<TrainingSite&>(building());
1691- }
1692-
1693-protected:
1694- void create_capsbuttons(UI::Box* buttons) override;
1695-};
1696-
1697-/**
1698 * Create the \ref TrainingSite specific soldier list tab.
1699 */
1700 TrainingSiteWindow::TrainingSiteWindow(InteractiveGameBase& parent,
1701- TrainingSite& ts,
1702- UI::Window*& registry)
1703- : ProductionSiteWindow(parent, ts, registry) {
1704+ UI::UniqueWindow::Registry& reg,
1705+ Widelands::TrainingSite& ts,
1706+ bool avoid_fastclick)
1707+ : ProductionSiteWindow(parent, reg, ts, avoid_fastclick) {
1708+ init(avoid_fastclick);
1709+}
1710+
1711+void TrainingSiteWindow::init(bool avoid_fastclick) {
1712+ ProductionSiteWindow::init(avoid_fastclick);
1713 get_tabs()->add("soldiers", g_gr->images().get(pic_tab_military),
1714- create_soldier_list(*get_tabs(), parent, trainingsite()),
1715+ create_soldier_list(*get_tabs(), *igbase(), trainingsite()),
1716 _("Soldiers in training"));
1717+ think();
1718 }
1719
1720 void TrainingSiteWindow::create_capsbuttons(UI::Box* buttons) {
1721 ProductionSiteWindow::create_capsbuttons(buttons);
1722 }
1723-
1724-/*
1725-===============
1726-Create the training site information window.
1727-===============
1728-*/
1729-void TrainingSite::create_options_window(InteractiveGameBase& plr, UI::Window*& registry) {
1730- ProductionSiteWindow* win =
1731- dynamic_cast<ProductionSiteWindow*>(new TrainingSiteWindow(plr, *this, registry));
1732- Building::options_window_connections.push_back(Building::workers_changed.connect(
1733- boost::bind(&ProductionSiteWindow::update_worker_table, boost::ref(*win))));
1734-}
1735
1736=== added file 'src/wui/trainingsitewindow.h'
1737--- src/wui/trainingsitewindow.h 1970-01-01 00:00:00 +0000
1738+++ src/wui/trainingsitewindow.h 2017-02-28 09:26:14 +0000
1739@@ -0,0 +1,48 @@
1740+/*
1741+ * Copyright (C) 2002-2016 by the Widelands Development Team
1742+ *
1743+ * This program is free software; you can redistribute it and/or
1744+ * modify it under the terms of the GNU General Public License
1745+ * as published by the Free Software Foundation; either version 2
1746+ * of the License, or (at your option) any later version.
1747+ *
1748+ * This program is distributed in the hope that it will be useful,
1749+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1750+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1751+ * GNU General Public License for more details.
1752+ *
1753+ * You should have received a copy of the GNU General Public License
1754+ * along with this program; if not, write to the Free Software
1755+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1756+ *
1757+ */
1758+
1759+#ifndef WL_WUI_TRAININGSITEWINDOW_H
1760+#define WL_WUI_TRAININGSITEWINDOW_H
1761+
1762+#include "logic/map_objects/tribes/trainingsite.h"
1763+#include "ui_basic/button.h"
1764+#include "wui/productionsitewindow.h"
1765+
1766+/**
1767+ * Status window for \ref TrainingSite
1768+ */
1769+struct TrainingSiteWindow : public ProductionSiteWindow {
1770+ TrainingSiteWindow(InteractiveGameBase& parent,
1771+ UI::UniqueWindow::Registry& reg,
1772+ Widelands::TrainingSite&,
1773+ bool avoid_fastclick);
1774+
1775+ Widelands::TrainingSite& trainingsite() {
1776+ return dynamic_cast<Widelands::TrainingSite&>(building());
1777+ }
1778+
1779+protected:
1780+ void init(bool avoid_fastclick) override;
1781+ void create_capsbuttons(UI::Box* buttons) override;
1782+
1783+private:
1784+ DISALLOW_COPY_AND_ASSIGN(TrainingSiteWindow);
1785+};
1786+
1787+#endif // end of include guard: WL_WUI_TRAININGSITEWINDOW_H
1788
1789=== modified file 'src/wui/warehousewindow.cc'
1790--- src/wui/warehousewindow.cc 2017-02-25 13:27:40 +0000
1791+++ src/wui/warehousewindow.cc 2017-02-28 09:26:14 +0000
1792@@ -17,7 +17,7 @@
1793 *
1794 */
1795
1796-#include "logic/map_objects/tribes/warehouse.h"
1797+#include "wui/warehousewindow.h"
1798
1799 #include "graphic/graphic.h"
1800 #include "graphic/rendertarget.h"
1801@@ -28,8 +28,6 @@
1802 #include "wui/portdockwaresdisplay.h"
1803 #include "wui/waresdisplay.h"
1804
1805-using Widelands::Warehouse;
1806-
1807 static const char pic_tab_wares[] = "images/wui/buildings/menu_tab_wares.png";
1808 static const char pic_tab_workers[] = "images/wui/buildings/menu_tab_workers.png";
1809 static const char pic_tab_dock_wares[] = "images/wui/buildings/menu_tab_wares_dock.png";
1810@@ -47,7 +45,7 @@
1811 public:
1812 WarehouseWaresDisplay(UI::Panel* parent,
1813 uint32_t width,
1814- Warehouse& wh,
1815+ Widelands::Warehouse& wh,
1816 Widelands::WareWorker type,
1817 bool selectable);
1818
1819@@ -55,11 +53,14 @@
1820 void draw_ware(RenderTarget& dst, Widelands::DescriptionIndex ware) override;
1821
1822 private:
1823- Warehouse& warehouse_;
1824+ Widelands::Warehouse& warehouse_;
1825 };
1826
1827-WarehouseWaresDisplay::WarehouseWaresDisplay(
1828- UI::Panel* parent, uint32_t width, Warehouse& wh, Widelands::WareWorker type, bool selectable)
1829+WarehouseWaresDisplay::WarehouseWaresDisplay(UI::Panel* parent,
1830+ uint32_t width,
1831+ Widelands::Warehouse& wh,
1832+ Widelands::WareWorker type,
1833+ bool selectable)
1834 : WaresDisplay(parent, 0, 0, wh.owner().tribe(), type, selectable), warehouse_(wh) {
1835 set_inner_size(width, 0);
1836 add_warelist(type == Widelands::wwWORKER ? warehouse_.get_workers() : warehouse_.get_wares());
1837@@ -75,19 +76,19 @@
1838 void WarehouseWaresDisplay::draw_ware(RenderTarget& dst, Widelands::DescriptionIndex ware) {
1839 WaresDisplay::draw_ware(dst, ware);
1840
1841- Warehouse::StockPolicy policy = warehouse_.get_stock_policy(get_type(), ware);
1842+ Widelands::Warehouse::StockPolicy policy = warehouse_.get_stock_policy(get_type(), ware);
1843 const Image* pic = nullptr;
1844 switch (policy) {
1845- case Warehouse::StockPolicy::kPrefer:
1846+ case Widelands::Warehouse::StockPolicy::kPrefer:
1847 pic = g_gr->images().get(pic_policy_prefer);
1848 break;
1849- case Warehouse::StockPolicy::kDontStock:
1850+ case Widelands::Warehouse::StockPolicy::kDontStock:
1851 pic = g_gr->images().get(pic_policy_dontstock);
1852 break;
1853- case Warehouse::StockPolicy::kRemove:
1854+ case Widelands::Warehouse::StockPolicy::kRemove:
1855 pic = g_gr->images().get(pic_policy_remove);
1856 break;
1857- case Warehouse::StockPolicy::kNormal:
1858+ case Widelands::Warehouse::StockPolicy::kNormal:
1859 // don't draw anything for the normal policy
1860 return;
1861 }
1862@@ -103,14 +104,14 @@
1863 WarehouseWaresPanel(UI::Panel* parent,
1864 uint32_t width,
1865 InteractiveGameBase&,
1866- Warehouse&,
1867+ Widelands::Warehouse&,
1868 Widelands::WareWorker type);
1869
1870- void set_policy(Warehouse::StockPolicy);
1871+ void set_policy(Widelands::Warehouse::StockPolicy);
1872
1873 private:
1874 InteractiveGameBase& gb_;
1875- Warehouse& wh_;
1876+ Widelands::Warehouse& wh_;
1877 bool can_act_;
1878 Widelands::WareWorker type_;
1879 WarehouseWaresDisplay display_;
1880@@ -119,7 +120,7 @@
1881 WarehouseWaresPanel::WarehouseWaresPanel(UI::Panel* parent,
1882 uint32_t width,
1883 InteractiveGameBase& gb,
1884- Warehouse& wh,
1885+ Widelands::Warehouse& wh,
1886 Widelands::WareWorker type)
1887 : UI::Box(parent, 0, 0, UI::Box::Vertical),
1888 gb_(gb),
1889@@ -138,8 +139,8 @@
1890 b = new UI::Button( \
1891 buttons, #policy, 0, 0, 34, 34, g_gr->images().get("images/ui_basic/but4.png"), \
1892 g_gr->images().get("images/wui/buildings/stock_policy_button_" #policy ".png"), tooltip), \
1893- b->sigclicked.connect( \
1894- boost::bind(&WarehouseWaresPanel::set_policy, this, Warehouse::StockPolicy::k##policyname)), \
1895+ b->sigclicked.connect(boost::bind( \
1896+ &WarehouseWaresPanel::set_policy, this, Widelands::Warehouse::StockPolicy::k##policyname)), \
1897 buttons->add(b);
1898
1899 ADD_POLICY_BUTTON(normal, Normal, _("Normal policy"))
1900@@ -152,7 +153,7 @@
1901 /**
1902 * Add Buttons policy buttons
1903 */
1904-void WarehouseWaresPanel::set_policy(Warehouse::StockPolicy newpolicy) {
1905+void WarehouseWaresPanel::set_policy(Widelands::Warehouse::StockPolicy newpolicy) {
1906 if (gb_.can_act(wh_.owner().player_number())) {
1907 bool is_workers = type_ == Widelands::wwWORKER;
1908 const std::set<Widelands::DescriptionIndex> indices =
1909@@ -169,31 +170,28 @@
1910 }
1911
1912 /**
1913- * Status window for warehouses
1914- */
1915-struct WarehouseWindow : public BuildingWindow {
1916- WarehouseWindow(InteractiveGameBase& parent, Warehouse&, UI::Window*& registry);
1917-
1918- Warehouse& warehouse() {
1919- return dynamic_cast<Warehouse&>(building());
1920- }
1921-};
1922-
1923-/**
1924 * Create the tabs of a warehouse window.
1925 */
1926-WarehouseWindow::WarehouseWindow(InteractiveGameBase& parent, Warehouse& wh, UI::Window*& registry)
1927- : BuildingWindow(parent, wh, registry) {
1928+WarehouseWindow::WarehouseWindow(InteractiveGameBase& parent,
1929+ UI::UniqueWindow::Registry& reg,
1930+ Widelands::Warehouse& wh,
1931+ bool avoid_fastclick)
1932+ : BuildingWindow(parent, reg, wh, avoid_fastclick) {
1933+ init(avoid_fastclick);
1934+}
1935+
1936+void WarehouseWindow::init(bool avoid_fastclick) {
1937+ BuildingWindow::init(avoid_fastclick);
1938 get_tabs()->add(
1939 "wares", g_gr->images().get(pic_tab_wares),
1940- new WarehouseWaresPanel(get_tabs(), Width, igbase(), warehouse(), Widelands::wwWARE),
1941+ new WarehouseWaresPanel(get_tabs(), Width, *igbase(), warehouse(), Widelands::wwWARE),
1942 _("Wares"));
1943 get_tabs()->add(
1944 "workers", g_gr->images().get(pic_tab_workers),
1945- new WarehouseWaresPanel(get_tabs(), Width, igbase(), warehouse(), Widelands::wwWORKER),
1946+ new WarehouseWaresPanel(get_tabs(), Width, *igbase(), warehouse(), Widelands::wwWORKER),
1947 _("Workers"));
1948
1949- if (Widelands::PortDock* pd = wh.get_portdock()) {
1950+ if (Widelands::PortDock* pd = warehouse().get_portdock()) {
1951 get_tabs()->add("dock_wares", g_gr->images().get(pic_tab_dock_wares),
1952 create_portdock_wares_display(get_tabs(), Width, *pd, Widelands::wwWARE),
1953 _("Wares waiting to be shipped"));
1954@@ -202,16 +200,9 @@
1955 _("Workers waiting to embark"));
1956 if (pd->expedition_started()) {
1957 get_tabs()->add("expedition_wares_queue", g_gr->images().get(pic_tab_expedition),
1958- create_portdock_expedition_display(get_tabs(), warehouse(), igbase()),
1959+ create_portdock_expedition_display(get_tabs(), warehouse(), *igbase()),
1960 _("Expedition"));
1961 }
1962 }
1963-}
1964-
1965-/**
1966- * Create the status window describing the warehouse.
1967- */
1968-void Widelands::Warehouse::create_options_window(InteractiveGameBase& parent,
1969- UI::Window*& registry) {
1970- new WarehouseWindow(parent, *this, registry);
1971+ think();
1972 }
1973
1974=== added file 'src/wui/warehousewindow.h'
1975--- src/wui/warehousewindow.h 1970-01-01 00:00:00 +0000
1976+++ src/wui/warehousewindow.h 2017-02-28 09:26:14 +0000
1977@@ -0,0 +1,46 @@
1978+/*
1979+ * Copyright (C) 2002-2016 by the Widelands Development Team
1980+ *
1981+ * This program is free software; you can redistribute it and/or
1982+ * modify it under the terms of the GNU General Public License
1983+ * as published by the Free Software Foundation; either version 2
1984+ * of the License, or (at your option) any later version.
1985+ *
1986+ * This program is distributed in the hope that it will be useful,
1987+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1988+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1989+ * GNU General Public License for more details.
1990+ *
1991+ * You should have received a copy of the GNU General Public License
1992+ * along with this program; if not, write to the Free Software
1993+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1994+ *
1995+ */
1996+
1997+#ifndef WL_WUI_WAREHOUSEWINDOW_H
1998+#define WL_WUI_WAREHOUSEWINDOW_H
1999+
2000+#include "logic/map_objects/tribes/warehouse.h"
2001+#include "wui/buildingwindow.h"
2002+
2003+/**
2004+ * Status window for warehouses
2005+ */
2006+struct WarehouseWindow : public BuildingWindow {
2007+ WarehouseWindow(InteractiveGameBase& parent,
2008+ UI::UniqueWindow::Registry& reg,
2009+ Widelands::Warehouse&,
2010+ bool avoid_fastclick);
2011+
2012+ Widelands::Warehouse& warehouse() {
2013+ return dynamic_cast<Widelands::Warehouse&>(building());
2014+ }
2015+
2016+protected:
2017+ void init(bool avoid_fastclick) override;
2018+
2019+private:
2020+ DISALLOW_COPY_AND_ASSIGN(WarehouseWindow);
2021+};
2022+
2023+#endif // end of include guard: WL_WUI_WAREHOUSEWINDOW_H

Subscribers

People subscribed via source and target branches

to status/vote changes: