move some more functions up to controller_base

This commit is contained in:
Tomasz Śniatowski 2008-07-06 15:49:19 +01:00
parent ccbfa8acf1
commit 1855ca47fc
2 changed files with 26 additions and 2 deletions

View file

@ -179,3 +179,25 @@ void controller_base::slice_end()
//no action by default
}
void controller_base::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu)
{
std::vector<std::string> items = items_arg;
hotkey::HOTKEY_COMMAND command;
std::vector<std::string>::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;
}

View file

@ -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<std::string>& items_arg, int xloc, int yloc, bool context_menu) = 0;
virtual void show_menu(const std::vector<std::string>& 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_;