The Battle for Wesnoth  1.19.0-dev
highlighter.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2024
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 */
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. */
70  class highlight_main_visitor;
71 
72  /** Highlight the given secondary action. */
73  class highlight_secondary_visitor;
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 
90 
92 };
93 
95 public:
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:
122  void visit(move_ptr);
123  void visit(attack_ptr);
125  void visit(recall_ptr);
127 private:
129 };
130 
131 } // end namespace wb
Container associating units to locations.
Definition: map.hpp:98
Class that handles highlighting planned actions as you hover over them and determine the right target...
Definition: highlighter.hpp:39
virtual ~highlighter()
Definition: highlighter.cpp:58
side_actions_ptr side_actions_
Definition: highlighter.hpp:91
std::deque< weak_action_ptr > secondary_highlights_t
Definition: highlighter.hpp:58
void find_main_highlight()
const map_location & get_mouseover_hex() const
Definition: highlighter.hpp:46
std::set< map_location > exclusive_display_hexes_
Definition: highlighter.hpp:83
action_ptr get_bump_target()
void last_action_redraw(move_ptr)
Redraw the given move action when needed.
secondary_highlights_t secondary_highlights_
Definition: highlighter.hpp:89
weak_action_ptr get_main_highlight()
Definition: highlighter.hpp:57
unit_ptr selection_candidate_
Definition: highlighter.hpp:85
action_ptr get_execute_target()
void set_selection_candidate(unit_ptr candidate)
Definition: highlighter.hpp:62
void set_mouseover_hex(const map_location &hex)
Definition: highlighter.cpp:67
map_location mouseover_hex_
Definition: highlighter.hpp:82
secondary_highlights_t get_secondary_highlights()
Definition: highlighter.hpp:60
unit_ptr owner_unit_
Definition: highlighter.hpp:84
highlighter(side_actions_ptr side_actions)
Definition: highlighter.cpp:46
unit_map & get_unit_map()
action_ptr get_delete_target()
weak_action_ptr selected_action_
Definition: highlighter.hpp:87
unit_ptr get_selection_target()
void find_secondary_highlights()
weak_action_ptr main_highlight_
Definition: highlighter.hpp:88
This internal whiteboard class holds the planned action queues for a team, and offers many utility me...
Abstract base class for all the visitors (cf GoF Visitor Design Pattern) the whiteboard uses.
Definition: visitor.hpp:33
static lg::log_domain log_whiteboard_highlight("whiteboard/highlight")
Definition: display.hpp:45
std::shared_ptr< recruit > recruit_ptr
Definition: typedefs.hpp:72
std::weak_ptr< action > weak_action_ptr
Definition: typedefs.hpp:64
std::shared_ptr< suppose_dead > suppose_dead_ptr
Definition: typedefs.hpp:76
std::shared_ptr< move > move_ptr
Definition: typedefs.hpp:68
std::shared_ptr< action > action_ptr
Definition: typedefs.hpp:62
std::shared_ptr< attack > attack_ptr
Definition: typedefs.hpp:70
std::shared_ptr< side_actions > side_actions_ptr
Definition: typedefs.hpp:66
std::shared_ptr< recall > recall_ptr
Definition: typedefs.hpp:74
std::shared_ptr< unit > unit_ptr
Definition: ptr.hpp:26
Encapsulates the map of the game.
Definition: location.hpp:38
visitor is an abstract interface : action.accept(visitor) calls visitor.visit(action)
#define h