Changeset - r25009:40a73870eb9b
[Not reviewed]
master
0 2 0
dP - 3 years ago 2021-02-20 22:00:11
dp@dpointer.org
Change: Don't show global goals in company goal windows
2 files changed with 20 insertions and 76 deletions:
0 comments (0 inline, 0 general)
src/goal_gui.cpp
Show inline comments
 
@@ -66,33 +66,13 @@ struct GoalListWindow : public Window {
 
		if (widget != WID_GOAL_LIST) return;
 

	
 
		int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WD_FRAMERECT_TOP);
 
		int num = 0;
 
		for (const Goal *s : Goal::Iterate()) {
 
			if (s->company == INVALID_COMPANY) {
 
				y--;
 
			if (s->company == this->window_number) {
 
				if (y == 0) {
 
					this->HandleClick(s);
 
					return;
 
				}
 
				num++;
 
			}
 
		}
 

	
 
		if (num == 0) {
 
			y--; // "None" line.
 
			if (y < 0) return;
 
		}
 

	
 
		y -= 2; // "Company specific goals:" line.
 
		if (y < 0) return;
 

	
 
		for (const Goal *s : Goal::Iterate()) {
 
			if (s->company == this->window_number && s->company != INVALID_COMPANY) {
 
				y--;
 
				if (y == 0) {
 
					this->HandleClick(s);
 
					return;
 
				}
 
			}
 
		}
 
	}
 
@@ -161,28 +141,21 @@ struct GoalListWindow : public Window {
 
	uint CountLines()
 
	{
 
		/* Count number of (non) awarded goals. */
 
		uint num_global = 0;
 
		uint num_company = 0;
 
		uint num = 0;
 
		for (const Goal *s : Goal::Iterate()) {
 
			if (s->company == INVALID_COMPANY) {
 
				num_global++;
 
			} else if (s->company == this->window_number) {
 
				num_company++;
 
			}
 
			if (s->company == this->window_number) num++;
 
		}
 

	
 
		/* Count the 'none' lines. */
 
		if (num_global  == 0) num_global = 1;
 
		if (num_company == 0) num_company = 1;
 
		if (num == 0) num = 1;
 

	
 
		/* Global, company and an empty line before the accepted ones. */
 
		return 3 + num_global + num_company;
 
		return num;
 
	}
 

	
 
	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
 
	{
 
		if (widget != WID_GOAL_LIST) return;
 
		Dimension d = maxdim(GetStringBoundingBox(STR_GOALS_GLOBAL_TITLE), GetStringBoundingBox(STR_GOALS_COMPANY_TITLE));
 
		Dimension d = GetStringBoundingBox(STR_GOALS_NONE);
 

	
 
		resize->height = d.height;
 

	
 
@@ -193,26 +166,26 @@ struct GoalListWindow : public Window {
 
	}
 

	
 
	/**
 
	 * Draws either the global goals or the company goal section.
 
	 * This is a helper method for #DrawWidget.
 
	 * @param[in,out] pos Vertical line number to draw.
 
	 * @param cap Number of lines to draw in the window.
 
	 * @param x Left edge of the text line to draw.
 
	 * @param y Vertical position of the top edge of the window.
 
	 * @param right Right edge of the text line to draw.
 
	 * @param global_section Whether the global goals are printed.
 
	 * Draws a given column of the goal list.
 
	 * @param column Which column to draw.
 
	 * @param wid Pointer to the goal list widget.
 
	 * @param progress_col_width Width of the progress column.
 
	 * @return max width of drawn text
 
	 */
 
	void DrawPartialGoalList(int &pos, const int cap, int x, int y, int right, uint progress_col_width, bool global_section, GoalColumn column) const
 
	void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
 
	{
 
		if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, global_section ? STR_GOALS_GLOBAL_TITLE : STR_GOALS_COMPANY_TITLE);
 
		pos++;
 
		/* Get column draw area. */
 
		int y = wid->pos_y + WD_FRAMERECT_TOP;
 
		int x = wid->pos_x + WD_FRAMERECT_LEFT;
 
		int right = x + wid->current_x - WD_FRAMERECT_RIGHT;
 
		bool rtl = _current_text_dir == TD_RTL;
 

	
 
		bool rtl = _current_text_dir == TD_RTL;
 
		int pos = -this->vscroll->GetPosition();
 
		const int cap = this->vscroll->GetCapacity();
 

	
 
		uint num = 0;
 
		for (const Goal *s : Goal::Iterate()) {
 
			if (global_section ? s->company == INVALID_COMPANY : (s->company == this->window_number && s->company != INVALID_COMPANY)) {
 
			if (s->company == this->window_number) {
 
				if (IsInsideMM(pos, 0, cap)) {
 
					switch (column) {
 
						case GC_GOAL: {
 
@@ -241,38 +214,12 @@ struct GoalListWindow : public Window {
 

	
 
		if (num == 0) {
 
			if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
 
				StringID str = !global_section && this->window_number == INVALID_COMPANY ? STR_GOALS_SPECTATOR_NONE : STR_GOALS_NONE;
 
				DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, str);
 
				DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
 
			}
 
			pos++;
 
		}
 
	}
 

	
 
	/**
 
	 * Draws a given column of the goal list.
 
	 * @param column Which column to draw.
 
	 * @param wid Pointer to the goal list widget.
 
	 * @param progress_col_width Width of the progress column.
 
	 * @return max width of drawn text
 
	 */
 
	void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
 
	{
 
		/* Get column draw area. */
 
		int y = wid->pos_y + WD_FRAMERECT_TOP;
 
		int x = wid->pos_x + WD_FRAMERECT_LEFT;
 
		int right = x + wid->current_x - WD_FRAMERECT_RIGHT;
 

	
 
		int pos = -this->vscroll->GetPosition();
 
		const int cap = this->vscroll->GetCapacity();
 

	
 
		/* Draw partial list with global goals. */
 
		DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, true, column);
 

	
 
		/* Draw partial list with company goals. */
 
		pos++;
 
		DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, false, column);
 
	}
 

	
 
	void OnPaint() override
 
	{
 
		this->DrawWidgets();
src/lang/english.txt
Show inline comments
 
@@ -3197,13 +3197,10 @@ STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE
 
STR_GOALS_CAPTION                                               :{WHITE}{COMPANY} Goals
 
STR_GOALS_SPECTATOR_CAPTION                                     :{WHITE}Global Goals
 
STR_GOALS_SPECTATOR                                             :Global Goals
 
STR_GOALS_GLOBAL_TITLE                                          :{BLACK}Global goals:
 
STR_GOALS_TEXT                                                  :{ORANGE}{RAW_STRING}
 
STR_GOALS_NONE                                                  :{ORANGE}- None -
 
STR_GOALS_SPECTATOR_NONE                                        :{ORANGE}- Not applicable -
 
STR_GOALS_PROGRESS                                              :{ORANGE}{RAW_STRING}
 
STR_GOALS_PROGRESS_COMPLETE                                     :{GREEN}{RAW_STRING}
 
STR_GOALS_COMPANY_TITLE                                         :{BLACK}Company goals:
 
STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER                    :{BLACK}Click on goal to centre main view on industry/town/tile. Ctrl+Click opens a new viewport on industry/town/tile location
 

	
 
# Goal question window
0 comments (0 inline, 0 general)