virtual void DrawWidget(const Rect &r, int widget) const
{
switch (widget) {
case WID_AIC_GAMELIST: {
Dimension square = GetSpriteSize(SPR_SQUARE);
uint square_y_offset = (line_height - square.height) / 2;
Dimension warning = GetSpriteSize(SPR_WARNING_SIGN);
uint warning_y_offset = (line_height - warning.height) / 2;
uint widest_icon = max(square.width, warning.width);
uint square_x_offset = (widest_icon - square.width) / 2;
uint warning_x_offset = (widest_icon - warning.width) / 2;
Dimension rai = GetSpriteSize(SPR_RANDOM_AI);
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 = rtl ? cid_left + widest_cid : cid_left + widest_cid;
DrawSprite(SPR_SQUARE, IsEligible(OWNER_DEITY) ? PALETTE_TO_BLUE : IsDead(OWNER_DEITY) ? _game_mode == GM_NORMAL ? PALETTE_TO_GREY : PALETTE_TO_RED : PALETTE_TO_GREEN, icon_left + square_x_offset, r.top + square_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_width = GetStringBoundingBox(text).width;
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 : IsSelectable(OWNER_DEITY) ? TC_ORANGE : TC_SILVER);
break;
}
case WID_AIC_LIST: {
Dimension square = GetSpriteSize(SPR_SQUARE);
uint square_y_offset = (line_height - square.height) / 2;
Dimension warning = GetSpriteSize(SPR_WARNING_SIGN);
uint warning_y_offset = (line_height - warning.height) / 2;
uint widest_icon = max(square.width, warning.width);
uint square_x_offset = (widest_icon - square.width) / 2;
uint warning_x_offset = (widest_icon - warning.width) / 2;
Dimension rai = GetSpriteSize(SPR_RANDOM_AI);
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 = rtl ? cid_left + widest_cid : cid_left + widest_cid;
int y = r.top;
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
if (_game_mode == GM_NORMAL && Company::IsValidAiID(i) && IsDead((CompanyID)i)) {
DrawSprite(SPR_WARNING_SIGN, PAL_NONE, icon_left + warning_x_offset, y + warning_y_offset);
} else {
DrawSprite(SPR_SQUARE, IsEligible((CompanyID)i) ? _game_mode != GM_NORMAL ? PALETTE_TO_BLUE : PALETTE_TO_ORANGE : !IsDead((CompanyID)i) ? PALETTE_TO_GREEN : PALETTE_TO_GREY, icon_left + square_x_offset, y + square_y_offset);
}
if (_game_mode == GM_NORMAL && Company::IsValidAiID(i) && AIConfig::GetConfig((CompanyID)i)->IsRandom()) {
DrawSprite(SPR_RANDOM_AI, 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_width = GetStringBoundingBox(text).width;
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;
}
}
}