33 #include <boost/algorithm/string/predicate.hpp>
35 namespace balg = boost::algorithm;
37 #define ERR_G LOG_STREAM(err, lg::general())
38 #define WRN_G LOG_STREAM(warn, lg::general())
39 #define LOG_G LOG_STREAM(info, lg::general())
40 #define DBG_G LOG_STREAM(debug, lg::general())
48 : play_controller_(pc)
49 , menu_handler_(pc.get_menu_handler())
50 , mouse_handler_(pc.get_mouse_handler_base())
57 return &play_controller_.get_display();
61 return play_controller_.gamestate();
65 return play_controller_.gamestate();
88 play_controller_.save_game();
92 play_controller_.save_replay();
96 play_controller_.save_map();
100 play_controller_.load_game();
112 auto touched_hex =
gui()->mouseover_hex();
148 play_controller_.undo();
152 play_controller_.redo();
201 play_controller_.set_scroll_up(on);
206 play_controller_.set_scroll_down(on);
211 play_controller_.set_scroll_left(on);
216 play_controller_.set_scroll_right(on);
221 DBG_G <<
"play_controller::do_execute_command: Found command:" << cmd.
id;
227 load_autosave(savename,
false);
233 load_autosave(savename,
true);
237 if(balg::starts_with(cmd.
id, wml_menu_hotkey_prefix)) {
238 std::string name = cmd.
id.substr(wml_menu_hotkey_prefix.length());
246 return command_executor::do_execute_command(cmd, press, release);
306 std::size_t humans_notme_cnt = 0;
307 for(
const auto&
t : play_controller_.get_teams()) {
308 if(
t.is_network_human()) {
313 return !(humans_notme_cnt < 1 || play_controller_.is_linger_mode() || play_controller_.is_observer());
322 return !
linger() && play_controller_.enemies_visible();
326 return !play_controller_.is_networked_mp();
335 return play_controller_.can_redo();
337 return play_controller_.can_undo();
360 void append_items(std::vector<T>&& newitems, std::vector<T>& out)
362 auto input = std::move(newitems);
365 if(input.size() > 5) {
366 out.push_back(std::move(input[0]));
367 out.push_back(std::move(input[1]));
368 out.push_back(std::move(input[input.size() / 3]));
369 out.push_back(std::move(input[input.size() * 2 / 3]));
370 out.push_back(std::move(input.back()));
375 std::move(input.begin(), input.end(), std::back_inserter(out));
386 const std::string name =
turn > 0
387 ? autosave.create_filename(
turn)
388 : starting.create_filename();
400 std::vector<config> newitems;
403 std::string label = turn > 0
404 ? VGETTEXT(
"Back to Turn $number", {{
"number", std::to_string(turn)}})
405 :
_(
"Back to Start");
410 append_items(std::move(newitems), items);
415 std::vector<config> newitems;
418 std::string label = turn > 0
419 ? VGETTEXT(
"Replay from Turn $number", {{
"number", std::to_string(turn)}})
420 :
_(
"Replay from Start");
425 append_items(std::move(newitems), items);
437 std::vector<config> items;
438 for(
const auto& item : items_arg) {
439 std::string
id = item[
"id"];
442 if(
id ==
"AUTOSAVES") {
443 expand_autosaves(items);
444 }
else if(
id ==
"QUICKREPLAY") {
445 expand_quickreplay(items);
446 }
else if(
id ==
"wml") {
447 expand_wml_commands(items);
448 }
else if(can_execute_command(cmd) && (!context_menu || in_context_menu(cmd))) {
449 items.emplace_back(
"id",
id);
472 if(!play_controller_.get_map().is_keep(last_hex)
473 && !play_controller_.get_map().is_castle(last_hex))
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()
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
virtual hotkey::action_state get_action_state(const hotkey::ui_command &) const override
static const std::string wml_menu_hotkey_prefix
virtual void select_and_action() override
virtual void save_game() override
void expand_quickreplay(std::vector< config > &items) const
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
virtual void goto_leader() override
virtual void show_help() override
virtual void preferences() override
void expand_wml_commands(std::vector< config > &items)
Replaces "wml" in items with all active WML menu items for the current field.
virtual void scroll_up(bool on) override
virtual void scroll_left(bool on) override
virtual void status_table() override
void expand_autosaves(std::vector< config > &items) const
virtual void unit_list() override
virtual void undo() 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 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
virtual void speak() override
virtual void show_enemy_moves(bool ignore_units) override
hotkey_handler(play_controller &, saved_game &)
bool in_context_menu(const hotkey::ui_command &cmd) const override
Inherited from command_executor.
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
void show_menu(const std::vector< config > &items_arg, const point &menu_loc, bool context_menu) 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()
Class for start-of-scenario saves.
static std::string _(const char *str)
std::string label
What to show in the filter's drop-down list.
static const std::string quickload_prefix
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.
action_state on_if(bool condition)
Returns action_state::on if condition is true, else action_state::off.
const hotkey_command & get_hotkey_command(std::string_view command)
Returns the hotkey_command with the given id.
@ 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...
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.