Skip to content

Instantly share code, notes, and snippets.

@SamuXarick
Created March 2, 2023 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamuXarick/57b79067c5635d894c02f5aebc0fe5bb to your computer and use it in GitHub Desktop.
Save SamuXarick/57b79067c5635d894c02f5aebc0fe5bb to your computer and use it in GitHub Desktop.
case WID_SCRL_LIST: {
/* Draw a list of all available Scripts. */
Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
Dimension rai = GetSpriteSize(SPR_AICONFIG_RANDOM);
bool rtl = _current_text_dir == TD_RTL;
Rect rai_rect = tr.WithWidth(rai.width, rtl);
Rect text_rect = tr.Indent(rai.width + WidgetDimensions::scaled.hsep_normal, rtl);
/* First AI in the list is hardcoded to random */
if (this->vscroll->IsVisible(0)) {
StringID text = STR_AI_CONFIG_RANDOM_AI;
if (this->slot == OWNER_DEITY) text = STR_AI_CONFIG_NONE;
DrawString(text_rect.left, text_rect.right, tr.top, text, this->selected == -1 ? TC_WHITE : TC_ORANGE);
tr.top += this->line_height;
}
int i = 0;
for (const auto &item : *this->info_list) {
i++;
if (this->vscroll->IsVisible(i)) {
SetDParamStr(0, item.second->GetName());
if (this->slot != OWNER_DEITY && static_cast<AIInfo *>(item.second)->UseAsRandomAI()) {
DrawSprite(SPR_AICONFIG_RANDOM, PAL_NONE, rai_rect.left, tr.top);
}
DrawString(text_rect.left, text_rect.right, tr.top, item.second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
tr.top += this->line_height;
}
}
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment