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