Track whether a hotkey is user or server defined

This commit is contained in:
UnknownShadow200 2021-11-15 22:33:45 +11:00
parent fa4a63b3bd
commit b62e9fd10c
5 changed files with 28 additions and 17 deletions

View File

@ -229,7 +229,7 @@ void HacksComp_RecheckFlags(struct HacksComp* hacks) {
/* Can use hacks by default (also case with WoM), no need to check +hax */ /* Can use hacks by default (also case with WoM), no need to check +hax */
cc_bool hax = !String_ContainsConst(&hacks->HacksFlags, "-hax"); cc_bool hax = !String_ContainsConst(&hacks->HacksFlags, "-hax");
HacksComp_SetAll(hacks, hax); HacksComp_SetAll(hacks, hax);
hacks->CanBePushed = true; hacks->CanBePushed = true;
HacksComp_ParseFlag(hacks, "+fly", "-fly", &hacks->CanFly); HacksComp_ParseFlag(hacks, "+fly", "-fly", &hacks->CanFly);
HacksComp_ParseFlag(hacks, "+noclip", "-noclip", &hacks->CanNoclip); HacksComp_ParseFlag(hacks, "+noclip", "-noclip", &hacks->CanNoclip);

View File

@ -420,12 +420,12 @@ static void Hotkeys_QuickSort(int left, int right) {
} }
} }
static void Hotkeys_AddNewHotkey(int trigger, cc_uint8 modifiers, const cc_string* text, cc_bool more) { static void Hotkeys_AddNewHotkey(int trigger, cc_uint8 modifiers, const cc_string* text, cc_uint8 flags) {
struct HotkeyData hKey; struct HotkeyData hKey;
hKey.trigger = trigger; hKey.trigger = trigger;
hKey.mods = modifiers; hKey.mods = modifiers;
hKey.textIndex = HotkeysText.count; hKey.textIndex = HotkeysText.count;
hKey.staysOpen = more; hKey.flags = flags;
if (HotkeysText.count == HOTKEYS_MAX_COUNT) { if (HotkeysText.count == HOTKEYS_MAX_COUNT) {
Chat_AddRaw("&cCannot define more than 256 hotkeys"); Chat_AddRaw("&cCannot define more than 256 hotkeys");
@ -449,7 +449,7 @@ static void Hotkeys_RemoveText(int index) {
} }
void Hotkeys_Add(int trigger, cc_uint8 modifiers, const cc_string* text, cc_bool more) { void Hotkeys_Add(int trigger, cc_uint8 modifiers, const cc_string* text, cc_uint8 flags) {
struct HotkeyData* hk = HotkeysList; struct HotkeyData* hk = HotkeysList;
int i; int i;
@ -457,12 +457,12 @@ void Hotkeys_Add(int trigger, cc_uint8 modifiers, const cc_string* text, cc_bool
if (hk->trigger != trigger || hk->mods != modifiers) continue; if (hk->trigger != trigger || hk->mods != modifiers) continue;
Hotkeys_RemoveText(hk->textIndex); Hotkeys_RemoveText(hk->textIndex);
hk->staysOpen = more; hk->flags = flags;
hk->textIndex = HotkeysText.count; hk->textIndex = HotkeysText.count;
StringsBuffer_Add(&HotkeysText, text); StringsBuffer_Add(&HotkeysText, text);
return; return;
} }
Hotkeys_AddNewHotkey(trigger, modifiers, text, more); Hotkeys_AddNewHotkey(trigger, modifiers, text, flags);
} }
cc_bool Hotkeys_Remove(int trigger, cc_uint8 modifiers) { cc_bool Hotkeys_Remove(int trigger, cc_uint8 modifiers) {
@ -938,7 +938,7 @@ static void HandleHotkeyDown(int key) {
hkey = &HotkeysList[i]; hkey = &HotkeysList[i];
text = StringsBuffer_UNSAFE_Get(&HotkeysText, hkey->textIndex); text = StringsBuffer_UNSAFE_Get(&HotkeysText, hkey->textIndex);
if (!hkey->staysOpen) { if (!(hkey->flags & HOTKEY_FLAG_STAYS_OPEN)) {
Chat_Send(&text, false); Chat_Send(&text, false);
} else if (!Gui.InputGrab) { } else if (!Gui.InputGrab) {
ChatScreen_OpenInput(&text); ChatScreen_OpenInput(&text);

View File

@ -141,12 +141,17 @@ CC_API cc_bool KeyBind_IsPressed(KeyBind binding);
/* Set the key that the given key binding is bound to. (also updates options list) */ /* Set the key that the given key binding is bound to. (also updates options list) */
void KeyBind_Set(KeyBind binding, int key); void KeyBind_Set(KeyBind binding, int key);
/* whether to leave text input open for user to enter further input */
#define HOTKEY_FLAG_STAYS_OPEN 0x01
/* Whether the hotkey was auto defined (e.g. by server) */
#define HOTKEY_FLAG_AUTO_DEFINED 0x02
extern const cc_uint8 Hotkeys_LWJGL[256]; extern const cc_uint8 Hotkeys_LWJGL[256];
struct HotkeyData { struct HotkeyData {
int textIndex; /* contents to copy directly into the input bar */ int textIndex; /* contents to copy directly into the input bar */
cc_uint8 trigger; /* Member of Key enumeration */ cc_uint8 trigger; /* Member of Key enumeration */
cc_uint8 mods; /* HotkeyModifiers bitflags */ cc_uint8 mods; /* HotkeyModifiers bitflags */
cc_bool staysOpen; /* whether the user is able to enter further input */ cc_uint8 flags; /* HOTKEY_FLAG flags */
}; };
#define HOTKEYS_MAX_COUNT 256 #define HOTKEYS_MAX_COUNT 256
@ -157,7 +162,7 @@ enum HotkeyModifiers {
}; };
/* Adds or updates a new hotkey. */ /* Adds or updates a new hotkey. */
void Hotkeys_Add(int trigger, cc_uint8 modifiers, const cc_string* text, cc_bool more); void Hotkeys_Add(int trigger, cc_uint8 modifiers, const cc_string* text, cc_uint8 flags);
/* Removes the given hotkey. */ /* Removes the given hotkey. */
cc_bool Hotkeys_Remove(int trigger, cc_uint8 modifiers); cc_bool Hotkeys_Remove(int trigger, cc_uint8 modifiers);
/* Returns the first hotkey which is bound to the given key and has its modifiers pressed. */ /* Returns the first hotkey which is bound to the given key and has its modifiers pressed. */

View File

@ -789,7 +789,8 @@ static void EditHotkeyScreen_UpdateLeaveOpen(struct EditHotkeyScreen* s) {
String_InitArray(text, textBuffer); String_InitArray(text, textBuffer);
String_AppendConst(&text, "Input stays open: "); String_AppendConst(&text, "Input stays open: ");
String_AppendConst(&text, s->curHotkey.staysOpen ? "ON" : "OFF"); String_AppendConst(&text,
(s->curHotkey.flags & HOTKEY_FLAG_STAYS_OPEN) ? "ON" : "OFF");
ButtonWidget_Set(&s->btns[2], &text, &s->titleFont); ButtonWidget_Set(&s->btns[2], &text, &s->titleFont);
} }
@ -817,7 +818,8 @@ static void EditHotkeyScreen_LeaveOpen(void* screen, void* b) {
EditHotkeyScreen_UpdateModifiers(s); EditHotkeyScreen_UpdateModifiers(s);
} }
s->curHotkey.staysOpen = !s->curHotkey.staysOpen; /* Toggle Input Stays Open flag */
s->curHotkey.flags ^= HOTKEY_FLAG_STAYS_OPEN;
EditHotkeyScreen_UpdateLeaveOpen(s); EditHotkeyScreen_UpdateLeaveOpen(s);
} }
@ -829,12 +831,14 @@ static void EditHotkeyScreen_SaveChanges(void* screen, void* b) {
Hotkeys_Remove(hk.trigger, hk.mods); Hotkeys_Remove(hk.trigger, hk.mods);
StoredHotkeys_Remove(hk.trigger, hk.mods); StoredHotkeys_Remove(hk.trigger, hk.mods);
} }
hk = s->curHotkey; hk = s->curHotkey;
if (hk.trigger) { if (hk.trigger) {
cc_string text = s->input.base.text; cc_string text = s->input.base.text;
Hotkeys_Add(hk.trigger, hk.mods, &text, hk.staysOpen); cc_bool staysOpen = hk.flags & HOTKEY_FLAG_STAYS_OPEN;
StoredHotkeys_Add(hk.trigger, hk.mods, hk.staysOpen, &text);
Hotkeys_Add(hk.trigger, hk.mods, &text, hk.flags);
StoredHotkeys_Add(hk.trigger, hk.mods, staysOpen, &text);
} }
HotkeyListScreen_Show(); HotkeyListScreen_Show();
} }

View File

@ -1015,9 +1015,11 @@ static void CPE_SetTextHotkey(cc_uint8* data) {
StoredHotkeys_Load(key, keyMods); StoredHotkeys_Load(key, keyMods);
} else if (action.buffer[action.length - 1] == '\n') { } else if (action.buffer[action.length - 1] == '\n') {
action.length--; action.length--;
Hotkeys_Add(key, keyMods, &action, false); Hotkeys_Add(key, keyMods, &action,
HOTKEY_FLAG_AUTO_DEFINED);
} else { /* more input needed by user */ } else { /* more input needed by user */
Hotkeys_Add(key, keyMods, &action, true); Hotkeys_Add(key, keyMods, &action,
HOTKEY_FLAG_AUTO_DEFINED | HOTKEY_FLAG_STAYS_OPEN);
} }
} }