Skip to content

Creating your own Auxiliary Upgrade Console

PrimeSonic edited this page Jun 21, 2020 · 20 revisions

Released in version 5.0, you can now add your own Auxiliary Upgrade Consoles, in whatever size or shape you want.
It's your very own cyclops upgrade console made easy!

New public API class: AuxiliaryUpgradeConsole

The new class AuxiliaryUpgradeConsole will provide most everything your aux upgrade console will need to interact with the Cyclops and the MoreCyclopsUpgrades API.
To get started creating your own Auxiliary Upgrade Console Component, create yourself a class that implements AuxiliaryUpgradeConsole.

using MoreCyclopsUpgrades.API.Buildables;

internal class MyCyclopsUpgradeConsole : AuxiliaryUpgradeConsole
{
    // Override any of virtual members and customize how your upgrade console behaves.
    // If you intend on using using all default behavior, this is all the code you need here.
}

So what will AuxiliaryUpgradeConsole do for me?

This base class will actually handle a lot of things for you, such as:

  • Managing the Equipment events
  • Handling player interaction via the HandTarget methods
  • Reading and writing of custom save data for the console and its installed upgrade modules
  • And most importantly, connect with MoreCyclopsUpgrades so it functions just like the original Auxiliary Upgrade Console.

All this is to say that the only thing you will really need to take care of yourself is how you want your aux upgrade console to look and if you want any extra code to run when upgrade modules are added and removed.


Remember the Constructable component

Like any Buildable item you mod into the game, your aux upgrade console must have a Constructable component.
If your prefab didn't include one already, you will need to add it yourself.
And don't forget to set the allowedInSub value of the Constructable component to true.
You can use the original AuxCyUpgradeConsole as an example.

// In your Buildable class
public override GameObject GetGameObject()
{
    var obj = GameObject.Instantiate(<your prefab here>);
. . . .
    Constructable constructible = obj.EnsureComponent<Constructable>(); // You can use GetComponent if you know it will be there
    constructible.allowedInBase = false; // Do not allow this in a normal base
    constructible.allowedInSub = true; // Allow only in the Cyclops sub
    constructible.allowedOutside = false; // Not allowed outside
    constructible.controlModelState = true; // Keep this enabled
    constructible.rotationEnabled = true; // Up to you
    constructible.techType = this.TechType;
    constructible.model = <your chosen or custom model here>;
. . . .
    return obj;
}

Add your AuxiliaryUpgradeConsole like any other custom component

Once you have your buildable set up, remember to add your aux upgrade console component to the GameObject.
The code in the AuxiliaryUpgradeConsole base class will take action once you build your custom console in the Cyclops.

// In your ModPrefab class
public override GameObject GetGameObject()
{
    var obj = GameObject.Instantiate(<your prefab here>);
. . . .
    obj.AddComponent<MyCyclopsUpgradeConsole>(); // Implements AuxiliaryUpgradeConsole
. . . .
    return obj;
}

Six Upgrade Slots Only

To maintain some consistency and prevent any one upgrade console from being too powerful,
all upgrade consoles are limited to six slots. No more, no less.


Customizing your upgrade console's functions

Members you can override

The AuxiliaryUpgradeConsole class offers several virtual methods you can override.

Member Usage Default Behavior Notes
OnHoverText Configures what text to display when the player hovers the cursor over the buildable Returns the same hover text as the original aux upgrade console It's recommended to use SMLHelper's LanguageHelper to set a language line and use Language.main.Get to fetch the string instead of returning a literal string.
OnSlotEquipped Does nothing by default You can use this to set up how your upgrade console will react when a new module is added. The original aux upgrade console uses these events to update its displayed icons.
OnSlotUnequipped Does nothing by default You can use this to set up how your upgrade console will react when a module is removed. The original aux upgrade console uses these events to update its displayed icons.
OnHandHover Handles IHandTarget behavior Displays the standard hand icon and OnHoverText Override if you want to handle player-hover events yourself.
OnHandClick Handles IHandTarget behavior Invokes the protected method OpenEquipmentScreen Override if you want to handle player-click events yourself.
You will need to call OpenEquipmentScreen from your own code if you do!

Members you can access

There are various public and protected members in AuxiliaryUpgradeConsole that you can use from your own code.

Member Usage Notes
SlotNames A public static field that provides an enumeration of all Equipment slot names. Used mostly internally but it's here if you need it. see also UpgradeSlots.
Modules A public reference to the Equipment that houses the upgrade module slots. Use if you ever need to check what's installed in the upgrade console.
IsConnectedToCyclops A public property that returns true once the upgrade console has finished connecting with MoreCyclopsUpgrades. Check if you want to be sure the upgrade console is ready start doing things.
UpgradeSlots A public enumeration of UpgradeSlot structs.
Contains simplified methods for checking what's inside that slot.
Used mostly internally as a way to go through all upgrade slots across all upgrade consoles. It's here if you have a need for it.
OpenEquipmentScreen A protected method that opens the PDA's Equipment screen for this upgrade module. You will need to call this method from your code if you override OnHandClick.
Clone this wiki locally
  翻译: