get rid of keypress from widgets (only inputwidget used and needs it), fix edithotkey screen not showing

This commit is contained in:
UnknownShadow200 2019-08-17 20:41:42 +10:00
parent 6c90fdd884
commit 02deabc0da
4 changed files with 27 additions and 38 deletions

View file

@ -66,7 +66,6 @@ struct WidgetVTABLE {
void (*Free)(void* elem);
bool (*HandlesKeyDown)(void* elem, Key key);
bool (*HandlesKeyUp)(void* elem, Key key);
bool (*HandlesKeyPress)(void* elem, char keyChar);
bool (*HandlesMouseDown)(void* elem, int x, int y, MouseButton btn);
bool (*HandlesMouseUp)(void* elem, int x, int y, MouseButton btn);
bool (*HandlesMouseMove)(void* elem, int x, int y);

View file

@ -374,7 +374,7 @@ static void ListScreen_Select(struct ListScreen* s, const String* str) {
static bool ListScreen_KeyDown(void* screen, Key key) {
struct ListScreen* s = (struct ListScreen*)screen;
if (key == KEY_LEFT || key == KEY_PAGEUP) {
if (key == KEY_LEFT || key == KEY_PAGEUP) {
ListScreen_PageClick(s, false);
} else if (key == KEY_RIGHT || key == KEY_PAGEDOWN) {
ListScreen_PageClick(s, true);
@ -753,21 +753,17 @@ static void EditHotkeyScreen_MakeLeaveOpen(struct EditHotkeyScreen* s, Widget_Le
}
static void EditHotkeyScreen_BaseKey(void* screen, void* b) {
static const String msg = String_FromConst("Key: press a key..");
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
s->selectedI = 0;
s->supressNextPress = true;
ButtonWidget_Set(&s->buttons[0], &msg, &s->titleFont);
ButtonWidget_SetConst(&s->buttons[0], "Key: press a key..", &s->titleFont);
}
static void EditHotkeyScreen_Modifiers(void* screen, void* b) {
static const String msg = String_FromConst("Modifiers: press a key..");
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
s->selectedI = 1;
s->supressNextPress = true;
ButtonWidget_Set(&s->buttons[1], &msg, &s->titleFont);
ButtonWidget_SetConst(&s->buttons[1], "Modifiers: press a key..", &s->titleFont);
}
static void EditHotkeyScreen_LeaveOpen(void* screen, void* b) {
@ -839,9 +835,10 @@ static bool EditHotkeyScreen_KeyPress(void* screen, char keyChar) {
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
if (s->supressNextPress) {
s->supressNextPress = false;
return true;
} else {
InputWidget_Append(&s->input.base, keyChar);
}
return Elem_HandlesKeyPress(&s->input.base, keyChar);
return true;
}
static bool EditHotkeyScreen_KeyDown(void* screen, Key key) {
@ -907,7 +904,7 @@ static struct ScreenVTABLE EditHotkeyScreen_VTABLE = {
Menu_MouseDown, Menu_MouseUp, Menu_MouseMove, MenuScreen_MouseScroll,
Menu_OnResize, Menu_ContextLost, EditHotkeyScreen_ContextRecreated
};
struct Screen* EditHotkeyScreen_MakeInstance(struct HotkeyData original) {
void EditHotkeyScreen_Show(struct HotkeyData original) {
static struct Widget* widgets[7];
struct EditHotkeyScreen* s = &EditHotkeyScreen_Instance;
@ -920,7 +917,7 @@ struct Screen* EditHotkeyScreen_MakeInstance(struct HotkeyData original) {
s->selectedI = -1;
s->origHotkey = original;
s->curHotkey = original;
return (struct Screen*)s;
Gui_Replace((struct Screen*)s, GUI_PRIORITY_MENU);
}
@ -1039,7 +1036,8 @@ static bool GenLevelScreen_KeyUp(void* screen, Key key) {
static bool GenLevelScreen_KeyPress(void* screen, char keyChar) {
struct GenLevelScreen* s = (struct GenLevelScreen*)screen;
return !s->selected || Elem_HandlesKeyPress(&s->selected->base, keyChar);
if (s->selected) InputWidget_Append(&s->selected->base, keyChar);
return true;
}
static void GenLevelScreen_ContextRecreated(void* screen) {
@ -1244,7 +1242,8 @@ static void SaveLevelScreen_Render(void* screen, double delta) {
static bool SaveLevelScreen_KeyPress(void* screen, char keyChar) {
struct SaveLevelScreen* s = (struct SaveLevelScreen*)screen;
SaveLevelScreen_RemoveOverwrites(s);
return Elem_HandlesKeyPress(&s->input.base, keyChar);
InputWidget_Append(&s->input.base, keyChar);
return true;
}
static bool SaveLevelScreen_KeyDown(void* screen, Key key) {
@ -1412,8 +1411,7 @@ static void HotkeyListScreen_EntryClick(void* screen, void* widget) {
text = ListScreen_UNSAFE_GetCur(s, widget);
if (String_CaselessEqualsConst(&text, LIST_SCREEN_EMPTY)) {
Gui_FreeActive();
Gui_SetActive(EditHotkeyScreen_MakeInstance(original));
EditHotkeyScreen_Show(original);
return;
}
@ -1428,8 +1426,7 @@ static void HotkeyListScreen_EntryClick(void* screen, void* widget) {
if (h.Trigger == trigger && h.Flags == flags) { original = h; break; }
}
Gui_FreeActive();
Gui_SetActive(EditHotkeyScreen_MakeInstance(original));
EditHotkeyScreen_Show(original);
}
static void HotkeyListScreen_MakeFlags(int flags, String* str) {
@ -1940,8 +1937,8 @@ static void MenuOptionsScreen_ContextLost(void* screen) {
static bool MenuOptionsScreen_KeyPress(void* screen, char keyChar) {
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
if (s->activeI == -1) return true;
return Elem_HandlesKeyPress(&s->input.base, keyChar);
if (s->activeI >= 0) InputWidget_Append(&s->input.base, keyChar);
return true;
}
static bool MenuOptionsScreen_KeyDown(void* screen, Key key) {

View file

@ -1024,7 +1024,7 @@ static bool HUDScreen_KeyPress(void* screen, char keyChar) {
return false;
}
Elem_HandlesKeyPress(&s->input.base, keyChar);
InputWidget_Append(&s->input.base, keyChar);
HUDScreen_UpdateAltTextY(s);
return true;
}

View file

@ -24,7 +24,6 @@ static Size2D Size2D_Empty;
static bool Widget_Mouse(void* elem, int x, int y, MouseButton btn) { return false; }
static bool Widget_Key(void* elem, Key key) { return false; }
static bool Widget_KeyPress(void* elem, char keyChar) { return false; }
static bool Widget_MouseMove(void* elem, int x, int y) { return false; }
static bool Widget_MouseScroll(void* elem, float delta) { return false; }
@ -50,7 +49,7 @@ static void TextWidget_Reposition(void* widget) {
static struct WidgetVTABLE TextWidget_VTABLE = {
Widget_NullFunc, TextWidget_Render, TextWidget_Free,
Widget_Key, Widget_Key, Widget_KeyPress,
Widget_Key, Widget_Key,
Widget_Mouse, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
TextWidget_Reposition
};
@ -153,7 +152,7 @@ static void ButtonWidget_Render(void* widget, double delta) {
static struct WidgetVTABLE ButtonWidget_VTABLE = {
Widget_NullFunc, ButtonWidget_Render, ButtonWidget_Free,
Widget_Key, Widget_Key, Widget_KeyPress,
Widget_Key, Widget_Key,
Widget_Mouse, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
ButtonWidget_Reposition
};
@ -299,7 +298,7 @@ static bool ScrollbarWidget_MouseMove(void* widget, int x, int y) {
static struct WidgetVTABLE ScrollbarWidget_VTABLE = {
Widget_NullFunc, ScrollbarWidget_Render, Widget_NullFunc,
Widget_Key, Widget_Key, Widget_KeyPress,
Widget_Key, Widget_Key,
ScrollbarWidget_MouseDown, ScrollbarWidget_MouseUp, ScrollbarWidget_MouseMove, ScrollbarWidget_MouseScroll,
Widget_CalcPosition
};
@ -488,7 +487,7 @@ static bool HotbarWidget_MouseScroll(void* widget, float delta) {
static struct WidgetVTABLE HotbarWidget_VTABLE = {
HotbarWidget_Init, HotbarWidget_Render, Widget_NullFunc,
HotbarWidget_KeyDown, HotbarWidget_KeyUp, Widget_KeyPress,
HotbarWidget_KeyDown, HotbarWidget_KeyUp,
HotbarWidget_MouseDown, Widget_Mouse, Widget_MouseMove, HotbarWidget_MouseScroll,
HotbarWidget_Reposition
};
@ -820,7 +819,7 @@ static bool TableWidget_KeyDown(void* widget, Key key) {
static struct WidgetVTABLE TableWidget_VTABLE = {
TableWidget_Init, TableWidget_Render, TableWidget_Free,
TableWidget_KeyDown, Widget_Key, Widget_KeyPress,
TableWidget_KeyDown, Widget_Key,
TableWidget_MouseDown, TableWidget_MouseUp, TableWidget_MouseMove, TableWidget_MouseScroll,
TableWidget_Reposition
};
@ -1212,12 +1211,6 @@ static bool InputWidget_KeyDown(void* widget, Key key) {
static bool InputWidget_KeyUp(void* widget, Key key) { return true; }
static bool InputWidget_KeyPress(void* widget, char keyChar) {
struct InputWidget* w = (struct InputWidget*)widget;
InputWidget_Append(w, keyChar);
return true;
}
static bool InputWidget_MouseDown(void* widget, int x, int y, MouseButton button) {
String line; char lineBuffer[STRING_SIZE];
struct InputWidget* w = (struct InputWidget*)widget;
@ -1492,7 +1485,7 @@ static bool MenuInputWidget_AllowedChar(void* widget, char c) {
static int MenuInputWidget_GetMaxLines(void) { return 1; }
static struct WidgetVTABLE MenuInputWidget_VTABLE = {
InputWidget_Init, MenuInputWidget_Render, InputWidget_Free,
InputWidget_KeyDown, InputWidget_KeyUp, InputWidget_KeyPress,
InputWidget_KeyDown, InputWidget_KeyUp,
InputWidget_MouseDown, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
InputWidget_Reposition
};
@ -1745,7 +1738,7 @@ static int ChatInputWidget_GetMaxLines(void) {
static struct WidgetVTABLE ChatInputWidget_VTABLE = {
InputWidget_Init, ChatInputWidget_Render, InputWidget_Free,
ChatInputWidget_KeyDown, InputWidget_KeyUp, InputWidget_KeyPress,
ChatInputWidget_KeyDown, InputWidget_KeyUp,
InputWidget_MouseDown, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
InputWidget_Reposition
};
@ -2142,7 +2135,7 @@ static void PlayerListWidget_Free(void* widget) {
static struct WidgetVTABLE PlayerListWidget_VTABLE = {
PlayerListWidget_Init, PlayerListWidget_Render, PlayerListWidget_Free,
Widget_Key, Widget_Key, Widget_KeyPress,
Widget_Key, Widget_Key,
Widget_Mouse, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
PlayerListWidget_Reposition
};
@ -2574,7 +2567,7 @@ static void TextGroupWidget_Free(void* widget) {
static struct WidgetVTABLE TextGroupWidget_VTABLE = {
TextGroupWidget_Init, TextGroupWidget_Render, TextGroupWidget_Free,
Widget_Key, Widget_Key, Widget_KeyPress,
Widget_Key, Widget_Key,
Widget_Mouse, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
TextGroupWidget_Reposition
};
@ -2827,7 +2820,7 @@ void SpecialInputWidget_SetActive(struct SpecialInputWidget* w, bool active) {
static struct WidgetVTABLE SpecialInputWidget_VTABLE = {
SpecialInputWidget_Init, SpecialInputWidget_Render, SpecialInputWidget_Free,
Widget_Key, Widget_Key, Widget_KeyPress,
Widget_Key, Widget_Key,
SpecialInputWidget_MouseDown, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
Widget_CalcPosition
};