static void InputHandler_KeyDown(void* obj, int key, bool was) { struct Screen* active; int idx; struct HotkeyData* hkey; String text; if (!was && InputHandler_SimulateMouse(key, true)) return; active = Gui_GetActiveScreen(); #ifndef CC_BUILD_WEB if (key == KEY_ESCAPE && active->Closable) { /* Don't want holding down escape to go in and out of pause menu */ if (!was) Gui_Close(active); return; } #endif if (InputHandler_IsShutdown(key)) { /* TODO: Do we need a separate exit function in Game class? */ Window_Close(); return; } else if (key == KeyBinds[KEYBIND_SCREENSHOT] && !was) { Game_ScreenshotRequested = true; return; } else if (Elem_HandlesKeyDown(active, key, was)) { return; } else if ((key == KEY_ESCAPE || key == KEY_PAUSE) && !active->HandlesAllInput) { #ifdef CC_BUILD_WEB /* Can't do this in KeyUp, because pressing escape without having */ /* explicitly disabled mouse lock means a KeyUp event isn't sent. */ /* But switching to pause screen disables mouse lock, causing a KeyUp */ /* event to be sent, triggering the active->Closable case which immediately /* closes the pause screen. Hence why the next KeyUp must be supressed. */ suppressEscape = true; #endif Gui_FreeActive(); Gui_SetActive(PauseScreen_MakeInstance()); return; } /* These should not be triggered multiple times when holding down */ if (was) return; if (InputHandler_HandleCoreKey(key)) { } else if (LocalPlayer_HandlesKey(key)) { } else { idx = Hotkeys_FindPartial(key); if (idx == -1) return; hkey = &HotkeysList[idx]; text = StringsBuffer_UNSAFE_Get(&HotkeysText, hkey->TextIndex); if (!hkey->StaysOpen) { Chat_Send(&text, false); } else if (!Gui_Active) { HUDScreen_OpenInput(Gui_HUD, &text); } } }
void GameClose() { LoggerInfo("Closing game"); Gui_Close(); if(theWorld!=NULL) WorldDestory(theWorld); IN_DestroyInput(); RE_DestroyWindow(); PMD_Close(); RankDestroy(); RM_Close(); SDL_Quit(); LoggerInfo("SDL closed"); LoggerClose(); }
static void InputHandler_KeyUp(void* obj, int key) { struct Screen* active; if (InputHandler_SimulateMouse(key, false)) return; if (key == KeyBinds[KEYBIND_ZOOM_SCROLL]) Game_SetFov(Game_DefaultFov); active = Gui_GetActiveScreen(); #ifdef CC_BUILD_WEB /* When closing menus (which reacquires mouse focus) in key down, */ /* this still leaves the cursor visible. But if this is instead */ /* done in key up, the cursor disappears as expected. */ if (key == KEY_ESCAPE && active->Closable) { if (suppressEscape) { suppressEscape = false; return; } Gui_Close(active); return; } #endif Elem_HandlesKeyUp(active, key); }
void Gui_CloseActive(void) { Gui_Close(Gui_Active); }