Forum rules - please read before posting.

Scrolling menu, controled by and reflected by a slider?

Ok so I have the menu system working exactly as I want, comes and goes via buttons, it also auto-hides when I select an object from it, I can scroll the list up and down by clicking the top and bottom buttons. This is all excellent.

However, to make the interface more efficient I'd like to have the slider reflect the position the player is in the inventory list. I'd also like the ability to grab the handle and scroll their way through the inventory. Is this possible?

I have made a vertical slider with the graphics and positions figured out. I can grab it and slide it around and it stops exactly where it needs too, top and bottom, perfectly. But I have no idea how to hook this into the menu, there is an option to add a slider to the inventory menu, and it is that, but it doesn't control anything as of yet.

Any idea on how I should approach this? Any easy way to hook this in to at least get it to reflect the position in the inventory scrolling? Or better yet, have it also control the scrolling?

Let me know,
Thank you.

I've worked on this for 15 hours on my own and the discord hasn't really been active today for some reason.

Attached is a screenshot showing the scroller and buttons.

If you need me to clarify anything let me know. :)

Comments

  • Something like this should probably do it:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class InventorySlider : MonoBehaviour
    {
    
        public Slider slider;
        public string menuName = "Inventory";
        public string inventoryElementName = "InventoryBox";
        private MenuInventoryBox inventoryBox;
    
    
        private void OnEnable ()
        {
            UpdateScrollbar ();
            EventManager.OnMenuElementShift += OnMenuElementShift;
        }
    
        private void OnDisable ()
        {
            EventManager.OnMenuElementShift -= OnMenuElementShift;
        }
    
        private void OnMenuElementShift (MenuElement _element, AC_ShiftInventory shiftType)
        {
            if (_element is MenuInventoryBox)
            {
                UpdateScrollbar ();
            }
        }
    
        private void UpdateScrollbar ()
        {
            if (inventoryBox == null)
            {
                inventoryBox = PlayerMenus.GetElementWithName (menuName, inventoryElementName) as MenuInventoryBox;
            }
    
            if (inventoryBox != null)
            {
                slider.minValue = 0f;
                slider.maxValue = (float) KickStarter.runtimeInventory.GetNumberOfItemsCarried (true);
                slider.normalizedValue = (float) inventoryBox.GetOffset () / (slider.maxValue - inventoryBox.GetNumSlots ());
            }
        }
    
    }
    
  • First off, THANK YOU!

    Wow, that's awesome.

    I'm not 100% sure where to put it, but I'll guess and try a few places. The script makes sense, I'm just fuzzy on where to add the script exactly and I'm a bit tired (1:30am here). I'll probably think more clearly in the morning.

    Again, thank you so much!

  • Ok, I placed it on my slider base and hooked it up and it now reflects the position of the list. So if I hit the buttons and get midway it's in the middle at the bottom it's at the bottom, which is awesome.

    Is there a way to have it work the other way? Since I can grab the slider and move it, can I make the list move to the middle for if I drag the slider to the middle? I see it changes the variable number, but that doesn't translate to the list having shifted.

    Was this supposed to do that too and I did something wrong or is it to just reflect the current position? Still, you have me halfway there which is awesome. And the hide reveal works perfectly too and it remembers it's previous position A+! :D

  • SFGSFG
    edited April 2020

    On a strange side note, this warning comes up, but as you can see everything is spelled and capitalized properly... Not sure why this is happening?


  • Is the warning persistent or just once? It's likely safe to ignore.

    No, the script is one-way only - for the moment, you should disable the Slider's interactivity so that it's not possible to move it manually.

    The reverse way would probably be a case of calling the inventory's SetOffset function via the Slider's OnValueChanged click handler - but I'm not sure how to limit that only when the user changes it, and not when the value is changed via the script above.

  • Persistent but it doesn't seem to affect anything.

    I'm not really sure how to do that... Been a PM too long, lol. Well at least the interface looks nice. I guess I'll call it good enough for now :) Thank you for everything. I need to focus on getting this demo ready for Steam's virtual festival. Been working on art, writing and music for over a year now, it's nice to finally be putting it all together :D

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.