Update to 1.10.0-beta1

This commit is contained in:
dP
2019-10-31 22:24:28 +03:00
parent b84a475e14
commit 599ccf0c2b
1470 changed files with 354219 additions and 16795 deletions

View File

@@ -52,16 +52,16 @@ protected:
void BuildStoryPageList()
{
if (this->story_pages.NeedRebuild()) {
this->story_pages.Clear();
this->story_pages.clear();
const StoryPage *p;
FOR_ALL_STORY_PAGES(p) {
if (this->IsPageAvailable(p)) {
*this->story_pages.Append() = p;
this->story_pages.push_back(p);
}
}
this->story_pages.Compact();
this->story_pages.shrink_to_fit();
this->story_pages.RebuildDone();
}
@@ -69,28 +69,28 @@ protected:
}
/** Sort story pages by order value. */
static int CDECL PageOrderSorter(const StoryPage * const *a, const StoryPage * const *b)
static bool PageOrderSorter(const StoryPage * const &a, const StoryPage * const &b)
{
return (*a)->sort_value - (*b)->sort_value;
return a->sort_value < b->sort_value;
}
/** (Re)Build story page element list. */
void BuildStoryPageElementList()
{
if (this->story_page_elements.NeedRebuild()) {
this->story_page_elements.Clear();
this->story_page_elements.clear();
const StoryPage *p = GetSelPage();
if (p != NULL) {
if (p != nullptr) {
const StoryPageElement *pe;
FOR_ALL_STORY_PAGE_ELEMENTS(pe) {
if (pe->page == p->index) {
*this->story_page_elements.Append() = pe;
this->story_page_elements.push_back(pe);
}
}
}
this->story_page_elements.Compact();
this->story_page_elements.shrink_to_fit();
this->story_page_elements.RebuildDone();
}
@@ -98,9 +98,9 @@ protected:
}
/** Sort story page elements by order value. */
static int CDECL PageElementOrderSorter(const StoryPageElement * const *a, const StoryPageElement * const *b)
static bool PageElementOrderSorter(const StoryPageElement * const &a, const StoryPageElement * const &b)
{
return (*a)->sort_value - (*b)->sort_value;
return a->sort_value < b->sort_value;
}
/*
@@ -115,11 +115,11 @@ protected:
/**
* Get instance of selected page.
* @return Instance of selected page or NULL if no page is selected.
* @return Instance of selected page or nullptr if no page is selected.
*/
StoryPage *GetSelPage() const
{
if (!_story_page_pool.IsValidID(selected_page_id)) return NULL;
if (!_story_page_pool.IsValidID(selected_page_id)) return nullptr;
return _story_page_pool.Get(selected_page_id);
}
@@ -130,8 +130,7 @@ protected:
int GetSelPageNum() const
{
int page_number = 0;
for (const StoryPage *const*iter = this->story_pages.Begin(); iter != this->story_pages.End(); iter++) {
const StoryPage *p = *iter;
for (const StoryPage *p : this->story_pages) {
if (p->index == this->selected_page_id) {
return page_number;
}
@@ -148,7 +147,7 @@ protected:
/* Verify that the selected page exist. */
if (!_story_page_pool.IsValidID(this->selected_page_id)) return false;
return (*this->story_pages.Begin())->index == this->selected_page_id;
return this->story_pages.front()->index == this->selected_page_id;
}
/**
@@ -159,8 +158,8 @@ protected:
/* Verify that the selected page exist. */
if (!_story_page_pool.IsValidID(this->selected_page_id)) return false;
if (this->story_pages.Length() <= 1) return true;
const StoryPage *last = *(this->story_pages.End() - 1);
if (this->story_pages.size() <= 1) return true;
const StoryPage *last = this->story_pages.back();
return last->index == this->selected_page_id;
}
@@ -171,7 +170,7 @@ protected:
{
/* Generate generic title if selected page have no custom title. */
StoryPage *page = this->GetSelPage();
if (page != NULL && page->title == NULL) {
if (page != nullptr && page->title == nullptr) {
SetDParam(0, GetSelPageNum() + 1);
GetString(selected_generic_title, STR_STORY_BOOK_GENERIC_PAGE_ITEM, lastof(selected_generic_title));
}
@@ -194,11 +193,10 @@ protected:
/* Find the last available page which is previous to the current selected page. */
const StoryPage *last_available;
last_available = NULL;
for (const StoryPage *const*iter = this->story_pages.Begin(); iter != this->story_pages.End(); iter++) {
const StoryPage *p = *iter;
last_available = nullptr;
for (const StoryPage *p : this->story_pages) {
if (p->index == this->selected_page_id) {
if (last_available == NULL) return; // No previous page available.
if (last_available == nullptr) return; // No previous page available.
this->SetSelectedPage(last_available->index);
return;
}
@@ -214,12 +212,12 @@ protected:
if (!_story_page_pool.IsValidID(this->selected_page_id)) return;
/* Find selected page. */
for (const StoryPage *const*iter = this->story_pages.Begin(); iter != this->story_pages.End(); iter++) {
for (auto iter = this->story_pages.begin(); iter != this->story_pages.end(); iter++) {
const StoryPage *p = *iter;
if (p->index == this->selected_page_id) {
/* Select the page after selected page. */
iter++;
if (iter != this->story_pages.End()) {
if (iter != this->story_pages.end()) {
this->SetSelectedPage((*iter)->index);
}
return;
@@ -230,15 +228,14 @@ protected:
/**
* Builds the page selector drop down list.
*/
DropDownList *BuildDropDownList() const
DropDownList BuildDropDownList() const
{
DropDownList *list = new DropDownList();
DropDownList list;
uint16 page_num = 1;
for (const StoryPage *const*iter = this->story_pages.Begin(); iter != this->story_pages.End(); iter++) {
const StoryPage *p = *iter;
for (const StoryPage *p : this->story_pages) {
bool current_page = p->index == this->selected_page_id;
DropDownListStringItem *item = NULL;
if (p->title != NULL) {
DropDownListStringItem *item = nullptr;
if (p->title != nullptr) {
item = new DropDownListCharStringItem(p->title, p->index, current_page);
} else {
/* No custom title => use a generic page title with page number. */
@@ -248,16 +245,10 @@ protected:
item = str_item;
}
*list->Append() = item;
list.emplace_back(item);
page_num++;
}
/* Check if list is empty. */
if (list->Length() == 0) {
delete list;
list = NULL;
}
return list;
}
@@ -272,19 +263,19 @@ protected:
/**
* Counts how many pixels of height that are used by Date and Title
* (excluding marginal after Title, as each body element has
* an empty row before the elment).
* an empty row before the element).
* @param max_width Available width to display content.
* @return the height in pixels.
*/
uint GetHeadHeight(int max_width) const
{
StoryPage *page = this->GetSelPage();
if (page == NULL) return 0;
if (page == nullptr) return 0;
int height = 0;
/* Title lines */
height += FONT_HEIGHT_NORMAL; // Date always use exactly one line.
SetDParamStr(0, page->title != NULL ? page->title : this->selected_generic_title);
SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title);
height += GetStringHeight(STR_STORY_BOOK_TITLE, max_width);
return height;
@@ -301,7 +292,7 @@ protected:
switch (pe.type) {
case SPET_GOAL: {
Goal *g = Goal::Get((GoalID) pe.referenced_id);
if (g == NULL) return SPR_IMG_GOAL_BROKEN_REF;
if (g == nullptr) return SPR_IMG_GOAL_BROKEN_REF;
return g->completed ? SPR_IMG_GOAL_COMPLETED : SPR_IMG_GOAL;
}
case SPET_LOCATION:
@@ -345,7 +336,7 @@ protected:
uint GetContentHeight()
{
StoryPage *page = this->GetSelPage();
if (page == NULL) return 0;
if (page == nullptr) return 0;
int max_width = GetAvailablePageContentWidth();
uint element_vertical_dist = FONT_HEIGHT_NORMAL;
@@ -353,8 +344,7 @@ protected:
uint height = GetHeadHeight(max_width);
/* Body */
for (const StoryPageElement **iter = this->story_page_elements.Begin(); iter != this->story_page_elements.End(); iter++) {
const StoryPageElement *pe = *iter;
for (const StoryPageElement *pe : this->story_page_elements) {
height += element_vertical_dist;
height += GetPageElementHeight(*pe, max_width);
}
@@ -422,7 +412,7 @@ public:
this->vscroll = this->GetScrollbar(WID_SB_SCROLLBAR);
this->vscroll->SetStepSize(FONT_HEIGHT_NORMAL);
/* Initalize page sort. */
/* Initialize page sort. */
this->story_pages.SetSortFuncs(StoryBookWindow::page_sorter_funcs);
this->story_pages.ForceRebuild();
this->BuildStoryPageList();
@@ -444,8 +434,8 @@ public:
*/
void UpdatePrevNextDisabledState()
{
this->SetWidgetDisabledState(WID_SB_PREV_PAGE, story_pages.Length() == 0 || this->IsFirstPageSelected());
this->SetWidgetDisabledState(WID_SB_NEXT_PAGE, story_pages.Length() == 0 || this->IsLastPageSelected());
this->SetWidgetDisabledState(WID_SB_PREV_PAGE, story_pages.size() == 0 || this->IsFirstPageSelected());
this->SetWidgetDisabledState(WID_SB_NEXT_PAGE, story_pages.size() == 0 || this->IsLastPageSelected());
this->SetWidgetDirty(WID_SB_PREV_PAGE);
this->SetWidgetDirty(WID_SB_NEXT_PAGE);
}
@@ -463,12 +453,12 @@ public:
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_SB_SEL_PAGE: {
StoryPage *page = this->GetSelPage();
SetDParamStr(0, page != NULL && page->title != NULL ? page->title : this->selected_generic_title);
SetDParamStr(0, page != nullptr && page->title != nullptr ? page->title : this->selected_generic_title);
break;
}
case WID_SB_CAPTION:
@@ -482,7 +472,7 @@ public:
}
}
virtual void OnPaint()
void OnPaint() override
{
/* Detect if content has changed height. This can happen if a
* multi-line text contains eg. {COMPANY} and that company is
@@ -497,12 +487,12 @@ public:
this->DrawWidgets();
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_SB_PAGE_PANEL) return;
StoryPage *page = this->GetSelPage();
if (page == NULL) return;
if (page == nullptr) return;
const int x = r.left + WD_FRAMETEXT_LEFT;
const int y = r.top + WD_FRAMETEXT_TOP;
@@ -528,12 +518,11 @@ public:
y_offset += line_height;
/* Title */
SetDParamStr(0, page->title != NULL ? page->title : this->selected_generic_title);
SetDParamStr(0, page->title != nullptr ? page->title : this->selected_generic_title);
y_offset = DrawStringMultiLine(0, right - x, y_offset, bottom - y, STR_STORY_BOOK_TITLE, TC_BLACK, SA_TOP | SA_HOR_CENTER);
/* Page elements */
for (const StoryPageElement *const*iter = this->story_page_elements.Begin(); iter != this->story_page_elements.End(); iter++) {
const StoryPageElement *const pe = *iter;
for (const StoryPageElement *const pe : this->story_page_elements) {
y_offset += line_height; // margin to previous element
switch (pe->type) {
@@ -544,8 +533,8 @@ public:
case SPET_GOAL: {
Goal *g = Goal::Get((GoalID) pe->referenced_id);
StringID string_id = g == NULL ? STR_STORY_BOOK_INVALID_GOAL_REF : STR_JUST_RAW_STRING;
if (g != NULL) SetDParamStr(0, g->text);
StringID string_id = g == nullptr ? STR_STORY_BOOK_INVALID_GOAL_REF : STR_JUST_RAW_STRING;
if (g != nullptr) SetDParamStr(0, g->text);
DrawActionElement(y_offset, right - x, line_height, GetPageElementSprite(*pe), string_id);
break;
}
@@ -563,7 +552,7 @@ public:
_cur_dpi = old_dpi;
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_SB_SEL_PAGE && widget != WID_SB_PAGE_PANEL) return;
@@ -575,10 +564,10 @@ public:
case WID_SB_SEL_PAGE: {
/* Get max title width. */
for (uint16 i = 0; i < this->story_pages.Length(); i++) {
for (uint16 i = 0; i < this->story_pages.size(); i++) {
const StoryPage *s = this->story_pages[i];
if (s->title != NULL) {
if (s->title != nullptr) {
SetDParamStr(0, s->title);
} else {
SetDParamStr(0, this->selected_generic_title);
@@ -606,27 +595,27 @@ public:
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_SB_PAGE_PANEL, WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM);
this->vscroll->SetCount(this->GetContentHeight());
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_SB_SEL_PAGE: {
DropDownList *list = this->BuildDropDownList();
if (list != NULL) {
DropDownList list = this->BuildDropDownList();
if (!list.empty()) {
/* Get the index of selected page. */
int selected = 0;
for (uint16 i = 0; i < this->story_pages.Length(); i++) {
for (uint16 i = 0; i < this->story_pages.size(); i++) {
const StoryPage *p = this->story_pages[i];
if (p->index == this->selected_page_id) break;
selected++;
}
ShowDropDownList(this, list, selected, widget);
ShowDropDownList(this, std::move(list), selected, widget);
}
break;
}
@@ -650,8 +639,7 @@ public:
/* Detect if a page element was clicked. */
uint y = head_height;
uint element_vertical_dist = FONT_HEIGHT_NORMAL;
for (const StoryPageElement *const*iter = this->story_page_elements.Begin(); iter != this->story_page_elements.End(); iter++) {
const StoryPageElement *const pe = *iter;
for (const StoryPageElement *const pe : this->story_page_elements) {
y += element_vertical_dist; // margin row
@@ -667,7 +655,7 @@ public:
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
if (widget != WID_SB_SEL_PAGE) return;
@@ -682,7 +670,7 @@ public:
* >= 0 Id of the page that needs to be refreshed. If it is not the current page, nothing happens.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
@@ -694,7 +682,7 @@ public:
this->BuildStoryPageList();
/* Was the last page removed? */
if (this->story_pages.Length() == 0) {
if (this->story_pages.size() == 0) {
this->selected_generic_title[0] = '\0';
}
@@ -702,14 +690,14 @@ public:
if (!_story_page_pool.IsValidID(this->selected_page_id)) {
this->selected_page_id = INVALID_STORY_PAGE;
}
if (this->selected_page_id == INVALID_STORY_PAGE && this->story_pages.Length() > 0) {
if (this->selected_page_id == INVALID_STORY_PAGE && this->story_pages.size() > 0) {
/* No page is selected, but there exist at least one available.
* => Select first page.
*/
this->SetSelectedPage(this->story_pages[0]->index);
}
this->SetWidgetDisabledState(WID_SB_SEL_PAGE, this->story_pages.Length() == 0);
this->SetWidgetDisabledState(WID_SB_SEL_PAGE, this->story_pages.size() == 0);
this->SetWidgetDirty(WID_SB_SEL_PAGE);
this->UpdatePrevNextDisabledState();
} else if (data >= 0 && this->selected_page_id == data) {