DFU Will Not Make A New Button

Discuss modding questions and implementation details.
Post Reply
13thsyndicate
Posts: 75
Joined: Sat Jul 25, 2020 5:53 pm

DFU Will Not Make A New Button

Post by 13thsyndicate »

Hello! Some of you may be aware that I'm the maintainer and updater of Races Framework Redone after Races Framework stopped being supported by its original creator. Some of you may also know that RFR stopped working in 0.14.5. I've been trying in 0.15.2 to get it working again and I believe I've narrowed down the problem as to why the "More" button which allows the selection of extra races will not show up - namely, I don't think DFU is making the button properly. The button is hard coded and drawn onto the screen, and by commenting out various sections I think I can confirm that basically this button is never being drawn. But I'm not sure where to go from here or how to fix this. Here's the relevant section of code relating to the creation of the button:
Spoiler!

Code: Select all

static void OnWindowChange(object sender, System.EventArgs e)
        {
            if (list.Count == 0)
            {
                //if no races, skip
                return;
            }

            UserInterfaceManager manager = DaggerfallUI.Instance.UserInterfaceManager;

            //clean-up old windows
            if (listWindow != null && !manager.ContainsWindow(listWindow))
            {
                //if list closed, remember
                listWindow = null;
            }
            if (raceWindow != null && !manager.ContainsWindow(raceWindow))
            {
                //if new game closed, remember
                raceWindow = null;
            }

            //check new window
            IUserInterfaceWindow window = manager.TopWindow;

            if (listButton != null)
            {
                //show button only on new game window
                listButton.Enabled = (window == raceWindow);
            }

            if (window.GetType() == typeof(CreateCharRaceSelect))
            {
                if (window == raceWindow)
                {
                    //if same window, skip
                    return;
                }

                //if new game, get window
                raceWindow = (CreateCharRaceSelect)window;

                //add button
                listButton = new Button();
                listButton.Size = new Vector2(32, 12);
                listButton.Position = new Vector2(272, 176);
                listButton.BackgroundColor = new Color32(62, 62, 62, 255);
                listButton.Outline.Enabled = true;
                listButton.Label.Text = "More";
                listButton.OnMouseClick += ShowList;
                raceWindow.NativePanel.Components.Add(listButton);
            }
        }
Even if the two "skip" sections are commented out, the button still won't be drawn. I'll admit I've reached the limit of my (very basic) coding knowledge here and any advice would be appreciated. Is there an easier way to do this?

User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Re: DFU Will Not Make A New Button

Post by DunnyOfPenwick »

In the context of DFU, a 'button' is an invisible rectangle on the screen that records mouse clicks.

If you want the button to be visible you will have to create the graphic separately, usually by manually editing the window graphic.

13thsyndicate
Posts: 75
Joined: Sat Jul 25, 2020 5:53 pm

Re: DFU Will Not Make A New Button

Post by 13thsyndicate »

Forgive me if I'm mistaken, but I believe that's what setting the background color and text does in this code; this code worked in previous versions of DFU and showed a rectangular "button" graphic with (IIRC) a reddish-brown background that simply said "More", as long as there was a properly formatted race file mod also present in the mod list; it is no longer doing this in the new version. It's using Unity's tools to draw an image on screen with the listed dimensions at the listed vector, or at least, that's what it used to do and what it should be doing. (I think I'm using the correct terms; my programming knowledge is limited and I'm using taking over this mod as well as creating my own mods as a way to learn more)

So if what I'm hearing from you is correct, this code no longer works that way and does not place the graphic on screen when th button is created. On the other hand, clicking in the area the button used to be in previous versions also doesn't open the list dialog that it used to in previous versions of DFU, so I still believe the button isn't being created for some reason.

User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Re: DFU Will Not Make A New Button

Post by DunnyOfPenwick »

Most windows in DFU use pre-drawn buttons in the graphic that have invisible buttons layered on top of them.
I assumed that's what the original post was referencing.

13thsyndicate
Posts: 75
Joined: Sat Jul 25, 2020 5:53 pm

Re: DFU Will Not Make A New Button

Post by 13thsyndicate »

No, the mod is creating a brand new button with the specified appearance. You can see what it looked like in a previous version (0.14.4) in this screenshot:
rfr button screenshot.png
rfr button screenshot.png (213.34 KiB) Viewed 2822 times
Clicking the "More" button shown opens a list as shown here:
rfr list screenshot.png
rfr list screenshot.png (112.72 KiB) Viewed 2822 times
Neither of these things happens in 0.14.5 and later versions despite the code throwing no errors. It's infuriating xD

User avatar
MrFlibble
Posts: 410
Joined: Sat Jan 27, 2018 10:43 am

Re: DFU Will Not Make A New Button

Post by MrFlibble »

Oh, and I was wondering why I couldn't get the extra races when I installed these mods with 0.14.5.

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

Re: DFU Will Not Make A New Button

Post by pango »

According to this bug report on Nexus,
https://www.nexusmods.com/daggerfalluni ... 6?tab=bugs

Mod stopped working because it can't find a method

Code: Select all

MissingMethodException: object DaggerfallWorkshop.Game.Serialization.SaveLoadManager.Deserialize(System.Type,string)
Looking at DFU diff, that method got added a new optional parameter between 0.14.4 and 0.14.5, that's probably what broke the mod:

Code: Select all

➭ git diff v0.14.4-beta..v0.14.5-beta Assets/Scripts/Game/Serialization/SaveLoadManager.cs
diff --git a/Assets/Scripts/Game/Serialization/SaveLoadManager.cs b/Assets/Scripts/Game/Serialization/SaveLoadManager.cs
index d7af2129a..d88da95b4 100644
--- a/Assets/Scripts/Game/Serialization/SaveLoadManager.cs
+++ b/Assets/Scripts/Game/Serialization/SaveLoadManager.cs
@@ -615,14 +615,17 @@ namespace DaggerfallWorkshop.Game.Serialization
             return (pretty) ? fsJsonPrinter.PrettyJson(data) : fsJsonPrinter.CompressedJson(data);
         }
 
-        public static object Deserialize(Type type, string serializedState)
+        public static object Deserialize(Type type, string serializedState, bool assertSuccess = false)
         {
             // Step 1: Parse the JSON data
             fsData data = fsJsonParser.Parse(serializedState);
 
             // Step 2: Deserialize the data
             object deserialized = null;
-            _serializer.TryDeserialize(data, type, ref deserialized).AssertSuccessWithoutWarnings();
+            if (assertSuccess)
+                _serializer.TryDeserialize(data, type, ref deserialized).AssertSuccess();
+            else
+                _serializer.TryDeserialize(data, type, ref deserialized).AssertSuccessWithoutWarnings();
 
             return deserialized;
         }
@@ -1374,7 +1377,7 @@ namespace DaggerfallWorkshop.Game.Serialization
             // Restore quest machine state
             if (!string.IsNullOrEmpty(questDataJson))
             {
-                QuestMachine.QuestMachineData_v1 questData = Deserialize(typeof(QuestMachine.QuestMachineData_v1), questDataJson) as QuestMachine.QuestMachineData_v1;
+                QuestMachine.QuestMachineData_v1 questData = Deserialize(typeof(QuestMachine.QuestMachineData_v1), questDataJson, assertSuccess:true) as QuestMachine.QuestMachineData_v1;
                 QuestMachine.Instance.RestoreSaveData(questData);
             }
 
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

13thsyndicate
Posts: 75
Joined: Sat Jul 25, 2020 5:53 pm

Re: DFU Will Not Make A New Button

Post by 13thsyndicate »

Oh my god, Pango, that is such a lifesaver. So I need to fix the method call syntax to allow it to deserialize the json files properly! I need to look up how to do that, thank you so much.

13thsyndicate
Posts: 75
Joined: Sat Jul 25, 2020 5:53 pm

Re: DFU Will Not Make A New Button

Post by 13thsyndicate »

With Pango's help, I have finally fixed the mod. Thank you all for your help and support~!

Post Reply