From 8f11b583dcd34f5b90d355fa8da3b7612171ba61 Mon Sep 17 00:00:00 2001 From: flafmg Date: Wed, 18 Jun 2025 01:25:46 -0300 Subject: [PATCH 1/3] implement flag-based key handling system --- src/Entity.c | 66 ++++++++++++++++++------------------ src/InputHandler.c | 83 +++++++++++++++++++++++----------------------- src/InputHandler.h | 6 +++- 3 files changed, 79 insertions(+), 76 deletions(-) diff --git a/src/Entity.c b/src/Entity.c index 69b0a3ce7..dd2e9042b 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -853,29 +853,29 @@ static void LocalPlayer_DoRespawn(struct LocalPlayer* p) { p->Base.OnGround = Entity_TouchesAny(&bb, LocalPlayer_IsSolidCollide); } -static cc_bool LocalPlayer_HandleRespawn(int key, struct InputDevice* device) { +static cc_key_flags LocalPlayer_HandleRespawn(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; - if (Gui.InputGrab) return false; + if (Gui.InputGrab) return KEY_NONE; if (p->Hacks.CanRespawn) { LocalPlayer_DoRespawn(p); - return true; + return KEY_HANDLED; } else if (!p->_warnedRespawn) { - p->_warnedRespawn = true; + p->_warnedRespawn = KEY_HANDLED; if (hackPermMsgs) Chat_AddRaw("&cRespawning is currently disabled"); } - return false; + return KEY_NONE; } -static cc_bool LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) { +static cc_key_flags LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; - if (Gui.InputGrab) return false; + if (Gui.InputGrab) return KEY_NONE; if (p->Hacks.CanRespawn) { if (!p->Hacks.CanNoclip && !p->Base.OnGround) { Chat_AddRaw("&cCannot set spawn midair when noclip is disabled"); - return false; + return KEY_NONE; } /* Spawn is normally centered to match vanilla Minecraft classic */ @@ -897,45 +897,45 @@ static cc_bool LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) { return LocalPlayer_HandleRespawn(key, device); } -static cc_bool LocalPlayer_HandleFly(int key, struct InputDevice* device) { +static cc_key_flags LocalPlayer_HandleFly(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; - if (Gui.InputGrab) return false; + if (Gui.InputGrab) return KEY_NONE; if (p->Hacks.CanFly && p->Hacks.Enabled) { HacksComp_SetFlying(&p->Hacks, !p->Hacks.Flying); - return true; + return KEY_HANDLED; } else if (!p->_warnedFly) { - p->_warnedFly = true; + p->_warnedFly = KEY_HANDLED; if (hackPermMsgs) Chat_AddRaw("&cFlying is currently disabled"); } - return false; + return KEY_NONE; } -static cc_bool LocalPlayer_HandleNoclip(int key, struct InputDevice* device) { +static cc_key_flags LocalPlayer_HandleNoclip(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; - p->Hacks._noclipping = true; - if (Gui.InputGrab) return false; + p->Hacks._noclipping = KEY_HANDLED; + if (Gui.InputGrab) return KEY_NONE; if (p->Hacks.CanNoclip && p->Hacks.Enabled) { - if (p->Hacks.WOMStyleHacks) return true; /* don't handle this here */ + if (p->Hacks.WOMStyleHacks) return KEY_HANDLED; /* don't handle this here */ if (p->Hacks.Noclip) p->Base.Velocity.y = 0; HacksComp_SetNoclip(&p->Hacks, !p->Hacks.Noclip); - return true; + return KEY_HANDLED; } else if (!p->_warnedNoclip) { - p->_warnedNoclip = true; + p->_warnedNoclip = KEY_HANDLED; if (hackPermMsgs) Chat_AddRaw("&cNoclip is currently disabled"); } - return false; + return KEY_NONE; } -static cc_bool LocalPlayer_HandleJump(int key, struct InputDevice* device) { +static cc_key_flags LocalPlayer_HandleJump(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; struct HacksComp* hacks = &p->Hacks; struct PhysicsComp* physics = &p->Physics; int maxJumps; - if (Gui.InputGrab) return false; - physics->Jumping = true; + if (Gui.InputGrab) return KEY_NONE; + physics->Jumping = KEY_HANDLED; if (!p->Base.OnGround && !(hacks->Flying || hacks->Noclip)) { maxJumps = hacks->CanDoubleJump && hacks->WOMStyleHacks ? 2 : 0; @@ -945,28 +945,28 @@ static cc_bool LocalPlayer_HandleJump(int key, struct InputDevice* device) { PhysicsComp_DoNormalJump(physics); physics->MultiJumps++; } - return true; + return KEY_HANDLED; } - return false; + return KEY_NONE; } -static cc_bool LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* device) { +static cc_key_flags LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* device) { struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks; - cc_bool touch = device->type == INPUT_DEVICE_TOUCH; - if (Gui.InputGrab) return false; + cc_key_flags touch = device->type == INPUT_DEVICE_TOUCH; + if (Gui.InputGrab) return KEY_NONE; hacks->HalfSpeeding = (!touch || !hacks->HalfSpeeding) && hacks->Enabled; - return true; + return KEY_HANDLED; } -static cc_bool LocalPlayer_TriggerSpeed(int key, struct InputDevice* device) { +static cc_key_flags LocalPlayer_TriggerSpeed(int key, struct InputDevice* device) { struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks; - cc_bool touch = device->type == INPUT_DEVICE_TOUCH; - if (Gui.InputGrab) return false; + cc_key_flags touch = device->type == INPUT_DEVICE_TOUCH; + if (Gui.InputGrab) return KEY_NONE; hacks->Speeding = (!touch || !hacks->Speeding) && hacks->Enabled; - return true; + return KEY_HANDLED; } static void LocalPlayer_ReleaseHalfSpeed(int key, struct InputDevice* device) { diff --git a/src/InputHandler.c b/src/InputHandler.c index 73553f9a0..4856e7988 100644 --- a/src/InputHandler.c +++ b/src/InputHandler.c @@ -632,71 +632,69 @@ static void BindReleased_PickBlock(int key, struct InputDevice* device) { } -static cc_bool BindTriggered_HideFPS(int key, struct InputDevice* device) { - if (Gui.InputGrab) return false; +static cc_key_flags BindTriggered_HideFPS(int key, struct InputDevice* device) { + if (Gui.InputGrab) return KEY_NONE; Gui.ShowFPS = !Gui.ShowFPS; - return true; + return KEY_HANDLED; } -static cc_bool BindTriggered_Fullscreen(int key, struct InputDevice* device) { - if (Gui.InputGrab) return false; - - Game_ToggleFullscreen(); - return true; +static cc_key_flags BindTriggered_Fullscreen(int key, struct InputDevice* device) { + Game_ToggleFullscreen(); + return KEY_HANDLED | KEY_SUPPRESS_UI; } -static cc_bool BindTriggered_Fog(int key, struct InputDevice* device) { - if (Gui.InputGrab) return false; +static cc_key_flags BindTriggered_Fog(int key, struct InputDevice* device) { + if (Gui.InputGrab) return KEY_NONE; Game_CycleViewDistance(); - return true; + return KEY_HANDLED; } -static cc_bool BindTriggered_HideGUI(int key, struct InputDevice* device) { - if (Gui.InputGrab) return false; +static cc_key_flags BindTriggered_HideGUI(int key, struct InputDevice* device) { + if (Gui.InputGrab) return KEY_NONE; Game_HideGui = !Game_HideGui; - return true; + return KEY_HANDLED; } -static cc_bool BindTriggered_SmoothCamera(int key, struct InputDevice* device) { - if (Gui.InputGrab) return false; +static cc_key_flags BindTriggered_SmoothCamera(int key, struct InputDevice* device) { + if (Gui.InputGrab) return KEY_NONE; InputHandler_Toggle(key, &Camera.Smooth, " &eSmooth camera is &aenabled", " &eSmooth camera is &cdisabled"); - return true; + return KEY_HANDLED; } -static cc_bool BindTriggered_AxisLines(int key, struct InputDevice* device) { - if (Gui.InputGrab) return false; +static cc_key_flags BindTriggered_AxisLines(int key, struct InputDevice* device) { + if (Gui.InputGrab) return KEY_NONE; InputHandler_Toggle(key, &AxisLinesRenderer_Enabled, " &eAxis lines (&4X&e, &2Y&e, &1Z&e) now show", " &eAxis lines no longer show"); - return true; + return KEY_HANDLED; } -static cc_bool BindTriggered_AutoRotate(int key, struct InputDevice* device) { - if (Gui.InputGrab) return false; +static cc_key_flags BindTriggered_AutoRotate(int key, struct InputDevice* device) { + if (Gui.InputGrab) return KEY_NONE; InputHandler_Toggle(key, &AutoRotate_Enabled, " &eAuto rotate is &aenabled", " &eAuto rotate is &cdisabled"); - return true; + return KEY_HANDLED; } -static cc_bool BindTriggered_ThirdPerson(int key, struct InputDevice* device) { - if (Gui.InputGrab) return false; +static cc_key_flags BindTriggered_ThirdPerson(int key, struct InputDevice* device) { + if (Gui.InputGrab) return KEY_NONE; Camera_CycleActive(); - return true; + return KEY_HANDLED; } -static cc_bool BindTriggered_DropBlock(int key, struct InputDevice* device) { - if (Gui.InputGrab) return false; +static cc_key_flags BindTriggered_DropBlock(int key, struct InputDevice* device) { + if (Gui.InputGrab) return KEY_NONE; if (Inventory_CheckChangeSelected() && Inventory_SelectedBlock != BLOCK_AIR) { /* Don't assign SelectedIndex directly, because we don't want held block @@ -704,17 +702,17 @@ static cc_bool BindTriggered_DropBlock(int key, struct InputDevice* device) { Inventory_Set(Inventory.SelectedIndex, BLOCK_AIR); Event_RaiseVoid(&UserEvents.HeldBlockChanged); } - return true; + return KEY_HANDLED; } -static cc_bool BindTriggered_IDOverlay(int key, struct InputDevice* device) { +static cc_key_flags BindTriggered_IDOverlay(int key, struct InputDevice* device) { struct Screen* s = Gui_GetScreen(GUI_PRIORITY_TEXIDS); if (s) { Gui_Remove(s); } else { TexIdsOverlay_Show(); } - return true; + return KEY_HANDLED; } static cc_bool BindTriggered_BreakLiquids(int key, struct InputDevice* device) { @@ -836,7 +834,7 @@ static void OnPointerUp(void* obj, int idx) { static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* device) { struct Screen* s; - cc_bool triggered; + cc_key_flags triggered_flags; int i; if (Input.DownHook && Input.DownHook(key, device)) return; @@ -854,23 +852,24 @@ static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* dev Game_ScreenshotRequested = true; return; } - triggered = false; + triggered_flags = KEY_NONE; for (i = 0; !was && i < BIND_COUNT; i++) { if (!InputBind_Claims(i, key, device)) continue; Bind_IsTriggered[i] |= device->type; if (!Bind_OnTriggered[i]) continue; - triggered |= Bind_OnTriggered[i](key, device); + triggered_flags |= Bind_OnTriggered[i](key, device); } - - for (i = 0; i < Gui.ScreensCount; i++) - { - s = Gui_Screens[i]; - s->dirty = true; - if (s->VTABLE->HandlesInputDown(s, key, device)) return; + if (!(triggered_flags & KEY_SUPPRESS_UI)) { //if key is supressing gui's key handling skip it + for (i = 0; i < Gui.ScreensCount; i++) + { + s = Gui_Screens[i]; + s->dirty = true; + if (s->VTABLE->HandlesInputDown(s, key, device)) return; + } + if (Gui.InputGrab) return; } - if (Gui.InputGrab) return; if (InputDevice_IsPause(key, device)) { #ifdef CC_BUILD_WEB @@ -887,7 +886,7 @@ static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* dev /* Hotkeys should not be triggered multiple times when holding down */ if (was) return; - if (triggered) { + if (triggered_flags & KEY_HANDLED) { } else if (key == CCKEY_F5 && Game_ClassicMode) { int weather = Env.Weather == WEATHER_SUNNY ? WEATHER_RAINY : WEATHER_SUNNY; Env_SetWeather(weather); diff --git a/src/InputHandler.h b/src/InputHandler.h index 344fe7cd9..c7cb3663b 100644 --- a/src/InputHandler.h +++ b/src/InputHandler.h @@ -53,8 +53,12 @@ cc_bool Input_HandleMouseWheel(float delta); void InputHandler_Tick(float delta); void InputHandler_OnScreensChanged(void); +typedef cc_uint8 cc_key_flags; /*dont know if this is the best place to put this*/ +#define KEY_NONE 0x00 /* key havent been handled */ +#define KEY_HANDLED 0x01 /* key has been handled */ +#define KEY_SUPPRESS_UI 0x02 /* key supresses GUI's key processing*/ -typedef cc_bool (*BindTriggered)(int key, struct InputDevice* device); +typedef cc_key_flags (*BindTriggered)(int key, struct InputDevice* device); /*changes this to use 'cc_key_flag' instead of bool*/ typedef void (*BindReleased)(int key, struct InputDevice* device); /* Gets whether the given input binding is currently being triggered */ CC_API cc_bool KeyBind_IsPressed(InputBind binding); From 3c729c656b0e5f3f9fdb0a88d33491bbcb65fcfc Mon Sep 17 00:00:00 2001 From: flafmg Date: Wed, 18 Jun 2025 13:44:02 -0300 Subject: [PATCH 2/3] fix: correct accidental key_flags replacements in booleans --- src/Entity.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Entity.c b/src/Entity.c index dd2e9042b..d75b2371f 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -861,7 +861,7 @@ static cc_key_flags LocalPlayer_HandleRespawn(int key, struct InputDevice* devic LocalPlayer_DoRespawn(p); return KEY_HANDLED; } else if (!p->_warnedRespawn) { - p->_warnedRespawn = KEY_HANDLED; + p->_warnedRespawn = true; if (hackPermMsgs) Chat_AddRaw("&cRespawning is currently disabled"); } return KEY_NONE; @@ -905,7 +905,7 @@ static cc_key_flags LocalPlayer_HandleFly(int key, struct InputDevice* device) { HacksComp_SetFlying(&p->Hacks, !p->Hacks.Flying); return KEY_HANDLED; } else if (!p->_warnedFly) { - p->_warnedFly = KEY_HANDLED; + p->_warnedFly = true; if (hackPermMsgs) Chat_AddRaw("&cFlying is currently disabled"); } return KEY_NONE; @@ -913,7 +913,7 @@ static cc_key_flags LocalPlayer_HandleFly(int key, struct InputDevice* device) { static cc_key_flags LocalPlayer_HandleNoclip(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; - p->Hacks._noclipping = KEY_HANDLED; + p->Hacks._noclipping = true; if (Gui.InputGrab) return KEY_NONE; if (p->Hacks.CanNoclip && p->Hacks.Enabled) { @@ -923,7 +923,7 @@ static cc_key_flags LocalPlayer_HandleNoclip(int key, struct InputDevice* device HacksComp_SetNoclip(&p->Hacks, !p->Hacks.Noclip); return KEY_HANDLED; } else if (!p->_warnedNoclip) { - p->_warnedNoclip = KEY_HANDLED; + p->_warnedNoclip = true; if (hackPermMsgs) Chat_AddRaw("&cNoclip is currently disabled"); } return KEY_NONE; @@ -935,7 +935,7 @@ static cc_key_flags LocalPlayer_HandleJump(int key, struct InputDevice* device) struct PhysicsComp* physics = &p->Physics; int maxJumps; if (Gui.InputGrab) return KEY_NONE; - physics->Jumping = KEY_HANDLED; + physics->Jumping = true; if (!p->Base.OnGround && !(hacks->Flying || hacks->Noclip)) { maxJumps = hacks->CanDoubleJump && hacks->WOMStyleHacks ? 2 : 0; @@ -953,7 +953,7 @@ static cc_key_flags LocalPlayer_HandleJump(int key, struct InputDevice* device) static cc_key_flags LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* device) { struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks; - cc_key_flags touch = device->type == INPUT_DEVICE_TOUCH; + cc_bool touch = device->type == INPUT_DEVICE_TOUCH; if (Gui.InputGrab) return KEY_NONE; hacks->HalfSpeeding = (!touch || !hacks->HalfSpeeding) && hacks->Enabled; @@ -962,7 +962,7 @@ static cc_key_flags LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* de static cc_key_flags LocalPlayer_TriggerSpeed(int key, struct InputDevice* device) { struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks; - cc_key_flags touch = device->type == INPUT_DEVICE_TOUCH; + cc_bool touch = device->type == INPUT_DEVICE_TOUCH; if (Gui.InputGrab) return KEY_NONE; hacks->Speeding = (!touch || !hacks->Speeding) && hacks->Enabled; From 164a6552bfbc53ef01f9225878fc9d32eb9b0b36 Mon Sep 17 00:00:00 2001 From: flafmg Date: Thu, 24 Jul 2025 21:13:52 -0300 Subject: [PATCH 3/3] change defines to IPT(input) instead of KEY --- src/Entity.c | 52 ++++++++++++++++++------------------- src/InputHandler.c | 64 +++++++++++++++++++++++----------------------- src/InputHandler.h | 10 ++++---- 3 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/Entity.c b/src/Entity.c index d75b2371f..c5231de9c 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -853,29 +853,29 @@ static void LocalPlayer_DoRespawn(struct LocalPlayer* p) { p->Base.OnGround = Entity_TouchesAny(&bb, LocalPlayer_IsSolidCollide); } -static cc_key_flags LocalPlayer_HandleRespawn(int key, struct InputDevice* device) { +static cc_ipt_flags LocalPlayer_HandleRespawn(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; - if (Gui.InputGrab) return KEY_NONE; + if (Gui.InputGrab) return IPT_NONE; if (p->Hacks.CanRespawn) { LocalPlayer_DoRespawn(p); - return KEY_HANDLED; + return IPT_HANDLED; } else if (!p->_warnedRespawn) { p->_warnedRespawn = true; if (hackPermMsgs) Chat_AddRaw("&cRespawning is currently disabled"); } - return KEY_NONE; + return IPT_NONE; } -static cc_key_flags LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) { +static cc_ipt_flags LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; - if (Gui.InputGrab) return KEY_NONE; + if (Gui.InputGrab) return IPT_NONE; if (p->Hacks.CanRespawn) { if (!p->Hacks.CanNoclip && !p->Base.OnGround) { Chat_AddRaw("&cCannot set spawn midair when noclip is disabled"); - return KEY_NONE; + return IPT_NONE; } /* Spawn is normally centered to match vanilla Minecraft classic */ @@ -897,44 +897,44 @@ static cc_key_flags LocalPlayer_HandleSetSpawn(int key, struct InputDevice* devi return LocalPlayer_HandleRespawn(key, device); } -static cc_key_flags LocalPlayer_HandleFly(int key, struct InputDevice* device) { +static cc_ipt_flags LocalPlayer_HandleFly(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; - if (Gui.InputGrab) return KEY_NONE; + if (Gui.InputGrab) return IPT_NONE; if (p->Hacks.CanFly && p->Hacks.Enabled) { HacksComp_SetFlying(&p->Hacks, !p->Hacks.Flying); - return KEY_HANDLED; + return IPT_HANDLED; } else if (!p->_warnedFly) { p->_warnedFly = true; if (hackPermMsgs) Chat_AddRaw("&cFlying is currently disabled"); } - return KEY_NONE; + return IPT_NONE; } -static cc_key_flags LocalPlayer_HandleNoclip(int key, struct InputDevice* device) { +static cc_ipt_flags LocalPlayer_HandleNoclip(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; p->Hacks._noclipping = true; - if (Gui.InputGrab) return KEY_NONE; + if (Gui.InputGrab) return IPT_NONE; if (p->Hacks.CanNoclip && p->Hacks.Enabled) { - if (p->Hacks.WOMStyleHacks) return KEY_HANDLED; /* don't handle this here */ + if (p->Hacks.WOMStyleHacks) return IPT_HANDLED; /* don't handle this here */ if (p->Hacks.Noclip) p->Base.Velocity.y = 0; HacksComp_SetNoclip(&p->Hacks, !p->Hacks.Noclip); - return KEY_HANDLED; + return IPT_HANDLED; } else if (!p->_warnedNoclip) { p->_warnedNoclip = true; if (hackPermMsgs) Chat_AddRaw("&cNoclip is currently disabled"); } - return KEY_NONE; + return IPT_NONE; } -static cc_key_flags LocalPlayer_HandleJump(int key, struct InputDevice* device) { +static cc_ipt_flags LocalPlayer_HandleJump(int key, struct InputDevice* device) { struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex]; struct HacksComp* hacks = &p->Hacks; struct PhysicsComp* physics = &p->Physics; int maxJumps; - if (Gui.InputGrab) return KEY_NONE; + if (Gui.InputGrab) return IPT_NONE; physics->Jumping = true; if (!p->Base.OnGround && !(hacks->Flying || hacks->Noclip)) { @@ -945,28 +945,28 @@ static cc_key_flags LocalPlayer_HandleJump(int key, struct InputDevice* device) PhysicsComp_DoNormalJump(physics); physics->MultiJumps++; } - return KEY_HANDLED; + return IPT_HANDLED; } - return KEY_NONE; + return IPT_NONE; } -static cc_key_flags LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* device) { +static cc_ipt_flags LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* device) { struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks; cc_bool touch = device->type == INPUT_DEVICE_TOUCH; - if (Gui.InputGrab) return KEY_NONE; + if (Gui.InputGrab) return IPT_NONE; hacks->HalfSpeeding = (!touch || !hacks->HalfSpeeding) && hacks->Enabled; - return KEY_HANDLED; + return IPT_HANDLED; } -static cc_key_flags LocalPlayer_TriggerSpeed(int key, struct InputDevice* device) { +static cc_ipt_flags LocalPlayer_TriggerSpeed(int key, struct InputDevice* device) { struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks; cc_bool touch = device->type == INPUT_DEVICE_TOUCH; - if (Gui.InputGrab) return KEY_NONE; + if (Gui.InputGrab) return IPT_NONE; hacks->Speeding = (!touch || !hacks->Speeding) && hacks->Enabled; - return KEY_HANDLED; + return IPT_HANDLED; } static void LocalPlayer_ReleaseHalfSpeed(int key, struct InputDevice* device) { diff --git a/src/InputHandler.c b/src/InputHandler.c index 4856e7988..cda71844c 100644 --- a/src/InputHandler.c +++ b/src/InputHandler.c @@ -632,69 +632,69 @@ static void BindReleased_PickBlock(int key, struct InputDevice* device) { } -static cc_key_flags BindTriggered_HideFPS(int key, struct InputDevice* device) { - if (Gui.InputGrab) return KEY_NONE; +static cc_ipt_flags BindTriggered_HideFPS(int key, struct InputDevice* device) { + if (Gui.InputGrab) return IPT_NONE; Gui.ShowFPS = !Gui.ShowFPS; - return KEY_HANDLED; + return IPT_HANDLED; } -static cc_key_flags BindTriggered_Fullscreen(int key, struct InputDevice* device) { +static cc_ipt_flags BindTriggered_Fullscreen(int key, struct InputDevice* device) { Game_ToggleFullscreen(); - return KEY_HANDLED | KEY_SUPPRESS_UI; + return IPT_HANDLED | IPT_SUPPRESS_UI; } -static cc_key_flags BindTriggered_Fog(int key, struct InputDevice* device) { - if (Gui.InputGrab) return KEY_NONE; +static cc_ipt_flags BindTriggered_Fog(int key, struct InputDevice* device) { + if (Gui.InputGrab) return IPT_NONE; Game_CycleViewDistance(); - return KEY_HANDLED; + return IPT_HANDLED; } -static cc_key_flags BindTriggered_HideGUI(int key, struct InputDevice* device) { - if (Gui.InputGrab) return KEY_NONE; +static cc_ipt_flags BindTriggered_HideGUI(int key, struct InputDevice* device) { + if (Gui.InputGrab) return IPT_NONE; Game_HideGui = !Game_HideGui; - return KEY_HANDLED; + return IPT_HANDLED; } -static cc_key_flags BindTriggered_SmoothCamera(int key, struct InputDevice* device) { - if (Gui.InputGrab) return KEY_NONE; +static cc_ipt_flags BindTriggered_SmoothCamera(int key, struct InputDevice* device) { + if (Gui.InputGrab) return IPT_NONE; InputHandler_Toggle(key, &Camera.Smooth, " &eSmooth camera is &aenabled", " &eSmooth camera is &cdisabled"); - return KEY_HANDLED; + return IPT_HANDLED; } -static cc_key_flags BindTriggered_AxisLines(int key, struct InputDevice* device) { - if (Gui.InputGrab) return KEY_NONE; +static cc_ipt_flags BindTriggered_AxisLines(int key, struct InputDevice* device) { + if (Gui.InputGrab) return IPT_NONE; InputHandler_Toggle(key, &AxisLinesRenderer_Enabled, " &eAxis lines (&4X&e, &2Y&e, &1Z&e) now show", " &eAxis lines no longer show"); - return KEY_HANDLED; + return IPT_HANDLED; } -static cc_key_flags BindTriggered_AutoRotate(int key, struct InputDevice* device) { - if (Gui.InputGrab) return KEY_NONE; +static cc_ipt_flags BindTriggered_AutoRotate(int key, struct InputDevice* device) { + if (Gui.InputGrab) return IPT_NONE; InputHandler_Toggle(key, &AutoRotate_Enabled, " &eAuto rotate is &aenabled", " &eAuto rotate is &cdisabled"); - return KEY_HANDLED; + return IPT_HANDLED; } -static cc_key_flags BindTriggered_ThirdPerson(int key, struct InputDevice* device) { - if (Gui.InputGrab) return KEY_NONE; +static cc_ipt_flags BindTriggered_ThirdPerson(int key, struct InputDevice* device) { + if (Gui.InputGrab) return IPT_NONE; Camera_CycleActive(); - return KEY_HANDLED; + return IPT_HANDLED; } -static cc_key_flags BindTriggered_DropBlock(int key, struct InputDevice* device) { - if (Gui.InputGrab) return KEY_NONE; +static cc_ipt_flags BindTriggered_DropBlock(int key, struct InputDevice* device) { + if (Gui.InputGrab) return IPT_NONE; if (Inventory_CheckChangeSelected() && Inventory_SelectedBlock != BLOCK_AIR) { /* Don't assign SelectedIndex directly, because we don't want held block @@ -702,17 +702,17 @@ static cc_key_flags BindTriggered_DropBlock(int key, struct InputDevice* device) Inventory_Set(Inventory.SelectedIndex, BLOCK_AIR); Event_RaiseVoid(&UserEvents.HeldBlockChanged); } - return KEY_HANDLED; + return IPT_HANDLED; } -static cc_key_flags BindTriggered_IDOverlay(int key, struct InputDevice* device) { +static cc_ipt_flags BindTriggered_IDOverlay(int key, struct InputDevice* device) { struct Screen* s = Gui_GetScreen(GUI_PRIORITY_TEXIDS); if (s) { Gui_Remove(s); } else { TexIdsOverlay_Show(); } - return KEY_HANDLED; + return IPT_HANDLED; } static cc_bool BindTriggered_BreakLiquids(int key, struct InputDevice* device) { @@ -834,7 +834,7 @@ static void OnPointerUp(void* obj, int idx) { static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* device) { struct Screen* s; - cc_key_flags triggered_flags; + cc_ipt_flags triggered_flags; int i; if (Input.DownHook && Input.DownHook(key, device)) return; @@ -852,7 +852,7 @@ static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* dev Game_ScreenshotRequested = true; return; } - triggered_flags = KEY_NONE; + triggered_flags = IPT_NONE; for (i = 0; !was && i < BIND_COUNT; i++) { if (!InputBind_Claims(i, key, device)) continue; @@ -861,7 +861,7 @@ static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* dev if (!Bind_OnTriggered[i]) continue; triggered_flags |= Bind_OnTriggered[i](key, device); } - if (!(triggered_flags & KEY_SUPPRESS_UI)) { //if key is supressing gui's key handling skip it + if (!(triggered_flags & IPT_SUPPRESS_UI)) { //if key is supressing gui's key handling skip it for (i = 0; i < Gui.ScreensCount; i++) { s = Gui_Screens[i]; @@ -886,7 +886,7 @@ static void OnInputDown(void* obj, int key, cc_bool was, struct InputDevice* dev /* Hotkeys should not be triggered multiple times when holding down */ if (was) return; - if (triggered_flags & KEY_HANDLED) { + if (triggered_flags & IPT_HANDLED) { } else if (key == CCKEY_F5 && Game_ClassicMode) { int weather = Env.Weather == WEATHER_SUNNY ? WEATHER_RAINY : WEATHER_SUNNY; Env_SetWeather(weather); diff --git a/src/InputHandler.h b/src/InputHandler.h index c7cb3663b..3940fac7d 100644 --- a/src/InputHandler.h +++ b/src/InputHandler.h @@ -53,12 +53,12 @@ cc_bool Input_HandleMouseWheel(float delta); void InputHandler_Tick(float delta); void InputHandler_OnScreensChanged(void); -typedef cc_uint8 cc_key_flags; /*dont know if this is the best place to put this*/ -#define KEY_NONE 0x00 /* key havent been handled */ -#define KEY_HANDLED 0x01 /* key has been handled */ -#define KEY_SUPPRESS_UI 0x02 /* key supresses GUI's key processing*/ +typedef cc_uint8 cc_ipt_flags; /*dont know if this is the best place to put this*/ +#define IPT_NONE 0x00 /* key havent been handled */ +#define IPT_HANDLED 0x01 /* key has been handled */ +#define IPT_SUPPRESS_UI 0x02 /* key supresses GUI's key processing*/ -typedef cc_key_flags (*BindTriggered)(int key, struct InputDevice* device); /*changes this to use 'cc_key_flag' instead of bool*/ +typedef cc_ipt_flags (*BindTriggered)(int key, struct InputDevice* device); /*changes this to use 'cc_key_flag' instead of bool*/ typedef void (*BindReleased)(int key, struct InputDevice* device); /* Gets whether the given input binding is currently being triggered */ CC_API cc_bool KeyBind_IsPressed(InputBind binding);