Make hotkey struct field naming more consistent

This commit is contained in:
UnknownShadow200 2021-11-15 21:47:07 +11:00
parent b2b6273aa7
commit fa4a63b3bd
3 changed files with 50 additions and 50 deletions

View File

@ -407,12 +407,12 @@ static void Hotkeys_QuickSort(int left, int right) {
while (left < right) { while (left < right) {
int i = left, j = right; int i = left, j = right;
cc_uint8 pivot = keys[(i + j) >> 1].Flags; cc_uint8 pivot = keys[(i + j) >> 1].mods;
/* partition the list */ /* partition the list */
while (i <= j) { while (i <= j) {
while (pivot < keys[i].Flags) i++; while (pivot < keys[i].mods) i++;
while (pivot > keys[j].Flags) j--; while (pivot > keys[j].mods) j--;
QuickSort_Swap_Maybe(); QuickSort_Swap_Maybe();
} }
/* recurse into the smaller subset */ /* recurse into the smaller subset */
@ -422,10 +422,10 @@ 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_bool more) {
struct HotkeyData hKey; struct HotkeyData hKey;
hKey.Trigger = trigger; hKey.trigger = trigger;
hKey.Flags = modifiers; hKey.mods = modifiers;
hKey.TextIndex = HotkeysText.count; hKey.textIndex = HotkeysText.count;
hKey.StaysOpen = more; hKey.staysOpen = more;
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");
@ -443,7 +443,7 @@ static void Hotkeys_RemoveText(int index) {
int i; int i;
for (i = 0; i < HotkeysText.count; i++, hKey++) { for (i = 0; i < HotkeysText.count; i++, hKey++) {
if (hKey->TextIndex >= index) hKey->TextIndex--; if (hKey->textIndex >= index) hKey->textIndex--;
} }
StringsBuffer_Remove(&HotkeysText, index); StringsBuffer_Remove(&HotkeysText, index);
} }
@ -454,11 +454,11 @@ void Hotkeys_Add(int trigger, cc_uint8 modifiers, const cc_string* text, cc_bool
int i; int i;
for (i = 0; i < HotkeysText.count; i++, hk++) { for (i = 0; i < HotkeysText.count; i++, hk++) {
if (hk->Trigger != trigger || hk->Flags != modifiers) continue; if (hk->trigger != trigger || hk->mods != modifiers) continue;
Hotkeys_RemoveText(hk->TextIndex); Hotkeys_RemoveText(hk->textIndex);
hk->StaysOpen = more; hk->staysOpen = more;
hk->TextIndex = HotkeysText.count; hk->textIndex = HotkeysText.count;
StringsBuffer_Add(&HotkeysText, text); StringsBuffer_Add(&HotkeysText, text);
return; return;
} }
@ -470,8 +470,8 @@ cc_bool Hotkeys_Remove(int trigger, cc_uint8 modifiers) {
int i, j; int i, j;
for (i = 0; i < HotkeysText.count; i++, hk++) { for (i = 0; i < HotkeysText.count; i++, hk++) {
if (hk->Trigger != trigger || hk->Flags != modifiers) continue; if (hk->trigger != trigger || hk->mods != modifiers) continue;
Hotkeys_RemoveText(hk->TextIndex); Hotkeys_RemoveText(hk->textIndex);
for (j = i; j < HotkeysText.count; j++) { for (j = i; j < HotkeysText.count; j++) {
HotkeysList[j] = HotkeysList[j + 1]; HotkeysList[j] = HotkeysList[j + 1];
@ -492,7 +492,7 @@ int Hotkeys_FindPartial(int key) {
for (i = 0; i < HotkeysText.count; i++) { for (i = 0; i < HotkeysText.count; i++) {
hk = HotkeysList[i]; hk = HotkeysList[i];
/* e.g. if holding Ctrl and Shift, a hotkey with only Ctrl modifiers matches */ /* e.g. if holding Ctrl and Shift, a hotkey with only Ctrl modifiers matches */
if ((hk.Flags & modifiers) == hk.Flags && hk.Trigger == key) return i; if ((hk.mods & modifiers) == hk.mods && hk.trigger == key) return i;
} }
return -1; return -1;
} }
@ -936,9 +936,9 @@ static void HandleHotkeyDown(int key) {
if (i == -1) return; if (i == -1) return;
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->staysOpen) {
Chat_Send(&text, false); Chat_Send(&text, false);
} else if (!Gui.InputGrab) { } else if (!Gui.InputGrab) {
ChatScreen_OpenInput(&text); ChatScreen_OpenInput(&text);

View File

@ -143,10 +143,10 @@ void KeyBind_Set(KeyBind binding, int key);
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 Flags; /* HotkeyModifiers bitflags */ cc_uint8 mods; /* HotkeyModifiers bitflags */
cc_bool StaysOpen; /* whether the user is able to enter further input */ cc_bool staysOpen; /* whether the user is able to enter further input */
}; };
#define HOTKEYS_MAX_COUNT 256 #define HOTKEYS_MAX_COUNT 256

View File

@ -766,7 +766,7 @@ static void EditHotkeyScreen_UpdateBaseKey(struct EditHotkeyScreen* s) {
String_AppendConst(&text, "Key: press a key.."); String_AppendConst(&text, "Key: press a key..");
} else { } else {
String_AppendConst(&text, "Key: "); String_AppendConst(&text, "Key: ");
String_AppendConst(&text, Input_Names[s->curHotkey.Trigger]); String_AppendConst(&text, Input_Names[s->curHotkey.trigger]);
} }
ButtonWidget_Set(&s->btns[0], &text, &s->titleFont); ButtonWidget_Set(&s->btns[0], &text, &s->titleFont);
} }
@ -779,7 +779,7 @@ static void EditHotkeyScreen_UpdateModifiers(struct EditHotkeyScreen* s) {
String_AppendConst(&text, "Modifiers: press a key.."); String_AppendConst(&text, "Modifiers: press a key..");
} else { } else {
String_AppendConst(&text, "Modifiers:"); String_AppendConst(&text, "Modifiers:");
EditHotkeyScreen_MakeFlags(s->curHotkey.Flags, &text); EditHotkeyScreen_MakeFlags(s->curHotkey.mods, &text);
} }
ButtonWidget_Set(&s->btns[1], &text, &s->titleFont); ButtonWidget_Set(&s->btns[1], &text, &s->titleFont);
} }
@ -789,7 +789,7 @@ 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.staysOpen ? "ON" : "OFF");
ButtonWidget_Set(&s->btns[2], &text, &s->titleFont); ButtonWidget_Set(&s->btns[2], &text, &s->titleFont);
} }
@ -817,7 +817,7 @@ static void EditHotkeyScreen_LeaveOpen(void* screen, void* b) {
EditHotkeyScreen_UpdateModifiers(s); EditHotkeyScreen_UpdateModifiers(s);
} }
s->curHotkey.StaysOpen = !s->curHotkey.StaysOpen; s->curHotkey.staysOpen = !s->curHotkey.staysOpen;
EditHotkeyScreen_UpdateLeaveOpen(s); EditHotkeyScreen_UpdateLeaveOpen(s);
} }
@ -825,16 +825,16 @@ static void EditHotkeyScreen_SaveChanges(void* screen, void* b) {
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen; struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
struct HotkeyData hk = s->origHotkey; struct HotkeyData hk = s->origHotkey;
if (hk.Trigger) { if (hk.trigger) {
Hotkeys_Remove(hk.Trigger, hk.Flags); Hotkeys_Remove(hk.trigger, hk.mods);
StoredHotkeys_Remove(hk.Trigger, hk.Flags); 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.Flags, &text, hk.StaysOpen); Hotkeys_Add(hk.trigger, hk.mods, &text, hk.staysOpen);
StoredHotkeys_Add(hk.Trigger, hk.Flags, hk.StaysOpen, &text); StoredHotkeys_Add(hk.trigger, hk.mods, hk.staysOpen, &text);
} }
HotkeyListScreen_Show(); HotkeyListScreen_Show();
} }
@ -843,9 +843,9 @@ static void EditHotkeyScreen_RemoveHotkey(void* screen, void* b) {
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen; struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
struct HotkeyData hk = s->origHotkey; struct HotkeyData hk = s->origHotkey;
if (hk.Trigger) { if (hk.trigger) {
Hotkeys_Remove(hk.Trigger, hk.Flags); Hotkeys_Remove(hk.trigger, hk.mods);
StoredHotkeys_Remove(hk.Trigger, hk.Flags); StoredHotkeys_Remove(hk.trigger, hk.mods);
} }
HotkeyListScreen_Show(); HotkeyListScreen_Show();
} }
@ -881,12 +881,12 @@ static int EditHotkeyScreen_KeyDown(void* screen, int key) {
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen; struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
if (s->selectedI >= 0) { if (s->selectedI >= 0) {
if (s->selectedI == 0) { if (s->selectedI == 0) {
s->curHotkey.Trigger = key; s->curHotkey.trigger = key;
} else if (s->selectedI == 1) { } else if (s->selectedI == 1) {
if (key == KEY_LCTRL || key == KEY_RCTRL) s->curHotkey.Flags |= HOTKEY_MOD_CTRL; if (key == KEY_LCTRL || key == KEY_RCTRL) s->curHotkey.mods |= HOTKEY_MOD_CTRL;
else if (key == KEY_LSHIFT || key == KEY_RSHIFT) s->curHotkey.Flags |= HOTKEY_MOD_SHIFT; else if (key == KEY_LSHIFT || key == KEY_RSHIFT) s->curHotkey.mods |= HOTKEY_MOD_SHIFT;
else if (key == KEY_LALT || key == KEY_RALT) s->curHotkey.Flags |= HOTKEY_MOD_ALT; else if (key == KEY_LALT || key == KEY_RALT) s->curHotkey.mods |= HOTKEY_MOD_ALT;
else s->curHotkey.Flags = 0; else s->curHotkey.mods = 0;
} }
s->supressNextPress = true; s->supressNextPress = true;
@ -908,7 +908,7 @@ static void EditHotkeyScreen_ContextLost(void* screen) {
static void EditHotkeyScreen_ContextRecreated(void* screen) { static void EditHotkeyScreen_ContextRecreated(void* screen) {
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen; struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
cc_bool existed = s->origHotkey.Trigger != KEY_NONE; cc_bool existed = s->origHotkey.trigger != KEY_NONE;
Gui_MakeTitleFont(&s->titleFont); Gui_MakeTitleFont(&s->titleFont);
Gui_MakeBodyFont(&s->textFont); Gui_MakeBodyFont(&s->textFont);
@ -966,8 +966,8 @@ static void EditHotkeyScreen_Init(void* screen) {
ButtonWidget_Init(&s->btns[3], 300, EditHotkeyScreen_SaveChanges); ButtonWidget_Init(&s->btns[3], 300, EditHotkeyScreen_SaveChanges);
ButtonWidget_Init(&s->btns[4], 300, EditHotkeyScreen_RemoveHotkey); ButtonWidget_Init(&s->btns[4], 300, EditHotkeyScreen_RemoveHotkey);
if (s->origHotkey.Trigger) { if (s->origHotkey.trigger) {
text = StringsBuffer_UNSAFE_Get(&HotkeysText, s->origHotkey.TextIndex); text = StringsBuffer_UNSAFE_Get(&HotkeysText, s->origHotkey.textIndex);
} else { text = String_Empty; } } else { text = String_Empty; }
TextInputWidget_Create(&s->input, 500, &text, &desc); TextInputWidget_Create(&s->input, 500, &text, &desc);
@ -1657,7 +1657,7 @@ static void HotkeyListScreen_EntryClick(void* screen, void* widget) {
struct HotkeyData h, original = { 0 }; struct HotkeyData h, original = { 0 };
cc_string text, key, value; cc_string text, key, value;
int trigger; int trigger;
int i, flags = 0; int i, mods = 0;
text = ListScreen_UNSAFE_GetCur(s, widget); text = ListScreen_UNSAFE_GetCur(s, widget);
if (!text.length) { if (!text.length) {
@ -1665,14 +1665,14 @@ static void HotkeyListScreen_EntryClick(void* screen, void* widget) {
} }
String_UNSAFE_Separate(&text, '+', &key, &value); String_UNSAFE_Separate(&text, '+', &key, &value);
if (String_ContainsConst(&value, "Ctrl")) flags |= HOTKEY_MOD_CTRL; if (String_ContainsConst(&value, "Ctrl")) mods |= HOTKEY_MOD_CTRL;
if (String_ContainsConst(&value, "Shift")) flags |= HOTKEY_MOD_SHIFT; if (String_ContainsConst(&value, "Shift")) mods |= HOTKEY_MOD_SHIFT;
if (String_ContainsConst(&value, "Alt")) flags |= HOTKEY_MOD_ALT; if (String_ContainsConst(&value, "Alt")) mods |= HOTKEY_MOD_ALT;
trigger = Utils_ParseEnum(&key, KEY_NONE, Input_Names, INPUT_COUNT); trigger = Utils_ParseEnum(&key, KEY_NONE, Input_Names, INPUT_COUNT);
for (i = 0; i < HotkeysText.count; i++) { for (i = 0; i < HotkeysText.count; i++) {
h = HotkeysList[i]; h = HotkeysList[i];
if (h.Trigger == trigger && h.Flags == flags) { original = h; break; } if (h.trigger == trigger && h.mods == mods) { original = h; break; }
} }
EditHotkeyScreen_Show(original); EditHotkeyScreen_Show(original);
@ -1693,11 +1693,11 @@ static void HotkeyListScreen_LoadEntries(struct ListScreen* s) {
for (i = 0; i < HotkeysText.count; i++) { for (i = 0; i < HotkeysText.count; i++) {
hKey = HotkeysList[i]; hKey = HotkeysList[i];
text.length = 0; text.length = 0;
String_AppendConst(&text, Input_Names[hKey.Trigger]); String_AppendConst(&text, Input_Names[hKey.trigger]);
if (hKey.Flags) { if (hKey.mods) {
String_AppendConst(&text, " +"); String_AppendConst(&text, " +");
HotkeyListScreen_MakeFlags(hKey.Flags, &text); HotkeyListScreen_MakeFlags(hKey.mods, &text);
} }
StringsBuffer_Add(&s->entries, &text); StringsBuffer_Add(&s->entries, &text);
} }