Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/wesnoth/wesnoth
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 23, 2014
2 parents 34a7454 + e2e82e8 commit 1526066
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 252 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
6 changes: 3 additions & 3 deletions src/font.cpp
Expand Up @@ -1217,10 +1217,10 @@ void undraw_floating_labels(surface screen)

}

static bool add_font_to_fontlist(config &fonts_config,
static bool add_font_to_fontlist(const config &fonts_config,
std::vector<font::subset_descriptor>& fontlist, const std::string& name)
{
config &font = fonts_config.find_child("font", "name", name);
const config &font = fonts_config.find_child("font", "name", name);
if (!font)
return false;

Expand Down Expand Up @@ -1272,7 +1272,7 @@ bool load_font_config()
return false;
}

config &fonts_config = cfg.child("fonts");
const config &fonts_config = cfg.child("fonts");
if (!fonts_config)
return false;

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
429 changes: 218 additions & 211 deletions src/hotkey/hotkey_command.cpp

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions src/hotkey/hotkey_command.hpp
Expand Up @@ -19,6 +19,7 @@
#include "tstring.hpp"
#include "boost/ptr_container/ptr_vector.hpp"

#include <bitset>
class config;

namespace hotkey {
Expand All @@ -28,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 @@ -181,14 +183,16 @@ enum HOTKEY_COMMAND {
HOTKEY_NULL
};

typedef std::bitset<SCOPE_COUNT> hk_scopes;

/// Stores all information related to functions that can be bound to hotkeys.
/// this is currently a semi struct: it haves a constructor, but only const-public members.
struct hotkey_command {
public:
/// 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 @@ -200,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 @@ -224,7 +228,7 @@ struct hotkey_command_temp {

bool hidden;

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

const char* tooltip;
};
Expand All @@ -234,7 +238,7 @@ class scope_changer {
scope_changer();
~scope_changer();
private:
std::vector<bool> prev_scope_active_;
hk_scopes prev_scope_active_;
};

/// returns a container that contains all currently active hotkey_commands.
Expand All @@ -249,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 1526066

Please sign in to comment.