Fixed hotkey scope regression

See comment in hotkey/hotkey/hotkey_command.hpp for explanation. This isn't a good solution,
but I need to figure out a better one.
This commit is contained in:
Charles Dang 2022-05-26 22:41:44 -04:00
parent 8960e407e9
commit 7e76e21a87
5 changed files with 10 additions and 8 deletions

View File

@ -32,7 +32,7 @@ EXIT_STATUS start(const std::string& filename /* = "" */,
{ {
EXIT_STATUS e = EXIT_ERROR; EXIT_STATUS e = EXIT_ERROR;
try { try {
const hotkey::scope_changer h{hotkey::SCOPE_EDITOR}; const hotkey::scope_changer h{hotkey::scope_editor};
editor_controller editor; editor_controller editor;
if (!filename.empty() && filesystem::file_exists (filename)) { if (!filename.empty() && filesystem::file_exists (filename)) {
if (filesystem::is_directory(filename)) { if (filesystem::is_directory(filename)) {

View File

@ -115,7 +115,7 @@ bool game_config_manager::init_game_config(FORCE_RELOAD_CONFIG force_reload)
// It's necessary to block the event thread while load_hotkeys() runs, otherwise keyboard input // It's necessary to block the event thread while load_hotkeys() runs, otherwise keyboard input
// can cause a crash by accessing the list of hotkeys while it's being modified. // can cause a crash by accessing the list of hotkeys while it's being modified.
events::call_in_main_thread([this]() { events::call_in_main_thread([this]() {
const hotkey::scope_changer hk_scope{hotkey::SCOPE_MAIN_MENU, false}; const hotkey::scope_changer hk_scope{hotkey::scope_main, false};
// Load the standard hotkeys, then apply any player customizations. // Load the standard hotkeys, then apply any player customizations.
hotkey::load_default_hotkeys(game_config()); hotkey::load_default_hotkeys(game_config());

View File

@ -63,11 +63,6 @@ const std::map<HOTKEY_CATEGORY, std::string> category_names {
{ HKCAT_CUSTOM, N_("Custom WML Commands") }, { HKCAT_CUSTOM, N_("Custom WML Commands") },
}; };
// For some reason std::bitset::operator| is not constexpr, so we'll construct the bitset with these values
constexpr uint32_t scope_game = 1 << SCOPE_GAME;
constexpr uint32_t scope_editor = 1 << SCOPE_EDITOR;
constexpr uint32_t scope_main = 1 << SCOPE_MAIN_MENU;
// //
// All static hotkeys. // All static hotkeys.
// //

View File

@ -39,6 +39,13 @@ enum scope {
SCOPE_COUNT, SCOPE_COUNT,
}; };
// For some reason std::bitset::operator| is not constexpr, so we'll construct the bitset with these values
// FIXME: unify these with the enum above. Right now these are the proper bitmasks to initialize a bitset,
// while the values above are used as indices to access the bits of the bitset.
constexpr uint32_t scope_game = 1 << SCOPE_GAME;
constexpr uint32_t scope_editor = 1 << SCOPE_EDITOR;
constexpr uint32_t scope_main = 1 << SCOPE_MAIN_MENU;
enum HOTKEY_COMMAND { enum HOTKEY_COMMAND {
HOTKEY_CYCLE_UNITS, HOTKEY_CYCLE_BACK_UNITS, HOTKEY_CYCLE_UNITS, HOTKEY_CYCLE_BACK_UNITS,
HOTKEY_UNIT_HOLD_POSITION, HOTKEY_UNIT_HOLD_POSITION,

View File

@ -89,7 +89,7 @@ namespace test_utils {
unit_types.set_config(game_config_view_.merged_children_view("units")); unit_types.set_config(game_config_view_.merged_children_view("units"));
game_config::load_config(cfg_.child("game_config")); game_config::load_config(cfg_.child("game_config"));
const hotkey::scope_changer hk_scope{hotkey::SCOPE_GAME, false}; const hotkey::scope_changer hk_scope{hotkey::scope_game, false};
hotkey::load_default_hotkeys(game_config_view_); hotkey::load_default_hotkeys(game_config_view_);
paths_manager_.set_paths(game_config_view_); paths_manager_.set_paths(game_config_view_);