1
0
Fork 0

(svn r13109) -Codechange: make a class out of the CheatWindow.

release/0.7
rubidium 2008-05-15 20:51:52 +00:00
parent b08d728ac9
commit 9013632325
1 changed files with 90 additions and 86 deletions

View File

@ -120,14 +120,17 @@ static const Widget _cheat_widgets[] = {
{ WIDGETS_END}, { WIDGETS_END},
}; };
static void CheatsWndProc(Window *w, WindowEvent *e) struct CheatWindow : Window {
{ int clicked;
switch (e->event) {
case WE_PAINT: {
int clk = WP(w, def_d).data_1;
DrawWindowWidgets(w); CheatWindow(const WindowDesc *desc) : Window(desc)
DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, w->width - 50); {
}
virtual void OnPaint()
{
DrawWindowWidgets(this);
DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, width - 50);
for (int i = 0, x = 0, y = 45; i != lengthof(_cheats_ui); i++) { for (int i = 0, x = 0, y = 45; i != lengthof(_cheats_ui); i++) {
const CheatEntry *ce = &_cheats_ui[i]; const CheatEntry *ce = &_cheats_ui[i];
@ -147,7 +150,7 @@ static void CheatsWndProc(Window *w, WindowEvent *e)
char buf[512]; char buf[512];
/* Draw [<][>] boxes for settings of an integer-type */ /* Draw [<][>] boxes for settings of an integer-type */
DrawArrowButtons(x + 20, y, 3, clk - (i * 2), true, true); DrawArrowButtons(x + 20, y, 3, clicked - (i * 2), true, true);
switch (ce->str) { switch (ce->str) {
/* Display date for change date cheat */ /* Display date for change date cheat */
@ -173,15 +176,15 @@ static void CheatsWndProc(Window *w, WindowEvent *e)
y += 12; y += 12;
} }
break;
} }
case WE_CLICK: { virtual void OnClick(Point pt, int widget)
uint btn = (e->we.click.pt.y - 46) / 12; {
uint x = e->we.click.pt.x; uint btn = (pt.y - 46) / 12;
uint x = pt.x;
/* Not clicking a button? */ /* Not clicking a button? */
if (!IsInsideMM(x, 20, 40) || btn >= lengthof(_cheats_ui)) break; if (!IsInsideMM(x, 20, 40) || btn >= lengthof(_cheats_ui)) return;
const CheatEntry *ce = &_cheats_ui[btn]; const CheatEntry *ce = &_cheats_ui[btn];
int value = (int32)ReadValue(ce->variable, ce->type); int value = (int32)ReadValue(ce->variable, ce->type);
@ -199,35 +202,36 @@ static void CheatsWndProc(Window *w, WindowEvent *e)
/* Take whatever the function returns */ /* Take whatever the function returns */
value = ce->proc(value + ((x >= 30) ? 1 : -1), (x >= 30) ? 1 : -1); value = ce->proc(value + ((x >= 30) ? 1 : -1), (x >= 30) ? 1 : -1);
if (value != oldvalue) WP(w, def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0); /* The first cheat (money), doesn't return a different value. */
if (value != oldvalue || btn == 0) this->clicked = btn * 2 + 1 + ((x >= 30) ? 1 : 0);
break; break;
} }
if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value); if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value);
w->flags4 |= 5 << WF_TIMEOUT_SHL; flags4 |= 5 << WF_TIMEOUT_SHL;
w->SetDirty(); SetDirty();
} break; }
case WE_TIMEOUT: virtual void OnTimeout()
WP(w, def_d).data_1 = 0; {
w->SetDirty(); this->clicked = 0;
break; this->SetDirty();
}
} }
};
static const WindowDesc _cheats_desc = { static const WindowDesc _cheats_desc = {
240, 22, 400, 170, 400, 170, 240, 22, 400, 170, 400, 170,
WC_CHEATS, WC_NONE, WC_CHEATS, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_cheat_widgets, _cheat_widgets,
CheatsWndProc NULL
}; };
void ShowCheatWindow() void ShowCheatWindow()
{ {
DeleteWindowById(WC_CHEATS, 0); DeleteWindowById(WC_CHEATS, 0);
new Window(&_cheats_desc); new CheatWindow(&_cheats_desc);
} }