Merge branch 'master' of github.com:wesnoth/wesnoth

This commit is contained in:
Charles Dang 2014-12-21 15:21:58 +11:00
commit c5c1311ba8
7 changed files with 48 additions and 12 deletions

View file

@ -57,7 +57,7 @@ void controller_base::handle_event(const SDL_Event& event)
// in which case the key press events should go only to it.
if(have_keyboard_focus()) {
process_keydown_event(event);
hotkey::key_event(get_display(), event.key,this);
hotkey::key_event(get_display(), event.key, get_hotkey_command_executor());
} else {
process_focus_keydown_event(event);
break;
@ -68,11 +68,11 @@ void controller_base::handle_event(const SDL_Event& event)
break;
case SDL_JOYBUTTONDOWN:
process_keydown_event(event);
hotkey::jbutton_event(get_display(), event.jbutton, this);
hotkey::jbutton_event(get_display(), event.jbutton, get_hotkey_command_executor());
break;
case SDL_JOYHATMOTION:
process_keydown_event(event);
hotkey::jhat_event(get_display(), event.jhat, this);
hotkey::jhat_event(get_display(), event.jhat, get_hotkey_command_executor());
break;
case SDL_MOUSEMOTION:
// Ignore old mouse motion events in the event queue
@ -92,7 +92,7 @@ void controller_base::handle_event(const SDL_Event& event)
if (get_mouse_handler_base().get_show_menu()){
show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true, get_display());
}
hotkey::mbutton_event(get_display(), event.button, this);
hotkey::mbutton_event(get_display(), event.button, get_hotkey_command_executor());
break;
case SDL_MOUSEBUTTONUP:
get_mouse_handler_base().mouse_press(event.button, browse_);
@ -291,11 +291,16 @@ void controller_base::play_slice(bool is_delay_enabled)
void controller_base::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& disp)
{
hotkey::command_executor * cmd_exec = get_hotkey_command_executor();
if (!cmd_exec) {
return;
}
std::vector<std::string> items = items_arg;
std::vector<std::string>::iterator i = items.begin();
while(i != items.end()) {
const hotkey::hotkey_command& command = hotkey::get_hotkey_command(*i);
if(!can_execute_command(command)
if(!cmd_exec->can_execute_command(command)
|| (context_menu && !in_context_menu(command.id))) {
i = items.erase(i);
continue;
@ -304,23 +309,27 @@ void controller_base::show_menu(const std::vector<std::string>& items_arg, int x
}
if(items.empty())
return;
command_executor::show_menu(items, xloc, yloc, context_menu, disp);
cmd_exec->show_menu(items, xloc, yloc, context_menu, disp);
}
void controller_base::execute_action(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu)
{
hotkey::command_executor * cmd_exec = get_hotkey_command_executor();
if (!cmd_exec) {
return;
}
std::vector<std::string> items;
BOOST_FOREACH(const std::string& item, items_arg) {
const hotkey::hotkey_command& command = hotkey::get_hotkey_command(item);
if(can_execute_command(command))
if(cmd_exec->can_execute_command(command))
items.push_back(item);
}
if(items.empty())
return;
command_executor::execute_action(items, xloc, yloc, context_menu, get_display());
cmd_exec->execute_action(items, xloc, yloc, context_menu, get_display());
}

View file

@ -38,18 +38,22 @@
#include "global.hpp"
#include "hotkey/command_executor.hpp"
#include "events.hpp"
#include "hotkey/hotkey_command.hpp"
#include "joystick.hpp"
#include "key.hpp"
class CVideo;
class display;
class plugins_context;
namespace events { class mouse_handler_base; }
namespace hotkey { class command_executor; }
namespace soundsource { class manager; }
class controller_base : public hotkey::command_executor, public events::sdl_handler
class controller_base : public events::sdl_handler
{
public:
controller_base(const config& game_config, CVideo& video);
@ -77,6 +81,11 @@ protected:
*/
virtual plugins_context * get_plugins_context() { return NULL; }
/**
* Get (optionally) a command executor to handle context menu events
*/
virtual hotkey::command_executor * get_hotkey_command_executor() { return NULL; }
/**
* Derived classes should override this to return false when arrow keys
* should not scroll the map, hotkeys not processed etc, for example

View file

@ -963,7 +963,7 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
gui().invalidate_all();
return true;
default:
return controller_base::execute_command(cmd, index);
return hotkey::command_executor::execute_command(cmd, index);
}
}
@ -1339,5 +1339,8 @@ void editor_controller::process_keyup_event(const SDL_Event& event)
toolkit_->set_mouseover_overlay();
}
hotkey::command_executor * editor_controller::get_hotkey_command_executor() {
return this;
}
} //end namespace editor

View file

@ -24,6 +24,7 @@
#include "../../controller_base.hpp"
#include "help/help.hpp"
#include "hotkey/command_executor.hpp"
#include "../../mouse_handler_base.hpp"
#include "../../tooltips.hpp"
@ -68,6 +69,7 @@ enum menu_type {
* general logic.
*/
class editor_controller : public controller_base,
public hotkey::command_executor,
public events::mouse_handler_base,
private boost::noncopyable
{
@ -158,6 +160,7 @@ class editor_controller : public controller_base,
void right_drag_end(int x, int y, const bool browse);
void right_mouse_up(int x, int y, const bool browse);
virtual hotkey::command_executor * get_hotkey_command_executor();
protected:
/* controller_base overrides */

View file

@ -513,6 +513,7 @@ void jhat_event(display& disp, const SDL_JoyHatEvent& event, command_executor* e
void key_event(display& disp, const SDL_KeyboardEvent& event, command_executor* executor)
{
if (!executor) return;
if(event.keysym.sym == SDLK_ESCAPE && disp.in_game()) {
LOG_G << "escape pressed..showing quit\n";
const int res = gui2::show_message(disp.video(), _("Quit"),
@ -529,6 +530,7 @@ void key_event(display& disp, const SDL_KeyboardEvent& event, command_executor*
void mbutton_event_execute(display& disp, const SDL_MouseButtonEvent& event, command_executor* executor)
{
if (!executor) return;
const hotkey_item* hk = &get_hotkey(event);
if (!hk->active()) {
return;
@ -540,6 +542,7 @@ void mbutton_event_execute(display& disp, const SDL_MouseButtonEvent& event, com
void jbutton_event_execute(display& disp, const SDL_JoyButtonEvent& event, command_executor* executor)
{
if (!executor) return;
const hotkey_item* hk = &get_hotkey(event);
if (!hk->active()) {
return;
@ -551,6 +554,7 @@ void jbutton_event_execute(display& disp, const SDL_JoyButtonEvent& event, comma
void jhat_event_execute(display& disp, const SDL_JoyHatEvent& event, command_executor* executor)
{
if (!executor) return;
const hotkey_item* hk = &get_hotkey(event);
if (!hk->active()) {
return;
@ -562,6 +566,7 @@ void jhat_event_execute(display& disp, const SDL_JoyHatEvent& event, command_exe
void key_event_execute(display& disp, const SDL_KeyboardEvent& event, command_executor* executor)
{
if (!executor) return;
const hotkey_item* hk = &get_hotkey(event);
#if 0

View file

@ -37,6 +37,7 @@
#include "map_label.hpp"
#include "gettext.hpp"
#include "halo.hpp"
#include "hotkey/command_executor.hpp"
#include "loadscreen.hpp"
#include "log.hpp"
#include "pathfind/teleport.hpp"
@ -1463,3 +1464,7 @@ soundsource::manager * play_controller::get_soundsource_man() {
plugins_context * play_controller::get_plugins_context() {
return plugins_context_.get();
}
hotkey::command_executor * play_controller::get_hotkey_command_executor() {
return this;
}

View file

@ -20,6 +20,7 @@
#include "game_end_exceptions.hpp"
#include "game_state.hpp"
#include "help/help.hpp"
#include "hotkey/command_executor.hpp"
#include "menu_events.hpp"
#include "mouse_events.hpp"
#include "persist_manager.hpp"
@ -75,7 +76,7 @@ namespace wb {
// Holds gamestate related objects
class game_state;
class play_controller : public controller_base, public events::observer, public savegame::savegame_config
class play_controller : public controller_base, public hotkey::command_executor, public events::observer, public savegame::savegame_config
{
public:
play_controller(const config& level, saved_game& state_of_game,
@ -196,6 +197,7 @@ public:
virtual soundsource::manager * get_soundsource_man();
virtual plugins_context * get_plugins_context();
virtual hotkey::command_executor * get_hotkey_command_executor();
protected:
game_display& get_display();