Changeset - r19874:ee1f6282fb23
[Not reviewed]
master
0 1 0
zuu - 11 years ago 2012-12-20 18:35:13
zuu@openttd.org
(svn r24829) -Codechange: Reduce code duplication in the goal GUI
1 file changed with 33 insertions and 43 deletions:
0 comments (0 inline, 0 general)
src/goal_gui.cpp
Show inline comments
 
@@ -146,6 +146,35 @@ struct GoalListWindow : Window {
 
		*size = maxdim(*size, d);
 
	}
 

	
 
	/**
 
	 * 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 (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 (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);
 
					DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
 
				}
 
				pos++;
 
				num++;
 
			}
 
		}
 

	
 
		if (num == 0) {
 
			if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
 
			pos++;
 
		}
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (widget != WID_GL_PANEL) return;
 
@@ -160,51 +189,12 @@ struct GoalListWindow : Window {
 
		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++;
 

	
 
		uint num = 0;
 
		const Goal *s;
 
		FOR_ALL_GOALS(s) {
 
			if (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++;
 
			}
 
		}
 

	
 
		if (num == 0) {
 
			if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
 
			pos++;
 
		}
 
		/* Draw partial list with global goals */
 
		DrawPartialGoalList(pos, cap, x, y, right, true);
 

	
 
		/* Section for drawing the company goals */
 
		pos++;
 
		if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_COMPANY_TITLE);
 
		/* Draw partial list with company goals */
 
		pos++;
 
		num = 0;
 

	
 
		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++;
 
			}
 
		}
 

	
 
		if (num == 0) {
 
			if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
 
			pos++;
 
		}
 
		DrawPartialGoalList(pos, cap, x, y, right, false);
 
	}
 

	
 
	virtual void OnResize()
0 comments (0 inline, 0 general)