The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
hotkey_handler.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Chris Beck <[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 /**
16  * @file
17  * This file implements all the hotkey handling and menu details for
18  * play controller.
19  */
20 
21 #ifndef HOTKEY_HANDLER_HPP_INCL_
22 #define HOTKEY_HANDLER_HPP_INCL_
23 
24 #include "play_controller.hpp"
25 
26 #include <boost/scoped_ptr.hpp>
27 #include <boost/shared_ptr.hpp>
28 
29 namespace events { class menu_handler; }
30 namespace events { class mouse_handler; }
31 namespace game_events { class wml_menu_item; }
32 
33 class game_display;
34 class game_state;
35 class saved_game;
36 class wmi_pager;
37 
38 class team;
39 
41 
42 protected:
44 
45  /** References to parent object / constituents */
47 
50  game_display * gui() const;
53  const game_state & gamestate() const;
54 
55 private:
56  //
57  // Private data related to menu implementation (expansion of AUTOSAVES, WML entries)
58  //
59 
60  /// A smart pointer used when retrieving menu items.
62 
63  // Expand AUTOSAVES in the menu items, setting the real savenames.
64  void expand_autosaves(std::vector<std::string>& items);
65 
66  std::vector<std::string> savenames_;
67 
68  /**
69  * Replaces "wml" in @a items with all active WML menu items for the current field.
70  */
71  void expand_wml_commands(std::vector<std::string>& items);
72  std::vector<const_item_ptr> wml_commands_;
73  boost::scoped_ptr<wmi_pager> wml_command_pager_;
76 
77 protected:
78  bool browse() const;
79  bool linger() const;
80 
81  const team & viewing_team() const;
82  bool viewing_team_is_playing() const;
83 
84 public:
87 
89 
90  //event handlers, overridden from command_executor
91  virtual void objectives();
92  virtual void show_statistics();
93  virtual void unit_list();
94  virtual void left_mouse_click();
95  virtual void move_action();
96  virtual void select_and_action();
97  virtual void select_hex();
98  virtual void deselect_hex();
99  virtual void right_mouse_click();
100  virtual void status_table();
101  virtual void save_game();
102  virtual void save_replay();
103  virtual void save_map();
104  virtual void load_game();
105  virtual void preferences();
106  virtual void show_chat_log();
107  virtual void show_help();
108  virtual void cycle_units();
109  virtual void cycle_back_units();
110  virtual void undo();
111  virtual void redo();
112  virtual void show_enemy_moves(bool ignore_units);
113  virtual void goto_leader();
114  virtual void unit_description();
115  virtual void terrain_description();
116  virtual void toggle_ellipses();
117  virtual void toggle_grid();
118  virtual void search();
119  virtual void toggle_accelerated_speed();
120  virtual void scroll_up(bool on);
121  virtual void scroll_down(bool on);
122  virtual void scroll_left(bool on);
123  virtual void scroll_right(bool on);
124  virtual void replay_skip_animation() override
125  { return play_controller_.toggle_skipping_replay(); }
126 
128  virtual void load_autosave(const std::string& filename);
130  /** Check if a command can be executed. */
131  virtual bool can_execute_command(const hotkey::hotkey_command& command, int index=-1) const;
132  virtual bool execute_command(const hotkey::hotkey_command& command, int index=-1, bool press=true);
133  void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& disp);
134 
135  /**
136  * Determines whether the command should be in the context menu or not.
137  * Independent of whether or not we can actually execute the command.
138  */
139  bool in_context_menu(hotkey::HOTKEY_COMMAND command) const;
140 
141 };
142 
143 #endif
hotkey_handler(play_controller &, saved_game &)
virtual void scroll_up(bool on)
void expand_wml_commands(std::vector< std::string > &items)
Replaces "wml" in items with all active WML menu items for the current field.
virtual hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const
virtual void replay_skip_animation() override
boost::scoped_ptr< wmi_pager > wml_command_pager_
virtual void scroll_left(bool on)
Stores all information related to functions that can be bound to hotkeys.
const std::vector< std::string > items
virtual std::string get_action_image(hotkey::HOTKEY_COMMAND, int index) const
play_controller & play_controller_
References to parent object / constituents.
bool in_context_menu(hotkey::HOTKEY_COMMAND command) const
Determines whether the command should be in the context menu or not.
std::vector< std::string > savenames_
virtual void scroll_down(bool on)
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
virtual void scroll_right(bool on)
events::menu_handler & menu_handler_
void expand_autosaves(std::vector< std::string > &items)
virtual bool can_execute_command(const hotkey::hotkey_command &command, int index=-1) const
Check if a command can be executed.
const team & viewing_team() const
static const std::string wml_menu_hotkey_prefix
virtual void show_enemy_moves(bool ignore_units)
Domain specific events.
Definition: action_wml.cpp:93
virtual void load_autosave(const std::string &filename)
boost::shared_ptr< const game_events::wml_menu_item > const_item_ptr
A smart pointer used when retrieving menu items.
GLuint index
Definition: glew.h:1782
events::mouse_handler & mouse_handler_
void show_menu(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu, display &disp)
Handling of system events.
Definition: manager.hpp:42
std::vector< const_item_ptr > wml_commands_
game_display * gui() const
game_display & get_display()
Get a reference to a display member a derived class uses.
virtual bool execute_command(const hotkey::hotkey_command &command, int index=-1, bool press=true)
GLsizei const GLcharARB ** string
Definition: glew.h:4503