Skip to content

Registering your Icon Overlay

PrimeSonic edited this page Jul 19, 2019 · 1 revision

Originally introduced in the 3.0 update and later refined in the 4.0 overhaul, MoreCyclopsUpgrades can now be used as a public API, allowing other mods to integrate their own cyclops upgrade modules and have them be fully compatible with the Auxiliary Upgrade Console.


Registering your custom Icon Overlay class

Now that you've defined how your class works and how it updates, the last step is to simply register your icon overlay. You'll find this very similar to the way UpgadeHandlers are registered.
Since you're probably already familiar with that, we'll just dive right into the examples.

Option 1 - Using a method that returns your IconOverlay

This form takes in a TechType and a CreateIconOverlay delegate method as its one parameter.
The CreateIconOverlay delegate defines this pattern:

IconOverlay CreateIconOverlay(uGUI_ItemIcon icon, InventoryItem upgradeModule);

This means that method to be used here.

  1. Must take in one ItemIcon and one InventoryItem as its only parameters (in that order)
  2. Must return an object that is or inherits from IconOverlay.

It is expected that you will pass the ItemIcon and InventoryItem parameters to your Icon Overlay constructor.

public static class QPatch
{
    private static TechType myCyclopsUpgrade;
    public static void Patch()
    {
        // Your patching code
        ....
        // In this pattern, you can pass the method by name
        MCUServices.Register.PdaIconOverlay(myCyclopsUpgrade, CreateMyUpgradeHandlerMethod);
    }

    private static CreateMyIconOverlayMethod(uGUI_ItemIcon icon, InventoryItem upgradeModule)
    {
        return new MyIconOverlay(icon, upgradeModule);
    }
}

This can also be done using anonymous methods.
As long as the anonymous method follows the same requirements, it doesn't have to have a name.

public static class QPatch
{
    private static TechType myCyclopsUpgrade;
    public static void Patch()
    {
        // Your patching code
        ....
        // In this pattern, you can pass the method by name
        MCUServices.Register.PdaIconOverlay(myCyclopsUpgrade, (uGUI_ItemIcon icon, InventoryItem upgradeModule) =>
        {
            return new MyIconOverlay(icon, upgradeModule);
        });
    }

Option 2 - Using a class that implements the IIconOverlayCreator interface

If passing methods as a parameter feels a little too weird to you, this alternative might serve you better.
This interface requires a class to implement a method named CreateIconOverlay.
Just as before, this CreateIconOverlay method

  1. Must take in one ItemIcon and one InventoryItem as its only parameters (in that order)
  2. Must return an object that is or inherits from IconOverlay.

It is expected that you will pass the ItemIcon and InventoryItem parameters to your Icon Overlay constructor.

public static class QPatch
{
    private static TechType myCyclopsUpgrade;
    public static void Patch()
    {
        // Your patching code
        ....        
        var myMaker = new MyUpgradeHandlerMaker()
        MCUServices.Register.PdaIconOverlay(myCyclopsUpgrade, myMaker);
    }
}

internal class MyUpgradeHandlerMaker : IIconOverlayCreator
{
    public IconOverlay CreateIconOverlay(uGUI_ItemIcon icon, InventoryItem upgradeModule)
    {
        return new MyIconOverlay(icon, upgradeModule);
    }
}

And that's it. Once registered, your custom Icon Overlay will be used and updated whenever it comes up.

Clone this wiki locally
  翻译: