mirror of https://github.com/OpenTTD/OpenTTD
(svn r6273) Clean up the custom currency window handler a bit
parent
a0486a3b48
commit
d5e21c2dc3
|
@ -1081,59 +1081,50 @@ 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 y = 20;
|
||||||
int clk = WP(w,def_d).data_1;
|
int clk = WP(w,def_d).data_1;
|
||||||
DrawWindowWidgets(w);
|
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;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WE_CLICK: {
|
case WE_CLICK: {
|
||||||
bool edittext = false;
|
|
||||||
int line = (e->click.pt.y - 20) / 12;
|
int line = (e->click.pt.y - 20) / 12;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int x = e->click.pt.x;
|
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 (IS_INT_INSIDE(x, 10, 30)) { // clicked buttons
|
||||||
if (x < 20) {
|
if (x < 20) {
|
||||||
if (_custom_currency.rate > 1) _custom_currency.rate--;
|
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 {
|
} else {
|
||||||
if (_custom_currency.rate < 5000) _custom_currency.rate++;
|
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
|
} else { // enter text
|
||||||
SetDParam(0, _custom_currency.rate);
|
SetDParam(0, _custom_currency.rate);
|
||||||
str = STR_CONFIG_PATCHES_INT32;
|
str = STR_CONFIG_PATCHES_INT32;
|
||||||
len = 4;
|
len = 4;
|
||||||
edittext = true;
|
|
||||||
afilter = CS_NUMERAL;
|
afilter = CS_NUMERAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // separator
|
case 1: // separator
|
||||||
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
|
if (IS_INT_INSIDE(x, 10, 30)) { // clicked button
|
||||||
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
|
WP(w,def_d).data_1 = 1 << (line * 2 + 1);
|
||||||
|
}
|
||||||
str = BindCString(_str_separator);
|
str = BindCString(_str_separator);
|
||||||
len = 1;
|
len = 1;
|
||||||
edittext = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // prefix
|
case 2: // prefix
|
||||||
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
|
if (IS_INT_INSIDE(x, 10, 30)) { // clicked button
|
||||||
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
|
WP(w,def_d).data_1 = 1 << (line * 2 + 1);
|
||||||
|
}
|
||||||
str = BindCString(_custom_currency.prefix);
|
str = BindCString(_custom_currency.prefix);
|
||||||
len = 12;
|
len = 12;
|
||||||
edittext = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: // suffix
|
case 3: // suffix
|
||||||
if ( IS_INT_INSIDE(x, 10, 30) ) // clicked button
|
if (IS_INT_INSIDE(x, 10, 30)) { // clicked button
|
||||||
WP(w,def_d).data_1 = (1 << (line * 2 + 1));
|
WP(w,def_d).data_1 = 1 << (line * 2 + 1);
|
||||||
|
}
|
||||||
str = BindCString(_custom_currency.suffix);
|
str = BindCString(_custom_currency.suffix);
|
||||||
len = 12;
|
len = 12;
|
||||||
edittext = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4: // to euro
|
case 4: // to euro
|
||||||
if (IS_INT_INSIDE(x, 10, 30)) { // clicked buttons
|
if (IS_INT_INSIDE(x, 10, 30)) { // clicked buttons
|
||||||
if (x < 20) {
|
if (x < 20) {
|
||||||
_custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ?
|
_custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ?
|
||||||
CF_NOEURO : _custom_currency.to_euro - 1;
|
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 {
|
} else {
|
||||||
_custom_currency.to_euro =
|
_custom_currency.to_euro =
|
||||||
clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
|
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
|
} else { // enter text
|
||||||
SetDParam(0, _custom_currency.to_euro);
|
SetDParam(0, _custom_currency.to_euro);
|
||||||
str = STR_CONFIG_PATCHES_INT32;
|
str = STR_CONFIG_PATCHES_INT32;
|
||||||
len = 4;
|
len = 4;
|
||||||
edittext = true;
|
|
||||||
afilter = CS_NUMERAL;
|
afilter = CS_NUMERAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edittext) {
|
if (len != 0) {
|
||||||
WP(w,def_d).data_2 = line;
|
WP(w,def_d).data_2 = line;
|
||||||
ShowQueryString(
|
ShowQueryString(
|
||||||
str,
|
str,
|
||||||
|
@ -1213,16 +1206,15 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e)
|
||||||
|
|
||||||
w->flags4 |= 5 << WF_TIMEOUT_SHL;
|
w->flags4 |= 5 << WF_TIMEOUT_SHL;
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WE_ON_EDIT_TEXT: {
|
case WE_ON_EDIT_TEXT: {
|
||||||
int val;
|
|
||||||
const char *b = e->edittext.str;
|
const char *b = e->edittext.str;
|
||||||
|
|
||||||
switch (WP(w,def_d).data_2) {
|
switch (WP(w,def_d).data_2) {
|
||||||
case 0: /* Exchange rate */
|
case 0: /* Exchange rate */
|
||||||
val = atoi(b);
|
_custom_currency.rate = clamp(atoi(b), 1, 5000);
|
||||||
val = clamp(val, 1, 5000);
|
|
||||||
_custom_currency.rate = val;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: /* Thousands seperator */
|
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));
|
ttd_strlcpy(_custom_currency.suffix, b, lengthof(_custom_currency.suffix));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4: /* Year to switch to euro */
|
case 4: { /* Year to switch to euro */
|
||||||
val = atoi(b);
|
int val = atoi(b);
|
||||||
val = clamp(val, 1999, MAX_YEAR);
|
|
||||||
if (val == 1999) val = 0;
|
_custom_currency.to_euro =
|
||||||
_custom_currency.to_euro = val;
|
(val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
|
break;
|
||||||
|
}
|
||||||
} break;
|
|
||||||
|
|
||||||
case WE_TIMEOUT:
|
case WE_TIMEOUT:
|
||||||
WP(w,def_d).data_1 = 0;
|
WP(w,def_d).data_1 = 0;
|
||||||
|
|
Loading…
Reference in New Issue