Changeset - r20359:fae457d8d0be
[Not reviewed]
master
0 7 0
zuu - 11 years ago 2013-06-09 13:23:03
zuu@openttd.org
(svn r25372) -Add: Allow opening a goal list window specific to a company
7 files changed with 30 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/goal_gui.cpp
Show inline comments
 
@@ -17,12 +17,13 @@
 
#include "date_func.h"
 
#include "viewport_func.h"
 
#include "gui.h"
 
#include "goal_base.h"
 
#include "core/geometry_func.hpp"
 
#include "company_func.h"
 
#include "company_base.h"
 
#include "command_func.h"
 

	
 
#include "widgets/goal_widget.h"
 

	
 
#include "table/strings.h"
 

	
 
@@ -34,12 +35,24 @@ struct GoalListWindow : Window {
 
		this->CreateNestedTree();
 
		this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
 
		this->FinishInitNested(window_number);
 
		this->OnInvalidateData(0);
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		if (widget != WID_GOAL_CAPTION) return;
 

	
 
		if (this->window_number == INVALID_COMPANY) {
 
			SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
 
		} else {
 
			SetDParam(0, STR_GOALS_CAPTION);
 
			SetDParam(1, this->window_number);
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		if (widget != WID_GOAL_GOAL && widget != WID_GOAL_PROGRESS) return;
 

	
 
		int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_GOAL, WD_FRAMERECT_TOP);
 
		int num = 0;
 
@@ -61,13 +74,13 @@ struct GoalListWindow : Window {
 
		}
 

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

	
 
		FOR_ALL_GOALS(s) {
 
			if (s->company == _local_company) {
 
			if (s->company == this->window_number) {
 
				y--;
 
				if (y == 0) {
 
					this->HandleClick(s);
 
					return;
 
				}
 
			}
 
@@ -117,13 +130,13 @@ struct GoalListWindow : Window {
 
		uint num_global = 0;
 
		uint num_company = 0;
 
		const Goal *s;
 
		FOR_ALL_GOALS(s) {
 
			if (s->company == INVALID_COMPANY) {
 
				num_global++;
 
			} else if (s->company == _local_company) {
 
			} else if (s->company == this->window_number) {
 
				num_company++;
 
			}
 
		}
 

	
 
		/* Count the 'none' lines */
 
		if (num_global  == 0) num_global = 1;
 
@@ -171,13 +184,13 @@ struct GoalListWindow : Window {
 
		if (widget == WID_GOAL_GOAL && 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 (global_section ? s->company == INVALID_COMPANY : s->company == this->window_number && s->company != INVALID_COMPANY) {
 
				if (IsInsideMM(pos, 0, cap)) {
 
					switch (widget) {
 
						case WID_GOAL_GOAL:
 
							/* Display the goal. */
 
							SetDParamStr(0, s->text);
 
							DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
 
@@ -194,13 +207,13 @@ struct GoalListWindow : Window {
 
				pos++;
 
				num++;
 
			}
 
		}
 

	
 
		if (widget == WID_GOAL_GOAL && num == 0) {
 
			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, !global_section && this->window_number == INVALID_COMPANY ? STR_GOALS_SPECTATOR_NONE : STR_GOALS_NONE);
 
			pos++;
 
		}
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
@@ -241,13 +254,13 @@ struct GoalListWindow : Window {
 
	}
 
};
 

	
 
static const NWidgetPart _nested_goals_list_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GOALS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(NWID_HORIZONTAL), SetFill(1, 1),
 
		NWidget(WWT_PANEL, COLOUR_BROWN), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetResize(1, 1), SetFill(1, 0), SetScrollbar(WID_GOAL_SCROLLBAR),
 
@@ -269,15 +282,17 @@ static WindowDesc _goals_list_desc(
 
	WDP_AUTO, "list_goals", 500, 127,
 
	WC_GOALS_LIST, WC_NONE,
 
	0,
 
	_nested_goals_list_widgets, lengthof(_nested_goals_list_widgets)
 
);
 

	
 
void ShowGoalsList()
 
void ShowGoalsList(CompanyID company)
 
{
 
	AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, 0);
 
	if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;
 

	
 
	AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, company);
 
}
 

	
 

	
 

	
 
struct GoalQuestionWindow : Window {
 
	char *question;
src/gui.h
Show inline comments
 
@@ -48,13 +48,13 @@ void ShowLandInfo(TileIndex tile);
 
void ShowAboutWindow();
 
void ShowBuildTreesToolbar();
 
void ShowTownDirectory();
 
void ShowIndustryDirectory();
 
void ShowIndustryCargoesWindow();
 
void ShowSubsidiesList();
 
void ShowGoalsList();
 
void ShowGoalsList(CompanyID company);
 
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question);
 
void ShowStoryBook(CompanyID company, uint16 page_id = INVALID_STORY_PAGE);
 

	
 
void ShowEstimatedCostOrIncome(Money cost, int x, int y);
 

	
 
void ShowExtraViewPortWindow(TileIndex tile = INVALID_TILE);
src/lang/english.txt
Show inline comments
 
@@ -2927,16 +2927,18 @@ STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_
 
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_STATUE_OF_COMPANY            :{YELLOW}Build a statue in honour of your company.{}Cost: {CURRENCY_LONG}
 
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS                :{YELLOW}Fund the construction of new commercial buildings in the town.{}Cost: {CURRENCY_LONG}
 
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT          :{YELLOW}Buy 1 year's exclusive transport rights in town. Town authority will only allow passengers and cargo to use your company's stations.{}Cost: {CURRENCY_LONG}
 
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE                        :{YELLOW}Bribe the local authority to increase your rating, at the risk of a severe penalty if caught.{}Cost: {CURRENCY_LONG}
 

	
 
# Goal window
 
STR_GOALS_CAPTION                                               :{WHITE}Goals
 
STR_GOALS_CAPTION                                               :{WHITE}{COMPANY} Goals
 
STR_GOALS_SPECTATOR_CAPTION                                     :{WHITE}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
src/script/api/script_window.hpp
Show inline comments
 
@@ -1336,12 +1336,13 @@ public:
 
		WID_GP_ABORT                                 = ::WID_GP_ABORT,                                 ///< Abort button.
 
	};
 

	
 
	/* automatically generated from ../../widgets/goal_widget.h */
 
	/** Widgets of the #GoalListWindow class. */
 
	enum GoalListWidgets {
 
		WID_GOAL_CAPTION                             = ::WID_GOAL_CAPTION,                             ///< Caption of the window.
 
		WID_GOAL_GOAL                                = ::WID_GOAL_GOAL,                                ///< Goal text column of the goal list.
 
		WID_GOAL_PROGRESS                            = ::WID_GOAL_PROGRESS,                            ///< Goal progress column of the goal list.
 
		WID_GOAL_SCROLLBAR                           = ::WID_GOAL_SCROLLBAR,                           ///< Scrollbar of the goal list.
 
	};
 

	
 
	/** Widgets of the #GoalQuestionWindow class. */
src/story_gui.cpp
Show inline comments
 
@@ -402,13 +402,13 @@ protected:
 
				} else {
 
					ScrollMainWindowToTile((TileIndex)pe.referenced_id);
 
				}
 
				break;
 

	
 
			case SPET_GOAL:
 
				ShowGoalsList();
 
				ShowGoalsList((CompanyID)this->window_number);
 
				break;
 

	
 
			default:
 
				NOT_REACHED();
 
		}
 
	}
src/toolbar_gui.cpp
Show inline comments
 
@@ -652,13 +652,13 @@ static CallBackFunction ToolbarLeagueCli
 
 * @param index Menu entry number.
 
 * @return #CBF_NONE
 
 */
 
static CallBackFunction MenuClickLeague(int index)
 
{
 
	switch (index) {
 
		case 0: ShowGoalsList();               break;
 
		case 0: ShowGoalsList(_local_company); break;
 
		case 1: ShowStoryBook(_local_company); break;
 
		case 2: ShowCompanyLeagueTable();      break;
 
		case 3: ShowPerformanceRatingDetail(); break;
 
		case 4: ShowHighscoreTable();          break;
 
	}
 
	return CBF_NONE;
src/widgets/goal_widget.h
Show inline comments
 
@@ -12,12 +12,13 @@
 

	
 
#ifndef WIDGETS_GOAL_WIDGET_H
 
#define WIDGETS_GOAL_WIDGET_H
 

	
 
/** Widgets of the #GoalListWindow class. */
 
enum GoalListWidgets {
 
	WID_GOAL_CAPTION,   ///< Caption of the window.
 
	WID_GOAL_GOAL,      ///< Goal text column of the goal list.
 
	WID_GOAL_PROGRESS,  ///< Goal progress column of the goal list.
 
	WID_GOAL_SCROLLBAR, ///< Scrollbar of the goal list.
 
};
 

	
 
/** Widgets of the #GoalQuestionWindow class. */
0 comments (0 inline, 0 general)