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

Proposed by SirVer
Status: Merged
Merged at revision: 7291
Proposed branch: lp:~widelands-dev/widelands/move_mapview_children
Merge into: lp:widelands
Diff against target: 400 lines (+91/-109)
8 files modified
src/wui/chatoverlay.cc (+4/-0)
src/wui/chatoverlay.h (+3/-0)
src/wui/interactive_base.cc (+33/-100)
src/wui/interactive_base.h (+0/-5)
src/wui/interactive_gamebase.cc (+49/-0)
src/wui/interactive_gamebase.h (+2/-0)
src/wui/interactive_player.cc (+0/-2)
src/wui/interactive_spectator.cc (+0/-2)
To merge this branch: bzr merge lp:~widelands-dev/widelands/move_mapview_children
Reviewer Review Type Date Requested Status
Tino Approve
GunChleoc Approve
Review via email: mp+243233@code.launchpad.net

Description of the change

Proposed commit message:

- Resize chat overlay on changing of resolution.
- Draw game speed in InteractiveGameBase using polymorphism instead of a
  dynamic_cast.
- Gets rid of display flag dfSpeed.

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

Working without problems on Ubuntu. Do we need a Windows test on this as well?

Code LGTM.

review: Approve
Revision history for this message
Tino (tino79) wrote :

LGoWin ;)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/wui/chatoverlay.cc'
2--- src/wui/chatoverlay.cc 2014-11-22 10:18:20 +0000
3+++ src/wui/chatoverlay.cc 2014-11-30 12:35:21 +0000
4@@ -101,6 +101,10 @@
5 }
6 }
7
8+void ChatOverlay::recompute() {
9+ m->recompute();
10+}
11+
12 /**
13 * Recompute the chat message display.
14 */
15
16=== modified file 'src/wui/chatoverlay.h'
17--- src/wui/chatoverlay.h 2014-09-20 09:37:47 +0000
18+++ src/wui/chatoverlay.h 2014-11-30 12:35:21 +0000
19@@ -39,6 +39,9 @@
20 void draw(RenderTarget &) override;
21 void think() override;
22
23+ // Check is position and size is still correct.
24+ void recompute();
25+
26 private:
27 struct Impl;
28 std::unique_ptr<Impl> m;
29
30=== modified file 'src/wui/interactive_base.cc'
31--- src/wui/interactive_base.cc 2014-11-30 11:14:34 +0000
32+++ src/wui/interactive_base.cc 2014-11-30 12:35:21 +0000
33@@ -98,8 +98,6 @@
34 m_road_buildhelp_overlay_jobid(0),
35 m_buildroad(nullptr),
36 m_road_build_player(0),
37- m_label_speed_shadow(this, get_w() - 1, 0, std::string(), UI::Align_TopRight),
38- m_label_speed(this, get_w(), 1, std::string(), UI::Align_TopRight),
39 unique_window_handler_(new UniqueWindowHandler()),
40 // Start at idx 0 for 2 enhancements, idx 3 for 1, idx 5 if none
41 m_workarea_pics{g_gr->images().get("pics/workarea123.png"),
42@@ -112,6 +110,9 @@
43 graphic_resolution_changed_subscriber_ = Notifications::subscribe<GraphicResolutionChanged>(
44 [this](const GraphicResolutionChanged& message) {
45 set_size(message.width, message.height);
46+
47+ m_chatOverlay->set_size(get_w() / 2, get_h() - 25);
48+ m_chatOverlay->recompute();
49 adjust_toolbar_position();
50 });
51
52@@ -131,20 +132,10 @@
53 set_dock_windows_to_edges
54 (global_s.get_bool("dock_windows_to_edges", false));
55
56- // Switch to the new graphics system now, if necessary.
57- WLApplication::get()->refresh_graphics();
58-
59 // Having this in the initializer list (before Sys_InitGraphics) will give
60 // funny results.
61 m_sel.pic = g_gr->images().get("pics/fsel.png");
62
63- m_label_speed.set_visible(false);
64- m_label_speed_shadow.set_visible(false);
65-
66- UI::TextStyle style_shadow = m_label_speed.get_textstyle();
67- style_shadow.fg = RGBColor(0, 0, 0);
68- m_label_speed_shadow.set_textstyle(style_shadow);
69-
70 setDefaultCommand (boost::bind(&InteractiveBase::cmd_lua, this, _1));
71 addCommand
72 ("mapobject", boost::bind(&InteractiveBase::cmd_map_object, this, _1));
73@@ -306,51 +297,6 @@
74 */
75 void InteractiveBase::postload() {}
76
77-static std::string speed_string(uint32_t const speed)
78-{
79- if (speed) {
80- return (boost::format("%u.%ux")
81- % (speed / 1000)
82- % (speed / 100 % 10)).str();
83- }
84- return _("PAUSE");
85-}
86-
87-/**
88- * Bring the label that display in-game speed uptodate.
89- */
90-void InteractiveBase::update_speedlabel()
91-{
92- if (get_display_flag(dfSpeed)) {
93- upcast(Game, game, &m_egbase);
94- if (game && game->game_controller()) {
95- uint32_t const real = game->game_controller()->real_speed ();
96- uint32_t const desired = game->game_controller()->desired_speed();
97- if (real == desired)
98- m_label_speed.set_text
99- (real == 1000 ? std::string() : speed_string(real));
100- else {
101- m_label_speed.set_text(
102- (boost::format
103- /** TRANSLATORS: actual_speed (desired_speed) */
104- (_("%1$s (%2$s)"))
105- % speed_string(real).c_str()
106- % speed_string(desired).c_str()
107- ).str()
108- );
109- }
110- } else
111- m_label_speed.set_text(_("NO GAME CONTROLLER"));
112- m_label_speed.set_visible(true);
113- } else
114- m_label_speed.set_visible(false);
115-
116- m_label_speed_shadow.set_text(m_label_speed.get_text());
117- m_label_speed_shadow.set_visible(m_label_speed.is_visible());
118-
119-}
120-
121-
122 /*
123 ===============
124 Called once per frame by the UI code
125@@ -393,8 +339,6 @@
126 // etc...)
127 g_gr->update();
128
129- update_speedlabel();
130-
131 UI::Panel::think();
132 }
133
134@@ -411,11 +355,8 @@
135
136 // Blit node information when in debug mode.
137 if (get_display_flag(dfDebug) || !is_game) {
138-
139 std::string node_text;
140-
141 if (is_game) {
142-
143 const std::string gametime(gametimestring(egbase().get_gametime()));
144 const std::string gametime_text = as_uifont(gametime, UI_FONT_SIZE_SMALL);
145 dst.blit(Point(5, 5), UI::g_fh1->render(gametime_text), BlendMode::UseAlpha, UI::Align_TopLeft);
146@@ -423,9 +364,7 @@
147 static boost::format node_format("(%i, %i)");
148 node_text = as_uifont
149 ((node_format % m_sel.pos.node.x % m_sel.pos.node.y).str(), UI_FONT_SIZE_SMALL);
150-
151 } else { //this is an editor
152-
153 static boost::format node_format("(%i, %i, %i)");
154 const int32_t height = map[m_sel.pos.node].get_height();
155 node_text = as_uifont
156@@ -592,8 +531,6 @@
157 void InteractiveBase::set_display_flags(uint32_t flags)
158 {
159 m_display_flags = flags;
160-
161- update_speedlabel();
162 }
163
164
165@@ -613,8 +550,6 @@
166
167 if (on)
168 m_display_flags |= flag;
169-
170- update_speedlabel();
171 }
172
173 /*
174@@ -931,53 +866,51 @@
175 if (m->quicknavigation->handle_key(down, code))
176 return true;
177
178- switch (code.sym) {
179- case SDLK_KP_9:
180- if (code.mod & KMOD_NUM)
181- break;
182+ if (down) {
183+ switch (code.sym) {
184+ case SDLK_KP_9:
185+ if (code.mod & KMOD_NUM)
186+ break;
187 /* no break */
188- case SDLK_PAGEUP:
189- if (!get_display_flag(dfSpeed))
190- break;
191-
192- if (down)
193- if (upcast(Game, game, &m_egbase))
194- if (GameController * const ctrl = game->game_controller())
195+ case SDLK_PAGEUP:
196+ if (upcast(Game, game, &m_egbase)) {
197+ if (GameController* const ctrl = game->game_controller()) {
198 ctrl->set_desired_speed(ctrl->desired_speed() + 1000);
199- return true;
200+ }
201+ }
202+ return true;
203
204- case SDLK_PAUSE:
205- if (down)
206- if (upcast(Game, game, &m_egbase))
207- if (GameController * const ctrl = game->game_controller())
208+ case SDLK_PAUSE:
209+ if (upcast(Game, game, &m_egbase)) {
210+ if (GameController* const ctrl = game->game_controller()) {
211 ctrl->toggle_paused();
212- return true;
213+ }
214+ }
215+ return true;
216
217- case SDLK_KP_3:
218- if (code.mod & KMOD_NUM)
219- break;
220+ case SDLK_KP_3:
221+ if (code.mod & KMOD_NUM)
222+ break;
223 /* no break */
224- case SDLK_PAGEDOWN:
225- if (!get_display_flag(dfSpeed))
226- break;
227-
228- if (down)
229- if (upcast(Widelands::Game, game, &m_egbase))
230- if (GameController * const ctrl = game->game_controller()) {
231+ case SDLK_PAGEDOWN:
232+ if (upcast(Widelands::Game, game, &m_egbase)) {
233+ if (GameController* const ctrl = game->game_controller()) {
234 uint32_t const speed = ctrl->desired_speed();
235 ctrl->set_desired_speed(1000 < speed ? speed - 1000 : 0);
236 }
237- return true;
238-#ifndef NDEBUG // only in debug builds
239+ }
240+ return true;
241+#ifndef NDEBUG // only in debug builds
242 case SDLK_F6:
243 if (get_display_flag(dfDebug)) {
244 GameChatMenu::create_script_console(
245- this, m_debugconsole, *DebugConsole::get_chat_provider());
246+ this, m_debugconsole, *DebugConsole::get_chat_provider());
247 }
248 return true;
249 #endif
250- default:
251- break;
252+ default:
253+ break;
254+ }
255 }
256
257 return MapView::handle_key(down, code);
258
259=== modified file 'src/wui/interactive_base.h'
260--- src/wui/interactive_base.h 2014-11-23 14:34:38 +0000
261+++ src/wui/interactive_base.h 2014-11-30 12:35:21 +0000
262@@ -53,7 +53,6 @@
263 dfShowCensus = 1, ///< show census report on buildings
264 dfShowStatistics = 2, ///< show statistics report on buildings
265 dfDebug = 4, ///< general debugging info
266- dfSpeed = 8, ///< show game speed and speed controls
267 };
268
269 // Manages all UniqueWindows.
270@@ -155,7 +154,6 @@
271 void roadb_remove_overlay();
272 void cmd_map_object(const std::vector<std::string> & args);
273 void cmd_lua(const std::vector<std::string> & args);
274- void update_speedlabel();
275
276 struct SelData {
277 SelData
278@@ -195,9 +193,6 @@
279 Widelands::CoordPath * m_buildroad; // path for the new road
280 Widelands::PlayerNumber m_road_build_player;
281
282- UI::Textarea m_label_speed_shadow;
283- UI::Textarea m_label_speed;
284-
285 UI::UniqueWindow::Registry m_debugconsole;
286 std::unique_ptr<UniqueWindowHandler> unique_window_handler_;
287 std::vector<const Image*> m_workarea_pics;
288
289=== modified file 'src/wui/interactive_gamebase.cc'
290--- src/wui/interactive_gamebase.cc 2014-09-20 09:37:47 +0000
291+++ src/wui/interactive_gamebase.cc 2014-11-30 12:35:21 +0000
292@@ -19,13 +19,31 @@
293
294 #include "wui/interactive_gamebase.h"
295
296+#include <boost/format.hpp>
297+
298 #include "base/macros.h"
299+#include "graphic/font_handler1.h"
300+#include "graphic/rendertarget.h"
301 #include "logic/findbob.h"
302 #include "logic/game.h"
303+#include "logic/game_controller.h"
304 #include "logic/player.h"
305 #include "logic/ship.h"
306 #include "profile/profile.h"
307 #include "wui/game_summary.h"
308+#include "wui/text_constants.h"
309+#include "wui/text_layout.h"
310+
311+namespace {
312+
313+std::string speed_string(int const speed) {
314+ if (speed) {
315+ return (boost::format("%u.%ux") % (speed / 1000) % (speed / 100 % 10)).str();
316+ }
317+ return _("PAUSE");
318+}
319+
320+} // namespace
321
322 InteractiveGameBase::InteractiveGameBase
323 (Widelands::Game & _game, Section & global_s,
324@@ -69,6 +87,37 @@
325 return m_chatProvider;
326 }
327
328+void InteractiveGameBase::draw_overlay(RenderTarget& dst) {
329+ InteractiveBase::draw_overlay(dst);
330+
331+ GameController* game_controller = game().game_controller();
332+ // Display the gamespeed.
333+ if (game_controller != nullptr) {
334+ std::string game_speed;
335+ uint32_t const real = game_controller->real_speed();
336+ uint32_t const desired = game_controller->desired_speed();
337+ if (real == desired) {
338+ if (real != 1000) {
339+ game_speed = as_uifont(speed_string(real), UI_FONT_SIZE_SMALL);
340+ }
341+ } else {
342+ game_speed = as_uifont((boost::format
343+ /** TRANSLATORS: actual_speed (desired_speed) */
344+ (_("%1$s (%2$s)")) %
345+ speed_string(real) % speed_string(desired)).str(),
346+ UI_FONT_SIZE_SMALL);
347+ }
348+
349+ if (!game_speed.empty()) {
350+ dst.blit(Point(get_w() - 5, 5),
351+ UI::g_fh1->render(game_speed),
352+ BlendMode::UseAlpha,
353+ UI::Align_TopRight);
354+ }
355+ }
356+}
357+
358+
359 /**
360 * See if we can reasonably open a ship window at the current selection position.
361 * If so, do it and return true; otherwise, return false.
362
363=== modified file 'src/wui/interactive_gamebase.h'
364--- src/wui/interactive_gamebase.h 2014-09-10 16:57:31 +0000
365+++ src/wui/interactive_gamebase.h 2014-11-30 12:35:21 +0000
366@@ -84,6 +84,8 @@
367 void show_game_summary();
368
369 protected:
370+ void draw_overlay(RenderTarget &) override;
371+
372 GameMainMenuWindows m_mainm_windows;
373 ChatProvider * m_chatProvider;
374 std::string m_building_census_format;
375
376=== modified file 'src/wui/interactive_player.cc'
377--- src/wui/interactive_player.cc 2014-11-23 14:34:38 +0000
378+++ src/wui/interactive_player.cc 2014-11-30 12:35:21 +0000
379@@ -163,8 +163,6 @@
380
381 adjust_toolbar_position();
382
383- set_display_flag(dfSpeed, true);
384-
385 #define INIT_BTN_HOOKS(registry, btn) \
386 registry.on_create = std::bind(&UI::Button::set_perm_pressed, &btn, true); \
387 registry.on_delete = std::bind(&UI::Button::set_perm_pressed, &btn, false); \
388
389=== modified file 'src/wui/interactive_spectator.cc'
390--- src/wui/interactive_spectator.cc 2014-11-23 14:34:38 +0000
391+++ src/wui/interactive_spectator.cc 2014-11-30 12:35:21 +0000
392@@ -96,8 +96,6 @@
393 // Setup all screen elements
394 fieldclicked.connect(boost::bind(&InteractiveSpectator::node_action, this));
395
396- set_display_flag(dfSpeed, true);
397-
398 #define INIT_BTN_HOOKS(registry, btn) \
399 registry.on_create = std::bind(&UI::Button::set_perm_pressed, &btn, true); \
400 registry.on_delete = std::bind(&UI::Button::set_perm_pressed, &btn, false); \

Subscribers

People subscribed via source and target branches

to status/vote changes: