whiteboard/highlight_visitor.hpp

Go to the documentation of this file.
00001 /* $Id: highlight_visitor.hpp 53009 2012-02-14 18:10:04Z mordante $ */
00002 /*
00003  Copyright (C) 2010 - 2012 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
00004  Part of the Battle for Wesnoth Project http://www.wesnoth.org
00005 
00006  This program is free software; you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010  This program is distributed in the hope that it will be useful,
00011  but WITHOUT ANY WARRANTY.
00012 
00013  See the COPYING file for more details.
00014  */
00015 
00016 /**
00017  * @file
00018  */
00019 
00020 #ifndef WB_HIGHLIGHT_VISITOR_HPP_
00021 #define WB_HIGHLIGHT_VISITOR_HPP_
00022 
00023 #include "visitor.hpp"
00024 
00025 static lg::log_domain log_whiteboard_highlight("whiteboard/highlight");
00026 #define ERR_WB_H LOG_STREAM(err, log_whiteboard_highlight)
00027 #define WRN_WB_H LOG_STREAM(warn, log_whiteboard_highlight)
00028 #define LOG_WB_H LOG_STREAM(info, log_whiteboard_highlight)
00029 #define DBG_WB_H LOG_STREAM(debug, log_whiteboard_highlight)
00030 
00031 namespace wb
00032 {
00033 
00034 /**
00035  * Visitor that handles highlighting planned actions as you hover over them,
00036  * and determine the right target for contextual execution.
00037  */
00038 class highlight_visitor
00039     : private visitor
00040     , private enable_visit_all<highlight_visitor>
00041 {
00042     friend class enable_visit_all<highlight_visitor>;
00043 
00044 public:
00045     highlight_visitor(unit_map& unit_map, side_actions_ptr side_actions);
00046     virtual ~highlight_visitor();
00047 
00048     void set_mouseover_hex(const map_location& hex);
00049     const map_location& get_mouseover_hex() const {return mouseover_hex_; }
00050 
00051     void highlight();
00052     void clear();
00053 
00054     action_ptr get_execute_target();
00055     action_ptr get_delete_target();
00056     action_ptr get_bump_target();
00057     unit* get_selection_target();
00058 
00059     /// @return the action the currently receives the highlight focus
00060     weak_action_ptr get_main_highlight() { return main_highlight_; }
00061     typedef std::deque<weak_action_ptr> secondary_highlights_t;
00062     /// @return the collection of actions that are highlighted but don't have the focus
00063     secondary_highlights_t get_secondary_highlights() { return secondary_highlights_; }
00064 
00065 private:
00066     virtual void visit(move_ptr move);
00067     virtual void visit(attack_ptr attack);
00068     virtual void visit(recruit_ptr recruit);
00069     virtual void visit(recall_ptr recall);
00070     virtual void visit(suppose_dead_ptr sup_d);
00071 
00072     //"Inherited" from enable_visit_all
00073     bool process(size_t team_index, team&, side_actions&, side_actions::iterator);
00074 
00075     void unhighlight();
00076 
00077     void find_main_highlight();
00078     void find_secondary_highlights();
00079 
00080     enum mode {
00081         FIND_MAIN_HIGHLIGHT,
00082         FIND_SECONDARY_HIGHLIGHTS,
00083         HIGHLIGHT_MAIN,
00084         HIGHLIGHT_SECONDARY,
00085         UNHIGHLIGHT_MAIN,
00086         UNHIGHLIGHT_SECONDARY,
00087         NONE
00088     };
00089 
00090     mode mode_;
00091 
00092     unit_map& unit_map_;
00093 
00094     map_location mouseover_hex_;
00095     std::set<map_location> exclusive_display_hexes_;
00096     unit* owner_unit_;
00097     unit* selection_candidate_;
00098 
00099     weak_action_ptr selected_action_;
00100     weak_action_ptr main_highlight_;
00101     secondary_highlights_t secondary_highlights_;
00102 
00103     side_actions_ptr side_actions_;
00104 };
00105 
00106 } // end namespace wb
00107 
00108 #endif /* WB_HIGHLIGHT_VISITOR_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:15 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs