1
0
Fork 0

(svn r6273) Clean up the custom currency window handler a bit

release/0.5
tron 2006-08-31 14:12:08 +00:00
parent a0486a3b48
commit d5e21c2dc3
1 changed files with 147 additions and 155 deletions

View File

@ -1080,185 +1080,177 @@ static char _str_separator[2];
static void CustCurrencyWndProc(Window *w, WindowEvent *e) static void CustCurrencyWndProc(Window *w, WindowEvent *e)
{ {
switch (e->event) { switch (e->event) {
case WE_PAINT: { case WE_PAINT: {
int x=35, y=20, i=0; int x;
int clk = WP(w,def_d).data_1; int y = 20;
DrawWindowWidgets(w); int clk = WP(w,def_d).data_1;
DrawWindowWidgets(w);
// exchange rate // exchange rate
DrawArrowButtons(10, y, 3, (clk >> (i*2)) & 0x03, true, true); DrawArrowButtons(10, y, 3, GB(clk, 0, 2), true, true);
SetDParam(0, 1); SetDParam(0, 1);
SetDParam(1, 1); SetDParam(1, 1);
DrawString(x, y + 1, STR_CURRENCY_EXCHANGE_RATE, 0); DrawString(35, y + 1, STR_CURRENCY_EXCHANGE_RATE, 0);
x = 35; y += 12;
y+=12;
i++;
// separator // separator
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0); DrawFrameRect(10, y + 1, 29, y + 9, 0, GB(clk, 2, 2) ? FR_LOWERED : 0);
x = DrawString(x, y + 1, STR_CURRENCY_SEPARATOR, 0); x = DrawString(35, y + 1, STR_CURRENCY_SEPARATOR, 0);
DoDrawString(_str_separator, x + 4, y + 1, 6); DoDrawString(_str_separator, x + 4, y + 1, 6);
x = 35; y += 12;
y+=12;
i++;
// prefix // prefix
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0); DrawFrameRect(10, y + 1, 29, y + 9, 0, GB(clk, 4, 2) ? FR_LOWERED : 0);
x = DrawString(x, y + 1, STR_CURRENCY_PREFIX, 0); x = DrawString(35, y + 1, STR_CURRENCY_PREFIX, 0);
DoDrawString(_custom_currency.prefix, x + 4, y + 1, 6); DoDrawString(_custom_currency.prefix, x + 4, y + 1, 6);
x = 35; y += 12;
y+=12;
i++;
// suffix // suffix
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0); DrawFrameRect(10, y + 1, 29, y + 9, 0, GB(clk, 6, 2) ? FR_LOWERED : 0);
x = DrawString(x, y + 1, STR_CURRENCY_SUFFIX, 0); x = DrawString(35, y + 1, STR_CURRENCY_SUFFIX, 0);
DoDrawString(_custom_currency.suffix, x + 4, y + 1, 6); DoDrawString(_custom_currency.suffix, x + 4, y + 1, 6);
x = 35; y += 12;
y+=12;
i++;
// switch to euro // switch to euro
DrawArrowButtons(10, y, 3, (clk >> (i*2)) & 0x03, true, true); DrawArrowButtons(10, y, 3, GB(clk, 8, 2), true, true);
SetDParam(0, _custom_currency.to_euro); SetDParam(0, _custom_currency.to_euro);
DrawString(x, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, 0); DrawString(35, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, 0);
x = 35; y += 12;
y+=12;
i++;
// Preview // Preview
y+=12; y += 12;
SetDParam(0, 10000); SetDParam(0, 10000);
DrawString(x, y + 1, STR_CURRENCY_PREVIEW, 0); DrawString(35, y + 1, STR_CURRENCY_PREVIEW, 0);
} break;
case WE_CLICK: {
bool edittext = false;
int line = (e->click.pt.y - 20)/12;
int len = 0;
int x = e->click.pt.x;
StringID str = 0;
CharSetFilter afilter = CS_ALPHANUMERAL;
switch ( line ) {
case 0: // rate
if ( IS_INT_INSIDE(x, 10, 30) ) { // clicked buttons
if (x < 20) {
if (_custom_currency.rate > 1) _custom_currency.rate--;
WP(w,def_d).data_1 = (1 << (line * 2 + 0));
} else {
if (_custom_currency.rate < 5000) _custom_currency.rate++;
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
}
} else { // enter text
SetDParam(0, _custom_currency.rate);
str = STR_CONFIG_PATCHES_INT32;
len = 4;
edittext = true;
afilter = CS_NUMERAL;
}
break;
case 1: // separator
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
str = BindCString(_str_separator);
len = 1;
edittext = true;
break;
case 2: // prefix
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
str = BindCString(_custom_currency.prefix);
len = 12;
edittext = true;
break;
case 3: // suffix
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
str = BindCString(_custom_currency.suffix);
len = 12;
edittext = true;
break;
case 4: // to euro
if ( IS_INT_INSIDE(x, 10, 30) ) { // clicked buttons
if (x < 20) {
_custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ?
CF_NOEURO : _custom_currency.to_euro - 1;
WP(w,def_d).data_1 = (1 << (line * 2 + 0));
} else {
_custom_currency.to_euro =
clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
}
} else { // enter text
SetDParam(0, _custom_currency.to_euro);
str = STR_CONFIG_PATCHES_INT32;
len = 4;
edittext = true;
afilter = CS_NUMERAL;
}
break; break;
} }
if (edittext) { case WE_CLICK: {
WP(w,def_d).data_2 = line; int line = (e->click.pt.y - 20) / 12;
ShowQueryString( int len = 0;
str, int x = e->click.pt.x;
STR_CURRENCY_CHANGE_PARAMETER, StringID str = 0;
len + 1, // maximum number of characters OR CharSetFilter afilter = CS_ALPHANUMERAL;
250, // characters up to this width pixels, whichever is satisfied first
w->window_class,
w->window_number, afilter);
}
w->flags4 |= 5 << WF_TIMEOUT_SHL; switch (line) {
SetWindowDirty(w); case 0: // rate
} break; if (IS_INT_INSIDE(x, 10, 30)) { // clicked buttons
if (x < 20) {
case WE_ON_EDIT_TEXT: { if (_custom_currency.rate > 1) _custom_currency.rate--;
int val; WP(w,def_d).data_1 = 1 << (line * 2 + 0);
const char *b = e->edittext.str; } else {
switch (WP(w,def_d).data_2) { if (_custom_currency.rate < 5000) _custom_currency.rate++;
case 0: /* Exchange rate */ WP(w,def_d).data_1 = 1 << (line * 2 + 1);
val = atoi(b); }
val = clamp(val, 1, 5000); } else { // enter text
_custom_currency.rate = val; SetDParam(0, _custom_currency.rate);
str = STR_CONFIG_PATCHES_INT32;
len = 4;
afilter = CS_NUMERAL;
}
break; break;
case 1: /* Thousands seperator */ case 1: // separator
_custom_currency.separator = (b[0] == '\0') ? ' ' : b[0]; if (IS_INT_INSIDE(x, 10, 30)) { // clicked button
ttd_strlcpy(_str_separator, b, lengthof(_str_separator)); WP(w,def_d).data_1 = 1 << (line * 2 + 1);
}
str = BindCString(_str_separator);
len = 1;
break; break;
case 2: /* Currency prefix */ case 2: // prefix
ttd_strlcpy(_custom_currency.prefix, b, lengthof(_custom_currency.prefix)); if (IS_INT_INSIDE(x, 10, 30)) { // clicked button
WP(w,def_d).data_1 = 1 << (line * 2 + 1);
}
str = BindCString(_custom_currency.prefix);
len = 12;
break; break;
case 3: /* Currency suffix */ case 3: // suffix
ttd_strlcpy(_custom_currency.suffix, b, lengthof(_custom_currency.suffix)); if (IS_INT_INSIDE(x, 10, 30)) { // clicked button
WP(w,def_d).data_1 = 1 << (line * 2 + 1);
}
str = BindCString(_custom_currency.suffix);
len = 12;
break; break;
case 4: /* Year to switch to euro */ case 4: // to euro
val = atoi(b); if (IS_INT_INSIDE(x, 10, 30)) { // clicked buttons
val = clamp(val, 1999, MAX_YEAR); if (x < 20) {
if (val == 1999) val = 0; _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ?
_custom_currency.to_euro = val; CF_NOEURO : _custom_currency.to_euro - 1;
WP(w,def_d).data_1 = 1 << (line * 2 + 0);
} else {
_custom_currency.to_euro =
clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
WP(w,def_d).data_1 = 1 << (line * 2 + 1);
}
} else { // enter text
SetDParam(0, _custom_currency.to_euro);
str = STR_CONFIG_PATCHES_INT32;
len = 4;
afilter = CS_NUMERAL;
}
break; break;
} }
MarkWholeScreenDirty();
if (len != 0) {
WP(w,def_d).data_2 = line;
ShowQueryString(
str,
STR_CURRENCY_CHANGE_PARAMETER,
len + 1, // maximum number of characters OR
250, // characters up to this width pixels, whichever is satisfied first
w->window_class,
w->window_number, afilter);
}
} break; w->flags4 |= 5 << WF_TIMEOUT_SHL;
SetWindowDirty(w);
break;
}
case WE_TIMEOUT: case WE_ON_EDIT_TEXT: {
WP(w,def_d).data_1 = 0; const char *b = e->edittext.str;
SetWindowDirty(w);
break;
case WE_DESTROY: switch (WP(w,def_d).data_2) {
DeleteWindowById(WC_QUERY_STRING, 0); case 0: /* Exchange rate */
MarkWholeScreenDirty(); _custom_currency.rate = clamp(atoi(b), 1, 5000);
break; break;
case 1: /* Thousands seperator */
_custom_currency.separator = (b[0] == '\0') ? ' ' : b[0];
ttd_strlcpy(_str_separator, b, lengthof(_str_separator));
break;
case 2: /* Currency prefix */
ttd_strlcpy(_custom_currency.prefix, b, lengthof(_custom_currency.prefix));
break;
case 3: /* Currency suffix */
ttd_strlcpy(_custom_currency.suffix, b, lengthof(_custom_currency.suffix));
break;
case 4: { /* Year to switch to euro */
int val = atoi(b);
_custom_currency.to_euro =
(val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
break;
}
}
MarkWholeScreenDirty();
break;
}
case WE_TIMEOUT:
WP(w,def_d).data_1 = 0;
SetWindowDirty(w);
break;
case WE_DESTROY:
DeleteWindowById(WC_QUERY_STRING, 0);
MarkWholeScreenDirty();
break;
} }
} }