virtual void DrawWidget(const Rect &r, int widget) const { uint widest_icon = 0; static const SpriteID icons[] = { SPR_AICONFIG_DEAD, SPR_AICONFIG_ELIGIBLE, SPR_AICONFIG_ALIVE, SPR_AICONFIG_HUMAN, SPR_AICONFIG_RANDOM }; for (uint i = 0; i < lengthof(icons); i++) { widest_icon = max(widest_icon, GetSpriteSize(icons[i]).width); } uint dead_x_offset = (widest_icon - GetSpriteSize(SPR_AICONFIG_DEAD).width) / 2; uint eligible_x_offset = (widest_icon - GetSpriteSize(SPR_AICONFIG_ELIGIBLE).width) / 2; uint alive_x_offset = (widest_icon - GetSpriteSize(SPR_AICONFIG_ALIVE).width) / 2; uint human_x_offset = (widest_icon - GetSpriteSize(SPR_AICONFIG_HUMAN).width) / 2; uint dead_y_offset = (line_height - GetSpriteSize(SPR_AICONFIG_DEAD).height) / 2; uint eligible_y_offset = (line_height - GetSpriteSize(SPR_AICONFIG_ELIGIBLE).height) / 2; uint alive_y_offset = (line_height - GetSpriteSize(SPR_AICONFIG_ALIVE).height) / 2; uint human_y_offset = (line_height - GetSpriteSize(SPR_AICONFIG_HUMAN).height) / 2; Dimension rai = GetSpriteSize(SPR_AICONFIG_RANDOM); uint rai_y_offset = (line_height - rai.height) / 2; uint widest_cid = 0; for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { SetDParam(0, i + 1); widest_cid = max(GetStringBoundingBox(STR_JUST_INT).width, widest_cid); } bool rtl = _current_text_dir == TD_RTL; uint icon_left = rtl ? r.right - WD_MATRIX_RIGHT - widest_icon : r.left + WD_MATRIX_LEFT; uint rai_left = rtl ? icon_left - 1 - rai.width : icon_left + widest_icon + 1; uint cid_left = rtl ? rai_left - 10 - widest_cid : rai_left + rai.width + 10; uint cid_right = cid_left + widest_cid; switch (widget) { case WID_AIC_GAMELIST: { if (IsEligible(OWNER_DEITY)) { DrawSprite(SPR_AICONFIG_ELIGIBLE, PAL_NONE, icon_left + eligible_x_offset, r.top + eligible_y_offset); } else { if (Game::GetInstance() != NULL) { if (!IsConsideredDead(OWNER_DEITY)) { DrawSprite(SPR_AICONFIG_ALIVE, PAL_NONE, icon_left + alive_x_offset, r.top + alive_y_offset); } else { DrawSprite(SPR_AICONFIG_DEAD, PAL_NONE, icon_left + dead_x_offset, r.top + dead_y_offset); } } } StringID text = STR_AI_CONFIG_NONE; if (GameConfig::GetConfig()->GetInfo() != NULL) { SetDParamStr(0, GameConfig::GetConfig()->GetInfo()->GetName()); text = STR_JUST_RAW_STRING; } uint text_left = rtl ? r.left + WD_MATRIX_LEFT : cid_right + 10; uint text_right = rtl ? cid_left - 10 : r.right - WD_MATRIX_RIGHT; DrawString(text_left, text_right, r.top + WD_MATRIX_TOP, text, this->selected_slot == OWNER_DEITY ? TC_WHITE : TC_ORANGE); break; } case WID_AIC_LIST: { int y = r.top; for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { if (IsEligible((CompanyID)i)) { DrawSprite(SPR_AICONFIG_ELIGIBLE, PAL_NONE, icon_left + eligible_x_offset, y + eligible_y_offset); } else { if (Company::IsValidHumanID(i)) { DrawSprite(SPR_AICONFIG_HUMAN, PAL_NONE, icon_left + human_x_offset, y + human_y_offset); } else { if (Company::IsValidAiID(i)) { if (!IsConsideredDead((CompanyID)i)) { DrawSprite(SPR_AICONFIG_ALIVE, PAL_NONE, icon_left + alive_x_offset, y + alive_y_offset); } else { DrawSprite(SPR_AICONFIG_DEAD, PAL_NONE, icon_left + dead_x_offset, y + dead_y_offset); } } } } if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL && AIConfig::GetConfig((CompanyID)i)->IsRandom()) { DrawSprite(SPR_AICONFIG_RANDOM, PAL_NONE, rai_left, y + rai_y_offset); } SetDParam(0, i + 1); DrawString(cid_left, cid_right, y + WD_MATRIX_TOP, STR_JUST_INT, TC_LIGHT_BLUE); StringID text; if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) { SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName()); text = STR_JUST_RAW_STRING; } else { text = STR_AI_CONFIG_RANDOM_AI; } uint text_left = rtl ? r.left + WD_MATRIX_LEFT : cid_right + 10; uint text_right = rtl ? cid_left - 10 : r.right - WD_MATRIX_RIGHT; DrawString(text_left, text_right, y + WD_MATRIX_TOP, text, this->selected_slot == i ? TC_WHITE : TC_ORANGE); y += this->line_height; } break; } } }