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