← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~nomeata/widelands/bugfix667000 into lp:widelands

 

Joachim Breitner has proposed merging lp:~nomeata/widelands/bugfix667000 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  #667000 Buttons in Replay watcher and network observer are not toggable
  https://bugs.launchpad.net/bugs/667000


Fixes 667000 (sticky buttons for Replay/Observer)
-- 
https://code.launchpad.net/~nomeata/widelands/bugfix667000/+merge/39456
Your team Widelands Developers is requested to review the proposed merge of lp:~nomeata/widelands/bugfix667000 into lp:widelands.
=== modified file 'src/wui/interactive_spectator.cc'
--- src/wui/interactive_spectator.cc	2010-10-17 19:32:07 +0000
+++ src/wui/interactive_spectator.cc	2010-10-27 16:18:52 +0000
@@ -98,6 +98,37 @@
 	fieldclicked.set(this, &Interactive_Spectator::node_action);
 
 	set_display_flag(dfSpeed, true);
+
+#define INIT_BTN_HOOKS(registry, btn)                                        \
+ registry.onCreate = boost::bind(&UI::Button::set_perm_pressed,&btn, true);  \
+ registry.onDelete = boost::bind(&UI::Button::set_perm_pressed,&btn, false); \
+ if (registry.window) btn.set_perm_pressed(true);                            \
+
+        INIT_BTN_HOOKS(m_chat, m_toggle_chat)
+        INIT_BTN_HOOKS(m_options, m_toggle_options_menu)
+        INIT_BTN_HOOKS(m_mainm_windows.general_stats, m_toggle_statistics)
+        INIT_BTN_HOOKS(m_mainm_windows.savegame, m_save)
+        INIT_BTN_HOOKS(minimap_registry(), m_toggle_minimap)
+
+}
+
+Interactive_Spectator::~Interactive_Spectator() {
+	// We need to remove these callbacks because the opened window might
+        // (theoretically) live longer than 'this' window, and thus the
+        // buttons. The assertions are safeguards in case somewhere else in the
+        // code someone would overwrite our hooks. 
+
+#define DEINIT_BTN_HOOKS(registry, btn)                                                \
+ assert (registry.onCreate == boost::bind(&UI::Button::set_perm_pressed,&btn, true));  \
+ assert (registry.onDelete == boost::bind(&UI::Button::set_perm_pressed,&btn, false)); \
+ registry.onCreate = 0;                                                                \
+ registry.onDelete = 0;                                                                \
+
+        DEINIT_BTN_HOOKS(m_chat, m_toggle_chat)
+        DEINIT_BTN_HOOKS(m_options, m_toggle_options_menu)
+        DEINIT_BTN_HOOKS(m_mainm_windows.general_stats, m_toggle_statistics)
+        DEINIT_BTN_HOOKS(m_mainm_windows.savegame, m_save)
+        DEINIT_BTN_HOOKS(minimap_registry(), m_toggle_minimap)
 }
 
 

=== modified file 'src/wui/interactive_spectator.h'
--- src/wui/interactive_spectator.h	2010-10-17 19:42:01 +0000
+++ src/wui/interactive_spectator.h	2010-10-27 16:18:52 +0000
@@ -38,6 +38,8 @@
 	Interactive_Spectator
 		(Widelands::Game &, Section & global_s, bool multiplayer = false);
 
+	~Interactive_Spectator();
+
 	void start();
 
 	Widelands::Player * get_player() const throw ();


Follow ups