Opening chat input shouldn't cause 'speed: X' to immediately vanish

This commit is contained in:
UnknownShadow200 2020-12-27 18:32:03 +11:00
parent 1457d1207c
commit fb4c74d0a0
5 changed files with 41 additions and 46 deletions

View File

@ -803,30 +803,46 @@ static void LocalPlayer_HandleInput(float* xMoving, float* zMoving) {
if (Gui.InputGrab) { if (Gui.InputGrab) {
/* TODO: Don't always turn these off anytime a screen is opened, only do it on InputUp */ /* 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; p->Physics.Jumping = false; hacks->FlyingUp = false; hacks->FlyingDown = false;
hacks->FlyingUp = false; hacks->FlyingDown = false; return;
} 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));
}
} }
/* 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) { 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) { static void Entities_Init(void) {
Event_Register_(&GfxEvents.ContextLost, NULL, Entities_ContextLost); Event_Register_(&GfxEvents.ContextLost, NULL, Entities_ContextLost);
Event_Register_(&ChatEvents.FontChanged, NULL, Entities_ChatFontChanged); 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, Entities.NamesMode = Options_GetEnum(OPT_NAMES_MODE, NAME_MODE_HOVERED,
NameMode_Names, Array_Elems(NameMode_Names)); NameMode_Names, Array_Elems(NameMode_Names));

View File

@ -97,7 +97,6 @@ void Event_UnregisterAll(void) {
InputEvents.Up.Count = 0; InputEvents.Up.Count = 0;
InputEvents.Wheel.Count = 0; InputEvents.Wheel.Count = 0;
InputEvents.TextChanged.Count = 0; InputEvents.TextChanged.Count = 0;
InputEvents.BindChanged.Count = 0;
PointerEvents.Moved.Count = 0; PointerEvents.Moved.Count = 0;
PointerEvents.Down.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); 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);
}
}

View File

@ -63,12 +63,6 @@ struct Event_RawMove {
void* Objs[EVENT_MAX_CALLBACKS]; int Count; 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. */ /* 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. */ /* 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); 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); void Event_RaiseString(struct Event_String* handlers, const cc_string* str);
/* Calls all registered callbacks for an event which has raw pointer movement arguments. */ /* Calls all registered callbacks for an event which has raw pointer movement arguments. */
void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDelta); 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); void Event_UnregisterAll(void);
/* NOTE: Event_UnregisterAll must be updated if events lists are changed */ /* 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_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_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_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; } InputEvents;
CC_VAR extern struct _PointerEventsList { CC_VAR extern struct _PointerEventsList {

View File

@ -345,9 +345,7 @@ void KeyBind_Set(KeyBind binding, int key) {
String_Format1(&name, "key-%c", keybindNames[binding]); String_Format1(&name, "key-%c", keybindNames[binding]);
value = String_FromReadonly(Input_Names[key]); value = String_FromReadonly(Input_Names[key]);
Options_SetString(&name, &value); Options_SetString(&name, &value);
KeyBinds[binding] = key; KeyBinds[binding] = key;
Event_RaiseBind(&InputEvents.BindChanged, binding, KeyBind_IsPressed(binding));
} }
/* Initialises and loads key bindings from options */ /* Initialises and loads key bindings from options */

View File

@ -688,10 +688,6 @@ static void TabListOverlay_Render(void* screen, double delta) {
Texture_Render(&tex); Texture_Render(&tex);
} }
Gfx_SetTexturing(false); 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) { static void TabListOverlay_Free(void* screen) {