virtual void OnClick(Point pt, int widget, int click_count)
{
if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) {
if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == NULL) return;
ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
return;
}
switch (widget) {
case WID_AIC_DECREASE:
case WID_AIC_INCREASE: {
int new_value;
if (widget == WID_AIC_DECREASE) {
new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
} else {
new_value = min(MAX_COMPANIES, GetGameSettings().difficulty.max_no_competitors + 1);
}
IConsoleSetSetting("difficulty.max_no_competitors", new_value);
this->InvalidateData();
break;
}
case WID_AIC_GAMELIST: {
this->selected_slot = OWNER_DEITY;
this->InvalidateData();
if (click_count > 1 && this->selected_slot != INVALID_COMPANY && _game_mode != GM_NORMAL) ShowAIListWindow((CompanyID)this->selected_slot);
break;
}
case WID_AIC_LIST: { // Select a slot
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
this->InvalidateData();
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
break;
}
case WID_AIC_MOVE_UP: {
bool is_orange_slot = IsEditable((CompanyID)(this->selected_slot)) && !Company::IsValidID(this->selected_slot);
bool is_red_slot = IsEditable((CompanyID)(this->selected_slot)) && Company::IsValidID(this->selected_slot) && Company::IsValidAiID(this->selected_slot) && Company::Get(this->selected_slot)->ai_instance->IsDead();
bool is_orange_slot_above = IsEditable((CompanyID)(this->selected_slot - 1)) && !Company::IsValidID(this->selected_slot - 1);
bool is_orange_slot_below = IsEditable((CompanyID)(this->selected_slot + 1)) && !Company::IsValidID(this->selected_slot + 1);
bool is_red_slot_above = IsEditable((CompanyID)(this->selected_slot - 1)) && Company::IsValidID(this->selected_slot - 1) && Company::IsValidAiID(this->selected_slot - 1) && Company::Get(this->selected_slot - 1)->ai_instance->IsDead();
bool is_red_slot_below = IsEditable((CompanyID)(this->selected_slot + 1)) && Company::IsValidID(this->selected_slot + 1) && Company::IsValidAiID(this->selected_slot + 1) && Company::Get(this->selected_slot + 1)->ai_instance->IsDead();
if ((is_orange_slot || is_red_slot) && (is_orange_slot_above || is_red_slot_above)) {
Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
this->selected_slot--;
this->vscroll->ScrollTowards(this->selected_slot);
this->InvalidateData();
}
break;
case WID_AIC_MOVE_DOWN:
if ((is_orange_slot || is_red_slot) && (is_orange_slot_below || is_red_slot_below)) {
Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
this->selected_slot++;
this->vscroll->ScrollTowards(this->selected_slot);
this->InvalidateData();
}
break;
}
case WID_AIC_CHANGE: // choose other AI
ShowAIListWindow((CompanyID)this->selected_slot);
break;
case WID_AIC_CONFIGURE: // change the settings for an AI
ShowAISettingsWindow((CompanyID)this->selected_slot);
break;
case WID_AIC_CLOSE:
delete this;
break;
case WID_AIC_CONTENT_DOWNLOAD:
if (!_network_available) {
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
} else {
#if defined(ENABLE_NETWORK)
ShowNetworkContentListWindow(NULL, CONTENT_TYPE_AI, CONTENT_TYPE_GAME);
#endif
}
break;
}
}