Changeset - r25039:1deb621cd116
[Not reviewed]
master
0 6 0
Tyler Trahan - 3 years ago 2021-03-11 14:30:29
tyler@tylertrahan.com
Change: Recolour graph windows to brown (#8700)
6 files changed with 96 insertions and 95 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -1386,97 +1386,97 @@ struct AIDebugWindow : public Window {
 
			}
 
		}
 

	
 
		if (!gui_scope) return;
 

	
 
		this->SelectValidDebugCompany();
 

	
 
		ScriptLog::LogData *log = ai_debug_company != INVALID_COMPANY ? this->GetLogPointer() : nullptr;
 
		this->vscroll->SetCount((log == nullptr) ? 0 : log->used);
 

	
 
		/* Update company buttons */
 
		for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
 
			this->SetWidgetDisabledState(i + WID_AID_COMPANY_BUTTON_START, !Company::IsValidAiID(i));
 
			this->SetWidgetLoweredState(i + WID_AID_COMPANY_BUTTON_START, ai_debug_company == i);
 
		}
 

	
 
		this->SetWidgetDisabledState(WID_AID_SCRIPT_GAME, Game::GetGameInstance() == nullptr);
 
		this->SetWidgetLoweredState(WID_AID_SCRIPT_GAME, ai_debug_company == OWNER_DEITY);
 

	
 
		this->SetWidgetLoweredState(WID_AID_BREAK_STR_ON_OFF_BTN, this->break_check_enabled);
 
		this->SetWidgetLoweredState(WID_AID_MATCH_CASE_BTN, this->case_sensitive_break_check);
 

	
 
		this->SetWidgetDisabledState(WID_AID_SETTINGS, ai_debug_company == INVALID_COMPANY);
 
		extern CompanyID _local_company;
 
		this->SetWidgetDisabledState(WID_AID_RELOAD_TOGGLE, ai_debug_company == INVALID_COMPANY || ai_debug_company == OWNER_DEITY || ai_debug_company == _local_company);
 
		this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, ai_debug_company == INVALID_COMPANY ||
 
				(ai_debug_company == OWNER_DEITY ? !Game::IsPaused() : !AI::IsPaused(ai_debug_company)));
 
	}
 

	
 
	void OnResize() override
 
	{
 
		this->vscroll->SetCapacityFromWidget(this, WID_AID_LOG_PANEL);
 
	}
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
const int AIDebugWindow::top_offset = WD_FRAMERECT_TOP + 2;
 
const int AIDebugWindow::bottom_offset = WD_FRAMERECT_BOTTOM;
 
CompanyID AIDebugWindow::ai_debug_company = INVALID_COMPANY;
 
char AIDebugWindow::break_string[MAX_BREAK_STR_STRING_LENGTH] = "";
 
bool AIDebugWindow::break_check_enabled = true;
 
bool AIDebugWindow::case_sensitive_break_check = false;
 
StringFilter AIDebugWindow::break_string_filter(&AIDebugWindow::case_sensitive_break_check);
 

	
 
/** Make a number of rows with buttons for each company for the AI debug window. */
 
NWidgetBase *MakeCompanyButtonRowsAIDebug(int *biggest_index)
 
{
 
	return MakeCompanyButtonRows(biggest_index, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END, 8, STR_AI_DEBUG_SELECT_AI_TOOLTIP);
 
	return MakeCompanyButtonRows(biggest_index, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END, COLOUR_GREY, 8, STR_AI_DEBUG_SELECT_AI_TOOLTIP);
 
}
 

	
 
/**
 
 * Handler for global hotkeys of the AIDebugWindow.
 
 * @param hotkey Hotkey
 
 * @return ES_HANDLED if hotkey was accepted.
 
 */
 
static EventState AIDebugGlobalHotkeys(int hotkey)
 
{
 
	if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
 
	Window *w = ShowAIDebugWindow(INVALID_COMPANY);
 
	if (w == nullptr) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
static Hotkey aidebug_hotkeys[] = {
 
	Hotkey('1', "company_1", WID_AID_COMPANY_BUTTON_START),
 
	Hotkey('2', "company_2", WID_AID_COMPANY_BUTTON_START + 1),
 
	Hotkey('3', "company_3", WID_AID_COMPANY_BUTTON_START + 2),
 
	Hotkey('4', "company_4", WID_AID_COMPANY_BUTTON_START + 3),
 
	Hotkey('5', "company_5", WID_AID_COMPANY_BUTTON_START + 4),
 
	Hotkey('6', "company_6", WID_AID_COMPANY_BUTTON_START + 5),
 
	Hotkey('7', "company_7", WID_AID_COMPANY_BUTTON_START + 6),
 
	Hotkey('8', "company_8", WID_AID_COMPANY_BUTTON_START + 7),
 
	Hotkey('9', "company_9", WID_AID_COMPANY_BUTTON_START + 8),
 
	Hotkey((uint16)0, "company_10", WID_AID_COMPANY_BUTTON_START + 9),
 
	Hotkey((uint16)0, "company_11", WID_AID_COMPANY_BUTTON_START + 10),
 
	Hotkey((uint16)0, "company_12", WID_AID_COMPANY_BUTTON_START + 11),
 
	Hotkey((uint16)0, "company_13", WID_AID_COMPANY_BUTTON_START + 12),
 
	Hotkey((uint16)0, "company_14", WID_AID_COMPANY_BUTTON_START + 13),
 
	Hotkey((uint16)0, "company_15", WID_AID_COMPANY_BUTTON_START + 14),
 
	Hotkey('S', "settings", WID_AID_SETTINGS),
 
	Hotkey('0', "game_script", WID_AID_SCRIPT_GAME),
 
	Hotkey((uint16)0, "reload", WID_AID_RELOAD_TOGGLE),
 
	Hotkey('B', "break_toggle", WID_AID_BREAK_STR_ON_OFF_BTN),
 
	Hotkey('F', "break_string", WID_AID_BREAK_STR_EDIT_BOX),
 
	Hotkey('C', "match_case", WID_AID_MATCH_CASE_BTN),
 
	Hotkey(WKC_RETURN, "continue", WID_AID_CONTINUE_BTN),
 
	HOTKEY_LIST_END
 
};
 
HotkeyList AIDebugWindow::hotkeys("aidebug", aidebug_hotkeys, AIDebugGlobalHotkeys);
 

	
 
/** Widgets for the AI debug window. */
 
static const NWidgetPart _nested_ai_debug_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
src/graph_gui.cpp
Show inline comments
 
@@ -68,114 +68,114 @@ struct GraphLegendWindow : Window {
 
		DrawCompanyIcon(cid, rtl ? r.right - d.width - 2 : r.left + 2, r.top + (r.bottom - r.top - d.height) / 2);
 

	
 
		SetDParam(0, cid);
 
		SetDParam(1, cid);
 
		DrawString(r.left + (rtl ? (uint)WD_FRAMERECT_LEFT : (d.width + 4)), r.right - (rtl ? (d.width + 4) : (uint)WD_FRAMERECT_RIGHT), r.top + (r.bottom - r.top + 1 - FONT_HEIGHT_NORMAL) / 2, STR_COMPANY_NAME_COMPANY_NUM, HasBit(_legend_excluded_companies, cid) ? TC_BLACK : TC_WHITE);
 
	}
 

	
 
	void OnClick(Point pt, int widget, int click_count) override
 
	{
 
		if (!IsInsideMM(widget, WID_GL_FIRST_COMPANY, MAX_COMPANIES + WID_GL_FIRST_COMPANY)) return;
 

	
 
		ToggleBit(_legend_excluded_companies, widget - WID_GL_FIRST_COMPANY);
 
		this->ToggleWidgetLoweredState(widget);
 
		this->SetDirty();
 
		InvalidateWindowData(WC_INCOME_GRAPH, 0);
 
		InvalidateWindowData(WC_OPERATING_PROFIT, 0);
 
		InvalidateWindowData(WC_DELIVERED_CARGO, 0);
 
		InvalidateWindowData(WC_PERFORMANCE_HISTORY, 0);
 
		InvalidateWindowData(WC_COMPANY_VALUE, 0);
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	void OnInvalidateData(int data = 0, bool gui_scope = true) override
 
	{
 
		if (!gui_scope) return;
 
		if (Company::IsValidID(data)) return;
 

	
 
		SetBit(_legend_excluded_companies, data);
 
		this->RaiseWidget(data + WID_GL_FIRST_COMPANY);
 
	}
 
};
 

	
 
/**
 
 * Construct a vertical list of buttons, one for each company.
 
 * @param biggest_index Storage for collecting the biggest index used in the returned tree.
 
 * @return Panel with company buttons.
 
 * @post \c *biggest_index contains the largest used index in the tree.
 
 */
 
static NWidgetBase *MakeNWidgetCompanyLines(int *biggest_index)
 
{
 
	NWidgetVertical *vert = new NWidgetVertical();
 
	uint line_height = std::max<uint>(GetSpriteSize(SPR_COMPANY_ICON).height, FONT_HEIGHT_NORMAL) + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 

	
 
	for (int widnum = WID_GL_FIRST_COMPANY; widnum <= WID_GL_LAST_COMPANY; widnum++) {
 
		NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
 
		NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_BROWN, widnum);
 
		panel->SetMinimalSize(246, line_height);
 
		panel->SetFill(1, 0);
 
		panel->SetDataTip(0x0, STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP);
 
		vert->Add(panel);
 
	}
 
	*biggest_index = WID_GL_LAST_COMPANY;
 
	return vert;
 
}
 

	
 
static const NWidgetPart _nested_graph_legend_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_KEY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_KEY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, WID_GL_BACKGROUND),
 
	NWidget(WWT_PANEL, COLOUR_BROWN, WID_GL_BACKGROUND),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, 2),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(NWID_SPACER), SetMinimalSize(2, 0),
 
			NWidgetFunction(MakeNWidgetCompanyLines),
 
			NWidget(NWID_SPACER), SetMinimalSize(2, 0),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
static WindowDesc _graph_legend_desc(
 
	WDP_AUTO, "graph_legend", 0, 0,
 
	WC_GRAPH_LEGEND, WC_NONE,
 
	0,
 
	_nested_graph_legend_widgets, lengthof(_nested_graph_legend_widgets)
 
);
 

	
 
static void ShowGraphLegend()
 
{
 
	AllocateWindowDescFront<GraphLegendWindow>(&_graph_legend_desc, 0);
 
}
 

	
 
/** Contains the interval of a graph's data. */
 
struct ValuesInterval {
 
	OverflowSafeInt64 highest; ///< Highest value of this interval. Must be zero or greater.
 
	OverflowSafeInt64 lowest;  ///< Lowest value of this interval. Must be zero or less.
 
};
 

	
 
/******************/
 
/* BASE OF GRAPHS */
 
/*****************/
 

	
 
struct BaseGraphWindow : Window {
 
protected:
 
	static const int GRAPH_MAX_DATASETS     =  64;
 
	static const int GRAPH_BASE_COLOUR      =  GREY_SCALE(2);
 
	static const int GRAPH_GRID_COLOUR      =  GREY_SCALE(3);
 
	static const int GRAPH_AXIS_LINE_COLOUR =  GREY_SCALE(1);
 
	static const int GRAPH_ZERO_LINE_COLOUR =  GREY_SCALE(8);
 
	static const int GRAPH_YEAR_LINE_COLOUR =  GREY_SCALE(5);
 
	static const int GRAPH_NUM_MONTHS       =  24; ///< Number of months displayed in the graph.
 

	
 
	static const TextColour GRAPH_AXIS_LABEL_COLOUR = TC_BLACK; ///< colour of the graph axis label.
 

	
 
	static const int MIN_GRAPH_NUM_LINES_Y  =   9; ///< Minimal number of horizontal lines to draw.
 
	static const int MIN_GRID_PIXEL_SIZE    =  20; ///< Minimum distance between graph lines.
 

	
 
	uint64 excluded_data; ///< bitmask of the datasets that shouldn't be displayed.
 
	byte num_dataset;
 
@@ -589,314 +589,314 @@ public:
 
		if (!initialize && this->excluded_data == excluded_companies && this->num_on_x_axis == nums &&
 
				this->year == yr && this->month == mo) {
 
			/* There's no reason to get new stats */
 
			return;
 
		}
 

	
 
		this->excluded_data = excluded_companies;
 
		this->num_on_x_axis = nums;
 
		this->year = yr;
 
		this->month = mo;
 

	
 
		int numd = 0;
 
		for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
 
			const Company *c = Company::GetIfValid(k);
 
			if (c != nullptr) {
 
				this->colours[numd] = _colour_gradient[c->colour][6];
 
				for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
 
					this->cost[numd][i] = (j >= c->num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(c, j);
 
					i++;
 
				}
 
			}
 
			numd++;
 
		}
 

	
 
		this->num_dataset = numd;
 
	}
 
};
 

	
 

	
 
/********************/
 
/* OPERATING PROFIT */
 
/********************/
 

	
 
struct OperatingProfitGraphWindow : BaseGraphWindow {
 
	OperatingProfitGraphWindow(WindowDesc *desc, WindowNumber window_number) :
 
			BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_CURRENCY_SHORT)
 
	{
 
		this->InitializeWindow(window_number);
 
	}
 

	
 
	OverflowSafeInt64 GetGraphData(const Company *c, int j) override
 
	{
 
		return c->old_economy[j].income + c->old_economy[j].expenses;
 
	}
 
};
 

	
 
static const NWidgetPart _nested_operating_profit_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_OPERATING_PROFIT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_OPERATING_PROFIT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, WID_CV_BACKGROUND),
 
	NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(WWT_EMPTY, COLOUR_GREY, WID_CV_GRAPH), SetMinimalSize(576, 160), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 160), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(NWID_VERTICAL),
 
				NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
 
				NWidget(WWT_RESIZEBOX, COLOUR_GREY, WID_CV_RESIZE),
 
				NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE),
 
			EndContainer(),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
static WindowDesc _operating_profit_desc(
 
	WDP_AUTO, "graph_operating_profit", 0, 0,
 
	WC_OPERATING_PROFIT, WC_NONE,
 
	0,
 
	_nested_operating_profit_widgets, lengthof(_nested_operating_profit_widgets)
 
);
 

	
 

	
 
void ShowOperatingProfitGraph()
 
{
 
	AllocateWindowDescFront<OperatingProfitGraphWindow>(&_operating_profit_desc, 0);
 
}
 

	
 

	
 
/****************/
 
/* INCOME GRAPH */
 
/****************/
 

	
 
struct IncomeGraphWindow : BaseGraphWindow {
 
	IncomeGraphWindow(WindowDesc *desc, WindowNumber window_number) :
 
			BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_CURRENCY_SHORT)
 
	{
 
		this->InitializeWindow(window_number);
 
	}
 

	
 
	OverflowSafeInt64 GetGraphData(const Company *c, int j) override
 
	{
 
		return c->old_economy[j].income;
 
	}
 
};
 

	
 
static const NWidgetPart _nested_income_graph_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_INCOME_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_INCOME_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, WID_CV_BACKGROUND),
 
	NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(WWT_EMPTY, COLOUR_GREY, WID_CV_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(NWID_VERTICAL),
 
				NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
 
				NWidget(WWT_RESIZEBOX, COLOUR_GREY, WID_CV_RESIZE),
 
				NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE),
 
			EndContainer(),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
static WindowDesc _income_graph_desc(
 
	WDP_AUTO, "graph_income", 0, 0,
 
	WC_INCOME_GRAPH, WC_NONE,
 
	0,
 
	_nested_income_graph_widgets, lengthof(_nested_income_graph_widgets)
 
);
 

	
 
void ShowIncomeGraph()
 
{
 
	AllocateWindowDescFront<IncomeGraphWindow>(&_income_graph_desc, 0);
 
}
 

	
 
/*******************/
 
/* DELIVERED CARGO */
 
/*******************/
 

	
 
struct DeliveredCargoGraphWindow : BaseGraphWindow {
 
	DeliveredCargoGraphWindow(WindowDesc *desc, WindowNumber window_number) :
 
			BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_COMMA)
 
	{
 
		this->InitializeWindow(window_number);
 
	}
 

	
 
	OverflowSafeInt64 GetGraphData(const Company *c, int j) override
 
	{
 
		return c->old_economy[j].delivered_cargo.GetSum<OverflowSafeInt64>();
 
	}
 
};
 

	
 
static const NWidgetPart _nested_delivered_cargo_graph_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_CARGO_DELIVERED_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_CARGO_DELIVERED_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, WID_CV_BACKGROUND),
 
	NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(WWT_EMPTY, COLOUR_GREY, WID_CV_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(NWID_VERTICAL),
 
				NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
 
				NWidget(WWT_RESIZEBOX, COLOUR_GREY, WID_CV_RESIZE),
 
				NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE),
 
			EndContainer(),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
static WindowDesc _delivered_cargo_graph_desc(
 
	WDP_AUTO, "graph_delivered_cargo", 0, 0,
 
	WC_DELIVERED_CARGO, WC_NONE,
 
	0,
 
	_nested_delivered_cargo_graph_widgets, lengthof(_nested_delivered_cargo_graph_widgets)
 
);
 

	
 
void ShowDeliveredCargoGraph()
 
{
 
	AllocateWindowDescFront<DeliveredCargoGraphWindow>(&_delivered_cargo_graph_desc, 0);
 
}
 

	
 
/***********************/
 
/* PERFORMANCE HISTORY */
 
/***********************/
 

	
 
struct PerformanceHistoryGraphWindow : BaseGraphWindow {
 
	PerformanceHistoryGraphWindow(WindowDesc *desc, WindowNumber window_number) :
 
			BaseGraphWindow(desc, WID_PHG_GRAPH, STR_JUST_COMMA)
 
	{
 
		this->InitializeWindow(window_number);
 
	}
 

	
 
	OverflowSafeInt64 GetGraphData(const Company *c, int j) override
 
	{
 
		return c->old_economy[j].performance_history;
 
	}
 

	
 
	void OnClick(Point pt, int widget, int click_count) override
 
	{
 
		if (widget == WID_PHG_DETAILED_PERFORMANCE) ShowPerformanceRatingDetail();
 
		this->BaseGraphWindow::OnClick(pt, widget, click_count);
 
	}
 
};
 

	
 
static const NWidgetPart _nested_performance_history_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_COMPANY_PERFORMANCE_RATINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PHG_DETAILED_PERFORMANCE), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_PERFORMANCE_DETAIL_KEY, STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PHG_KEY), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_COMPANY_PERFORMANCE_RATINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_PHG_DETAILED_PERFORMANCE), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_PERFORMANCE_DETAIL_KEY, STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_PHG_KEY), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, WID_PHG_BACKGROUND),
 
	NWidget(WWT_PANEL, COLOUR_BROWN, WID_PHG_BACKGROUND),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(WWT_EMPTY, COLOUR_GREY, WID_PHG_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(WWT_EMPTY, COLOUR_BROWN, WID_PHG_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(NWID_VERTICAL),
 
				NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
 
				NWidget(WWT_RESIZEBOX, COLOUR_GREY, WID_PHG_RESIZE),
 
				NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_PHG_RESIZE),
 
			EndContainer(),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
static WindowDesc _performance_history_desc(
 
	WDP_AUTO, "graph_performance", 0, 0,
 
	WC_PERFORMANCE_HISTORY, WC_NONE,
 
	0,
 
	_nested_performance_history_widgets, lengthof(_nested_performance_history_widgets)
 
);
 

	
 
void ShowPerformanceHistoryGraph()
 
{
 
	AllocateWindowDescFront<PerformanceHistoryGraphWindow>(&_performance_history_desc, 0);
 
}
 

	
 
/*****************/
 
/* COMPANY VALUE */
 
/*****************/
 

	
 
struct CompanyValueGraphWindow : BaseGraphWindow {
 
	CompanyValueGraphWindow(WindowDesc *desc, WindowNumber window_number) :
 
			BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_CURRENCY_SHORT)
 
	{
 
		this->InitializeWindow(window_number);
 
	}
 

	
 
	OverflowSafeInt64 GetGraphData(const Company *c, int j) override
 
	{
 
		return c->old_economy[j].company_value;
 
	}
 
};
 

	
 
static const NWidgetPart _nested_company_value_graph_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_COMPANY_VALUES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_COMPANY_VALUES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, WID_CV_BACKGROUND),
 
	NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(WWT_EMPTY, COLOUR_GREY, WID_CV_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(NWID_VERTICAL),
 
				NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
 
				NWidget(WWT_RESIZEBOX, COLOUR_GREY, WID_CV_RESIZE),
 
				NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE),
 
			EndContainer(),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
static WindowDesc _company_value_graph_desc(
 
	WDP_AUTO, "graph_company_value", 0, 0,
 
	WC_COMPANY_VALUE, WC_NONE,
 
	0,
 
	_nested_company_value_graph_widgets, lengthof(_nested_company_value_graph_widgets)
 
);
 

	
 
void ShowCompanyValueGraph()
 
{
 
	AllocateWindowDescFront<CompanyValueGraphWindow>(&_company_value_graph_desc, 0);
 
}
 

	
 
/*****************/
 
/* PAYMENT RATES */
 
/*****************/
 

	
 
struct PaymentRatesGraphWindow : BaseGraphWindow {
 
	uint line_height;   ///< Pixel height of each cargo type row.
 
	Scrollbar *vscroll; ///< Cargo list scrollbar.
 

	
 
	PaymentRatesGraphWindow(WindowDesc *desc, WindowNumber window_number) :
 
			BaseGraphWindow(desc, WID_CPR_GRAPH, STR_JUST_CURRENCY_SHORT)
 
	{
 
		this->num_on_x_axis = 20;
 
		this->num_vert_lines = 20;
 
		this->month = 0xFF;
 
		this->x_values_start     = 10;
 
		this->x_values_increment = 10;
 

	
 
		this->CreateNestedTree();
 
		this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
 
		this->vscroll->SetCount(_sorted_standard_cargo_specs_size);
 

	
 
		/* Initialise the dataset */
 
		this->OnHundredthTick();
 

	
 
		this->FinishInitNested(window_number);
 
	}
 

	
 
	void UpdateExcludedData()
 
	{
 
		this->excluded_data = 0;
 

	
 
@@ -909,223 +909,223 @@ struct PaymentRatesGraphWindow : BaseGra
 
	}
 

	
 
	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
 
	{
 
		if (widget != WID_CPR_MATRIX) {
 
			BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
 
			return;
 
		}
 

	
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 
			SetDParam(0, cs->name);
 
			Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
 
			d.width += 14; // colour field
 
			d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
			d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
			*size = maxdim(d, *size);
 
		}
 

	
 
		this->line_height = size->height;
 
		size->height = this->line_height * 11; /* Default number of cargo types in most climates. */
 
		resize->width = 0;
 
		resize->height = this->line_height;
 
	}
 

	
 
	void DrawWidget(const Rect &r, int widget) const override
 
	{
 
		if (widget != WID_CPR_MATRIX) {
 
			BaseGraphWindow::DrawWidget(r, widget);
 
			return;
 
		}
 

	
 
		bool rtl = _current_text_dir == TD_RTL;
 

	
 
		int x = r.left + WD_FRAMERECT_LEFT;
 
		int y = r.top;
 

	
 
		int pos = this->vscroll->GetPosition();
 
		int max = pos + this->vscroll->GetCapacity();
 

	
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 
			if (pos-- > 0) continue;
 
			if (--max < 0) break;
 

	
 
			bool lowered = !HasBit(_legend_excluded_cargo, cs->Index());
 

	
 
			/* Redraw box if lowered */
 
			if (lowered) DrawFrameRect(r.left, y, r.right, y + this->line_height - 1, COLOUR_ORANGE, lowered ? FR_LOWERED : FR_NONE);
 
			if (lowered) DrawFrameRect(r.left, y, r.right, y + this->line_height - 1, COLOUR_BROWN, lowered ? FR_LOWERED : FR_NONE);
 

	
 
			byte clk_dif = lowered ? 1 : 0;
 
			int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
 

	
 
			GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, PC_BLACK);
 
			GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
 
			SetDParam(0, cs->name);
 
			DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
 

	
 
			y += this->line_height;
 
		}
 
	}
 

	
 
	void OnClick(Point pt, int widget, int click_count) override
 
	{
 
		switch (widget) {
 
			case WID_CPR_ENABLE_CARGOES:
 
				/* Remove all cargoes from the excluded lists. */
 
				_legend_excluded_cargo = 0;
 
				this->excluded_data = 0;
 
				this->SetDirty();
 
				break;
 

	
 
			case WID_CPR_DISABLE_CARGOES: {
 
				/* Add all cargoes to the excluded lists. */
 
				int i = 0;
 
				const CargoSpec *cs;
 
				FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 
					SetBit(_legend_excluded_cargo, cs->Index());
 
					SetBit(this->excluded_data, i);
 
					i++;
 
				}
 
				this->SetDirty();
 
				break;
 
			}
 

	
 
			case WID_CPR_MATRIX: {
 
				uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CPR_MATRIX, 0, this->line_height);
 
				if (row >= this->vscroll->GetCount()) return;
 

	
 
				const CargoSpec *cs;
 
				FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 
					if (row-- > 0) continue;
 

	
 
					ToggleBit(_legend_excluded_cargo, cs->Index());
 
					this->UpdateExcludedData();
 
					this->SetDirty();
 
					break;
 
				}
 
				break;
 
			}
 
		}
 
	}
 

	
 
	void OnResize() override
 
	{
 
		this->vscroll->SetCapacityFromWidget(this, WID_CPR_MATRIX);
 
	}
 

	
 
	void OnGameTick() override
 
	{
 
		/* Override default OnGameTick */
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	void OnInvalidateData(int data = 0, bool gui_scope = true) override
 
	{
 
		if (!gui_scope) return;
 
		this->OnHundredthTick();
 
	}
 

	
 
	void OnHundredthTick() override
 
	{
 
		this->UpdateExcludedData();
 

	
 
		int i = 0;
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 
			this->colours[i] = cs->legend_colour;
 
			for (uint j = 0; j != 20; j++) {
 
				this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
 
			}
 
			i++;
 
		}
 
		this->num_dataset = i;
 
	}
 
};
 

	
 
static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, WID_CPR_BACKGROUND), SetMinimalSize(568, 128),
 
	NWidget(WWT_PANEL, COLOUR_BROWN, WID_CPR_BACKGROUND), SetMinimalSize(568, 128),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
 
			NWidget(WWT_TEXT, COLOUR_GREY, WID_CPR_HEADER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE, STR_NULL),
 
			NWidget(WWT_TEXT, COLOUR_BROWN, WID_CPR_HEADER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE, STR_NULL),
 
			NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
 
		EndContainer(),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(WWT_EMPTY, COLOUR_GREY, WID_CPR_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CPR_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1),
 
			NWidget(NWID_VERTICAL),
 
				NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
 
				NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CPR_ENABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0),
 
				NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CPR_DISABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0),
 
				NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CPR_ENABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0),
 
				NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CPR_DISABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0),
 
				NWidget(NWID_SPACER), SetMinimalSize(0, 4),
 
				NWidget(NWID_HORIZONTAL),
 
					NWidget(WWT_MATRIX, COLOUR_ORANGE, WID_CPR_MATRIX), SetResize(0, 2), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), SetScrollbar(WID_CPR_MATRIX_SCROLLBAR),
 
					NWidget(NWID_VSCROLLBAR, COLOUR_ORANGE, WID_CPR_MATRIX_SCROLLBAR),
 
					NWidget(WWT_MATRIX, COLOUR_BROWN, WID_CPR_MATRIX), SetResize(0, 2), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), SetScrollbar(WID_CPR_MATRIX_SCROLLBAR),
 
					NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_CPR_MATRIX_SCROLLBAR),
 
				EndContainer(),
 
				NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
 
			EndContainer(),
 
			NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
 
		EndContainer(),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(NWID_SPACER), SetMinimalSize(WD_RESIZEBOX_WIDTH, 0), SetFill(1, 0), SetResize(1, 0),
 
			NWidget(WWT_TEXT, COLOUR_GREY, WID_CPR_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL, STR_NULL),
 
			NWidget(WWT_TEXT, COLOUR_BROWN, WID_CPR_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL, STR_NULL),
 
			NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
 
			NWidget(WWT_RESIZEBOX, COLOUR_GREY, WID_CPR_RESIZE),
 
			NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CPR_RESIZE),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
static WindowDesc _cargo_payment_rates_desc(
 
	WDP_AUTO, "graph_cargo_payment_rates", 0, 0,
 
	WC_PAYMENT_RATES, WC_NONE,
 
	0,
 
	_nested_cargo_payment_rates_widgets, lengthof(_nested_cargo_payment_rates_widgets)
 
);
 

	
 

	
 
void ShowCargoPaymentRates()
 
{
 
	AllocateWindowDescFront<PaymentRatesGraphWindow>(&_cargo_payment_rates_desc, 0);
 
}
 

	
 
/************************/
 
/* COMPANY LEAGUE TABLE */
 
/************************/
 

	
 
static const StringID _performance_titles[] = {
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_PRESIDENT,
 
	STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TYCOON,
 
};
 

	
 
static inline StringID GetPerformanceTitleFromValue(uint value)
 
{
 
	return _performance_titles[std::min(value, 1000u) >> 6];
 
}
 

	
 
class CompanyLeagueWindow : public Window {
 
private:
 
	GUIList<const Company*> companies;
 
@@ -1219,102 +1219,102 @@ public:
 
				widest_title = i;
 
				widest_width = width;
 
			}
 
		}
 

	
 
		Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
 
		this->icon_width = d.width + 2;
 
		this->line_height = std::max<int>(d.height + 2, FONT_HEIGHT_NORMAL);
 

	
 
		for (const Company *c : Company::Iterate()) {
 
			SetDParam(0, c->index);
 
			SetDParam(1, c->index);
 
			SetDParam(2, _performance_titles[widest_title]);
 
			widest_width = std::max(widest_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_NAME).width);
 
		}
 

	
 
		this->text_width = widest_width + 30; // Keep some extra spacing
 

	
 
		size->width = WD_FRAMERECT_LEFT + this->ordinal_width + WD_FRAMERECT_RIGHT + this->icon_width + WD_FRAMERECT_LEFT + this->text_width + WD_FRAMERECT_RIGHT;
 
		size->height = WD_FRAMERECT_TOP + this->line_height * MAX_COMPANIES + WD_FRAMERECT_BOTTOM;
 
	}
 

	
 

	
 
	void OnGameTick() override
 
	{
 
		if (this->companies.NeedResort()) {
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	void OnInvalidateData(int data = 0, bool gui_scope = true) override
 
	{
 
		if (data == 0) {
 
			/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
 
			this->companies.ForceRebuild();
 
		} else {
 
			this->companies.ForceResort();
 
		}
 
	}
 
};
 

	
 
static const NWidgetPart _nested_company_league_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_COMPANY_LEAGUE_TABLE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_COMPANY_LEAGUE_TABLE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, WID_CL_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM),
 
	NWidget(WWT_PANEL, COLOUR_BROWN, WID_CL_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM),
 
};
 

	
 
static WindowDesc _company_league_desc(
 
	WDP_AUTO, "league", 0, 0,
 
	WC_COMPANY_LEAGUE, WC_NONE,
 
	0,
 
	_nested_company_league_widgets, lengthof(_nested_company_league_widgets)
 
);
 

	
 
void ShowCompanyLeagueTable()
 
{
 
	AllocateWindowDescFront<CompanyLeagueWindow>(&_company_league_desc, 0);
 
}
 

	
 
/*****************************/
 
/* PERFORMANCE RATING DETAIL */
 
/*****************************/
 

	
 
struct PerformanceRatingDetailWindow : Window {
 
	static CompanyID company;
 
	int timeout;
 

	
 
	PerformanceRatingDetailWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
 
	{
 
		this->UpdateCompanyStats();
 

	
 
		this->InitNested(window_number);
 
		this->OnInvalidateData(INVALID_COMPANY);
 
	}
 

	
 
	void UpdateCompanyStats()
 
	{
 
		/* Update all company stats with the current data
 
		 * (this is because _score_info is not saved to a savegame) */
 
		for (Company *c : Company::Iterate()) {
 
			UpdateCompanyRatingAndValue(c, false);
 
		}
 

	
 
		this->timeout = DAY_TICKS * 5;
 
	}
 

	
 
	uint score_info_left;
 
	uint score_info_right;
 
	uint bar_left;
 
	uint bar_right;
 
	uint bar_width;
 
	uint bar_height;
 
	uint score_detail_left;
 
@@ -1494,93 +1494,93 @@ struct PerformanceRatingDetailWindow : W
 
		}
 

	
 
		/* Check if the currently selected company is still active. */
 
		if (this->company != INVALID_COMPANY && !Company::IsValidID(this->company)) {
 
			/* Raise the widget for the previous selection. */
 
			this->RaiseWidget(this->company + WID_PRD_COMPANY_FIRST);
 
			this->company = INVALID_COMPANY;
 
		}
 

	
 
		if (this->company == INVALID_COMPANY) {
 
			for (const Company *c : Company::Iterate()) {
 
				this->company = c->index;
 
				break;
 
			}
 
		}
 

	
 
		/* Make sure the widget is lowered */
 
		this->LowerWidget(this->company + WID_PRD_COMPANY_FIRST);
 
	}
 
};
 

	
 
CompanyID PerformanceRatingDetailWindow::company = INVALID_COMPANY;
 

	
 
/**
 
 * Make a vertical list of panels for outputting score details.
 
 * @param biggest_index Storage for collecting the biggest index used in the returned tree.
 
 * @return Panel with performance details.
 
 * @post \c *biggest_index contains the largest used index in the tree.
 
 */
 
static NWidgetBase *MakePerformanceDetailPanels(int *biggest_index)
 
{
 
	const StringID performance_tips[] = {
 
		STR_PERFORMANCE_DETAIL_VEHICLES_TOOLTIP,
 
		STR_PERFORMANCE_DETAIL_STATIONS_TOOLTIP,
 
		STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP,
 
		STR_PERFORMANCE_DETAIL_MIN_INCOME_TOOLTIP,
 
		STR_PERFORMANCE_DETAIL_MAX_INCOME_TOOLTIP,
 
		STR_PERFORMANCE_DETAIL_DELIVERED_TOOLTIP,
 
		STR_PERFORMANCE_DETAIL_CARGO_TOOLTIP,
 
		STR_PERFORMANCE_DETAIL_MONEY_TOOLTIP,
 
		STR_PERFORMANCE_DETAIL_LOAN_TOOLTIP,
 
		STR_PERFORMANCE_DETAIL_TOTAL_TOOLTIP,
 
	};
 

	
 
	static_assert(lengthof(performance_tips) == SCORE_END - SCORE_BEGIN);
 

	
 
	NWidgetVertical *vert = new NWidgetVertical(NC_EQUALSIZE);
 
	for (int widnum = WID_PRD_SCORE_FIRST; widnum <= WID_PRD_SCORE_LAST; widnum++) {
 
		NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
 
		NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_BROWN, widnum);
 
		panel->SetFill(1, 1);
 
		panel->SetDataTip(0x0, performance_tips[widnum - WID_PRD_SCORE_FIRST]);
 
		vert->Add(panel);
 
	}
 
	*biggest_index = WID_PRD_SCORE_LAST;
 
	return vert;
 
}
 

	
 
/** Make a number of rows with buttons for each company for the performance rating detail window. */
 
NWidgetBase *MakeCompanyButtonRowsGraphGUI(int *biggest_index)
 
{
 
	return MakeCompanyButtonRows(biggest_index, WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST, 8, STR_PERFORMANCE_DETAIL_SELECT_COMPANY_TOOLTIP);
 
	return MakeCompanyButtonRows(biggest_index, WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST, COLOUR_BROWN, 8, STR_PERFORMANCE_DETAIL_SELECT_COMPANY_TOOLTIP);
 
}
 

	
 
static const NWidgetPart _nested_performance_rating_detail_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_PERFORMANCE_DETAIL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_PERFORMANCE_DETAIL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY),
 
	NWidget(WWT_PANEL, COLOUR_BROWN),
 
		NWidgetFunction(MakeCompanyButtonRowsGraphGUI), SetPadding(0, 1, 1, 2),
 
	EndContainer(),
 
	NWidgetFunction(MakePerformanceDetailPanels),
 
};
 

	
 
static WindowDesc _performance_rating_detail_desc(
 
	WDP_AUTO, "league_details", 0, 0,
 
	WC_PERFORMANCE_DETAIL, WC_NONE,
 
	0,
 
	_nested_performance_rating_detail_widgets, lengthof(_nested_performance_rating_detail_widgets)
 
);
 

	
 
void ShowPerformanceRatingDetail()
 
{
 
	AllocateWindowDescFront<PerformanceRatingDetailWindow>(&_performance_rating_detail_desc, 0);
 
}
 

	
 
void InitializeGraphGui()
 
{
 
	_legend_excluded_companies = 0;
 
	_legend_excluded_cargo = 0;
 
}
src/linkgraph/linkgraph_gui.cpp
Show inline comments
 
@@ -330,97 +330,97 @@ void LinkGraphOverlay::DrawStationDots(c
 
	w1++;
 
	w2++;
 
	GfxDrawLine(x - w1, y - w1, x + w2, y - w1, border_colour);
 
	GfxDrawLine(x - w1, y + w2, x + w2, y + w2, border_colour);
 
	GfxDrawLine(x - w1, y - w1, x - w1, y + w2, border_colour);
 
	GfxDrawLine(x + w2, y - w1, x + w2, y + w2, border_colour);
 
}
 

	
 
/**
 
 * Determine the middle of a station in the current window.
 
 * @param st The station we're looking for.
 
 * @return Middle point of the station in the current window.
 
 */
 
Point LinkGraphOverlay::GetStationMiddle(const Station *st) const
 
{
 
	if (this->window->viewport != nullptr) {
 
		return GetViewportStationMiddle(this->window->viewport, st);
 
	} else {
 
		/* assume this is a smallmap */
 
		return static_cast<const SmallMapWindow *>(this->window)->GetStationMiddle(st);
 
	}
 
}
 

	
 
/**
 
 * Set a new cargo mask and rebuild the cache.
 
 * @param cargo_mask New cargo mask.
 
 */
 
void LinkGraphOverlay::SetCargoMask(CargoTypes cargo_mask)
 
{
 
	this->cargo_mask = cargo_mask;
 
	this->RebuildCache();
 
	this->window->GetWidget<NWidgetBase>(this->widget_id)->SetDirty(this->window);
 
}
 

	
 
/**
 
 * Set a new company mask and rebuild the cache.
 
 * @param company_mask New company mask.
 
 */
 
void LinkGraphOverlay::SetCompanyMask(uint32 company_mask)
 
{
 
	this->company_mask = company_mask;
 
	this->RebuildCache();
 
	this->window->GetWidget<NWidgetBase>(this->widget_id)->SetDirty(this->window);
 
}
 

	
 
/** Make a number of rows with buttons for each company for the linkgraph legend window. */
 
NWidgetBase *MakeCompanyButtonRowsLinkGraphGUI(int *biggest_index)
 
{
 
	return MakeCompanyButtonRows(biggest_index, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST, 3, STR_NULL);
 
	return MakeCompanyButtonRows(biggest_index, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST, COLOUR_GREY, 3, STR_NULL);
 
}
 

	
 
NWidgetBase *MakeSaturationLegendLinkGraphGUI(int *biggest_index)
 
{
 
	NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE);
 
	for (uint i = 0; i < lengthof(LinkGraphOverlay::LINK_COLOURS); ++i) {
 
		NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_DARK_GREEN, i + WID_LGL_SATURATION_FIRST);
 
		wid->SetMinimalSize(50, FONT_HEIGHT_SMALL);
 
		wid->SetFill(1, 1);
 
		wid->SetResize(0, 0);
 
		panel->Add(wid);
 
	}
 
	*biggest_index = WID_LGL_SATURATION_LAST;
 
	return panel;
 
}
 

	
 
NWidgetBase *MakeCargoesLegendLinkGraphGUI(int *biggest_index)
 
{
 
	static const uint ENTRIES_PER_ROW = CeilDiv(NUM_CARGO, 5);
 
	NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE);
 
	NWidgetHorizontal *row = nullptr;
 
	for (uint i = 0; i < NUM_CARGO; ++i) {
 
		if (i % ENTRIES_PER_ROW == 0) {
 
			if (row) panel->Add(row);
 
			row = new NWidgetHorizontal(NC_EQUALSIZE);
 
		}
 
		NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, i + WID_LGL_CARGO_FIRST);
 
		wid->SetMinimalSize(25, FONT_HEIGHT_SMALL);
 
		wid->SetFill(1, 1);
 
		wid->SetResize(0, 0);
 
		row->Add(wid);
 
	}
 
	/* Fill up last row */
 
	for (uint i = 0; i < 4 - (NUM_CARGO - 1) % 5; ++i) {
 
		NWidgetSpacer *spc = new NWidgetSpacer(25, FONT_HEIGHT_SMALL);
 
		spc->SetFill(1, 1);
 
		spc->SetResize(0, 0);
 
		row->Add(spc);
 
	}
 
	panel->Add(row);
 
	*biggest_index = WID_LGL_CARGO_LAST;
 
	return panel;
 
}
 

	
 

	
 
static const NWidgetPart _nested_linkgraph_legend_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
src/signs_gui.cpp
Show inline comments
 
@@ -312,119 +312,119 @@ struct SignListWindow : Window, SignList
 
	void OnHundredthTick() override
 
	{
 
		this->BuildSortSignList();
 
		this->SetDirty();
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	void OnInvalidateData(int data = 0, bool gui_scope = true) override
 
	{
 
		/* When there is a filter string, we always need to rebuild the list even if
 
		 * the amount of signs in total is unchanged, as the subset of signs that is
 
		 * accepted by the filter might has changed. */
 
		if (data == 0 || data == -1 || !this->string_filter.IsEmpty()) { // New or deleted sign, changed visibility setting or there is a filter string
 
			/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
 
			this->signs.ForceRebuild();
 
		} else { // Change of sign contents while there is no filter string
 
			this->signs.ForceResort();
 
		}
 
	}
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
/**
 
 * Handler for global hotkeys of the SignListWindow.
 
 * @param hotkey Hotkey
 
 * @return ES_HANDLED if hotkey was accepted.
 
 */
 
static EventState SignListGlobalHotkeys(int hotkey)
 
{
 
	if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
 
	Window *w = ShowSignList();
 
	if (w == nullptr) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
static Hotkey signlist_hotkeys[] = {
 
	Hotkey('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX),
 
	HOTKEY_LIST_END
 
};
 
HotkeyList SignListWindow::hotkeys("signlist", signlist_hotkeys, SignListGlobalHotkeys);
 

	
 
static const NWidgetPart _nested_sign_list_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY, WID_SIL_CAPTION), SetDataTip(STR_SIGN_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SIL_CAPTION), SetDataTip(STR_SIGN_LIST_CAPTION, 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),
 
		NWidget(NWID_VERTICAL),
 
			NWidget(WWT_PANEL, COLOUR_GREY, WID_SIL_LIST), SetMinimalSize(WD_FRAMETEXT_LEFT + 16 + 255 + WD_FRAMETEXT_RIGHT, 50),
 
			NWidget(WWT_PANEL, COLOUR_BROWN, WID_SIL_LIST), SetMinimalSize(WD_FRAMETEXT_LEFT + 16 + 255 + WD_FRAMETEXT_RIGHT, 50),
 
								SetResize(1, 10), SetFill(1, 0), SetScrollbar(WID_SIL_SCROLLBAR), EndContainer(),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1),
 
					NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SIL_FILTER_TEXT), SetMinimalSize(80, 12), SetResize(1, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
 
				NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 1),
 
					NWidget(WWT_EDITBOX, COLOUR_BROWN, WID_SIL_FILTER_TEXT), SetMinimalSize(80, 12), SetResize(1, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
 
							SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
 
				EndContainer(),
 
				NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SIL_FILTER_MATCH_CASE_BTN), SetDataTip(STR_SIGN_LIST_MATCH_CASE, STR_SIGN_LIST_MATCH_CASE_TOOLTIP),
 
				NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_SIL_FILTER_MATCH_CASE_BTN), SetDataTip(STR_SIGN_LIST_MATCH_CASE, STR_SIGN_LIST_MATCH_CASE_TOOLTIP),
 
			EndContainer(),
 
		EndContainer(),
 
		NWidget(NWID_VERTICAL),
 
			NWidget(NWID_VERTICAL), SetFill(0, 1),
 
				NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SIL_SCROLLBAR),
 
				NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_SIL_SCROLLBAR),
 
			EndContainer(),
 
			NWidget(WWT_RESIZEBOX, COLOUR_GREY),
 
			NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
static WindowDesc _sign_list_desc(
 
	WDP_AUTO, "list_signs", 358, 138,
 
	WC_SIGN_LIST, WC_NONE,
 
	0,
 
	_nested_sign_list_widgets, lengthof(_nested_sign_list_widgets),
 
	&SignListWindow::hotkeys
 
);
 

	
 
/**
 
 * Open the sign list window
 
 *
 
 * @return newly opened sign list window, or nullptr if the window could not be opened.
 
 */
 
Window *ShowSignList()
 
{
 
	return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
 
}
 

	
 
/**
 
 * Actually rename the sign.
 
 * @param index the sign to rename.
 
 * @param text  the new name.
 
 * @return true if the window will already be removed after returning.
 
 */
 
static bool RenameSign(SignID index, const char *text)
 
{
 
	bool remove = StrEmpty(text);
 
	DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_ERROR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_ERROR_CAN_T_CHANGE_SIGN_NAME)), nullptr, text);
 
	return remove;
 
}
 

	
 
struct SignWindow : Window, SignList {
 
	QueryString name_editbox;
 
	SignID cur_sign;
 

	
 
	SignWindow(WindowDesc *desc, const Sign *si) : Window(desc), name_editbox(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
 
	{
 
		this->querystrings[WID_QES_TEXT] = &this->name_editbox;
 
		this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
 
		this->name_editbox.cancel_button = WID_QES_CANCEL;
 
		this->name_editbox.ok_button = WID_QES_OK;
 

	
 
		this->InitNested(WN_QUERY_STRING_SIGN);
 

	
src/widget.cpp
Show inline comments
 
@@ -2818,98 +2818,99 @@ NWidgetContainer *MakeNWidgets(const NWi
 
 * @pre \c biggest_index != nullptr
 
 * @post \c *biggest_index contains the largest widget index of the tree and \c -1 if no index is used.
 
 */
 
NWidgetContainer *MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select)
 
{
 
	*biggest_index = -1;
 

	
 
	/* Read the first widget recursively from the array. */
 
	NWidgetBase *nwid = nullptr;
 
	int num_used = MakeWidgetTree(parts, count, &nwid, biggest_index);
 
	assert(nwid != nullptr);
 
	parts += num_used;
 
	count -= num_used;
 

	
 
	NWidgetContainer *root = new NWidgetVertical;
 
	root->Add(nwid);
 
	if (count == 0) { // There is no body at all.
 
		*shade_select = nullptr;
 
		return root;
 
	}
 

	
 
	/* If the first widget looks like a titlebar, treat it as such.
 
	 * If it has a shading box, silently add a shade selection widget in the tree. */
 
	NWidgetHorizontal *hor_cont = dynamic_cast<NWidgetHorizontal *>(nwid);
 
	NWidgetContainer *body;
 
	if (hor_cont != nullptr && hor_cont->GetWidgetOfType(WWT_CAPTION) != nullptr && hor_cont->GetWidgetOfType(WWT_SHADEBOX) != nullptr) {
 
		*shade_select = new NWidgetStacked;
 
		root->Add(*shade_select);
 
		body = new NWidgetVertical;
 
		(*shade_select)->Add(body);
 
	} else {
 
		*shade_select = nullptr;
 
		body = root;
 
	}
 

	
 
	/* Load the remaining parts into 'body'. */
 
	int biggest2 = -1;
 
	MakeNWidgets(parts, count, &biggest2, body);
 

	
 
	*biggest_index = std::max(*biggest_index, biggest2);
 
	return root;
 
}
 

	
 
/**
 
 * Make a number of rows with button-like graphics, for enabling/disabling each company.
 
 * @param biggest_index Storage for collecting the biggest index used in the returned tree.
 
 * @param widget_first The first widget index to use.
 
 * @param widget_last The last widget index to use.
 
 * @param colour The colour in which to draw the button.
 
 * @param max_length Maximal number of company buttons in one row.
 
 * @param button_tooltip The tooltip-string of every button.
 
 * @return Panel with rows of company buttons.
 
 * @post \c *biggest_index contains the largest used index in the tree.
 
 */
 
NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, int max_length, StringID button_tooltip)
 
NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, Colours button_colour, int max_length, StringID button_tooltip)
 
{
 
	assert(max_length >= 1);
 
	NWidgetVertical *vert = nullptr; // Storage for all rows.
 
	NWidgetHorizontal *hor = nullptr; // Storage for buttons in one row.
 
	int hor_length = 0;
 

	
 
	Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
 
	sprite_size.width  += WD_MATRIX_LEFT + WD_MATRIX_RIGHT;
 
	sprite_size.height += WD_MATRIX_TOP + WD_MATRIX_BOTTOM + 1; // 1 for the 'offset' of being pressed
 

	
 
	for (int widnum = widget_first; widnum <= widget_last; widnum++) {
 
		/* Ensure there is room in 'hor' for another button. */
 
		if (hor_length == max_length) {
 
			if (vert == nullptr) vert = new NWidgetVertical();
 
			vert->Add(hor);
 
			hor = nullptr;
 
			hor_length = 0;
 
		}
 
		if (hor == nullptr) {
 
			hor = new NWidgetHorizontal();
 
			hor_length = 0;
 
		}
 

	
 
		NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
 
		NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, button_colour, widnum);
 
		panel->SetMinimalSize(sprite_size.width, sprite_size.height);
 
		panel->SetFill(1, 1);
 
		panel->SetResize(1, 0);
 
		panel->SetDataTip(0x0, button_tooltip);
 
		hor->Add(panel);
 
		hor_length++;
 
	}
 
	*biggest_index = widget_last;
 
	if (vert == nullptr) return hor; // All buttons fit in a single row.
 

	
 
	if (hor_length > 0 && hor_length < max_length) {
 
		/* Last row is partial, add a spacer at the end to force all buttons to the left. */
 
		NWidgetSpacer *spc = new NWidgetSpacer(sprite_size.width, sprite_size.height);
 
		spc->SetFill(1, 1);
 
		spc->SetResize(1, 0);
 
		hor->Add(spc);
 
	}
 
	if (hor != nullptr) vert->Add(hor);
 
	return vert;
 
}
src/widget_type.h
Show inline comments
 
@@ -1110,51 +1110,51 @@ static inline NWidgetPart SetScrollbar(i
 
 *       Child widgets must have a index bigger than the parent index.
 
 * @ingroup NestedWidgetParts
 
 */
 
static inline NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx = -1)
 
{
 
	NWidgetPart part;
 

	
 
	part.type = tp;
 
	part.u.widget.colour = col;
 
	part.u.widget.index = idx;
 

	
 
	return part;
 
}
 

	
 
/**
 
 * Widget part function for starting a new horizontal container, vertical container, or spacer widget.
 
 * @param tp         Type of the new nested widget, #NWID_HORIZONTAL, #NWID_VERTICAL, #NWID_SPACER, #NWID_SELECTION, and #NWID_MATRIX.
 
 * @param cont_flags Flags for the containers (#NWID_HORIZONTAL and #NWID_VERTICAL).
 
 * @ingroup NestedWidgetParts
 
 */
 
static inline NWidgetPart NWidget(WidgetType tp, NWidContainerFlags cont_flags = NC_NONE)
 
{
 
	NWidgetPart part;
 

	
 
	part.type = tp;
 
	part.u.cont_flags = cont_flags;
 

	
 
	return part;
 
}
 

	
 
/**
 
 * Obtain a nested widget (sub)tree from an external source.
 
 * @param func_ptr Pointer to function that returns the tree.
 
 * @ingroup NestedWidgetParts
 
 */
 
static inline NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
 
{
 
	NWidgetPart part;
 

	
 
	part.type = WPT_FUNCTION;
 
	part.u.func_ptr = func_ptr;
 

	
 
	return part;
 
}
 

	
 
NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container);
 
NWidgetContainer *MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select);
 

	
 
NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, int max_length, StringID button_tooltip);
 
NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, Colours button_colour, int max_length, StringID button_tooltip);
 

	
 
#endif /* WIDGET_TYPE_H */
0 comments (0 inline, 0 general)