/**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{
if (!IsSelectable(this->selected_slot)) {
this->selected_slot = INVALID_COMPANY;
}
if (!gui_scope) return;
this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES);
this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY || Company::IsValidAiID(this->selected_slot) || GetFreeSlot(this->selected_slot, -1) == INVALID_COMPANY);
this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY || Company::IsValidAiID(this->selected_slot) || GetFreeSlot(this->selected_slot, +1) == INVALID_COMPANY);
for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES; cid++) {
if (!Company::IsValidAiID(cid) && AIConfig::GetConfig(cid)->IsRandom()) {
AIConfig::GetConfig(cid)->Change(NULL);
DeleteWindowById(WC_AI_SETTINGS, cid);
DeleteWindowByClass(WC_TEXTFILE);
DeleteWindowByClass(WC_QUERY_STRING);
}
}
this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY && (_game_mode == GM_NORMAL || (_game_mode == GM_EDITOR && Game::GetInstance() != NULL)) || Company::IsValidAiID(this->selected_slot));
this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0 || _game_mode == GM_EDITOR && !IsConsideredDead(this->selected_slot));
/* Display either Settings or Configure button */
NWidgetCore *configure_button = this->GetWidget<NWidgetCore>(WID_AIC_CONFIGURE);
if (this->selected_slot != INVALID_COMPANY && !IsConsideredDead(this->selected_slot)) {
configure_button->SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP);
} else {
configure_button->SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP);
}
this->SetWidgetDisabledState(WID_AIC_START_STOP_TOGGLE, _game_mode != GM_NORMAL || this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY || Company::IsValidHumanID(this->selected_slot) || GetCurrentNoAIs() >= GetGameSettings().difficulty.max_no_competitors && !Company::IsValidID(this->selected_slot));
/* Display either Start AI or Stop AI button */
NWidgetCore *toggle_button = this->GetWidget<NWidgetCore>(WID_AIC_START_STOP_TOGGLE);
if (this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY || Company::IsValidHumanID(this->selected_slot) || !Company::IsValidAiID(this->selected_slot)) {
toggle_button->SetDataTip(STR_AI_CONFIG_START, STR_AI_CONFIG_START_TOOLTIP);
} else {
toggle_button->SetDataTip(STR_AI_CONFIG_STOP, STR_AI_CONFIG_STOP_TOOLTIP);
}
for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
}
}
};