changeset 13906:076f80f5a2f4 draft

(svn r18437) -Fix (r16557): background of disabled button in AI GUI wasn't set back to grey after AI bankrupt
author smatz <smatz@openttd.org>
date Wed, 09 Dec 2009 00:08:13 +0000
parents eb3e25c07db1
children df279b977e38
files src/ai/ai_gui.cpp
diffstat 1 files changed, 18 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -731,35 +731,29 @@
 
 		/* Paint the company icons */
 		for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
-			/* Background is grey by default, will be changed to red for dead AIs */
-			this->GetWidget<NWidgetCore>(i + AID_WIDGET_COMPANY_BUTTON_START)->colour = COLOUR_GREY;
+			NWidgetCore *button = this->GetWidget<NWidgetCore>(i + AID_WIDGET_COMPANY_BUTTON_START);
+			bool dirty = false;
 
-			const Company *c = Company::GetIfValid(i);
-			if (c == NULL || !c->is_ai) {
-				/* Check if we have the company as an active company */
-				if (!this->IsWidgetDisabled(i + AID_WIDGET_COMPANY_BUTTON_START)) {
-					/* Bah, company gone :( */
-					this->DisableWidget(i + AID_WIDGET_COMPANY_BUTTON_START);
-
-					/* We need a repaint */
-					this->SetDirty();
-				}
-				continue;
+			bool valid = Company::IsValidAiID(i);
+			bool disabled = !valid;
+			if (button->IsDisabled() != disabled) {
+				/* Invalid/non-AI companies have button disabled */
+				button->SetDisabled(disabled);
+				dirty = true;
 			}
 
-			/* Mark dead AIs by red background */
-			if (c->ai_instance->IsDead()) {
-				this->GetWidget<NWidgetCore>(i + AID_WIDGET_COMPANY_BUTTON_START)->colour = COLOUR_RED;
+			bool dead = valid && Company::Get(i)->ai_instance->IsDead();
+			Colours colour = dead ? COLOUR_RED : COLOUR_GREY;
+			if (button->colour != colour) {
+				/* Mark dead AIs by red background */
+				button->colour = colour;
+				dirty = true;
 			}
 
-			/* Check if we have the company marked as inactive */
-			if (this->IsWidgetDisabled(i + AID_WIDGET_COMPANY_BUTTON_START)) {
-				/* New AI! Yippie :p */
-				this->EnableWidget(i + AID_WIDGET_COMPANY_BUTTON_START);
-
-				/* We need a repaint */
-				this->SetDirty();
-			}
+			/* Do we need a repaint? */
+			if (dirty) this->SetDirty();
+			/* Draw company icon only for valid AI companies */
+			if (!valid) continue;
 
 			byte offset = (i == ai_debug_company) ? 1 : 0;
 			DrawCompanyIcon(i, this->GetWidget<NWidgetBase>(AID_WIDGET_COMPANY_BUTTON_START + i)->pos_x + 11 + offset, this->GetWidget<NWidgetBase>(AID_WIDGET_COMPANY_BUTTON_START + i)->pos_y + 2 + offset);