35 #include "../resources.hpp"
36 #include "../playmp_controller.hpp"
42 #include <SDL2/SDL_image.h>
50 #define ERR_G LOG_STREAM(err, lg::general())
51 #define WRN_G LOG_STREAM(warn, lg::general())
52 #define LOG_G LOG_STREAM(info, lg::general())
53 #define DBG_G LOG_STREAM(debug, lg::general())
54 #define ERR_CF LOG_STREAM(err, log_config)
55 #define LOG_HK LOG_STREAM(info, log_hotkey)
65 gui2::dialogs::screenshot_notification::display(filename, screenshot);
71 static void event_queue(
const SDL_Event& event, command_executor* executor);
415 std::vector<config>
items = items_arg;
416 if (
items.empty())
return;
422 SDL_Rect pos {xloc, yloc, 1, 1};
428 if (res < 0 || std::size_t(res) >=
items.size())
return;
430 std::string
id =
items[res][
"id"];
445 std::vector<std::string>
items = items_arg;
463 const std::string base_image_name =
"icons/action/" + command +
"_25.png";
464 const std::string pressed_image_name =
"icons/action/" + command +
"_25-pressed.png";
471 return "icons/arrows/short_arrow_right_25.png~CROP(3,3,18,18)";
478 return pressed_image_name +
"~CROP(3,3,18,18)";
480 return base_image_name +
"~CROP(3,3,18,18)";
499 for(std::size_t
i = 0;
i <
items.size(); ++
i) {
502 const std::string& item_id =
item[
"id"];
507 if (img.empty() ==
false) {
523 item[
"label"] = desc;
559 if (!executor)
return;
565 if(!executor)
return;
571 if(!executor)
return;
580 if (!executor)
return;
587 LOG_HK <<
"event 0x" << std::hex <<
event.type << std::dec;
588 if(event.type == SDL_TEXTINPUT) {
589 LOG_HK <<
"SDL_TEXTINPUT \"" <<
event.text.text <<
"\"";
593 if(!hk->active() || hk->is_disabled()) {
598 bool keypress = (
event.type == SDL_KEYDOWN ||
event.type == SDL_TEXTINPUT) &&
600 bool press = keypress ||
601 (
event.type == SDL_JOYBUTTONDOWN ||
event.type == SDL_MOUSEBUTTONDOWN ||
event.type == SDL_FINGERDOWN);
602 bool release =
event.type == SDL_KEYUP;
604 LOG_HK <<
"sending press event (keypress = " <<
605 std::boolalpha << keypress << std::noboolalpha <<
")";
622 if (!command.
press) {
642 static struct before_muted_s
644 bool playing_sound,playing_music;
645 before_muted_s() : playing_sound(
false),playing_music(
false){}
664 DBG_G <<
"command_executor: unknown command number " << command.
command->
command <<
", ignoring.";
675 if (!button)
continue;
676 bool enabled =
false;
677 for (
const auto& command : menu.items()) {
686 button->enable(enabled);
692 if (!button)
continue;
693 bool enabled =
false;
695 for (
const std::string& command : action.items()) {
698 std::string
tooltip = action.tooltip(
i);
700 button->set_overlay(
"icons/action/" + command);
702 button->set_tooltip_string(
tooltip);
706 if (!can_execute)
continue;
713 button->set_check(
true);
717 button->set_check(
false);
727 button->enable(enabled);
735 std::vector<queued_command> filtered_commands;
738 using command_with_keyrelease = std::pair<const hotkey_command*, bool>;
739 std::set<command_with_keyrelease> seen_commands;
742 command_with_keyrelease command_key(cmd.command, cmd.release);
743 if(seen_commands.find(command_key) == seen_commands.end()) {
744 seen_commands.insert(command_key);
745 filtered_commands.push_back(cmd);
751 return filtered_commands;
761 return !commands.empty();
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.
std::size_t viewing_team() const
The viewing team is the team currently viewing the game.
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.
This shows a dialog displaying achievements.
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 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)
virtual void scroll_left(bool)
virtual void whiteboard_execute_all_actions()
void get_menu_images(display &, std::vector< config > &items)
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()
void execute_action(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu, display &gui)
virtual void show_enemy_moves(bool)
std::vector< queued_command > command_queue_
virtual void lua_console()
std::string get_menu_image(display &disp, const std::string &command, int index=-1) const
virtual void status_table()
virtual ACTION_STATE get_action_state(const hotkey::ui_command &) const
virtual void save_replay()
virtual void toggle_shroud_updates()
virtual void whiteboard_bump_down_action()
void execute_command_wrap(const queued_command &command)
virtual void whiteboard_delete_action()
virtual void move_action()
virtual void user_command()
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()
virtual void show_menu(const std::vector< config > &items_arg, int xloc, int yloc, bool context_menu, display &gui)
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 std::string get_action_image(const hotkey::ui_command &) const
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()
bool is_linger_mode() const
void surrender(int side_number)
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")
Declarations for File-IO.
Contains the exception interfaces used to signal completion of a scenario, campaign or turn.
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...
std::string selected_menu
std::string deselected_menu
std::string unchecked_menu
static void make_screenshot()
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, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
std::pair< std::string, unsigned > item
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)
void keyup_event(const SDL_Event &, command_executor *executor)
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
@ 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
const std::vector< std::string > items
bool set_sound(bool ison)
void toggle_minimap_draw_villages()
void toggle_minimap_draw_units()
bool mouse_scroll_enabled()
bool set_music(bool ison)
void enable_mouse_scroll(bool value)
void toggle_minimap_terrain_coding()
void set_animate_map(bool value)
void toggle_minimap_draw_terrain()
void toggle_minimap_movement_coding()
play_controller * controller
uint32_t get_mouse_state(int *x, int *y)
A wrapper for SDL_GetMouseState that gives coordinates in draw space.
std::size_t index(const std::string &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::const_iterator iterator
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 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...