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 // see if interactable captures this scancode
if (djui_interactable_on_key_down(scancode)) { if (djui_interactable_on_key_down(scancode)) {
keyboard_lastkey = scancode;
return FALSE; return FALSE;
} }

View file

@ -23,7 +23,6 @@ static void djui_bind_button_on_bind(struct DjuiBase* caller) {
if (key == VK_INVALID) { return; } if (key == VK_INVALID) { return; }
// invalidate key // invalidate key
if (key == VK_ESCAPE) { key = VK_INVALID; }
for (int i = 0; i < MAX_BINDS; i++) { for (int i = 0; i < MAX_BINDS; i++) {
if (i == button->base.tag) { continue; } if (i == button->base.tag) { continue; }
if (bind->configKey[i] == key) { 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) { static void djui_chat_box_input_escape(struct DjuiInputbox* chatInput) {
djui_interactable_set_input_focus(NULL);
djui_inputbox_set_text(chatInput, ""); djui_inputbox_set_text(chatInput, "");
djui_inputbox_select_all(chatInput); djui_inputbox_select_all(chatInput);
if (gDjuiChatBoxFocus) { djui_chat_box_toggle(); } 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) { void djui_interactable_set_input_focus(struct DjuiBase* base) {
djui_interactable_on_focus_end(base); djui_interactable_on_focus_end(sInteractableFocus);
sInteractableFocus = base; sInteractableFocus = base;
djui_interactable_on_focus_begin(base); djui_interactable_on_focus_begin(base);
djui_cursor_set_visible(base == NULL); 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) { bool djui_interactable_on_key_down(int scancode) {
if (sInteractableBinding != NULL) {
return true;
}
bool keyFocused = (sInteractableFocus != NULL) bool keyFocused = (sInteractableFocus != NULL)
&& (sInteractableFocus->interactable != 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 // pressed escape button on keyboard
djui_panel_back(); djui_panel_back();
return true;
} }
if (gDjuiChatBox != NULL && !gDjuiChatBoxFocus) { if (gDjuiChatBox != NULL && !gDjuiChatBoxFocus) {
@ -194,6 +198,7 @@ bool djui_interactable_on_key_down(int scancode) {
} }
} }
if (gDjuiChatBoxFocus || djui_panel_is_active()) {
switch (scancode) { switch (scancode) {
case SCANCODE_UP: sKeyboardHoldDirection = PAD_HOLD_DIR_UP; return true; case SCANCODE_UP: sKeyboardHoldDirection = PAD_HOLD_DIR_UP; return true;
case SCANCODE_DOWN: sKeyboardHoldDirection = PAD_HOLD_DIR_DOWN; return true; case SCANCODE_DOWN: sKeyboardHoldDirection = PAD_HOLD_DIR_DOWN; return true;
@ -201,6 +206,7 @@ bool djui_interactable_on_key_down(int scancode) {
case SCANCODE_RIGHT: sKeyboardHoldDirection = PAD_HOLD_DIR_RIGHT; return true; case SCANCODE_RIGHT: sKeyboardHoldDirection = PAD_HOLD_DIR_RIGHT; return true;
case SCANCODE_ENTER: sKeyboardButtons |= PAD_BUTTON_A; return true; case SCANCODE_ENTER: sKeyboardButtons |= PAD_BUTTON_A; return true;
} }
}
return false; return false;
} }