From 9fd38d1022fc5e7586ebcc4c83f61382889f3a0e Mon Sep 17 00:00:00 2001 From: Yexo Date: Wed, 21 Jan 2009 00:36:22 +0000 Subject: (svn r15186) -Fix: Select the currently selected AI instead of the second on in the list. -Feature: Double clicking on a slot in the AI config window results in opening the list of AIs. --- src/ai/ai_gui.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 01fd4699c..b2e1b4be5 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -58,7 +58,6 @@ struct AIListWindow : public Window { CompanyID slot; AIListWindow(const WindowDesc *desc, CompanyID slot) : Window(desc, 0), - selected(0), slot(slot) { this->ai_info_list = AI::GetUniqueInfoList(); @@ -66,6 +65,20 @@ struct AIListWindow : public Window { this->vscroll.cap = (this->widget[AIL_WIDGET_LIST].bottom - this->widget[AIL_WIDGET_LIST].top) / 14 + 1; this->widget[AIL_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1; SetVScrollCount(this, this->ai_info_list->size() + 1); + + /* Try if we can find the currently selected AI */ + this->selected = -1; + if (AIConfig::GetConfig(slot)->HasAI()) { + AIInfo *info = AIConfig::GetConfig(slot)->GetInfo(); + int i = 0; + for (AIInfoList::const_iterator it = this->ai_info_list->begin(); it != this->ai_info_list->end(); it++, i++) { + if ((*it).second == info) { + this->selected = i; + break; + } + } + } + this->FindWindowPlacementAndResize(desc); } @@ -497,6 +510,16 @@ struct AIConfigWindow : public Window { } } + virtual void OnDoubleClick(Point pt, int widget) + { + switch (widget) { + case AIC_WIDGET_LIST: + this->OnClick(pt, widget); + if (this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot); + break; + } + } + virtual void OnResize(Point new_size, Point delta) { this->vscroll.cap += delta.y / 14; -- cgit v1.2.3-70-g09d2