37 #include <boost/algorithm/string/predicate.hpp>
39 namespace balg = boost::algorithm;
44 #define ERR_G LOG_STREAM(err, lg::general())
45 #define WRN_G LOG_STREAM(warn, lg::general())
46 #define LOG_G LOG_STREAM(info, lg::general())
47 #define DBG_G LOG_STREAM(debug, lg::general())
55 : play_controller_(pc)
56 , menu_handler_(pc.get_menu_handler())
57 , mouse_handler_(pc.get_mouse_handler_base())
59 , last_context_menu_x_(0)
60 , last_context_menu_y_(0)
66 return &play_controller_.get_display();
70 return play_controller_.gamestate();
74 return play_controller_.gamestate();
100 play_controller_.save_game();
104 play_controller_.save_replay();
108 play_controller_.save_map();
112 play_controller_.load_game();
120 int x =
gui()->get_location_x(
gui()->mouseover_hex());
121 int y =
gui()->get_location_y(
gui()->mouseover_hex());
123 SDL_MouseButtonEvent event;
129 event.state = SDL_PRESSED;
139 auto touched_hex =
gui()->mouseover_hex();
155 int x =
gui()->get_location_x(
gui()->mouseover_hex());
156 int y =
gui()->get_location_y(
gui()->mouseover_hex());
158 SDL_MouseButtonEvent event;
164 event.state = SDL_PRESSED;
191 play_controller_.undo();
195 play_controller_.redo();
247 play_controller_.set_scroll_up(on);
252 play_controller_.set_scroll_down(on);
257 play_controller_.set_scroll_left(on);
262 play_controller_.set_scroll_right(on);
267 DBG_G <<
"play_controller::do_execute_command: Found command:" << cmd.
id;
271 load_autosave(savename,
false);
276 load_autosave(savename,
true);
280 if(balg::starts_with(cmd.
id, wml_menu_hotkey_prefix)) {
281 std::string name = std::string(cmd.
id.substr(wml_menu_hotkey_prefix.length()));
287 return command_executor::do_execute_command(cmd, press, release);
347 std::size_t humans_notme_cnt = 0;
348 for(
const auto&
t : play_controller_.get_teams()) {
349 if(
t.is_network_human()) {
354 return !(humans_notme_cnt < 1 || play_controller_.is_linger_mode() || play_controller_.is_observer());
362 return !
linger() && play_controller_.enemies_visible();
365 return !play_controller_.is_networked_mp();
374 return play_controller_.can_redo();
376 return play_controller_.can_undo();
399 if(newitems.size() > 5) {
400 std::vector<T> subitems;
401 subitems.push_back(std::move(newitems[0]));
402 subitems.push_back(std::move(newitems[1]));
403 subitems.push_back(std::move(newitems[newitems.size() / 3]));
404 subitems.push_back(std::move(newitems[newitems.size() * 2 / 3]));
405 subitems.push_back(std::move(newitems.back()));
437 std::vector<config> newitems;
441 std::string label = turn > 0 ? _(
"Back to Turn ") + std::to_string(turn) : _(
"Back to Start");
442 newitems.emplace_back(
"label", label,
"id", quickload_prefix + filename);
447 items.insert(pos, newitems.begin(), newitems.end());
453 std::vector<config> newitems;
457 std::string label = turn > 0 ? _(
"Replay from Turn ") + std::to_string(turn) : _(
"Replay from Start");
458 newitems.emplace_back(
"label", label,
"id", quickreplay_prefix + filename);
463 items.insert(pos, newitems.begin(), newitems.end());
470 std::vector<config> newitems;
476 items.insert(pos, newitems.begin(), newitems.end());
482 last_context_menu_x_ = xloc;
483 last_context_menu_y_ = yloc;
486 std::vector<config>
items;
487 for(
const auto&
item : items_arg) {
489 std::string
id =
item[
"id"];
492 if(
id ==
"wml" || (can_execute_command(cmd) && (!context_menu ||
in_context_menu(cmd)))) {
493 items.emplace_back(
"id",
id);
499 for(
int i =
items.size() - 1;
i >= 0;
i--) {
500 if(
items[
i][
"id"] ==
"AUTOSAVES") {
501 expand_autosaves(
items,
i);
502 }
else if(
items[
i][
"id"] ==
"QUICKREPLAY") {
503 expand_quickreplay(
items,
i);
504 }
else if(
items[
i][
"id"] ==
"wml") {
505 expand_wml_commands(
items,
i);
525 const int viewing_side =
gui()->viewing_side();
529 if ( !play_controller_.get_map().is_keep(last_hex) &&
530 !play_controller_.get_map().is_castle(last_hex) )
544 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 map_location & get_last_hex() const
void touch_action(const map_location hex, bool browse)
void cycle_units(const bool browse, const bool reverse=false)
void move_action(bool browse)
Overridden in derived class.
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)
bool viewing_team_is_playing() const
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
const team & viewing_team() const
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_
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.
This class stores all the data for a single 'side' (in game nomenclature).
Various functions related to the creation of units (recruits, recalls, and placed units).
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::pair< std::string, unsigned > item
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],...
const std::vector< std::string > items
void set_turbo(bool ison)
bool minimap_movement_coding()
bool minimap_draw_villages()
bool minimap_terrain_coding()
bool minimap_draw_terrain()
compression::format save_compression_format()
bool minimap_draw_units()
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
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.