mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-08 14:56:12 -04:00
Make hotkey struct field naming more consistent
This commit is contained in:
parent
b2b6273aa7
commit
fa4a63b3bd
34
src/Input.c
34
src/Input.c
@ -407,12 +407,12 @@ static void Hotkeys_QuickSort(int left, int right) {
|
||||
|
||||
while (left < 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 */
|
||||
while (i <= j) {
|
||||
while (pivot < keys[i].Flags) i++;
|
||||
while (pivot > keys[j].Flags) j--;
|
||||
while (pivot < keys[i].mods) i++;
|
||||
while (pivot > keys[j].mods) j--;
|
||||
QuickSort_Swap_Maybe();
|
||||
}
|
||||
/* 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) {
|
||||
struct HotkeyData hKey;
|
||||
hKey.Trigger = trigger;
|
||||
hKey.Flags = modifiers;
|
||||
hKey.TextIndex = HotkeysText.count;
|
||||
hKey.StaysOpen = more;
|
||||
hKey.trigger = trigger;
|
||||
hKey.mods = modifiers;
|
||||
hKey.textIndex = HotkeysText.count;
|
||||
hKey.staysOpen = more;
|
||||
|
||||
if (HotkeysText.count == HOTKEYS_MAX_COUNT) {
|
||||
Chat_AddRaw("&cCannot define more than 256 hotkeys");
|
||||
@ -443,7 +443,7 @@ static void Hotkeys_RemoveText(int index) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < HotkeysText.count; i++, hKey++) {
|
||||
if (hKey->TextIndex >= index) hKey->TextIndex--;
|
||||
if (hKey->textIndex >= index) hKey->textIndex--;
|
||||
}
|
||||
StringsBuffer_Remove(&HotkeysText, index);
|
||||
}
|
||||
@ -454,11 +454,11 @@ void Hotkeys_Add(int trigger, cc_uint8 modifiers, const cc_string* text, cc_bool
|
||||
int i;
|
||||
|
||||
for (i = 0; i < HotkeysText.count; i++, hk++) {
|
||||
if (hk->Trigger != trigger || hk->Flags != modifiers) continue;
|
||||
Hotkeys_RemoveText(hk->TextIndex);
|
||||
if (hk->trigger != trigger || hk->mods != modifiers) continue;
|
||||
Hotkeys_RemoveText(hk->textIndex);
|
||||
|
||||
hk->StaysOpen = more;
|
||||
hk->TextIndex = HotkeysText.count;
|
||||
hk->staysOpen = more;
|
||||
hk->textIndex = HotkeysText.count;
|
||||
StringsBuffer_Add(&HotkeysText, text);
|
||||
return;
|
||||
}
|
||||
@ -470,8 +470,8 @@ cc_bool Hotkeys_Remove(int trigger, cc_uint8 modifiers) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < HotkeysText.count; i++, hk++) {
|
||||
if (hk->Trigger != trigger || hk->Flags != modifiers) continue;
|
||||
Hotkeys_RemoveText(hk->TextIndex);
|
||||
if (hk->trigger != trigger || hk->mods != modifiers) continue;
|
||||
Hotkeys_RemoveText(hk->textIndex);
|
||||
|
||||
for (j = i; j < HotkeysText.count; j++) {
|
||||
HotkeysList[j] = HotkeysList[j + 1];
|
||||
@ -492,7 +492,7 @@ int Hotkeys_FindPartial(int key) {
|
||||
for (i = 0; i < HotkeysText.count; i++) {
|
||||
hk = HotkeysList[i];
|
||||
/* 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;
|
||||
}
|
||||
@ -936,9 +936,9 @@ static void HandleHotkeyDown(int key) {
|
||||
|
||||
if (i == -1) return;
|
||||
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);
|
||||
} else if (!Gui.InputGrab) {
|
||||
ChatScreen_OpenInput(&text);
|
||||
|
@ -143,10 +143,10 @@ void KeyBind_Set(KeyBind binding, int key);
|
||||
|
||||
extern const cc_uint8 Hotkeys_LWJGL[256];
|
||||
struct HotkeyData {
|
||||
int TextIndex; /* contents to copy directly into the input bar */
|
||||
cc_uint8 Trigger; /* Member of Key enumeration */
|
||||
cc_uint8 Flags; /* HotkeyModifiers bitflags */
|
||||
cc_bool StaysOpen; /* whether the user is able to enter further input */
|
||||
int textIndex; /* contents to copy directly into the input bar */
|
||||
cc_uint8 trigger; /* Member of Key enumeration */
|
||||
cc_uint8 mods; /* HotkeyModifiers bitflags */
|
||||
cc_bool staysOpen; /* whether the user is able to enter further input */
|
||||
};
|
||||
|
||||
#define HOTKEYS_MAX_COUNT 256
|
||||
|
58
src/Menus.c
58
src/Menus.c
@ -766,7 +766,7 @@ static void EditHotkeyScreen_UpdateBaseKey(struct EditHotkeyScreen* s) {
|
||||
String_AppendConst(&text, "Key: press a key..");
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
@ -779,7 +779,7 @@ static void EditHotkeyScreen_UpdateModifiers(struct EditHotkeyScreen* s) {
|
||||
String_AppendConst(&text, "Modifiers: press a key..");
|
||||
} else {
|
||||
String_AppendConst(&text, "Modifiers:");
|
||||
EditHotkeyScreen_MakeFlags(s->curHotkey.Flags, &text);
|
||||
EditHotkeyScreen_MakeFlags(s->curHotkey.mods, &text);
|
||||
}
|
||||
ButtonWidget_Set(&s->btns[1], &text, &s->titleFont);
|
||||
}
|
||||
@ -789,7 +789,7 @@ static void EditHotkeyScreen_UpdateLeaveOpen(struct EditHotkeyScreen* s) {
|
||||
String_InitArray(text, textBuffer);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -817,7 +817,7 @@ static void EditHotkeyScreen_LeaveOpen(void* screen, void* b) {
|
||||
EditHotkeyScreen_UpdateModifiers(s);
|
||||
}
|
||||
|
||||
s->curHotkey.StaysOpen = !s->curHotkey.StaysOpen;
|
||||
s->curHotkey.staysOpen = !s->curHotkey.staysOpen;
|
||||
EditHotkeyScreen_UpdateLeaveOpen(s);
|
||||
}
|
||||
|
||||
@ -825,16 +825,16 @@ static void EditHotkeyScreen_SaveChanges(void* screen, void* b) {
|
||||
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
|
||||
struct HotkeyData hk = s->origHotkey;
|
||||
|
||||
if (hk.Trigger) {
|
||||
Hotkeys_Remove(hk.Trigger, hk.Flags);
|
||||
StoredHotkeys_Remove(hk.Trigger, hk.Flags);
|
||||
if (hk.trigger) {
|
||||
Hotkeys_Remove(hk.trigger, hk.mods);
|
||||
StoredHotkeys_Remove(hk.trigger, hk.mods);
|
||||
}
|
||||
|
||||
hk = s->curHotkey;
|
||||
if (hk.Trigger) {
|
||||
if (hk.trigger) {
|
||||
cc_string text = s->input.base.text;
|
||||
Hotkeys_Add(hk.Trigger, hk.Flags, &text, hk.StaysOpen);
|
||||
StoredHotkeys_Add(hk.Trigger, hk.Flags, hk.StaysOpen, &text);
|
||||
Hotkeys_Add(hk.trigger, hk.mods, &text, hk.staysOpen);
|
||||
StoredHotkeys_Add(hk.trigger, hk.mods, hk.staysOpen, &text);
|
||||
}
|
||||
HotkeyListScreen_Show();
|
||||
}
|
||||
@ -843,9 +843,9 @@ static void EditHotkeyScreen_RemoveHotkey(void* screen, void* b) {
|
||||
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
|
||||
struct HotkeyData hk = s->origHotkey;
|
||||
|
||||
if (hk.Trigger) {
|
||||
Hotkeys_Remove(hk.Trigger, hk.Flags);
|
||||
StoredHotkeys_Remove(hk.Trigger, hk.Flags);
|
||||
if (hk.trigger) {
|
||||
Hotkeys_Remove(hk.trigger, hk.mods);
|
||||
StoredHotkeys_Remove(hk.trigger, hk.mods);
|
||||
}
|
||||
HotkeyListScreen_Show();
|
||||
}
|
||||
@ -881,12 +881,12 @@ static int EditHotkeyScreen_KeyDown(void* screen, int key) {
|
||||
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
|
||||
if (s->selectedI >= 0) {
|
||||
if (s->selectedI == 0) {
|
||||
s->curHotkey.Trigger = key;
|
||||
s->curHotkey.trigger = key;
|
||||
} else if (s->selectedI == 1) {
|
||||
if (key == KEY_LCTRL || key == KEY_RCTRL) s->curHotkey.Flags |= HOTKEY_MOD_CTRL;
|
||||
else if (key == KEY_LSHIFT || key == KEY_RSHIFT) s->curHotkey.Flags |= HOTKEY_MOD_SHIFT;
|
||||
else if (key == KEY_LALT || key == KEY_RALT) s->curHotkey.Flags |= HOTKEY_MOD_ALT;
|
||||
else s->curHotkey.Flags = 0;
|
||||
if (key == KEY_LCTRL || key == KEY_RCTRL) s->curHotkey.mods |= HOTKEY_MOD_CTRL;
|
||||
else if (key == KEY_LSHIFT || key == KEY_RSHIFT) s->curHotkey.mods |= HOTKEY_MOD_SHIFT;
|
||||
else if (key == KEY_LALT || key == KEY_RALT) s->curHotkey.mods |= HOTKEY_MOD_ALT;
|
||||
else s->curHotkey.mods = 0;
|
||||
}
|
||||
|
||||
s->supressNextPress = true;
|
||||
@ -908,7 +908,7 @@ static void EditHotkeyScreen_ContextLost(void* screen) {
|
||||
|
||||
static void EditHotkeyScreen_ContextRecreated(void* 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_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[4], 300, EditHotkeyScreen_RemoveHotkey);
|
||||
|
||||
if (s->origHotkey.Trigger) {
|
||||
text = StringsBuffer_UNSAFE_Get(&HotkeysText, s->origHotkey.TextIndex);
|
||||
if (s->origHotkey.trigger) {
|
||||
text = StringsBuffer_UNSAFE_Get(&HotkeysText, s->origHotkey.textIndex);
|
||||
} else { text = String_Empty; }
|
||||
|
||||
TextInputWidget_Create(&s->input, 500, &text, &desc);
|
||||
@ -1657,7 +1657,7 @@ static void HotkeyListScreen_EntryClick(void* screen, void* widget) {
|
||||
struct HotkeyData h, original = { 0 };
|
||||
cc_string text, key, value;
|
||||
int trigger;
|
||||
int i, flags = 0;
|
||||
int i, mods = 0;
|
||||
|
||||
text = ListScreen_UNSAFE_GetCur(s, widget);
|
||||
if (!text.length) {
|
||||
@ -1665,14 +1665,14 @@ static void HotkeyListScreen_EntryClick(void* screen, void* widget) {
|
||||
}
|
||||
|
||||
String_UNSAFE_Separate(&text, '+', &key, &value);
|
||||
if (String_ContainsConst(&value, "Ctrl")) flags |= HOTKEY_MOD_CTRL;
|
||||
if (String_ContainsConst(&value, "Shift")) flags |= HOTKEY_MOD_SHIFT;
|
||||
if (String_ContainsConst(&value, "Alt")) flags |= HOTKEY_MOD_ALT;
|
||||
if (String_ContainsConst(&value, "Ctrl")) mods |= HOTKEY_MOD_CTRL;
|
||||
if (String_ContainsConst(&value, "Shift")) mods |= HOTKEY_MOD_SHIFT;
|
||||
if (String_ContainsConst(&value, "Alt")) mods |= HOTKEY_MOD_ALT;
|
||||
|
||||
trigger = Utils_ParseEnum(&key, KEY_NONE, Input_Names, INPUT_COUNT);
|
||||
for (i = 0; i < HotkeysText.count; 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);
|
||||
@ -1693,11 +1693,11 @@ static void HotkeyListScreen_LoadEntries(struct ListScreen* s) {
|
||||
for (i = 0; i < HotkeysText.count; i++) {
|
||||
hKey = HotkeysList[i];
|
||||
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, " +");
|
||||
HotkeyListScreen_MakeFlags(hKey.Flags, &text);
|
||||
HotkeyListScreen_MakeFlags(hKey.mods, &text);
|
||||
}
|
||||
StringsBuffer_Add(&s->entries, &text);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user