-
Notifications
You must be signed in to change notification settings - Fork 9
SHORTTUTORIAL: Add A Tab
roxxploxx edited this page May 21, 2017
·
5 revisions
A Tab (an ITab class) is a small button element that adorns the inspection window of the selected item (the MainTabWindow_Inspect class).
Below, the ITabs are "Social", "Gear", "Character", etc.
If you want to create your own Tabs for your created Thing X
, follow these three steps:
- Create the ITab_X C# class
- Create the XCardUtility C# class to draw the UI elements
- Add the ITab to your X's ThingDef in XML
ITabs open when selected and display their Card's UI elements. So, you need an ITab_X class and on that you'll draw UI elements with a XCardUtility.
using RimWorld;
using System;
using UnityEngine;
using Verse;
namespace MyNamespace
{
public class ITab_X: ITab
{
// useful if you have criteria to show/hide this per Thing
public override bool IsVisible
{
get
{
if ( <your test> ) { return true; }
else return false;
}
}
public ITab_X()
{
Vector2 offsets= Vector2(17f,17f);
this.size = XCardUtility.CardSize + offsets;
this.labelKey = "MyNamespace_TabX"; // used to get the Tab's label
}
// Draw the Tab with the Card class
protected override void FillTab()
{
// Get the Thing selected by the cursor
ThingWithComps selected = Find.Selector.SingleSelectedThing as ThingWithComps;
Rect rect = new Rect(17f, 17f, WornAtCardUtility.CardSize.x, WornAtCardUtility.CardSize.y);
WornAtCardUtility.DrawCard(rect, selected);
}
}
}
The XCardUtility class is a class that draws the content of the ITab. It uses all the UI elements of the Widget class.
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
namespace MyNamespace
{
public class WornAtCardUtility
{
public static Vector2 CardSize = new Vector2(395f, 536f); // set the card's size
public static void DrawCard(Rect rect, ThingWithComps wornAtThing )
{
GUI.BeginGroup();
... draw ...
GUI.EndGroup();
}
}
}
Add this line to your XML definition of your Thing in XML. If you skip this step, your ITab will exist but will never be connected with your Thing X!
<inspectorTabs>
<li>MyNamespace.ITab_X</li>
</inspectorTabs>