How do I use my own designator class?

Started by ItchyFlea, December 22, 2014, 03:34:43 PM

Previous topic - Next topic

ItchyFlea

How do I get the game to use my own designator class instead of it's own set? I've created the class, and shoved it into the <specialDesignatorClasses> section of the DesignationCategories.xml file, yet when I start the game, I get given this error:
DesignationCategoryDefPlantsGrowable could not instantiate special designator from class .
Exception:
System.ArgumentNullException: Argument cannot be null.

Parameter name: type

  at System.Activator.CheckType (System.Type type) [0x00000] in <filename unknown>:0

  at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0

  at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0

  at Verse.DesignationCategoryDef.ResolveReferences () [0x00000] in <filename unknown>:0


This is the source code of my designator class: (Pretty much a copy'n'paste of the existing plant designator class code obtained via ILSpy)
using System;
using UnityEngine;
using Verse;
using RimWorld;
namespace IFPlantCut
{
public class Designator_Harvest : Designator_Plants
{
public Designator_Harvest()
{
this.defaultLabel = "DesignatorHarvest".Translate();
this.defaultDesc = "DesignatorHarvestDesc".Translate();
this.icon = ContentFinder<Texture2D>.Get("UI/Designators/Harvest", true);
this.dragSound = SoundDefOf.DesignateDragStandard;
this.useMouseIcon = true;
this.designateSucceededSound = SoundDefOf.DesignateHarvest;
this.hotKey = KeyBindingDefOf.Misc2;
}
public override AcceptanceReport CanDesignateAt(IntVec3 c)
{
if (!c.InBounds())
{
return false;
}
if (c.Fogged())
{
return false;
}
Plant plant = c.GetPlant();
if (!plant.HarvestableNow)
{
return false;
}
if (plant.def.plant.harvestTag != "Standard")
{
return false;
}
if (Find.DesignationManager.DesignationOn(plant, DesignationDefOf.HarvestPlant) != null)
{
return false;
}
return true;
}
public override void DesignateAtSingle(IntVec3 c)
{
Find.DesignationManager.AddDesignation(new Designation(c.GetPlant(), DesignationDefOf.HarvestPlant));
}
public override void FinalizeDesignationFailed()
{
Messages.Message("Must designate harvestable plants.", MessageSound.Silent);
base.FinalizeDesignationFailed();
}
}
}


My ability to code in C# is the ability to copy'n'paste existing code. My overall ability to code is nearly that bad as well. So if the solution to this issue is more code, can you provide it?
Side question: Will the above code allow me to have the game place a harvest designation on something that is in the Building category? The building category was the only way I could get the game to let me make plants "buildable" outside of a growing zone.
All my mods are licensed under a Attribution-NonCommercial-ShareAlike 4.0 International
Ask for permission before using in ModPacks

Click here for a list of the mods I've created

Lord Fappington

Itchy, I'd be interested in helping you.  However, I too am also a novice.  How does one get to opening the code in the way that you've shown.  I tried Haplo's demo and was able to open .cs files; however, I was not able to open the DLLs where I assumed more code lied?

Best,
Fapps

ItchyFlea

Download ILSpy and tell it to open \RimWorld657Win_Data\Managed\Assembly-CSharp.dll
Most of the game code is in there.
All my mods are licensed under a Attribution-NonCommercial-ShareAlike 4.0 International
Ask for permission before using in ModPacks

Click here for a list of the mods I've created

mipen

Did you remember to include the full path of your class? So instead of just MyClass, it should be MyNameSpace.MyClass otherwise I can't think why it would throw an error

Gaesatae

I've been messing with the designators the last couple of days and I want to kill myself.

I've taken a quick look at the code and I've tried it. It 'works' as a new designator for me. Look at the def XML for any typos and check if you included your full path as mipen said.

You'll get a null on every c.GetPlant() if you try to designate something without the EntityCategory of a plant.

Take a look:
public static Plant GetPlant(this IntVec3 c)
    {
      List<Thing> list = Find.ThingGrid.ThingsListAt(c);
      for (int index = 0; index < list.Count; ++index)
      {
        if (list[index].def.category == EntityCategory.Plant)
          return (Plant) list[index];
      }
      return (Plant) null;
    }


I don't think it's easy to replace a designator. Take a look at EdB Interface new designator class and what it takes to make it work. Makes you appreciate things...