diff options
author | alberth <alberth@openttd.org> | 2009-07-03 21:38:41 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2009-07-03 21:38:41 +0000 |
commit | 50ca18752420fd9c26740e2fc0dbb1c8a8fb7b06 (patch) | |
tree | e572e0182b5e3853e8f4b4c4b6f5400b26e33e11 | |
parent | ab67cf00312ff93672d628ef68c6772469de460c (diff) | |
download | openttd-50ca18752420fd9c26740e2fc0dbb1c8a8fb7b06.tar.xz |
(svn r16733) -Codechange: Move rebuilding and sorting the town list out of TownDirectoryWindow::OnPaint.
-rw-r--r-- | src/town_gui.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 84ca240c7..c42552fca 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -537,23 +537,21 @@ private: GUITownList towns; - void BuildTownList() + void BuildSortTownList() { - if (!this->towns.NeedRebuild()) return; + if (this->towns.NeedRebuild()) { + this->towns.Clear(); - this->towns.Clear(); + const Town *t; + FOR_ALL_TOWNS(t) { + *this->towns.Append() = t; + } - const Town *t; - FOR_ALL_TOWNS(t) { - *this->towns.Append() = t; + this->towns.Compact(); + this->towns.RebuildDone(); + SetVScrollCount(this, this->towns.Length()); // Update scrollbar as well. } - - this->towns.Compact(); - this->towns.RebuildDone(); - } - - void SortTownList() - { + /* Always sort the towns. */ last_town = NULL; this->towns.Sort(); } @@ -598,6 +596,7 @@ public: this->towns.SetListing(this->last_sorting); this->towns.SetSortFuncs(this->sorter_funcs); this->towns.ForceRebuild(); + this->BuildSortTownList(); } ~TownDirectoryWindow() @@ -607,11 +606,6 @@ public: virtual void OnPaint() { - this->BuildTownList(); - this->SortTownList(); - - SetVScrollCount(this, this->towns.Length()); - this->DrawWidgets(); } @@ -659,6 +653,7 @@ public: } else { this->towns.SetSortType(0); } + this->BuildSortTownList(); this->SetDirty(); break; @@ -668,6 +663,7 @@ public: } else { this->towns.SetSortType(1); } + this->BuildSortTownList(); this->SetDirty(); break; @@ -694,6 +690,7 @@ public: virtual void OnHundredthTick() { + this->BuildSortTownList(); this->SetDirty(); } @@ -709,6 +706,7 @@ public: } else { this->towns.ForceResort(); } + this->BuildSortTownList(); } }; |