The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mouse_events.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2016 by Joerg Hinrichs <[email protected]>
3  wesnoth playturn Copyright (C) 2003 by David White <[email protected]>
4  Part of the Battle for Wesnoth Project http://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 #ifndef MOUSE_EVENTS_H_INCLUDED
17 #define MOUSE_EVENTS_H_INCLUDED
18 
19 #include "game_display.hpp" // for game_display -> display conversion.
20 #include "map/location.hpp" // for map_location
21 #include "mouse_handler_base.hpp" // for mouse_handler_base
22 #include "pathfind/pathfind.hpp" // for marked_route, paths
23 #include "units/map.hpp" // for unit_map, etc
24 
25 #include <set> // for set
26 #include <vector> // for vector
27 #include <SDL_events.h> // for SDL_MouseButtonEvent
28 
29 class game_display;
30 class battle_context; // lines 23-23
31 class play_controller;
32 class team;
33 class unit;
34 
35 namespace events{
36 
38 public:
41  static mouse_handler* get_singleton() { return singleton_ ;}
42  void set_side(int side_number);
43  void mouse_press(const SDL_MouseButtonEvent& event, const bool browse);
44  void cycle_units(const bool browse, const bool reverse = false);
45  void cycle_back_units(const bool browse) { cycle_units(browse, true); }
46 
47  int get_path_turns() const { return path_turns_; }
48 
49  /**
50  * @param loc the location occupied by the enemy
51  * @returns the location from which the selected unit can attack the enemy
52  */
54  const pathfind::paths& current_paths() const { return current_paths_; }
55 
56  const map_location& get_last_hex() const { return last_hex_; }
58  void set_path_turns(const int path_turns) { path_turns_ = path_turns; }
59  void set_current_paths(const pathfind::paths & new_paths);
60  void deselect_hex();
62 
63  void set_gui(game_display* gui) { gui_ = gui; }
64 
66 
67  pathfind::marked_route get_route(const unit* un, map_location go_to, team &team) const;
68 
70 
71  //get visible adjacent enemies of 1-based side around location loc
72  std::set<map_location> get_adj_enemies(const map_location& loc, int side) const;
73 
74  // show the attack dialog and return the choice made
75  // which can be invalid if 'cancel' was used
76  int show_attack_dialog(const map_location& attacker_loc, const map_location& defender_loc);
77  // wrapper to catch bad_alloc so this should be called
78  void attack_enemy(const map_location& attacker_loc, const map_location& defender_loc, int choice);
79 
80  /// Moves a unit across the board for a player.
81  size_t move_unit_along_route(const std::vector<map_location> & steps, bool & interrupted);
82 
83  void select_hex(const map_location& hex, const bool browse,
84  const bool highlight = true,
85  const bool fire_event = true);
86 
87  void move_action(bool browse);
88 
89  void select_or_action(bool browse);
90 
91  void left_mouse_up(int x, int y, const bool /*browse*/);
92  void mouse_wheel_up(int x, int y, const bool /*browse*/);
93  void mouse_wheel_down(int x, int y, const bool /*browse*/);
94  void mouse_wheel_left(int x, int y, const bool /*browse*/);
95  void mouse_wheel_right(int x, int y, const bool /*browse*/);
96 
97 protected:
98  /**
99  * Due to the way this class is constructed we can assume that the
100  * display* gui_ member actually points to a game_display (derived class)
101  */
102  game_display& gui() { return *gui_; }
103  /** Const version */
104  const game_display& gui() const { return *gui_; }
105 
106  int drag_threshold() const;
107  /**
108  * Use update to force an update of the mouse state.
109  */
110  void mouse_motion(int x, int y, const bool browse, bool update=false, map_location loc = map_location::null_location());
111  bool right_click_show_menu(int x, int y, const bool browse);
112 // bool left_click(int x, int y, const bool browse);
114 
115  void save_whiteboard_attack(const map_location& attacker_loc, const map_location& defender_loc, int weapon_choice);
116 
117  // fill weapon choices into bc_vector
118  // return the best weapon choice
119  int fill_weapon_choices(std::vector<battle_context>& bc_vector, unit_map::iterator attacker, unit_map::iterator defender);
120  // the real function but can throw bad_alloc
121  // choice is the attack chosen in the attack dialog
122  void attack_enemy_(const map_location& attacker_loc
123  , const map_location& defender_loc
124  , int choice);
125 
130 private:
131  team& viewing_team();
132  const team& viewing_team() const;
133  team &current_team();
134 
137 
138  // previous highlighted hexes
139  // the hex of the selected unit and empty hex are "free"
149 
153 
155 };
156 
157 }
158 
159 #endif
void set_current_paths(const pathfind::paths &new_paths)
int get_path_turns() const
int fill_weapon_choices(std::vector< battle_context > &bc_vector, unit_map::iterator attacker, unit_map::iterator defender)
void mouse_press(const SDL_MouseButtonEvent &event, const bool browse)
Definition: unit.hpp:95
map_location selected_hex_
unit_map::const_iterator find_unit(const map_location &hex) const
pathfind::marked_route get_route(const unit *un, map_location go_to, team &team) const
pathfind::paths current_paths_
General purpose widgets.
const pathfind::marked_route & get_current_route() const
bool move_unit_along_current_route()
Moves a unit along the currently cached route.
bool unit_in_cycle(unit_map::const_iterator it)
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
const map_location & get_last_hex() const
map_location previous_hex_
void mouse_motion(int x, int y, const bool browse, bool update=false, map_location loc=map_location::null_location())
Use update to force an update of the mouse state.
void select_hex(const map_location &hex, const bool browse, const bool highlight=true, const bool fire_event=true)
map_location get_selected_hex() const
static mouse_handler * singleton_
const game_display & gui() const
Const version.
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
static mouse_handler * get_singleton()
void set_path_turns(const int path_turns)
map_location current_unit_attacks_from(const map_location &loc) const
Computes the statistics of a battle between an attacker and a defender unit.
Definition: attack.hpp:135
void set_gui(game_display *gui)
Structure which holds a single route and marks for special events.
Definition: pathfind.hpp:141
static const map_location & null_location()
Definition: location.hpp:195
void mouse_wheel_right(int x, int y, const bool)
Called when the mouse wheel is scrolled right.
bool right_click_show_menu(int x, int y, const bool browse)
Called in the default right_click when the context menu is about to be shown, can be used for preproc...
Encapsulates the map of the game.
Definition: location.hpp:38
void cycle_back_units(const bool browse)
void left_mouse_up(int x, int y, const bool)
Called when the left mouse button is up.
void attack_enemy(const map_location &attacker_loc, const map_location &defender_loc, int choice)
unit_map::iterator selected_unit()
void save_whiteboard_attack(const map_location &attacker_loc, const map_location &defender_loc, int weapon_choice)
map_location previous_free_hex_
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
mouse_handler(game_display *gui, play_controller &pc)
void cycle_units(const bool browse, const bool reverse=false)
bool fire_event(const tevent event, std::vector< std::pair< twidget *, tevent > > &event_chain, twidget *dispatcher, twidget *widget, F functor)
Helper function for fire_event.
play_controller & pc_
Handling of system events.
Definition: manager.hpp:42
size_t move_unit_along_route(const std::vector< map_location > &steps, bool &interrupted)
Moves a unit across the board for a player.
map_location last_hex_
last highlighted hex
int drag_threshold() const
void show_attack_options(const unit_map::const_iterator &u)
Causes attackable hexes to be highlighted.
cl_event event
Definition: glew.h:3070
void mouse_wheel_down(int x, int y, const bool)
Called when the mouse wheel is scrolled down.
pathfind::marked_route current_route_
Object which contains all the possible locations a unit can move to, with associated best routes to t...
Definition: pathfind.hpp:71
void mouse_wheel_left(int x, int y, const bool)
Called when the mouse wheel is scrolled left.
void mouse_wheel_up(int x, int y, const bool)
Called when the mouse wheel is scrolled up.
int side_number
Definition: game_info.hpp:44
void set_side(int side_number)
void attack_enemy_(const map_location &attacker_loc, const map_location &defender_loc, int choice)
const pathfind::paths & current_paths() const
game_display & gui()
Due to the way this class is constructed we can assume that the display* gui_ member actually points ...
This module contains various pathfinding functions and utilities.
std::set< map_location > get_adj_enemies(const map_location &loc, int side) const
int show_attack_dialog(const map_location &attacker_loc, const map_location &defender_loc)
void move_action(bool browse)
Overridden in derived class.
void select_or_action(bool browse)