Fix keydown not working

This commit is contained in:
UnknownShadow200 2019-08-17 07:53:03 +10:00
parent ab6df2cc7a
commit 2a4fb3208a
4 changed files with 23 additions and 19 deletions

View File

@ -395,10 +395,15 @@ void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right)
} }
static void InputHandler_MouseWheel(void* obj, float delta) { static void InputHandler_MouseWheel(void* obj, float delta) {
struct Screen* active = Gui_GetActiveScreen(); struct Screen* s;
int i;
struct Widget* widget; struct Widget* widget;
bool hotbar; bool hotbar;
if (Elem_HandlesMouseScroll(active, delta)) return;
for (i = 0; i < Gui_ScreensCount; i++) {
s = Gui_Screens[i];
if (s->VTABLE->HandlesMouseScroll(s, delta)) return;
}
hotbar = Key_IsAltPressed() || Key_IsControlPressed() || Key_IsShiftPressed(); hotbar = Key_IsAltPressed() || Key_IsControlPressed() || Key_IsShiftPressed();
if (!hotbar && Camera.Active->Zoom(delta)) return; if (!hotbar && Camera.Active->Zoom(delta)) return;
@ -462,18 +467,18 @@ static bool InputHandler_SimulateMouse(Key key, bool pressed) {
} }
static void InputHandler_KeyDown(void* obj, int key, bool was) { static void InputHandler_KeyDown(void* obj, int key, bool was) {
struct Screen* active; struct Screen* s;
int idx; int i;
struct HotkeyData* hkey; struct HotkeyData* hkey;
String text; String text;
if (!was && InputHandler_SimulateMouse(key, true)) return; if (!was && InputHandler_SimulateMouse(key, true)) return;
active = Gui_GetActiveScreen(); s = Gui_GetActiveScreen();
#ifndef CC_BUILD_WEB #ifndef CC_BUILD_WEB
if (key == KEY_ESCAPE && active->closable) { if (key == KEY_ESCAPE && (s = Gui_GetClosable())) {
/* Don't want holding down escape to go in and out of pause menu */ /* Don't want holding down escape to go in and out of pause menu */
if (!was) Gui_Close(active); if (!was) Gui_Remove(s);
return; return;
} }
#endif #endif
@ -483,9 +488,14 @@ static void InputHandler_KeyDown(void* obj, int key, bool was) {
Window_Close(); return; Window_Close(); return;
} else if (key == KeyBinds[KEYBIND_SCREENSHOT] && !was) { } else if (key == KeyBinds[KEYBIND_SCREENSHOT] && !was) {
Game_ScreenshotRequested = true; return; Game_ScreenshotRequested = true; return;
} else if (Elem_HandlesKeyDown(active, key)) { }
return;
} else if ((key == KEY_ESCAPE || key == KEY_PAUSE) && !Gui_GetInputGrab()) { for (i = 0; i < Gui_ScreensCount; i++) {
s = Gui_Screens[i];
if (s->VTABLE->HandlesKeyDown(s, key)) return;
}
if ((key == KEY_ESCAPE || key == KEY_PAUSE) && !Gui_GetInputGrab()) {
#ifdef CC_BUILD_WEB #ifdef CC_BUILD_WEB
/* Can't do this in KeyUp, because pressing escape without having */ /* Can't do this in KeyUp, because pressing escape without having */
/* explicitly disabled mouse lock means a KeyUp event isn't sent. */ /* explicitly disabled mouse lock means a KeyUp event isn't sent. */
@ -502,10 +512,10 @@ static void InputHandler_KeyDown(void* obj, int key, bool was) {
if (InputHandler_HandleCoreKey(key)) { if (InputHandler_HandleCoreKey(key)) {
} else if (LocalPlayer_HandlesKey(key)) { } else if (LocalPlayer_HandlesKey(key)) {
} else { } else {
idx = Hotkeys_FindPartial(key); i = Hotkeys_FindPartial(key);
if (idx == -1) return; if (i == -1) return;
hkey = &HotkeysList[idx]; hkey = &HotkeysList[i];
text = StringsBuffer_UNSAFE_Get(&HotkeysText, hkey->TextIndex); text = StringsBuffer_UNSAFE_Get(&HotkeysText, hkey->TextIndex);
if (!hkey->StaysOpen) { if (!hkey->StaysOpen) {

View File

@ -216,7 +216,6 @@ void InventoryScreen_Show(void) {
s->VTABLE = &InventoryScreen_VTABLE; s->VTABLE = &InventoryScreen_VTABLE;
Gui_Replace((struct Screen*)s, GUI_PRIORITY_INVENTORY); Gui_Replace((struct Screen*)s, GUI_PRIORITY_INVENTORY);
} }
struct Screen* InventoryScreen_UNSAFE_RawPointer = (struct Screen*)&InventoryScreen_Instance;
/*########################################################################################################################* /*########################################################################################################################*

View File

@ -14,8 +14,6 @@ void GeneratingScreen_Show(void);
void HUDScreen_Show(void); void HUDScreen_Show(void);
void DisconnectScreen_Show(const String* title, const String* message); void DisconnectScreen_Show(const String* title, const String* message);
/* Raw pointer to inventory screen. DO NOT USE THIS. Use InventoryScreen_MakeInstance() */
extern struct Screen* InventoryScreen_UNSAFE_RawPointer;
/* Raw pointer to loading screen. DO NOT USE THIS. Use LoadingScreen_MakeInstance() */ /* Raw pointer to loading screen. DO NOT USE THIS. Use LoadingScreen_MakeInstance() */
extern struct Screen* LoadingScreen_UNSAFE_RawPointer; extern struct Screen* LoadingScreen_UNSAFE_RawPointer;
/* Opens chat input for the HUD with the given initial text. */ /* Opens chat input for the HUD with the given initial text. */

View File

@ -450,13 +450,10 @@ static bool HotbarWidget_KeyUp(void* widget, Key key) {
static bool HotbarWidget_MouseDown(void* widget, int x, int y, MouseButton btn) { static bool HotbarWidget_MouseDown(void* widget, int x, int y, MouseButton btn) {
struct HotbarWidget* w = (struct HotbarWidget*)widget; struct HotbarWidget* w = (struct HotbarWidget*)widget;
struct Screen* screen;
int width, height; int width, height;
int i, cellX, cellY; int i, cellX, cellY;
if (btn != MOUSE_LEFT || !Widget_Contains(w, x, y)) return false; if (btn != MOUSE_LEFT || !Widget_Contains(w, x, y)) return false;
screen = Gui_GetActiveScreen();
if (screen != InventoryScreen_UNSAFE_RawPointer) return false;
width = (int)(w->elemSize + w->borderSize); width = (int)(w->elemSize + w->borderSize);
height = Math_Ceil(w->barHeight); height = Math_Ceil(w->barHeight);