diff -r 54aa6c047c7a src/ai/ai_gui.cpp --- a/src/ai/ai_gui.cpp Tue Jul 03 21:28:15 2012 +0200 +++ b/src/ai/ai_gui.cpp Tue Jul 03 22:19:52 2012 +0200 @@ -959,6 +959,23 @@ } /** + * Set the widget colour of a button based on the + * state of the script. (dead or alive) + * @param button the button to update + * @param dead true if the script is dead, otherwise false + * @return true if the colour was changed and the window need to be marked as dirty + */ +bool SetScriptButtonColour(NWidgetCore &button, bool dead) +{ + Colours colour = dead ? COLOUR_RED : COLOUR_GREY; + if (button.colour != colour) { + button.colour = colour; + return true; + } + return false; +} + +/** * Window with everything an AI prints via ScriptLog. */ struct AIDebugWindow : public QueryStringBaseWindow { @@ -1084,11 +1101,10 @@ dirty = true; } + /* Mark dead AIs by red background */ 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; + if (SetScriptButtonColour(*button, dead)) { + /* re-paint if the button was updated */ dirty = true; } @@ -1101,6 +1117,15 @@ DrawCompanyIcon(i, button->pos_x + button->current_x / 2 - 7 + offset, this->GetWidget(WID_AID_COMPANY_BUTTON_START + i)->pos_y + 2 + offset); } + /* Set button colour for Game Script */ + GameInstance *game = Game::GetInstance(); + bool dead = game != NULL && game->IsDead(); + NWidgetCore *button = this->GetWidget(WID_AID_SCRIPT_GAME); + if (SetScriptButtonColour(*button, dead)) { + /* re-paint if the button was updated */ + this->SetDirty(); + } + /* If there are no active companies, don't display anything else. */ if (ai_debug_company == INVALID_COMPANY) return;