-
Notifications
You must be signed in to change notification settings - Fork 9
SHORTTUTORIAL: CompToggleDef
This is in the process of entering Jec's Tools so give it some time to go live.
A situational Component that allows you to toggle the ThingDef of a selected Thing via a radio button menu. ex. Change a ring to be for a pinky finger versus a ring or index finger.
![](https://github.com/roxxploxx/RimWorldModGuide/raw/master/src/CompToggleDef1.png)
![](https://github.com/roxxploxx/RimWorldModGuide/raw/master/src/CompToggleDef2.png)
You will be creating an abstract Thing in XML and listing several Toggleable versions of it that are not abstract. The only other change is to ensure the ITab has a label.
Notice the Abstract="True"
. This means you can create several ThingDefs from it in a future step. Additionally, ensure that <thingClass>
is or is a child of ThingWithComps. If your <ThingDef>
uses "ParentName", then it may get the <thingClass>
from that.
<ThingDef Name="Apparel_MyRing" Abstract="True">
...
<thingClass>...</thingClass>
...
</ThingDef>
In your ThingDef, you need to have a <comps>
element that contains the CompProperties_ToggleDef component. The one entry in it is a key into the language files, which names the ITab that appears on the item when selected.
<comps>
<li Class="CompToggleDef.CompProperties_ToggleDef">
<labelKey>MyLabelOnITabForChangingDef</labelKey>
</li>
</comps>
This element will add the ITab to the item that will be able to Toggle it's def. Copy this in exactly or, if there is already an <inspectorTabs>
element, just place the inner <li>
tag inside the <inspectorTabs>
.
<inspectorTabs>
<li>CompToggleDef.ITab_ToggleDef</li>
</inspectorTabs>
Now, create additional ThingDef entries for all the different types/flavors of toggleable def you wish to have. Anything in here will overwrite its parent. The following must be set appropriately though:
-
The
<defName>
element MUST follow this format:previous thingdef name | "_TOGGLEDEF_" | key
. Key doesn't really matter except that it must be different from all other items. The"_TOGGLEDEF_"
is used to identify a toggleable ThingDef and if missing, will not connect this new child to the parent. I.e. at start, the CompToggleDef will search every ThingDef and see if they are a child. -
The "ParentName" must be set to the about ThingDef entry.
<ThingDef ParentName="Apparel_MyRing">
<defName>Apparel_MyRing_TOGGLEDEF_RP</defName>
<label>my ring (right pinky)</label>
<apparel>
<layers><li>Belt</li></layers>
<bodyPartGroups>
<li>RightHandPinky</li>
</bodyPartGroups>
</apparel>
</ThingDef>
So the ITab will show "Worn On" and when selected, a window will open and allow you to set the new ThingDef of the item.
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>
<MyLabelOnITabForChangingDef>Worn On</MyLabelOnITabForChangingDef>
</LanguageData>
This is a ring of warmth that can be worn on various fingers. I only show two fingers (right pinky and ring).
<!-- Ring of Warmth-->
<ThingDef Name="Apparel_RingOfWarmth" Abstract="True" ParentName="WizardArmorMakeableBase">
<selectable>true</selectable>
<description>Infused with arcane energy, this ring radiates a warmth throughouth your body.</description>
<techLevel>Neolithic</techLevel>
<recipeMaker>
<skillRequirements>
<li>
<skill>Wizardry</skill>
<minLevel>3</minLevel>
</li>
</skillRequirements>
<researchPrerequisite>Elementalism</researchPrerequisite>
</recipeMaker>
<graphicData>
<texPath>Things/Pawn/Humanlike/Apparel/Wizardry/Ring</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<statBases>
<WorkToMake>3000</WorkToMake>
<MaxHitPoints>100</MaxHitPoints>
<Insulation_Cold>-25</Insulation_Cold>
</statBases>
<thingCategories>
<li>Apparel</li>
</thingCategories>
<inspectorTabs>
<li>CompToggleDef.ITab_ToggleDef</li>
</inspectorTabs>
<comps>
<li Class="CompToggleDef.CompProperties_ToggleDef">
<labelKey>UM_Tab_ToggleDef_Rings</labelKey>
</li>
</comps>
<costList>
<Gold>10</Gold>
<PowerRune>1</PowerRune>
<BindingRune>2</BindingRune>
<ControlRune>1</ControlRune>
</costList>
<apparel>
<worngraphicPath>Things/Pawn/Humanlike/Apparel/PowerArmor/PowerArmor</worngraphicPath>
<layers>
<li>Belt</li>
</layers>
</apparel>
</ThingDef>
<ThingDef ParentName="Apparel_RingOfWarmth">
<defName>Apparel_RingOfWarmth_TOGGLEDEF_RP</defName>
<label>ring of warmth (RPinky)</label>
<apparel>
<layers>
<li>Belt</li>
</layers>
<bodyPartGroups>
<li>RightHandPinky</li>
</bodyPartGroups>
</apparel>
</ThingDef>
<ThingDef ParentName="Apparel_RingOfWarmth">
<defName>Apparel_RingOfWarmth_TOGGLEDEF_RR</defName>
<label>ring of warmth (RRing)</label>
<apparel>
<bodyPartGroups>
<li>RightHandRingFinger</li>
</bodyPartGroups>
</apparel>
</ThingDef>