diff options
author | smatz <smatz@openttd.org> | 2009-12-09 00:08:13 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-12-09 00:08:13 +0000 |
commit | 784d6d836d5d879faa95ce3cbe7bdc2f1d4c072b (patch) | |
tree | b072d78367737745995f075bda57f5926855d111 /src/ai | |
parent | 7d33e62d7bda071f4cc5c713c8a1b802e6915778 (diff) | |
download | openttd-784d6d836d5d879faa95ce3cbe7bdc2f1d4c072b.tar.xz |
(svn r18437) -Fix (r16557): background of disabled button in AI GUI wasn't set back to grey after AI bankrupt
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/ai_gui.cpp | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index bf65e62cf..8e90972ff 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -731,35 +731,29 @@ struct AIDebugWindow : public Window { /* 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; - - 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; + NWidgetCore *button = this->GetWidget<NWidgetCore>(i + AID_WIDGET_COMPANY_BUTTON_START); + bool dirty = false; + + 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); |