Skip to content
Jaxe edited this page Sep 14, 2023 · 3 revisions

Presets

To include a preset with your mod, save a preset in-game with the layout set up to include your mod's features and copy it from your Config\RimHUD\Presets to your mod's RimHUD\Presets folder. This will be automatically detected and added to RimHUD's built-in presets.

Custom Widgets

There are 5 types of custom widgets available for third-party mods as of RimHUD v1.14.0.

  • RimHUD.CustomNeedDef this is a simple wrapper for a need bar that allows for a tooltip
  • RimHUD.CustomBarDef provides parameters to create a standard bar widget
  • RimHUD.CustomValueDef provides parameters to create a standard value widget
  • RimHUD.CustomSelectorDef provides parameters to create a standard selector widget
  • RimHUD.CustomWidgetDef allows a completely custom drawn widget

All defs must provide an apiVersion field. The latest version is currently 1. Add the defs to your mod's Defs folder to have them integrate with RimHUD.

RimHUD.CustomNeedDef

  <RimHUD.CustomNeedDef>
    <defName>StressWidget</defName>
    <label>Stress</label>
    <needDef>Stress</needDef>
    <colorStyle>MainToLow</colorStyle>
    <defClass>MyMod.MyStressWidget</defClass>
    <apiVersion>1</apiVersion>
  </RimHUD.CustomNeedDef>

defName [required]

The unique ID for this widget.

label [optional]

A human-readable label for the widget. If omitted, the defName will be used instead.

needDef [required]

The defName of the NeedDef being wrapped.

colorStyle [optional]

There are currently 4 styles:

  • LowToMain: This is the default and will be used if this field is omitted
  • LowOnly: The bar color will be only the low color (red by default)
  • MainOnly: The bar color will be only the main color (green by default)
  • MainToLow: The bar color will be the main color when the value is low, and change to the low color when full

defClass [optional]

This is a link to a static class within your mod which contains the following static methods:

public static string GetTooltip(Pawn pawn)

This will be called when the user hovers over the widget and will provide the text for the tooltip.

RimHUD.CustomBarDef

  <RimHUD.CustomBarDef>
    <defName>MyBarWidget</defName>
    <label>My Bar</label>
    <textStyle>Small</textStyle>
    <colorStyle>MainToLow</colorStyle>
    <defClass>MyMod.MyBarWidget</defClass>
    <apiVersion>1</apiVersion>
  </RimHUD.CustomBarDef>

defName [required]

The unique ID for this widget.

label [optional]

A human-readable label for the widget. If omitted, the defName will be used instead.

textStyle [optional]

This is the size of the text for this widget. Available styles are:

  • Regular (default for Bar widget)
  • Large
  • Small

colorStyle [optional]

There are currently 4 styles:

  • LowToMain: This is the default and will be used if this field is omitted
  • LowOnly: The bar color will be only the low color (red by default)
  • MainOnly: The bar color will be only the main color (green by default)
  • MainToLow: The bar color will be the main color when the value is low, and change to the low color when full

defClass [required]

This is a link to a static class within your mod which contains the following static methods:

public static (string? label, string? value, float fill, float[]? thresholds, Func<string?>? tooltip, Action? onHover, Action? onClick) GetParameters(Pawn pawn)

This will be called when the widget will be built and provide the parameters needed to display it correctly.

  • label is the label to the left of the bar
  • value is the value shown as a string. This is commonly a percentage string of the actual value
  • fill is how full the bar is (0 to 1)
  • thresholds show thresholds on the bar if required
  • tooltip provides a tooltip if required
  • onHover will be performed when the user hovers over the widget
  • onClick will be performed when the user clicks on the widget

RimHUD.CustomValueDef

  <RimHUD.CustomValueDef>
    <defName>MyValueWidget</defName>
    <label>My Value</label>
    <textStyle>Regular</textStyle>
    <defClass>MyMod.MyValueWidget</defClass>
    <apiVersion>1</apiVersion>
  </RimHUD.CustomValueDef>

defName [required]

The unique ID for this widget.

label [optional]

A human-readable label for the widget. If omitted, the defName will be used instead.

textStyle [optional]

This is the size of the text for this widget. Available styles are:

  • Regular
  • Large
  • Small (default for Value widget)

defClass [required]

This is a link to a static class within your mod which contains the following static methods:

public static (string? label, string? value, Func<string?>? tooltip, Action? onHover, Action? onClick) GetParameters(Pawn pawn)

This will be called when the widget will be built and provide the parameters needed to display it correctly.

  • label can be null if only a value is required
  • value is text value shown
  • tooltip provides a tooltip if required
  • onHover will be performed when the user hovers over the widget
  • onClick will be performed when the user clicks on the widget

RimHUD.CustomSelectorDef

  <RimHUD.CustomSelectorDef>
    <defName>MySelector</defName>
    <label>My Selector</label>
    <textStyle>Regular</textStyle>
    <defClass>MyMod.MySelectorWidget</defClass>
    <apiVersion>1</apiVersion>
  </RimHUD.CustomSelectorDef>

defName [required]

The unique ID for this widget.

label [optional]

A human-readable label for the widget. If omitted, the defName will be used instead.

textStyle [optional]

This is the size of the text for this widget. Available styles are:

  • Regular
  • Large
  • Small (default for Selector widget)

defClass [required]

This is a link to a static class within your mod which contains the following static methods:

public static (string? label, Func<string?>? tooltip, Action? onClick, Action? onHover, Color? backColor) GetParameters(Pawn pawn)

This will be called when the widget will be built and provide the parameters needed to display it correctly.

  • label the label shown on the selector
  • tooltip provides a tooltip if required
  • onHover will be performed when the user hovers over the widget
  • onClick will be performed when the user clicks on the widget

RimHUD.CustomWidgetDef

  <RimHUD.CustomWidgetDef>
    <defName>MyCustomWidget</defName>
    <label>My Custom</label>
    <defClass>MyMod.MyCustomWidget</defClass>
    <apiVersion>1</apiVersion>
  </RimHUD.CustomWidgetDef>

defName [required]

The unique ID for this widget.

label [optional]

A human-readable label for the widget. If omitted, the defName will be used instead.

defClass [required]

This is a link to a static class within your mod which contains the following static methods:

public static bool OnDraw(Pawn pawn, Rect rect)

This will be called when the widget is ready to be drawn. The bool returned should report whether the widget was drawn (and the space used) or not.

public static float GetMaxHeight()

This expects a value of the height the widget takes at its maximum. Generally this is the line height of the text.