The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
command_executor.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #ifndef COMMAND_EXECUTOR_HPP_INCLUDED
16 #define COMMAND_EXECUTOR_HPP_INCLUDED
17 
18 #include "hotkey_command.hpp"
19 #include "game_end_exceptions.hpp"
20 #include "events.hpp"
21 
22 class display;
23 class CVideo;
24 
25 namespace hotkey {
26 
28 
29 // Abstract base class for objects that implement the ability
30 // to execute hotkey commands.
32 {
33 
34 protected:
35  virtual ~command_executor() {}
36 
37 public:
38  virtual void cycle_units() {}
39  virtual void cycle_back_units() {}
40  virtual void end_turn() {}
41  virtual void goto_leader() {}
42  virtual void unit_hold_position() {}
43  virtual void end_unit_turn() {}
44  virtual void undo() {}
45  virtual void redo() {}
46  virtual void terrain_description() {}
47  virtual void unit_description() {}
48  virtual void rename_unit() {}
49  virtual void save_game() {}
50  virtual void save_replay() {}
51  virtual void save_map() {}
52  virtual void load_game() {}
53  virtual void toggle_ellipses() {}
54  virtual void toggle_grid() {}
55  virtual void status_table() {}
56  virtual void recall() {}
57  virtual void recruit() {}
58  virtual void repeat_recruit() {}
59  virtual void speak() {}
60  virtual void whisper() {}
61  virtual void shout() {}
62  virtual void create_unit() {}
63  virtual void change_side() {}
64  virtual void kill_unit() {}
65  virtual void preferences() {}
66  virtual void objectives() {}
67  virtual void unit_list() {}
68  virtual void show_statistics() {}
69  virtual void stop_network() {}
70  virtual void start_network() {}
71  virtual void label_terrain(bool /*team_only*/) {}
72  virtual void clear_labels() {}
73  virtual void label_settings() {}
74  virtual void show_enemy_moves(bool /*ignore_units*/) {}
75  virtual void toggle_shroud_updates() {}
76  virtual void update_shroud_now() {}
77  virtual void continue_move() {}
78  virtual void search() {}
79  virtual void show_help() {}
80  virtual void show_chat_log() {}
81  virtual void user_command() {}
82  virtual void custom_command() {}
83  virtual void ai_formula() {}
84  virtual void clear_messages() {}
85  virtual void change_language() {}
86  virtual void play_replay() { }
87  virtual void reset_replay() {}
88  virtual void stop_replay() {}
89  virtual void replay_next_turn() { }
90  virtual void replay_next_side() { }
91  virtual void replay_next_move() { }
92  virtual void replay_show_everything() {}
93  virtual void replay_show_each() {}
94  virtual void replay_show_team1() {}
95  virtual void replay_skip_animation() {}
96  virtual void replay_exit() {}
97  virtual void whiteboard_toggle() {}
98  virtual void whiteboard_execute_action() {}
100  virtual void whiteboard_delete_action() {}
101  virtual void whiteboard_bump_up_action() {}
102  virtual void whiteboard_bump_down_action() {}
103  virtual void whiteboard_suppose_dead() {}
104  virtual void select_hex() {}
105  virtual void deselect_hex() {}
106  virtual void move_action() {}
107  virtual void select_and_action() {}
108  virtual void left_mouse_click() {}
109  virtual void right_mouse_click() {}
110  virtual void toggle_accelerated_speed() {}
111  virtual void scroll_up(bool /*on*/) {}
112  virtual void scroll_down(bool /*on*/) {}
113  virtual void scroll_left(bool /*on*/) {}
114  virtual void scroll_right(bool /*on*/) {}
115  virtual void lua_console();
116  virtual void zoom_in() {}
117  virtual void zoom_out() {}
118  virtual void zoom_default() {}
119  virtual void map_screenshot() {}
120 
121  virtual void set_button_state() {}
122  virtual void recalculate_minimap() {}
123  virtual CVideo& get_video() = 0;
124 
125  // execute_command's parameter is changed to "hotkey_command& command" and this not maybe that is too inconsitent.
126  // Gets the action's image (if any). Displayed left of the action text in menus.
127  virtual std::string get_action_image(hotkey::HOTKEY_COMMAND /*command*/, int /*index*/) const { return ""; }
128  // Does the action control a toggle switch? If so, return the state of the action (on or off).
129  virtual ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND /*command*/, int /*index*/) const { return ACTION_STATELESS; }
130  // Returns the appropriate menu image. Checkable items will get a checked/unchecked image.
131  std::string get_menu_image(display& disp, const std::string& command, int index=-1) const;
132  // Returns a vector of images for a given menu.
133  std::vector<std::string> get_menu_images(display &, const std::vector<std::string>& items_arg);
134 
135  virtual void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& gui);
136  void execute_action(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& gui);
137 
138  virtual bool can_execute_command(const hotkey_command& command, int index=-1) const = 0;
139  virtual bool execute_command(const hotkey_command& command, int index=-1, bool press=true);
140 };
142 {
143 protected:
144  static const int zoom_amount = 4;
145  virtual display& get_display() = 0;
146 public:
147  CVideo& get_video();
148  void set_button_state();
149  void recalculate_minimap();
150  void lua_console();
151  void zoom_in();
152  void zoom_out();
153  void zoom_default();
154  void map_screenshot();
155  void quit_to_main_menu();
156 };
157 /* Functions to be called every time a event is intercepted.
158  * Will call the relevant function in executor if the event is not nullptr.
159  * Also handles some events in the function itself,
160  * and so is still meaningful to call with executor=nullptr
161  */
162 void jbutton_event(const SDL_Event& event, command_executor* executor);
163 void jhat_event(const SDL_Event& event, command_executor* executor);
164 void key_event(const SDL_Event& event, command_executor* executor);
165 void mbutton_event(const SDL_Event& event, command_executor* executor);
166 
167 
168 //TODO
169 void execute_command(const hotkey_command& command, command_executor* executor, int index=-1, bool press=true);
170 
171 // Object which will ensure that basic keyboard events like escape
172 // are handled properly for the duration of its lifetime.
174 {
175 public:
177 
178  void handle_event(const SDL_Event& event);
179  void handle_window_event(const SDL_Event&) {}
180 
181 private:
183 };
184 
185 
186 }
187 #endif
virtual void toggle_shroud_updates()
virtual ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND, int) const
void handle_event(const SDL_Event &event)
Definition: video.hpp:58
General purpose widgets.
Stores all information related to functions that can be bound to hotkeys.
virtual void terrain_description()
void mbutton_event(const SDL_Event &event, command_executor *executor)
virtual void recalculate_minimap()
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
virtual void whiteboard_execute_action()
virtual void scroll_up(bool)
virtual CVideo & get_video()=0
Keyboard shortcuts for game actions.
virtual void whiteboard_delete_action()
virtual bool can_execute_command(const hotkey_command &command, int index=-1) const =0
virtual void whiteboard_bump_up_action()
virtual void label_terrain(bool)
std::vector< std::string > get_menu_images(display &, const std::vector< std::string > &items_arg)
void handle_window_event(const SDL_Event &)
virtual display & get_display()=0
void execute_command(const hotkey_command &command, command_executor *executor, int index, bool press)
virtual void replay_show_team1()
void jbutton_event(const SDL_Event &event, command_executor *executor)
virtual void unit_hold_position()
virtual void scroll_right(bool)
virtual void show_enemy_moves(bool)
void jhat_event(const SDL_Event &event, command_executor *executor)
virtual void scroll_left(bool)
virtual void update_shroud_now()
void execute_action(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu, display &gui)
virtual void replay_show_everything()
GLuint index
Definition: glew.h:1782
std::string get_menu_image(display &disp, const std::string &command, int index=-1) const
virtual void scroll_down(bool)
virtual void whiteboard_suppose_dead()
void key_event(const SDL_Event &event, command_executor *executor)
virtual void whiteboard_bump_down_action()
virtual bool execute_command(const hotkey_command &command, int index=-1, bool press=true)
command_executor * exec_
cl_event event
Definition: glew.h:3070
virtual void whiteboard_execute_all_actions()
virtual void show_menu(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu, display &gui)
virtual std::string get_action_image(hotkey::HOTKEY_COMMAND, int) const
GLsizei const GLcharARB ** string
Definition: glew.h:4503
virtual void replay_skip_animation()
virtual void whiteboard_toggle()
basic_handler(command_executor *exec)
virtual void toggle_accelerated_speed()