Forum rules - please read before posting.

Item count alignment

Hi Chris, would it be possible to allow us to change the alignment of the item count, both in the cursor and in an AC menu's inventory slot? I'm aware that it's already possible to do this if you use Unity UI for the inventory, but (1) the AC menu is very useful for simple interfaces, and I got it working just right except for this, and (2) as far as I'm aware, you can't use Unity UI for the cursor.

What I have in mind is an item count at the bottom right of the icon, like in Stardew Valley or Minecraft, instead of sitting right in the middle of the icon.

Comments

  • It's a level of customisation that Unity UI is intended for - AC-based menus are best used for rapid prototyping.

    Unity UI is available as a cursor-rendering option - see the Manual's "Unity UI Cursor rendering" chapter - however, additional scripting is currently required to display the item count with this method. I will incorporate this into the UnityUICursor script as part of the next update.

  • Right, I could redo my inventory menu in Unity UI if necessary!

    The cursor situation is a bit more complicated though (please bear with me). I've got a couple of dozen interfaces all working and ready to go, and about 2/3 of them are AC-based. If I change the cursor, I'm going to have to redo everything because of the render order of Unity UI vs GUI elements.

    I was already subclassing RuntimeInventory anyway (see https://www.adventurecreator.org/forum/discussion/11272/display-item-amounts), so I decided to poke around. I got the effect I needed by doing this:

        public override void DrawSelectedInventoryCount()
        {
            if (KickStarter.cursorManager.displayCountSize <= 0)
            {
                return;
            }
    
            if (InvInstance.IsValid(selectedInstance))
            {
                string countText = GetInventoryCountText();
                if (!string.IsNullOrEmpty(countText))
                {
                    Vector2 cursorPosition = KickStarter.playerInput.GetMousePosition();
                    float cursorSize = KickStarter.cursorManager.inventoryCursorSize;
    
                    if (countTextEffects != TextEffects.None)
                    {                   
                        Vector2 cursorOffset = new Vector2(30 * ACScreen.safeArea.width / 1920, -30 * ACScreen.safeArea.height / 1080);
                        AdvGame.DrawTextEffect(AdvGame.GUIBox(cursorPosition + cursorOffset, cursorSize), countText, countStyle, Color.black, countStyle.normal.textColor, 2, countTextEffects);
                    }
                    else
                    {
                        GUI.Label(AdvGame.GUIBox(cursorPosition, cursorSize), countText, countStyle);
                    }
                }
            }
        }
    

    This looks exactly the way I want it to... for 16:9 resolutions only. I do use a fixed aspect ratio of 1.78, enforced by AC, but there are two issues that I can see:

    (1) This one has to do with my code above. If the screen resolution is not 16:9 and AC creates black bars to enforce the aspect ratio, my cursor offset isn't rendered exactly at the intended location:

    Am I calculating AC's playable area incorrectly?

    (2) This one is inherent to AC. I've noticed that the AC cursor also acts wonky at different resolutions. As you can see above, it seems to behave if the screen is very tall, but if you make the screen very wide, the cursor gets huge:

    This doesn't seem like a big issue because monitor sizes are never that extreme, but having a consistent cursor size is sometimes really important, and this makes it impossible to predict.

    Lastly, I looked into the inventory menu code to see if it could be as easily modified as this, but I gather it isn't? I see the draw location is defined by a Rect, but I wouldn't know what to do with it. Either way, I could redo my inventory menu! That's a manageable amount of work. I'm just worried about all the others.

  • Re: the last question, don't worry about it, I've redone the inventory in Unity UI and it's looking good! But I'd really like to keep using the software-rendered cursor.

  • Am I calculating AC's playable area incorrectly?

    You might not need to. Try it with:

    Vector2 cursorOffset = new Vector2(30, -30);
    

    having a consistent cursor size is sometimes really important, and this makes it impossible to predict.

    The Software cursor size is tied with the screen's width, but you can have it be a fixed size at all times with the Hardware cursor option.

    Otherwise, you may have to look into dynamically altering the Inventory cursor size through script. Right-click the field's label in the Cursor Manager to get an API reference to it.

  • You might not need to. Try it with:

    Vector2 cursorOffset = new Vector2(30, -30);

    Thanks! This didn't quite work (the location of the number changes even between 16:9 resolutions), but! Your comment about the cursor size being tied to width made me realise that this would work, for anyone else who would benefit:

    Vector2 cursorOffset = new Vector2(30 * ACScreen.safeArea.width / 1920, -30 * ACScreen.safeArea.width / 1920);

  • Thanks! In case anyone is interested in the solution (you'd have to adapt it since these are for my desired settings, but you get the gist):

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class ResizeCursor : MonoBehaviour
    {
        float x = 0;
    
        void Update()
        {
            float xScale = (KickStarter.mainCamera) ? KickStarter.mainCamera.GetPlayableScreenArea(false).size.x : ACScreen.width;          
            float cursorRatio = xScale / ACScreen.width;   
    
            if (cursorRatio != x)
            {
    
                AC.KickStarter.cursorManager.pointerIcon.size = 0.03f * cursorRatio;
                AC.KickStarter.cursorManager.mouseOverIcon.size = 0.03f * cursorRatio;
                AC.KickStarter.cursorManager.inventoryCursorSize = 0.06f * cursorRatio;
                AC.KickStarter.cursorManager.waitIcon.size = 0.03f * cursorRatio;
    
                int i = 0;
                while (i < 16)
                {
                    AC.KickStarter.cursorManager.GetCursorIconFromID(i).size = 0.03f * cursorRatio;
                    i++;
                }
    
                x = cursorRatio;
            }
    
    
        }
    }
    

    And this:

    using UnityEngine;
    using System.Collections.Generic;
    using AC;
    
    public class CustomRuntimeInventory : RuntimeInventory
    {
    
        public override void DrawSelectedInventoryCount()
        {
            if (KickStarter.cursorManager.displayCountSize <= 0)
            {
                return;
            }
    
            if (InvInstance.IsValid(selectedInstance))
            {
                string countText = GetInventoryCountText();
                if (!string.IsNullOrEmpty(countText))
                {
                    Vector2 cursorPosition = KickStarter.playerInput.GetMousePosition();
                    float cursorSize = KickStarter.cursorManager.inventoryCursorSize;
    
                    if (countTextEffects != TextEffects.None)
                    {                   
                        Color32 outlineColor = new Color32(45, 135, 135, 255);
    
                        float xScale = (KickStarter.mainCamera) ? KickStarter.mainCamera.GetPlayableScreenArea(false).size.x : ACScreen.width;
                        float cursorRatio = xScale / ACScreen.width;
                        Vector2 cursorOffset = new Vector2(30 * ACScreen.safeArea.width / 1920, -30 * ACScreen.safeArea.width / 1920);
                        cursorPosition = cursorPosition + (cursorOffset * cursorRatio);
    
                        AdvGame.DrawTextEffect(AdvGame.GUIBox(cursorPosition, cursorSize), countText, countStyle, outlineColor, countStyle.normal.textColor, 2, countTextEffects);
                    }
                    else
                    {
                        GUI.Label(AdvGame.GUIBox(cursorPosition, cursorSize), countText, countStyle);
                    }
                }
            }
        }
    }
    

    To get the second script to work you need to replace the RuntimeInventory component in the PersistentEngine prefab.

  • Nice, thanks for posting!

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.