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
 
@@ -1490,53 +1490,53 @@ const SettingDesc _patch_settings[] = {
 
	  SDTC_VAR(network.restart_game_year,     SLE_INT32, S,D0|NO|NC,0, MIN_YEAR, MAX_YEAR, 1, STR_NULL,                                       NULL),
 
	  SDTC_VAR(network.min_active_clients,    SLE_UINT8, S, NO,     0,     0, MAX_CLIENTS, 0, STR_NULL,                                       UpdateMinActiveClients),
 
	SDTC_OMANY(network.server_lang,           SLE_UINT8, S, NO,     0,    35, "ANY|ENGLISH|GERMAN|FRENCH|BRAZILIAN|BULGARIAN|CHINESE|CZECH|DANISH|DUTCH|ESPERANTO|FINNISH|HUNGARIAN|ICELANDIC|ITALIAN|JAPANESE|KOREAN|LITHUANIAN|NORWEGIAN|POLISH|PORTUGUESE|ROMANIAN|RUSSIAN|SLOVAK|SLOVENIAN|SPANISH|SWEDISH|TURKISH|UKRAINIAN|AFRIKAANS|CROATIAN|CATALAN|ESTONIAN|GALICIAN|GREEK|LATVIAN", STR_NULL, NULL),
 
	 SDTC_BOOL(network.reload_cfg,                       S, NO, false,                        STR_NULL,                                       NULL),
 
	  SDTC_STR(network.last_host,              SLE_STRB, S,  0, "0.0.0.0",                    STR_NULL,                                       NULL),
 
	  SDTC_VAR(network.last_port,            SLE_UINT16, S,  0,     0,     0,  UINT16_MAX, 0, STR_NULL,                                       NULL),
 
#endif /* ENABLE_NETWORK */
 

	
 
	/*
 
	 * Since the network code (CmdChangePatchSetting and friends) use the index in this array to decide
 
	 * which patch the server is talking about all conditional compilation of this array must be at the
 
	 * end. This isn't really the best solution, the patches the server can tell the client about should
 
	 * 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
 
#undef CR
 

	
 
/**
 
 * Prepare for reading and old diff_custom by zero-ing the memory.
 
 */
 
static void PrepareOldDiffCustom()
 
{
 
	memset(_old_diff_custom, 0, sizeof(_old_diff_custom));
 
}
 

	
 
/**
 
 * Reading of the old diff_custom array and transforming it to the new format.
src/settings_gui.cpp
Show inline comments
 
@@ -1090,122 +1090,120 @@ struct CustomCurrencyWindow : Window {
 
		DrawString(35, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, TC_FROMSTRING);
 
		y += 12;
 

	
 
		/* Preview */
 
		y += 12;
 
		SetDParam(0, 10000);
 
		DrawString(35, y + 1, STR_CURRENCY_PREVIEW, TC_FROMSTRING);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		int line = (pt.y - 20) / 12;
 
		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;
 

	
 
			case CUSTCURR_PREFIX:
 
				if (IsInsideMM(x, 10, 30)) { // clicked button
 
					this->click = 1 << (line * 2 + 1);
 
				}
 
				SetDParamStr(0, _custom_currency.prefix);
 
				str = STR_JUST_RAW_STRING;
 
				len = 12;
 
				break;
 

	
 
			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:
 
				strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
 
				break;
 

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

	
 
				_custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
 
				break;
 
			}
 
		}
 
		MarkWholeScreenDirty();
 
	}
0 comments (0 inline, 0 general)