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())
59 return &play_controller_.get_display();
63 return play_controller_.gamestate();
67 return play_controller_.gamestate();
90 play_controller_.save_game();
94 play_controller_.save_replay();
98 play_controller_.save_map();
102 play_controller_.load_game();
110 const auto [x, y] =
gui()->get_location(
gui()->mouseover_hex());
111 SDL_MouseButtonEvent event;
117 event.state = SDL_PRESSED;
127 auto touched_hex =
gui()->mouseover_hex();
143 const auto [x, y] =
gui()->get_location(
gui()->mouseover_hex());
144 SDL_MouseButtonEvent event;
150 event.state = SDL_PRESSED;
177 play_controller_.undo();
181 play_controller_.redo();
233 play_controller_.set_scroll_up(on);
238 play_controller_.set_scroll_down(on);
243 play_controller_.set_scroll_left(on);
248 play_controller_.set_scroll_right(on);
253 DBG_G <<
"play_controller::do_execute_command: Found command:" << cmd.
id;
257 load_autosave(savename,
false);
262 load_autosave(savename,
true);
266 if(balg::starts_with(cmd.
id, wml_menu_hotkey_prefix)) {
267 std::string name = std::string(cmd.
id.substr(wml_menu_hotkey_prefix.length()));
273 return command_executor::do_execute_command(cmd, press, release);
333 std::size_t humans_notme_cnt = 0;
334 for(
const auto&
t : play_controller_.get_teams()) {
335 if(
t.is_network_human()) {
340 return !(humans_notme_cnt < 1 || play_controller_.is_linger_mode() || play_controller_.is_observer());
348 return !
linger() && play_controller_.enemies_visible();
352 return !play_controller_.is_networked_mp();
361 return play_controller_.can_redo();
363 return play_controller_.can_undo();
386 if(newitems.size() > 5) {
387 std::vector<T> subitems;
388 subitems.push_back(std::move(newitems[0]));
389 subitems.push_back(std::move(newitems[1]));
390 subitems.push_back(std::move(newitems[newitems.size() / 3]));
391 subitems.push_back(std::move(newitems[newitems.size() * 2 / 3]));
392 subitems.push_back(std::move(newitems.back()));
421 auto pos = items.erase(items.begin() +
i);
422 std::vector<config> newitems;
426 std::string label = turn > 0 ? _(
"Back to Turn ") + std::to_string(turn) : _(
"Back to Start");
427 newitems.emplace_back(
"label", label,
"id", quickload_prefix + filename);
432 items.insert(pos, newitems.begin(), newitems.end());
437 auto pos = items.erase(items.begin() +
i);
438 std::vector<config> newitems;
442 std::string label = turn > 0 ? _(
"Replay from Turn ") + std::to_string(turn) : _(
"Replay from Start");
443 newitems.emplace_back(
"label", label,
"id", quickreplay_prefix + filename);
448 items.insert(pos, newitems.begin(), newitems.end());
454 auto pos = items.erase(items.begin() +
i);
455 std::vector<config> newitems;
461 items.insert(pos, newitems.begin(), newitems.end());
466 std::vector<config> items;
467 for(
const auto& item : items_arg) {
469 std::string
id = item[
"id"];
472 if(
id ==
"wml" || (can_execute_command(cmd) && (!context_menu ||
in_context_menu(cmd)))) {
473 items.emplace_back(
"id",
id);
478 for(
int i = items.size() - 1;
i >= 0;
i--) {
479 if(items[
i][
"id"] ==
"AUTOSAVES") {
480 expand_autosaves(items,
i);
481 }
else if(items[
i][
"id"] ==
"QUICKREPLAY") {
482 expand_quickreplay(items,
i);
483 }
else if(items[
i][
"id"] ==
"wml") {
484 expand_wml_commands(items,
i);
504 const int viewing_side =
gui()->viewing_team().side();
508 if ( !play_controller_.get_map().is_keep(last_hex) &&
509 !play_controller_.get_map().is_castle(last_hex) )
523 return command_executor::get_action_image(cmd);
virtual bool in_context_menu(const hotkey::ui_command &cmd) const
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)
void show_menu(const std::vector< config > &items_arg, int xloc, int yloc, bool context_menu) override
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
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 abort 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 parameter for can_execute_command/do_execute_command These functions are used to exe...
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.
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.