summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzuu <zuu@openttd.org>2012-12-20 18:35:13 +0000
committerzuu <zuu@openttd.org>2012-12-20 18:35:13 +0000
commitff465245fa26e9b6d8e9fb96ff24334f702ea6ae (patch)
treebd4f24f76f22ff5476867a05381a60ffcd10b17d /src
parente428952110f0a7c64bdd9616f8d7a5f61345d441 (diff)
downloadopenttd-ff465245fa26e9b6d8e9fb96ff24334f702ea6ae.tar.xz
(svn r24829) -Codechange: Reduce code duplication in the goal GUI
Diffstat (limited to 'src')
-rw-r--r--src/goal_gui.cpp62
1 files changed, 26 insertions, 36 deletions
diff --git a/src/goal_gui.cpp b/src/goal_gui.cpp
index 0b01f825a..cf0e63398 100644
--- a/src/goal_gui.cpp
+++ b/src/goal_gui.cpp
@@ -146,28 +146,19 @@ struct GoalListWindow : Window {
*size = maxdim(*size, d);
}
- virtual void DrawWidget(const Rect &r, int widget) const
+ /**
+ * Draws either the global goals or the company goal section.
+ * This is a helper method for DrawWidget.
+ */
+ void DrawPartialGoalList(int &pos, const int cap, int x, int y, int right, bool global_section) const
{
- if (widget != WID_GL_PANEL) return;
-
- YearMonthDay ymd;
- ConvertDateToYMD(_date, &ymd);
-
- int right = r.right - WD_FRAMERECT_RIGHT;
- int y = r.top + WD_FRAMERECT_TOP;
- int x = r.left + WD_FRAMERECT_LEFT;
-
- int pos = -this->vscroll->GetPosition();
- const int cap = this->vscroll->GetCapacity();
-
- /* Section for drawing the global goals */
- if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_GLOBAL_TITLE);
+ if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, global_section ? STR_GOALS_GLOBAL_TITLE : STR_GOALS_COMPANY_TITLE);
pos++;
uint num = 0;
const Goal *s;
FOR_ALL_GOALS(s) {
- if (s->company == INVALID_COMPANY) {
+ if (global_section ? s->company == INVALID_COMPANY : s->company == _local_company && s->company != INVALID_COMPANY) {
if (IsInsideMM(pos, 0, cap)) {
/* Display the goal */
SetDParamStr(0, s->text);
@@ -182,29 +173,28 @@ struct GoalListWindow : Window {
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
pos++;
}
+ }
- /* Section for drawing the company goals */
- pos++;
- if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_COMPANY_TITLE);
- pos++;
- num = 0;
+ virtual void DrawWidget(const Rect &r, int widget) const
+ {
+ if (widget != WID_GL_PANEL) return;
- FOR_ALL_GOALS(s) {
- if (s->company == _local_company && s->company != INVALID_COMPANY) {
- if (IsInsideMM(pos, 0, cap)) {
- /* Display the goal */
- SetDParamStr(0, s->text);
- DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
- }
- pos++;
- num++;
- }
- }
+ YearMonthDay ymd;
+ ConvertDateToYMD(_date, &ymd);
- if (num == 0) {
- if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
- pos++;
- }
+ int right = r.right - WD_FRAMERECT_RIGHT;
+ int y = r.top + WD_FRAMERECT_TOP;
+ int x = r.left + WD_FRAMERECT_LEFT;
+
+ int pos = -this->vscroll->GetPosition();
+ const int cap = this->vscroll->GetCapacity();
+
+ /* Draw partial list with global goals */
+ DrawPartialGoalList(pos, cap, x, y, right, true);
+
+ /* Draw partial list with company goals */
+ pos++;
+ DrawPartialGoalList(pos, cap, x, y, right, false);
}
virtual void OnResize()