Merge lp:~widelands-dev/widelands/observer_building_spaces into lp:widelands

Proposed by Martin Schmidt
Status: Merged
Merged at revision: 7404
Proposed branch: lp:~widelands-dev/widelands/observer_building_spaces
Merge into: lp:widelands
Diff against target: 329 lines (+71/-79)
6 files modified
src/wui/interactive_gamebase.cc (+43/-2)
src/wui/interactive_gamebase.h (+5/-1)
src/wui/interactive_player.cc (+5/-60)
src/wui/interactive_player.h (+1/-4)
src/wui/interactive_spectator.cc (+16/-10)
src/wui/interactive_spectator.h (+1/-2)
To merge this branch: bzr merge lp:~widelands-dev/widelands/observer_building_spaces
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+249764@code.launchpad.net

Description of the change

move of toogle buildhelp to the base class of player and spectator

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

lgtm.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/wui/interactive_gamebase.cc'
--- src/wui/interactive_gamebase.cc 2014-12-06 12:22:35 +0000
+++ src/wui/interactive_gamebase.cc 2015-02-14 22:40:35 +0000
@@ -29,6 +29,7 @@
29#include "logic/findbob.h"29#include "logic/findbob.h"
30#include "logic/game.h"30#include "logic/game.h"
31#include "logic/game_controller.h"31#include "logic/game_controller.h"
32#include "logic/map.h"
32#include "logic/player.h"33#include "logic/player.h"
33#include "logic/ship.h"34#include "logic/ship.h"
34#include "profile/profile.h"35#include "profile/profile.h"
@@ -59,8 +60,18 @@
59 (global_s.get_string("building_tooltip_format", "%r")),60 (global_s.get_string("building_tooltip_format", "%r")),
60 m_chatenabled(chatenabled),61 m_chatenabled(chatenabled),
61 m_multiplayer(multiplayer),62 m_multiplayer(multiplayer),
62 m_playertype(pt)63 m_playertype(pt),
63{}64
65#define INIT_BTN(picture, name, tooltip) \
66 TOOLBAR_BUTTON_COMMON_PARAMETERS(name), \
67 g_gr->images().get("pics/" picture ".png"), \
68 tooltip \
69
70 m_toggle_buildhelp
71 (INIT_BTN("menu_toggle_buildhelp", "buildhelp", _("Show Building Spaces (on/off)")))
72{
73 m_toggle_buildhelp.sigclicked.connect(boost::bind(&InteractiveGameBase::toggle_buildhelp, this));
74}
6475
65/// \return a pointer to the running \ref Game instance.76/// \return a pointer to the running \ref Game instance.
66Widelands::Game * InteractiveGameBase::get_game() const77Widelands::Game * InteractiveGameBase::get_game() const
@@ -119,6 +130,36 @@
119130
120131
121/**132/**
133 * Called for every game after loading (from a savegame or just from a map
134 * during single/multiplayer/scenario).
135 */
136void InteractiveGameBase::postload() {
137 Widelands::Map & map = egbase().map();
138 OverlayManager & overlay_manager = map.overlay_manager();
139 overlay_manager.show_buildhelp(false);
140 overlay_manager.register_overlay_callback_function
141 (boost::bind(&InteractiveGameBase::calculate_buildcaps, this, _1));
142
143 // Connect buildhelp button to reflect build help state. Needs to be
144 // done here rather than in the constructor as the map is not present then.
145 // This code assumes that the InteractivePlayer object lives longer than
146 // the overlay_manager. Otherwise remove the hook in the deconstructor.
147 egbase().map().overlay_manager().onBuildHelpToggle =
148 boost::bind(&UI::Button::set_perm_pressed, &m_toggle_buildhelp, _1);
149 m_toggle_buildhelp.set_perm_pressed(buildhelp());
150
151 // Recalc whole map for changed owner stuff
152 map.recalc_whole_map(egbase().world());
153
154 // Close game-relevant UI windows (but keep main menu open)
155 delete m_fieldaction.window;
156 m_fieldaction.window = nullptr;
157
158 hide_minimap();
159}
160
161
162/**
122 * See if we can reasonably open a ship window at the current selection position.163 * See if we can reasonably open a ship window at the current selection position.
123 * If so, do it and return true; otherwise, return false.164 * If so, do it and return true; otherwise, return false.
124 */165 */
125166
=== modified file 'src/wui/interactive_gamebase.h'
--- src/wui/interactive_gamebase.h 2014-11-30 12:23:45 +0000
+++ src/wui/interactive_gamebase.h 2015-02-14 22:40:35 +0000
@@ -82,9 +82,11 @@
82 bool is_multiplayer() {return m_multiplayer;}82 bool is_multiplayer() {return m_multiplayer;}
8383
84 void show_game_summary();84 void show_game_summary();
8585 void postload() override;
86 void start() override {};
86protected:87protected:
87 void draw_overlay(RenderTarget &) override;88 void draw_overlay(RenderTarget &) override;
89 virtual int32_t calculate_buildcaps(const Widelands::TCoords<Widelands::FCoords> c) =0;
8890
89 GameMainMenuWindows m_mainm_windows;91 GameMainMenuWindows m_mainm_windows;
90 ChatProvider * m_chatProvider;92 ChatProvider * m_chatProvider;
@@ -96,6 +98,8 @@
96 PlayerType m_playertype;98 PlayerType m_playertype;
97 UI::UniqueWindow::Registry m_fieldaction;99 UI::UniqueWindow::Registry m_fieldaction;
98 UI::UniqueWindow::Registry m_game_summary;100 UI::UniqueWindow::Registry m_game_summary;
101
102 UI::Button m_toggle_buildhelp;
99};103};
100104
101#endif // end of include guard: WL_WUI_INTERACTIVE_GAMEBASE_H105#endif // end of include guard: WL_WUI_INTERACTIVE_GAMEBASE_H
102106
=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc 2014-12-08 11:08:38 +0000
+++ src/wui/interactive_player.cc 2015-02-14 22:40:35 +0000
@@ -61,18 +61,6 @@
61using Widelands::Building;61using Widelands::Building;
62using Widelands::Map;62using Widelands::Map;
6363
64namespace {
65
66// This function is the callback for recalculation of field overlays
67int32_t int_player_overlay_callback_function
68 (Widelands::TCoords<Widelands::FCoords> const c, InteractivePlayer& iap)
69{
70 assert(iap.get_player());
71 return iap.get_player()->get_buildcaps(c);
72}
73
74} // namespace
75
76InteractivePlayer::InteractivePlayer64InteractivePlayer::InteractivePlayer
77 (Widelands::Game & _game,65 (Widelands::Game & _game,
78 Section & global_s,66 Section & global_s,
@@ -84,7 +72,6 @@
84 m_flag_to_connect(Widelands::Coords::null()),72 m_flag_to_connect(Widelands::Coords::null()),
8573
86// Chat is different, as m_chatProvider needs to be checked when toggling74// Chat is different, as m_chatProvider needs to be checked when toggling
87// Buildhelp is different as it does not toggle a UniqueWindow
88// Minimap is different as it warps and stuff75// Minimap is different as it warps and stuff
8976
90#define INIT_BTN_this(picture, name, tooltip) \77#define INIT_BTN_this(picture, name, tooltip) \
@@ -114,9 +101,6 @@
114m_toggle_minimap101m_toggle_minimap
115 (INIT_BTN_this102 (INIT_BTN_this
116 ("menu_toggle_minimap", "minimap", _("Minimap"))),103 ("menu_toggle_minimap", "minimap", _("Minimap"))),
117m_toggle_buildhelp
118 (INIT_BTN_this
119 ("menu_toggle_buildhelp", "buildhelp", _("Show Building Spaces (on/off)"))),
120m_toggle_message_menu104m_toggle_message_menu
121 (INIT_BTN105 (INIT_BTN
122 ("menu_toggle_oldmessage_menu", "messages", _("Messages"))),106 ("menu_toggle_oldmessage_menu", "messages", _("Messages"))),
@@ -135,8 +119,6 @@
135 (boost::bind(&UI::UniqueWindow::Registry::toggle, boost::ref(m_objectives)));119 (boost::bind(&UI::UniqueWindow::Registry::toggle, boost::ref(m_objectives)));
136 m_toggle_minimap.sigclicked.connect120 m_toggle_minimap.sigclicked.connect
137 (boost::bind(&InteractivePlayer::toggle_minimap, this));121 (boost::bind(&InteractivePlayer::toggle_minimap, this));
138 m_toggle_buildhelp.sigclicked.connect
139 (boost::bind(&InteractivePlayer::toggle_buildhelp, this));
140 m_toggle_message_menu.sigclicked.connect122 m_toggle_message_menu.sigclicked.connect
141 (boost::bind(&UI::UniqueWindow::Registry::toggle, boost::ref(m_message_menu)));123 (boost::bind(&UI::UniqueWindow::Registry::toggle, boost::ref(m_message_menu)));
142 m_toggle_help.sigclicked.connect124 m_toggle_help.sigclicked.connect
@@ -206,17 +188,6 @@
206 DEINIT_BTN_HOOKS(m_message_menu, m_toggle_message_menu)188 DEINIT_BTN_HOOKS(m_message_menu, m_toggle_message_menu)
207}189}
208190
209
210/*
211===============
212Called just before the game starts, after postload, init and gfxload
213===============
214*/
215void InteractivePlayer::start()
216{
217 postload();
218}
219
220void InteractivePlayer::think()191void InteractivePlayer::think()
221{192{
222 InteractiveBase::think();193 InteractiveBase::think();
@@ -267,37 +238,6 @@
267}238}
268239
269240
270/**
271 * Called for every game after loading (from a savegame or just from a map
272 * during single/multiplayer/scenario).
273 */
274void InteractivePlayer::postload()
275{
276 Map & map = egbase().map();
277 OverlayManager & overlay_manager = map.overlay_manager();
278 overlay_manager.show_buildhelp(false);
279 overlay_manager.register_overlay_callback_function
280 (boost::bind(&int_player_overlay_callback_function, _1, boost::ref(*this)));
281
282 // Connect buildhelp button to reflect build help state. Needs to be
283 // done here rather than in the constructor as the map is not present then.
284 // This code assumes that the InteractivePlayer object lives longer than
285 // the overlay_manager. Otherwise remove the hook in the deconstructor.
286 egbase().map().overlay_manager().onBuildHelpToggle =
287 boost::bind(&UI::Button::set_perm_pressed, &m_toggle_buildhelp, _1);
288 m_toggle_buildhelp.set_perm_pressed(buildhelp());
289
290 // Recalc whole map for changed owner stuff
291 map.recalc_whole_map(egbase().world());
292
293 // Close game-relevant UI windows (but keep main menu open)
294 delete m_fieldaction.window;
295 m_fieldaction.window = nullptr;
296
297 hide_minimap();
298}
299
300
301void InteractivePlayer::popup_message241void InteractivePlayer::popup_message
302 (Widelands::MessageId const id, const Widelands::Message & message)242 (Widelands::MessageId const id, const Widelands::Message & message)
303{243{
@@ -328,6 +268,11 @@
328 return m_player_number;268 return m_player_number;
329}269}
330270
271int32_t InteractivePlayer::calculate_buildcaps(const Widelands::TCoords<Widelands::FCoords> c) {
272 assert(get_player());
273 return get_player()->get_buildcaps(c);
274}
275
331276
332/// Player has clicked on the given node; bring up the context menu.277/// Player has clicked on the given node; bring up the context menu.
333void InteractivePlayer::node_action()278void InteractivePlayer::node_action()
334279
=== modified file 'src/wui/interactive_player.h'
--- src/wui/interactive_player.h 2014-10-14 06:30:20 +0000
+++ src/wui/interactive_player.h 2015-02-14 22:40:35 +0000
@@ -51,8 +51,6 @@
5151
52 ~InteractivePlayer();52 ~InteractivePlayer();
5353
54 void start() override;
55
56 void toggle_chat ();54 void toggle_chat ();
5755
58 bool can_see(Widelands::PlayerNumber) const override;56 bool can_see(Widelands::PlayerNumber) const override;
@@ -77,13 +75,13 @@
77 // For load75 // For load
78 void cleanup_for_load() override;76 void cleanup_for_load() override;
79 void think() override;77 void think() override;
80 void postload() override;
8178
82 void set_flag_to_connect(Widelands::Coords const location) {79 void set_flag_to_connect(Widelands::Coords const location) {
83 m_flag_to_connect = location;80 m_flag_to_connect = location;
84 }81 }
8582
86 void popup_message(Widelands::MessageId, const Widelands::Message &);83 void popup_message(Widelands::MessageId, const Widelands::Message &);
84 int32_t calculate_buildcaps(const Widelands::TCoords<Widelands::FCoords> c) override;
8785
88private:86private:
89 void cmdSwitchPlayer(const std::vector<std::string> & args);87 void cmdSwitchPlayer(const std::vector<std::string> & args);
@@ -97,7 +95,6 @@
97 UI::Button m_toggle_statistics_menu;95 UI::Button m_toggle_statistics_menu;
98 UI::Button m_toggle_objectives;96 UI::Button m_toggle_objectives;
99 UI::Button m_toggle_minimap;97 UI::Button m_toggle_minimap;
100 UI::Button m_toggle_buildhelp;
101 UI::Button m_toggle_message_menu;98 UI::Button m_toggle_message_menu;
102 UI::Button m_toggle_help;99 UI::Button m_toggle_help;
103100
104101
=== modified file 'src/wui/interactive_spectator.cc'
--- src/wui/interactive_spectator.cc 2014-12-03 08:14:35 +0000
+++ src/wui/interactive_spectator.cc 2015-02-14 22:40:35 +0000
@@ -24,6 +24,7 @@
24#include "chat/chat.h"24#include "chat/chat.h"
25#include "graphic/graphic.h"25#include "graphic/graphic.h"
26#include "logic/game_controller.h"26#include "logic/game_controller.h"
27#include "logic/player.h"
27#include "ui_basic/editbox.h"28#include "ui_basic/editbox.h"
28#include "ui_basic/multilinetextarea.h"29#include "ui_basic/multilinetextarea.h"
29#include "ui_basic/textarea.h"30#include "ui_basic/textarea.h"
@@ -75,6 +76,7 @@
75 m_toolbar.add(&m_toggle_options_menu, UI::Box::AlignLeft);76 m_toolbar.add(&m_toggle_options_menu, UI::Box::AlignLeft);
76 m_toolbar.add(&m_toggle_statistics, UI::Box::AlignLeft);77 m_toolbar.add(&m_toggle_statistics, UI::Box::AlignLeft);
77 m_toolbar.add(&m_toggle_minimap, UI::Box::AlignLeft);78 m_toolbar.add(&m_toggle_minimap, UI::Box::AlignLeft);
79 m_toolbar.add(&m_toggle_buildhelp, UI::Box::AlignLeft);
78 m_toolbar.add(&m_toggle_chat, UI::Box::AlignLeft);80 m_toolbar.add(&m_toggle_chat, UI::Box::AlignLeft);
7981
80 // TODO(unknown): instead of making unneeded buttons invisible after generation,82 // TODO(unknown): instead of making unneeded buttons invisible after generation,
@@ -140,17 +142,17 @@
140}142}
141143
142144
143/**145int32_t InteractiveSpectator::calculate_buildcaps(const Widelands::TCoords<Widelands::FCoords> c) {
144 * Called just before the game starts, after postload, init and gfxload146 const Widelands::PlayerNumber nr_players = game().map().get_nrplayers();
145 */147
146void InteractiveSpectator::start()148 iterate_players_existing(p, nr_players, game(), player) {
147{149 const Widelands::NodeCaps nc = player->get_buildcaps(c);
148 Widelands::Map & map = game().map();150 if( nc > Widelands::NodeCaps::CAPS_NONE ) {
149 OverlayManager & overlay_manager = map.overlay_manager();151 return nc;
150 overlay_manager.show_buildhelp(false);152 }
153 }
151154
152 // Recalc whole map for changed owner stuff155 return Widelands::NodeCaps::CAPS_NONE;
153 map.recalc_whole_map(game().world());
154}156}
155157
156158
@@ -245,6 +247,10 @@
245{247{
246 if (down)248 if (down)
247 switch (code.sym) {249 switch (code.sym) {
250 case SDLK_SPACE:
251 toggle_buildhelp();
252 return true;
253
248 case SDLK_m:254 case SDLK_m:
249 toggle_minimap();255 toggle_minimap();
250 return true;256 return true;
251257
=== modified file 'src/wui/interactive_spectator.h'
--- src/wui/interactive_spectator.h 2014-10-14 06:30:20 +0000
+++ src/wui/interactive_spectator.h 2015-02-14 22:40:35 +0000
@@ -40,8 +40,6 @@
4040
41 ~InteractiveSpectator();41 ~InteractiveSpectator();
4242
43 void start() override;
44
45 Widelands::Player * get_player() const override;43 Widelands::Player * get_player() const override;
4644
47 bool handle_key(bool down, SDL_Keysym) override;45 bool handle_key(bool down, SDL_Keysym) override;
@@ -52,6 +50,7 @@
52 void toggle_statistics();50 void toggle_statistics();
53 void exit_btn();51 void exit_btn();
54 void save_btn();52 void save_btn();
53 int32_t calculate_buildcaps(const Widelands::TCoords<Widelands::FCoords> ) override;
55 bool can_see(Widelands::PlayerNumber) const override;54 bool can_see(Widelands::PlayerNumber) const override;
56 bool can_act(Widelands::PlayerNumber) const override;55 bool can_act(Widelands::PlayerNumber) const override;
57 Widelands::PlayerNumber player_number() const override;56 Widelands::PlayerNumber player_number() const override;

Subscribers

People subscribed via source and target branches

to status/vote changes: