Skip to content

Commit

Permalink
more flexible hotkey scopes
Browse files Browse the repository at this point in the history
there are some hotkeys that are senseful in editor and in game but not
in teh main menu, so now instead of having hotkeys eigher in GAME,
EDITOR, MAIN_MENU or GENERAL we now allow any combination of the first
3.

this is also intended to fix a bug in add_hotkey() if new_scope ==
hotkey::SCOPE_COUNT where new hotkeys doesn't correctly overwrite other
scoped hotkeys.
  • Loading branch information
gfgtdf committed Jun 21, 2014
1 parent 7e3ba43 commit 436be9a
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 246 deletions.
1 change: 0 additions & 1 deletion src/editor/editor_main.cpp
Expand Up @@ -33,7 +33,6 @@ EXIT_STATUS start(const config& game_conf, CVideo& video, const std::string& fil
try {
hotkey::scope_changer h_;
hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
editor_controller editor(game_conf, video);
if (!filename.empty()) {
Expand Down
1 change: 0 additions & 1 deletion src/game_config_manager.cpp
Expand Up @@ -81,7 +81,6 @@ bool game_config_manager::init_game_config(FORCE_RELOAD_CONFIG force_reload)
game_config::load_config(game_config_.child("game_config"));

hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_MAIN_MENU);

hotkey::load_hotkeys(game_config(), true);
Expand Down
425 changes: 216 additions & 209 deletions src/hotkey/hotkey_command.cpp

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions src/hotkey/hotkey_command.hpp
Expand Up @@ -29,11 +29,12 @@ namespace hotkey {
* non-overlapping areas of the game share the same key
*/
enum scope {
SCOPE_GENERAL,
SCOPE_MAIN_MENU,
SCOPE_GAME,
SCOPE_EDITOR,
SCOPE_COUNT
SCOPE_COUNT,
//SCOPE_GENERAL is onyl used by teh preferences menu as a categors = all of the above.
SCOPE_GENERAL
};

enum HOTKEY_COMMAND {
Expand Down Expand Up @@ -191,7 +192,7 @@ struct hotkey_command {
/// the compiler want me to make a default constructor
/// since most member are const, calling the default constructor is normally no use.
hotkey_command();
hotkey_command(hotkey::HOTKEY_COMMAND cmd, const std::string& id, const t_string& desc, bool hidden, hotkey::scope scope, const t_string& tooltip);
hotkey_command(hotkey::HOTKEY_COMMAND cmd, const std::string& id, const t_string& desc, bool hidden, hotkey::hk_scopes scope, const t_string& tooltip);
/// the names are strange: the "hotkey::HOTKEY_COMMAND" is named id, and the string to identify the object is called "command"
/// there is some inconstancy with that names in this file.
/// This binds the command to a function. Does not need to be unique.
Expand All @@ -203,7 +204,7 @@ struct hotkey_command {
/// If hidden then don't show the command in the hotkey preferences.
const bool hidden;
/// The visibility scope of the command.
const hotkey::scope scope;
const hotkey::hk_scopes scope;

const t_string tooltip;

Expand All @@ -227,7 +228,7 @@ struct hotkey_command_temp {

bool hidden;

hotkey::scope scope;
hotkey::hk_scopes scope;

const char* tooltip;
};
Expand All @@ -252,7 +253,8 @@ const hotkey_command& get_hotkey_null();

void deactivate_all_scopes();
void set_scope_active(scope s, bool set = true);
bool is_scope_active(scope s);
void set_active_scopes(hk_scopes s);
bool is_scope_active(hk_scopes s);

///
bool has_hotkey_command(const std::string& id);
Expand Down
9 changes: 2 additions & 7 deletions src/hotkey/hotkey_item.cpp
Expand Up @@ -234,14 +234,9 @@ bool has_hotkey_item(const std::string& command)
}

void add_hotkey(const hotkey_item& item) {

scope new_scope = hotkey::get_hotkey_command(item.get_command()).scope;
if(new_scope == hotkey::SCOPE_COUNT)
new_scope = hotkey::SCOPE_GAME;

scope_changer scope_ch;
deactivate_all_scopes();
hotkey::set_scope_active(new_scope);
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
set_active_scopes(hotkey::get_hotkey_command(item.get_command()).scope);

hotkey_item& old_hk = (item.get_mouse() != -1 || item.get_joystick() != -1) ?
::get_hotkey(item.get_mouse(), item.get_joystick(), item.get_button(), item.get_hat()
Expand Down
39 changes: 19 additions & 20 deletions src/hotkey/hotkey_preferences_display.cpp
Expand Up @@ -286,23 +286,26 @@ hotkey_preferences_dialog::hotkey_preferences_dialog(display& disp) :
{
continue;
}

switch (command.scope) {

case hotkey::SCOPE_GAME:
game_commands_.push_back(command.command);
break;
case hotkey::SCOPE_EDITOR:
editor_commands_.push_back(command.command);
break;
case hotkey::SCOPE_GENERAL:
// We move hotkeys in all categories thet they belog to, except for hotkeys that
// belong to all 3 scoped that we put in a seperate HOTKEY_GENERAL category.
if(command.scope.count() < hotkey::SCOPE_COUNT) //Not all
{
if(command.scope[hotkey::SCOPE_GAME])
{
game_commands_.push_back(command.command);
}
if(command.scope[hotkey::SCOPE_EDITOR])
{
editor_commands_.push_back(command.command);
}
if(command.scope[hotkey::SCOPE_MAIN_MENU])
{
title_screen_commands_.push_back(command.command);
}
}
else
{
general_commands_.push_back(command.command);
break;
case hotkey::SCOPE_MAIN_MENU:
title_screen_commands_.push_back(command.command);
break;
case hotkey::SCOPE_COUNT:
break;
}
}

Expand Down Expand Up @@ -433,21 +436,17 @@ void hotkey_preferences_dialog::set_selection(int index) {
hotkey::deactivate_all_scopes();
switch (tab_) {
case hotkey::SCOPE_MAIN_MENU:
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_MAIN_MENU);
break;
case hotkey::SCOPE_GENERAL:
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_GAME);
hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
hotkey::set_scope_active(hotkey::SCOPE_MAIN_MENU);
break;
case hotkey::SCOPE_GAME:
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_GAME);
break;
case hotkey::SCOPE_EDITOR:
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
break;
case hotkey::SCOPE_COUNT:
Expand Down
1 change: 0 additions & 1 deletion src/play_controller.cpp
Expand Up @@ -162,7 +162,6 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,

game_config::add_color_info(level);
hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_GAME);
try {
init(video);
Expand Down
1 change: 0 additions & 1 deletion src/tests/utils/game_config_manager.cpp
Expand Up @@ -95,7 +95,6 @@ namespace test_utils {

game_config::load_config(cfg_.child("game_config"));
hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_GAME);

hotkey::load_hotkeys(cfg_);
Expand Down

0 comments on commit 436be9a

Please sign in to comment.