Codechange: use std::string instead of stredup/free for stories

This commit is contained in:
Rubidium
2023-04-27 19:21:06 +02:00
committed by rubidium42
parent 3342967ad9
commit aac95eeaf5
4 changed files with 30 additions and 40 deletions

View File

@@ -60,7 +60,7 @@ protected:
GUIStoryPageList story_pages; ///< Sorted list of pages.
GUIStoryPageElementList story_page_elements; ///< Sorted list of page elements that belong to the current page.
StoryPageID selected_page_id; ///< Pool index of selected page.
char selected_generic_title[255]; ///< If the selected page doesn't have a custom title, this buffer is used to store a generic page title.
std::string selected_generic_title; ///< If the selected page doesn't have a custom title, this buffer is used to store a generic page title.
StoryPageElementID active_button_id; ///< Which button element the player is currently using
@@ -188,9 +188,9 @@ protected:
{
/* Generate generic title if selected page have no custom title. */
StoryPage *page = this->GetSelPage();
if (page != nullptr && page->title == nullptr) {
if (page != nullptr && page->title.empty()) {
SetDParam(0, GetSelPageNum() + 1);
GetString(selected_generic_title, STR_STORY_BOOK_GENERIC_PAGE_ITEM, lastof(selected_generic_title));
selected_generic_title = GetString(STR_STORY_BOOK_GENERIC_PAGE_ITEM);
}
this->story_page_elements.ForceRebuild();
@@ -255,7 +255,7 @@ protected:
for (const StoryPage *p : this->story_pages) {
bool current_page = p->index == this->selected_page_id;
DropDownListStringItem *item = nullptr;
if (p->title != nullptr) {
if (!p->title.empty()) {
item = new DropDownListCharStringItem(p->title, p->index, current_page);
} else {
/* No custom title => use a generic page title with page number. */
@@ -295,7 +295,7 @@ protected:
/* Title lines */
height += FONT_HEIGHT_NORMAL; // Date always use exactly one line.
SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title);
SetDParamStr(0, !page->title.empty() ? page->title : this->selected_generic_title);
height += GetStringHeight(STR_STORY_BOOK_TITLE, max_width);
return height;
@@ -616,7 +616,7 @@ public:
this->owner = (Owner)this->window_number;
/* Initialize selected vars. */
this->selected_generic_title[0] = '\0';
this->selected_generic_title.clear();
this->selected_page_id = INVALID_STORY_PAGE;
this->active_button_id = INVALID_STORY_PAGE_ELEMENT;
@@ -655,7 +655,7 @@ public:
switch (widget) {
case WID_SB_SEL_PAGE: {
StoryPage *page = this->GetSelPage();
SetDParamStr(0, page != nullptr && page->title != nullptr ? page->title : this->selected_generic_title);
SetDParamStr(0, page != nullptr && !page->title.empty() ? page->title : this->selected_generic_title);
break;
}
case WID_SB_CAPTION:
@@ -713,7 +713,7 @@ public:
y_offset += line_height;
/* Title */
SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title);
SetDParamStr(0, !page->title.empty() ? page->title : this->selected_generic_title);
y_offset = DrawStringMultiLine(0, fr.right, y_offset, fr.bottom, STR_STORY_BOOK_TITLE, TC_BLACK, SA_TOP | SA_HOR_CENTER);
/* Page elements */
@@ -773,7 +773,7 @@ public:
for (size_t i = 0; i < this->story_pages.size(); i++) {
const StoryPage *s = this->story_pages[i];
if (s->title != nullptr) {
if (!s->title.empty()) {
SetDParamStr(0, s->title);
} else {
SetDParamStr(0, this->selected_generic_title);
@@ -877,7 +877,7 @@ public:
/* Was the last page removed? */
if (this->story_pages.size() == 0) {
this->selected_generic_title[0] = '\0';
this->selected_generic_title.clear();
}
/* Verify page selection. */