[Solved] Custom Text Label In Trade Window Overlapping When "Updated"

Discuss modding questions and implementation details.
Post Reply
User avatar
Magicono43
Posts: 279
Joined: Tue Nov 06, 2018 7:06 am

[Solved] Custom Text Label In Trade Window Overlapping When "Updated"

Post by Magicono43 » Sat May 16, 2020 8:08 pm

Quick context, I'm using a custom text label in the trade window that displays a value from my mod. This part works fine statically, but the text label does not update while inside the window, only when the trade panel is first brought up. So the only way for this displayed value to be updated is to close out of the trade window panel, and open up the trade window again.

So obviously I would like to have this displayed value to update dynamically as the value changes during transactions. Problem is that when I have tried various attempts and methods that I could think of to do this, they have all resulted in the same thing, that being the displayed value getting layered upon each other every-time I have the value set to "update" resulting in the gif example below.
Non-Working_Text_Update.gif
Non-Working_Text_Update.gif (67.89 KiB) Viewed 62 times
Looking for examples, one that uses the "textlabel" method specifically is, "DaggerfallTravelMapWindow.cs" that being the part that displays the name of the Region you are moused over in the top-center of the screen.

Code: Select all

// Add region label
            regionLabel = DaggerfallUI.AddTextLabel(DaggerfallUI.DefaultFont, new Vector2(0, 2), string.Empty, NativePanel);
            regionLabel.HorizontalAlignment = HorizontalAlignment.Center;
            
            
            // Updates the text label at top of screen
        void UpdateRegionLabel()
        {
            if (RegionSelected == false)
                regionLabel.Text = GetRegionName(mouseOverRegion);
            else if (locationSelected)
                regionLabel.Text = string.Format("{0} : {1}", DaggerfallUnity.ContentReader.MapFileReader.GetRegionName(mouseOverRegion), currentDFRegion.MapNames[locationSummary.MapIndex]);
            else if (MouseOverOtherRegion)
                regionLabel.Text = string.Format("Switch To: {0} Region", DaggerfallUnity.ContentReader.MapFileReader.GetRegionName(mouseOverRegion));
            else
                regionLabel.Text = GetRegionName(mouseOverRegion);
        }
So that obviously works fine, but when I look at my latest attempt for the trade-window and my custom label, it does not work the same.

Code: Select all

public override void Refresh(bool refreshPaperDoll = true)
        {
            if (!IsSetup)
                return;

            base.Refresh(refreshPaperDoll);

            UpdateRepairTimes(false);
            UpdateCostAndGold();
            UpdateShopGoldDisplay();
        }
        
        
        // Refresh is called earlier for initial display
        public void UpdateShopGoldDisplay()
        {
            int currentBuildingID = GameManager.Instance.PlayerEnterExit.BuildingDiscoveryData.buildingKey;
            int goldSupply = 0;
            foreach (KeyValuePair<int, SaveDataTestingScript1.ShopData> kvp in SaveDataTestingScript1.SaveDataTestingScript1.ShopBuildingData)
            {
                if (kvp.Key == currentBuildingID)
                    goldSupply = kvp.Value.CurrentGoldSupply;
            }

            localTextLabelTwo = DaggerfallUI.AddTextLabel(DaggerfallUI.DefaultFont, new Vector2(263, 41), string.Empty, NativePanel);
            localTextLabelTwo.TextScale = 0.85f;
            localTextLabelTwo.Text = "Shop Gold: " + goldSupply.ToString();
        }

If anybody knows what i'm doing wrong here, assistance would be much appreciated, trying to mess with the UI and windows has been a damn nightmare for me so far, lol.
Thanks for reading.
Last edited by Magicono43 on Mon May 18, 2020 5:24 pm, edited 1 time in total.

User avatar
pango
Posts: 2330
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Custom Text Label In Trade Window Overlapping When "Updated"

Post by pango » Sat May 16, 2020 8:30 pm

Code: Select all

            localTextLabelTwo = DaggerfallUI.AddTextLabel(DaggerfallUI.DefaultFont, new Vector2(263, 41), string.Empty, NativePanel);
You're adding a new TextLabel every time your Refresh method is called.
Instead you should create a TextLabel during setup, keep its reference, and only modify its text during Refresh...
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Magicono43
Posts: 279
Joined: Tue Nov 06, 2018 7:06 am

Re: Custom Text Label In Trade Window Overlapping When "Updated"

Post by Magicono43 » Sat May 16, 2020 8:45 pm

pango wrote:
Sat May 16, 2020 8:30 pm

Code: Select all

            localTextLabelTwo = DaggerfallUI.AddTextLabel(DaggerfallUI.DefaultFont, new Vector2(263, 41), string.Empty, NativePanel);
You're adding a new TextLabel every time your Refresh method is called.
Instead you should create a TextLabel during setup, keep its reference, and only modify its text during Refresh...
Yeah, was talking to Burt on the Discord after posting this, was a really obviously fix when he mentioned it. It's working as intended now, lol, that was a really silly mistake. Thanks for pointing it out as well, Pango. Hopefully somebody finds my dumb mistake helpful, lol

In case anyone reads this with a similar issue. OBJECTS CAN BE MODIFIED PIECE BY PIECE, you don't need to add the whole part that makes the label initially over and over, you can do that once in this case, and edit the other parts of it later on as you please.

User avatar
Magicono43
Posts: 279
Joined: Tue Nov 06, 2018 7:06 am

Re: Custom Text Label In Trade Window Overlapping When "Updated"

Post by Magicono43 » Sat May 16, 2020 10:05 pm

Here is what it looks like now working for those curious. Once again, thanks for the help.
Working_Text_Update.gif
Working_Text_Update.gif (18.77 KiB) Viewed 38 times

Post Reply