Author: tschmitz
Date: Fri Aug 19 01:39:21 2011
New Revision: 50845

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50845&view=rev
Log:
Added whiteboard options dialog.

Modified:
    trunk/src/game_display.cpp
    trunk/src/game_preferences.cpp
    trunk/src/game_preferences.hpp
    trunk/src/menu_events.cpp
    trunk/src/whiteboard/manager.cpp
    trunk/src/whiteboard/manager.hpp

Modified: trunk/src/game_display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_display.cpp?rev=50845&r1=50844&r2=50845&view=diff
==============================================================================
--- trunk/src/game_display.cpp (original)
+++ trunk/src/game_display.cpp Fri Aug 19 01:39:21 2011
@@ -1310,7 +1310,8 @@
                viewpoint_ = NULL;
        }
        labels().recalculate_labels();
-       resources::whiteboard->on_viewer_change(teamindex);
+       if(resources::whiteboard)
+               resources::whiteboard->on_viewer_change(teamindex);
 }
 
 void game_display::set_playing_team(size_t teamindex)

Modified: trunk/src/game_preferences.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_preferences.cpp?rev=50845&r1=50844&r2=50845&view=diff
==============================================================================
--- trunk/src/game_preferences.cpp (original)
+++ trunk/src/game_preferences.cpp Fri Aug 19 01:39:21 2011
@@ -407,6 +407,16 @@
        preferences::set("enable_planning_mode_on_start", value);
 }
 
+bool hide_whiteboard()
+{
+       return preferences::get("hide_whiteboard", false);
+}
+
+void set_hide_whiteboard(bool value)
+{
+       preferences::set("hide_whiteboard", value);
+}
+
 bool show_combat()
 {
        return preferences::get("show_combat", true);

Modified: trunk/src/game_preferences.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_preferences.hpp?rev=50845&r1=50844&r2=50845&view=diff
==============================================================================
--- trunk/src/game_preferences.hpp (original)
+++ trunk/src/game_preferences.hpp Fri Aug 19 01:39:21 2011
@@ -93,6 +93,9 @@
        bool enable_whiteboard_mode_on_start();
        void set_enable_whiteboard_mode_on_start(bool value);
 
+       bool hide_whiteboard();
+       void set_hide_whiteboard(bool value);
+
        bool show_combat();
 
        bool allow_observers();

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=50845&r1=50844&r2=50845&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Fri Aug 19 01:39:21 2011
@@ -2493,6 +2493,7 @@
                void do_toggle_draw_coordinates();
                void do_toggle_draw_terrain_codes();
                void do_toggle_whiteboard();
+               void do_whiteboard_options();
 
                std::string get_flags_description() const {
                        return _("(D) - debug only, (N) - network only, (A) - 
admin only");
@@ -2621,6 +2622,9 @@
                        register_command("whiteboard", 
&console_handler::do_toggle_whiteboard,
                                _("Toggle planning mode."));
                        register_alias("whiteboard", "wb");
+                       register_command("whiteboard_options", 
&console_handler::do_whiteboard_options,
+                               _("Access whiteboard options dialog."));
+                       register_alias("whiteboard_options", "wbo");
 
                        if (const config &alias_list = preferences::get_alias())
                        {
@@ -3623,6 +3627,11 @@
        }
 }
 
+void console_handler::do_whiteboard_options()
+{
+       resources::whiteboard->options_dlg();
+}
+
 void menu_handler::do_ai_formula(const std::string& str,
        int side_num, mouse_handler& /*mousehandler*/)
 {

Modified: trunk/src/whiteboard/manager.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.cpp?rev=50845&r1=50844&r2=50845&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.cpp (original)
+++ trunk/src/whiteboard/manager.cpp Fri Aug 19 01:39:21 2011
@@ -31,7 +31,10 @@
 #include "arrow.hpp"
 #include "chat_events.hpp"
 #include "foreach.hpp"
+#include "formula_string_utils.hpp"
 #include "game_preferences.hpp"
+#include "gettext.hpp"
+#include "gui/dialogs/simple_item_selector.hpp"
 #include "key.hpp"
 #include "network.hpp"
 #include "pathfind/pathfind.hpp"
@@ -61,7 +64,8 @@
                fake_unit_(),
                key_poller_(new CKey),
                hidden_unit_hex_(),
-               net_buffer_(resources::teams->size())
+               net_buffer_(resources::teams->size()),
+               team_plans_hidden_(resources::teams->size(),false)
 {
        LOG_WB << "Manager initialized.\n";
 }
@@ -229,7 +233,7 @@
 
 void manager::on_init_side()
 {
-       validate_viewer_actions();
+       update_plan_hiding(); //< validates actions
        wait_for_side_init_ = false;
        LOG_WB << "on_init_side()\n";
 
@@ -254,7 +258,8 @@
                t.get_side_actions()->hide();
 }
 
-void manager::on_viewer_change(size_t team_index)
+/* private */
+void manager::update_plan_hiding(size_t team_index) const
 {
        //We don't control the "viewing" side ... we're probably an observer
        if(!resources::teams->at(team_index).is_human())
@@ -263,13 +268,19 @@
        {
                foreach(team& t, *resources::teams)
                {
-                       if(t.is_enemy(team_index+1))
+                       if(t.is_enemy(team_index+1) || 
team_plans_hidden_[t.side()-1])
                                t.get_side_actions()->hide();
                        else
                                t.get_side_actions()->show();
                }
        }
-}
+       resources::teams->at(team_index).get_side_actions()->validate_actions();
+}
+void manager::update_plan_hiding() const
+       {update_plan_hiding(viewer_team());}
+
+void manager::on_viewer_change(size_t team_index)
+       {update_plan_hiding(team_index);}
 
 void manager::on_change_controller(int side, team& t)
 {
@@ -280,7 +291,7 @@
                
resources::whiteboard->queue_net_cmd(sa.team_index(),sa.make_net_cmd_clear());
                sa.clear();
                //refresh the hidden_ attribute of every team's side_actions
-               on_viewer_change(viewer_team());
+               update_plan_hiding();
        }
        else if(t.is_ai() || t.is_network_ai()) //< no one owns this side 
anymore
                sa.clear(); //< clear its plans away -- the ai doesn't plan ... 
yet
@@ -903,6 +914,67 @@
        resources::redo_stack->clear();
 }
 
+void manager::options_dlg()
+{
+       int v_side = viewer_side();
+
+       int selection = 0;
+
+       std::vector<team*> allies;
+       std::vector<std::string> options;
+       utils::string_map t_vars;
+
+       options.push_back(_("SHOW ALL allies' plans"));
+       options.push_back(_("HIDE ALL allies' plans"));
+
+       //populate list of networked allies
+       foreach(team &t, *resources::teams)
+       {
+               //Exclude enemies, AIs, and local players
+               if(t.is_enemy(v_side) || !t.is_network())
+                       continue;
+
+               allies.push_back(&t);
+
+               t_vars["player"] = t.current_player();
+               size_t t_index = t.side()-1;
+               if(team_plans_hidden_[t_index])
+                       options.push_back(vgettext("Show plans for $player", 
t_vars));
+               else
+                       options.push_back(vgettext("Hide plans for $player", 
t_vars));
+       }
+
+       gui2::tsimple_item_selector dlg("", _("Whiteboard Options"), options);
+       dlg.show(resources::screen->video());
+       selection = dlg.selected_index();
+
+       if(selection == -1)
+               return;
+
+       switch(selection)
+       {
+       case 0:
+               preferences::set_hide_whiteboard(false);
+               foreach(team* t, allies)
+                       team_plans_hidden_[t->side()-1]=false;
+               break;
+       case 1:
+               preferences::set_hide_whiteboard(true);
+               foreach(team* t, allies)
+                       team_plans_hidden_[t->side()-1]=true;
+               break;
+       default:
+               if(selection > 1)
+               {
+                       size_t t_index = allies[selection-2]->side()-1;
+                       //toggle ...
+                       bool hidden = team_plans_hidden_[t_index];
+                       team_plans_hidden_[t_index] = !hidden;
+               }
+       }
+       update_plan_hiding();
+}
+
 scoped_planned_unit_map::scoped_planned_unit_map():
                
has_planned_unit_map_(resources::whiteboard->has_planned_unit_map())
 {

Modified: trunk/src/whiteboard/manager.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.hpp?rev=50845&r1=50844&r2=50845&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.hpp (original)
+++ trunk/src/whiteboard/manager.hpp Fri Aug 19 01:39:21 2011
@@ -159,10 +159,15 @@
        /// Updates shroud and clears the undo_stack and redo_stack.
        void clear_undo();
 
+       /// Displays the whiteboard options dialog.
+       void options_dlg();
+
 private:
        void validate_actions_if_needed();
        /// Called by all of the save_***() methods after they have added their 
action to the queue
        void on_save_action() const;
+       void update_plan_hiding(size_t viewing_team) const;
+       void update_plan_hiding() const; //same as above, but uses 
wb::viewer_team() as default argument
 
        ///Tracks whether the whiteboard is active.
        bool active_;
@@ -190,6 +195,9 @@
 
        ///net_buffer_[i] = whiteboard network data to be sent "from" teams[i].
        std::vector<config> net_buffer_;
+
+       ///team_plans_hidden_[i] = whether or not to hide actions from teams[i].
+       std::vector<bool> team_plans_hidden_;
 };
 
 /** Applies the planned unit map for the duration of the struct's life.


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to