Filtering DaggerfallExteriorAutomapWindow nameplates

Discuss modding questions and implementation details.
flynsarmy
Posts: 12
Joined: Tue Dec 22, 2020 11:39 pm

Filtering DaggerfallExteriorAutomapWindow nameplates

Post by flynsarmy »

I'm attempting to write my first mod and running into some difficulty with protection levels. I want to make a mod very similar to Inventory Filter but for the city map to filter out nameplates. It's a simple mod that adds filter field to the bottom right of the map that will filter out building nameplates as you type.

I'm new to C# and Unity but I believe this can be done by overriding DaggerfallExteriorAutomapWindow's UpdateAutomapView method.

Here's what I have so far:

Code: Select all

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

    for (int i = 0; i < exteriorAutomap.buildingNameplates.Length; i++)
    {
        if (NameplatePassesFilter(exteriorAutomap.buildingNameplates[i].textLabel.Text))
        {
            exteriorAutomap.buildingNameplates[i].textLabel.Enabled(false);
        }
    }
}
I'm running into a couple of problems though.
  1. 'FlynsarmyExteriorAutomapWindow.UpdateAutomapView()': cannot override inherited member 'DaggerfallExteriorAutomapWindow.UpdateAutomapView()' because it is not marked virtual, abstract, or override
  2. 'DaggerfallExteriorAutomapWindow.exteriorAutomap' is inaccessible due to its protection level
For #1, my very limited understanding is that because DaggerfallExteriorAutomapWindow.UpdateAutomapView is not overrideable, I have to replace 'override' with 'new' in my method name and copy paste the entire parent methods contents into my method? This could get messy if DFU's author ever changes the parent method at all. Is there any way to do what I'm attempting to do above or is a patch needed? Alternatively, will something like this work?

Code: Select all

public new void UpdateAutomapView()
{
    base.UpdateAutomapView();
    ...
}
For #2, exteriorAutomap doesn't appear to have been set public and there's no Getter that I can see. Will this also need a patch?

EDIT: Looks like I might be able to do something like this?

Code: Select all

public new void UpdateAutomapView()
{
    base.UpdateAutomapView();

    for (int i = 0; i < PanelRenderAutomap.Components.Count(); i++)
    {
        foreach (TextLabel label in PanelRenderAutomap.Components)
        {
            if (!NameplatePassesFilter(label.Text))
            {
                PanelRenderAutomap.Components.Remove(label);
            }
        }
    }
}

flynsarmy
Posts: 12
Joined: Tue Dec 22, 2020 11:39 pm

Re: Filtering DaggerfallExteriorAutomapWindow nameplates

Post by flynsarmy »

OK, got this mod mostly working. Here's some screenshots.

Standard map menu (notice the new Filter field at the bottom left):
Image

I typed 'w' into the filter field. Now, only buildings containing that letter are displaying their names:
Image

There's one showstopper bug: Setting OverridesHotkeySequences to true on the filter field does nothing. If you type the letter M (hotkey to show/hide the map menu) the map closes. Isn't OverridesHotkeySequences supposed to stop this?

Any ideas how to solve this? Full source code available here.

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

Re: Filtering DaggerfallExteriorAutomapWindow nameplates

Post by pango »

Hi,
Hotkeys are disabled as long as this control has the focus, so it has to take the focus first;
What had to be modified in Outfit Manager was described in the original issue: https://github.com/Interkarma/daggerfal ... ssues/1707
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
TheLacus
Posts: 1315
Joined: Wed Sep 14, 2016 6:22 pm
Contact:

Re: Filtering DaggerfallExteriorAutomapWindow nameplates

Post by TheLacus »

You can't override a method that is not marked as virtual, this would need to be changed in core. Defining a new member with the same name (with or without keyword "new") doesn't achieve what you need, it only hides the original member in base class.
Mod System documentation - Learn how to create mods for Daggerfall Unity.
Modder Discussion - General help and discussion for the mod system.
Github Issues - Submit a bug report for the game, including the mod system.

flynsarmy
Posts: 12
Joined: Tue Dec 22, 2020 11:39 pm

Re: Filtering DaggerfallExteriorAutomapWindow nameplates

Post by flynsarmy »

Thanks for the link. I added the SetFocus() call however that doesn't appear to be working for me in this instance because the code for closing the map window isn't using HotkeySequence. You can see the code they use to close the window on GitHub here:

Code: Select all

if (Input.GetKeyDown(KeyCode.Escape) ||
    // Toggle window closed with same hotkey used to open it
    InputManager.Instance.GetKeyDown(automapBinding))
    isCloseWindowDeferred = true;
else if ((Input.GetKeyUp(KeyCode.Escape) ||
    // Toggle window closed with same hotkey used to open it
    InputManager.Instance.GetKeyUp(automapBinding)) && isCloseWindowDeferred)
{
    isCloseWindowDeferred = false;
    CloseWindow();
    return;
}
TheLacus wrote: Wed Dec 23, 2020 3:42 pm You can't override a method that is not marked as virtual, this would need to be changed in core.
Ahh damn. Thanks for the explanation.

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

Re: Filtering DaggerfallExteriorAutomapWindow nameplates

Post by l3lessed »

The quickest gimmick around this I can think of is to force, through code, either a new map key or just clear it while the map is open. When the player closes the map using escape, reset the key back to what it was.
My Daggerfall Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

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

flynsarmy
Posts: 12
Joined: Tue Dec 22, 2020 11:39 pm

Re: Filtering DaggerfallExteriorAutomapWindow nameplates

Post by flynsarmy »

l3lessed wrote: Thu Dec 24, 2020 11:26 pm When the player closes the map using escape, reset the key back to what it was.
I had considered this option too however that would have to be done in CloseWindow() method and it's declared as a public void meaning I can't override it right?

EDIT: Actually, because the DaggerfallExteriorAutomapWindow.Update() method is overrideable, I should be able to change the hotkey, call base.Update() then set it back. We may be onto something here!

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

Re: Filtering DaggerfallExteriorAutomapWindow nameplates

Post by l3lessed »

No, use the UI object/method to monitor when the UI is open and when it has the minimap open to be specific. Then, when UI.type == minimap, then switch the key. and then have the else switch it back.

I did this with my outfit manager mod to ensure the GUI only appears when the inventory window is open. Let me find the code I'm speaking of and post it as an example.
Last edited by l3lessed on Fri Dec 25, 2020 3:54 am, edited 1 time in total.
My Daggerfall Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

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

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

Re: Filtering DaggerfallExteriorAutomapWindow nameplates

Post by l3lessed »

You're making this more complicated then I think it needs to be. Here is the code I would use to detect the map being open and switch the keys as needed.

Code: Select all

  
  	    //checks if this ui item is open and assigns it to bool.         
            bool MinimapOpen = DaggerfallUI.Instance.UserInterfaceManager.ContainsWindow(DaggerfallUI.Instance.ExteriorAutomapWindow);

            // if minimap is open and the key hasn't been switched yet, do....
            if ((MinimapKey == DefaultKey && MinimapOpen)
            {
            	//insert code to switch key off here.
            }
            //else when the key has been changed by the above code, and the minimap isn't open, switch back. This ensures the switch only flips back once, when the map is closed.
            else if(MinimapKey != DefaultKey && !MinimapOpen)
            {
            	//insert code to switch key back to default binding.
            }
My Daggerfall Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

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

flynsarmy
Posts: 12
Joined: Tue Dec 22, 2020 11:39 pm

Re: Filtering DaggerfallExteriorAutomapWindow nameplates

Post by flynsarmy »

This mod is now complete and fully working! Source code available here. Will get an updated readme and compiled versions added to the repo soon.

Quick question: Should I add a gitignore for the .meta files or just leave them in the repo?

Post Reply