Having Issue Using UI Object

Discuss modding questions and implementation details.
Post Reply
l3lessed
Posts: 1400
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Having Issue Using UI Object

Post by l3lessed »

So, working on the UI for outfit manager, and I am having an issue. I have used the override method to override the inventory objects and inject my own code into the base cycle.

It all seemed to be working well, once I got it going and used the setup and update methods in the inventory window. However, when I equip weapons, It equips two items, one after the other. It appears I have two inventory windows open, so when I click to equip an item, it seems to think I am clicking the inventory twice. Where am I going wrong with this code?

Code: Select all

using UnityEngine;
using System;
using DaggerfallWorkshop.Game.UserInterface;
using System.Linq;
using OutfitManager;

namespace DaggerfallWorkshop.Game.UserInterfaceWindows
{
    public class OutfitManagerInventoryWindow : DaggerfallInventoryWindow
    {
        public TextLabel currentoutfitLabel;
        public TextLabel BundleLabel;
        private TextLabel RebundleLabel;
        public TextLabel DismantleLabel;
        private Button NextoutfitButton;
        private object PrevoufitButton;
        private Button PrevoutfitButton;
        private TextLabel selectedoutfitLabel;
        private TextLabel NextoutfitLabel;
        private TextLabel PrevoutfitLabel;
        private Button BundleButton;
        private Button DismantleButton;
        DaggerfallFont outfitFont = new DaggerfallFont(DaggerfallFont.FontName.FONT0000);
        DaggerfallFont buttonFont = new DaggerfallFont(DaggerfallFont.FontName.FONT0002);

        public OutfitManagerInventoryWindow(IUserInterfaceManager uiManager, DaggerfallBaseWindow previous = null)
    : base(uiManager, previous)
        {

        }

        protected override void Setup()
        {
            base.Setup();
            currentoutfitLabel = DaggerfallUI.AddTextLabel(outfitFont, new Vector2(DaggerfallUI.Instance.InventoryWindow.NativePanel.InteriorWidth * OutfitManager.OutfitManager.instance.panelSlider, 12f), "", DaggerfallUI.Instance.InventoryWindow.NativePanel);
            //BundleLabel = DaggerfallUI.AddTextLabel(buttonFont, new Vector2(50, 193), "Bundle", DaggerfallUI.Instance.InventoryWindow.NativePanel);
            //RebundleLabel = DaggerfallUI.AddTextLabel(buttonFont, new Vector2(50, 18), "Rebundle", DaggerfallUI.Instance.InventoryWindow.NativePanel);
            //DismantleLabel = DaggerfallUI.AddTextLabel(buttonFont, new Vector2(129, 193), "Dismantle", DaggerfallUI.Instance.InventoryWindow.NativePanel);
            selectedoutfitLabel = DaggerfallUI.AddTextLabel(buttonFont, new Vector2(89, 190), OutfitManager.OutfitManager.instance.currentOutfit, DaggerfallUI.Instance.InventoryWindow.NativePanel);
            NextoutfitLabel = DaggerfallUI.AddTextLabel(buttonFont, new Vector2(120, 191), ">", DaggerfallUI.Instance.InventoryWindow.NativePanel);
            PrevoutfitLabel = DaggerfallUI.AddTextLabel(buttonFont, new Vector2(80, 191), "<", DaggerfallUI.Instance.InventoryWindow.NativePanel);

            BundleButton = DaggerfallUI.AddButton(new Rect(89, 191, 30, 10), DaggerfallUI.Instance.InventoryWindow.NativePanel);
            DismantleButton = DaggerfallUI.AddButton(new Rect(89, 191, 30, 10), DaggerfallUI.Instance.InventoryWindow.NativePanel);
            NextoutfitButton = DaggerfallUI.AddButton(new Rect(120, 191, 10, 10), DaggerfallUI.Instance.InventoryWindow.NativePanel);
            PrevoutfitButton = DaggerfallUI.AddButton(new Rect(80, 191, 10, 10), DaggerfallUI.Instance.InventoryWindow.NativePanel);

            BundleButton.OnMouseClick += OutfitManager.OutfitManager.instance.SaveOutfitBundle;
            DismantleButton.OnMouseClick += OutfitManager.OutfitManager.instance.DeleteOutfit;
            NextoutfitButton.OnMouseClick += OutfitManager.OutfitManager.instance.NextOutfit;
            PrevoutfitButton.OnMouseClick += OutfitManager.OutfitManager.instance.PreviousOutfit;
        }

        public override void Update()
        {
            base.Update();

//CODE INJECTION: updates inventory UI when outfit name is changed by player using outfit manager ui controls. This works fine to update the UI propertly, despite the equip bug. Still have equip bug with this code removed, so this does not cause it.
            if(currentoutfitLabel.Text != OutfitManager.OutfitManager.instance.currentOutfit)
            {
                currentoutfitLabel.Position = new Vector2(((DaggerfallUI.Instance.InventoryWindow.NativePanel.InteriorWidth - currentoutfitLabel.TextWidth) * OutfitManager.OutfitManager.instance.panelSlider), 12f);
                currentoutfitLabel.Text = OutfitManager.OutfitManager.instance.currentOutfit;
            }
            else if(currentoutfitLabel.Text == OutfitManager.OutfitManager.instance.currentOutfit && currentoutfitLabel.Text == "Bundle" && selectedoutfitLabel.Text != "Bundle")
            {
                currentoutfitLabel.Enabled = false;
                BundleButton.Enabled = true;
                DismantleButton.Enabled = false;
                selectedoutfitLabel.Text = "Bundle";
            }
            else if (currentoutfitLabel.Text == OutfitManager.OutfitManager.instance.currentOutfit && currentoutfitLabel.Text != "Bundle" && selectedoutfitLabel.Text != "Unbundle")
            {
                currentoutfitLabel.Enabled = true;
                BundleButton.Enabled = false;
                DismantleButton.Enabled = true;
                selectedoutfitLabel.Text = "Unbundle";
            }
        }
    }
}
Even with a simple update routine like this, it causes a duplicate inventory window. I imagine I'm not overriding/implementing this 100% correct.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Having Issue Using UI Object

Post by Hazelnut »

Are you setting this up with UIWindowFactory.RegisterCustomUIWindow() ?
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

l3lessed
Posts: 1400
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Having Issue Using UI Object

Post by l3lessed »

Yes, in the main mod loading and manager script. The above code is from the the UI manager script, which is loaded through the separate main management script for the actual code that launches the mod and runs the outfit routines.

Code: Select all

        void Awake()
        {
                UIWindowFactory.RegisterCustomUIWindow(UIWindowType.Inventory, typeof(OutfitManagerInventoryWindow));
        }
I found a work around. Instead of overriding the setup method and implementing the custom UI objects after the base.setup, I found the action button setup object can be overridden and is ran once on the setup routine. This gets my items in without creating a duplicate inventory setup window.

I think I may be duplicating the inventory screen some how when I use the base.setup method and injection code. I still want to know why this is happening, even though I have a work around for now.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1400
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Having Issue Using UI Object

Post by l3lessed »

One quick question, once you register a custom ui, like so

Code: Select all

UIWindowFactory.RegisterCustomUIWindow(UIWindowType.Inventory, typeof(OutfitManagerInventoryWindow));
How do I grab my custom injected InventoryWindow Object from the interface manager.

Code: Select all

OutfitManagerInventoryWindow OutfitUIManager = (What do I use here to grab the newly injected OutfitManagerInventoryWindow object?)
I've tried using this

Code: Select all

OutfitManagerInventoryWindow OutfitUIManager = (OutfitManagerInventoryWindow)UIWindowFactory.GetInstance(UIWindowType.Inventory, uiManager, null);
I get a null error when I try to use the OutfitUIManager object to grab properties, like individual buttons or labels.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Having Issue Using UI Object

Post by Hazelnut »

That call is to create a new instance. The inventory window has a single instance created and re-used like many other UI windows, and this instance is managed by DaggerfallUI.

Code: Select all

OutfitManagerInventoryWindow OutfitUIManager = (OutfitManagerInventoryWindow)DaggerfallUI.Instance.InventoryWindow;
That is what you want, so you grab the instance being used and are not creating a new one. You can see this everywhere in the code that the inventory window is pushed or used.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

l3lessed
Posts: 1400
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Having Issue Using UI Object

Post by l3lessed »

Facepalm . Thanks, as always. I knew my untrained OOL eyes were missing it scanning the inventory script files. Makes perfect sense now.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

Post Reply