1
0
Fork 0

(svn r13294) -Codechange: convert the inheritance of GUIList in IndustryDirectoryWindow to a member object

release/0.7
skidd13 2008-05-27 18:50:31 +00:00
parent 9c7d4ffd4c
commit 83c442cc57
1 changed files with 24 additions and 22 deletions

View File

@ -849,9 +849,11 @@ static void SortIndustriesList(GUIIndustryList *sl)
/** /**
* The list of industries. * The list of industries.
*/ */
struct IndustryDirectoryWindow : public Window, public GUIIndustryList { struct IndustryDirectoryWindow : public Window {
static Listing industry_sort; static Listing industry_sort;
GUIIndustryList industries;
IndustryDirectoryWindow(const WindowDesc *desc, WindowNumber number) : Window(desc, number) IndustryDirectoryWindow(const WindowDesc *desc, WindowNumber number) : Window(desc, number)
{ {
this->vscroll.cap = 16; this->vscroll.cap = 16;
@ -859,26 +861,26 @@ struct IndustryDirectoryWindow : public Window, public GUIIndustryList {
this->resize.step_height = 10; this->resize.step_height = 10;
this->FindWindowPlacementAndResize(desc); this->FindWindowPlacementAndResize(desc);
this->flags = VL_REBUILD; this->industries.flags = VL_REBUILD;
this->sort_type = industry_sort.criteria; this->industries.sort_type = industry_sort.criteria;
if (industry_sort.order) this->flags |= VL_DESC; if (industry_sort.order) this->industries.flags |= VL_DESC;
} }
virtual void OnPaint() virtual void OnPaint()
{ {
BuildIndustriesList(this); BuildIndustriesList(&this->industries);
SortIndustriesList(this); SortIndustriesList(&this->industries);
SetVScrollCount(this, this->Length()); SetVScrollCount(this, this->industries.Length());
this->DrawWidgets(); this->DrawWidgets();
this->DrawSortButtonState(IDW_SORTBYNAME + this->sort_type, this->flags & VL_DESC ? SBS_DOWN : SBS_UP); this->DrawSortButtonState(IDW_SORTBYNAME + this->industries.sort_type, this->industries.flags & VL_DESC ? SBS_DOWN : SBS_UP);
int max = min(this->vscroll.pos + this->vscroll.cap, this->Length()); int max = min(this->vscroll.pos + this->vscroll.cap, this->industries.Length());
int y = 28; // start of the list-widget int y = 28; // start of the list-widget
for (int n = this->vscroll.pos; n < max; ++n) { for (int n = this->vscroll.pos; n < max; ++n) {
const Industry* i = *this->Get(n); const Industry* i = this->industries[n];
const IndustrySpec *indsp = GetIndustrySpec(i->type); const IndustrySpec *indsp = GetIndustrySpec(i->type);
byte p = 0; byte p = 0;
@ -915,15 +917,15 @@ struct IndustryDirectoryWindow : public Window, public GUIIndustryList {
case IDW_SORTBYTYPE: case IDW_SORTBYTYPE:
case IDW_SORTBYPROD: case IDW_SORTBYPROD:
case IDW_SORTBYTRANSPORT: case IDW_SORTBYTRANSPORT:
if (this->sort_type == (widget - IDW_SORTBYNAME)) { if (this->industries.sort_type == (widget - IDW_SORTBYNAME)) {
this->flags ^= VL_DESC; this->industries.flags ^= VL_DESC;
} else { } else {
this->sort_type = widget - IDW_SORTBYNAME; this->industries.sort_type = widget - IDW_SORTBYNAME;
this->flags &= ~VL_DESC; this->industries.flags &= ~VL_DESC;
} }
industry_sort.criteria = this->sort_type; industry_sort.criteria = this->industries.sort_type;
industry_sort.order = HasBit(this->flags, 0); industry_sort.order = HasBit(this->industries.flags, 0);
this->flags |= VL_RESORT; this->industries.flags |= VL_RESORT;
this->SetDirty(); this->SetDirty();
break; break;
@ -933,11 +935,11 @@ struct IndustryDirectoryWindow : public Window, public GUIIndustryList {
if (!IsInsideMM(y, 0, this->vscroll.cap)) return; if (!IsInsideMM(y, 0, this->vscroll.cap)) return;
p = y + this->vscroll.pos; p = y + this->vscroll.pos;
if (p < this->Length()) { if (p < this->industries.Length()) {
if (_ctrl_pressed) { if (_ctrl_pressed) {
ShowExtraViewPortWindow((*this->Get(p))->xy); ShowExtraViewPortWindow(this->industries[p]->xy);
} else { } else {
ScrollMainWindowToTile((*this->Get(p))->xy); ScrollMainWindowToTile(this->industries[p]->xy);
} }
} }
} break; } break;
@ -951,12 +953,12 @@ struct IndustryDirectoryWindow : public Window, public GUIIndustryList {
virtual void OnInvalidateData(int data) virtual void OnInvalidateData(int data)
{ {
this->flags |= (data == 0 ? VL_REBUILD : VL_RESORT); this->industries.flags |= (data == 0 ? VL_REBUILD : VL_RESORT);
this->InvalidateWidget(IDW_INDUSTRY_LIST); this->InvalidateWidget(IDW_INDUSTRY_LIST);
} }
}; };
Listing IndustryDirectoryWindow::industry_sort = {0, 0}; Listing IndustryDirectoryWindow::industry_sort = {false, 0};
/** Window definition of the industy directory gui */ /** Window definition of the industy directory gui */
static const WindowDesc _industry_directory_desc = { static const WindowDesc _industry_directory_desc = {