The Battle for Wesnoth  1.15.1+dev
highlighter.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2018 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13  */
14 
15 /**
16  * @file
17  */
18 
19 #pragma once
20 
21 #include "visitor.hpp"
22 #include "map/location.hpp"
23 
24 static lg::log_domain log_whiteboard_highlight("whiteboard/highlight");
25 #define ERR_WB_H LOG_STREAM(err, log_whiteboard_highlight)
26 #define WRN_WB_H LOG_STREAM(warn, log_whiteboard_highlight)
27 #define LOG_WB_H LOG_STREAM(info, log_whiteboard_highlight)
28 #define DBG_WB_H LOG_STREAM(debug, log_whiteboard_highlight)
29 
30 namespace wb
31 {
32 
33 /**
34  * Class that handles highlighting planned actions as you hover over them
35  * and determine the right target for contextual execution.
36  */
38 {
39 
40 public:
42  virtual ~highlighter();
43 
44  void set_mouseover_hex(const map_location& hex);
45  const map_location& get_mouseover_hex() const {return mouseover_hex_; }
46 
47  void highlight();
48  void clear();
49 
54 
55  /// @return the action that currently receives the highlight focus
57  typedef std::deque<weak_action_ptr> secondary_highlights_t;
58  /// @return the collection of actions that are highlighted but don't have the focus
59  secondary_highlights_t get_secondary_highlights() { return secondary_highlights_; }
60 
61  void set_selection_candidate(unit_ptr candidate) { selection_candidate_ = candidate; }
62 
63 private:
65  /** Unhighlight a given action (main or secondary). */
66  class unhighlight_visitor;
67 
68  /** Highlight the given main action. */
70 
71  /** Highlight the given secondary action. */
73 
74  void unhighlight();
75  void find_main_highlight();
77 
78  /** Redraw the given move action when needed. */
80 
82  std::set<map_location> exclusive_display_hexes_;
85 
88  secondary_highlights_t secondary_highlights_;
89 
91 };
92 
94 public:
95  highlight_main_visitor(highlighter &h): highlighter_(h) {}
96  void visit(move_ptr);
97  void visit(attack_ptr);
98  void visit(recruit_ptr);
99  /// @todo: find some suitable effect for mouseover on planned recall.
102 private:
104 };
105 
107 public:
109  void visit(move_ptr);
110  void visit(attack_ptr);
114 private:
116 };
117 
119 public:
120  unhighlight_visitor(highlighter &h): highlighter_(h) {}
121  void visit(move_ptr);
122  void visit(attack_ptr);
124  void visit(recall_ptr);
126 private:
128 };
129 
130 } // end namespace wb
action_ptr get_delete_target()
side_actions_ptr side_actions_
Definition: highlighter.hpp:90
weak_action_ptr main_highlight_
Definition: highlighter.hpp:87
unit_ptr owner_unit_
Definition: highlighter.hpp:83
void find_main_highlight()
std::shared_ptr< side_actions > side_actions_ptr
Definition: typedefs.hpp:65
weak_action_ptr selected_action_
Definition: highlighter.hpp:86
std::shared_ptr< attack > attack_ptr
Definition: typedefs.hpp:69
#define h
void find_secondary_highlights()
map_location mouseover_hex_
Definition: highlighter.hpp:81
unit_map & get_unit_map()
const map_location & get_mouseover_hex() const
Definition: highlighter.hpp:45
secondary_highlights_t get_secondary_highlights()
Definition: highlighter.hpp:59
unit_ptr selection_candidate_
Definition: highlighter.hpp:84
static lg::log_domain log_whiteboard_highlight("whiteboard/highlight")
std::shared_ptr< recruit > recruit_ptr
Definition: typedefs.hpp:71
highlighter(side_actions_ptr side_actions)
Definition: highlighter.cpp:52
secondary_highlights_t secondary_highlights_
Definition: highlighter.hpp:88
virtual ~highlighter()
Definition: highlighter.cpp:64
Class that handles highlighting planned actions as you hover over them and determine the right target...
Definition: highlighter.hpp:37
std::shared_ptr< action > action_ptr
Definition: typedefs.hpp:61
void set_selection_candidate(unit_ptr candidate)
Definition: highlighter.hpp:61
Encapsulates the map of the game.
Definition: location.hpp:42
std::deque< weak_action_ptr > secondary_highlights_t
Definition: highlighter.hpp:57
void set_mouseover_hex(const map_location &hex)
Definition: highlighter.cpp:73
std::shared_ptr< suppose_dead > suppose_dead_ptr
Definition: typedefs.hpp:75
std::shared_ptr< move > move_ptr
Definition: typedefs.hpp:67
std::weak_ptr< action > weak_action_ptr
Definition: typedefs.hpp:63
boost::intrusive_ptr< unit > unit_ptr
Definition: ptr.hpp:29
action_ptr get_bump_target()
unit_ptr get_selection_target()
std::set< map_location > exclusive_display_hexes_
Definition: highlighter.hpp:82
Container associating units to locations.
Definition: map.hpp:99
std::shared_ptr< recall > recall_ptr
Definition: typedefs.hpp:73
void last_action_redraw(move_ptr)
Redraw the given move action when needed.
visitor is an abstract interface : action.accept(visitor) calls visitor.visit(action) ...
action_ptr get_execute_target()
weak_action_ptr get_main_highlight()
Definition: highlighter.hpp:56
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
Definition: display.hpp:48
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses...
Definition: visitor.hpp:31