The Battle for Wesnoth  1.17.0-dev
hotkey_handler.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
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_display;
31 class game_state;
32 class saved_game;
33 
34 class team;
35 
37 
38 protected:
39  display& get_display() override { return play_controller_.get_display(); }
40 
41  /** References to parent object / constituents */
43 
46  game_display * gui() const;
48  game_state & gamestate();
49  const game_state & gamestate() const;
50 
51 private:
52  //
53  // Private data related to menu implementation (expansion of AUTOSAVES, WML entries)
54  //
55 
56  /** A smart pointer used when retrieving menu items. */
57  typedef std::shared_ptr<const game_events::wml_menu_item> const_item_ptr;
58 
59  // Expand AUTOSAVES in the menu items, setting the real savenames.
60  void expand_autosaves(std::vector<config>& items, int i);
61 
62  std::vector<std::string> savenames_;
63 
64  /**
65  * Replaces "wml" in @a items with all active WML menu items for the current field.
66  */
67  void expand_wml_commands(std::vector<config>& items, int i);
68  std::vector<const_item_ptr> wml_commands_;
71 
72 protected:
73  bool browse() const;
74  bool linger() const;
75 
76  const team & viewing_team() const;
77  bool viewing_team_is_playing() const;
78 
79 public:
81  ~hotkey_handler();
82 
83  static const std::string wml_menu_hotkey_prefix;
84 
85  //event handlers, overridden from command_executor
86  virtual void objectives() override;
87  virtual void show_statistics() override;
88  virtual void unit_list() override;
89  virtual void left_mouse_click() override;
90  virtual void move_action() override;
91  virtual void select_and_action() override;
92  virtual void touch_hex() override;
93  virtual void select_hex() override;
94  virtual void deselect_hex() override;
95  virtual void right_mouse_click() override;
96  virtual void status_table() override;
97  virtual void save_game() override;
98  virtual void save_replay() override;
99  virtual void save_map() override;
100  virtual void load_game() override;
101  virtual void preferences() override;
102  virtual void speak() override;
103  virtual void show_chat_log() override;
104  virtual void show_help() override;
105  virtual void cycle_units() override;
106  virtual void cycle_back_units() override;
107  virtual void undo() override;
108  virtual void redo() override;
109  virtual void show_enemy_moves(bool ignore_units) override;
110  virtual void goto_leader() override;
111  virtual void unit_description() override;
112  virtual void terrain_description() override;
113  virtual void toggle_ellipses() override;
114  virtual void toggle_grid() override;
115  virtual void search() override;
116  virtual void toggle_accelerated_speed() override;
117  virtual void scroll_up(bool on) override;
118  virtual void scroll_down(bool on) override;
119  virtual void scroll_left(bool on) override;
120  virtual void scroll_right(bool on) override;
121  virtual void replay_skip_animation() override
122  { return play_controller_.toggle_skipping_replay(); }
123 
124  virtual std::string get_action_image(hotkey::HOTKEY_COMMAND, int index) const override;
125  virtual void load_autosave(const std::string& filename);
126  virtual hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const override;
127  /** Check if a command can be executed. */
128  virtual bool can_execute_command(const hotkey::hotkey_command& command, int index=-1) const override;
129  virtual bool do_execute_command(const hotkey::hotkey_command& command, int index=-1, bool press=true, bool release=false) override;
130  void show_menu(const std::vector<config>& items_arg, int xloc, int yloc, bool context_menu, display& disp) override;
131 
132  /**
133  * Determines whether the command should be in the context menu or not.
134  * Independent of whether or not we can actually execute the command.
135  */
136  bool in_context_menu(hotkey::HOTKEY_COMMAND command) const;
137 
138 };
void show_help(const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
Definition: help.cpp:144
virtual void replay_skip_animation() override
General purpose widgets.
Stores all information related to functions that can be bound to hotkeys.
const std::vector< std::string > items
play_controller & play_controller_
References to parent object / constituents.
std::vector< std::string > savenames_
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:72
events::menu_handler & menu_handler_
std::shared_ptr< const game_events::wml_menu_item > const_item_ptr
A smart pointer used when retrieving menu items.
Modify, read and display user preferences.
int show_menu(lua_State *L)
Displays a popup menu at the current mouse position Best used from a [set_menu_item], to show a submenu.
Definition: lua_gui2.cpp:185
static const std::string wml_menu_hotkey_prefix
Domain specific events.
Definition: action_wml.cpp:87
std::size_t i
Definition: function.cpp:967
events::mouse_handler & mouse_handler_
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:72
Handling of system events.
Definition: manager.hpp:43
std::vector< const_item_ptr > wml_commands_
display & get_display() override