summaryrefslogtreecommitdiff
path: root/src/industry_gui.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-08-30 14:06:55 +0000
committerrubidium <rubidium@openttd.org>2009-08-30 14:06:55 +0000
commite8433f6d48a801d6c008b8c61e6ea4dff525b2c1 (patch)
treeb28326b26c34c56b989dbd0ca1e2c2f69aa4a5ec /src/industry_gui.cpp
parent0aab13bf448c5626030a63b3106b128c891a3aa1 (diff)
downloadopenttd-e8433f6d48a801d6c008b8c61e6ea4dff525b2c1.tar.xz
(svn r17320) -Codechange: move the code to determine the string and set dparams of industries in the industry directory out of OnPaint
Diffstat (limited to 'src/industry_gui.cpp')
-rw-r--r--src/industry_gui.cpp61
1 files changed, 36 insertions, 25 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index f829e821a..c23dc39ac 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -905,6 +905,41 @@ protected:
return (r == 0) ? IndustryNameSorter(a, b) : r;
}
+ /**
+ * Get the StringID to draw and set the appropriate DParams.
+ * @param i the industry to get the StringID of.
+ * @return the StringID.
+ */
+ StringID GetIndustryString(const Industry *i)
+ {
+ const IndustrySpec *indsp = GetIndustrySpec(i->type);
+ byte p = 0;
+
+ /* Industry name */
+ SetDParam(p++, i->index);
+
+ /* Industry productions */
+ for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+ if (i->produced_cargo[j] == CT_INVALID) continue;
+ SetDParam(p++, i->produced_cargo[j]);
+ SetDParam(p++, i->last_month_production[j]);
+ SetDParam(p++, GetCargoSuffix(j + 3, CST_DIR, const_cast<Industry *>(i), i->type, indsp));
+ }
+
+ /* Transported productions */
+ for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+ if (i->produced_cargo[j] == CT_INVALID) continue;
+ SetDParam(p++, ToPercent8(i->last_month_pct_transported[j]));
+ }
+
+ /* Drawing the right string */
+ switch (p) {
+ case 1: return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
+ case 5: return STR_INDUSTRY_DIRECTORY_ITEM;
+ default: return STR_INDUSTRY_DIRECTORY_ITEM_TWO;
+ }
+ }
+
public:
IndustryDirectoryWindow(const WindowDesc *desc, WindowNumber number) : Window(desc, number)
{
@@ -938,32 +973,8 @@ public:
int y = this->widget[IDW_INDUSTRY_LIST].top + 2; // start of the list-widget
for (int n = this->vscroll.pos; n < max; ++n) {
- const Industry *i = this->industries[n];
- const IndustrySpec *indsp = GetIndustrySpec(i->type);
- byte p = 0;
-
- /* Industry name */
- SetDParam(p++, i->index);
-
- /* Industry productions */
- for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
- if (i->produced_cargo[j] == CT_INVALID) continue;
- SetDParam(p++, i->produced_cargo[j]);
- SetDParam(p++, i->last_month_production[j]);
- SetDParam(p++, GetCargoSuffix(j + 3, CST_DIR, const_cast<Industry *>(i), i->type, indsp));
- }
-
- /* Transported productions */
- for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
- if (i->produced_cargo[j] == CT_INVALID) continue;
- SetDParam(p++, ToPercent8(i->last_month_pct_transported[j]));
- }
-
- /* Drawing the right string */
- StringID str = STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
- if (p != 1) str = (p == 5) ? STR_INDUSTRY_DIRECTORY_ITEM : STR_INDUSTRY_DIRECTORY_ITEM_TWO;
+ StringID str = this->GetIndustryString(this->industries[n]);
DrawString(this->widget[IDW_INDUSTRY_LIST].left + 2, this->widget[IDW_INDUSTRY_LIST].right - 2, y, str);
-
y += this->industryline_height;
}
}