Codechange: Make DropDownListStringItem preformat and remove other implementations. (#11063)
Having to choose between DropDownListStringItem, DropDownListCharStringItem, and DropDownListParamStringItem depending on whether to draw a StringID, a raw string, or a StringID with extra parameters was needlessly complex. Instead, allow passing a StringID or raw string to DropDownListStringItem. This will preformat the StringID into a raw string, and can therefore accept parameters via the normal SetDParam mechanism. This also means that strings no longer need to be formatted on every draw.
This commit is contained in:
@@ -252,18 +252,13 @@ protected:
|
||||
uint16 page_num = 1;
|
||||
for (const StoryPage *p : this->story_pages) {
|
||||
bool current_page = p->index == this->selected_page_id;
|
||||
DropDownListStringItem *item = nullptr;
|
||||
if (!p->title.empty()) {
|
||||
item = new DropDownListCharStringItem(p->title, p->index, current_page);
|
||||
list.emplace_back(new DropDownListStringItem(p->title, p->index, current_page));
|
||||
} else {
|
||||
/* No custom title => use a generic page title with page number. */
|
||||
DropDownListParamStringItem *str_item =
|
||||
new DropDownListParamStringItem(STR_STORY_BOOK_GENERIC_PAGE_ITEM, p->index, current_page);
|
||||
str_item->SetParam(0, page_num);
|
||||
item = str_item;
|
||||
SetDParam(0, page_num);
|
||||
list.emplace_back(new DropDownListStringItem(STR_STORY_BOOK_GENERIC_PAGE_ITEM, p->index, current_page));
|
||||
}
|
||||
|
||||
list.emplace_back(item);
|
||||
page_num++;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user