Changeset - r10510:bd195f7d514b
[Not reviewed]
master
0 2 0
rubidium - 15 years ago 2008-12-29 15:46:14
rubidium@openttd.org
(svn r14767) -Codechange: remove some unneeded artificial limits from currencies and use the bounds of the data type.
2 files changed with 11 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/settings.cpp
Show inline comments
 
@@ -1502,29 +1502,29 @@ const SettingDesc _patch_settings[] = {
 
	 * either use a seperate array or some other form of identifier.
 
	 */
 

	
 
#ifdef __APPLE__
 
	/* We might need to emulate a right mouse button on mac */
 
	 SDTC_VAR(gui.right_mouse_btn_emulation, SLE_UINT8, S, MS, 0, 0, 2, 0, STR_CONFIG_PATCHES_RIGHT_MOUSE_BTN_EMU, NULL),
 
#endif
 

	
 
	SDT_END()
 
};
 

	
 
static const SettingDesc _currency_settings[] = {
 
	SDT_VAR(CurrencySpec, rate,    SLE_UINT16, S, 0,  1, 0, 100, 0, STR_NULL, NULL),
 
	SDT_CHR(CurrencySpec, separator,           S, 0,        ".",    STR_NULL, NULL),
 
	SDT_VAR(CurrencySpec, to_euro,  SLE_INT32, S, 0,  0, 0, 3000, 0, STR_NULL, NULL),
 
	SDT_STR(CurrencySpec, prefix,   SLE_STRBQ, S, 0,       NULL,    STR_NULL, NULL),
 
	SDT_STR(CurrencySpec, suffix,   SLE_STRBQ, S, 0, " credits",    STR_NULL, NULL),
 
	SDT_VAR(CurrencySpec, rate,    SLE_UINT16, S, 0, 1,      0, UINT16_MAX, 0, STR_NULL, NULL),
 
	SDT_CHR(CurrencySpec, separator,           S, 0, ".",                      STR_NULL, NULL),
 
	SDT_VAR(CurrencySpec, to_euro,  SLE_INT32, S, 0, 0, MIN_YEAR, MAX_YEAR, 0, STR_NULL, NULL),
 
	SDT_STR(CurrencySpec, prefix,   SLE_STRBQ, S, 0, NULL,                     STR_NULL, NULL),
 
	SDT_STR(CurrencySpec, suffix,   SLE_STRBQ, S, 0, " credits",               STR_NULL, NULL),
 
	SDT_END()
 
};
 

	
 
/* Undefine for the shortcut macros above */
 
#undef S
 
#undef C
 
#undef N
 

	
 
#undef D0
 
#undef NC
 
#undef MS
 
#undef NO
src/settings_gui.cpp
Show inline comments
 
@@ -1102,31 +1102,31 @@ struct CustomCurrencyWindow : Window {
 
		int len = 0;
 
		int x = pt.x;
 
		StringID str = 0;
 
		CharSetFilter afilter = CS_ALPHANUMERAL;
 

	
 
		switch (line) {
 
			case CUSTCURR_EXCHANGERATE:
 
				if (IsInsideMM(x, 10, 30)) { // clicked buttons
 
					if (x < 20) {
 
						if (_custom_currency.rate > 1) _custom_currency.rate--;
 
						this->click = 1 << (line * 2 + 0);
 
					} else {
 
						if (_custom_currency.rate < 5000) _custom_currency.rate++;
 
						if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
 
						this->click = 1 << (line * 2 + 1);
 
					}
 
				} else { // enter text
 
					SetDParam(0, _custom_currency.rate);
 
					str = STR_CONFIG_PATCHES_INT32;
 
					len = 4;
 
					len = 5;
 
					afilter = CS_NUMERAL;
 
				}
 
				break;
 

	
 
			case CUSTCURR_SEPARATOR:
 
				if (IsInsideMM(x, 10, 30)) { // clicked button
 
					this->click = 1 << (line * 2 + 1);
 
				}
 
				SetDParamStr(0, this->separator);
 
				str = STR_JUST_RAW_STRING;
 
				len = 1;
 
				break;
 
@@ -1143,57 +1143,55 @@ struct CustomCurrencyWindow : Window {
 
			case CUSTCURR_SUFFIX:
 
				if (IsInsideMM(x, 10, 30)) { // clicked button
 
					this->click = 1 << (line * 2 + 1);
 
				}
 
				SetDParamStr(0, _custom_currency.suffix);
 
				str = STR_JUST_RAW_STRING;
 
				len = 12;
 
				break;
 

	
 
			case CUSTCURR_TO_EURO:
 
				if (IsInsideMM(x, 10, 30)) { // clicked buttons
 
					if (x < 20) {
 
						_custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ?
 
							CF_NOEURO : _custom_currency.to_euro - 1;
 
						_custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
 
						this->click = 1 << (line * 2 + 0);
 
					} else {
 
						_custom_currency.to_euro =
 
							Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
 
						_custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
 
						this->click = 1 << (line * 2 + 1);
 
					}
 
				} else { // enter text
 
					SetDParam(0, _custom_currency.to_euro);
 
					str = STR_CONFIG_PATCHES_INT32;
 
					len = 4;
 
					len = 7;
 
					afilter = CS_NUMERAL;
 
				}
 
				break;
 
		}
 

	
 
		if (len != 0) {
 
			this->query_widget = line;
 
			ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, 250, this, afilter, QSF_NONE);
 
		}
 

	
 
		this->flags4 |= WF_TIMEOUT_BEGIN;
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (str == NULL) return;
 

	
 
		switch (this->query_widget) {
 
			case CUSTCURR_EXCHANGERATE:
 
				_custom_currency.rate = Clamp(atoi(str), 1, 5000);
 
				_custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
 
				break;
 

	
 
			case CUSTCURR_SEPARATOR: /* Thousands seperator */
 
				_custom_currency.separator = StrEmpty(str) ? ' ' : str[0];
 
				strecpy(this->separator, str, lastof(this->separator));
 
				break;
 

	
 
			case CUSTCURR_PREFIX:
 
				strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
 
				break;
 

	
 
			case CUSTCURR_SUFFIX:
0 comments (0 inline, 0 general)