Changeset - r13125:eb7db1536e66
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-09-26 10:01:53
rubidium@openttd.org
(svn r17640) -Codechange: make the custom currency window nested
1 file changed with 53 insertions and 70 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -1707,73 +1707,91 @@ void DrawArrowButtons(int x, int y, Colo
 
/** Widget numbers of the custom currency window. */
 
enum CustomCurrencyWidgets {
 
	CUSTCURR_CLOSEBOX,
 
	CUSTCURR_CAPTION,
 
	CUSTCURR_BACKGROUND,
 

	
 
	CUSTCURR_RATE_DOWN,
 
	CUSTCURR_RATE_UP,
 
	CUSTCURR_RATE,
 
	CUSTCURR_SEPARATOR_EDIT,
 
	CUSTCURR_SEPARATOR,
 
	CUSTCURR_PREFIX_EDIT,
 
	CUSTCURR_PREFIX,
 
	CUSTCURR_SUFFIX_EDIT,
 
	CUSTCURR_SUFFIX,
 
	CUSTCURR_YEAR_DOWN,
 
	CUSTCURR_YEAR_UP,
 
	CUSTCURR_YEAR,
 
	CUSTCURR_PREVIEW,
 
};
 

	
 
struct CustomCurrencyWindow : Window {
 
	int query_widget;
 

	
 
	CustomCurrencyWindow(const WindowDesc *desc) : Window(desc)
 
	CustomCurrencyWindow(const WindowDesc *desc) : Window()
 
	{
 
		this->FindWindowPlacementAndResize(desc);
 
		this->InitNested(desc);
 

	
 
		SetButtonState();
 
	}
 

	
 
	void SetButtonState()
 
	{
 
		this->SetWidgetDisabledState(CUSTCURR_RATE_DOWN, _custom_currency.rate == 1);
 
		this->SetWidgetDisabledState(CUSTCURR_RATE_UP, _custom_currency.rate == UINT16_MAX);
 
		this->SetWidgetDisabledState(CUSTCURR_YEAR_DOWN, _custom_currency.to_euro == CF_NOEURO);
 
		this->SetWidgetDisabledState(CUSTCURR_YEAR_UP, _custom_currency.to_euro == MAX_YEAR);
 
	}
 

	
 
	virtual void OnPaint()
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		SetDParam(0, 1);
 
		SetDParam(1, 1);
 
		SetDParamStr(2, _custom_currency.separator);
 
		SetDParamStr(3, _custom_currency.prefix);
 
		SetDParamStr(4, _custom_currency.suffix);
 
		SetDParam(5, _custom_currency.to_euro);
 
		this->widget[CUSTCURR_YEAR].data = (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER;
 
		SetDParam(6, 10000);
 
		if (widget == CUSTCURR_YEAR) {
 
			this->GetWidget<NWidgetCore>(CUSTCURR_YEAR)->widget_data = (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER;
 
			SetDParam(6, 10000);
 
		}
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
 
	{
 
		switch (widget) {
 
			/* Set the appropriate width for the edit 'buttons' */
 
			case CUSTCURR_SEPARATOR_EDIT:
 
			case CUSTCURR_PREFIX_EDIT:
 
			case CUSTCURR_SUFFIX_EDIT:
 
				size->width  = this->GetWidget<NWidgetCore>(CUSTCURR_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetCore>(CUSTCURR_RATE_UP)->smallest_x;
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		int line = 0;
 
		int len = 0;
 
		StringID str = 0;
 
		CharSetFilter afilter = CS_ALPHANUMERAL;
 

	
 
		switch (widget) {
 
			case CUSTCURR_RATE_DOWN:
 
				if (_custom_currency.rate > 1) _custom_currency.rate--;
 
				if (_custom_currency.rate == 1) this->DisableWidget(CUSTCURR_RATE_DOWN);
 
				this->EnableWidget(CUSTCURR_RATE_UP);
 
				break;
 

	
 
			case CUSTCURR_RATE_UP:
 
				if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
 
				if (_custom_currency.rate == UINT16_MAX) this->DisableWidget(CUSTCURR_RATE_UP);
 
				this->EnableWidget(CUSTCURR_RATE_DOWN);
 
				break;
 

	
 
			case CUSTCURR_RATE:
 
@@ -1855,111 +1873,76 @@ struct CustomCurrencyWindow : Window {
 
				strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
 
				break;
 

	
 
			case CUSTCURR_SUFFIX:
 
				strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
 
				break;
 

	
 
			case CUSTCURR_YEAR: { // Year to switch to euro
 
				int val = atoi(str);
 

	
 
				_custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
 
				break;
 
			}
 
		}
 
		MarkWholeScreenDirty();
 
		SetButtonState();
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
 
		this->SetDirty();
 
	}
 
};
 

	
 
static const Widget _cust_currency_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,       0,    10,     0,    13, STR_BLACK_CROSS,             STR_TOOLTIP_CLOSE_WINDOW},                     // CUSTCURR_CLOSEBOX
 
{    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,      11,   229,     0,    13, STR_CURRENCY_WINDOW,         STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS},           // CUSTCURR_CAPTION
 
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,       0,   229,    14,   119, 0x0,                         STR_NULL},                                     // CUSTCURR_BACKGROUND
 

	
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_YELLOW,    10,    19,    21,    29, STR_BLACK_SMALL_ARROW_LEFT,  STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP},           // CUSTCURR_RATE_DOWN
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_YELLOW,    20,    29,    21,    29, STR_BLACK_SMALL_ARROW_RIGHT, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP},           // CUSTCURR_RATE_UP
 
{       WWT_TEXT,   RESIZE_NONE,  COLOUR_BLUE,      35,   227,    21,    29, STR_CURRENCY_EXCHANGE_RATE,  STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP},                // CUSTCURR_RATE
 

	
 
{    WWT_PUSHBTN,   RESIZE_NONE,  COLOUR_DARK_BLUE, 10,    29,    33,    41, 0x0,                         STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP},    // CUSTCURR_SEPARATOR_EDIT
 
{       WWT_TEXT,   RESIZE_NONE,  COLOUR_BLUE,      35,   227,    33,    41, STR_CURRENCY_SEPARATOR,      STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP},    // CUSTCURR_SEPARATOR
 

	
 
{    WWT_PUSHBTN,   RESIZE_NONE,  COLOUR_DARK_BLUE, 10,    29,    45,    53, 0x0,                         STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP},       // CUSTCURR_PREFIX_EDIT
 
{       WWT_TEXT,   RESIZE_NONE,  COLOUR_BLUE,      35,   227,    45,    53, STR_CURRENCY_PREFIX,         STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP},       // CUSTCURR_PREFIX
 

	
 
{    WWT_PUSHBTN,   RESIZE_NONE,  COLOUR_DARK_BLUE, 10,    29,    57,    65, 0x0,                         STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP},       // CUSTCURR_SUFFIX_EDIT
 
{       WWT_TEXT,   RESIZE_NONE,  COLOUR_BLUE,      35,   227,    57,    65, STR_CURRENCY_SUFFIX,         STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP},       // CUSTCURR_SUFFIX
 

	
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_YELLOW,    10,    19,    69,    77, STR_BLACK_SMALL_ARROW_LEFT,  STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP}, // CUSTCURR_YEAR_DOWN
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_YELLOW,    20,    29,    69,    77, STR_BLACK_SMALL_ARROW_RIGHT, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP}, // CUSTCURR_YEAR_UP
 
{       WWT_TEXT,   RESIZE_NONE,  COLOUR_BLUE,      35,   227,    69,    77, STR_CURRENCY_SWITCH_TO_EURO, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP},      // CUSTCURR_YEAR
 

	
 
{      WWT_LABEL,   RESIZE_NONE,  COLOUR_BLUE,       2,   227,    93,   101, STR_CURRENCY_PREVIEW,        STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP},          // CUSTCURR_PREVIEW
 

	
 
{   WIDGETS_END},
 
};
 

	
 
static const NWidgetPart _nested_cust_currency_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY, CUSTCURR_CLOSEBOX),
 
		NWidget(WWT_CAPTION, COLOUR_GREY, CUSTCURR_CAPTION), SetDataTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, CUSTCURR_BACKGROUND),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, 7),
 
		NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 2),
 
			NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, CUSTCURR_RATE_DOWN), SetMinimalSize(10, 9), SetDataTip(STR_BLACK_SMALL_ARROW_LEFT, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
 
			NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, CUSTCURR_RATE_UP), SetMinimalSize(10, 9), SetDataTip(STR_BLACK_SMALL_ARROW_RIGHT, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
 
			NWidget(NWID_SPACER), SetMinimalSize(5, 0),
 
			NWidget(WWT_TEXT, COLOUR_BLUE, CUSTCURR_RATE), SetMinimalSize(193, 9), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP),
 
			NWidget(NWID_SPACER), SetFill(true, false),
 
		EndContainer(),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, 3),
 
		NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 2),
 
			NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, CUSTCURR_SEPARATOR_EDIT), SetMinimalSize(20, 9), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP),
 
			NWidget(NWID_SPACER), SetMinimalSize(5, 0),
 
			NWidget(WWT_TEXT, COLOUR_BLUE, CUSTCURR_SEPARATOR), SetMinimalSize(193, 9), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP),
 
			NWidget(NWID_SPACER), SetFill(true, false),
 
		NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(7, 3, 0),
 
			NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
 
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, CUSTCURR_RATE_DOWN), SetDataTip(STR_BLACK_SMALL_ARROW_LEFT, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
 
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, CUSTCURR_RATE_UP), SetDataTip(STR_BLACK_SMALL_ARROW_RIGHT, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
 
				NWidget(NWID_SPACER), SetMinimalSize(5, 0),
 
				NWidget(WWT_TEXT, COLOUR_BLUE, CUSTCURR_RATE), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(true, false),
 
			EndContainer(),
 
			NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
 
				NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, CUSTCURR_SEPARATOR_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(false, true),
 
				NWidget(NWID_SPACER), SetMinimalSize(5, 0),
 
				NWidget(WWT_TEXT, COLOUR_BLUE, CUSTCURR_SEPARATOR), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(true, false),
 
			EndContainer(),
 
			NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
 
				NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, CUSTCURR_PREFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(false, true),
 
				NWidget(NWID_SPACER), SetMinimalSize(5, 0),
 
				NWidget(WWT_TEXT, COLOUR_BLUE, CUSTCURR_PREFIX), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(true, false),
 
			EndContainer(),
 
			NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
 
				NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, CUSTCURR_SUFFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(false, true),
 
				NWidget(NWID_SPACER), SetMinimalSize(5, 0),
 
				NWidget(WWT_TEXT, COLOUR_BLUE, CUSTCURR_SUFFIX), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(true, false),
 
			EndContainer(),
 
			NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
 
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, CUSTCURR_YEAR_DOWN), SetDataTip(STR_BLACK_SMALL_ARROW_LEFT, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
 
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, CUSTCURR_YEAR_UP), SetDataTip(STR_BLACK_SMALL_ARROW_RIGHT, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
 
				NWidget(NWID_SPACER), SetMinimalSize(5, 0),
 
				NWidget(WWT_TEXT, COLOUR_BLUE, CUSTCURR_YEAR), SetDataTip(STR_CURRENCY_SWITCH_TO_EURO, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(true, false),
 
			EndContainer(),
 
		EndContainer(),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, 3),
 
		NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 2),
 
			NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, CUSTCURR_PREFIX_EDIT), SetMinimalSize(20, 9), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP),
 
			NWidget(NWID_SPACER), SetMinimalSize(5, 0),
 
			NWidget(WWT_TEXT, COLOUR_BLUE, CUSTCURR_PREFIX), SetMinimalSize(193, 9), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP),
 
			NWidget(NWID_SPACER), SetFill(true, false),
 
		EndContainer(),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, 3),
 
		NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 2),
 
			NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, CUSTCURR_SUFFIX_EDIT), SetMinimalSize(20, 9), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP),
 
			NWidget(NWID_SPACER), SetMinimalSize(5, 0),
 
			NWidget(WWT_TEXT, COLOUR_BLUE, CUSTCURR_SUFFIX), SetMinimalSize(193, 9), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP),
 
			NWidget(NWID_SPACER), SetFill(true, false),
 
		EndContainer(),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, 3),
 
		NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 2),
 
			NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, CUSTCURR_YEAR_DOWN), SetMinimalSize(10, 9), SetDataTip(STR_BLACK_SMALL_ARROW_LEFT, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
 
			NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, CUSTCURR_YEAR_UP), SetMinimalSize(10, 9), SetDataTip(STR_BLACK_SMALL_ARROW_RIGHT, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
 
			NWidget(NWID_SPACER), SetMinimalSize(5, 0),
 
			NWidget(WWT_TEXT, COLOUR_BLUE, CUSTCURR_YEAR), SetMinimalSize(193, 9), SetDataTip(STR_CURRENCY_SWITCH_TO_EURO, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
 
			NWidget(NWID_SPACER), SetFill(true, false),
 
		EndContainer(),
 
		NWidget(WWT_LABEL, COLOUR_BLUE, CUSTCURR_PREVIEW), SetMinimalSize(226, 9),
 
		NWidget(WWT_LABEL, COLOUR_BLUE, CUSTCURR_PREVIEW),
 
								SetDataTip(STR_CURRENCY_PREVIEW, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP), SetPadding(15, 1, 18, 2),
 
	EndContainer(),
 
};
 

	
 
static const WindowDesc _cust_currency_desc(
 
	WDP_CENTER, WDP_CENTER, 230, 120, 230, 120,
 
	WC_CUSTOM_CURRENCY, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
 
	_cust_currency_widgets, _nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)
 
	NULL, _nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)
 
);
 

	
 
static void ShowCustCurrency()
 
{
 
	DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
 
	new CustomCurrencyWindow(&_cust_currency_desc);
 
}
0 comments (0 inline, 0 general)