From 1855ca47fcdaa521f0c41147fde57d73bc58c784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=9Aniatowski?= Date: Sun, 6 Jul 2008 15:49:19 +0100 Subject: [PATCH] move some more functions up to controller_base --- src/controller_base.cpp | 22 ++++++++++++++++++++++ src/controller_base.hpp | 6 ++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/controller_base.cpp b/src/controller_base.cpp index 6233823c3ef..9a947871ef3 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -179,3 +179,25 @@ void controller_base::slice_end() //no action by default } +void controller_base::show_menu(const std::vector& items_arg, int xloc, int yloc, bool context_menu) +{ + std::vector items = items_arg; + hotkey::HOTKEY_COMMAND command; + std::vector::iterator i = items.begin(); + while(i != items.end()) { + if(!can_execute_command(command) + || (context_menu && !in_context_menu(command))) { + i = items.erase(i); + continue; + } + ++i; + } + if(items.empty()) + return; + command_executor::show_menu(items, xloc, yloc, context_menu, get_display()); +} + +bool controller_base::in_context_menu(hotkey::HOTKEY_COMMAND /*command*/) const +{ + return true; +} diff --git a/src/controller_base.hpp b/src/controller_base.hpp index 11bb9f0d36c..d802509341b 100644 --- a/src/controller_base.hpp +++ b/src/controller_base.hpp @@ -55,7 +55,7 @@ protected: * Inherited from command_executor, still declared pure virtual but might * provide some defaults */ - virtual bool can_execute_command(hotkey::HOTKEY_COMMAND command, int index) const = 0; + virtual bool can_execute_command(hotkey::HOTKEY_COMMAND command, int index=-1) const = 0; /** * Get a reference to a mouse handler member a derived class uses */ @@ -106,7 +106,9 @@ protected: */ virtual void post_mouse_press(const SDL_Event& event); - virtual void show_menu(const std::vector& items_arg, int xloc, int yloc, bool context_menu) = 0; + virtual void show_menu(const std::vector& items_arg, int xloc, int yloc, bool context_menu); + + virtual bool in_context_menu(hotkey::HOTKEY_COMMAND command) const; const config& game_config_; const int ticks_;