Made DJUI no longer take priority over arrowkey/enter binds when no panel is active

This commit is contained in:
MysterD 2021-08-01 13:18:22 -07:00
parent caa13fb69f
commit aedba38ca5
4 changed files with 16 additions and 9 deletions

View file

@ -44,6 +44,7 @@ bool keyboard_on_key_down(int scancode) {
// see if interactable captures this scancode
if (djui_interactable_on_key_down(scancode)) {
keyboard_lastkey = scancode;
return FALSE;
}

View file

@ -23,7 +23,6 @@ static void djui_bind_button_on_bind(struct DjuiBase* caller) {
if (key == VK_INVALID) { return; }
// invalidate key
if (key == VK_ESCAPE) { key = VK_INVALID; }
for (int i = 0; i < MAX_BINDS; i++) {
if (i == button->base.tag) { continue; }
if (bind->configKey[i] == key) {

View file

@ -40,6 +40,7 @@ static void djui_chat_box_input_enter(struct DjuiInputbox* chatInput) {
}
static void djui_chat_box_input_escape(struct DjuiInputbox* chatInput) {
djui_interactable_set_input_focus(NULL);
djui_inputbox_set_text(chatInput, "");
djui_inputbox_select_all(chatInput);
if (gDjuiChatBoxFocus) { djui_chat_box_toggle(); }

View file

@ -152,7 +152,7 @@ void djui_interactable_set_binding(struct DjuiBase* base) {
}
void djui_interactable_set_input_focus(struct DjuiBase* base) {
djui_interactable_on_focus_end(base);
djui_interactable_on_focus_end(sInteractableFocus);
sInteractableFocus = base;
djui_interactable_on_focus_begin(base);
djui_cursor_set_visible(base == NULL);
@ -163,6 +163,9 @@ bool djui_interactable_is_input_focus(struct DjuiBase* base) {
}
bool djui_interactable_on_key_down(int scancode) {
if (sInteractableBinding != NULL) {
return true;
}
bool keyFocused = (sInteractableFocus != NULL)
&& (sInteractableFocus->interactable != NULL)
@ -177,9 +180,10 @@ bool djui_interactable_on_key_down(int scancode) {
}
}
if (scancode == SCANCODE_ESCAPE) {
if (scancode == SCANCODE_ESCAPE && djui_panel_is_active()) {
// pressed escape button on keyboard
djui_panel_back();
return true;
}
if (gDjuiChatBox != NULL && !gDjuiChatBoxFocus) {
@ -194,12 +198,14 @@ bool djui_interactable_on_key_down(int scancode) {
}
}
switch (scancode) {
case SCANCODE_UP: sKeyboardHoldDirection = PAD_HOLD_DIR_UP; return true;
case SCANCODE_DOWN: sKeyboardHoldDirection = PAD_HOLD_DIR_DOWN; return true;
case SCANCODE_LEFT: sKeyboardHoldDirection = PAD_HOLD_DIR_LEFT; return true;
case SCANCODE_RIGHT: sKeyboardHoldDirection = PAD_HOLD_DIR_RIGHT; return true;
case SCANCODE_ENTER: sKeyboardButtons |= PAD_BUTTON_A; return true;
if (gDjuiChatBoxFocus || djui_panel_is_active()) {
switch (scancode) {
case SCANCODE_UP: sKeyboardHoldDirection = PAD_HOLD_DIR_UP; return true;
case SCANCODE_DOWN: sKeyboardHoldDirection = PAD_HOLD_DIR_DOWN; return true;
case SCANCODE_LEFT: sKeyboardHoldDirection = PAD_HOLD_DIR_LEFT; return true;
case SCANCODE_RIGHT: sKeyboardHoldDirection = PAD_HOLD_DIR_RIGHT; return true;
case SCANCODE_ENTER: sKeyboardButtons |= PAD_BUTTON_A; return true;
}
}
return false;