← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~nomeata/widelands/statistics-menu-settings-persistent into lp:widelands

 

Joachim Breitner has proposed merging lp:~nomeata/widelands/statistics-menu-settings-persistent into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #840377 in widelands: "WL should remember which section in general statistic the user had opened last"
  https://bugs.launchpad.net/widelands/+bug/840377

For more details, see:
https://code.launchpad.net/~nomeata/widelands/statistics-menu-settings-persistent/+merge/81411

This makes the general statistics menu remember the selected category (but not the selected player or others, but now that the infrastructure is there, that can easily be added).
-- 
https://code.launchpad.net/~nomeata/widelands/statistics-menu-settings-persistent/+merge/81411
Your team Widelands Developers is requested to review the proposed merge of lp:~nomeata/widelands/statistics-menu-settings-persistent into lp:widelands.
=== modified file 'src/ui_basic/unique_window.cc'
--- src/ui_basic/unique_window.cc	2010-10-17 16:54:32 +0000
+++ src/ui_basic/unique_window.cc	2011-11-06 18:17:25 +0000
@@ -33,7 +33,7 @@
 */
 void UniqueWindow::Registry::create() {
 	if (not window) {
-		constr(*this);
+		constr();
 	}
 }
 
@@ -53,7 +53,7 @@
 	if (window) {
 		delete window;
 	} else {
-		constr(*this);
+		constr();
 	}
 }
 

=== modified file 'src/ui_basic/unique_window.h'
--- src/ui_basic/unique_window.h	2010-11-05 19:36:57 +0000
+++ src/ui_basic/unique_window.h	2011-11-06 18:17:25 +0000
@@ -40,7 +40,7 @@
 		UniqueWindow * window;
 		boost::function<void()> onCreate;
 		boost::function<void()> onDelete;
-		boost::function<void(Registry &)> constr;
+		boost::function<void()> constr;
 
 		void create();
 		void destroy();

=== modified file 'src/wui/game_main_menu.cc'
--- src/wui/game_main_menu.cc	2010-11-21 11:44:22 +0000
+++ src/wui/game_main_menu.cc	2011-11-06 18:17:25 +0000
@@ -48,7 +48,7 @@
 	 posx(0, 4), posy(0, 3), buttonw(4), buttonh(1),
 	 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
 	 g_gr->get_picture(PicMod_Game, "pics/menu_general_stats.png"),
-	 boost::bind(&UI::UniqueWindow::Registry::toggle, boost::ref(m_windows.general_stats)),
+	 boost::bind(&General_Statistics_Menu::Registry::toggle, boost::ref(m_windows.general_stats)),
 	 _("General Statistics")),
 ware_stats
 	(this, "ware_stats",
@@ -85,14 +85,21 @@
 	INIT_BTN_HOOKS(m_windows.stock, stock)
 
 	m_windows.general_stats.constr = boost::lambda::bind
-		(boost::lambda::new_ptr<General_Statistics_Menu>(), boost::ref(m_player), boost::lambda::_1);
+		(boost::lambda::new_ptr<General_Statistics_Menu>(),
+		 boost::ref(m_player),
+		 boost::ref(m_windows.general_stats));
 	m_windows.ware_stats.constr = boost::lambda::bind
-		(boost::lambda::new_ptr<Ware_Statistics_Menu>(), boost::ref(m_player), boost::lambda::_1);
+		(boost::lambda::new_ptr<Ware_Statistics_Menu>(),
+		 boost::ref(m_player),
+		 boost::ref(m_windows.ware_stats));
 	m_windows.building_stats.constr = boost::lambda::bind
-		(boost::lambda::new_ptr<Building_Statistics_Menu>(), boost::ref(m_player), boost::lambda::_1);
+		(boost::lambda::new_ptr<Building_Statistics_Menu>(),
+		 boost::ref(m_player),
+		 boost::ref(m_windows.building_stats));
 	m_windows.stock.constr = boost::lambda::bind
-		(boost::lambda::new_ptr<Stock_Menu>(), boost::ref(m_player), boost::lambda::_1);
-
+		(boost::lambda::new_ptr<Stock_Menu>(),
+		 boost::ref(m_player),
+		 boost::ref(m_windows.stock));
 	if (get_usedefaultpos())
 		center_to_parent();
 }

=== modified file 'src/wui/game_options_menu.cc'
--- src/wui/game_options_menu.cc	2010-11-21 11:44:22 +0000
+++ src/wui/game_options_menu.cc	2011-11-06 18:17:25 +0000
@@ -100,9 +100,18 @@
 		 _("Exit Game"))
 {
 
-	m_windows.readme.constr = boost::bind(&fileview_window, boost::ref(m_gb), _1, "txts/README");
-	m_windows.license.constr = boost::bind(&fileview_window, boost::ref(m_gb), _1, "txts/COPYING");
-	m_windows.authors.constr = boost::bind(&fileview_window, boost::ref(m_gb), _1, "txts/developers");
+	m_windows.readme.constr = boost::bind
+		(&fileview_window, boost::ref(m_gb),
+		 boost::ref(m_windows.readme),
+		 "txts/README");
+	m_windows.license.constr = boost::bind
+		(&fileview_window, boost::ref(m_gb),
+		 boost::ref(m_windows.license),
+		 "txts/COPYING");
+	m_windows.authors.constr = boost::bind
+		(&fileview_window, boost::ref(m_gb),
+		 boost::ref(m_windows.authors),
+		 "txts/developers");
 
 #define INIT_BTN_HOOKS(registry, btn)                                        \
  registry.onCreate = boost::bind(&UI::Button::set_perm_pressed, &btn, true);  \

=== modified file 'src/wui/general_statistics_menu.cc'
--- src/wui/general_statistics_menu.cc	2011-11-06 12:38:07 +0000
+++ src/wui/general_statistics_menu.cc	2011-11-06 18:17:25 +0000
@@ -42,14 +42,20 @@
 #define NR_BASE_DATASETS 11
 
 General_Statistics_Menu::General_Statistics_Menu
-	(Interactive_GameBase & parent, UI::UniqueWindow::Registry & registry)
+	(Interactive_GameBase & parent, General_Statistics_Menu::Registry & registry)
 :
 UI::UniqueWindow
 	(&parent, "statistics_menu", &registry,
 	 440, 400, _("General Statistics")),
+m_my_registry      (&registry),
 m_box           (this, 0, 0, UI::Box::Vertical, 0, 0, 5),
-m_plot          (&m_box, 0, 0, 430, PLOT_HEIGHT)
+m_plot          (&m_box, 0, 0, 430, PLOT_HEIGHT),
+m_selected_information(0)
 {
+	if (m_my_registry) {
+		m_selected_information = m_my_registry->selected_information;
+	}
+
 	set_center_panel(&m_box);
 	m_box.set_border(5, 5, 5, 5);
 
@@ -257,8 +263,7 @@
 		hbox2->add(btn, UI::Box::AlignLeft);
 	}
 
-	m_radiogroup.set_state(0);
-	m_selected_information = 0;
+	m_radiogroup.set_state(m_selected_information);
 	m_radiogroup.changedto.set
 		(this, &General_Statistics_Menu::radiogroup_changed);
 
@@ -273,6 +278,11 @@
 
 }
 
+General_Statistics_Menu::~General_Statistics_Menu() {
+	if (m_my_registry) {
+		m_my_registry->selected_information = m_selected_information;
+	}
+}
 
 /**
  * called when the help button was clicked

=== modified file 'src/wui/general_statistics_menu.h'
--- src/wui/general_statistics_menu.h	2011-11-06 12:38:07 +0000
+++ src/wui/general_statistics_menu.h	2011-11-06 18:17:25 +0000
@@ -35,10 +35,20 @@
 }
 
 struct General_Statistics_Menu : public UI::UniqueWindow {
+
+	// Custom registry, to store the selected_information as well.
+	struct Registry : public UI::UniqueWindow::Registry {
+		Registry() : UI::UniqueWindow::Registry(), selected_information(0) {}
+
+		int32_t selected_information;
+	};
+
 	General_Statistics_Menu
-		(Interactive_GameBase &, UI::UniqueWindow::Registry &);
+		(Interactive_GameBase &, Registry &);
+	virtual ~General_Statistics_Menu();
 
 private:
+	Registry           * m_my_registry;
 	UI::Box              m_box;
 	WUIPlot_Area         m_plot;
 	UI::Radiogroup       m_radiogroup;

=== modified file 'src/wui/interactive_gamebase.h'
--- src/wui/interactive_gamebase.h	2011-02-19 23:53:52 +0000
+++ src/wui/interactive_gamebase.h	2011-11-06 18:17:25 +0000
@@ -23,6 +23,7 @@
 #include "interactive_base.h"
 #include "logic/game.h"
 #include "graphic/graphic.h"
+#include "general_statistics_menu.h"
 
 struct ChatOverlay;
 struct ChatProvider;
@@ -40,7 +41,7 @@
 		UI::UniqueWindow::Registry sound_options;
 
 		UI::UniqueWindow::Registry building_stats;
-		UI::UniqueWindow::Registry general_stats;
+		General_Statistics_Menu::Registry general_stats;
 		UI::UniqueWindow::Registry ware_stats;
 		UI::UniqueWindow::Registry stock;
 	};

=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc	2011-11-04 21:57:40 +0000
+++ src/wui/interactive_player.cc	2011-11-06 18:17:25 +0000
@@ -189,25 +189,25 @@
 	m_encyclopedia.constr = boost::lambda::bind
 		(boost::lambda::new_ptr<EncyclopediaWindow>(),
 		 boost::ref(*this),
-		 boost::lambda::_1);
+		 boost::ref(m_encyclopedia));
 	m_options.constr = boost::lambda::bind
 		(boost::lambda::new_ptr<GameOptionsMenu>(),
 		 boost::ref(*this),
-		 boost::lambda::_1,
+		 boost::ref(m_options),
 		 boost::ref(m_mainm_windows));
 	m_statisticsmenu.constr = boost::lambda::bind
 		(boost::lambda::new_ptr<GameMainMenu>(),
 		 boost::ref(*this),
-		 boost::lambda::_1,
+		 boost::ref(m_statisticsmenu),
 		 boost::ref(m_mainm_windows));
 	m_objectives.constr = boost::lambda::bind
 		(boost::lambda::new_ptr<GameObjectivesMenu>(),
 		 boost::ref(*this),
-		 boost::lambda::_1);
+		 boost::ref(m_objectives));
 	m_message_menu.constr = boost::lambda::bind
 		(boost::lambda::new_ptr<GameMessageMenu>(),
 		 boost::ref(*this),
-		 boost::lambda::_1);
+		 boost::ref(m_message_menu));
 
 #ifdef DEBUG //  only in debug builds
 	addCommand


Follow ups