Forum rules - please read before posting.

[Menu Question] Possible to change when "Alternative input button" is active?

Hello,

I'm currently adding a journal/log menu system, wherein there are around 40 entries. I am using a keyboard-only navigation style, so scrolling can be a bit tedious. In an attempt to ease this, I created scroll "arrows" to use the "Alternative input button" option (named ScrollUp and ScrollDown) to Offset the list when the user gets to them. See image:

image

However, since these Inputs utilize the same keys as the usual up/down, this causes the menu to jump two entries (once from normal input and once from Alternative input). I'm assuming the cause is that the "Alternative input" is active at all times, when I'd only like it active when the appropriate menu item is currently highlighted/in-use.

Might there be a way to remedy this?

Thanks for any help!

Cory

Comments

  • Even if you used scripting to clear the "Alternative input" field so long as the selected slot isn't the bottom of the list, you'd likely still have the same issue of it being read twice - so that pressing down when the last is selected still ends up with the "down" arrow selected after the scroll.

    If you switch over to Unity UI, however, it's relative simple to achieve the right behaviour.

    With Unity UI, you can attach a simple script to the Shift Down button GameObject that - when selected - causes it to shift the list and re-select the bottom-most slot.

    Try this:

    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;
    using AC;
    
    public class AutoShift : MonoBehaviour, ISelectHandler
    {
    
        public AC_ShiftInventory direction;
        public Selectable selectableAfter;
    
        public void OnSelect (BaseEventData eventData)
        {
            Canvas canvas = GetComponentInParent<Canvas> ();
            MenuElement element = KickStarter.playerMenus.GetMenuWithCanvas (canvas).GetElementWithGameObject (selectableAfter.gameObject);
            element.Shift (direction, 1);
            selectableAfter.Select  ();
        }
    
    }
    

    With a Unity UI variant of the Menu (see this tutorial for details on the conversion process), attach the above script to your two shift buttons and update their Inspectors. You'll want to detach these from the Menu, though - the two Shift Button elements in the Menu can be removed.

  • edited March 1

    Hello, and thank you! I actually am learning a lot playing around with the Unity Canvas elements, but for the life of me I cannot get this to work.

    I'm attempting to try it out by editing the premade UI assets inside AC (in this case, ObjectivesUI). I've attached the above script to the btnShiftUp & Down, and set the "Selectable After" to btnSlot1 (Up) and btnSlot5 (Down) respectively. As well as removed the Shift elements from the AC Menu.

    Upon selecting the Shift Buttons they do shift the grid in the appropriate direction, but the selector does not reset and just sits on the Shift Button.

    I also noticed that selecting any 'Inventory' item resets the selector to the top-most slot regardless of where it is. Not sure if that's a sign of what may be wrong or not.

    Keep on keeping on! I appreciate ya trying to decipher my issues. :P

  • Ah. It's down to a "quirk" of Unity's UI system - to manually select a UI object, you need to do so at the end of the frame.

    Try this instead:

    using System.Collections;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;
    using AC;
    
    public class AutoShift : MonoBehaviour, ISelectHandler
    {
    
        public AC_ShiftInventory direction;
        public Selectable selectableAfter;
    
        public void OnSelect (BaseEventData eventData)
        {
            Canvas canvas = GetComponentInParent<Canvas> ();
            MenuElement element = KickStarter.playerMenus.GetMenuWithCanvas (canvas).GetElementWithGameObject (selectableAfter.gameObject);
            element.Shift (direction, 1);
            StartCoroutine (DoSelect ());
        }
    
        private IEnumerator DoSelect ()
        {
            yield return new WaitForEndOfFrame ();
            selectableAfter.Select ();
        }
    
    }
    
  • Ah ha! Thank you, that worked perfectly!

    Sidenote, if anyone encounters a similar issue: The menu snapping back to Slot1 was due to the AC Menu option "Auto-select first visible element" that has to be on for keyboard control. I simply moved that to an ActionList so it'd only be called once, and viola.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.