(svn r24829) -Codechange: Reduce code duplication in the goal GUI

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
zuu 12 years ago
parent e428952110
commit ff465245fa

@ -146,28 +146,19 @@ struct GoalListWindow : Window {
*size = maxdim(*size, d); *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; if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, global_section ? STR_GOALS_GLOBAL_TITLE : STR_GOALS_COMPANY_TITLE);
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);
pos++; pos++;
uint num = 0; uint num = 0;
const Goal *s; const Goal *s;
FOR_ALL_GOALS(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)) { if (IsInsideMM(pos, 0, cap)) {
/* Display the goal */ /* Display the goal */
SetDParamStr(0, s->text); 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); if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
pos++; pos++;
} }
}
/* Section for drawing the company goals */ virtual void DrawWidget(const Rect &r, int widget) const
pos++; {
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_COMPANY_TITLE); if (widget != WID_GL_PANEL) return;
pos++;
num = 0;
FOR_ALL_GOALS(s) { YearMonthDay ymd;
if (s->company == _local_company && s->company != INVALID_COMPANY) { ConvertDateToYMD(_date, &ymd);
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++;
}
}
if (num == 0) { int right = r.right - WD_FRAMERECT_RIGHT;
if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE); int y = r.top + WD_FRAMERECT_TOP;
pos++; 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() virtual void OnResize()

Loading…
Cancel
Save