The Battle for Wesnoth  1.19.0-dev
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
3  by Chris Beck <>
4  Part of the Battle for Wesnoth Project
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,
13  See the COPYING file for more details.
14 */
16 /**
17  * @file
18  * This file implements all the hotkey handling and menu details for
19  * play controller.
20  */
22 #pragma once
24 #include "play_controller.hpp"
26 namespace events { class menu_handler; }
27 namespace events { class mouse_handler; }
28 namespace game_events { class wml_menu_item; }
30 class game_state;
31 class saved_game;
33 class team;
37 protected:
38  display& get_display() override { return play_controller_.get_display(); }
40  /** References to parent object / constituents */
45  game_display * gui() const;
48  const game_state & gamestate() const;
50 private:
51  //
52  // Private data related to menu implementation (expansion of AUTOSAVES, WML entries)
53  //
55  /** A smart pointer used when retrieving menu items. */
56  typedef std::shared_ptr<const game_events::wml_menu_item> const_item_ptr;
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);
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);
69 protected:
70  bool browse() const;
71  bool linger() const;
73  const team & viewing_team() const;
74  bool viewing_team_is_playing() const;
76 public:
80  static const std::string wml_menu_hotkey_prefix;
82  //event handlers, overridden from command_executor
83  virtual void objectives() override;
84  virtual void show_statistics() override;
85  virtual void unit_list() override;
86  virtual void left_mouse_click() override;
87  virtual void move_action() override;
88  virtual void select_and_action() override;
89  virtual void touch_hex() override;
90  virtual void select_hex() override;
91  virtual void deselect_hex() override;
92  virtual void right_mouse_click() override;
93  virtual void status_table() override;
94  virtual void save_game() override;
95  virtual void save_replay() override;
96  virtual void save_map() override;
97  virtual void load_game() override;
98  virtual void preferences() override;
99  virtual void speak() override;
100  virtual void show_chat_log() override;
101  virtual void show_help() override;
102  virtual void cycle_units() override;
103  virtual void cycle_back_units() override;
104  virtual void undo() override;
105  virtual void redo() override;
106  virtual void show_enemy_moves(bool ignore_units) override;
107  virtual void goto_leader() override;
108  virtual void unit_description() override;
109  virtual void terrain_description() override;
110  virtual void toggle_ellipses() override;
111  virtual void toggle_grid() override;
112  virtual void search() override;
113  virtual void toggle_accelerated_speed() override;
114  virtual void scroll_up(bool on) override;
115  virtual void scroll_down(bool on) override;
116  virtual void scroll_left(bool on) override;
117  virtual void scroll_right(bool on) override;
118  virtual void replay_skip_animation() override
121  virtual std::string get_action_image(const hotkey::ui_command&) const override;
122  virtual void load_autosave(const std::string& filename, bool start_replay = false);
123  virtual hotkey::ACTION_STATE get_action_state(const hotkey::ui_command&) const override;
124  /** Check if a command can be executed. */
125  virtual bool can_execute_command(const hotkey::ui_command& command) const override;
126  virtual bool do_execute_command(const hotkey::ui_command& command, bool press=true, bool release=false) override;
127  void show_menu(const std::vector<config>& items_arg, int xloc, int yloc, bool context_menu, display& disp) override;
129  /**
130  * Determines whether the command should be in the context menu or not.
131  * Independent of whether or not we can actually execute the command.
132  */
133  bool in_context_menu(const hotkey::ui_command& cmd) const;
135 };
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition: display.hpp:88
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
const team & viewing_team() const
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:74
std::size_t i
Definition: function.cpp:968
Handling of system events.
Domain specific events.
const std::vector< std::string > items
Used as the main paramneter for can_execute_command/do_execute_command These functions are used to ex...