MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BuildSortTownList

Method BuildSortTownList

src/town_gui.cpp:738–760  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

736 Scrollbar *vscroll = nullptr;
737
738 void BuildSortTownList()
739 {
740 if (this->towns.NeedRebuild()) {
741 this->towns.clear();
742 this->towns.reserve(Town::GetNumItems());
743
744 for (const Town *t : Town::Iterate()) {
745 if (this->string_filter.IsEmpty()) {
746 this->towns.push_back(t);
747 continue;
748 }
749 this->string_filter.ResetState();
750 this->string_filter.AddLine(t->GetCachedName());
751 if (this->string_filter.GetState()) this->towns.push_back(t);
752 }
753
754 this->towns.RebuildDone();
755 this->vscroll->SetCount(this->towns.size()); // Update scrollbar as well.
756 }
757 /* Always sort the towns. */
758 this->towns.Sort();
759 this->SetWidgetDirty(WID_TD_LIST); // Force repaint of the displayed towns.
760 }
761
762 /** Sort by town name */
763 static bool TownNameSorter(const Town * const &a, const Town * const &b, const bool &)

Callers 4

TownDirectoryWindowMethod · 0.95
OnDropdownSelectMethod · 0.95
OnPaintMethod · 0.95
TownDirectoryWindowClass · 0.95

Calls 13

NeedRebuildMethod · 0.80
reserveMethod · 0.80
push_backMethod · 0.80
ResetStateMethod · 0.80
RebuildDoneMethod · 0.80
SetWidgetDirtyMethod · 0.80
clearMethod · 0.45
IsEmptyMethod · 0.45
AddLineMethod · 0.45
GetStateMethod · 0.45
SetCountMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected