Merge lp:~widelands-dev/widelands/bug-1664052-expedition-shipwindow-crash into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8424
Proposed branch: lp:~widelands-dev/widelands/bug-1664052-expedition-shipwindow-crash
Merge into: lp:widelands
Diff against target: 431 lines (+152/-125)
5 files modified
src/economy/portdock.cc (+0/-1)
src/logic/map_objects/tribes/ship.cc (+0/-5)
src/wui/itemwaresdisplay.cc (+22/-6)
src/wui/shipwindow.cc (+126/-109)
src/wui/shipwindow.h (+4/-4)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1664052-expedition-shipwindow-crash
Reviewer Review Type Date Requested Status
Klaus Halfmann review, compile Approve
GunChleoc Needs Resubmitting
kaputtnik (community) testing Approve
Review via email: mp+318986@code.launchpad.net

Commit message

Do not delete/recreate buttons in the ship window. This fixes a segfault with the button signals. This also makes NoteShipWindow::Action::kRefresh obsolete. Also, some layout tweaks to the shipwindow.

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

Started and canceled an expedition about 10 times and no crash anymore.

What i noticed:
1. The Black 'Cargo-space' does not fill the entire window anymore... intended?
2. If an expedition is canceled the button 'Cancel expedition is removed from the ship window. But if you close the ship window and reopen it, the button is there again.

An Idea to 1.: Is it possible to have an image there where the black area is? I am thinking of a wooden ship hold with some book shelf, enlightened with a candle or so... :-D

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2037. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/207741358.
Appveyor build 1872. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1664052_expedition_shipwindow_crash-1872.

Revision history for this message
GunChleoc (gunchleoc) wrote :

1. I added some padding around the navigation buttons, if this is what you mean. A background image would be possible, but someone needs to make one first - that's beyond my skills. Let me know if you want to try - I will code a branch then so you can drop in the image and see it in-game.

2. Thanks, should be fixed now.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2040. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/207850688.
Appveyor build 1875. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1664052_expedition_shipwindow_crash-1875.

Revision history for this message
kaputtnik (franku) wrote :

Ah, ok i see... i meant formerly the black area fits the whole inner window, whereas now there is some space on the left and right between window border and black area. It looks like the black area is in the air somehow.

I have no time (and maybe no experience) for creating such an image i mentioned. But maybe it is possible to have something like shown in the bottom of this mockup: https://bugs.launchpad.net/widelands/+bug/1664052/+attachment/4831701/+files/laderaum_1.png (just compared ship windows: Old style, this branch, and a suggestion)

Otherwise looks good :-)

Revision history for this message
GunChleoc (gunchleoc) wrote :

I like the mockup - should be doable :)

Revision history for this message
GunChleoc (gunchleoc) wrote :

Prettification is done.

I also rearranged the buttons on the bottom - the shipwindow was the only window where the goto-button is on the left.

Revision history for this message
kaputtnik (franku) wrote :

Looks good :-)

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

Continuous integration builds have changed state:

Travis build 2056. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/209994662.
Appveyor build 1891. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1664052_expedition_shipwindow_crash-1891.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2094. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/223928118.
Appveyor build 1929. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1664052_expedition_shipwindow_crash-1929.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2116. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/225038488.
Appveyor build 1951. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1664052_expedition_shipwindow_crash-1951.

Revision history for this message
GunChleoc (gunchleoc) wrote :

*bump* I'd like this branch to be next in line for code review.

review: Needs Resubmitting
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Mhh, this looks familiar, we had a similar Issue where some Notfication was caught by some other ship.
Ill try to have a lok tonight.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

What I get is that you moved around some code from ::init to the CTor for that shipwindow.
See som inline comments.

I see no obvious Problems in that code, no let mey try to download it from appvoyer ors such.

review: Approve (review, compile)
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the review :)

Kaputtnik has already tested this branch, so I'll merge trunk and then get this in.

Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/economy/portdock.cc'
2--- src/economy/portdock.cc 2017-07-01 15:36:36 +0000
3+++ src/economy/portdock.cc 2017-08-16 04:49:28 +0000
4@@ -337,7 +337,6 @@
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- Notifications::publish(NoteShipWindow(ship.serial(), NoteShipWindow::Action::kRefresh));
9 return fleet_->update(game);
10 }
11 }
12
13=== modified file 'src/logic/map_objects/tribes/ship.cc'
14--- src/logic/map_objects/tribes/ship.cc 2017-08-09 19:25:04 +0000
15+++ src/logic/map_objects/tribes/ship.cc 2017-08-16 04:49:28 +0000
16@@ -680,8 +680,6 @@
17 }
18
19 expedition_.reset(nullptr);
20-
21- Notifications::publish(NoteShipWindow(serial(), NoteShipWindow::Action::kRefresh));
22 return start_task_idle(game, descr().main_animation(), 1500);
23 }
24 }
25@@ -942,9 +940,6 @@
26
27 // Delete the expedition and the economy it created.
28 expedition_.reset(nullptr);
29-
30- // And finally update our ship window
31- Notifications::publish(NoteShipWindow(serial(), NoteShipWindow::Action::kRefresh));
32 }
33
34 /// Sinks the ship
35
36=== modified file 'src/wui/itemwaresdisplay.cc'
37--- src/wui/itemwaresdisplay.cc 2017-06-23 17:23:04 +0000
38+++ src/wui/itemwaresdisplay.cc 2017-08-16 04:49:28 +0000
39@@ -22,16 +22,18 @@
40 #include "graphic/rendertarget.h"
41 #include "logic/map_objects/tribes/tribe_descr.h"
42 #include "logic/player.h"
43+#include "ui_basic/mouse_constants.h"
44
45 namespace {
46
47+constexpr int kMargin = 4;
48 static const uint32_t IWD_HBorder = 10;
49 static const uint32_t IWD_VBorder = 10;
50 static const uint32_t IWD_DefaultItemsPerRow = 9;
51 static const uint32_t IWD_ItemWidth = 14;
52 static const uint32_t IWD_ItemHeight = 26;
53 static const uint32_t IWD_WorkerBaseline =
54- -2; ///< Offset of anim center from bottom border of item rect
55+ 2; ///< Offset of anim center from bottom border of item rect
56 static const uint32_t IWD_WareBaseLine = -6;
57
58 } // anonymous namespace
59@@ -44,7 +46,7 @@
60 player_(gplayer),
61 capacity_(0),
62 items_per_row_(IWD_DefaultItemsPerRow) {
63- set_desired_size(2 * IWD_HBorder, 2 * IWD_VBorder);
64+ recalc_desired_size();
65 }
66
67 /**
68@@ -72,7 +74,7 @@
69 uint32_t rowitems = capacity_ >= items_per_row_ ? items_per_row_ : capacity_;
70
71 set_desired_size(
72- 2 * IWD_HBorder + rowitems * IWD_ItemWidth, 2 * IWD_VBorder + nrrows * IWD_ItemHeight);
73+ 2 * (IWD_HBorder + kMargin) + rowitems * IWD_ItemWidth, 2 * (IWD_VBorder + kMargin) + nrrows * IWD_ItemHeight);
74 }
75
76 /**
77@@ -88,15 +90,29 @@
78 void ItemWaresDisplay::draw(RenderTarget& dst) {
79 const Widelands::TribeDescr& tribe(player().tribe());
80
81- dst.fill_rect(Recti(0, 0, get_w(), get_h()), RGBAColor(0, 0, 0, 0));
82+ // Snazzy background
83+ const int width = get_w() - 2 * kMargin;
84+ const int height = get_h() - 2 * kMargin;
85+ RGBAColor black(0, 0, 0, 255);
86+ dst.brighten_rect(Recti(kMargin, kMargin, width - 1, height - 1), -BUTTON_EDGE_BRIGHT_FACTOR / 2);
87+ // bottom edge
88+ dst.brighten_rect(Recti(kMargin, height + 2, width, 2), 1.5 * BUTTON_EDGE_BRIGHT_FACTOR);
89+ // right edge
90+ dst.brighten_rect(Recti(kMargin + width - 2, kMargin, 2, height - 2), 1.5 * BUTTON_EDGE_BRIGHT_FACTOR);
91+ // top edge
92+ dst.fill_rect(Recti(kMargin, kMargin, width - 1, 1), black);
93+ dst.fill_rect(Recti(kMargin, kMargin + 1, width - 2, 1), black);
94+ // left edge
95+ dst.fill_rect(Recti(kMargin, kMargin, 1, height - 1), black);
96+ dst.fill_rect(Recti(kMargin + 1, kMargin, 1, height - 2), black);
97
98 for (uint32_t idx = 0; idx < items_.size(); ++idx) {
99 const Item& it = items_[idx];
100 uint32_t row = idx / items_per_row_;
101 uint32_t col = idx % items_per_row_;
102
103- uint32_t x = IWD_HBorder / 2 + col * IWD_ItemWidth;
104- uint32_t y = IWD_VBorder + row * IWD_ItemHeight;
105+ uint32_t x = IWD_HBorder / 2 + col * IWD_ItemWidth + kMargin;
106+ uint32_t y = IWD_VBorder + row * IWD_ItemHeight + kMargin;
107
108 if (it.worker) {
109 y += IWD_WorkerBaseline;
110
111=== modified file 'src/wui/shipwindow.cc'
112--- src/wui/shipwindow.cc 2017-06-20 08:18:38 +0000
113+++ src/wui/shipwindow.cc 2017-08-16 04:49:28 +0000
114@@ -47,13 +47,117 @@
115 static const char pic_scout_sw[] = "images/wui/ship/ship_scout_sw.png";
116 static const char pic_scout_se[] = "images/wui/ship/ship_scout_se.png";
117 static const char pic_construct_port[] = "images/wui/editor/fsel_editor_set_port_space.png";
118+
119+constexpr int kPadding = 5;
120 } // namespace
121
122 using namespace Widelands;
123
124 ShipWindow::ShipWindow(InteractiveGameBase& igb, UniqueWindow::Registry& reg, Ship& ship)
125- : UniqueWindow(&igb, "shipwindow", &reg, 0, 0, ship.get_shipname()), igbase_(igb), ship_(ship) {
126- init(false);
127+ : UniqueWindow(&igb, "shipwindow", &reg, 0, 0, ship.get_shipname()),
128+ igbase_(igb),
129+ ship_(ship),
130+ vbox_(this, 0, 0, UI::Box::Vertical),
131+ navigation_box_(&vbox_, 0, 0, UI::Box::Vertical),
132+ navigation_box_height_(0) {
133+ vbox_.set_inner_spacing(kPadding);
134+ assert(ship_.get_owner());
135+
136+ display_ = new ItemWaresDisplay(&vbox_, *ship_.get_owner());
137+ display_->set_capacity(ship_.descr().get_capacity());
138+ vbox_.add(display_, UI::Box::Resizing::kAlign, UI::Align::kCenter);
139+
140+ // Expedition buttons
141+ UI::Box* exp_top = new UI::Box(&navigation_box_, 0, 0, UI::Box::Horizontal);
142+ navigation_box_.add(exp_top, UI::Box::Resizing::kAlign, UI::Align::kCenter);
143+ UI::Box* exp_mid = new UI::Box(&navigation_box_, 0, 0, UI::Box::Horizontal);
144+ navigation_box_.add(exp_mid, UI::Box::Resizing::kAlign, UI::Align::kCenter);
145+ UI::Box* exp_bot = new UI::Box(&navigation_box_, 0, 0, UI::Box::Horizontal);
146+ navigation_box_.add(exp_bot, UI::Box::Resizing::kAlign, UI::Align::kCenter);
147+
148+ btn_scout_[WALK_NW - 1] =
149+ make_button(exp_top, "scnw", _("Scout towards the north west"), pic_scout_nw,
150+ boost::bind(&ShipWindow::act_scout_towards, this, WALK_NW));
151+ exp_top->add(btn_scout_[WALK_NW - 1]);
152+
153+ btn_explore_island_cw_ = make_button(
154+ exp_top, "expcw", _("Explore the island’s coast clockwise"), pic_explore_cw,
155+ boost::bind(&ShipWindow::act_explore_island, this, IslandExploreDirection::kClockwise));
156+ exp_top->add(btn_explore_island_cw_);
157+
158+ btn_scout_[WALK_NE - 1] =
159+ make_button(exp_top, "scne", _("Scout towards the north east"), pic_scout_ne,
160+ boost::bind(&ShipWindow::act_scout_towards, this, WALK_NE));
161+ exp_top->add(btn_scout_[WALK_NE - 1]);
162+
163+ btn_scout_[WALK_W - 1] = make_button(exp_mid, "scw", _("Scout towards the west"), pic_scout_w,
164+ boost::bind(&ShipWindow::act_scout_towards, this, WALK_W));
165+ exp_mid->add(btn_scout_[WALK_W - 1]);
166+
167+ btn_construct_port_ =
168+ make_button(exp_mid, "buildport", _("Construct a port at the current location"),
169+ pic_construct_port, boost::bind(&ShipWindow::act_construct_port, this));
170+ exp_mid->add(btn_construct_port_);
171+
172+ btn_scout_[WALK_E - 1] = make_button(exp_mid, "sce", _("Scout towards the east"), pic_scout_e,
173+ boost::bind(&ShipWindow::act_scout_towards, this, WALK_E));
174+ exp_mid->add(btn_scout_[WALK_E - 1]);
175+
176+ btn_scout_[WALK_SW - 1] =
177+ make_button(exp_bot, "scsw", _("Scout towards the south west"), pic_scout_sw,
178+ boost::bind(&ShipWindow::act_scout_towards, this, WALK_SW));
179+ exp_bot->add(btn_scout_[WALK_SW - 1]);
180+
181+ btn_explore_island_ccw_ =
182+ make_button(exp_bot, "expccw", _("Explore the island’s coast counter clockwise"),
183+ pic_explore_ccw, boost::bind(&ShipWindow::act_explore_island, this,
184+ IslandExploreDirection::kCounterClockwise));
185+ exp_bot->add(btn_explore_island_ccw_);
186+
187+ btn_scout_[WALK_SE - 1] =
188+ make_button(exp_bot, "scse", _("Scout towards the south east"), pic_scout_se,
189+ boost::bind(&ShipWindow::act_scout_towards, this, WALK_SE));
190+ exp_bot->add(btn_scout_[WALK_SE - 1]);
191+
192+ vbox_.add(&navigation_box_, UI::Box::Resizing::kAlign, UI::Align::kCenter);
193+
194+ // Bottom buttons
195+ UI::Box* buttons = new UI::Box(&vbox_, 0, 0, UI::Box::Horizontal);
196+ vbox_.add(buttons, UI::Box::Resizing::kFullSize);
197+
198+ btn_sink_ = make_button(
199+ buttons, "sink", _("Sink the ship"), pic_sink, boost::bind(&ShipWindow::act_sink, this));
200+ buttons->add(btn_sink_);
201+
202+ btn_cancel_expedition_ =
203+ make_button(buttons, "cancel_expedition", _("Cancel the Expedition"), pic_cancel_expedition,
204+ boost::bind(&ShipWindow::act_cancel_expedition, this));
205+ buttons->add(btn_cancel_expedition_);
206+
207+ buttons->add_inf_space();
208+
209+ if (igbase_.get_display_flag(InteractiveBase::dfDebug)) {
210+ btn_debug_ = make_button(buttons, "debug", _("Show Debug Window"), pic_debug,
211+ boost::bind(&ShipWindow::act_debug, this));
212+ btn_debug_->set_enabled(true);
213+ buttons->add(btn_debug_);
214+ }
215+
216+ btn_destination_ = make_button(buttons, "destination", _("Go to destination"), pic_destination,
217+ boost::bind(&ShipWindow::act_destination, this));
218+ btn_destination_->set_enabled(false);
219+ buttons->add(btn_destination_);
220+
221+ btn_goto_ = make_button(
222+ buttons, "goto", _("Go to ship"), pic_goto, boost::bind(&ShipWindow::act_goto, this));
223+ buttons->add(btn_goto_);
224+
225+ set_center_panel(&vbox_);
226+ set_thinks(true);
227+ set_fastclick_panel(btn_goto_);
228+ move_out_of_the_way();
229+ warp_mouse_to_fastclick_panel();
230+
231 shipnotes_subscriber_ = Notifications::subscribe<Widelands::NoteShipWindow>([this](
232 const Widelands::NoteShipWindow& note) {
233 if (note.serial == ship_.serial()) {
234@@ -72,10 +176,6 @@
235 }
236 }
237 break;
238- // The ship state has changed, e.g. expedition canceled
239- case Widelands::NoteShipWindow::Action::kRefresh:
240- init(true);
241- break;
242 // The ship is no more
243 case Widelands::NoteShipWindow::Action::kClose:
244 // Stop this from thinking to avoid segfaults
245@@ -85,108 +185,24 @@
246 }
247 }
248 });
249+
250+ // Init button visibility
251+ navigation_box_height_ = navigation_box_.get_h();
252+ navigation_box_.set_visible(false);
253+ navigation_box_.set_desired_size(navigation_box_.get_w(), 0);
254+ btn_cancel_expedition_->set_enabled(false);
255+ think();
256 }
257
258-void ShipWindow::init(bool avoid_fastclick) {
259- assert(ship_.get_owner());
260-
261- vbox_.reset(new UI::Box(this, 0, 0, UI::Box::Vertical));
262-
263- display_ = new ItemWaresDisplay(vbox_.get(), *ship_.get_owner());
264- display_->set_capacity(ship_.descr().get_capacity());
265- vbox_->add(display_, UI::Box::Resizing::kAlign, UI::Align::kCenter);
266-
267- // Expedition buttons
268- if (ship_.state_is_expedition()) {
269- UI::Box* exp_top = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal);
270- vbox_->add(exp_top, UI::Box::Resizing::kAlign, UI::Align::kCenter);
271- UI::Box* exp_mid = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal);
272- vbox_->add(exp_mid, UI::Box::Resizing::kAlign, UI::Align::kCenter);
273- UI::Box* exp_bot = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal);
274- vbox_->add(exp_bot, UI::Box::Resizing::kAlign, UI::Align::kCenter);
275-
276- btn_scout_[WALK_NW - 1] =
277- make_button(exp_top, "scnw", _("Scout towards the north west"), pic_scout_nw,
278- boost::bind(&ShipWindow::act_scout_towards, this, WALK_NW));
279- exp_top->add(btn_scout_[WALK_NW - 1]);
280-
281- btn_explore_island_cw_ = make_button(
282- exp_top, "expcw", _("Explore the island’s coast clockwise"), pic_explore_cw,
283- boost::bind(&ShipWindow::act_explore_island, this, IslandExploreDirection::kClockwise));
284- exp_top->add(btn_explore_island_cw_);
285-
286- btn_scout_[WALK_NE - 1] =
287- make_button(exp_top, "scne", _("Scout towards the north east"), pic_scout_ne,
288- boost::bind(&ShipWindow::act_scout_towards, this, WALK_NE));
289- exp_top->add(btn_scout_[WALK_NE - 1]);
290-
291- btn_scout_[WALK_W - 1] =
292- make_button(exp_mid, "scw", _("Scout towards the west"), pic_scout_w,
293- boost::bind(&ShipWindow::act_scout_towards, this, WALK_W));
294- exp_mid->add(btn_scout_[WALK_W - 1]);
295-
296- btn_construct_port_ =
297- make_button(exp_mid, "buildport", _("Construct a port at the current location"),
298- pic_construct_port, boost::bind(&ShipWindow::act_construct_port, this));
299- exp_mid->add(btn_construct_port_);
300-
301- btn_scout_[WALK_E - 1] =
302- make_button(exp_mid, "sce", _("Scout towards the east"), pic_scout_e,
303- boost::bind(&ShipWindow::act_scout_towards, this, WALK_E));
304- exp_mid->add(btn_scout_[WALK_E - 1]);
305-
306- btn_scout_[WALK_SW - 1] =
307- make_button(exp_bot, "scsw", _("Scout towards the south west"), pic_scout_sw,
308- boost::bind(&ShipWindow::act_scout_towards, this, WALK_SW));
309- exp_bot->add(btn_scout_[WALK_SW - 1]);
310-
311- btn_explore_island_ccw_ =
312- make_button(exp_bot, "expccw", _("Explore the island’s coast counter clockwise"),
313- pic_explore_ccw, boost::bind(&ShipWindow::act_explore_island, this,
314- IslandExploreDirection::kCounterClockwise));
315- exp_bot->add(btn_explore_island_ccw_);
316-
317- btn_scout_[WALK_SE - 1] =
318- make_button(exp_bot, "scse", _("Scout towards the south east"), pic_scout_se,
319- boost::bind(&ShipWindow::act_scout_towards, this, WALK_SE));
320- exp_bot->add(btn_scout_[WALK_SE - 1]);
321- }
322-
323- // Bottom buttons
324- UI::Box* buttons = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal);
325- vbox_->add(buttons);
326-
327- btn_goto_ = make_button(
328- buttons, "goto", _("Go to ship"), pic_goto, boost::bind(&ShipWindow::act_goto, this));
329- buttons->add(btn_goto_);
330- btn_destination_ = make_button(buttons, "destination", _("Go to destination"), pic_destination,
331- boost::bind(&ShipWindow::act_destination, this));
332- btn_destination_->set_enabled(false);
333- buttons->add(btn_destination_);
334-
335- btn_sink_ = make_button(
336- buttons, "sink", _("Sink the ship"), pic_sink, boost::bind(&ShipWindow::act_sink, this));
337- buttons->add(btn_sink_);
338-
339- if (ship_.state_is_expedition()) {
340- btn_cancel_expedition_ =
341- make_button(buttons, "cancel_expedition", _("Cancel the Expedition"),
342- pic_cancel_expedition, boost::bind(&ShipWindow::act_cancel_expedition, this));
343- buttons->add(btn_cancel_expedition_);
344- }
345-
346- if (igbase_.get_display_flag(InteractiveBase::dfDebug)) {
347- btn_debug_ = make_button(buttons, "debug", _("Show Debug Window"), pic_debug,
348- boost::bind(&ShipWindow::act_debug, this));
349- btn_debug_->set_enabled(true);
350- buttons->add(btn_debug_);
351- }
352- set_center_panel(vbox_.get());
353- set_thinks(true);
354- set_fastclick_panel(btn_goto_);
355- if (!avoid_fastclick) {
356- move_out_of_the_way();
357- warp_mouse_to_fastclick_panel();
358+void ShipWindow::set_button_visibility() {
359+ if (navigation_box_.is_visible() != ship_.state_is_expedition()) {
360+ navigation_box_.set_visible(ship_.state_is_expedition());
361+ navigation_box_.set_desired_size(
362+ navigation_box_.get_w(), ship_.state_is_expedition() ? navigation_box_height_ : 0);
363+ layout();
364+ }
365+ if (btn_cancel_expedition_->is_visible() != btn_cancel_expedition_->enabled()) {
366+ btn_cancel_expedition_->set_visible(btn_cancel_expedition_->enabled());
367 }
368 }
369
370@@ -215,7 +231,6 @@
371 }
372 }
373
374- // Expedition specific buttons
375 Ship::ShipStates state = ship_.get_ship_state();
376 if (ship_.state_is_expedition()) {
377 /* The following rules apply:
378@@ -243,9 +258,11 @@
379 btn_explore_island_ccw_->set_enabled(can_act && coast_nearby &&
380 (state != Ship::ShipStates::kExpeditionColonizing));
381 btn_sink_->set_enabled(can_act && (state != Ship::ShipStates::kExpeditionColonizing));
382- btn_cancel_expedition_->set_enabled(can_act &&
383- (state != Ship::ShipStates::kExpeditionColonizing));
384 }
385+ btn_cancel_expedition_->set_enabled(ship_.state_is_expedition() && can_act &&
386+ (state != Ship::ShipStates::kExpeditionColonizing));
387+ // Expedition specific buttons
388+ set_button_visibility();
389 }
390
391 UI::Button* ShipWindow::make_button(UI::Panel* parent,
392
393=== modified file 'src/wui/shipwindow.h'
394--- src/wui/shipwindow.h 2017-02-21 20:38:33 +0000
395+++ src/wui/shipwindow.h 2017-08-16 04:49:28 +0000
396@@ -39,9 +39,6 @@
397 ShipWindow(InteractiveGameBase& igb, UI::UniqueWindow::Registry& reg, Widelands::Ship& ship);
398
399 private:
400- // Resets the vbox_ and fills it with the currently needed buttons, then positions the window.
401- void init(bool avoid_fastclick);
402-
403 void think() override;
404
405 UI::Button* make_button(UI::Panel* parent,
406@@ -49,6 +46,7 @@
407 const std::string& title,
408 const std::string& picname,
409 boost::function<void()> callback);
410+ void set_button_visibility();
411
412 void act_goto();
413 void act_destination();
414@@ -62,7 +60,8 @@
415 InteractiveGameBase& igbase_;
416 Widelands::Ship& ship_;
417
418- std::unique_ptr<UI::Box> vbox_;
419+ UI::Box vbox_;
420+ UI::Box navigation_box_;
421 UI::Button* btn_goto_;
422 UI::Button* btn_destination_;
423 UI::Button* btn_sink_;
424@@ -74,6 +73,7 @@
425 UI::Button* btn_scout_[Widelands::LAST_DIRECTION];
426 UI::Button* btn_construct_port_;
427 ItemWaresDisplay* display_;
428+ int navigation_box_height_;
429 std::unique_ptr<Notifications::Subscriber<Widelands::NoteShipWindow>> shipnotes_subscriber_;
430 DISALLOW_COPY_AND_ASSIGN(ShipWindow);
431 };

Subscribers

People subscribed via source and target branches

to status/vote changes: