X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=19c47763e05236c491659fbd15d9b772ecf204f1;hb=2f5368f25e34c02cb5ff7a012aa96198442231cb;hp=1f78e6b2559b1a814425ef7d2072c9ce420219f8;hpb=72e44014938c9042261b67213a6cd37b7a17488f;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index 1f78e6b2..19c47763 100644 --- a/src/events.c +++ b/src/events.c @@ -23,11 +23,6 @@ #include "tape.h" #include "network.h" -/* values for key_status */ -#define KEY_NOT_PRESSED FALSE -#define KEY_RELEASED FALSE -#define KEY_PRESSED TRUE - static boolean cursor_inside_playfield = FALSE; static boolean playfield_cursor_set = FALSE; @@ -50,7 +45,7 @@ int FilterMouseMotionEvents(const Event *event) cursor_inside_playfield = (motion->x >= SX && motion->x < SX + SXSIZE && motion->y >= SY && motion->y < SY + SYSIZE); - if (game_status == PLAYING && playfield_cursor_set) + if (game_status == GAME_MODE_PLAYING && playfield_cursor_set) { SetMouseCursor(CURSOR_DEFAULT); playfield_cursor_set = FALSE; @@ -58,7 +53,8 @@ int FilterMouseMotionEvents(const Event *event) } /* skip mouse motion events without pressed button outside level editor */ - if (button_status == MB_RELEASED && game_status != LEVELED) + if (button_status == MB_RELEASED && game_status != GAME_MODE_EDITOR && + game_status != GAME_MODE_PLAYING) return 0; else return 1; @@ -83,7 +79,7 @@ static boolean NextValidEvent(Event *event) void EventLoop(void) { - while(1) + while (1) { if (PendingEvent()) /* got event */ { @@ -116,7 +112,7 @@ void EventLoop(void) else { /* when playing, display a special mouse pointer inside the playfield */ - if (game_status == PLAYING) + if (game_status == GAME_MODE_PLAYING) { if (!playfield_cursor_set && cursor_inside_playfield && DelayReached(&playfield_cursor_delay, 1000)) @@ -137,7 +133,7 @@ void EventLoop(void) /* don't use all CPU time when idle; the main loop while playing has its own synchronization and is CPU friendly, too */ - if (game_status == PLAYING) + if (game_status == GAME_MODE_PLAYING) HandleGameActions(); else { @@ -149,7 +145,7 @@ void EventLoop(void) /* refresh window contents from drawing buffer, if needed */ BackToFront(); - if (game_status == EXITGAME) + if (game_status == GAME_MODE_QUIT) return; } } @@ -223,7 +219,7 @@ void ClearPlayerAction() /* simulate key release events for still pressed keys */ key_joystick_mapping = 0; - for (i=0; itype==EVENT_KEYPRESS ? KEY_PRESSED : KEY_RELEASED); - boolean with_modifiers = (game_status == PLAYING ? FALSE : TRUE); + boolean with_modifiers = (game_status == GAME_MODE_PLAYING ? FALSE : TRUE); Key key = GetEventKey(event, with_modifiers); + Key keymod = (with_modifiers ? GetEventKey(event, FALSE) : key); + HandleKeyModState(keymod, key_status); HandleKey(key, key_status); } @@ -339,15 +337,15 @@ void HandleFocusEvent(FocusChangeEvent *event) because unfortunately this is a global setting and not (which would be far better) set for each X11 window individually. The effect would be keyboard auto repeat while playing the game - (game_status == PLAYING), which is not desired. + (game_status == GAME_MODE_PLAYING), which is not desired. To avoid this special case, we just wait 1/10 second before processing the 'FocusIn' event. */ - if (game_status == PLAYING) + if (game_status == GAME_MODE_PLAYING) { Delay(100); - KeyboardAutoRepeatOff(); + KeyboardAutoRepeatOffUnlessAutoplay(); } if (old_joystick_status != -1) joystick.status = old_joystick_status; @@ -376,46 +374,49 @@ void HandleButton(int mx, int my, int button) old_my = my; } - HandleGadgets(mx, my, button); + if (HandleGadgets(mx, my, button)) + { + /* do not handle this button event anymore */ + mx = my = -32; /* force mouse event to be outside screen tiles */ + } switch(game_status) { - case MAINMENU: + case GAME_MODE_MAIN: HandleMainMenu(mx,my, 0,0, button); break; - case TYPENAME: + case GAME_MODE_PSEUDO_TYPENAME: HandleTypeName(0, KSYM_Return); break; - case CHOOSELEVEL: + case GAME_MODE_LEVELS: HandleChooseLevel(mx,my, 0,0, button); break; - case HALLOFFAME: + case GAME_MODE_SCORES: HandleHallOfFame(0,0, 0,0, button); break; - case LEVELED: + case GAME_MODE_EDITOR: break; - case HELPSCREEN: - HandleHelpScreen(button); + case GAME_MODE_INFO: + HandleInfoScreen(mx,my, 0,0, button); break; - case SETUP: + case GAME_MODE_SETUP: HandleSetupScreen(mx,my, 0,0, button); break; - case PLAYING: + case GAME_MODE_PLAYING: #ifdef DEBUG if (button == MB_RELEASED) { - int sx = (mx - SX) / TILEX; - int sy = (my - SY) / TILEY; - - if (IN_VIS_FIELD(sx,sy)) + if (IN_GFX_SCREEN(mx, my)) { + int sx = (mx - SX) / TILEX; + int sy = (my - SY) / TILEY; int x = LEVELX(sx); int y = LEVELY(sy); @@ -424,14 +425,19 @@ void HandleButton(int mx, int my, int button) if (!IN_LEV_FIELD(x, y)) break; - printf(" Feld[%d][%d] == %d\n", x,y, Feld[x][y]); + printf(" Feld[%d][%d] == %d ('%s')\n", x,y, Feld[x][y], + element_info[Feld[x][y]].token_name); + printf(" Back[%d][%d] == %d\n", x,y, Back[x][y]); printf(" Store[%d][%d] == %d\n", x,y, Store[x][y]); printf(" Store2[%d][%d] == %d\n", x,y, Store2[x][y]); printf(" StorePlayer[%d][%d] == %d\n", x,y, StorePlayer[x][y]); printf(" MovPos[%d][%d] == %d\n", x,y, MovPos[x][y]); printf(" MovDir[%d][%d] == %d\n", x,y, MovDir[x][y]); printf(" MovDelay[%d][%d] == %d\n", x,y, MovDelay[x][y]); + printf(" ChangeDelay[%d][%d] == %d\n", x,y, ChangeDelay[x][y]); printf(" GfxElement[%d][%d] == %d\n", x,y, GfxElement[x][y]); + printf(" GfxAction[%d][%d] == %d\n", x,y, GfxAction[x][y]); + printf(" GfxFrame[%d][%d] == %d\n", x,y, GfxFrame[x][y]); printf("\n"); } } @@ -443,6 +449,63 @@ void HandleButton(int mx, int my, int button) } } +static boolean is_string_suffix(char *string, char *suffix) +{ + int string_len = strlen(string); + int suffix_len = strlen(suffix); + + if (suffix_len > string_len) + return FALSE; + + return (strcmp(&string[string_len - suffix_len], suffix) == 0); +} + +#define MAX_CHEAT_INPUT_LEN 32 + +static void HandleKeysCheating(Key key) +{ + static char cheat_input[2 * MAX_CHEAT_INPUT_LEN + 1] = ""; + char letter = getCharFromKey(key); + int cheat_input_len = strlen(cheat_input); + int i; + + if (letter == 0) + return; + + if (cheat_input_len >= 2 * MAX_CHEAT_INPUT_LEN) + { + for (i = 0; i < MAX_CHEAT_INPUT_LEN + 1; i++) + cheat_input[i] = cheat_input[MAX_CHEAT_INPUT_LEN + i]; + + cheat_input_len = MAX_CHEAT_INPUT_LEN; + } + + cheat_input[cheat_input_len++] = letter; + cheat_input[cheat_input_len] = '\0'; + +#if 0 + printf("::: '%s' [%d]\n", cheat_input, cheat_input_len); +#endif + +#if 1 + if (is_string_suffix(cheat_input, ":insert solution tape")) + InsertSolutionTape(); +#else + if (is_string_suffix(cheat_input, ":ist")) + InsertSolutionTape(); +#endif + +#ifdef DEBUG + else if (is_string_suffix(cheat_input, ":dump tape")) + DumpTape(&tape); + else if (is_string_suffix(cheat_input, ".q")) + for (i = 0; i < MAX_INVENTORY_SIZE; i++) + if (local_player->inventory_size < MAX_INVENTORY_SIZE) + local_player->inventory_element[local_player->inventory_size++] = + EL_DYNAMITE; +#endif +} + void HandleKey(Key key, int key_status) { int joy = 0; @@ -463,14 +526,14 @@ void HandleKey(Key key, int key_status) { &custom_key.bomb, DEFAULT_KEY_BOMB, JOY_BUTTON_2 } }; - if (game_status == PLAYING) + if (game_status == GAME_MODE_PLAYING) { /* only needed for single-step tape recording mode */ static boolean clear_button_2[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE }; static boolean bomb_placed[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE }; int pnr; - for (pnr=0; pnrdynamite = 1000; - break; - - - #if 0 case KSYM_z: { int i; - for(i=0; i