mirror of https://github.com/OpenTTD/OpenTTD
Fix 196d5868: Always apply filter on town directory rebuild
parent
150dfba95b
commit
5c10c426fe
|
@ -161,7 +161,6 @@ enum TownRatingCheckType {
|
||||||
/** Special values for town list window for the data parameter of #InvalidateWindowData. */
|
/** Special values for town list window for the data parameter of #InvalidateWindowData. */
|
||||||
enum TownDirectoryInvalidateWindowData {
|
enum TownDirectoryInvalidateWindowData {
|
||||||
TDIWD_FORCE_REBUILD,
|
TDIWD_FORCE_REBUILD,
|
||||||
TDIWD_FILTER_CHANGES, ///< The filename filter has changed (via the editbox)
|
|
||||||
TDIWD_FORCE_RESORT,
|
TDIWD_FORCE_RESORT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -687,10 +687,22 @@ private:
|
||||||
void BuildSortTownList()
|
void BuildSortTownList()
|
||||||
{
|
{
|
||||||
if (this->towns.NeedRebuild()) {
|
if (this->towns.NeedRebuild()) {
|
||||||
|
char buf[MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH];
|
||||||
|
|
||||||
this->towns.clear();
|
this->towns.clear();
|
||||||
|
|
||||||
for (const Town *t : Town::Iterate()) {
|
for (const Town *t : Town::Iterate()) {
|
||||||
this->towns.push_back(t);
|
if (this->string_filter.IsEmpty()) {
|
||||||
|
this->towns.push_back(t);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
this->string_filter.ResetState();
|
||||||
|
|
||||||
|
SetDParam(0, t->index);
|
||||||
|
GetString(buf, STR_TOWN_NAME, lastof(buf));
|
||||||
|
|
||||||
|
this->string_filter.AddLine(buf);
|
||||||
|
if (this->string_filter.GetState()) this->towns.push_back(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->towns.shrink_to_fit();
|
this->towns.shrink_to_fit();
|
||||||
|
@ -965,7 +977,7 @@ public:
|
||||||
{
|
{
|
||||||
if (wid == WID_TD_FILTER) {
|
if (wid == WID_TD_FILTER) {
|
||||||
this->string_filter.SetFilterTerm(this->townname_editbox.text.buf);
|
this->string_filter.SetFilterTerm(this->townname_editbox.text.buf);
|
||||||
this->InvalidateData(TDIWD_FILTER_CHANGES);
|
this->InvalidateData(TDIWD_FORCE_REBUILD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -976,38 +988,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
||||||
{
|
{
|
||||||
char buf[MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH];
|
|
||||||
|
|
||||||
switch (data) {
|
switch (data) {
|
||||||
case TDIWD_FORCE_REBUILD:
|
case TDIWD_FORCE_REBUILD:
|
||||||
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
|
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
|
||||||
this->towns.ForceRebuild();
|
this->towns.ForceRebuild();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TDIWD_FILTER_CHANGES:
|
|
||||||
if (this->string_filter.IsEmpty()) {
|
|
||||||
this->towns.ForceRebuild();
|
|
||||||
} else {
|
|
||||||
this->towns.clear();
|
|
||||||
|
|
||||||
for (const Town *t : Town::Iterate()) {
|
|
||||||
this->string_filter.ResetState();
|
|
||||||
|
|
||||||
SetDParam(0, t->index);
|
|
||||||
GetString(buf, STR_TOWN_NAME, lastof(buf));
|
|
||||||
|
|
||||||
this->string_filter.AddLine(buf);
|
|
||||||
if (this->string_filter.GetState()) this->towns.push_back(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->towns.SetListing(this->last_sorting);
|
|
||||||
this->towns.ForceResort();
|
|
||||||
this->towns.Sort();
|
|
||||||
this->towns.shrink_to_fit();
|
|
||||||
this->towns.RebuildDone();
|
|
||||||
this->vscroll->SetCount((int)this->towns.size()); // Update scrollbar as well.
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
this->towns.ForceResort();
|
this->towns.ForceResort();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue