changeset 13905:eb3e25c07db1 draft

(svn r18436) -Fix [FS#3357]: unselect an AI in the AI Settings window when it falls out of the range of active AIs
author rubidium <rubidium@openttd.org>
date Tue, 08 Dec 2009 23:32:32 +0000
parents 480eaf76e5ce
children 076f80f5a2f4
files src/ai/ai_gui.cpp
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -594,10 +594,7 @@
 			}
 
 			case AIC_WIDGET_LIST: { // Select a slot
-				uint slot = (pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y) / this->line_height + this->vscroll.GetPosition();
-
-				if (slot == 0 || slot > _settings_newgame.difficulty.max_no_competitors) slot = INVALID_COMPANY;
-				this->selected_slot = (CompanyID)slot;
+				this->selected_slot = (CompanyID)((pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y) / this->line_height + this->vscroll.GetPosition());
 				this->InvalidateData();
 				break;
 			}
@@ -628,6 +625,10 @@
 
 	virtual void OnInvalidateData(int data)
 	{
+		if (this->selected_slot == 0 || this->selected_slot > _settings_newgame.difficulty.max_no_competitors) {
+			this->selected_slot = INVALID_COMPANY;
+		}
+
 		this->SetWidgetDisabledState(AIC_WIDGET_DECREASE, _settings_newgame.difficulty.max_no_competitors == 0);
 		this->SetWidgetDisabledState(AIC_WIDGET_INCREASE, _settings_newgame.difficulty.max_no_competitors == MAX_COMPANIES - 1);
 		this->SetWidgetDisabledState(AIC_WIDGET_CHANGE, this->selected_slot == INVALID_COMPANY);