33 #include "../resources.hpp"
34 #include "../playmp_controller.hpp"
43 #define ERR_G LOG_STREAM(err, lg::general())
44 #define WRN_G LOG_STREAM(warn, lg::general())
45 #define LOG_G LOG_STREAM(info, lg::general())
46 #define DBG_G LOG_STREAM(debug, lg::general())
47 #define ERR_CF LOG_STREAM(err, log_config)
48 #define LOG_HK LOG_STREAM(info, log_hotkey)
52 void make_screenshot(
const std::string& name,
bool map_screenshot)
58 gui2::dialogs::screenshot_notification::display(
filename, screenshot);
64 static void event_queue(
const SDL_Event& event, command_executor* executor);
412 if(items_arg.empty()) {
417 std::vector<config> items = items_arg;
418 for(std::size_t
i = 0;
i < items.size(); ++
i) {
422 const auto do_command = [&](
int selected_item) {
423 std::string
id = items[selected_item][
"id"].str();
431 rect pos(menu_loc, {1,1});
436 mmenu.set_legacy_menu_mode(
true);
437 mmenu.set_legacy_toggle_callback(do_command);
440 res = mmenu.selected_item();
444 selection_pos = mmenu.selected_item_pos() -
point{1, 1};
449 if(res < 0 || std::size_t(res) >= items.size()) {
454 show_menu(submenu->items(), selection_pos, submenu->is_context());
462 for(
const std::string& item : items_arg) {
473 const std::string& command = item[
"id"];
476 const std::string default_image =
"icons/action/" + command +
"_25.png";
477 const std::string pressed_image =
"icons/action/" + command +
"_25-pressed.png";
488 item[
"icon"] = pressed_image +
"~CROP(3,3,18,18)";
491 item[
"icon"] = default_image +
"~CROP(3,3,18,18)";
498 item[
"checkbox"] =
true;
501 item[
"checkbox"] =
false;
504 item[
"radio"] =
true;
507 item[
"radio"] =
false;
517 const std::string& item_id = item[
"id"];
523 item[
"icon"] =
"icons/arrows/short_arrow_right_25.png~CROP(3,3,18,18)";
524 item[
"label"] = menu->title();
540 item[
"label"] =
b->title();
546 item[
"label"] = hk.description;
582 if (!executor)
return;
588 if(!executor)
return;
594 if(!executor)
return;
603 if (!executor)
return;
610 LOG_HK <<
"event 0x" << std::hex <<
event.type << std::dec;
611 if(event.type == SDL_TEXTINPUT) {
612 LOG_HK <<
"SDL_TEXTINPUT \"" <<
event.text.text <<
"\"";
616 if(!hk->active() || hk->is_disabled()) {
621 bool keypress = (
event.type == SDL_KEYDOWN ||
event.type == SDL_TEXTINPUT) &&
623 bool press = keypress ||
624 (
event.type == SDL_JOYBUTTONDOWN ||
event.type == SDL_MOUSEBUTTONDOWN ||
event.type == SDL_FINGERDOWN);
625 bool release =
event.type == SDL_KEYUP;
627 LOG_HK <<
"sending press event (keypress = " <<
628 std::boolalpha << keypress << std::noboolalpha <<
")";
645 if (!command.
press) {
654 make_screenshot(
_(
"Screenshot"),
false);
665 static struct before_muted_s
667 bool playing_sound,playing_music;
668 before_muted_s() : playing_sound(
false),playing_music(
false){}
687 DBG_G <<
"command_executor: unknown command number " << command.
command->
command <<
", ignoring.";
698 if (!button)
continue;
699 bool enabled =
false;
700 for (
const auto& command : menu.items()) {
709 button->enable(enabled);
715 if (!button)
continue;
716 bool enabled =
false;
718 for (
const std::string& command : action.items()) {
721 std::string
tooltip = action.tooltip(
i);
723 button->set_overlay(
"icons/action/" + command);
725 button->set_tooltip_string(
tooltip);
729 if (!can_execute)
continue;
736 button->set_check(
true);
740 button->set_check(
false);
750 button->enable(enabled);
758 std::vector<queued_command> filtered_commands;
761 using command_with_keyrelease = std::pair<const hotkey_command*, bool>;
762 std::set<command_with_keyrelease> seen_commands;
765 command_with_keyrelease command_key(cmd.command, cmd.release);
766 if(seen_commands.find(command_key) == seen_commands.end()) {
767 seen_commands.insert(command_key);
768 filtered_commands.push_back(cmd);
774 return filtered_commands;
784 return !commands.empty();
834 make_screenshot(
_(
"Map-Screenshot"),
true);
A config object defines a single node in a WML file, with access to child nodes.
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
void recalculate_minimap()
Schedule the minimap for recalculation.
std::shared_ptr< gui::button > find_action_button(const std::string &id)
Retrieves a pointer to a theme UI button.
std::shared_ptr< gui::button > find_menu_button(const std::string &id)
bool set_zoom(bool increase)
Zooms the display in (true) or out (false).
surface screenshot(bool map_screenshot=false)
Capture a (map-)screenshot into a surface.
void toggle_default_zoom()
Sets the zoom amount to the default.
static display * get_singleton()
Returns the display object if a display object exists.
std::size_t viewing_team_index() const
The viewing team is the team currently viewing the game.
static void display(lua_kernel_base *lk)
Display a new console, using given video and lua kernel.
@ yes_no_buttons
Shows a yes and no button.
bool show(const unsigned auto_close_time=0)
Shows the window.
virtual display & get_display()=0
void recalculate_minimap()
virtual void scroll_right(bool)
virtual void repeat_recruit()
virtual void show_menu(const std::vector< config > &items_arg, const point &menu_loc, bool context_menu)
virtual void replay_skip_animation()
virtual void set_button_state()
virtual void replay_next_side()
virtual void rename_unit()
virtual void clear_labels()
virtual void replay_show_team1()
virtual void preferences()
virtual void zoom_default()
virtual void scroll_up(bool)
void execute_quit_command()
virtual void scroll_left(bool)
virtual void whiteboard_execute_all_actions()
virtual void toggle_grid()
virtual void replay_next_move()
virtual bool do_execute_command(const hotkey::ui_command &command, bool press=true, bool release=false)
virtual void whiteboard_execute_action()
virtual void reset_replay()
virtual void show_enemy_moves(bool)
std::vector< queued_command > command_queue_
virtual void lua_console()
virtual void status_table()
virtual void save_replay()
virtual void select_teleport()
virtual void toggle_shroud_updates()
virtual void whiteboard_bump_down_action()
void execute_command_wrap(const queued_command &command)
void execute_action(const std::vector< std::string > &items_arg)
virtual action_state get_action_state(const hotkey::ui_command &) const
virtual void whiteboard_delete_action()
virtual void move_action()
virtual void user_command()
virtual bool keep_menu_open() const
If true, the menu will remain open after an item has been selected.
virtual void label_settings()
virtual void ai_formula()
virtual void show_statistics()
virtual void replay_exit()
virtual void replay_show_everything()
virtual void toggle_accelerated_speed()
virtual void whiteboard_suppose_dead()
void populate_menu_item_info(config &item, int index) const
virtual void scroll_down(bool)
virtual void play_replay()
virtual void deselect_hex()
virtual void stop_replay()
virtual void custom_command()
virtual void cycle_units()
virtual void cycle_back_units()
virtual void show_chat_log()
virtual void select_hex()
virtual void clear_messages()
virtual void unit_description()
virtual void select_and_action()
virtual void change_side()
virtual void label_terrain(bool)
virtual void start_network()
virtual void toggle_ellipses()
virtual void whiteboard_bump_up_action()
virtual void continue_move()
virtual void unit_hold_position()
virtual void goto_leader()
virtual void objectives()
virtual void create_unit()
virtual void terrain_description()
virtual void recalculate_minimap()
virtual void whiteboard_toggle()
virtual void replay_show_each()
virtual bool can_execute_command(const hotkey::ui_command &command) const =0
bool run_queued_commands()
std::vector< queued_command > filter_command_queue()
void queue_command(const SDL_Event &event, int index=-1)
virtual void replay_next_turn()
virtual void end_unit_turn()
virtual void update_shroud_now()
virtual void stop_network()
virtual void change_language()
virtual void map_screenshot()
void populate_menu_controls(config &item, int index) const
bool is_linger_mode() const
void surrender(int side_number)
bool set_music(bool ison)
bool set_sound(bool ison)
static void quit_to_desktop()
static void quit_to_title()
const action * get_action_item(const std::string &key) const
const menu * get_menu_item(const std::string &key) const
const std::vector< action > & actions() const
const std::vector< menu > & menus() const
static lg::log_domain log_hotkey("hotkey")
static lg::log_domain log_config("config")
map_display and display: classes which take care of displaying the map and game-data on the screen.
Declarations for File-IO.
static std::string _(const char *str)
std::string tooltip
Shown when hovering over an entry in the filter's drop-down list.
Standard logging facilities (interface).
static bool file_exists(const bfs::path &fpath)
std::string get_screenshot_dir()
std::string get_next_filename(const std::string &name, const std::string &extension)
Get the next free filename using "name + number (3 digits) + extension" maximum 1000 files then start...
void switch_theme(const std::string &theme_id)
Set and activate the given gui2 theme.
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
@ CANCEL
Dialog was closed with the CANCEL button.
void show_help(const std::string &show_topic)
Open the help browser, show topic with id show_topic.
Keyboard shortcuts for game actions.
void jhat_event(const SDL_Event &event, command_executor *executor)
void key_event(const SDL_Event &event, command_executor *executor)
void mbutton_event(const SDL_Event &event, command_executor *executor)
static void event_queue(const SDL_Event &event, command_executor *executor)
std::string get_names(const std::string &id)
Returns a comma-separated string of hotkey names.
std::shared_ptr< class hotkey_base > hotkey_ptr
const hotkey_ptr get_hotkey(const SDL_Event &event)
Iterate through the list of hotkeys and return a hotkey that matches the SDL_Event and the current ke...
void run_events(command_executor *executor)
void jbutton_event(const SDL_Event &event, command_executor *executor)
const hotkey_command & get_hotkey_command(std::string_view command)
Returns the hotkey_command with the given id.
void keyup_event(const SDL_Event &, command_executor *executor)
@ HOTKEY_MINIMAP_DRAW_VILLAGES
@ HOTKEY_TERRAIN_DESCRIPTION
@ HOTKEY_WB_EXECUTE_ALL_ACTIONS
@ HOTKEY_HELP_ABOUT_SAVELOAD
@ HOTKEY_SHOW_ENEMY_MOVES
@ HOTKEY_UNIT_DESCRIPTION
@ HOTKEY_LABEL_TEAM_TERRAIN
@ HOTKEY_UNIT_HOLD_POSITION
@ HOTKEY_REPLAY_NEXT_TURN
@ HOTKEY_SELECT_AND_ACTION
@ HOTKEY_REPLAY_SHOW_EVERYTHING
@ HOTKEY_REPLAY_SHOW_TEAM1
@ HOTKEY_MINIMAP_DRAW_TERRAIN
@ HOTKEY_BEST_ENEMY_MOVES
@ HOTKEY_MINIMAP_CODING_TERRAIN
@ HOTKEY_WB_EXECUTE_ACTION
@ HOTKEY_MINIMAP_DRAW_UNITS
@ HOTKEY_WB_BUMP_UP_ACTION
@ HOTKEY_REPLAY_NEXT_SIDE
@ HOTKEY_REPLAY_NEXT_MOVE
@ HOTKEY_REPLAY_SKIP_ANIMATION
@ HOTKEY_WB_BUMP_DOWN_ACTION
@ HOTKEY_REPLAY_SHOW_EACH
@ HOTKEY_CYCLE_BACK_UNITS
@ HOTKEY_WB_DELETE_ACTION
@ HOTKEY_MINIMAP_CODING_UNIT
play_controller * controller
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
void toggle_fullscreen()
Toggle fullscreen mode.
std::string filename
Filename.
const hotkey_command * command
Stores all information related to functions that can be bound to hotkeys.
HOTKEY_COMMAND command
The command associated with this hotkey.
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...
An abstract description of a rectangle with integer coordinates.