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;
444 std::vector<std::string>
items = items_arg;
450 while(i != items.end()) {
463 if(command[0] ==
'&') {
464 std::size_t
n = command.find_first_of(
'=');
465 if(n != std::string::npos)
466 return command.substr(1, n - 1);
469 const std::string base_image_name =
"icons/action/" + command +
"_25.png";
470 const std::string pressed_image_name =
"icons/action/" + command +
"_25-pressed.png";
477 return "icons/arrows/short_arrow_right_25.png~CROP(3,3,18,18)";
484 return pressed_image_name +
"~CROP(3,3,18,18)";
486 return base_image_name +
"~CROP(3,3,18,18)";
505 for(std::size_t
i = 0;
i < items.size(); ++
i) {
508 const std::string& item_id = item[
"id"];
513 if (img.empty() ==
false) {
519 item[
"label"] = menu->
title();
529 item[
"label"] = desc;
531 }
else if(item[
"label"].empty()) {
536 item[
"label"] = item_id;
571 if (!executor)
return;
577 if(!executor)
return;
583 if(!executor)
return;
592 if (!executor)
return;
599 LOG_HK <<
"event 0x" << std::hex <<
event.type << std::dec;
600 if(event.type == SDL_TEXTINPUT) {
601 LOG_HK <<
"SDL_TEXTINPUT \"" <<
event.text.text <<
"\"";
605 if(!hk->active() || hk->is_disabled()) {
610 bool keypress = (
event.type == SDL_KEYDOWN ||
event.type == SDL_TEXTINPUT) &&
612 bool press = keypress ||
613 (
event.type == SDL_JOYBUTTONDOWN ||
event.type == SDL_MOUSEBUTTONDOWN ||
event.type == SDL_FINGERDOWN);
614 bool release =
event.type == SDL_KEYUP;
616 LOG_HK <<
"sending press event (keypress = " <<
617 std::boolalpha << keypress << std::noboolalpha <<
")";
633 if (!command.
press) {
653 static struct before_muted_s
655 bool playing_sound,playing_music;
656 before_muted_s() : playing_sound(
false),playing_music(
false){}
675 DBG_G <<
"command_executor: unknown command number " << command.
command->
command <<
", ignoring.";
686 if (!button)
continue;
687 bool enabled =
false;
688 for (
const auto& command : menu.items()) {
697 button->enable(enabled);
703 if (!button)
continue;
704 bool enabled =
false;
706 for (
const std::string& command : action.items()) {
709 std::string
tooltip = action.tooltip(i);
711 button->set_overlay(
"icons/action/" + command);
712 if (!tooltip.empty())
713 button->set_tooltip_string(tooltip);
717 if (!can_execute)
continue;
724 button->set_check(
true);
728 button->set_check(
false);
738 button->enable(enabled);
746 std::vector<queued_command> filtered_commands;
749 using command_with_keyrelease = std::pair<const hotkey_command*, bool>;
750 std::set<command_with_keyrelease> seen_commands;
753 command_with_keyrelease command_key(cmd.command, cmd.release);
754 if(seen_commands.find(command_key) == seen_commands.end()) {
755 seen_commands.insert(command_key);
756 filtered_commands.push_back(cmd);
760 command_queue_.clear();
762 return filtered_commands;
772 return !commands.empty();
777 get_display().recalculate_minimap();
782 if (get_display().in_game()) {
797 if(!get_display().view_locked()) {
798 get_display().set_zoom(
true);
804 if(!get_display().view_locked()) {
805 get_display().set_zoom(
false);
811 if(!get_display().view_locked()) {
812 get_display().toggle_default_zoom();
std::shared_ptr< gui::button > find_action_button(const std::string &id)
Retrieves a pointer to a theme UI button.
play_controller * controller
Dialog was closed with the CANCEL button.
bool set_sound(bool ison)
virtual void toggle_shroud_updates()
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.
void show_help(const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
static display * get_singleton()
Returns the display object if a display object exists.
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 surrender(int side_number)
virtual void stop_network()
virtual void repeat_recruit()
virtual void lua_console()
static void quit_to_title()
virtual void save_replay()
virtual void create_unit()
virtual void goto_leader()
const action * get_action_item(const std::string &key) const
static bool file_exists(const bfs::path &fpath)
virtual void toggle_ellipses()
std::string selected_menu
void enable_mouse_scroll(bool value)
virtual void clear_labels()
virtual void play_replay()
virtual void ai_formula()
Stores all information related to functions that can be bound to hotkeys.
virtual void terrain_description()
const std::vector< std::string > items
std::string get_screenshot_dir()
virtual void show_chat_log()
virtual void select_hex()
void mbutton_event(const SDL_Event &event, command_executor *executor)
virtual void clear_messages()
virtual void move_action()
std::string unchecked_menu
HOTKEY_COMMAND command
The command associated with this hotkey.
virtual void recalculate_minimap()
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
virtual void select_and_action()
static std::string _(const char *str)
bool show(const unsigned auto_close_time=0)
Shows the window.
virtual void whiteboard_execute_action()
virtual void scroll_up(bool)
virtual void preferences()
virtual void toggle_grid()
virtual void replay_show_each()
Keyboard shortcuts for game actions.
virtual void stop_replay()
virtual void whiteboard_delete_action()
virtual bool can_execute_command(const hotkey_command &command, int index=-1) const =0
virtual void reset_replay()
static void display(lua_kernel_base *lk)
Display a new console, using given video and lua kernel.
virtual void whiteboard_bump_up_action()
virtual void label_terrain(bool)
virtual void deselect_hex()
void run_events(command_executor *executor)
static lg::log_domain log_config("config")
virtual void replay_next_move()
const hotkey_command * command
virtual void show_statistics()
std::string get_names(const std::string &id)
Returns a comma-separated string of hotkey names.
virtual void label_settings()
This shows a dialog displaying achievements.
static void event_queue(const SDL_Event &event, command_executor *executor)
std::string deselected_menu
void get_menu_images(display &, std::vector< config > &items)
virtual void replay_show_team1()
void jbutton_event(const SDL_Event &event, command_executor *executor)
void toggle_minimap_draw_units()
bool is_linger_mode() const
surface screenshot(bool map_screenshot=false)
Capture a (map-)screenshot into a surface.
virtual void continue_move()
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...
virtual void unit_hold_position()
std::shared_ptr< class hotkey_base > hotkey_ptr
virtual void scroll_right(bool)
virtual void end_unit_turn()
virtual void show_menu(const std::vector< config > &items_arg, int xloc, int yloc, bool context_menu, display &gui)
void keyup_event(const SDL_Event &, command_executor *executor)
virtual void user_command()
virtual void show_enemy_moves(bool)
Shows a yes and no button.
void toggle_minimap_draw_terrain()
map_display and display: classes which take care of displaying the map and game-data on the screen...
void set_animate_map(bool value)
void jhat_event(const SDL_Event &event, command_executor *executor)
void toggle_minimap_draw_villages()
void queue_command(const SDL_Event &event, int index=-1)
virtual void start_network()
std::string get_menu_image(display &disp, const std::string &command, int index=-1) const
void execute_command_wrap(const queued_command &command)
bool run_queued_commands()
static lg::log_domain log_hotkey("hotkey")
static void quit_to_desktop()
virtual void status_table()
virtual void scroll_left(bool)
std::vector< queued_command > command_queue_
virtual void update_shroud_now()
void toggle_minimap_terrain_coding()
void execute_action(const std::vector< std::string > &items_arg, int xloc, int yloc, bool context_menu, display &gui)
virtual void replay_show_everything()
virtual void scroll_down(bool)
virtual std::string get_action_image(hotkey::HOTKEY_COMMAND, int) const
void toggle_minimap_movement_coding()
virtual bool do_execute_command(const hotkey_command &command, int index=-1, bool press=true, bool release=false)
Declarations for File-IO.
const menu * get_menu_item(const std::string &key) const
const std::vector< action > & actions() const
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.
virtual void whiteboard_suppose_dead()
virtual void replay_next_turn()
void key_event(const SDL_Event &event, command_executor *executor)
virtual void whiteboard_bump_down_action()
void toggle_fullscreen()
Toggle fullscreen mode.
bool mouse_scroll_enabled()
virtual void change_side()
virtual void replay_next_side()
const std::string & title() const
virtual void whiteboard_execute_all_actions()
virtual void objectives()
virtual ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND, int) const
virtual void rename_unit()
uint32_t get_mouse_state(int *x, int *y)
A wrapper for SDL_GetMouseState that gives coordinates in draw space.
virtual void set_button_state()
bool set_music(bool ison)
Standard logging facilities (interface).
std::vector< queued_command > filter_command_queue()
virtual void cycle_units()
virtual void cycle_back_units()
const std::vector< menu > & menus() const
virtual void map_screenshot()
void recalculate_minimap()
A config object defines a single node in a WML file, with access to child nodes.
static void make_screenshot()
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
static map_location::DIRECTION n
virtual void replay_exit()
std::string::const_iterator iterator
virtual void zoom_default()
std::shared_ptr< gui::button > find_menu_button(const std::string &id)
virtual void replay_skip_animation()
std::string tooltip
Shown when hovering over an entry in the filter's drop-down list.
virtual void change_language()
std::pair< std::string, unsigned > item
virtual void whiteboard_toggle()
virtual void toggle_accelerated_speed()
virtual void unit_description()
virtual void custom_command()