widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #06479
[Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands.
Commit message:
The "Cancel Expedition" button in Port windows will now toggle and remove the tab.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1191556 in widelands: "Port window not updated ("Cancel the expedition" starts a new one)"
https://bugs.launchpad.net/widelands/+bug/1191556
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1191556-cancel-expedition/+merge/288375
Using a new note and a new "remove_last_tab" function to fix the cancel expedition button in port windows.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands.
=== modified file 'src/economy/expedition_bootstrap.cc'
--- src/economy/expedition_bootstrap.cc 2016-01-18 19:35:25 +0000
+++ src/economy/expedition_bootstrap.cc 2016-03-08 08:44:38 +0000
@@ -160,8 +160,10 @@
workers_.clear();
// Update the user interface
- if (upcast(InteractiveGameBase, igb, warehouse->owner().egbase().get_ibase()))
+ if (upcast(InteractiveGameBase, igb, warehouse->owner().egbase().get_ibase())) {
warehouse->refresh_options(*igb);
+ }
+ Notifications::publish(NoteExpeditionCanceled(this));
}
void ExpeditionBootstrap::cleanup(EditorGameBase& /* egbase */) {
=== modified file 'src/economy/expedition_bootstrap.h'
--- src/economy/expedition_bootstrap.h 2015-11-28 22:29:26 +0000
+++ src/economy/expedition_bootstrap.h 2016-03-08 08:44:38 +0000
@@ -99,6 +99,17 @@
DISALLOW_COPY_AND_ASSIGN(ExpeditionBootstrap);
};
+
+struct NoteExpeditionCanceled {
+ CAN_BE_SENT_AS_NOTE(NoteId::NoteExpeditionCanceled)
+
+ ExpeditionBootstrap* bootstrap;
+
+ NoteExpeditionCanceled(ExpeditionBootstrap* const init_bootstrap)
+ : bootstrap(init_bootstrap) {
+ }
+};
+
} // namespace Widelands
#endif // end of include guard: WL_ECONOMY_EXPEDITION_BOOTSTRAP_H
=== modified file 'src/notifications/note_ids.h'
--- src/notifications/note_ids.h 2016-01-14 22:09:24 +0000
+++ src/notifications/note_ids.h 2016-03-08 08:44:38 +0000
@@ -36,7 +36,7 @@
TrainingSiteSoldierTrained,
ShipMessage,
GraphicResolutionChanged,
-
+ NoteExpeditionCanceled
};
#endif // end of include guard: WL_NOTIFICATIONS_NOTE_IDS_H
=== modified file 'src/ui_basic/tabpanel.cc'
--- src/ui_basic/tabpanel.cc 2016-02-14 14:09:29 +0000
+++ src/ui_basic/tabpanel.cc 2016-03-08 08:44:38 +0000
@@ -254,12 +254,24 @@
}
/**
- * Return the tab names in order
+ * Return the tabs in order
*/
const TabPanel::TabList & TabPanel::tabs() {
return tabs_;
}
+bool TabPanel::remove_last_tab(const std::string& tabname) {
+ if (tabs_.back()->get_name() == tabname) {
+ tabs_.pop_back();
+ if (active_ > tabs_.size() - 1) {
+ active_ = 0ul;
+ }
+ update_desired_size();
+ return true;
+ }
+ return false;
+}
+
/**
* Draw the buttons and the tab
*/
=== modified file 'src/ui_basic/tabpanel.h'
--- src/ui_basic/tabpanel.h 2016-02-08 12:38:48 +0000
+++ src/ui_basic/tabpanel.h 2016-03-08 08:44:38 +0000
@@ -115,6 +115,9 @@
void activate(uint32_t idx);
void activate(const std::string &);
uint32_t active() {return active_;}
+ // Removes the last tab if the 'tabname' matches. Returns whether a tab was removed.
+ // We use the tabname as a safety precaution to prevent acidentally removing the wrong tab.
+ bool remove_last_tab(const std::string& tabname);
boost::signals2::signal<void ()> sigclicked;
=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc 2016-02-13 12:15:29 +0000
+++ src/wui/buildingwindow.cc 2016-03-08 08:44:38 +0000
@@ -58,7 +58,8 @@
registry_(registry),
building_ (b),
workarea_overlay_id_(0),
- avoid_fastclick_(false)
+ avoid_fastclick_(false),
+ expeditionbtn_(nullptr)
{
delete registry_;
registry_ = this;
@@ -178,27 +179,20 @@
// Check if this is a port building and if yes show expedition button
if (upcast(Widelands::Warehouse const, warehouse, &building_)) {
if (Widelands::PortDock * pd = warehouse->get_portdock()) {
- if (pd->expedition_started()) {
- UI::Button * expeditionbtn =
- new UI::Button
- (capsbuttons, "cancel_expedition", 0, 0, 34, 34,
- g_gr->images().get("images/ui_basic/but4.png"),
- g_gr->images().get("images/wui/buildings/cancel_expedition.png"),
- _("Cancel the expedition"));
- expeditionbtn->sigclicked.connect
- (boost::bind(&BuildingWindow::act_start_or_cancel_expedition, boost::ref(*this)));
- capsbuttons->add(expeditionbtn, UI::Align::kHCenter);
- } else {
- UI::Button * expeditionbtn =
- new UI::Button
- (capsbuttons, "start_expedition", 0, 0, 34, 34,
- g_gr->images().get("images/ui_basic/but4.png"),
- g_gr->images().get("images/wui/buildings/start_expedition.png"),
- _("Start an expedition"));
- expeditionbtn->sigclicked.connect
- (boost::bind(&BuildingWindow::act_start_or_cancel_expedition, boost::ref(*this)));
- capsbuttons->add(expeditionbtn, UI::Align::kHCenter);
- }
+ expedition_canceled_subscriber_ =
+ Notifications::subscribe<Widelands::NoteExpeditionCanceled>(
+ [this](const Widelands::NoteExpeditionCanceled&) {
+ update_expedition_button(true);
+ });
+ expeditionbtn_ =
+ new UI::Button
+ (capsbuttons, "start_or_cancel_expedition", 0, 0, 34, 34,
+ g_gr->images().get("images/ui_basic/but4.png"),
+ g_gr->images().get("images/wui/buildings/start_expedition.png"));
+ update_expedition_button(!pd->expedition_started());
+ expeditionbtn_->sigclicked.connect
+ (boost::bind(&BuildingWindow::act_start_or_cancel_expedition, boost::ref(*this)));
+ capsbuttons->add(expeditionbtn_, UI::Align::kHCenter);
}
}
else
@@ -422,12 +416,15 @@
===============
*/
void BuildingWindow::act_start_or_cancel_expedition() {
- if (upcast(Widelands::Warehouse const, warehouse, &building_))
- if (warehouse->get_portdock())
+ if (upcast(Widelands::Warehouse const, warehouse, &building_)) {
+ if (warehouse->get_portdock()) {
+ expeditionbtn_->set_enabled(false);
igbase().game().send_player_start_or_cancel_expedition(building_);
+ }
+ get_tabs()->activate("expedition_wares_queue");
+ }
// No need to die here - as soon as the request is handled, the UI will get updated by the portdock
- //die();
}
/**
@@ -539,3 +536,16 @@
{
igbase().move_view_to(building().get_position());
}
+
+void BuildingWindow::update_expedition_button(bool expedition_was_canceled) {
+ assert(expeditionbtn_ != nullptr);
+ if (expedition_was_canceled) {
+ expeditionbtn_->set_tooltip(_("Start an expedition"));
+ expeditionbtn_->set_pic(g_gr->images().get("images/wui/buildings/start_expedition.png"));
+ tabs_->remove_last_tab("expedition_wares_queue");
+ } else {
+ expeditionbtn_->set_tooltip(_("Cancel the expedition"));
+ expeditionbtn_->set_pic(g_gr->images().get("images/wui/buildings/cancel_expedition.png"));
+ }
+ expeditionbtn_->set_enabled(true);
+}
=== modified file 'src/wui/buildingwindow.h'
--- src/wui/buildingwindow.h 2016-01-24 20:11:53 +0000
+++ src/wui/buildingwindow.h 2016-03-08 08:44:38 +0000
@@ -21,7 +21,9 @@
#define WL_WUI_BUILDINGWINDOW_H
#include <cstdlib>
+#include <memory>
+#include "economy/expedition_bootstrap.h"
#include "ui_basic/button.h"
#include "ui_basic/window.h"
#include "wui/field_overlay_manager.h"
@@ -92,6 +94,13 @@
FieldOverlayManager::OverlayId workarea_overlay_id_;
bool avoid_fastclick_;
+
+ // For ports only.
+ void update_expedition_button(bool expedition_was_canceled);
+
+ UI::Button * expeditionbtn_;
+ std::unique_ptr<Notifications::Subscriber<Widelands::NoteExpeditionCanceled>>
+ expedition_canceled_subscriber_;
};
#endif // end of include guard: WL_WUI_BUILDINGWINDOW_H
Follow ups
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
From: GunChleoc, 2016-03-15
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
From: Klaus Halfmann, 2016-03-14
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
From: GunChleoc, 2016-03-14
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
From: Klaus Halfmann, 2016-03-13
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
From: GunChleoc, 2016-03-12
-
[Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
From: noreply, 2016-03-12
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
From: Klaus Halfmann, 2016-03-12
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
From: TiborB, 2016-03-10
-
[Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
From: bunnybot, 2016-03-09
-
[Merge] lp:~widelands-dev/widelands/bug-1191556-cancel-expedition into lp:widelands
From: bunnybot, 2016-03-08