diff --git a/gui/tool_selector.cc b/gui/tool_selector.cc index 8de605092..119db8724 100644 --- a/gui/tool_selector.cc +++ b/gui/tool_selector.cc @@ -20,11 +20,12 @@ #define MIN_WIDTH (80) -tool_selector_t::tool_selector_t(const char* title, const char *help_file, uint32 toolbar_id, bool allow_break) : +tool_selector_t::tool_selector_t(const char* title, const char *help_file, uint32 toolbar_id, toolbar_t* toolbar, bool allow_break) : gui_frame_t( translator::translate(title) ), tools(0) { set_table_layout(0,0); // we do our own positioning of icons (for now) this->toolbar_id = toolbar_id; + this->toolbar = toolbar; this->allow_break = allow_break; this->help_file = help_file; this->tool_icon_disp_start = 0; @@ -115,19 +116,24 @@ bool tool_selector_t::infowin_event(const event_t *ev) if (wz_idx < (int)tools.get_count()) { // change tool tool_t *tool = tools[wz_idx].tool; - if(IS_LEFTRELEASE(ev)) { - welt->set_tool( tool, welt->get_active_player() ); - } - else { - // right-click on toolbar icon closes toolbars and dialogues. Resets selectable simple and general tools to the query-tool - if (tool && tool->is_selected() ) { - // ->exit triggers tool_selector_t::infowin_event in the closing toolbar, - // which resets active tool to query tool - if( tool->exit(welt->get_active_player()) ) { - welt->set_tool( tool_t::general_tool[TOOL_QUERY], welt->get_active_player() ); - } + // right-click on toolbar icon closes toolbars and dialogues. Resets selectable simple and general tools to the query-tool + if (!IS_LEFTRELEASE(ev) && tool && tool->is_selected() ) { + // ->exit triggers tool_selector_t::infowin_event in the closing toolbar, + // which resets active tool to query tool + if( tool->exit(welt->get_active_player()) ) { + welt->set_tool( tool_t::general_tool[TOOL_QUERY], welt->get_active_player() ); + toolbar->remove_child(tool); } + return true; + } + + if(!IS_LEFTRELEASE(ev)) { + // close all tools launched by this toolbar + toolbar->destroy_children(welt->get_active_player()); } + // open the selected tool + welt->set_tool( tool, welt->get_active_player() ); + toolbar->append_child(tool); } return true; } diff --git a/gui/tool_selector.h b/gui/tool_selector.h index d6b297c2b..f46d073b1 100644 --- a/gui/tool_selector.h +++ b/gui/tool_selector.h @@ -13,7 +13,7 @@ #include "../dataobj/environment.h" class tool_t; - +class toolbar_t; /** * This class defines all toolbar dialogues, floating bar of tools, i.e. the part the user will see @@ -31,6 +31,8 @@ private: // get current toolbar number for saving uint32 toolbar_id; + + toolbar_t* toolbar; /** * window width in toolboxes @@ -59,7 +61,7 @@ private: bool allow_break; public: - tool_selector_t(const char *title, const char *help_file, uint32 toolbar_id, bool allow_break=true ); + tool_selector_t(const char *title, const char *help_file, uint32 toolbar_id, toolbar_t* toolbar, bool allow_break=true ); /** * Add a new tool with values and tooltip text. diff --git a/simmenu.cc b/simmenu.cc index 9e43aee99..54f3f44d1 100644 --- a/simmenu.cc +++ b/simmenu.cc @@ -840,7 +840,7 @@ void toolbar_t::update(player_t *player) const bool create = (tool_selector == NULL); if(create) { DBG_MESSAGE("toolbar_t::update()","create toolbar %s",default_param); - tool_selector = new tool_selector_t( default_param, helpfile, toolbar_tool.index_of(this), this!=tool_t::toolbar_tool[0] ); + tool_selector = new tool_selector_t( default_param, helpfile, toolbar_tool.index_of(this), this, this!=tool_t::toolbar_tool[0] ); } else { DBG_MESSAGE("toolbar_t::update()","update toolbar %s",default_param); @@ -952,6 +952,17 @@ bool toolbar_t::exit(player_t *) } +void toolbar_t::destroy_children(player_t* player) { + FOR(slist_tpl, const i, children) { + toolbar_t* tb = dynamic_cast(i); + if( tb ) { + tb->destroy_children(player); + } + i->exit(player); + } +} + + // from here on last used toolbar tools (for each player!) void toolbar_last_used_t::update(player_t *sp) { diff --git a/simmenu.h b/simmenu.h index 88964c8b5..afe551544 100644 --- a/simmenu.h +++ b/simmenu.h @@ -430,6 +430,7 @@ protected: const char *helpfile; tool_selector_t *tool_selector; slist_tpltools; + slist_tplchildren; public: toolbar_t(uint16 const id, char const* const t, char const* const h) : tool_t(id) { @@ -449,6 +450,9 @@ public: bool exit(player_t*) OVERRIDE; virtual void update(player_t *); // just refresh content void append(tool_t *tool) { tools.append(tool); } + void append_child(tool_t *tool) { children.append(tool); } + void remove_child(tool_t* tool) { children.remove(tool); } + void destroy_children(player_t*); }; #define MAX_LAST_TOOLS (10)