The Battle for Wesnoth  1.15.2+dev
hotkey_handler.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Chris Beck <render787@gmail.com>
3  Part of the Battle for Wesnoth Project https://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 /**
16  * @file
17  * This file implements all the hotkey handling and menu details for
18  * play controller.
19  */
20 
21 #pragma once
22 
23 #include "play_controller.hpp"
24 
25 namespace events { class menu_handler; }
26 namespace events { class mouse_handler; }
27 namespace game_events { class wml_menu_item; }
28 
29 class game_display;
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;
47  game_state & gamestate();
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 
61  std::vector<std::string> savenames_;
62 
63  /**
64  * Replaces "wml" in @a items with all active WML menu items for the current field.
65  */
66  void expand_wml_commands(std::vector<config>& items, int i);
67  std::vector<const_item_ptr> wml_commands_;
70 
71 protected:
72  bool browse() const;
73  bool linger() const;
74 
75  const team & viewing_team() const;
76  bool viewing_team_is_playing() const;
77 
78 public:
80  ~hotkey_handler();
81 
82  static const std::string wml_menu_hotkey_prefix;
83 
84  //event handlers, overridden from command_executor
85  virtual void objectives() override;
86  virtual void show_statistics() override;
87  virtual void unit_list() override;
88  virtual void left_mouse_click() override;
89  virtual void move_action() override;
90  virtual void select_and_action() override;
91  virtual void touch_hex() override;
92  virtual void select_hex() override;
93  virtual void deselect_hex() override;
94  virtual void right_mouse_click() override;
95  virtual void status_table() override;
96  virtual void save_game() override;
97  virtual void save_replay() override;
98  virtual void save_map() override;
99  virtual void load_game() override;
100  virtual void preferences() override;
101  virtual void speak() override;
102  virtual void show_chat_log() override;
103  virtual void show_help() override;
104  virtual void cycle_units() override;
105  virtual void cycle_back_units() override;
106  virtual void undo() override;
107  virtual void redo() override;
108  virtual void show_enemy_moves(bool ignore_units) override;
109  virtual void goto_leader() override;
110  virtual void unit_description() override;
111  virtual void terrain_description() override;
112  virtual void toggle_ellipses() override;
113  virtual void toggle_grid() override;
114  virtual void search() override;
115  virtual void toggle_accelerated_speed() override;
116  virtual void scroll_up(bool on) override;
117  virtual void scroll_down(bool on) override;
118  virtual void scroll_left(bool on) override;
119  virtual void scroll_right(bool on) override;
120  virtual void replay_skip_animation() override
121  { return play_controller_.toggle_skipping_replay(); }
122 
123  virtual std::string get_action_image(hotkey::HOTKEY_COMMAND, int index) const override;
124  virtual void load_autosave(const std::string& filename);
125  virtual hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const override;
126  /** Check if a command can be executed. */
127  virtual bool can_execute_command(const hotkey::hotkey_command& command, int index=-1) const override;
128  virtual bool do_execute_command(const hotkey::hotkey_command& command, int index=-1, bool press=true, bool release=false) override;
129  void show_menu(const std::vector<config>& items_arg, int xloc, int yloc, bool context_menu, display& disp) override;
130 
131  /**
132  * Determines whether the command should be in the context menu or not.
133  * Independent of whether or not we can actually execute the command.
134  */
135  bool in_context_menu(hotkey::HOTKEY_COMMAND command) const;
136 
137 };
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:116
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:44
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:380
static const std::string wml_menu_hotkey_prefix
Domain specific events.
Definition: action_wml.cpp:88
std::size_t i
Definition: function.cpp:933
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:71
Handling of system events.
Definition: manager.hpp:41
std::vector< const_item_ptr > wml_commands_
display & get_display() override