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 SDL_Rect pos {xloc, yloc, 1, 1};
451 if(res < 0 || std::size_t(res) >= items.size()) {
455 std::string
id = items[res][
"id"];
457 show_menu(submenu->items(), selection_pos.x, selection_pos.y, submenu->is_context());
465 for(
const std::string& item : items_arg) {
476 const std::string& command = item[
"id"];
479 const std::string default_image =
"icons/action/" + command +
"_25.png";
480 const std::string pressed_image =
"icons/action/" + command +
"_25-pressed.png";
491 item[
"icon"] = pressed_image +
"~CROP(3,3,18,18)";
494 item[
"icon"] = default_image +
"~CROP(3,3,18,18)";
501 item[
"checkbox"] =
true;
504 item[
"checkbox"] =
false;
507 item[
"radio"] =
true;
510 item[
"radio"] =
false;
520 const std::string& item_id = item[
"id"];
526 item[
"icon"] =
"icons/arrows/short_arrow_right_25.png~CROP(3,3,18,18)";
527 item[
"label"] = menu->title();
535 std::string desc = hk.description;
544 item[
"label"] = desc;
579 if (!executor)
return;
585 if(!executor)
return;
591 if(!executor)
return;
600 if (!executor)
return;
607 LOG_HK <<
"event 0x" << std::hex <<
event.type << std::dec;
608 if(event.type == SDL_TEXTINPUT) {
609 LOG_HK <<
"SDL_TEXTINPUT \"" <<
event.text.text <<
"\"";
613 if(!hk->active() || hk->is_disabled()) {
618 bool keypress = (
event.type == SDL_KEYDOWN ||
event.type == SDL_TEXTINPUT) &&
620 bool press = keypress ||
621 (
event.type == SDL_JOYBUTTONDOWN ||
event.type == SDL_MOUSEBUTTONDOWN ||
event.type == SDL_FINGERDOWN);
622 bool release =
event.type == SDL_KEYUP;
624 LOG_HK <<
"sending press event (keypress = " <<
625 std::boolalpha << keypress << std::noboolalpha <<
")";
642 if (!command.
press) {
651 make_screenshot(
_(
"Screenshot"),
false);
662 static struct before_muted_s
664 bool playing_sound,playing_music;
665 before_muted_s() : playing_sound(
false),playing_music(
false){}
684 DBG_G <<
"command_executor: unknown command number " << command.
command->
command <<
", ignoring.";
695 if (!button)
continue;
696 bool enabled =
false;
697 for (
const auto& command : menu.items()) {
706 button->enable(enabled);
712 if (!button)
continue;
713 bool enabled =
false;
715 for (
const std::string& command : action.items()) {
718 std::string
tooltip = action.tooltip(
i);
720 button->set_overlay(
"icons/action/" + command);
722 button->set_tooltip_string(
tooltip);
726 if (!can_execute)
continue;
733 button->set_check(
true);
737 button->set_check(
false);
747 button->enable(enabled);
755 std::vector<queued_command> filtered_commands;
758 using command_with_keyrelease = std::pair<const hotkey_command*, bool>;
759 std::set<command_with_keyrelease> seen_commands;
762 command_with_keyrelease command_key(cmd.command, cmd.release);
763 if(seen_commands.find(command_key) == seen_commands.end()) {
764 seen_commands.insert(command_key);
765 filtered_commands.push_back(cmd);
771 return filtered_commands;
781 return !commands.empty();
831 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 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 show_menu(const std::vector< config > &items_arg, int xloc, int yloc, bool context_menu)
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...