Author: ilor
Date: Wed Jul 16 18:25:07 2008
New Revision: 28054
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28054&view=rev
Log:
Turn on 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.
Modified:
trunk/data/core/editor2-hotkeys.cfg
trunk/src/editor2/editor_controller.cpp
trunk/src/editor2/editor_main.cpp
trunk/src/game.cpp
trunk/src/hotkeys.cpp
trunk/src/hotkeys.hpp
Modified: trunk/data/core/editor2-hotkeys.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/editor2-hotkeys.cfg?rev=28054&r1=28053&r2=28054&view=diff
==============================================================================
--- trunk/data/core/editor2-hotkeys.cfg (original)
+++ trunk/data/core/editor2-hotkeys.cfg Wed Jul 16 18:25:07 2008
@@ -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]
Modified: trunk/src/editor2/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28054&r1=28053&r2=28054&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Wed Jul 16 18:25:07 2008
@@ -41,9 +41,6 @@
, 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);
Modified: trunk/src/editor2/editor_main.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_main.cpp?rev=28054&r1=28053&r2=28054&view=diff
==============================================================================
--- trunk/src/editor2/editor_main.cpp (original)
+++ trunk/src/editor2/editor_main.cpp Wed Jul 16 18:25:07 2008
@@ -20,8 +20,13 @@
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
Modified: trunk/src/game.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=28054&r1=28053&r2=28054&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Wed Jul 16 18:25:07 2008
@@ -529,6 +529,9 @@
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 @@
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 @@
reset_game_cfg();
defines_map_["EDITOR2"] = preproc_define();
refresh_game_cfg();
- hotkey::load_hotkeys(game_config_);
return editor2::start(game_config_, video_);
}
#endif
Modified: trunk/src/hotkeys.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.cpp?rev=28054&r1=28053&r2=28054&view=diff
==============================================================================
--- trunk/src/hotkeys.cpp (original)
+++ trunk/src/hotkeys.cpp Wed Jul 16 18:25:07 2008
@@ -197,9 +197,11 @@
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 @@
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 @@
scope_active_[s] = set;
}
-bool is_scope_active(scope /*s*/)
-{
- return true; //scope_active_[s];
+bool is_scope_active(scope s)
+{
+ return scope_active_[s];
}
const std::string& get_scope_string(scope s)
@@ -390,16 +392,47 @@
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,
"", hotkey_list_[i].hidden,
hotkey_list_[i].scope));
}
}
+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 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 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)
{
Modified: trunk/src/hotkeys.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.hpp?rev=28054&r1=28053&r2=28054&view=diff
==============================================================================
--- trunk/src/hotkeys.hpp (original)
+++ trunk/src/hotkeys.hpp Wed Jul 16 18:25:07 2008
@@ -195,11 +195,24 @@
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);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits