SpooderCode-RockUI icon

RockUI

A handy dependency for making ingame UI

Last updated a day ago
Total downloads 0
Total rating 0 
Categories Mods
Dependency string SpooderCode-RockUI-1.0.1
Dependants 0 other packages depend on this package

This mod requires the following mods to function

UlvakSkillz-RumbleModdingAPI-5.3.0 icon
UlvakSkillz-RumbleModdingAPI

API to Help Modders Get Started and to remove the necessity of GameObject.Find

Preferred version: 5.3.0

README

Rock UI

Ever dreaded making UI for your mods? Well, say goodbye to slightly adjusting positions and copying RUMBLE objects, because RockUI solves it all!

Thats all it does though this mod is just a dependency

For Users

Just drag the mod into your mods folder and start up RUMBLE!

For Mod Developers

Be warned this is my first time making a mod like this so if you see some horrible way of doing something please lmk.

The Basics RockUI is made up of 2 main parts: UIElements and the UIBuilder. UIElements are the building blocks of UI. There are a few types currently:

  • RockPanel
  • RockButton
  • RockText
  • RockSlider
  • RockLever

Creating one of these is very simple:

RockPanel panel = new RockPanel()

Then you can set properties easily:

panel.size = new Vector2(10,10)

I will go further into the properties of each UIElement further down. The UI works off of a parent-child system. You can add any UIElement as a child of another like so:

RockPanel panel = new RockPanel()
RockButton button = new RockButton()
 
panel.AddChildUI(button)

When an element is a child of another it will be placed at the same position as its parent. Alternatively, if the parent node is a panel, you can set the object to be positioned at one of 9 anchor points on the panel with anchor:

  • TopLeft
  • TopRight
  • BottomLeft
  • BottomRight
  • LeftMiddle
  • RightMiddle
  • TopMiddle
  • BottomMiddle
  • Center

You can offset the element from its parent/anchor using anchorOffset

Once you have created your UIElements and applied them as children you are ready to build the UI. All you have to do is write RockUI.BuildUI(-Your Topmost UIElement-). The UIElement you pass in should be the topmost element (has no parent element). The UIBuilder will then create that element and all of it's children and return it as a GameObject.

List of All UIElements

UIElement Default UIElement. All other types inherit this. Properties:

  • anchor: Defines what anchor the element snaps to if child of a RockPanel
  • anchorOffset: Defines the position offset from the anchor or the parent element

Methods:

  • AddChildUI(UIElement): Adds another element as a child of this element

RockPanel A plain slab of rock for placing UI on. I recommend using this as your topmost UIElement. UIElements as children of it can choose one of 9 Anchors on it to be anchored to.

Properties:

  • size: Vector2 that defines the size of the panel.

RockButton A button that calls a method when pressed. Properties:

  • pressAction: The method that is called when the button is pressed. Must have no parameters

RockText A text label. Properties:

  • text: The text of the label
  • fontColor: The color of the label
  • fontSize: The size of the text (Honestly doesnt need to be higher than 1 most of the time)

RockSlider RUMBLE's built in slider object. Can be stepped or a smooth slider. Properties:

  • useSteps: Whether or not the slider has steps. If true, the slider stops at certain points based on stepCount
  • stepCount: The amount of steps the slider stops at
  • valueChangedAction: The method that is called when the value of the slider changes. Must have a float parameter, which is the value of the slider, from 0 to 1
  • stepReachedAction: The method that is called when a step in the slider is reached. Must have an int parameter, which is the step that was reached, starting at 0

RockLever RUMBLE's built in lever/switch object. Can be on or off. Properties:

  • leverToggledAction: Method that is called when the lever is toggled. Must have an integer parameter. Outputs 1 for toggled on and 0 for toggled off

Example UI Setup

Example UI Setup

    public override void OnLateInitializeMelon()
    {
        RumbleModdingAPI.RMAPI.Actions.onMapInitialized += debug;
    }
    
    private float a = 0.0f;
    private string t = "";
    private void debug()
    {
        RockPanel mainpanel = new RockPanel();
        mainpanel.size = new Vector2(10, 15);

        RockButton debugbutton = new RockButton();
        debugbutton.anchor = UIElement.AnchorType.Center;
        debugbutton.anchorOffset = new Vector2(0, 2);
        debugbutton.pressAction = log;

        RockText debugtext = new RockText();
        debugtext.anchor = UIElement.AnchorType.Center;
        debugtext.anchorOffset = new Vector2(0, 4);
        debugtext.text = "Print Debug Message";

        RockText debugtext2 = new RockText();
        debugtext2.anchor = UIElement.AnchorType.Center;
        debugtext2.anchorOffset = new Vector2(0, -2);
        debugtext2.text = "Number to Print";
        RockSlider debugslider = new RockSlider();
        debugslider.anchor = UIElement.AnchorType.Center;
        debugslider.anchorOffset = new Vector2(0, -4);
        debugslider.valueChangedAction = setAmount;

        RockText debugtext3 = new RockText();
        debugtext3.anchor = UIElement.AnchorType.Center;
        debugtext3.anchorOffset = new Vector2(-3, 2);
        debugtext3.text = "!!!";
        RockLever debuglever = new RockLever();
        debuglever.anchor = UIElement.AnchorType.Center;
        debuglever.anchorOffset = new Vector2(-3, 0);
        debuglever.leverToggledAction = setEnding;

        mainpanel.AddChildUI(debugtext);
        mainpanel.AddChildUI(debugbutton);
        mainpanel.AddChildUI(debuglever);
        mainpanel.AddChildUI(debugtext2);
        mainpanel.AddChildUI(debugtext3);
        mainpanel.AddChildUI(debugslider);

        GameObject debugmenu = RockUI.BuildUI(mainpanel);
        debugmenu.transform.position = new Vector3(0, 1, 0);
    }
    private void log()
    {
        MelonLogger.Msg("Pressed Button, Amount: " + a.ToString() + t);
    }
    private void setAmount(float amount)
    {
        a = 10 * amount;
    }
    private void setEnding(int ending)
    {
        if (ending == 1)
        {
            t = "!!!!!!!!!";
        }
        else
        {
            t = "";
        }
    }