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
=== modified file 'src/economy/portdock.cc'
--- src/economy/portdock.cc 2017-07-01 15:36:36 +0000
+++ src/economy/portdock.cc 2017-08-16 04:49:28 +0000
@@ -337,7 +337,6 @@
337 // The expedition goods are now on the ship, so from now on it is independent from the port337 // The expedition goods are now on the ship, so from now on it is independent from the port
338 // and thus we switch the port to normal, so we could even start a new expedition,338 // and thus we switch the port to normal, so we could even start a new expedition,
339 cancel_expedition(game);339 cancel_expedition(game);
340 Notifications::publish(NoteShipWindow(ship.serial(), NoteShipWindow::Action::kRefresh));
341 return fleet_->update(game);340 return fleet_->update(game);
342 }341 }
343 }342 }
344343
=== modified file 'src/logic/map_objects/tribes/ship.cc'
--- src/logic/map_objects/tribes/ship.cc 2017-08-09 19:25:04 +0000
+++ src/logic/map_objects/tribes/ship.cc 2017-08-16 04:49:28 +0000
@@ -680,8 +680,6 @@
680 }680 }
681681
682 expedition_.reset(nullptr);682 expedition_.reset(nullptr);
683
684 Notifications::publish(NoteShipWindow(serial(), NoteShipWindow::Action::kRefresh));
685 return start_task_idle(game, descr().main_animation(), 1500);683 return start_task_idle(game, descr().main_animation(), 1500);
686 }684 }
687 }685 }
@@ -942,9 +940,6 @@
942940
943 // Delete the expedition and the economy it created.941 // Delete the expedition and the economy it created.
944 expedition_.reset(nullptr);942 expedition_.reset(nullptr);
945
946 // And finally update our ship window
947 Notifications::publish(NoteShipWindow(serial(), NoteShipWindow::Action::kRefresh));
948}943}
949944
950/// Sinks the ship945/// Sinks the ship
951946
=== modified file 'src/wui/itemwaresdisplay.cc'
--- src/wui/itemwaresdisplay.cc 2017-06-23 17:23:04 +0000
+++ src/wui/itemwaresdisplay.cc 2017-08-16 04:49:28 +0000
@@ -22,16 +22,18 @@
22#include "graphic/rendertarget.h"22#include "graphic/rendertarget.h"
23#include "logic/map_objects/tribes/tribe_descr.h"23#include "logic/map_objects/tribes/tribe_descr.h"
24#include "logic/player.h"24#include "logic/player.h"
25#include "ui_basic/mouse_constants.h"
2526
26namespace {27namespace {
2728
29constexpr int kMargin = 4;
28static const uint32_t IWD_HBorder = 10;30static const uint32_t IWD_HBorder = 10;
29static const uint32_t IWD_VBorder = 10;31static const uint32_t IWD_VBorder = 10;
30static const uint32_t IWD_DefaultItemsPerRow = 9;32static const uint32_t IWD_DefaultItemsPerRow = 9;
31static const uint32_t IWD_ItemWidth = 14;33static const uint32_t IWD_ItemWidth = 14;
32static const uint32_t IWD_ItemHeight = 26;34static const uint32_t IWD_ItemHeight = 26;
33static const uint32_t IWD_WorkerBaseline =35static const uint32_t IWD_WorkerBaseline =
34 -2; ///< Offset of anim center from bottom border of item rect36 2; ///< Offset of anim center from bottom border of item rect
35static const uint32_t IWD_WareBaseLine = -6;37static const uint32_t IWD_WareBaseLine = -6;
3638
37} // anonymous namespace39} // anonymous namespace
@@ -44,7 +46,7 @@
44 player_(gplayer),46 player_(gplayer),
45 capacity_(0),47 capacity_(0),
46 items_per_row_(IWD_DefaultItemsPerRow) {48 items_per_row_(IWD_DefaultItemsPerRow) {
47 set_desired_size(2 * IWD_HBorder, 2 * IWD_VBorder);49 recalc_desired_size();
48}50}
4951
50/**52/**
@@ -72,7 +74,7 @@
72 uint32_t rowitems = capacity_ >= items_per_row_ ? items_per_row_ : capacity_;74 uint32_t rowitems = capacity_ >= items_per_row_ ? items_per_row_ : capacity_;
7375
74 set_desired_size(76 set_desired_size(
75 2 * IWD_HBorder + rowitems * IWD_ItemWidth, 2 * IWD_VBorder + nrrows * IWD_ItemHeight);77 2 * (IWD_HBorder + kMargin) + rowitems * IWD_ItemWidth, 2 * (IWD_VBorder + kMargin) + nrrows * IWD_ItemHeight);
76}78}
7779
78/**80/**
@@ -88,15 +90,29 @@
88void ItemWaresDisplay::draw(RenderTarget& dst) {90void ItemWaresDisplay::draw(RenderTarget& dst) {
89 const Widelands::TribeDescr& tribe(player().tribe());91 const Widelands::TribeDescr& tribe(player().tribe());
9092
91 dst.fill_rect(Recti(0, 0, get_w(), get_h()), RGBAColor(0, 0, 0, 0));93 // Snazzy background
94 const int width = get_w() - 2 * kMargin;
95 const int height = get_h() - 2 * kMargin;
96 RGBAColor black(0, 0, 0, 255);
97 dst.brighten_rect(Recti(kMargin, kMargin, width - 1, height - 1), -BUTTON_EDGE_BRIGHT_FACTOR / 2);
98 // bottom edge
99 dst.brighten_rect(Recti(kMargin, height + 2, width, 2), 1.5 * BUTTON_EDGE_BRIGHT_FACTOR);
100 // right edge
101 dst.brighten_rect(Recti(kMargin + width - 2, kMargin, 2, height - 2), 1.5 * BUTTON_EDGE_BRIGHT_FACTOR);
102 // top edge
103 dst.fill_rect(Recti(kMargin, kMargin, width - 1, 1), black);
104 dst.fill_rect(Recti(kMargin, kMargin + 1, width - 2, 1), black);
105 // left edge
106 dst.fill_rect(Recti(kMargin, kMargin, 1, height - 1), black);
107 dst.fill_rect(Recti(kMargin + 1, kMargin, 1, height - 2), black);
92108
93 for (uint32_t idx = 0; idx < items_.size(); ++idx) {109 for (uint32_t idx = 0; idx < items_.size(); ++idx) {
94 const Item& it = items_[idx];110 const Item& it = items_[idx];
95 uint32_t row = idx / items_per_row_;111 uint32_t row = idx / items_per_row_;
96 uint32_t col = idx % items_per_row_;112 uint32_t col = idx % items_per_row_;
97113
98 uint32_t x = IWD_HBorder / 2 + col * IWD_ItemWidth;114 uint32_t x = IWD_HBorder / 2 + col * IWD_ItemWidth + kMargin;
99 uint32_t y = IWD_VBorder + row * IWD_ItemHeight;115 uint32_t y = IWD_VBorder + row * IWD_ItemHeight + kMargin;
100116
101 if (it.worker) {117 if (it.worker) {
102 y += IWD_WorkerBaseline;118 y += IWD_WorkerBaseline;
103119
=== modified file 'src/wui/shipwindow.cc'
--- src/wui/shipwindow.cc 2017-06-20 08:18:38 +0000
+++ src/wui/shipwindow.cc 2017-08-16 04:49:28 +0000
@@ -47,13 +47,117 @@
47static const char pic_scout_sw[] = "images/wui/ship/ship_scout_sw.png";47static const char pic_scout_sw[] = "images/wui/ship/ship_scout_sw.png";
48static const char pic_scout_se[] = "images/wui/ship/ship_scout_se.png";48static const char pic_scout_se[] = "images/wui/ship/ship_scout_se.png";
49static const char pic_construct_port[] = "images/wui/editor/fsel_editor_set_port_space.png";49static const char pic_construct_port[] = "images/wui/editor/fsel_editor_set_port_space.png";
50
51constexpr int kPadding = 5;
50} // namespace52} // namespace
5153
52using namespace Widelands;54using namespace Widelands;
5355
54ShipWindow::ShipWindow(InteractiveGameBase& igb, UniqueWindow::Registry& reg, Ship& ship)56ShipWindow::ShipWindow(InteractiveGameBase& igb, UniqueWindow::Registry& reg, Ship& ship)
55 : UniqueWindow(&igb, "shipwindow", &reg, 0, 0, ship.get_shipname()), igbase_(igb), ship_(ship) {57 : UniqueWindow(&igb, "shipwindow", &reg, 0, 0, ship.get_shipname()),
56 init(false);58 igbase_(igb),
59 ship_(ship),
60 vbox_(this, 0, 0, UI::Box::Vertical),
61 navigation_box_(&vbox_, 0, 0, UI::Box::Vertical),
62 navigation_box_height_(0) {
63 vbox_.set_inner_spacing(kPadding);
64 assert(ship_.get_owner());
65
66 display_ = new ItemWaresDisplay(&vbox_, *ship_.get_owner());
67 display_->set_capacity(ship_.descr().get_capacity());
68 vbox_.add(display_, UI::Box::Resizing::kAlign, UI::Align::kCenter);
69
70 // Expedition buttons
71 UI::Box* exp_top = new UI::Box(&navigation_box_, 0, 0, UI::Box::Horizontal);
72 navigation_box_.add(exp_top, UI::Box::Resizing::kAlign, UI::Align::kCenter);
73 UI::Box* exp_mid = new UI::Box(&navigation_box_, 0, 0, UI::Box::Horizontal);
74 navigation_box_.add(exp_mid, UI::Box::Resizing::kAlign, UI::Align::kCenter);
75 UI::Box* exp_bot = new UI::Box(&navigation_box_, 0, 0, UI::Box::Horizontal);
76 navigation_box_.add(exp_bot, UI::Box::Resizing::kAlign, UI::Align::kCenter);
77
78 btn_scout_[WALK_NW - 1] =
79 make_button(exp_top, "scnw", _("Scout towards the north west"), pic_scout_nw,
80 boost::bind(&ShipWindow::act_scout_towards, this, WALK_NW));
81 exp_top->add(btn_scout_[WALK_NW - 1]);
82
83 btn_explore_island_cw_ = make_button(
84 exp_top, "expcw", _("Explore the island’s coast clockwise"), pic_explore_cw,
85 boost::bind(&ShipWindow::act_explore_island, this, IslandExploreDirection::kClockwise));
86 exp_top->add(btn_explore_island_cw_);
87
88 btn_scout_[WALK_NE - 1] =
89 make_button(exp_top, "scne", _("Scout towards the north east"), pic_scout_ne,
90 boost::bind(&ShipWindow::act_scout_towards, this, WALK_NE));
91 exp_top->add(btn_scout_[WALK_NE - 1]);
92
93 btn_scout_[WALK_W - 1] = make_button(exp_mid, "scw", _("Scout towards the west"), pic_scout_w,
94 boost::bind(&ShipWindow::act_scout_towards, this, WALK_W));
95 exp_mid->add(btn_scout_[WALK_W - 1]);
96
97 btn_construct_port_ =
98 make_button(exp_mid, "buildport", _("Construct a port at the current location"),
99 pic_construct_port, boost::bind(&ShipWindow::act_construct_port, this));
100 exp_mid->add(btn_construct_port_);
101
102 btn_scout_[WALK_E - 1] = make_button(exp_mid, "sce", _("Scout towards the east"), pic_scout_e,
103 boost::bind(&ShipWindow::act_scout_towards, this, WALK_E));
104 exp_mid->add(btn_scout_[WALK_E - 1]);
105
106 btn_scout_[WALK_SW - 1] =
107 make_button(exp_bot, "scsw", _("Scout towards the south west"), pic_scout_sw,
108 boost::bind(&ShipWindow::act_scout_towards, this, WALK_SW));
109 exp_bot->add(btn_scout_[WALK_SW - 1]);
110
111 btn_explore_island_ccw_ =
112 make_button(exp_bot, "expccw", _("Explore the island’s coast counter clockwise"),
113 pic_explore_ccw, boost::bind(&ShipWindow::act_explore_island, this,
114 IslandExploreDirection::kCounterClockwise));
115 exp_bot->add(btn_explore_island_ccw_);
116
117 btn_scout_[WALK_SE - 1] =
118 make_button(exp_bot, "scse", _("Scout towards the south east"), pic_scout_se,
119 boost::bind(&ShipWindow::act_scout_towards, this, WALK_SE));
120 exp_bot->add(btn_scout_[WALK_SE - 1]);
121
122 vbox_.add(&navigation_box_, UI::Box::Resizing::kAlign, UI::Align::kCenter);
123
124 // Bottom buttons
125 UI::Box* buttons = new UI::Box(&vbox_, 0, 0, UI::Box::Horizontal);
126 vbox_.add(buttons, UI::Box::Resizing::kFullSize);
127
128 btn_sink_ = make_button(
129 buttons, "sink", _("Sink the ship"), pic_sink, boost::bind(&ShipWindow::act_sink, this));
130 buttons->add(btn_sink_);
131
132 btn_cancel_expedition_ =
133 make_button(buttons, "cancel_expedition", _("Cancel the Expedition"), pic_cancel_expedition,
134 boost::bind(&ShipWindow::act_cancel_expedition, this));
135 buttons->add(btn_cancel_expedition_);
136
137 buttons->add_inf_space();
138
139 if (igbase_.get_display_flag(InteractiveBase::dfDebug)) {
140 btn_debug_ = make_button(buttons, "debug", _("Show Debug Window"), pic_debug,
141 boost::bind(&ShipWindow::act_debug, this));
142 btn_debug_->set_enabled(true);
143 buttons->add(btn_debug_);
144 }
145
146 btn_destination_ = make_button(buttons, "destination", _("Go to destination"), pic_destination,
147 boost::bind(&ShipWindow::act_destination, this));
148 btn_destination_->set_enabled(false);
149 buttons->add(btn_destination_);
150
151 btn_goto_ = make_button(
152 buttons, "goto", _("Go to ship"), pic_goto, boost::bind(&ShipWindow::act_goto, this));
153 buttons->add(btn_goto_);
154
155 set_center_panel(&vbox_);
156 set_thinks(true);
157 set_fastclick_panel(btn_goto_);
158 move_out_of_the_way();
159 warp_mouse_to_fastclick_panel();
160
57 shipnotes_subscriber_ = Notifications::subscribe<Widelands::NoteShipWindow>([this](161 shipnotes_subscriber_ = Notifications::subscribe<Widelands::NoteShipWindow>([this](
58 const Widelands::NoteShipWindow& note) {162 const Widelands::NoteShipWindow& note) {
59 if (note.serial == ship_.serial()) {163 if (note.serial == ship_.serial()) {
@@ -72,10 +176,6 @@
72 }176 }
73 }177 }
74 break;178 break;
75 // The ship state has changed, e.g. expedition canceled
76 case Widelands::NoteShipWindow::Action::kRefresh:
77 init(true);
78 break;
79 // The ship is no more179 // The ship is no more
80 case Widelands::NoteShipWindow::Action::kClose:180 case Widelands::NoteShipWindow::Action::kClose:
81 // Stop this from thinking to avoid segfaults181 // Stop this from thinking to avoid segfaults
@@ -85,108 +185,24 @@
85 }185 }
86 }186 }
87 });187 });
188
189 // Init button visibility
190 navigation_box_height_ = navigation_box_.get_h();
191 navigation_box_.set_visible(false);
192 navigation_box_.set_desired_size(navigation_box_.get_w(), 0);
193 btn_cancel_expedition_->set_enabled(false);
194 think();
88}195}
89196
90void ShipWindow::init(bool avoid_fastclick) {197void ShipWindow::set_button_visibility() {
91 assert(ship_.get_owner());198 if (navigation_box_.is_visible() != ship_.state_is_expedition()) {
92199 navigation_box_.set_visible(ship_.state_is_expedition());
93 vbox_.reset(new UI::Box(this, 0, 0, UI::Box::Vertical));200 navigation_box_.set_desired_size(
94201 navigation_box_.get_w(), ship_.state_is_expedition() ? navigation_box_height_ : 0);
95 display_ = new ItemWaresDisplay(vbox_.get(), *ship_.get_owner());202 layout();
96 display_->set_capacity(ship_.descr().get_capacity());203 }
97 vbox_->add(display_, UI::Box::Resizing::kAlign, UI::Align::kCenter);204 if (btn_cancel_expedition_->is_visible() != btn_cancel_expedition_->enabled()) {
98205 btn_cancel_expedition_->set_visible(btn_cancel_expedition_->enabled());
99 // Expedition buttons
100 if (ship_.state_is_expedition()) {
101 UI::Box* exp_top = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal);
102 vbox_->add(exp_top, UI::Box::Resizing::kAlign, UI::Align::kCenter);
103 UI::Box* exp_mid = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal);
104 vbox_->add(exp_mid, UI::Box::Resizing::kAlign, UI::Align::kCenter);
105 UI::Box* exp_bot = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal);
106 vbox_->add(exp_bot, UI::Box::Resizing::kAlign, UI::Align::kCenter);
107
108 btn_scout_[WALK_NW - 1] =
109 make_button(exp_top, "scnw", _("Scout towards the north west"), pic_scout_nw,
110 boost::bind(&ShipWindow::act_scout_towards, this, WALK_NW));
111 exp_top->add(btn_scout_[WALK_NW - 1]);
112
113 btn_explore_island_cw_ = make_button(
114 exp_top, "expcw", _("Explore the island’s coast clockwise"), pic_explore_cw,
115 boost::bind(&ShipWindow::act_explore_island, this, IslandExploreDirection::kClockwise));
116 exp_top->add(btn_explore_island_cw_);
117
118 btn_scout_[WALK_NE - 1] =
119 make_button(exp_top, "scne", _("Scout towards the north east"), pic_scout_ne,
120 boost::bind(&ShipWindow::act_scout_towards, this, WALK_NE));
121 exp_top->add(btn_scout_[WALK_NE - 1]);
122
123 btn_scout_[WALK_W - 1] =
124 make_button(exp_mid, "scw", _("Scout towards the west"), pic_scout_w,
125 boost::bind(&ShipWindow::act_scout_towards, this, WALK_W));
126 exp_mid->add(btn_scout_[WALK_W - 1]);
127
128 btn_construct_port_ =
129 make_button(exp_mid, "buildport", _("Construct a port at the current location"),
130 pic_construct_port, boost::bind(&ShipWindow::act_construct_port, this));
131 exp_mid->add(btn_construct_port_);
132
133 btn_scout_[WALK_E - 1] =
134 make_button(exp_mid, "sce", _("Scout towards the east"), pic_scout_e,
135 boost::bind(&ShipWindow::act_scout_towards, this, WALK_E));
136 exp_mid->add(btn_scout_[WALK_E - 1]);
137
138 btn_scout_[WALK_SW - 1] =
139 make_button(exp_bot, "scsw", _("Scout towards the south west"), pic_scout_sw,
140 boost::bind(&ShipWindow::act_scout_towards, this, WALK_SW));
141 exp_bot->add(btn_scout_[WALK_SW - 1]);
142
143 btn_explore_island_ccw_ =
144 make_button(exp_bot, "expccw", _("Explore the island’s coast counter clockwise"),
145 pic_explore_ccw, boost::bind(&ShipWindow::act_explore_island, this,
146 IslandExploreDirection::kCounterClockwise));
147 exp_bot->add(btn_explore_island_ccw_);
148
149 btn_scout_[WALK_SE - 1] =
150 make_button(exp_bot, "scse", _("Scout towards the south east"), pic_scout_se,
151 boost::bind(&ShipWindow::act_scout_towards, this, WALK_SE));
152 exp_bot->add(btn_scout_[WALK_SE - 1]);
153 }
154
155 // Bottom buttons
156 UI::Box* buttons = new UI::Box(vbox_.get(), 0, 0, UI::Box::Horizontal);
157 vbox_->add(buttons);
158
159 btn_goto_ = make_button(
160 buttons, "goto", _("Go to ship"), pic_goto, boost::bind(&ShipWindow::act_goto, this));
161 buttons->add(btn_goto_);
162 btn_destination_ = make_button(buttons, "destination", _("Go to destination"), pic_destination,
163 boost::bind(&ShipWindow::act_destination, this));
164 btn_destination_->set_enabled(false);
165 buttons->add(btn_destination_);
166
167 btn_sink_ = make_button(
168 buttons, "sink", _("Sink the ship"), pic_sink, boost::bind(&ShipWindow::act_sink, this));
169 buttons->add(btn_sink_);
170
171 if (ship_.state_is_expedition()) {
172 btn_cancel_expedition_ =
173 make_button(buttons, "cancel_expedition", _("Cancel the Expedition"),
174 pic_cancel_expedition, boost::bind(&ShipWindow::act_cancel_expedition, this));
175 buttons->add(btn_cancel_expedition_);
176 }
177
178 if (igbase_.get_display_flag(InteractiveBase::dfDebug)) {
179 btn_debug_ = make_button(buttons, "debug", _("Show Debug Window"), pic_debug,
180 boost::bind(&ShipWindow::act_debug, this));
181 btn_debug_->set_enabled(true);
182 buttons->add(btn_debug_);
183 }
184 set_center_panel(vbox_.get());
185 set_thinks(true);
186 set_fastclick_panel(btn_goto_);
187 if (!avoid_fastclick) {
188 move_out_of_the_way();
189 warp_mouse_to_fastclick_panel();
190 }206 }
191}207}
192208
@@ -215,7 +231,6 @@
215 }231 }
216 }232 }
217233
218 // Expedition specific buttons
219 Ship::ShipStates state = ship_.get_ship_state();234 Ship::ShipStates state = ship_.get_ship_state();
220 if (ship_.state_is_expedition()) {235 if (ship_.state_is_expedition()) {
221 /* The following rules apply:236 /* The following rules apply:
@@ -243,9 +258,11 @@
243 btn_explore_island_ccw_->set_enabled(can_act && coast_nearby &&258 btn_explore_island_ccw_->set_enabled(can_act && coast_nearby &&
244 (state != Ship::ShipStates::kExpeditionColonizing));259 (state != Ship::ShipStates::kExpeditionColonizing));
245 btn_sink_->set_enabled(can_act && (state != Ship::ShipStates::kExpeditionColonizing));260 btn_sink_->set_enabled(can_act && (state != Ship::ShipStates::kExpeditionColonizing));
246 btn_cancel_expedition_->set_enabled(can_act &&
247 (state != Ship::ShipStates::kExpeditionColonizing));
248 }261 }
262 btn_cancel_expedition_->set_enabled(ship_.state_is_expedition() && can_act &&
263 (state != Ship::ShipStates::kExpeditionColonizing));
264 // Expedition specific buttons
265 set_button_visibility();
249}266}
250267
251UI::Button* ShipWindow::make_button(UI::Panel* parent,268UI::Button* ShipWindow::make_button(UI::Panel* parent,
252269
=== modified file 'src/wui/shipwindow.h'
--- src/wui/shipwindow.h 2017-02-21 20:38:33 +0000
+++ src/wui/shipwindow.h 2017-08-16 04:49:28 +0000
@@ -39,9 +39,6 @@
39 ShipWindow(InteractiveGameBase& igb, UI::UniqueWindow::Registry& reg, Widelands::Ship& ship);39 ShipWindow(InteractiveGameBase& igb, UI::UniqueWindow::Registry& reg, Widelands::Ship& ship);
4040
41private:41private:
42 // Resets the vbox_ and fills it with the currently needed buttons, then positions the window.
43 void init(bool avoid_fastclick);
44
45 void think() override;42 void think() override;
4643
47 UI::Button* make_button(UI::Panel* parent,44 UI::Button* make_button(UI::Panel* parent,
@@ -49,6 +46,7 @@
49 const std::string& title,46 const std::string& title,
50 const std::string& picname,47 const std::string& picname,
51 boost::function<void()> callback);48 boost::function<void()> callback);
49 void set_button_visibility();
5250
53 void act_goto();51 void act_goto();
54 void act_destination();52 void act_destination();
@@ -62,7 +60,8 @@
62 InteractiveGameBase& igbase_;60 InteractiveGameBase& igbase_;
63 Widelands::Ship& ship_;61 Widelands::Ship& ship_;
6462
65 std::unique_ptr<UI::Box> vbox_;63 UI::Box vbox_;
64 UI::Box navigation_box_;
66 UI::Button* btn_goto_;65 UI::Button* btn_goto_;
67 UI::Button* btn_destination_;66 UI::Button* btn_destination_;
68 UI::Button* btn_sink_;67 UI::Button* btn_sink_;
@@ -74,6 +73,7 @@
74 UI::Button* btn_scout_[Widelands::LAST_DIRECTION];73 UI::Button* btn_scout_[Widelands::LAST_DIRECTION];
75 UI::Button* btn_construct_port_;74 UI::Button* btn_construct_port_;
76 ItemWaresDisplay* display_;75 ItemWaresDisplay* display_;
76 int navigation_box_height_;
77 std::unique_ptr<Notifications::Subscriber<Widelands::NoteShipWindow>> shipnotes_subscriber_;77 std::unique_ptr<Notifications::Subscriber<Widelands::NoteShipWindow>> shipnotes_subscriber_;
78 DISALLOW_COPY_AND_ASSIGN(ShipWindow);78 DISALLOW_COPY_AND_ASSIGN(ShipWindow);
79};79};

Subscribers

People subscribed via source and target branches

to status/vote changes: