The Battle for Wesnoth  1.17.17+dev
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2023
3  by Joerg Hinrichs <>
4  Copyright (C) 2003 by David White <>
5  Part of the Battle for Wesnoth Project
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  This program is distributed in the hope that it will be useful,
14  See the COPYING file for more details.
15 */
17 #pragma once
19 #include "chat_events.hpp"
20 #include "floating_textbox.hpp"
22 #include "units/map.hpp"
24 #include <vector>
26 class game_state;
27 class gamemap;
28 class game_data;
29 class game_board;
30 class game_config_view;
31 class play_controller;
32 class team;
33 class unit_map;
34 class t_string;
36 namespace events
37 {
38 class mouse_handler;
39 }
42 {
44 };
46 namespace events
47 {
48 class menu_handler : private chat_handler
49 {
50 public:
52  virtual ~menu_handler();
56  {
57  gui_ = gui;
58  }
60  void objectives();
61  void show_statistics(int side_num);
62  void unit_list();
63  void status_table();
64  void save_map();
65  void preferences();
66  void show_chat_log();
67  void show_help();
68  void speak();
69  void whisper();
70  void shout();
71  void recruit(int side_num, const map_location& last_hex);
72  void repeat_recruit(int side_num, const map_location& last_hex);
73  void recall(int side_num, const map_location& last_hex);
74  void show_enemy_moves(bool ignore_units, int side_num);
75  void toggle_shroud_updates(int side_num);
76  void update_shroud_now(int side_num);
77  bool end_turn(int side_num);
78  void goto_leader(int side_num);
79  void unit_description();
80  void terrain_description(mouse_handler& mousehandler);
81  void rename_unit();
82  void create_unit(mouse_handler& mousehandler);
83  void change_side(mouse_handler& mousehandler);
84  void kill_unit(mouse_handler& mousehandler);
85  void label_terrain(mouse_handler& mousehandler, bool team_only);
86  void clear_labels();
87  void label_settings();
88  void continue_move(mouse_handler& mousehandler, int side_num);
89  void execute_gotos(mouse_handler& mousehandler, int side_num);
90  void toggle_ellipses();
91  void toggle_grid();
92  void unit_hold_position(mouse_handler& mousehandler, int side_num);
93  void end_unit_turn(mouse_handler& mousehandler, int side_num);
94  void search();
95  void request_control_change(int side_num, const std::string& player);
96  void user_command();
97  void custom_command();
98  void ai_formula();
99  virtual void clear_messages() override;
100  std::vector<std::string> get_commands_list();
104  {
105  return const_cast<menu_handler*>(this)->current_unit();
106  }
108  void move_unit_to_loc(const unit_map::iterator& ui,
109  const map_location& target,
110  bool continue_move,
111  int side_num,
112  mouse_handler& mousehandler);
114  /** @return If the recruit is possible, an empty string and set @a recruited_from; otherwise, return an error message string. */
115  t_string can_recruit(const std::string& name, int side_num, map_location& target_hex, map_location& recruited_from);
116  /** @return Whether or not the recruit was successful */
117  bool do_recruit(const std::string& name, int side_num, map_location& target_hex);
118  void do_speak();
119  void do_search(const std::string& new_search);
120  void do_command(const std::string& str);
121  void do_ai_formula(const std::string& str, int side_num, mouse_handler& mousehandler);
122  void send_to_server(const config& cfg) override;
124  game_state& gamestate() const;
125  game_data& gamedata();
126  game_board& board() const;
128 protected:
129  void add_chat_message(const std::time_t& time,
130  const std::string& speaker,
131  int side,
132  const std::string& message,
134  void send_chat_message(const std::string& message, bool allies_only = false) override;
136 private:
137  // console_handler is basically a sliced out part of menu_handler
138  // and as such needs access to menu_handler's privates
139  friend class console_handler;
141  // void do_speak(const std::string& message, bool allies_only);
142  bool has_friends() const;
150  std::string last_search_;
152 };
153 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
void do_ai_formula(const std::string &str, int side_num, mouse_handler &mousehandler)
void show_enemy_moves(bool ignore_units, int side_num)
void label_terrain(mouse_handler &mousehandler, bool team_only)
game_board & board() const
gui::floating_textbox & get_textbox()
void update_shroud_now(int side_num)
void request_control_change(int side_num, const std::string &player)
menu_handler(game_display *gui, play_controller &pc)
Definition: menu_events.cpp:96
virtual void clear_messages() override
const game_config_view & game_config_
void goto_leader(int side_num)
void execute_gotos(mouse_handler &mousehandler, int side_num)
void recall(int side_num, const map_location &last_hex)
void do_command(const std::string &str)
void create_unit(mouse_handler &mousehandler)
Creates a unit (in debug mode via hotkey or context menu).
unit_map::const_iterator current_unit() const
void unit_hold_position(mouse_handler &mousehandler, int side_num)
void end_unit_turn(mouse_handler &mousehandler, int side_num)
void change_side(mouse_handler &mousehandler)
void terrain_description(mouse_handler &mousehandler)
bool do_recruit(const std::string &name, int side_num, map_location &target_hex)
game_data & gamedata()
void send_chat_message(const std::string &message, bool allies_only=false) override
gui::floating_textbox textbox_info_
void toggle_shroud_updates(int side_num)
void show_statistics(int side_num)
map_location last_search_hit_
void recruit(int side_num, const map_location &last_hex)
play_controller & pc_
t_string can_recruit(const std::string &name, int side_num, map_location &target_hex, map_location &recruited_from)
void continue_move(mouse_handler &mousehandler, int side_num)
void repeat_recruit(int side_num, const map_location &last_hex)
void kill_unit(mouse_handler &mousehandler)
void do_search(const std::string &new_search)
void set_gui(game_display *gui)
Definition: menu_events.hpp:55
std::vector< std::string > get_commands_list()
void send_to_server(const config &cfg) override
game_display * gui_
bool has_friends() const
game_state & gamestate() const
void add_chat_message(const std::time_t &time, const std::string &speaker, int side, const std::string &message, events::chat_handler::MESSAGE_TYPE type=events::chat_handler::MESSAGE_PRIVATE) override
std::string last_search_
unit_map::iterator current_unit()
bool end_turn(int side_num)
void move_unit_to_loc(const unit_map::iterator &ui, const map_location &target, bool continue_move, int side_num, mouse_handler &mousehandler)
Game board class.
Definition: game_board.hpp:53
A class grating read only view to a vector of config objects, viewed as one config with all children ...
Encapsulates the map of the game.
Definition: map.hpp:172
Base class for exceptions that want to be thrown 'through' lua.
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:76
Container associating units to locations.
Definition: map.hpp:99
Helper macro for classes deriving from lua_jailbreak_exception.
Handling of system events.
Definition: manager.hpp:43
General purpose widgets.
Encapsulates the map of the game.
Definition: location.hpp:38