← Back to team overview

widelands-dev team mailing list archive

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

 

SirVer has proposed merging lp:~widelands-dev/widelands/move_mapview_children into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1397302 in widelands: "Fullscreen Toggle Text Overlay"
  https://bugs.launchpad.net/widelands/+bug/1397302

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/move_mapview_children/+merge/243233

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. 
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/move_mapview_children into lp:widelands.
=== modified file 'src/wui/chatoverlay.cc'
--- src/wui/chatoverlay.cc	2014-11-22 10:18:20 +0000
+++ src/wui/chatoverlay.cc	2014-11-30 12:35:21 +0000
@@ -101,6 +101,10 @@
 	}
 }
 
+void ChatOverlay::recompute() {
+	m->recompute();
+}
+
 /**
  * Recompute the chat message display.
  */

=== modified file 'src/wui/chatoverlay.h'
--- src/wui/chatoverlay.h	2014-09-20 09:37:47 +0000
+++ src/wui/chatoverlay.h	2014-11-30 12:35:21 +0000
@@ -39,6 +39,9 @@
 	void draw(RenderTarget &) override;
 	void think() override;
 
+	// Check is position and size is still correct.
+	void recompute();
+
 private:
 	struct Impl;
 	std::unique_ptr<Impl> m;

=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc	2014-11-30 11:14:34 +0000
+++ src/wui/interactive_base.cc	2014-11-30 12:35:21 +0000
@@ -98,8 +98,6 @@
      m_road_buildhelp_overlay_jobid(0),
      m_buildroad(nullptr),
      m_road_build_player(0),
-     m_label_speed_shadow(this, get_w() - 1, 0, std::string(), UI::Align_TopRight),
-     m_label_speed(this, get_w(), 1, std::string(), UI::Align_TopRight),
      unique_window_handler_(new UniqueWindowHandler()),
      // Start at idx 0 for 2 enhancements, idx 3 for 1, idx 5 if none
      m_workarea_pics{g_gr->images().get("pics/workarea123.png"),
@@ -112,6 +110,9 @@
 	graphic_resolution_changed_subscriber_ = Notifications::subscribe<GraphicResolutionChanged>(
 	   [this](const GraphicResolutionChanged& message) {
 		   set_size(message.width, message.height);
+
+		   m_chatOverlay->set_size(get_w() / 2, get_h() - 25);
+		   m_chatOverlay->recompute();
 		   adjust_toolbar_position();
 		});
 
@@ -131,20 +132,10 @@
 	set_dock_windows_to_edges
 		(global_s.get_bool("dock_windows_to_edges", false));
 
-	//  Switch to the new graphics system now, if necessary.
-	WLApplication::get()->refresh_graphics();
-
 	//  Having this in the initializer list (before Sys_InitGraphics) will give
 	//  funny results.
 	m_sel.pic = g_gr->images().get("pics/fsel.png");
 
-	m_label_speed.set_visible(false);
-	m_label_speed_shadow.set_visible(false);
-
-	UI::TextStyle style_shadow = m_label_speed.get_textstyle();
-	style_shadow.fg = RGBColor(0, 0, 0);
-	m_label_speed_shadow.set_textstyle(style_shadow);
-
 	setDefaultCommand (boost::bind(&InteractiveBase::cmd_lua, this, _1));
 	addCommand
 		("mapobject", boost::bind(&InteractiveBase::cmd_map_object, this, _1));
@@ -306,51 +297,6 @@
  */
 void InteractiveBase::postload() {}
 
-static std::string speed_string(uint32_t const speed)
-{
-	if (speed) {
-		return (boost::format("%u.%ux")
-				  % (speed / 1000)
-				  % (speed / 100 % 10)).str();
-	}
-	return _("PAUSE");
-}
-
-/**
- * Bring the label that display in-game speed uptodate.
- */
-void InteractiveBase::update_speedlabel()
-{
-	if (get_display_flag(dfSpeed)) {
-		upcast(Game, game, &m_egbase);
-		if (game && game->game_controller()) {
-			uint32_t const real    = game->game_controller()->real_speed   ();
-			uint32_t const desired = game->game_controller()->desired_speed();
-			if (real == desired)
-				m_label_speed.set_text
-					(real == 1000 ? std::string() : speed_string(real));
-			else {
-				m_label_speed.set_text(
-					(boost::format
-						 /** TRANSLATORS: actual_speed (desired_speed) */
-						(_("%1$s (%2$s)"))
-						% speed_string(real).c_str()
-						% speed_string(desired).c_str()
-					).str()
-				);
-			}
-		} else
-			m_label_speed.set_text(_("NO GAME CONTROLLER"));
-		m_label_speed.set_visible(true);
-	} else
-		m_label_speed.set_visible(false);
-
-	m_label_speed_shadow.set_text(m_label_speed.get_text());
-	m_label_speed_shadow.set_visible(m_label_speed.is_visible());
-
-}
-
-
 /*
 ===============
 Called once per frame by the UI code
@@ -393,8 +339,6 @@
 	//  etc...)
 	g_gr->update();
 
-	update_speedlabel();
-
 	UI::Panel::think();
 }
 
@@ -411,11 +355,8 @@
 
 	// Blit node information when in debug mode.
 	if (get_display_flag(dfDebug) || !is_game) {
-
 		std::string node_text;
-
 		if (is_game) {
-
 			const std::string gametime(gametimestring(egbase().get_gametime()));
 			const std::string gametime_text = as_uifont(gametime, UI_FONT_SIZE_SMALL);
 			dst.blit(Point(5, 5), UI::g_fh1->render(gametime_text), BlendMode::UseAlpha, UI::Align_TopLeft);
@@ -423,9 +364,7 @@
 			static boost::format node_format("(%i, %i)");
 			node_text = as_uifont
 				((node_format % m_sel.pos.node.x % m_sel.pos.node.y).str(), UI_FONT_SIZE_SMALL);
-
 		} else { //this is an editor
-
 			static boost::format node_format("(%i, %i, %i)");
 			const int32_t height = map[m_sel.pos.node].get_height();
 			node_text = as_uifont
@@ -592,8 +531,6 @@
 void InteractiveBase::set_display_flags(uint32_t flags)
 {
 	m_display_flags = flags;
-
-	update_speedlabel();
 }
 
 
@@ -613,8 +550,6 @@
 
 	if (on)
 		m_display_flags |= flag;
-
-	update_speedlabel();
 }
 
 /*
@@ -931,53 +866,51 @@
 	if (m->quicknavigation->handle_key(down, code))
 		return true;
 
-	switch (code.sym) {
-	case SDLK_KP_9:
-		if (code.mod & KMOD_NUM)
-			break;
+	if (down) {
+		switch (code.sym) {
+		case SDLK_KP_9:
+			if (code.mod & KMOD_NUM)
+				break;
 		/* no break */
-	case SDLK_PAGEUP:
-		if (!get_display_flag(dfSpeed))
-			break;
-
-		if (down)
-			if (upcast(Game, game, &m_egbase))
-				if (GameController * const ctrl = game->game_controller())
+		case SDLK_PAGEUP:
+			if (upcast(Game, game, &m_egbase)) {
+				if (GameController* const ctrl = game->game_controller()) {
 					ctrl->set_desired_speed(ctrl->desired_speed() + 1000);
-		return true;
+				}
+			}
+			return true;
 
-	case SDLK_PAUSE:
-		if (down)
-			if (upcast(Game, game, &m_egbase))
-				if (GameController * const ctrl = game->game_controller())
+		case SDLK_PAUSE:
+			if (upcast(Game, game, &m_egbase)) {
+				if (GameController* const ctrl = game->game_controller()) {
 					ctrl->toggle_paused();
-		return true;
+				}
+			}
+			return true;
 
-	case SDLK_KP_3:
-		if (code.mod & KMOD_NUM)
-			break;
+		case SDLK_KP_3:
+			if (code.mod & KMOD_NUM)
+				break;
 		/* no break */
-	case SDLK_PAGEDOWN:
-		if (!get_display_flag(dfSpeed))
-			break;
-
-		if (down)
-			if (upcast(Widelands::Game, game, &m_egbase))
-				if (GameController * const ctrl = game->game_controller()) {
+		case SDLK_PAGEDOWN:
+			if (upcast(Widelands::Game, game, &m_egbase)) {
+				if (GameController* const ctrl = game->game_controller()) {
 					uint32_t const speed = ctrl->desired_speed();
 					ctrl->set_desired_speed(1000 < speed ? speed - 1000 : 0);
 				}
-		return true;
-#ifndef NDEBUG //  only in debug builds
+			}
+			return true;
+#ifndef NDEBUG  //  only in debug builds
 		case SDLK_F6:
 			if (get_display_flag(dfDebug)) {
 				GameChatMenu::create_script_console(
-					this, m_debugconsole, *DebugConsole::get_chat_provider());
+				   this, m_debugconsole, *DebugConsole::get_chat_provider());
 			}
 			return true;
 #endif
-	default:
-		break;
+		default:
+			break;
+		}
 	}
 
 	return MapView::handle_key(down, code);

=== modified file 'src/wui/interactive_base.h'
--- src/wui/interactive_base.h	2014-11-23 14:34:38 +0000
+++ src/wui/interactive_base.h	2014-11-30 12:35:21 +0000
@@ -53,7 +53,6 @@
 		dfShowCensus     = 1, ///< show census report on buildings
 		dfShowStatistics = 2, ///< show statistics report on buildings
 		dfDebug          = 4, ///< general debugging info
-		dfSpeed          = 8, ///< show game speed and speed controls
 	};
 
 	// Manages all UniqueWindows.
@@ -155,7 +154,6 @@
 	void roadb_remove_overlay();
 	void cmd_map_object(const std::vector<std::string> & args);
 	void cmd_lua(const std::vector<std::string> & args);
-	void update_speedlabel();
 
 	struct SelData {
 		SelData
@@ -195,9 +193,6 @@
 	Widelands::CoordPath  * m_buildroad;         //  path for the new road
 	Widelands::PlayerNumber m_road_build_player;
 
-	UI::Textarea m_label_speed_shadow;
-	UI::Textarea m_label_speed;
-
 	UI::UniqueWindow::Registry m_debugconsole;
 	std::unique_ptr<UniqueWindowHandler> unique_window_handler_;
 	std::vector<const Image*> m_workarea_pics;

=== modified file 'src/wui/interactive_gamebase.cc'
--- src/wui/interactive_gamebase.cc	2014-09-20 09:37:47 +0000
+++ src/wui/interactive_gamebase.cc	2014-11-30 12:35:21 +0000
@@ -19,13 +19,31 @@
 
 #include "wui/interactive_gamebase.h"
 
+#include <boost/format.hpp>
+
 #include "base/macros.h"
+#include "graphic/font_handler1.h"
+#include "graphic/rendertarget.h"
 #include "logic/findbob.h"
 #include "logic/game.h"
+#include "logic/game_controller.h"
 #include "logic/player.h"
 #include "logic/ship.h"
 #include "profile/profile.h"
 #include "wui/game_summary.h"
+#include "wui/text_constants.h"
+#include "wui/text_layout.h"
+
+namespace {
+
+std::string speed_string(int const speed) {
+	if (speed) {
+		return (boost::format("%u.%ux") % (speed / 1000) % (speed / 100 % 10)).str();
+	}
+	return _("PAUSE");
+}
+
+}  // namespace
 
 InteractiveGameBase::InteractiveGameBase
 	(Widelands::Game & _game, Section & global_s,
@@ -69,6 +87,37 @@
 	return m_chatProvider;
 }
 
+void InteractiveGameBase::draw_overlay(RenderTarget& dst) {
+	InteractiveBase::draw_overlay(dst);
+
+	GameController* game_controller = game().game_controller();
+	// Display the gamespeed.
+	if (game_controller != nullptr) {
+		std::string game_speed;
+		uint32_t const real = game_controller->real_speed();
+		uint32_t const desired = game_controller->desired_speed();
+		if (real == desired) {
+			if (real != 1000) {
+				game_speed = as_uifont(speed_string(real), UI_FONT_SIZE_SMALL);
+			}
+		} else {
+			game_speed = as_uifont((boost::format
+											/** TRANSLATORS: actual_speed (desired_speed) */
+											(_("%1$s (%2$s)")) %
+											speed_string(real) % speed_string(desired)).str(),
+										  UI_FONT_SIZE_SMALL);
+		}
+
+		if (!game_speed.empty()) {
+			dst.blit(Point(get_w() - 5,  5),
+						UI::g_fh1->render(game_speed),
+						BlendMode::UseAlpha,
+						UI::Align_TopRight);
+		}
+	}
+}
+
+
 /**
  * See if we can reasonably open a ship window at the current selection position.
  * If so, do it and return true; otherwise, return false.

=== modified file 'src/wui/interactive_gamebase.h'
--- src/wui/interactive_gamebase.h	2014-09-10 16:57:31 +0000
+++ src/wui/interactive_gamebase.h	2014-11-30 12:35:21 +0000
@@ -84,6 +84,8 @@
 	void show_game_summary();
 
 protected:
+	void draw_overlay(RenderTarget &) override;
+
 	GameMainMenuWindows m_mainm_windows;
 	ChatProvider           * m_chatProvider;
 	std::string              m_building_census_format;

=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc	2014-11-23 14:34:38 +0000
+++ src/wui/interactive_player.cc	2014-11-30 12:35:21 +0000
@@ -163,8 +163,6 @@
 
 	adjust_toolbar_position();
 
-	set_display_flag(dfSpeed, true);
-
 #define INIT_BTN_HOOKS(registry, btn)                                        \
  registry.on_create = std::bind(&UI::Button::set_perm_pressed, &btn, true);  \
  registry.on_delete = std::bind(&UI::Button::set_perm_pressed, &btn, false); \

=== modified file 'src/wui/interactive_spectator.cc'
--- src/wui/interactive_spectator.cc	2014-11-23 14:34:38 +0000
+++ src/wui/interactive_spectator.cc	2014-11-30 12:35:21 +0000
@@ -96,8 +96,6 @@
 	// Setup all screen elements
 	fieldclicked.connect(boost::bind(&InteractiveSpectator::node_action, this));
 
-	set_display_flag(dfSpeed, true);
-
 #define INIT_BTN_HOOKS(registry, btn)                                                              \
 	registry.on_create = std::bind(&UI::Button::set_perm_pressed, &btn, true);                      \
 	registry.on_delete = std::bind(&UI::Button::set_perm_pressed, &btn, false);                     \


Follow ups