The Battle for Wesnoth  1.19.5+dev
hotkey_handler.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
3  by Chris Beck <render787@gmail.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  * This file implements all the hotkey handling and menu details for
19  * play controller.
20  */
21 
22 #pragma once
23 
24 #include "play_controller.hpp"
25 
26 namespace events { class menu_handler; }
27 namespace events { class mouse_handler; }
28 namespace game_events { class wml_menu_item; }
29 
30 class game_state;
31 class saved_game;
32 
33 class team;
34 
36 
37 protected:
38  display& get_display() override { return play_controller_.get_display(); }
39 
40  /** References to parent object / constituents */
42 
45  game_display * gui() const;
48  const game_state & gamestate() const;
49 
50 private:
51  //
52  // Private data related to menu implementation (expansion of AUTOSAVES, WML entries)
53  //
54 
55  /** A smart pointer used when retrieving menu items. */
56  typedef std::shared_ptr<const game_events::wml_menu_item> const_item_ptr;
57 
58  // Expand AUTOSAVES in the menu items, setting the real savenames.
59  void expand_autosaves(std::vector<config>& items, int i);
60  void expand_quickreplay(std::vector<config>& items, int i);
61 
62  /**
63  * Replaces "wml" in @a items with all active WML menu items for the current field.
64  */
65  void expand_wml_commands(std::vector<config>& items, int i);
68 
69 protected:
70  bool browse() const;
71  bool linger() const;
72 
73 public:
76 
77  static const std::string wml_menu_hotkey_prefix;
78 
79  //event handlers, overridden from command_executor
80  virtual void objectives() override;
81  virtual void show_statistics() override;
82  virtual void unit_list() override;
83  virtual void left_mouse_click() override;
84  virtual void move_action() override;
85  virtual void select_and_action() override;
86  virtual void touch_hex() override;
87  virtual void select_hex() override;
88  virtual void deselect_hex() override;
89  virtual void right_mouse_click() override;
90  virtual void status_table() override;
91  virtual void save_game() override;
92  virtual void save_replay() override;
93  virtual void save_map() override;
94  virtual void load_game() override;
95  virtual void preferences() override;
96  virtual void speak() override;
97  virtual void show_chat_log() override;
98  virtual void show_help() override;
99  virtual void cycle_units() override;
100  virtual void cycle_back_units() override;
101  virtual void undo() override;
102  virtual void redo() override;
103  virtual void show_enemy_moves(bool ignore_units) override;
104  virtual void goto_leader() override;
105  virtual void unit_description() override;
106  virtual void terrain_description() override;
107  virtual void toggle_ellipses() override;
108  virtual void toggle_grid() override;
109  virtual void search() override;
110  virtual void toggle_accelerated_speed() override;
111  virtual void scroll_up(bool on) override;
112  virtual void scroll_down(bool on) override;
113  virtual void scroll_left(bool on) override;
114  virtual void scroll_right(bool on) override;
115  virtual void replay_skip_animation() override
117 
118  virtual std::string get_action_image(const hotkey::ui_command&) const override;
119  virtual void load_autosave(const std::string& filename, bool start_replay = false);
120  virtual hotkey::ACTION_STATE get_action_state(const hotkey::ui_command&) const override;
121  /** Check if a command can be executed. */
122  virtual bool can_execute_command(const hotkey::ui_command& command) const override;
123  virtual bool do_execute_command(const hotkey::ui_command& command, bool press=true, bool release=false) override;
124  void show_menu(const std::vector<config>& items_arg, int xloc, int yloc, bool context_menu, display& disp) override;
125 
126  /**
127  * Determines whether the command should be in the context menu or not.
128  * Independent of whether or not we can actually execute the command.
129  */
130  bool in_context_menu(const hotkey::ui_command& cmd) const;
131 
132 };
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition: display.hpp:97
game_display * gui() const
static const std::string wml_menu_hotkey_prefix
virtual void select_and_action() override
virtual void save_game() override
virtual void right_mouse_click() override
display & get_display() override
virtual void cycle_units() override
virtual void search() override
virtual void select_hex() override
virtual void scroll_right(bool on) override
virtual void move_action() override
void expand_autosaves(std::vector< config > &items, int i)
virtual void goto_leader() override
virtual void show_help() override
virtual void preferences() override
events::mouse_handler & mouse_handler_
virtual void scroll_up(bool on) override
virtual void scroll_left(bool on) override
virtual void status_table() override
virtual void unit_list() override
events::menu_handler & menu_handler_
virtual void undo() override
void expand_quickreplay(std::vector< config > &items, int i)
virtual void scroll_down(bool on) override
virtual void redo() override
virtual void load_autosave(const std::string &filename, bool start_replay=false)
virtual void objectives() override
virtual void show_statistics() override
virtual void save_map() override
virtual std::string get_action_image(const hotkey::ui_command &) const override
virtual hotkey::ACTION_STATE get_action_state(const hotkey::ui_command &) const override
play_controller & play_controller_
References to parent object / constituents.
virtual void deselect_hex() override
virtual bool do_execute_command(const hotkey::ui_command &command, bool press=true, bool release=false) override
virtual void load_game() override
virtual void replay_skip_animation() override
std::shared_ptr< const game_events::wml_menu_item > const_item_ptr
A smart pointer used when retrieving menu items.
bool in_context_menu(const hotkey::ui_command &cmd) const
Determines whether the command should be in the context menu or not.
void expand_wml_commands(std::vector< config > &items, int i)
Replaces "wml" in items with all active WML menu items for the current field.
virtual void speak() override
virtual void show_enemy_moves(bool ignore_units) override
hotkey_handler(play_controller &, saved_game &)
virtual void left_mouse_click() override
virtual void toggle_ellipses() override
void show_menu(const std::vector< config > &items_arg, int xloc, int yloc, bool context_menu, display &disp) override
virtual void terrain_description() override
virtual void toggle_accelerated_speed() override
virtual void cycle_back_units() override
virtual void show_chat_log() override
virtual void toggle_grid() override
virtual void unit_description() override
virtual bool can_execute_command(const hotkey::ui_command &command) const override
Check if a command can be executed.
virtual void save_replay() override
virtual void touch_hex() override
game_display & get_display() override
Get a reference to a display member a derived class uses.
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:75
std::size_t i
Definition: function.cpp:1028
Handling of system events.
Domain specific events.
std::string filename
Filename.
Used as the main paramneter for can_execute_command/do_execute_command These functions are used to ex...