--- src/ai/ai_gui.cpp +++ src/ai/ai_gui.cpp @@ -757,36 +787,76 @@ virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { switch (widget) { - case WID_AIC_GAMELIST: - this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM; + case WID_AIC_GAMELIST: { + uint highest_icon = 0; + static const SpriteID icons[] = {SPR_AICONFIG_DEAD, SPR_AICONFIG_ELIGIBLE, SPR_AICONFIG_ALIVE}; + for (int i = 0; i < lengthof(icons); i++) { + highest_icon = max(highest_icon, GetSpriteSize(icons[i]).height); + } + this->line_height = max((uint)FONT_HEIGHT_NORMAL, highest_icon) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM; size->height = 1 * this->line_height; break; + } - case WID_AIC_LIST: - this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM; - size->height = 8 * this->line_height; + case WID_AIC_LIST: { + uint highest_icon = 0; + static const SpriteID icons[] = {SPR_AICONFIG_DEAD, SPR_AICONFIG_ELIGIBLE, SPR_AICONFIG_ALIVE, SPR_AICONFIG_HUMAN, SPR_AICONFIG_RANDOM}; + for (int i = 0; i < lengthof(icons); i++) { + highest_icon = max(highest_icon, GetSpriteSize(icons[i]).height); + } + this->line_height = max((uint)FONT_HEIGHT_NORMAL, highest_icon) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM; + size->height = 15 * this->line_height; break; + } + + case WID_AIC_CHANGE: { + uint change_width = 0; + static const StringID params[] = {STR_AI_CONFIG_GAMESCRIPT, STR_AI_CONFIG_NONE, STR_AI_CONFIG_AI}; + for (int i = 0; i < lengthof(params); i++) { + SetDParam(0, params[i]); + change_width = max(change_width, GetStringBoundingBox(STR_AI_CONFIG_CHANGE).width); + } + size->width = change_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; + break; + } + + case WID_AIC_CONFIGURE: { + size->width = max(GetStringBoundingBox(STR_AI_CONFIG_CONFIGURE).width, GetStringBoundingBox(STR_AI_DEBUG_SETTINGS).width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; + break; + } } } /** - * Can the AI config in the given company slot be edited? + * Can the AI or GS config in the given slot be selected? * @param slot The slot to query. - * @return True if and only if the given AI Config slot can e edited. + * @return True if and only if the given AI or GS Config of this slot can be selected. */ - static bool IsEditable(CompanyID slot) + static bool IsSelectable(CompanyID slot) { - if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != NULL; + return slot >= COMPANY_FIRST && slot < MAX_COMPANIES || slot == OWNER_DEITY; + } - if (_game_mode != GM_NORMAL) { - return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors; - } + /** + * Is the AI or GS config in the given slot eligible to start? + * @param slot The slot to query. + * @return True if and only if the given AI or GS Config of this slot can start. + */ + static bool IsEligible(CompanyID slot) + { + if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL && GameConfig::GetConfig()->GetInfo() != NULL && (Game::GetInstance() == NULL || _game_mode == GM_MENU); + if (Company::IsValidID(slot) || slot < 0) return false; - int max_slot = GetGameSettings().difficulty.max_no_competitors; - for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) { - if (Company::IsValidHumanID(cid)) max_slot++; + int current_no_ais = 0; + for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES; cid++) { + if (Company::IsValidAiID(cid)) current_no_ais++; } + int empty_slots = 0; + CompanyID max_slot; + for (max_slot = COMPANY_FIRST; max_slot < MAX_COMPANIES && GetGameSettings().difficulty.max_no_competitors - current_no_ais > empty_slots; max_slot++) { + if (!Company::IsValidID(max_slot)) empty_slots++; + } return slot < max_slot; }