The Battle for Wesnoth  1.19.7+dev
menu_events.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2024
3  by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
4  Copyright (C) 2003 by David White <dave@whitevine.net>
5  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
6 
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,
12  but WITHOUT ANY WARRANTY.
13 
14  See the COPYING file for more details.
15 */
16 
17 #pragma once
18 
19 #include "chat_events.hpp"
20 #include "floating_textbox.hpp"
22 #include "units/map.hpp"
23 
24 #include <vector>
25 
26 class game_state;
27 class game_data;
28 class game_board;
29 class game_config_view;
30 class play_controller;
31 class t_string;
32 
33 namespace events
34 {
35 class mouse_handler;
36 }
37 
39 {
41  {
42  this->store();
43  }
44 
46 };
47 
48 namespace events
49 {
50 class menu_handler : private chat_handler
51 {
52 public:
54  virtual ~menu_handler();
55 
58  {
59  gui_ = gui;
60  }
61 
62  void objectives();
63  void show_statistics(int side_num);
64  void unit_list();
65  void status_table();
66  void save_map();
67  void preferences();
68  void show_chat_log();
69  void show_help();
70  void speak();
71  void whisper();
72  void shout();
73  void recruit(int side_num, const map_location& last_hex);
74  void repeat_recruit(int side_num, const map_location& last_hex);
75  void recall(int side_num, const map_location& last_hex);
76  void show_enemy_moves(bool ignore_units, int side_num);
77  void toggle_shroud_updates(int side_num);
78  void update_shroud_now(int side_num);
79  bool end_turn(int side_num);
80  void goto_leader(int side_num);
81  void unit_description();
82  void terrain_description(mouse_handler& mousehandler);
83  void rename_unit();
84  void create_unit(mouse_handler& mousehandler);
85  void change_side(mouse_handler& mousehandler);
86  void kill_unit(mouse_handler& mousehandler);
87  void label_terrain(mouse_handler& mousehandler, bool team_only);
88  void clear_labels();
89  void label_settings();
90  void continue_move(mouse_handler& mousehandler, int side_num);
91  void execute_gotos(mouse_handler& mousehandler, int side_num);
92  void toggle_ellipses();
93  void toggle_grid();
94  void unit_hold_position(mouse_handler& mousehandler, int side_num);
95  void end_unit_turn(mouse_handler& mousehandler, int side_num);
96  void search();
97  void request_control_change(int side_num, const std::string& player);
98  void user_command();
99  void custom_command();
100  void ai_formula();
101  virtual void clear_messages() override;
102  std::vector<std::string> get_commands_list();
103 
106  {
107  return const_cast<menu_handler*>(this)->current_unit();
108  }
109 
110  void move_unit_to_loc(const unit_map::iterator& ui,
111  const map_location& target,
112  bool continue_move,
113  int side_num,
114  mouse_handler& mousehandler);
115 
116  /** @return If the recruit is possible, an empty string and set @a recruited_from; otherwise, return an error message string. */
117  t_string can_recruit(const std::string& name, int side_num, map_location& target_hex, map_location& recruited_from);
118  /** @return Whether or not the recruit was successful */
119  bool do_recruit(const std::string& name, int side_num, map_location& target_hex);
120  void do_speak();
121  void do_search(const std::string& new_search);
122  void do_command(const std::string& str);
123  void do_ai_formula(const std::string& str, int side_num, mouse_handler& mousehandler);
124  void send_to_server(const config& cfg) override;
125 
126  game_state& gamestate() const;
127  game_data& gamedata();
128  game_board& board() const;
129 
130 protected:
131  void add_chat_message(const std::time_t& time,
132  const std::string& speaker,
133  int side,
134  const std::string& message,
136  void send_chat_message(const std::string& message, bool allies_only = false) override;
137 
138 private:
139  // console_handler is basically a sliced out part of menu_handler
140  // and as such needs access to menu_handler's privates
141  friend class console_handler;
142 
143  // void do_speak(const std::string& message, bool allies_only);
144  bool has_friends() const;
145 
148 
150 
152  std::string last_search_;
154 };
155 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
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:88
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:57
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:47
A class grating read only view to a vector of config objects, viewed as one config with all children ...
Base class for exceptions that want to be thrown 'through' lua.
void store() const noexcept
Stores a copy the current exception to be rethrown.
#define IMPLEMENT_LUA_JAILBREAK_EXCEPTION(type)
Helper macro for classes deriving from lua_jailbreak_exception.
Handling of system events.
General purpose widgets.
Encapsulates the map of the game.
Definition: location.hpp:45