From 50ca18752420fd9c26740e2fc0dbb1c8a8fb7b06 Mon Sep 17 00:00:00 2001 From: alberth Date: Fri, 3 Jul 2009 21:38:41 +0000 Subject: (svn r16733) -Codechange: Move rebuilding and sorting the town list out of TownDirectoryWindow::OnPaint. --- src/town_gui.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src') 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(); } }; -- cgit v1.2.3-54-g00ecf