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

@ -1081,59 +1081,50 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
int x=35, y=20, i=0;
int x;
int y = 20;
int clk = WP(w,def_d).data_1;
DrawWindowWidgets(w);
// 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(1, 1);
DrawString(x, y + 1, STR_CURRENCY_EXCHANGE_RATE, 0);
x = 35;
DrawString(35, y + 1, STR_CURRENCY_EXCHANGE_RATE, 0);
y += 12;
i++;
// separator
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0);
x = DrawString(x, y + 1, STR_CURRENCY_SEPARATOR, 0);
DrawFrameRect(10, y + 1, 29, y + 9, 0, GB(clk, 2, 2) ? FR_LOWERED : 0);
x = DrawString(35, y + 1, STR_CURRENCY_SEPARATOR, 0);
DoDrawString(_str_separator, x + 4, y + 1, 6);
x = 35;
y += 12;
i++;
// prefix
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0);
x = DrawString(x, y + 1, STR_CURRENCY_PREFIX, 0);
DrawFrameRect(10, y + 1, 29, y + 9, 0, GB(clk, 4, 2) ? FR_LOWERED : 0);
x = DrawString(35, y + 1, STR_CURRENCY_PREFIX, 0);
DoDrawString(_custom_currency.prefix, x + 4, y + 1, 6);
x = 35;
y += 12;
i++;
// suffix
DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03) ? FR_LOWERED : 0);
x = DrawString(x, y + 1, STR_CURRENCY_SUFFIX, 0);
DrawFrameRect(10, y + 1, 29, y + 9, 0, GB(clk, 6, 2) ? FR_LOWERED : 0);
x = DrawString(35, y + 1, STR_CURRENCY_SUFFIX, 0);
DoDrawString(_custom_currency.suffix, x + 4, y + 1, 6);
x = 35;
y += 12;
i++;
// 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);
DrawString(x, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, 0);
x = 35;
DrawString(35, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, 0);
y += 12;
i++;
// Preview
y += 12;
SetDParam(0, 10000);
DrawString(x, y + 1, STR_CURRENCY_PREVIEW, 0);
} break;
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;
@ -1145,62 +1136,64 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
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));
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));
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));
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));
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));
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));
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));
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;
}
if (edittext) {
if (len != 0) {
WP(w,def_d).data_2 = line;
ShowQueryString(
str,
@ -1213,16 +1206,15 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
w->flags4 |= 5 << WF_TIMEOUT_SHL;
SetWindowDirty(w);
} break;
break;
}
case WE_ON_EDIT_TEXT: {
int val;
const char *b = e->edittext.str;
switch (WP(w,def_d).data_2) {
case 0: /* Exchange rate */
val = atoi(b);
val = clamp(val, 1, 5000);
_custom_currency.rate = val;
_custom_currency.rate = clamp(atoi(b), 1, 5000);
break;
case 1: /* Thousands seperator */
@ -1238,17 +1230,17 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
ttd_strlcpy(_custom_currency.suffix, b, lengthof(_custom_currency.suffix));
break;
case 4: /* Year to switch to euro */
val = atoi(b);
val = clamp(val, 1999, MAX_YEAR);
if (val == 1999) val = 0;
_custom_currency.to_euro = val;
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;
break;
}
case WE_TIMEOUT:
WP(w,def_d).data_1 = 0;