From fb4c74d0a0ee3899fc9ec357379c161b57bfd654 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 27 Dec 2020 18:32:03 +1100 Subject: [PATCH] Opening chat input shouldn't cause 'speed: X' to immediately vanish --- src/Entity.c | 64 +++++++++++++++++++++++++++++++++------------------ src/Event.c | 8 ------- src/Event.h | 9 -------- src/Input.c | 2 -- src/Screens.c | 4 ---- 5 files changed, 41 insertions(+), 46 deletions(-) diff --git a/src/Entity.c b/src/Entity.c index ce9a5e8f0..dc37a173a 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -803,30 +803,46 @@ static void LocalPlayer_HandleInput(float* xMoving, float* zMoving) { if (Gui.InputGrab) { /* TODO: Don't always turn these off anytime a screen is opened, only do it on InputUp */ - p->Physics.Jumping = false; hacks->Speeding = false; hacks->HalfSpeeding = false; - hacks->FlyingUp = false; hacks->FlyingDown = false; - } else { - /* keyboard input, touch, joystick, etc */ - for (input = &p->input; input; input = input->next) { - input->GetMovement(xMoving, zMoving); - } - *xMoving *= 0.98f; - *zMoving *= 0.98f; - - p->Physics.Jumping = KeyBind_IsPressed(KEYBIND_JUMP); - hacks->Speeding = hacks->Enabled && KeyBind_IsPressed(KEYBIND_SPEED); - hacks->HalfSpeeding = hacks->Enabled && KeyBind_IsPressed(KEYBIND_HALF_SPEED); - hacks->FlyingUp = KeyBind_IsPressed(KEYBIND_FLY_UP); - hacks->FlyingDown = KeyBind_IsPressed(KEYBIND_FLY_DOWN); - - if (hacks->WOMStyleHacks && hacks->Enabled && hacks->CanNoclip) { - if (hacks->Noclip) { - /* need a { } block because it's a macro */ - Vec3_Set(p->Base.Velocity, 0,0,0); - } - HacksComp_SetNoclip(hacks, KeyBind_IsPressed(KEYBIND_NOCLIP)); - } + p->Physics.Jumping = false; hacks->FlyingUp = false; hacks->FlyingDown = false; + return; } + + /* keyboard input, touch, joystick, etc */ + for (input = &p->input; input; input = input->next) { + input->GetMovement(xMoving, zMoving); + } + *xMoving *= 0.98f; + *zMoving *= 0.98f; + + p->Physics.Jumping = KeyBind_IsPressed(KEYBIND_JUMP); + hacks->FlyingUp = KeyBind_IsPressed(KEYBIND_FLY_UP); + hacks->FlyingDown = KeyBind_IsPressed(KEYBIND_FLY_DOWN); + + if (hacks->WOMStyleHacks && hacks->Enabled && hacks->CanNoclip) { + if (hacks->Noclip) { + /* need a { } block because it's a macro */ + Vec3_Set(p->Base.Velocity, 0,0,0); + } + HacksComp_SetNoclip(hacks, KeyBind_IsPressed(KEYBIND_NOCLIP)); + } +} + +static void LocalPlayer_InputSet(int key, cc_bool pressed) { + struct LocalPlayer* p = &LocalPlayer_Instance; + struct HacksComp* hacks = &p->Hacks; + + if (pressed && !hacks->Enabled) return; + if (key == KeyBinds[KEYBIND_SPEED]) hacks->Speeding = pressed; + if (key == KeyBinds[KEYBIND_HALF_SPEED]) hacks->HalfSpeeding = pressed; +} + +static void LocalPlayer_InputDown(void* obj, int key) { + /* e.g. pressing Shift in chat input shouldn't turn on speeding */ + if (!Gui.InputGrab) LocalPlayer_InputSet(key, true); +} + +static void LocalPlayer_InputUp(void* obj, int key) { + LocalPlayer_InputSet(key, false); } static void LocalPlayer_SetLocation(struct Entity* e, struct LocationUpdate* update, cc_bool interpolate) { @@ -1165,6 +1181,8 @@ void NetPlayer_Init(struct NetPlayer* p) { static void Entities_Init(void) { Event_Register_(&GfxEvents.ContextLost, NULL, Entities_ContextLost); Event_Register_(&ChatEvents.FontChanged, NULL, Entities_ChatFontChanged); + Event_Register_(&InputEvents.Down, NULL, LocalPlayer_InputDown); + Event_Register_(&InputEvents.Up, NULL, LocalPlayer_InputUp); Entities.NamesMode = Options_GetEnum(OPT_NAMES_MODE, NAME_MODE_HOVERED, NameMode_Names, Array_Elems(NameMode_Names)); diff --git a/src/Event.c b/src/Event.c index e95facc33..2cc3fc060 100644 --- a/src/Event.c +++ b/src/Event.c @@ -97,7 +97,6 @@ void Event_UnregisterAll(void) { InputEvents.Up.Count = 0; InputEvents.Wheel.Count = 0; InputEvents.TextChanged.Count = 0; - InputEvents.BindChanged.Count = 0; PointerEvents.Moved.Count = 0; PointerEvents.Down.Count = 0; @@ -170,10 +169,3 @@ void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDel handlers->Handlers[i](handlers->Objs[i], xDelta, yDelta); } } - -void Event_RaiseBind(struct Event_Bind* handlers, int binding, int pressed) { - int i; - for (i = 0; i < handlers->Count; i++) { - handlers->Handlers[i](handlers->Objs[i], binding, pressed); - } -} diff --git a/src/Event.h b/src/Event.h index 197f5f015..0613f7621 100644 --- a/src/Event.h +++ b/src/Event.h @@ -63,12 +63,6 @@ struct Event_RawMove { void* Objs[EVENT_MAX_CALLBACKS]; int Count; }; -typedef void (*Event_Bind_Callback)(void* obj, int binding, int pressed); -struct Event_Bind { - Event_Bind_Callback Handlers[EVENT_MAX_CALLBACKS]; - void* Objs[EVENT_MAX_CALLBACKS]; int Count; -}; - /* Registers a callback function for the given event. */ /* NOTE: Trying to register a callback twice or over EVENT_MAX_CALLBACKS callbacks will terminate the game. */ CC_API void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler); @@ -100,8 +94,6 @@ void Event_RaiseInput(struct Event_Input* handlers, int key, cc_bool repeating); void Event_RaiseString(struct Event_String* handlers, const cc_string* str); /* Calls all registered callbacks for an event which has raw pointer movement arguments. */ void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDelta); -/* Calls all registered callbacks for an event which has key binding arguments. */ -void Event_RaiseBind(struct Event_Bind* handlers, int binding, int pressed); void Event_UnregisterAll(void); /* NOTE: Event_UnregisterAll must be updated if events lists are changed */ @@ -172,7 +164,6 @@ CC_VAR extern struct _InputEventsList { struct Event_Int Up; /* Key or button is released. Arg is a member of Key enumeration */ struct Event_Float Wheel; /* Mouse wheel is moved/scrolled (Arg is wheel delta) */ struct Event_String TextChanged; /* Text in the on-screen input keyboard changed (for Mobile) */ - struct Event_Bind BindChanged; /* Key binding changed. Arg is a member of KeyBind enumeration*/ } InputEvents; CC_VAR extern struct _PointerEventsList { diff --git a/src/Input.c b/src/Input.c index 4e64d07eb..dae1c15f8 100644 --- a/src/Input.c +++ b/src/Input.c @@ -345,9 +345,7 @@ void KeyBind_Set(KeyBind binding, int key) { String_Format1(&name, "key-%c", keybindNames[binding]); value = String_FromReadonly(Input_Names[key]); Options_SetString(&name, &value); - KeyBinds[binding] = key; - Event_RaiseBind(&InputEvents.BindChanged, binding, KeyBind_IsPressed(binding)); } /* Initialises and loads key bindings from options */ diff --git a/src/Screens.c b/src/Screens.c index 279d8e24e..71be09c33 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -688,10 +688,6 @@ static void TabListOverlay_Render(void* screen, double delta) { Texture_Render(&tex); } Gfx_SetTexturing(false); - - /* NOTE: Should usually be caught by KeyUp, but just in case. */ - if (KeyBind_IsPressed(KEYBIND_TABLIST) || Input_TouchMode) return; - Gui_Remove((struct Screen*)s); } static void TabListOverlay_Free(void* screen) {