32 #include <boost/algorithm/string/predicate.hpp>
34 namespace balg = boost::algorithm;
39 #define ERR_G LOG_STREAM(err, lg::general())
40 #define WRN_G LOG_STREAM(warn, lg::general())
41 #define LOG_G LOG_STREAM(info, lg::general())
42 #define DBG_G LOG_STREAM(debug, lg::general())
50 : play_controller_(pc)
51 , menu_handler_(pc.get_menu_handler())
52 , mouse_handler_(pc.get_mouse_handler_base())
54 , last_context_menu_x_(0)
55 , last_context_menu_y_(0)
61 return &play_controller_.get_display();
65 return play_controller_.gamestate();
69 return play_controller_.gamestate();
92 play_controller_.save_game();
96 play_controller_.save_replay();
100 play_controller_.save_map();
104 play_controller_.load_game();
112 const auto [x, y] =
gui()->get_location(
gui()->mouseover_hex());
113 SDL_MouseButtonEvent event;
119 event.state = SDL_PRESSED;
129 auto touched_hex =
gui()->mouseover_hex();
145 const auto [x, y] =
gui()->get_location(
gui()->mouseover_hex());
146 SDL_MouseButtonEvent event;
152 event.state = SDL_PRESSED;
179 play_controller_.undo();
183 play_controller_.redo();
235 play_controller_.set_scroll_up(on);
240 play_controller_.set_scroll_down(on);
245 play_controller_.set_scroll_left(on);
250 play_controller_.set_scroll_right(on);
255 DBG_G <<
"play_controller::do_execute_command: Found command:" << cmd.
id;
259 load_autosave(savename,
false);
264 load_autosave(savename,
true);
268 if(balg::starts_with(cmd.
id, wml_menu_hotkey_prefix)) {
269 std::string name = std::string(cmd.
id.substr(wml_menu_hotkey_prefix.length()));
275 return command_executor::do_execute_command(cmd, press, release);
335 std::size_t humans_notme_cnt = 0;
336 for(
const auto&
t : play_controller_.get_teams()) {
337 if(
t.is_network_human()) {
342 return !(humans_notme_cnt < 1 || play_controller_.is_linger_mode() || play_controller_.is_observer());
350 return !
linger() && play_controller_.enemies_visible();
354 return !play_controller_.is_networked_mp();
363 return play_controller_.can_redo();
365 return play_controller_.can_undo();
388 if(newitems.size() > 5) {
389 std::vector<T> subitems;
390 subitems.push_back(std::move(newitems[0]));
391 subitems.push_back(std::move(newitems[1]));
392 subitems.push_back(std::move(newitems[newitems.size() / 3]));
393 subitems.push_back(std::move(newitems[newitems.size() * 2 / 3]));
394 subitems.push_back(std::move(newitems.back()));
425 auto pos = items.erase(items.begin() +
i);
426 std::vector<config> newitems;
430 std::string label = turn > 0 ? _(
"Back to Turn ") + std::to_string(turn) : _(
"Back to Start");
431 newitems.emplace_back(
"label", label,
"id", quickload_prefix + filename);
436 items.insert(pos, newitems.begin(), newitems.end());
441 auto pos = items.erase(items.begin() +
i);
442 std::vector<config> newitems;
446 std::string label = turn > 0 ? _(
"Replay from Turn ") + std::to_string(turn) : _(
"Replay from Start");
447 newitems.emplace_back(
"label", label,
"id", quickreplay_prefix + filename);
452 items.insert(pos, newitems.begin(), newitems.end());
458 auto pos = items.erase(items.begin() +
i);
459 std::vector<config> newitems;
465 items.insert(pos, newitems.begin(), newitems.end());
471 last_context_menu_x_ = xloc;
472 last_context_menu_y_ = yloc;
475 std::vector<config> items;
476 for(
const auto& item : items_arg) {
478 std::string
id = item[
"id"];
481 if(
id ==
"wml" || (can_execute_command(cmd) && (!context_menu ||
in_context_menu(cmd)))) {
482 items.emplace_back(
"id",
id);
488 for(
int i = items.size() - 1;
i >= 0;
i--) {
489 if(items[
i][
"id"] ==
"AUTOSAVES") {
490 expand_autosaves(items,
i);
491 }
else if(items[
i][
"id"] ==
"QUICKREPLAY") {
492 expand_quickreplay(items,
i);
493 }
else if(items[
i][
"id"] ==
"wml") {
494 expand_wml_commands(items,
i);
514 const int viewing_side =
gui()->viewing_team().side();
518 if ( !play_controller_.get_map().is_keep(last_hex) &&
519 !play_controller_.get_map().is_castle(last_hex) )
533 return command_executor::get_action_image(cmd);
virtual bool in_context_menu(const hotkey::ui_command &cmd) const
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
void show_enemy_moves(bool ignore_units, int side_num)
void goto_leader(int side_num)
void terrain_description(mouse_handler &mousehandler)
void show_statistics(int side_num)
unit_map::iterator current_unit()
virtual void mouse_press(const SDL_MouseButtonEvent &event, const bool browse)
void cycle_back_units(const bool browse)
void select_or_action(bool browse)
void select_hex(const map_location &hex, const bool browse, const bool highlight=true, const bool fire_event=true, const bool force_unhighlight=false)
void touch_action(const map_location hex, bool browse) override
void move_action(bool browse) override
Overridden in derived class.
const map_location & get_last_hex() const
void cycle_units(const bool browse, const bool reverse=false)
void get_items(const map_location &hex, std::vector< config > &items, filter_context &fc, game_data &gamedata, unit_map &units) const
Returns the menu items that can be shown for the given location.
bool fire_item(const std::string &id, const map_location &hex, game_data &gamedata, filter_context &fc, unit_map &units, bool is_key_hold_repeat=false) const
Fires the menu item with the given id.
bool side_can_recruit_on(int side, map_location loc) const
Checks if any of the sides leaders can recruit at a location.
game_events::wmi_manager & get_wml_menu_items()
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
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
virtual void scroll_up(bool on) override
virtual void scroll_left(bool on) override
virtual void status_table() override
virtual void unit_list() override
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
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
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
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
events::menu_handler menu_handler_
events::mouse_handler mouse_handler_
void set_turbo(bool ison)
compression::format save_compression_format()
Exception used to signal that the user has decided to abortt a game, and to load another game instead...
static std::shared_ptr< save_index_class > default_saves_dir()
Returns an instance for managing saves in filesystem::get_saves_dir()
std::string create_filename() const
Build the filename according to the specific savegame's needs.
Class for start-of-scenario saves.
static std::string _(const char *str)
static void trim_items(std::vector< T > &newitems)
static const std::string quickload_prefix
static void foreach_autosave(int turn, saved_game &sg, F func)
static const std::string quickreplay_prefix
This file implements all the hotkey handling and menu details for play controller.
Standard logging facilities (interface).
std::string format_extension(format compression_format)
const color_t NORMAL_COLOR
std::string get_names(const std::string &id)
Returns a comma-separated string of hotkey names.
@ HOTKEY_MINIMAP_DRAW_VILLAGES
@ HOTKEY_TERRAIN_DESCRIPTION
@ HOTKEY_HELP_ABOUT_SAVELOAD
@ HOTKEY_SHOW_ENEMY_MOVES
@ HOTKEY_UNIT_DESCRIPTION
@ HOTKEY_SELECT_AND_ACTION
@ HOTKEY_MINIMAP_DRAW_TERRAIN
@ HOTKEY_BEST_ENEMY_MOVES
@ HOTKEY_MINIMAP_CODING_TERRAIN
@ HOTKEY_MINIMAP_DRAW_UNITS
@ HOTKEY_CYCLE_BACK_UNITS
@ HOTKEY_MINIMAP_CODING_UNIT
int show_menu(lua_State *L)
Displays a popup menu at the current mouse position Best used from a [set_menu_item],...
bool save_game_exists(std::string name, compression::format compressed)
Returns true if there is already a savegame with this name, looking only in the default save director...
std::map< std::string, t_string > string_map
std::string filename
Filename.
Holds options for calls to function 'announce' (announce).
bool discard_previous
An announcement according these options should replace the previous announce (typical of fast announc...
static const hotkey_command & get_command_by_command(HOTKEY_COMMAND command)
the execute_command argument was changed from HOTKEY_COMMAND to hotkey_command, to be able to call it...
Used as the main paramneter for can_execute_command/do_execute_command These functions are used to ex...
hotkey::HOTKEY_COMMAND hotkey_command
The hotkey::HOTKEY_COMMAND associated with this action, HOTKEY_NULL for actions that don't allow hotk...
std::string id
The string command, never empty, describes the action uniquely. when the action is the result of a me...
Encapsulates the map of the game.
Applies the planned unit map for the duration of the struct's life.
Declarations for a container for wml_menu_item.