Modding UI suggestion

Discuss coding questions, pull requests, and implementation details.
User avatar
Uncanny_Valley
Posts: 162
Joined: Mon Mar 23, 2015 5:47 pm

Modding UI suggestion

Post by Uncanny_Valley » Sun Oct 06, 2019 2:24 pm

I was experimenting with modding the game UI but it's something that currently can't really be done. So I would like suggeset and discuss some changes that would open up some possibilites on this front

1.) Don't set the UIWindows (for exampele dfBookReaderWindow) on Awake in DaggerfallUI.cs

2.) Change the Properties for each UIWindow

Code: Select all

    public DaggerfallBookReaderWindow BookReaderWindow
        {
            get { return dfBookReaderWindow; }
        }
to :

Code: Select all

        public DaggerfallBookReaderWindow BookReaderWindow
        {
            get { return dfBookReaderWindow ?? (dfBookReaderWindow = new DaggerfallBookReaderWindow(uiManager)); }
            set { dfBookReaderWindow = value;  }
        }
3.) Implement Properties for all UIWindows that doesn't have one

4.) Make sure the ProcessMessages (and all other references) in DaggerFallUI.cs always goes through the Property and not the variabel itself

5.) In the UIWindow classes (like DaggerfallBookReaderWindow.cs), set all private variabels and methods to protected, and also set all methods to virtual

This would allow modders to easily edit any UIWindow they like. Starting by setting the instance of DaggerfallUI they wish to replace with their own.

Code: Select all

   void Awake()
    {
        DaggerfallUI daggerfallUI = DaggerfallUI.Instance;
        daggerfallUI.BookReaderWindow = new MyBookReaderWindow(daggerfallUI.UserInterfaceManager);
    }
With MyBookReaderWindow being a class derived from BookReaderWindow that overrides with the changes that you would like to make

What do think?
Last edited by Uncanny_Valley on Sun Oct 06, 2019 11:09 pm, edited 2 times in total.

DFIronman
Posts: 68
Joined: Sat Aug 24, 2019 12:48 am

Re: Modding UI suggestion

Post by DFIronman » Sun Oct 06, 2019 8:23 pm

I like your implementation idea better, but you can replace windows by catching the window in an OnWindowChange event, closing the window, and using your own custom class.

I feel like most/all private variables in DFU should be protected and most/all of the functions should be virtual. As it is now, some components have to be copied-and-pasted, and then modified.

User avatar
Uncanny_Valley
Posts: 162
Joined: Mon Mar 23, 2015 5:47 pm

Re: Modding UI suggestion

Post by Uncanny_Valley » Sun Oct 06, 2019 9:30 pm

DFIronman wrote:
Sun Oct 06, 2019 8:23 pm
I like your implementation idea better, but you can replace windows by catching the window in an OnWindowChange event, closing the window, and using your own custom class.

I feel like most/all private variables in DFU should be protected and most/all of the functions should be virtual. As it is now, some components have to be copied-and-pasted, and then modified.
I actually started using the method you describe, I tried to make changes to the dialogue window, but there a few other scripts that reference it directly that are needed to make it function work (like getting the data from the NPC that your talking to). :/

DFIronman
Posts: 68
Joined: Sat Aug 24, 2019 12:48 am

Re: Modding UI suggestion

Post by DFIronman » Sun Oct 06, 2019 11:55 pm

Yeah, you'd have to replace those scripts at runtime OR (if the variable is available at the class-level) use reflection to set the target variable to point to your new window.

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

Re: Modding UI suggestion

Post by Hazelnut » Tue Oct 15, 2019 1:59 pm

I think this is a good idea. This is only possible for UI windows where a single instance is created and re-used every time. Some UI windows, including most the ones I developed, don't do this and have a new instance created each time they're used. I suggest we do this for all of the existing single instance windows, and then take the others and convert them one by one as needed.

An alternative is a UIFactory class that is used to create new instances of UI windows. Replacement ui classes could then be registered in here by mods. This would cover both types of window without requiring conversion.

Any thoughts on which way?
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
Interkarma
Posts: 5583
Joined: Sun Mar 22, 2015 1:51 am

Re: Modding UI suggestion

Post by Interkarma » Tue Oct 15, 2019 8:52 pm

Some really great suggestions in here. It lines up very closely with my thinking as well.

Something I'd like to add is the ability to optionally present standard UGUI in place of DagUI windows. This would allow modders to gradually reimplement UI to whatever modern standards they wish. Some of the events (like rest UI passing time) would need to be decoupled, but nothing too complex in all that. Hazelnut's suggestion of a UIFactory class is excellent here, as it could manage presentation of either UGUI or DagUI as required.

User avatar
Uncanny_Valley
Posts: 162
Joined: Mon Mar 23, 2015 5:47 pm

Re: Modding UI suggestion

Post by Uncanny_Valley » Wed Oct 16, 2019 1:50 pm

Could smeone explain to me the concept of a UIFactory. What does that mean exatctly?

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

Re: Modding UI suggestion

Post by Hazelnut » Wed Oct 16, 2019 2:08 pm

It's quite a standard pattern where a 'factory' class is responsible for instantiating implementations. So when you need an implementation of IFoo, you request one from the factory. It decided whether to instantiate FooImpl1 or FooImpl2 and you just use it via the interface not knowing which implementation you actually got. (See https://en.wikipedia.org/wiki/Factory_method_pattern) It's not really much different from your suggestion except for separating the concerns out into it's own class.

I plan to implement a UIFactory soon, so if that makes no sense you can wait and take a look at the code. There are many people doing all kinds of nasty things to mod the UI at the moment, like duplication (TT) or reflection or even event listening and substitution. This is way overdue, so thanks for prompting the change. I also want to make a variant of the travel map to help people select map coords for new locations. :)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

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

Re: Modding UI suggestion

Post by Hazelnut » Thu Oct 17, 2019 2:40 pm

You know, I've been thinking and I don't see why we couldn't have a UIFactory and a ManagerFactory. The latter will allow new versions of the *Manager classes to be used by mods. e.g. a new WeaponManager for the guy doing the weapon mechanics rework mod... unless anyone has any objections I will do them both at the same time. Probably tonight.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
Interkarma
Posts: 5583
Joined: Sun Mar 22, 2015 1:51 am

Re: Modding UI suggestion

Post by Interkarma » Thu Oct 17, 2019 9:11 pm

No objections here mate. :)

Post Reply