Update to 1.10.0-beta1
This commit is contained in:
@@ -45,7 +45,7 @@ struct SignList {
|
||||
|
||||
StringFilter string_filter; ///< The match string to be used when the GUIList is (re)-sorted.
|
||||
static bool match_case; ///< Should case sensitive matching be used?
|
||||
static char default_name[64]; ///< Default sign name, used if Sign::name is NULL.
|
||||
static char default_name[64]; ///< Default sign name, used if Sign::name is nullptr.
|
||||
|
||||
/**
|
||||
* Creates a SignList with filtering disabled by default.
|
||||
@@ -60,33 +60,33 @@ struct SignList {
|
||||
|
||||
DEBUG(misc, 3, "Building sign list");
|
||||
|
||||
this->signs.Clear();
|
||||
this->signs.clear();
|
||||
|
||||
const Sign *si;
|
||||
FOR_ALL_SIGNS(si) *this->signs.Append() = si;
|
||||
FOR_ALL_SIGNS(si) this->signs.push_back(si);
|
||||
|
||||
this->signs.SetFilterState(true);
|
||||
this->FilterSignList();
|
||||
this->signs.Compact();
|
||||
this->signs.shrink_to_fit();
|
||||
this->signs.RebuildDone();
|
||||
}
|
||||
|
||||
/** Sort signs by their name */
|
||||
static int CDECL SignNameSorter(const Sign * const *a, const Sign * const *b)
|
||||
static bool SignNameSorter(const Sign * const &a, const Sign * const &b)
|
||||
{
|
||||
/* Signs are very very rarely using the default text, but there can also be
|
||||
* a lot of them. Therefore a worthwhile performance gain can be made by
|
||||
* directly comparing Sign::name instead of going through the string
|
||||
* system for each comparison. */
|
||||
const char *a_name = (*a)->name;
|
||||
const char *b_name = (*b)->name;
|
||||
const char *a_name = a->name;
|
||||
const char *b_name = b->name;
|
||||
|
||||
if (a_name == NULL) a_name = SignList::default_name;
|
||||
if (b_name == NULL) b_name = SignList::default_name;
|
||||
if (a_name == nullptr) a_name = SignList::default_name;
|
||||
if (b_name == nullptr) b_name = SignList::default_name;
|
||||
|
||||
int r = strnatcmp(a_name, b_name); // Sort by name (natural sorting).
|
||||
|
||||
return r != 0 ? r : ((*a)->index - (*b)->index);
|
||||
return r != 0 ? r < 0 : (a->index < b->index);
|
||||
}
|
||||
|
||||
void SortSignsList()
|
||||
@@ -100,7 +100,7 @@ struct SignList {
|
||||
/* Same performance benefit as above for sorting. */
|
||||
const char *a_name = (*a)->name;
|
||||
|
||||
if (a_name == NULL) a_name = SignList::default_name;
|
||||
if (a_name == nullptr) a_name = SignList::default_name;
|
||||
|
||||
filter.ResetState();
|
||||
filter.AddLine(a_name);
|
||||
@@ -166,9 +166,9 @@ struct SignListWindow : Window, SignList {
|
||||
this->BuildSortSignList();
|
||||
}
|
||||
|
||||
virtual void OnInit()
|
||||
void OnInit() override
|
||||
{
|
||||
/* Default sign name, used if Sign::name is NULL. */
|
||||
/* Default sign name, used if Sign::name is nullptr. */
|
||||
GetString(SignList::default_name, STR_DEFAULT_SIGN_NAME, lastof(SignList::default_name));
|
||||
this->signs.ForceResort();
|
||||
this->SortSignsList();
|
||||
@@ -190,13 +190,13 @@ struct SignListWindow : Window, SignList {
|
||||
this->InvalidateData();
|
||||
}
|
||||
|
||||
virtual void OnPaint()
|
||||
void OnPaint() override
|
||||
{
|
||||
if (!this->IsShaded() && this->signs.NeedRebuild()) this->BuildSortSignList();
|
||||
this->DrawWidgets();
|
||||
}
|
||||
|
||||
virtual void DrawWidget(const Rect &r, int widget) const
|
||||
void DrawWidget(const Rect &r, int widget) const override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_SIL_LIST: {
|
||||
@@ -228,12 +228,12 @@ struct SignListWindow : Window, SignList {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void SetStringParameters(int widget) const
|
||||
void SetStringParameters(int widget) const override
|
||||
{
|
||||
if (widget == WID_SIL_CAPTION) SetDParam(0, this->vscroll->GetCount());
|
||||
}
|
||||
|
||||
virtual void OnClick(Point pt, int widget, int click_count)
|
||||
void OnClick(Point pt, int widget, int click_count) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_SIL_LIST: {
|
||||
@@ -246,7 +246,7 @@ struct SignListWindow : Window, SignList {
|
||||
}
|
||||
|
||||
case WID_SIL_FILTER_ENTER_BTN:
|
||||
if (this->signs.Length() >= 1) {
|
||||
if (this->signs.size() >= 1) {
|
||||
const Sign *si = this->signs[0];
|
||||
ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
|
||||
}
|
||||
@@ -260,12 +260,12 @@ struct SignListWindow : Window, SignList {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnResize()
|
||||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_SIL_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_SIL_LIST: {
|
||||
@@ -286,7 +286,7 @@ struct SignListWindow : Window, SignList {
|
||||
}
|
||||
}
|
||||
|
||||
virtual EventState OnHotkey(int hotkey)
|
||||
EventState OnHotkey(int hotkey) override
|
||||
{
|
||||
switch (hotkey) {
|
||||
case SLHK_FOCUS_FILTER_BOX:
|
||||
@@ -301,7 +301,7 @@ struct SignListWindow : Window, SignList {
|
||||
return ES_HANDLED;
|
||||
}
|
||||
|
||||
virtual void OnEditboxChanged(int widget)
|
||||
void OnEditboxChanged(int widget) override
|
||||
{
|
||||
if (widget == WID_SIL_FILTER_TEXT) this->SetFilterString(this->filter_editbox.text.buf);
|
||||
}
|
||||
@@ -310,13 +310,13 @@ struct SignListWindow : Window, SignList {
|
||||
{
|
||||
if (this->signs.NeedRebuild()) {
|
||||
this->BuildSignsList();
|
||||
this->vscroll->SetCount(this->signs.Length());
|
||||
this->vscroll->SetCount((uint)this->signs.size());
|
||||
this->SetWidgetDirty(WID_SIL_CAPTION);
|
||||
}
|
||||
this->SortSignsList();
|
||||
}
|
||||
|
||||
virtual void OnHundredthTick()
|
||||
void OnHundredthTick() override
|
||||
{
|
||||
this->BuildSortSignList();
|
||||
this->SetDirty();
|
||||
@@ -327,7 +327,7 @@ struct SignListWindow : Window, SignList {
|
||||
* @param data Information about the changed data.
|
||||
* @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
|
||||
{
|
||||
/* When there is a filter string, we always need to rebuild the list even if
|
||||
* the amount of signs in total is unchanged, as the subset of signs that is
|
||||
@@ -352,7 +352,7 @@ static EventState SignListGlobalHotkeys(int hotkey)
|
||||
{
|
||||
if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
|
||||
Window *w = ShowSignList();
|
||||
if (w == NULL) return ES_NOT_HANDLED;
|
||||
if (w == nullptr) return ES_NOT_HANDLED;
|
||||
return w->OnHotkey(hotkey);
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ static WindowDesc _sign_list_desc(
|
||||
/**
|
||||
* Open the sign list window
|
||||
*
|
||||
* @return newly opened sign list window, or NULL if the window could not be opened.
|
||||
* @return newly opened sign list window, or nullptr if the window could not be opened.
|
||||
*/
|
||||
Window *ShowSignList()
|
||||
{
|
||||
@@ -418,7 +418,7 @@ Window *ShowSignList()
|
||||
static bool RenameSign(SignID index, const char *text)
|
||||
{
|
||||
bool remove = StrEmpty(text);
|
||||
DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_ERROR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_ERROR_CAN_T_CHANGE_SIGN_NAME)), NULL, text);
|
||||
DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_ERROR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_ERROR_CAN_T_CHANGE_SIGN_NAME)), nullptr, text);
|
||||
return remove;
|
||||
}
|
||||
|
||||
@@ -442,7 +442,7 @@ struct SignWindow : Window, SignList {
|
||||
void UpdateSignEditWindow(const Sign *si)
|
||||
{
|
||||
/* Display an empty string when the sign hasn't been edited yet */
|
||||
if (si->name != NULL) {
|
||||
if (si->name != nullptr) {
|
||||
SetDParam(0, si->index);
|
||||
this->name_editbox.text.Assign(STR_SIGN_NAME);
|
||||
} else {
|
||||
@@ -471,7 +471,7 @@ struct SignWindow : Window, SignList {
|
||||
/* Search through the list for the current sign, excluding
|
||||
* - the first sign if we want the previous sign or
|
||||
* - the last sign if we want the next sign */
|
||||
uint end = this->signs.Length() - (next ? 1 : 0);
|
||||
size_t end = this->signs.size() - (next ? 1 : 0);
|
||||
for (uint i = next ? 0 : 1; i < end; i++) {
|
||||
if (this->cur_sign == this->signs[i]->index) {
|
||||
/* We've found the current sign, so return the sign before/after it */
|
||||
@@ -479,10 +479,10 @@ struct SignWindow : Window, SignList {
|
||||
}
|
||||
}
|
||||
/* If we haven't found the current sign by now, return the last/first sign */
|
||||
return this->signs[next ? 0 : this->signs.Length() - 1];
|
||||
return next ? this->signs.front() : this->signs.back();
|
||||
}
|
||||
|
||||
virtual void SetStringParameters(int widget) const
|
||||
void SetStringParameters(int widget) const override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_QES_CAPTION:
|
||||
@@ -491,7 +491,7 @@ struct SignWindow : Window, SignList {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnClick(Point pt, int widget, int click_count)
|
||||
void OnClick(Point pt, int widget, int click_count) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_QES_PREVIOUS:
|
||||
@@ -559,7 +559,7 @@ static WindowDesc _query_sign_edit_desc(
|
||||
void HandleClickOnSign(const Sign *si)
|
||||
{
|
||||
if (_ctrl_pressed && (si->owner == _local_company || (si->owner == OWNER_DEITY && _game_mode == GM_EDITOR))) {
|
||||
RenameSign(si->index, NULL);
|
||||
RenameSign(si->index, nullptr);
|
||||
return;
|
||||
}
|
||||
ShowRenameSignWindow(si);
|
||||
@@ -585,5 +585,5 @@ void DeleteRenameSignWindow(SignID sign)
|
||||
{
|
||||
SignWindow *w = dynamic_cast<SignWindow *>(FindWindowById(WC_QUERY_STRING, WN_QUERY_STRING_SIGN));
|
||||
|
||||
if (w != NULL && w->cur_sign == sign) delete w;
|
||||
if (w != nullptr && w->cur_sign == sign) delete w;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user