(svn r13071) -Codechange: make also a class of the MainWindow.

This commit is contained in:
rubidium 2008-05-13 14:59:50 +00:00
parent 8e702d1053
commit ab7a5568d7
1 changed files with 156 additions and 154 deletions

View File

@ -214,188 +214,194 @@ void ZoomInOrOutToCursorWindow(bool in, Window *w)
extern void UpdateAllStationVirtCoord(); extern void UpdateAllStationVirtCoord();
static void MainWindowWndProc(Window *w, WindowEvent *e) struct MainWindow : Window
{ {
switch (e->event) { MainWindow(int width, int height) : Window(0, 0, width, height, NULL, WC_MAIN_WINDOW, NULL)
case WE_PAINT: {
DrawWindowViewport(w); InitializeWindowViewport(this, 0, 0, width, height, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
if (_game_mode == GM_MENU) { }
int off_x = _screen.width / 2;
DrawSprite(SPR_OTTD_O, PAL_NONE, off_x - 120, 50); virtual void OnPaint()
DrawSprite(SPR_OTTD_P, PAL_NONE, off_x - 86, 50); {
DrawSprite(SPR_OTTD_E, PAL_NONE, off_x - 53, 50); DrawWindowViewport(this);
DrawSprite(SPR_OTTD_N, PAL_NONE, off_x - 22, 50); if (_game_mode == GM_MENU) {
int off_x = _screen.width / 2;
DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 34, 50); DrawSprite(SPR_OTTD_O, PAL_NONE, off_x - 120, 50);
DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 65, 50); DrawSprite(SPR_OTTD_P, PAL_NONE, off_x - 86, 50);
DrawSprite(SPR_OTTD_D, PAL_NONE, off_x + 96, 50); DrawSprite(SPR_OTTD_E, PAL_NONE, off_x - 53, 50);
} DrawSprite(SPR_OTTD_N, PAL_NONE, off_x - 22, 50);
break;
case WE_KEYPRESS: DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 34, 50);
switch (e->we.keypress.keycode) { DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 65, 50);
case 'Q' | WKC_CTRL: DrawSprite(SPR_OTTD_D, PAL_NONE, off_x + 96, 50);
case 'Q' | WKC_META: }
HandleExitGameRequest(); }
break;
}
/* Disable all key shortcuts, except quit shortcuts when virtual bool OnKeyPress(uint16 key, uint16 keycode)
* generating the world, otherwise they create threading {
* problem during the generating, resulting in random switch (keycode) {
* assertions that are hard to trigger and debug */ case 'Q' | WKC_CTRL:
if (IsGeneratingWorld()) break; case 'Q' | WKC_META:
HandleExitGameRequest();
return true;
}
if (e->we.keypress.keycode == WKC_BACKQUOTE) { /* Disable all key shortcuts, except quit shortcuts when
IConsoleSwitch(); * generating the world, otherwise they create threading
e->we.keypress.cont = false; * problem during the generating, resulting in random
break; * assertions that are hard to trigger and debug */
} if (IsGeneratingWorld()) return true;
if (e->we.keypress.keycode == ('B' | WKC_CTRL)) { if (keycode == WKC_BACKQUOTE) {
e->we.keypress.cont = false; IConsoleSwitch();
extern bool _draw_bounding_boxes; return false;
_draw_bounding_boxes = !_draw_bounding_boxes; }
MarkWholeScreenDirty();
break;
}
if (_game_mode == GM_MENU) break; if (keycode == ('B' | WKC_CTRL)) {
extern bool _draw_bounding_boxes;
_draw_bounding_boxes = !_draw_bounding_boxes;
MarkWholeScreenDirty();
return false;
}
switch (e->we.keypress.keycode) { if (_game_mode == GM_MENU) return true;
case 'C':
case 'Z': { switch (keycode) {
Point pt = GetTileBelowCursor(); case 'C':
if (pt.x != -1) { case 'Z': {
if (e->we.keypress.keycode == 'Z') MaxZoomInOut(ZOOM_IN, w); Point pt = GetTileBelowCursor();
ScrollMainWindowTo(pt.x, pt.y); if (pt.x != -1) {
} if (keycode == 'Z') MaxZoomInOut(ZOOM_IN, this);
break; ScrollMainWindowTo(pt.x, pt.y);
} }
break;
}
case WKC_ESC: ResetObjectToPlace(); break; case WKC_ESC: ResetObjectToPlace(); break;
case WKC_DELETE: DeleteNonVitalWindows(); break; case WKC_DELETE: DeleteNonVitalWindows(); break;
case WKC_DELETE | WKC_SHIFT: DeleteAllNonVitalWindows(); break; case WKC_DELETE | WKC_SHIFT: DeleteAllNonVitalWindows(); break;
case 'R' | WKC_CTRL: MarkWholeScreenDirty(); break; case 'R' | WKC_CTRL: MarkWholeScreenDirty(); break;
#if defined(_DEBUG) #if defined(_DEBUG)
case '0' | WKC_ALT: // Crash the game case '0' | WKC_ALT: // Crash the game
*(byte*)0 = 0; *(byte*)0 = 0;
break; break;
case '1' | WKC_ALT: // Gimme money case '1' | WKC_ALT: // Gimme money
/* Server can not cheat in advertise mode either! */ /* Server can not cheat in advertise mode either! */
if (!_networking || !_network_server || !_network_advertise) if (!_networking || !_network_server || !_network_advertise)
DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT); DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT);
break; break;
case '2' | WKC_ALT: // Update the coordinates of all station signs case '2' | WKC_ALT: // Update the coordinates of all station signs
UpdateAllStationVirtCoord(); UpdateAllStationVirtCoord();
break; break;
#endif #endif
case '1' | WKC_CTRL: case '1' | WKC_CTRL:
case '2' | WKC_CTRL: case '2' | WKC_CTRL:
case '3' | WKC_CTRL: case '3' | WKC_CTRL:
case '4' | WKC_CTRL: case '4' | WKC_CTRL:
case '5' | WKC_CTRL: case '5' | WKC_CTRL:
case '6' | WKC_CTRL: case '6' | WKC_CTRL:
case '7' | WKC_CTRL: case '7' | WKC_CTRL:
case '8' | WKC_CTRL: case '8' | WKC_CTRL:
case '9' | WKC_CTRL: case '9' | WKC_CTRL:
/* Transparency toggle hot keys */ /* Transparency toggle hot keys */
ToggleTransparency((TransparencyOption)(e->we.keypress.keycode - ('1' | WKC_CTRL))); ToggleTransparency((TransparencyOption)(keycode - ('1' | WKC_CTRL)));
MarkWholeScreenDirty(); MarkWholeScreenDirty();
break; break;
case '1' | WKC_CTRL | WKC_SHIFT: case '1' | WKC_CTRL | WKC_SHIFT:
case '2' | WKC_CTRL | WKC_SHIFT: case '2' | WKC_CTRL | WKC_SHIFT:
case '3' | WKC_CTRL | WKC_SHIFT: case '3' | WKC_CTRL | WKC_SHIFT:
case '4' | WKC_CTRL | WKC_SHIFT: case '4' | WKC_CTRL | WKC_SHIFT:
case '5' | WKC_CTRL | WKC_SHIFT: case '5' | WKC_CTRL | WKC_SHIFT:
case '6' | WKC_CTRL | WKC_SHIFT: case '6' | WKC_CTRL | WKC_SHIFT:
case '7' | WKC_CTRL | WKC_SHIFT: case '7' | WKC_CTRL | WKC_SHIFT:
case '8' | WKC_CTRL | WKC_SHIFT: case '8' | WKC_CTRL | WKC_SHIFT:
/* Invisibility toggle hot keys */ /* Invisibility toggle hot keys */
ToggleInvisibilityWithTransparency((TransparencyOption)(e->we.keypress.keycode - ('1' | WKC_CTRL | WKC_SHIFT))); ToggleInvisibilityWithTransparency((TransparencyOption)(keycode - ('1' | WKC_CTRL | WKC_SHIFT)));
MarkWholeScreenDirty(); MarkWholeScreenDirty();
break; break;
case 'X' | WKC_CTRL: case 'X' | WKC_CTRL:
ShowTransparencyToolbar(); ShowTransparencyToolbar();
break; break;
case 'X': case 'X':
ResetRestoreAllTransparency(); ResetRestoreAllTransparency();
break; break;
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
case WKC_RETURN: case 'T': // smart chat; send to team if any, otherwise to all case WKC_RETURN: case 'T': // smart chat; send to team if any, otherwise to all
if (_networking) { if (_networking) {
const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index); const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index);
bool teamchat = false; bool teamchat = false;
if (cio == NULL) break; if (cio == NULL) break;
/* Only players actually playing can speak to team. Eg spectators cannot */ /* Only players actually playing can speak to team. Eg spectators cannot */
if (_patches.prefer_teamchat && IsValidPlayer(cio->client_playas)) { if (_patches.prefer_teamchat && IsValidPlayer(cio->client_playas)) {
const NetworkClientInfo *ci; const NetworkClientInfo *ci;
FOR_ALL_ACTIVE_CLIENT_INFOS(ci) { FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
if (ci->client_playas == cio->client_playas && ci != cio) { if (ci->client_playas == cio->client_playas && ci != cio) {
teamchat = true; teamchat = true;
break; break;
}
} }
} }
ShowNetworkChatQueryWindow(teamchat ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas);
} }
break;
case WKC_SHIFT | WKC_RETURN: case WKC_SHIFT | 'T': // send text message to all players ShowNetworkChatQueryWindow(teamchat ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas);
if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0); }
break; break;
case WKC_CTRL | WKC_RETURN: case WKC_CTRL | 'T': // send text to all team mates case WKC_SHIFT | WKC_RETURN: case WKC_SHIFT | 'T': // send text message to all players
if (_networking) { if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index); break;
if (cio == NULL) break;
ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas); case WKC_CTRL | WKC_RETURN: case WKC_CTRL | 'T': // send text to all team mates
} if (_networking) {
break; const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index);
if (cio == NULL) break;
ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas);
}
break;
#endif #endif
default: return; default: return true;
} }
e->we.keypress.cont = false; return false;
break;
case WE_SCROLL: {
ViewPort *vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y);
if (vp == NULL) {
_cursor.fix_at = false;
_scrolling_viewport = false;
}
w->viewport->scrollpos_x += ScaleByZoom(e->we.scroll.delta.x, vp->zoom);
w->viewport->scrollpos_y += ScaleByZoom(e->we.scroll.delta.y, vp->zoom);
w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x;
w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y;
} break;
case WE_MOUSEWHEEL:
ZoomInOrOutToCursorWindow(e->we.wheel.wheel < 0, w);
break;
case WE_INVALIDATE_DATA:
/* Forward the message to the appropiate toolbar (ingame or scenario editor) */
InvalidateWindowData(WC_MAIN_TOOLBAR, 0, e->we.invalidate.data);
break;
} }
}
virtual void OnScroll(Point delta)
{
ViewPort *vp = IsPtInWindowViewport(this, _cursor.pos.x, _cursor.pos.y);
if (vp == NULL) {
_cursor.fix_at = false;
_scrolling_viewport = false;
}
this->viewport->scrollpos_x += ScaleByZoom(delta.x, vp->zoom);
this->viewport->scrollpos_y += ScaleByZoom(delta.y, vp->zoom);
this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
};
virtual void OnMouseWheel(int wheel)
{
ZoomInOrOutToCursorWindow(wheel < 0, this);
}
virtual void OnInvalidateData(int data)
{
/* Forward the message to the appropiate toolbar (ingame or scenario editor) */
InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data);
}
};
void ShowSelectGameWindow(); void ShowSelectGameWindow();
@ -409,11 +415,7 @@ void SetupColorsAndInitialWindow()
memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i])); memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
} }
int width = _screen.width; new MainWindow(_screen.width, _screen.height);
int height = _screen.height;
Window *w = new Window(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
InitializeWindowViewport(w, 0, 0, width, height, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
/* XXX: these are not done */ /* XXX: these are not done */
switch (_game_mode) { switch (_game_mode) {