X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=f67bc13ecac7dc8bb5d3aed4e151383cea5b7439;hb=69e8efac8d856859c55237e085ff8b514ae1aa3c;hp=1e2ca16841661450886d719a2f701e0c8eea49be;hpb=2ae6ae8ed951e87fcba7c363705cd6ddea8de91c;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index 1e2ca168..f67bc13e 100644 --- a/src/events.c +++ b/src/events.c @@ -1,7 +1,7 @@ /*********************************************************** * Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* (c) 1995-2000 Artsoft Entertainment * +* (c) 1995-2001 Artsoft Entertainment * * Holger Schemel * * Detmolder Strasse 189 * * 33604 Bielefeld * @@ -19,8 +19,8 @@ #include "tools.h" #include "game.h" #include "editor.h" +#include "files.h" #include "tape.h" -#include "joystick.h" #include "network.h" /* values for key_status */ @@ -45,6 +45,23 @@ int FilterMouseMotionEvents(const Event *event) return 1; } +/* this is only really needed for non-SDL targets to filter unwanted events; + when using SDL with properly installed event filter, this function can be + replaced with a simple "NextEvent()" call, but it doesn't hurt either */ + +static boolean NextValidEvent(Event *event) +{ + while (PendingEvent()) + { + NextEvent(event); + + if (FilterMouseMotionEvents(event)) + return TRUE; + } + + return FALSE; +} + void EventLoop(void) { while(1) @@ -53,9 +70,7 @@ void EventLoop(void) { Event event; - NextEvent(&event); - - if (FilterMouseMotionEvents(&event)) + if (NextValidEvent(&event)) { switch(event.type) { @@ -161,6 +176,16 @@ void ClearEventQueue() } } +void ClearPlayerAction() +{ + int i; + + /* simulate key release events for still pressed keys */ + key_joystick_mapping = 0; + for (i=0; ix, y = event->y; - int width = event->width, height = event->height; - - if (setup.direct_draw && game_status==PLAYING) - { - int xx,yy; - int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY; - int x2 = (x-SX+width)/TILEX, y2 = (y-SY+height)/TILEY; - - SetDrawtoField(DRAW_BACKBUFFER); - - for(xx=0; xx=x1 && xx<=x2 && yy>=y1 && yy<=y2) - DrawScreenField(xx,yy); - DrawAllPlayers(); - - SetDrawtoField(DRAW_DIRECT); - } - - if (setup.soft_scrolling && game_status == PLAYING) - { - int fx = FX, fy = FY; - - fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0); - fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0); - - BlitBitmap(fieldbuffer, backbuffer, fx,fy, SXSIZE,SYSIZE, SX,SY); - } - - BlitBitmap(drawto, window, x,y, width,height, x,y); - + RedrawPlayfield(FALSE, event->x, event->y, event->width, event->height); FlushDisplay(); #endif } @@ -285,16 +279,11 @@ void HandleFocusEvent(FocusChangeEvent *event) if (event->type == EVENT_FOCUSOUT) { - int i; - KeyboardAutoRepeatOn(); - old_joystick_status = joystick_status; - joystick_status = JOYSTICK_OFF; + old_joystick_status = joystick.status; + joystick.status = JOYSTICK_NOT_AVAILABLE; - /* simulate key release events for still pressed keys */ - key_joystick_mapping = 0; - for (i=0; itype == EVENT_FOCUSIN) { @@ -320,7 +309,7 @@ void HandleFocusEvent(FocusChangeEvent *event) KeyboardAutoRepeatOff(); } if (old_joystick_status != -1) - joystick_status = old_joystick_status; + joystick.status = old_joystick_status; } } @@ -377,10 +366,6 @@ void HandleButton(int mx, int my, int button) HandleSetupScreen(mx,my, 0,0, button); break; - case SETUPINPUT: - HandleSetupInputScreen(mx,my, 0,0, button); - break; - case PLAYING: #ifdef DEBUG if (button == MB_RELEASED) @@ -495,14 +480,26 @@ void HandleKey(Key key, int key_status) } /* allow quick escape to the main menu with the Escape key */ - if (key == KSYM_Escape && game_status != MAINMENU) + if (key == KSYM_Escape && + game_status != MAINMENU && + game_status != PLAYING && + game_status != LEVELED && + game_status != CHOOSELEVEL && + game_status != SETUP) { - CloseDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY); game_status = MAINMENU; DrawMainMenu(); return; } + /* special shortcuts for quick game tape saving and loading */ + if (game_status == MAINMENU || game_status == PLAYING) + { + if (key == setup.shortcut.save_game) + TapeQuickSave(); + else if (key == setup.shortcut.load_game) + TapeQuickLoad(); + } #ifndef DEBUG @@ -525,7 +522,6 @@ void HandleKey(Key key, int key_status) case MAINMENU: case CHOOSELEVEL: case SETUP: - case SETUPINPUT: switch(key) { case KSYM_Return: @@ -536,8 +532,13 @@ void HandleKey(Key key, int key_status) HandleChooseLevel(0,0, 0,0, MB_MENU_CHOICE); else if (game_status == SETUP) HandleSetupScreen(0,0, 0,0, MB_MENU_CHOICE); - else if (game_status == SETUPINPUT) - HandleSetupInputScreen(0,0, 0,0, MB_MENU_CHOICE); + break; + + case KSYM_Escape: + if (game_status == CHOOSELEVEL) + HandleChooseLevel(0,0, 0,0, MB_MENU_LEAVE); + else if (game_status == SETUP) + HandleSetupScreen(0,0, 0,0, MB_MENU_LEAVE); break; case KSYM_Page_Up: @@ -550,6 +551,12 @@ void HandleKey(Key key, int key_status) HandleChooseLevel(0,0, 0,SCR_FIELDY, MB_MENU_MARK); break; +#ifdef DEBUG + case KSYM_t: + DumpTape(&tape); + break; +#endif + default: break; } @@ -583,7 +590,7 @@ void HandleKey(Key key, int key_status) break; case LEVELED: - if (!anyTextGadgetActiveOrJustFinished) + if (!anyTextGadgetActiveOrJustFinished || key == KSYM_Escape) HandleLevelEditorKeyInput(key); break; @@ -591,6 +598,9 @@ void HandleKey(Key key, int key_status) { switch(key) { + case KSYM_Escape: + RequestQuitGame(setup.ask_on_escape); + break; #ifdef DEBUG case KSYM_0: @@ -766,11 +776,9 @@ static int HandleJoystickForAllPlayers() joy_action = Joystick(i); result |= joy_action; - if (!setup.input[i].use_joystick) continue; - stored_player[i].action = joy_action; } @@ -796,7 +804,6 @@ void HandleJoystick() case MAINMENU: case CHOOSELEVEL: case SETUP: - case SETUPINPUT: { static unsigned long joystickmove_delay = 0; @@ -810,9 +817,6 @@ void HandleJoystick() HandleChooseLevel(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); else if (game_status==SETUP) HandleSetupScreen(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); - else if (game_status==SETUPINPUT) - HandleSetupInputScreen(0,0,dx,dy, - newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); break; }