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
 
@@ -1508,17 +1508,17 @@ const SettingDesc _patch_settings[] = {
 
#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
src/settings_gui.cpp
Show inline comments
 
@@ -1108,19 +1108,19 @@ struct CustomCurrencyWindow : Window {
 
			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
 
@@ -1149,24 +1149,22 @@ struct CustomCurrencyWindow : Window {
 
				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) {
 
@@ -1181,13 +1179,13 @@ struct CustomCurrencyWindow : Window {
 
	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;
0 comments (0 inline, 0 general)