Merge lp:~widelands-dev/widelands/economy-target-profiles into lp:widelands

Proposed by Benedikt Straub
Status: Merged
Merged at revision: 9201
Proposed branch: lp:~widelands-dev/widelands/economy-target-profiles
Merge into: lp:widelands
Diff against target: 104 lines (+21/-11)
4 files modified
src/economy/economy.cc (+2/-2)
src/economy/economy.h (+9/-5)
src/wui/economy_options_window.cc (+3/-3)
src/wui/fieldaction.cc (+7/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/economy-target-profiles
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+372447@code.launchpad.net

Commit message

Move the economy options window to top when clicking Configure Economy

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

I can't think of a cleaner solution either at this point, so code LGTM :)

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

This does not work for minimized windows, they still stay minimzed.

Revision history for this message
Benedikt Straub (nordfriese) wrote :

Fixed as well now

9125. By Nordfriese

Restore window if minimized

Revision history for this message
GunChleoc (gunchleoc) wrote :

Fix confirmed :)

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5411. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/582115732.
Appveyor build 5181. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_economy_target_profiles-5181.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/economy/economy.cc'
2--- src/economy/economy.cc 2019-06-23 11:41:17 +0000
3+++ src/economy/economy.cc 2019-09-07 17:07:44 +0000
4@@ -52,7 +52,7 @@
5 }
6
7 Economy::Economy(Player& player, Serial init_serial)
8- : serial_(init_serial), owner_(player), request_timerid_(0), has_window_(false) {
9+ : serial_(init_serial), owner_(player), request_timerid_(0), options_window_(nullptr) {
10 last_economy_serial_ = std::max(last_economy_serial_, serial_ + 1);
11 const TribeDescr& tribe = player.tribe();
12 DescriptionIndex const nr_wares = player.egbase().tribes().nrwares();
13@@ -535,7 +535,7 @@
14
15 // If the options window for e is open, but not the one for this, the user
16 // should still have an options window after the merge.
17- if (e.has_window() && !has_window()) {
18+ if (e.get_options_window() && !get_options_window()) {
19 Notifications::publish(NoteEconomy{e.serial(), serial_, NoteEconomy::Action::kMerged});
20 }
21
22
23=== modified file 'src/economy/economy.h'
24--- src/economy/economy.h 2019-02-23 11:00:49 +0000
25+++ src/economy/economy.h 2019-09-07 17:07:44 +0000
26@@ -196,11 +196,11 @@
27 return worker_target_quantities_[i];
28 }
29
30- bool has_window() const {
31- return has_window_;
32+ void* get_options_window() const {
33+ return options_window_;
34 }
35- void set_has_window(bool yes) {
36- has_window_ = yes;
37+ void set_options_window(void* window) {
38+ options_window_ = window;
39 }
40
41 const WareList& get_wares() const {
42@@ -289,7 +289,11 @@
43 uint32_t request_timerid_;
44
45 static std::unique_ptr<Soldier> soldier_prototype_;
46- bool has_window_;
47+
48+ // This is always an EconomyOptionsWindow* (or nullptr) but I don't want a wui dependency here.
49+ // We cannot use UniqueWindow to make sure an economy never has two windows because the serial
50+ // may change when merging while the window is open, so we have to keep track of it here.
51+ void* options_window_;
52
53 // 'list' of unique providers
54 std::map<UniqueDistance, Supply*> available_supplies_;
55
56=== modified file 'src/wui/economy_options_window.cc'
57--- src/wui/economy_options_window.cc 2019-08-25 14:50:16 +0000
58+++ src/wui/economy_options_window.cc 2019-09-07 17:07:44 +0000
59@@ -124,7 +124,7 @@
60 main_box_.add_space(8);
61 main_box_.add(&dropdown_box_, UI::Box::Resizing::kAlign, UI::Align::kCenter);
62
63- economy->set_has_window(true);
64+ economy->set_options_window(static_cast<void*>(this));
65 economynotes_subscriber_ = Notifications::subscribe<Widelands::NoteEconomy>(
66 [this](const Widelands::NoteEconomy& note) { on_economy_note(note); });
67 profilenotes_subscriber_ =
68@@ -145,7 +145,7 @@
69 EconomyOptionsWindow::~EconomyOptionsWindow() {
70 Widelands::Economy* economy = player_->get_economy(serial_);
71 if (economy != nullptr) {
72- economy->set_has_window(false);
73+ economy->set_options_window(nullptr);
74 }
75 if (save_profile_dialog_) {
76 save_profile_dialog_->unset_parent();
77@@ -162,7 +162,7 @@
78 die();
79 return;
80 }
81- economy->set_has_window(true);
82+ economy->set_options_window(static_cast<void*>(this));
83 ware_panel_->set_economy(note.new_economy);
84 worker_panel_->set_economy(note.new_economy);
85 move_to_top();
86
87=== modified file 'src/wui/fieldaction.cc'
88--- src/wui/fieldaction.cc 2019-09-05 19:57:55 +0000
89+++ src/wui/fieldaction.cc 2019-09-07 17:07:44 +0000
90@@ -632,7 +632,13 @@
91 void FieldActionWindow::act_configure_economy() {
92 if (upcast(const Widelands::Flag, flag, node_.field->get_immovable())) {
93 Widelands::Economy* economy = flag->get_economy();
94- if (!economy->has_window()) {
95+ if (economy->get_options_window()) {
96+ EconomyOptionsWindow& window = *static_cast<EconomyOptionsWindow*>(economy->get_options_window());
97+ if (window.is_minimal()) {
98+ window.restore();
99+ }
100+ window.move_to_top();
101+ } else {
102 bool can_act =
103 dynamic_cast<InteractiveGameBase&>(ibase()).can_act(economy->owner().player_number());
104 new EconomyOptionsWindow(dynamic_cast<UI::Panel*>(&ibase()), economy, can_act);

Subscribers

People subscribed via source and target branches

to status/vote changes: