Merge lp:~widelands-dev/widelands/notifications_shipwindow into lp:widelands
- notifications_shipwindow
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 8146 |
Proposed branch: | lp:~widelands-dev/widelands/notifications_shipwindow |
Merge into: | lp:widelands |
Diff against target: |
627 lines (+170/-162) 10 files modified
src/economy/portdock.cc (+1/-2) src/logic/editor_game_base.h (+1/-0) src/logic/map_objects/tribes/ship.cc (+7/-10) src/logic/map_objects/tribes/ship.h (+24/-23) src/notifications/note_ids.h (+1/-0) src/wui/CMakeLists.txt (+1/-0) src/wui/interactive_gamebase.cc (+2/-1) src/wui/interactive_gamebase.h (+1/-2) src/wui/shipwindow.cc (+51/-124) src/wui/shipwindow.h (+81/-0) |
To merge this branch: | bzr merge lp:~widelands-dev/widelands/notifications_shipwindow |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
SirVer | Approve | ||
GunChleoc | Needs Resubmitting | ||
Review via email: mp+307048@code.launchpad.net |
Commit message
Ships no longer know about their windows.
- Ships send a NoteShipWindow when window contents need to be changed / the window destroyed.
- Ship windows are now controlled by InteractiveGame
- Made a bunch of functions in Ship const.
Description of the change
Another one for Build 20.
I want to remove the dependency from logic to wui, and I think the Notification system is a good way of doing that. I'd like some feedback on the design before I do more of these.
I also made a bunch of functions in Ship const while I was at it.
bunnybot (widelandsofficial) wrote : | # |
SirVer (sirver) wrote : | # |
> I want to remove the dependency from logic to wui,
that is a noble and excellent goal!
> and I think the Notification system is a good way of doing that.
I designed it with this idea in mind - to decouple user interface from logic.
I think the big problem in this change is the tracking of the open ship windows - I'd try getting rid of that by subscribing again for each ship window.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 1376. State: failed. Details: https:/
Appveyor build 1218. State: success. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
Thanks for the review, I like this much better now. Time for the next round :)
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 1379. State: passed. Details: https:/
Appveyor build 1221. State: success. Details: https:/
SirVer (sirver) wrote : | # |
lgtm. nice separation of concerns.
GunChleoc (gunchleoc) wrote : | # |
Set to WiP to give Bunnybot a break.
Preview Diff
1 | === modified file 'src/economy/portdock.cc' |
2 | --- src/economy/portdock.cc 2016-08-04 15:49:05 +0000 |
3 | +++ src/economy/portdock.cc 2016-10-18 16:46:53 +0000 |
4 | @@ -337,8 +337,7 @@ |
5 | // The expedition goods are now on the ship, so from now on it is independent from the port |
6 | // and thus we switch the port to normal, so we could even start a new expedition, |
7 | cancel_expedition(game); |
8 | - if (upcast(InteractiveGameBase, igb, game.get_ibase())) |
9 | - ship.refresh_window(*igb); |
10 | + Notifications::publish(NoteShipWindow(ship.serial(), NoteShipWindow::Action::kRefresh)); |
11 | return fleet_->update(game); |
12 | } |
13 | } |
14 | |
15 | === modified file 'src/logic/editor_game_base.h' |
16 | --- src/logic/editor_game_base.h 2016-08-04 15:49:05 +0000 |
17 | +++ src/logic/editor_game_base.h 2016-10-18 16:46:53 +0000 |
18 | @@ -154,6 +154,7 @@ |
19 | uint32_t get_gametime() const { |
20 | return gametime_; |
21 | } |
22 | + // TODO(GunChleoc): Get rid. |
23 | InteractiveBase* get_ibase() const { |
24 | return ibase_.get(); |
25 | } |
26 | |
27 | === modified file 'src/logic/map_objects/tribes/ship.cc' |
28 | --- src/logic/map_objects/tribes/ship.cc 2016-09-07 09:30:49 +0000 |
29 | +++ src/logic/map_objects/tribes/ship.cc 2016-10-18 16:46:53 +0000 |
30 | @@ -126,14 +126,13 @@ |
31 | |
32 | Ship::Ship(const ShipDescr& gdescr) |
33 | : Bob(gdescr), |
34 | - window_(nullptr), |
35 | fleet_(nullptr), |
36 | economy_(nullptr), |
37 | ship_state_(ShipStates::kTransport) { |
38 | } |
39 | |
40 | Ship::~Ship() { |
41 | - close_window(); |
42 | + Notifications::publish(NoteShipWindow(serial(), NoteShipWindow::Action::kClose)); |
43 | } |
44 | |
45 | PortDock* Ship::get_destination(EditorGameBase& egbase) const { |
46 | @@ -680,8 +679,7 @@ |
47 | |
48 | expedition_.reset(nullptr); |
49 | |
50 | - if (upcast(InteractiveGameBase, igb, game.get_ibase())) |
51 | - refresh_window(*igb); |
52 | + Notifications::publish(NoteShipWindow(serial(), NoteShipWindow::Action::kRefresh)); |
53 | return start_task_idle(game, descr().main_animation(), 1500); |
54 | } |
55 | } |
56 | @@ -743,7 +741,7 @@ |
57 | /** |
58 | * Find a path to the dock @p pd, returns its length, and the path optionally. |
59 | */ |
60 | -uint32_t Ship::calculate_sea_route(Game& game, PortDock& pd, Path* finalpath) { |
61 | +uint32_t Ship::calculate_sea_route(Game& game, PortDock& pd, Path* finalpath) const { |
62 | Map& map = game.map(); |
63 | StepEvalAStar se(pd.get_warehouse()->get_position()); |
64 | se.swim_ = true; |
65 | @@ -847,7 +845,7 @@ |
66 | expedition_->island_exploration = false; |
67 | } |
68 | |
69 | -WalkingDir Ship::get_scouting_direction() { |
70 | +WalkingDir Ship::get_scouting_direction() const { |
71 | if (expedition_ && ship_state_ == ShipStates::kExpeditionScouting && |
72 | !expedition_->island_exploration) { |
73 | return expedition_->scouting_direction; |
74 | @@ -882,7 +880,7 @@ |
75 | expedition_->island_exploration = true; |
76 | } |
77 | |
78 | -IslandExploreDirection Ship::get_island_explore_direction() { |
79 | +IslandExploreDirection Ship::get_island_explore_direction() const { |
80 | if (expedition_ && ship_state_ == ShipStates::kExpeditionScouting && |
81 | expedition_->island_exploration) { |
82 | return expedition_->island_explore_direction; |
83 | @@ -926,8 +924,7 @@ |
84 | expedition_.reset(nullptr); |
85 | |
86 | // And finally update our ship window |
87 | - if (upcast(InteractiveGameBase, igb, game.get_ibase())) |
88 | - refresh_window(*igb); |
89 | + Notifications::publish(NoteShipWindow(serial(), NoteShipWindow::Action::kRefresh)); |
90 | } |
91 | |
92 | /// Sinks the ship |
93 | @@ -936,10 +933,10 @@ |
94 | // Running colonization has the highest priority + a sink request is only valid once |
95 | if (!state_is_sinkable()) |
96 | return; |
97 | + Notifications::publish(NoteShipWindow(serial(), NoteShipWindow::Action::kClose)); |
98 | ship_state_ = ShipStates::kSinkRequest; |
99 | // Make sure the ship is active and close possible open windows |
100 | ship_wakeup(game); |
101 | - close_window(); |
102 | } |
103 | |
104 | void Ship::draw(const EditorGameBase& game, RenderTarget& dst, const Point& pos) const { |
105 | |
106 | === modified file 'src/logic/map_objects/tribes/ship.h' |
107 | --- src/logic/map_objects/tribes/ship.h 2016-09-07 09:30:49 +0000 |
108 | +++ src/logic/map_objects/tribes/ship.h 2016-10-18 16:46:53 +0000 |
109 | @@ -28,11 +28,6 @@ |
110 | #include "graphic/diranimations.h" |
111 | #include "logic/map_objects/bob.h" |
112 | |
113 | -namespace UI { |
114 | -class Window; |
115 | -} |
116 | -class InteractiveGameBase; |
117 | - |
118 | namespace Widelands { |
119 | |
120 | class Economy; |
121 | @@ -59,6 +54,19 @@ |
122 | } |
123 | }; |
124 | |
125 | +struct NoteShipWindow { |
126 | + CAN_BE_SENT_AS_NOTE(NoteId::ShipWindow) |
127 | + |
128 | + Serial serial; |
129 | + |
130 | + enum class Action { kRefresh, kClose }; |
131 | + const Action action; |
132 | + |
133 | + NoteShipWindow(Serial init_serial, const Action& init_action) |
134 | + : serial(init_serial), action(init_action) { |
135 | + } |
136 | +}; |
137 | + |
138 | class ShipDescr : public BobDescr { |
139 | public: |
140 | ShipDescr(const std::string& init_descname, const LuaTable& t); |
141 | @@ -119,7 +127,7 @@ |
142 | void start_task_movetodock(Game&, PortDock&); |
143 | void start_task_expedition(Game&); |
144 | |
145 | - uint32_t calculate_sea_route(Game& game, PortDock& pd, Path* finalpath = nullptr); |
146 | + uint32_t calculate_sea_route(Game& game, PortDock& pd, Path* finalpath = nullptr) const; |
147 | |
148 | void log_general_info(const EditorGameBase&) override; |
149 | |
150 | @@ -133,10 +141,6 @@ |
151 | void withdraw_items(Game& game, PortDock& pd, std::vector<ShippingItem>& items); |
152 | void add_item(Game&, const ShippingItem& item); |
153 | |
154 | - void show_window(InteractiveGameBase&, bool avoid_fastclick = false); |
155 | - void close_window(); |
156 | - void refresh_window(InteractiveGameBase&); |
157 | - |
158 | // A ship with task expedition can be in four states: kExpeditionWaiting, kExpeditionScouting, |
159 | // kExpeditionPortspaceFound or kExpeditionColonizing in the first states, the owning player of |
160 | // this ship |
161 | @@ -169,42 +173,42 @@ |
162 | }; |
163 | |
164 | /// \returns the current state the ship is in |
165 | - ShipStates get_ship_state() { |
166 | + ShipStates get_ship_state() const { |
167 | return ship_state_; |
168 | } |
169 | |
170 | /// \returns the current name of ship |
171 | - const std::string& get_shipname() { |
172 | + const std::string& get_shipname() const { |
173 | return shipname_; |
174 | } |
175 | |
176 | /// \returns whether the ship is currently on an expedition |
177 | - bool state_is_expedition() { |
178 | + bool state_is_expedition() const { |
179 | return (ship_state_ == ShipStates::kExpeditionScouting || |
180 | ship_state_ == ShipStates::kExpeditionWaiting || |
181 | ship_state_ == ShipStates::kExpeditionPortspaceFound || |
182 | ship_state_ == ShipStates::kExpeditionColonizing); |
183 | } |
184 | /// \returns whether the ship is in transport mode |
185 | - bool state_is_transport() { |
186 | + bool state_is_transport() const { |
187 | return (ship_state_ == ShipStates::kTransport); |
188 | } |
189 | /// \returns whether a sink request for the ship is currently valid |
190 | - bool state_is_sinkable() { |
191 | + bool state_is_sinkable() const { |
192 | return (ship_state_ != ShipStates::kSinkRequest && |
193 | ship_state_ != ShipStates::kSinkAnimation && |
194 | ship_state_ != ShipStates::kExpeditionColonizing); |
195 | } |
196 | |
197 | /// \returns (in expedition mode only!) whether the next field in direction \arg dir is swimmable |
198 | - bool exp_dir_swimmable(Direction dir) { |
199 | + bool exp_dir_swimmable(Direction dir) const { |
200 | if (!expedition_) |
201 | return false; |
202 | return expedition_->swimmable[dir - 1]; |
203 | } |
204 | |
205 | /// \returns whether the expedition ship is close to the coast |
206 | - bool exp_close_to_coast() { |
207 | + bool exp_close_to_coast() const { |
208 | if (!expedition_) |
209 | return false; |
210 | for (uint8_t dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) |
211 | @@ -214,7 +218,7 @@ |
212 | } |
213 | |
214 | /// \returns (in expedition mode only!) the list of currently seen port build spaces |
215 | - const std::vector<Coords>& exp_port_spaces() { |
216 | + const std::vector<Coords>& exp_port_spaces() const { |
217 | return expedition_->seen_port_buildspaces; |
218 | } |
219 | |
220 | @@ -224,12 +228,12 @@ |
221 | |
222 | // Returns integer of direction, or WalkingDir::IDLE if query invalid |
223 | // Intended for LUA scripting |
224 | - WalkingDir get_scouting_direction(); |
225 | + WalkingDir get_scouting_direction() const; |
226 | |
227 | // Returns integer of direction, or IslandExploreDirection::kNotSet |
228 | // if query invalid |
229 | // Intended for LUA scripting |
230 | - IslandExploreDirection get_island_explore_direction(); |
231 | + IslandExploreDirection get_island_explore_direction() const; |
232 | |
233 | void exp_cancel(Game&); |
234 | void sink_ship(Game&); |
235 | @@ -239,7 +243,6 @@ |
236 | |
237 | private: |
238 | friend struct Fleet; |
239 | - friend struct ShipWindow; |
240 | |
241 | void wakeup_neighbours(Game&); |
242 | |
243 | @@ -261,8 +264,6 @@ |
244 | const std::string& description, |
245 | const std::string& picture); |
246 | |
247 | - UI::Window* window_; |
248 | - |
249 | Fleet* fleet_; |
250 | Economy* economy_; |
251 | OPtr<PortDock> lastdock_; |
252 | |
253 | === modified file 'src/notifications/note_ids.h' |
254 | --- src/notifications/note_ids.h 2016-03-03 21:46:11 +0000 |
255 | +++ src/notifications/note_ids.h 2016-10-18 16:46:53 +0000 |
256 | @@ -35,6 +35,7 @@ |
257 | ProductionSiteOutOfResources, |
258 | TrainingSiteSoldierTrained, |
259 | ShipMessage, |
260 | + ShipWindow, |
261 | GraphicResolutionChanged, |
262 | NoteExpeditionCanceled |
263 | }; |
264 | |
265 | === modified file 'src/wui/CMakeLists.txt' |
266 | --- src/wui/CMakeLists.txt 2016-04-15 17:23:00 +0000 |
267 | +++ src/wui/CMakeLists.txt 2016-10-18 16:46:53 +0000 |
268 | @@ -153,6 +153,7 @@ |
269 | quicknavigation.cc |
270 | quicknavigation.h |
271 | shipwindow.cc |
272 | + shipwindow.h |
273 | soldiercapacitycontrol.cc |
274 | soldiercapacitycontrol.h |
275 | soldierlist.cc |
276 | |
277 | === modified file 'src/wui/interactive_gamebase.cc' |
278 | --- src/wui/interactive_gamebase.cc 2016-08-04 15:49:05 +0000 |
279 | +++ src/wui/interactive_gamebase.cc 2016-10-18 16:46:53 +0000 |
280 | @@ -34,6 +34,7 @@ |
281 | #include "logic/player.h" |
282 | #include "profile/profile.h" |
283 | #include "wui/game_summary.h" |
284 | +#include "wui/shipwindow.h" |
285 | |
286 | namespace { |
287 | |
288 | @@ -158,7 +159,7 @@ |
289 | for (Widelands::Bob* temp_ship : ships) { |
290 | if (upcast(Widelands::Ship, ship, temp_ship)) { |
291 | if (can_see(ship->get_owner()->player_number())) { |
292 | - ship->show_window(*this); |
293 | + new ShipWindow(*this, *ship); |
294 | return true; |
295 | } |
296 | } |
297 | |
298 | === modified file 'src/wui/interactive_gamebase.h' |
299 | --- src/wui/interactive_gamebase.h 2016-08-04 15:49:05 +0000 |
300 | +++ src/wui/interactive_gamebase.h 2016-10-18 16:46:53 +0000 |
301 | @@ -31,8 +31,7 @@ |
302 | |
303 | class InteractiveGameBase : public InteractiveBase { |
304 | public: |
305 | - class GameMainMenuWindows { |
306 | - public: |
307 | + struct GameMainMenuWindows { |
308 | UI::UniqueWindow::Registry loadgame; |
309 | UI::UniqueWindow::Registry savegame; |
310 | UI::UniqueWindow::Registry readme; |
311 | |
312 | === modified file 'src/wui/shipwindow.cc' |
313 | --- src/wui/shipwindow.cc 2016-09-07 09:30:49 +0000 |
314 | +++ src/wui/shipwindow.cc 2016-10-18 16:46:53 +0000 |
315 | @@ -1,5 +1,5 @@ |
316 | /* |
317 | - * Copyright (C) 2011, 2013 by the Widelands Development Team |
318 | + * Copyright (C) 2011 - 2016 by the Widelands Development Team |
319 | * |
320 | * This program is free software; you can redistribute it and/or |
321 | * modify it under the terms of the GNU General Public License |
322 | @@ -17,7 +17,7 @@ |
323 | * |
324 | */ |
325 | |
326 | -#include "logic/map_objects/tribes/ship.h" |
327 | +#include "wui/shipwindow.h" |
328 | |
329 | #include "base/macros.h" |
330 | #include "economy/portdock.h" |
331 | @@ -29,10 +29,9 @@ |
332 | #include "ui_basic/box.h" |
333 | #include "wui/actionconfirm.h" |
334 | #include "wui/game_debug_ui.h" |
335 | -#include "wui/interactive_gamebase.h" |
336 | #include "wui/interactive_player.h" |
337 | -#include "wui/itemwaresdisplay.h" |
338 | |
339 | +namespace { |
340 | static const char pic_goto[] = "images/wui/ship/menu_ship_goto.png"; |
341 | static const char pic_destination[] = "images/wui/ship/menu_ship_destination.png"; |
342 | static const char pic_sink[] = "images/wui/ship/menu_ship_sink.png"; |
343 | @@ -47,70 +46,51 @@ |
344 | static const char pic_scout_sw[] = "images/wui/ship/ship_scout_sw.png"; |
345 | static const char pic_scout_se[] = "images/wui/ship/ship_scout_se.png"; |
346 | static const char pic_construct_port[] = "images/wui/editor/fsel_editor_set_port_space.png"; |
347 | - |
348 | -namespace Widelands { |
349 | - |
350 | -/** |
351 | - * Display information about a ship. |
352 | - */ |
353 | -struct ShipWindow : UI::Window { |
354 | - ShipWindow(InteractiveGameBase& igb, Ship& ship, const std::string& title); |
355 | - virtual ~ShipWindow(); |
356 | - |
357 | - void think() override; |
358 | - |
359 | - UI::Button* make_button(UI::Panel* parent, |
360 | - const std::string& name, |
361 | - const std::string& title, |
362 | - const std::string& picname, |
363 | - boost::function<void()> callback); |
364 | - |
365 | - void act_goto(); |
366 | - void act_destination(); |
367 | - void act_sink(); |
368 | - void act_debug(); |
369 | - void act_cancel_expedition(); |
370 | - void act_scout_towards(WalkingDir); |
371 | - void act_construct_port(); |
372 | - void act_explore_island(IslandExploreDirection); |
373 | - |
374 | -private: |
375 | - InteractiveGameBase& igbase_; |
376 | - Ship& ship_; |
377 | - |
378 | - UI::Button* btn_goto_; |
379 | - UI::Button* btn_destination_; |
380 | - UI::Button* btn_sink_; |
381 | - UI::Button* btn_debug_; |
382 | - UI::Button* btn_cancel_expedition_; |
383 | - UI::Button* btn_explore_island_cw_; |
384 | - UI::Button* btn_explore_island_ccw_; |
385 | - UI::Button* |
386 | - btn_scout_[LAST_DIRECTION]; // format: DIRECTION - 1, as 0 is normally the current location. |
387 | - UI::Button* btn_construct_port_; |
388 | - ItemWaresDisplay* display_; |
389 | -}; |
390 | - |
391 | -ShipWindow::ShipWindow(InteractiveGameBase& igb, Ship& ship, const std::string& title) |
392 | - : Window(&igb, "shipwindow", 0, 0, 0, 0, title), igbase_(igb), ship_(ship) { |
393 | - assert(!ship_.window_); |
394 | +} // namespace |
395 | + |
396 | +using namespace Widelands; |
397 | + |
398 | +ShipWindow::ShipWindow(InteractiveGameBase& igb, Ship& ship) |
399 | + : Window(&igb, "shipwindow", 0, 0, 0, 0, ship.get_shipname()), igbase_(igb), ship_(ship) { |
400 | + init(false); |
401 | + shipnotes_subscriber_ = Notifications::subscribe<Widelands::NoteShipWindow>( |
402 | + [this](const Widelands::NoteShipWindow& note) { |
403 | + if (note.serial == ship_.serial()) { |
404 | + switch (note.action) { |
405 | + // The ship state has changed, e.g. expedition canceled |
406 | + case Widelands::NoteShipWindow::Action::kRefresh: |
407 | + init(true); |
408 | + break; |
409 | + // The ship is no more |
410 | + case Widelands::NoteShipWindow::Action::kClose: |
411 | + // Stop this from thinking to avoid segfaults |
412 | + set_thinks(false); |
413 | + die(); |
414 | + break; |
415 | + default: |
416 | + break; |
417 | + } |
418 | + } |
419 | + }); |
420 | +} |
421 | + |
422 | +void ShipWindow::init(bool avoid_fastclick) { |
423 | assert(ship_.get_owner()); |
424 | - ship_.window_ = this; |
425 | - |
426 | - UI::Box* vbox = new UI::Box(this, 0, 0, UI::Box::Vertical); |
427 | - |
428 | - display_ = new ItemWaresDisplay(vbox, *ship.get_owner()); |
429 | - display_->set_capacity(ship.descr().get_capacity()); |
430 | - vbox->add(display_, UI::Align::kHCenter, false); |
431 | + |
432 | + vbox_.reset(new UI::Box(this, 0, 0, UI::Box::Vertical)); |
433 | + |
434 | + display_ = new ItemWaresDisplay(vbox_.get(), *ship_.get_owner()); |
435 | + display_->set_capacity(ship_.descr().get_capacity()); |
436 | + vbox_->add(display_, UI::Align::kHCenter, false); |
437 | |
438 | // Expedition buttons |
439 | if (ship_.state_is_expedition()) { |
440 | - UI::Box* exp_top = new UI::Box(vbox, 0, 0, UI::Box::Horizontal); |
441 | - vbox->add(exp_top, UI::Align::kHCenter, false); |
442 | - UI::Box* exp_mid = new UI::Box(vbox, 0, 0, UI::Box::Horizontal); |
443 | - vbox->add(exp_mid, UI::Align::kHCenter, false); |
444 | - UI::Box* exp_bot = new UI::Box(vbox, 0, 0, UI::Box::Horizontal); |
445 | - vbox->add(exp_bot, UI::Align::kHCenter, false); |
446 | + UI::Box* exp_top = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal); |
447 | + vbox_->add(exp_top, UI::Align::kHCenter, false); |
448 | + UI::Box* exp_mid = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal); |
449 | + vbox_->add(exp_mid, UI::Align::kHCenter, false); |
450 | + UI::Box* exp_bot = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal); |
451 | + vbox_->add(exp_bot, UI::Align::kHCenter, false); |
452 | |
453 | btn_scout_[WALK_NW - 1] = |
454 | make_button(exp_top, "scnw", _("Scout towards the north west"), pic_scout_nw, |
455 | @@ -160,8 +140,8 @@ |
456 | } |
457 | |
458 | // Bottom buttons |
459 | - UI::Box* buttons = new UI::Box(vbox, 0, 0, UI::Box::Horizontal); |
460 | - vbox->add(buttons, UI::Align::kLeft, false); |
461 | + UI::Box* buttons = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal); |
462 | + vbox_->add(buttons, UI::Align::kLeft, false); |
463 | |
464 | btn_goto_ = make_button( |
465 | buttons, "goto", _("Go to ship"), pic_goto, boost::bind(&ShipWindow::act_goto, this)); |
466 | @@ -188,17 +168,13 @@ |
467 | btn_debug_->set_enabled(true); |
468 | buttons->add(btn_debug_, UI::Align::kLeft, false); |
469 | } |
470 | - set_center_panel(vbox); |
471 | + set_center_panel(vbox_.get()); |
472 | set_thinks(true); |
473 | - |
474 | - center_to_parent(); |
475 | - move_out_of_the_way(); |
476 | set_fastclick_panel(btn_goto_); |
477 | -} |
478 | - |
479 | -ShipWindow::~ShipWindow() { |
480 | - assert(ship_.window_ == this); |
481 | - ship_.window_ = nullptr; |
482 | + if (!avoid_fastclick) { |
483 | + move_out_of_the_way(); |
484 | + warp_mouse_to_fastclick_panel(); |
485 | + } |
486 | } |
487 | |
488 | void ShipWindow::think() { |
489 | @@ -335,52 +311,3 @@ |
490 | return; |
491 | igbase_.game().send_player_ship_explore_island(ship_, direction); |
492 | } |
493 | - |
494 | -/** |
495 | - * Show the window for this ship as long as it is not sinking: |
496 | - * either bring it to the front, or create it. |
497 | - */ |
498 | -void Ship::show_window(InteractiveGameBase& igb, bool avoid_fastclick) { |
499 | - // No window, if ship is sinking |
500 | - if (ship_state_ == ShipStates::kSinkRequest || ship_state_ == ShipStates::kSinkAnimation) |
501 | - return; |
502 | - |
503 | - if (window_) { |
504 | - if (window_->is_minimal()) |
505 | - window_->restore(); |
506 | - window_->move_to_top(); |
507 | - } else { |
508 | - const std::string& title = get_shipname(); |
509 | - new ShipWindow(igb, *this, title); |
510 | - if (!avoid_fastclick) |
511 | - window_->warp_mouse_to_fastclick_panel(); |
512 | - } |
513 | -} |
514 | - |
515 | -/** |
516 | - * Close the window for this ship. |
517 | - */ |
518 | -void Ship::close_window() { |
519 | - if (window_) { |
520 | - delete window_; |
521 | - window_ = nullptr; |
522 | - } |
523 | -} |
524 | - |
525 | -/** |
526 | - * refreshes the window of this ship - useful if some ui elements have to be removed or added |
527 | - */ |
528 | -void Ship::refresh_window(InteractiveGameBase& igb) { |
529 | - // Only do something if there is actually a window |
530 | - if (window_) { |
531 | - Point window_position = window_->get_pos(); |
532 | - close_window(); |
533 | - show_window(igb, true); |
534 | - // show window could theoretically fail if refresh_window was called at the very same moment |
535 | - // as the ship begins to sink |
536 | - if (window_) |
537 | - window_->set_pos(window_position); |
538 | - } |
539 | -} |
540 | - |
541 | -} // namespace Widelands |
542 | |
543 | === added file 'src/wui/shipwindow.h' |
544 | --- src/wui/shipwindow.h 1970-01-01 00:00:00 +0000 |
545 | +++ src/wui/shipwindow.h 2016-10-18 16:46:53 +0000 |
546 | @@ -0,0 +1,81 @@ |
547 | +/* |
548 | + * Copyright (C) 2011 - 2016 by the Widelands Development Team |
549 | + * |
550 | + * This program is free software; you can redistribute it and/or |
551 | + * modify it under the terms of the GNU General Public License |
552 | + * as published by the Free Software Foundation; either version 2 |
553 | + * of the License, or (at your option) any later version. |
554 | + * |
555 | + * This program is distributed in the hope that it will be useful, |
556 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
557 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
558 | + * GNU General Public License for more details. |
559 | + * |
560 | + * You should have received a copy of the GNU General Public License |
561 | + * along with this program; if not, write to the Free Software |
562 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
563 | + * |
564 | + */ |
565 | + |
566 | +#ifndef WL_WUI_SHIPWINDOW_H |
567 | +#define WL_WUI_SHIPWINDOW_H |
568 | + |
569 | +#include <memory> |
570 | + |
571 | +#include "logic/game.h" |
572 | +#include "logic/map_objects/tribes/ship.h" |
573 | +#include "logic/map_objects/walkingdir.h" |
574 | +#include "notifications/notifications.h" |
575 | +#include "ui_basic/button.h" |
576 | +#include "ui_basic/window.h" |
577 | +#include "wui/interactive_gamebase.h" |
578 | +#include "wui/itemwaresdisplay.h" |
579 | + |
580 | +/** |
581 | + * Display information about a ship. |
582 | + */ |
583 | +class ShipWindow : public UI::Window { |
584 | +public: |
585 | + ShipWindow(InteractiveGameBase& igb, Widelands::Ship& ship); |
586 | + |
587 | +private: |
588 | + // Resets the vbox_ and fills it with the currently needed buttons, then positions the window. |
589 | + void init(bool avoid_fastclick); |
590 | + |
591 | + void think() override; |
592 | + |
593 | + UI::Button* make_button(UI::Panel* parent, |
594 | + const std::string& name, |
595 | + const std::string& title, |
596 | + const std::string& picname, |
597 | + boost::function<void()> callback); |
598 | + |
599 | + void act_goto(); |
600 | + void act_destination(); |
601 | + void act_sink(); |
602 | + void act_debug(); |
603 | + void act_cancel_expedition(); |
604 | + void act_scout_towards(Widelands::WalkingDir); |
605 | + void act_construct_port(); |
606 | + void act_explore_island(Widelands::IslandExploreDirection); |
607 | + |
608 | + InteractiveGameBase& igbase_; |
609 | + Widelands::Ship& ship_; |
610 | + |
611 | + std::unique_ptr<UI::Box> vbox_; |
612 | + UI::Button* btn_goto_; |
613 | + UI::Button* btn_destination_; |
614 | + UI::Button* btn_sink_; |
615 | + UI::Button* btn_debug_; |
616 | + UI::Button* btn_cancel_expedition_; |
617 | + UI::Button* btn_explore_island_cw_; |
618 | + UI::Button* btn_explore_island_ccw_; |
619 | + // format: DIRECTION - 1, as 0 is normally the current location. |
620 | + UI::Button* btn_scout_[Widelands::LAST_DIRECTION]; |
621 | + UI::Button* btn_construct_port_; |
622 | + ItemWaresDisplay* display_; |
623 | + std::unique_ptr<Notifications::Subscriber<Widelands::NoteShipWindow>> shipnotes_subscriber_; |
624 | + DISALLOW_COPY_AND_ASSIGN(ShipWindow); |
625 | +}; |
626 | + |
627 | +#endif // end of include guard: WL_WUI_SHIPWINDOW_H |
Continuous integration builds have changed state:
Travis build 1373. State: passed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 163454001. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ notifications_ shipwindow- 1215.
Appveyor build 1215. State: success. Details: https:/