Turn hotkey scoping back on and fix issues...

...by making the editor have separate bindings from the main game. The
keys are separate, but some hotkey commands are shared.
This commit is contained in:
Tomasz Śniatowski 2008-07-16 17:25:07 +01:00
parent 018a528094
commit 28e567b641
6 changed files with 74 additions and 20 deletions

View File

@ -79,8 +79,8 @@
[/hotkey]
[hotkey]
command="editor-tool-draw"
description="Select the draw tool"
command="editor-tool-paint"
description="Select the paint (draw) tool"
key="d"
[/hotkey]

View File

@ -41,9 +41,6 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
, gui_(NULL), actions_since_save_(0), do_quit_(false), quit_mode_(EXIT_ERROR)
, current_brush_index_(0)
{
hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
init(video);
cursor::set(cursor::NORMAL);

View File

@ -20,8 +20,13 @@ namespace editor2 {
EXIT_STATUS start(config& game_conf, CVideo& video)
{
hotkey::scope_changer h_(game_conf, "hotkey_editor");
hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
editor_controller editor(game_conf, video);
return editor.main_loop();
EXIT_STATUS e = editor.main_loop();
return e;
}
} //end namespace editor2

View File

@ -529,6 +529,9 @@ bool game_controller::init_config()
refresh_game_cfg();
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_GAME);
hotkey::load_hotkeys(game_config_);
paths_manager_.set_paths(game_config_);
@ -2003,9 +2006,6 @@ bool game_controller::change_language()
void game_controller::show_preferences()
{
hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_GAME);
const preferences::display_manager disp_manager(&disp());
preferences::show_preferences_dialog(disp(),game_config_);
@ -2380,7 +2380,6 @@ editor2::EXIT_STATUS game_controller::start_editor()
reset_game_cfg();
defines_map_["EDITOR2"] = preproc_define();
refresh_game_cfg();
hotkey::load_hotkeys(game_config_);
return editor2::start(game_config_, video_);
}
#endif

View File

@ -197,9 +197,11 @@ const struct {
std::vector<hotkey::hotkey_item> hotkeys_;
hotkey::hotkey_item null_hotkey_;
std::string hotkey_tag_name = "hotkey";
const std::string scope_strings_[] = {"general", "game", "editor"};
const std::string scope_labels_[] = {"Common", "Game", "Editor"};
bool scope_active_[hotkey::SCOPE_COUNT] = {true, false};
std::vector<bool> scope_active_(hotkey::SCOPE_COUNT, false);
}
namespace hotkey {
@ -207,8 +209,8 @@ namespace hotkey {
void deactivate_all_scopes()
{
foreach (bool& b, scope_active_) {
b = false;
for (int i = 0; i < hotkey::SCOPE_COUNT; ++i) {
scope_active_[i] = false;
}
}
@ -217,9 +219,9 @@ void set_scope_active(scope s, bool set)
scope_active_[s] = set;
}
bool is_scope_active(scope /*s*/)
bool is_scope_active(scope s)
{
return true; //scope_active_[s];
return scope_active_[s];
}
const std::string& get_scope_string(scope s)
@ -389,6 +391,11 @@ void hotkey_item::set_key(int character, int keycode, bool shift, bool ctrl, boo
}
manager::manager()
{
init();
}
void manager::init()
{
for (int i = 0; hotkey_list_[i].command; ++i) {
hotkeys_.push_back(hotkey_item(hotkey_list_[i].id, hotkey_list_[i].command,
@ -396,10 +403,36 @@ manager::manager()
}
}
void manager::wipe()
{
hotkeys_.clear();
}
manager::~manager()
{
hotkeys_.clear();
wipe();
}
scope_changer::scope_changer(const config& cfg, const std::string& hotkey_tag)
: cfg_(cfg)
, prev_tag_name_(hotkey_tag_name)
, prev_scope_active_(scope_active_)
{
manager::wipe();
manager::init();
hotkey::load_descriptions();
load_hotkeys(cfg_);
set_hotkey_tag_name(hotkey_tag);
}
scope_changer::~scope_changer()
{
scope_active_.swap(prev_scope_active_);
manager::wipe();
manager::init();
hotkey::load_descriptions();
set_hotkey_tag_name(prev_tag_name_);
load_hotkeys(cfg_);
}
void load_descriptions()
@ -412,9 +445,15 @@ void load_descriptions()
}
}
void set_hotkey_tag_name(const std::string& name)
{
hotkey_tag_name = name;
}
void load_hotkeys(const config& cfg)
{
const config::child_list& children = cfg.get_children("hotkey");
std::cerr << "load_hotkeys " << hotkey_tag_name << "\n";
const config::child_list& children = cfg.get_children(hotkey_tag_name);
for(config::child_list::const_iterator i = children.begin(); i != children.end(); ++i) {
hotkey_item& h = get_hotkey((**i)["command"]);
if(h.get_id() != HOTKEY_NULL) {
@ -425,13 +464,14 @@ void load_hotkeys(const config& cfg)
void save_hotkeys(config& cfg)
{
cfg.clear_children("hotkey");
std::cerr << "save_hotkeys " << hotkey_tag_name << "\n";
cfg.clear_children(hotkey_tag_name);
for(std::vector<hotkey_item>::iterator i = hotkeys_.begin(); i != hotkeys_.end(); ++i) {
if (i->hidden() || i->get_type() == hotkey_item::UNBOUND)
if (i->hidden() || i->get_type() == hotkey_item::UNBOUND || !i->is_in_active_scope())
continue;
config& item = cfg.add_child("hotkey");
config& item = cfg.add_child(hotkey_tag_name);
item["command"] = i->get_command();
if (i->get_type() == hotkey_item::CLEARED)
{

View File

@ -195,11 +195,24 @@ private:
class manager {
public:
manager();
static void init();
static void wipe();
~manager();
};
class scope_changer {
public:
scope_changer(const config& cfg, const std::string& hotkey_tag);
~scope_changer();
private:
const config& cfg_;
std::string prev_tag_name_;
std::vector<bool> prev_scope_active_;
};
void load_descriptions();
void set_hotkey_tag_name(const std::string& name);
void load_hotkeys(const config& cfg);
void save_hotkeys(config& cfg);