33 #include "../resources.hpp"
34 #include "../playmp_controller.hpp"
45 #define ERR_G LOG_STREAM(err, lg::general())
46 #define WRN_G LOG_STREAM(warn, lg::general())
47 #define LOG_G LOG_STREAM(info, lg::general())
48 #define DBG_G LOG_STREAM(debug, lg::general())
49 #define ERR_CF LOG_STREAM(err, log_config)
50 #define LOG_HK LOG_STREAM(info, log_hotkey)
60 gui2::dialogs::screenshot_notification::display(
filename, screenshot);
66 static void event_queue(
const SDL_Event& event, command_executor* executor);
414 std::vector<config> items = items_arg;
415 if (items.empty())
return;
421 SDL_Rect pos {xloc, yloc, 1, 1};
427 if (res < 0 || std::size_t(res) >= items.size())
return;
429 std::string
id = items[res][
"id"];
443 std::vector<std::string> items = items_arg;
449 while(
i != items.end()) {
461 const std::string base_image_name =
"icons/action/" + command +
"_25.png";
462 const std::string pressed_image_name =
"icons/action/" + command +
"_25-pressed.png";
469 return "icons/arrows/short_arrow_right_25.png~CROP(3,3,18,18)";
476 return pressed_image_name +
"~CROP(3,3,18,18)";
478 return base_image_name +
"~CROP(3,3,18,18)";
497 for(std::size_t
i = 0;
i < items.size(); ++
i) {
500 const std::string& item_id = item[
"id"];
505 if (
img.empty() ==
false) {
511 item[
"label"] = menu->
title();
521 item[
"label"] = desc;
557 if (!executor)
return;
563 if(!executor)
return;
569 if(!executor)
return;
578 if (!executor)
return;
585 LOG_HK <<
"event 0x" << std::hex <<
event.type << std::dec;
586 if(event.type == SDL_TEXTINPUT) {
587 LOG_HK <<
"SDL_TEXTINPUT \"" <<
event.text.text <<
"\"";
591 if(!hk->active() || hk->is_disabled()) {
596 bool keypress = (
event.type == SDL_KEYDOWN ||
event.type == SDL_TEXTINPUT) &&
598 bool press = keypress ||
599 (
event.type == SDL_JOYBUTTONDOWN ||
event.type == SDL_MOUSEBUTTONDOWN ||
event.type == SDL_FINGERDOWN);
600 bool release =
event.type == SDL_KEYUP;
602 LOG_HK <<
"sending press event (keypress = " <<
603 std::boolalpha << keypress << std::noboolalpha <<
")";
620 if (!command.
press) {
640 static struct before_muted_s
642 bool playing_sound,playing_music;
643 before_muted_s() : playing_sound(
false),playing_music(
false){}
662 DBG_G <<
"command_executor: unknown command number " << command.
command->
command <<
", ignoring.";
673 if (!button)
continue;
674 bool enabled =
false;
675 for (
const auto& command : menu.items()) {
684 button->enable(enabled);
690 if (!button)
continue;
691 bool enabled =
false;
693 for (
const std::string& command : action.items()) {
696 std::string
tooltip = action.tooltip(
i);
698 button->set_overlay(
"icons/action/" + command);
700 button->set_tooltip_string(
tooltip);
704 if (!can_execute)
continue;
711 button->set_check(
true);
715 button->set_check(
false);
725 button->enable(enabled);
733 std::vector<queued_command> filtered_commands;
736 using command_with_keyrelease = std::pair<const hotkey_command*, bool>;
737 std::set<command_with_keyrelease> seen_commands;
740 command_with_keyrelease command_key(cmd.command, cmd.release);
741 if(seen_commands.find(command_key) == seen_commands.end()) {
742 seen_commands.insert(command_key);
743 filtered_commands.push_back(cmd);
749 return filtered_commands;
759 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.
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 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 select_teleport()
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)
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...
std::string selected_menu
std::string deselected_menu
std::string unchecked_menu
static void make_screenshot()
void switch_theme(const std::string ¤t_theme)
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)
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
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)
@ 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
std::string img(const std::string &src, const std::string &align, const bool floating)
play_controller * controller
point get_mouse_location()
Returns the current mouse location 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
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 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...