Is it possible?
What I'm doing exactly : I'm trying to make custom Graphic_LinkedTransmitter, which draws linked graphic when there is nearby linkable building.
What I figured : It seems I can't set Graphic_Linked* to ThingDef <graphicClass> directly, as they are defined as enum LinkDrawerType in ThingDef <linkDrawerType> and loaded at ThingDef.PostLoad(). I hate enums...
What I tried : Copied & pasted Grphic_LinkedTransmitter and modified a few words in ShouldLinkWith(). Also, made a custom building which looks like this.
public override void SpawnSetup()
{
base.SpawnSetup();
def.graphic = new Graphic_LinkedCustomTransmitter(def.graphic);
...
}
What I got : Bad material, that red square.
This might help, if i understand you correctly andif not you can try Haplo power switches since they use linked graphic to
using RimWorld;
using System;
using System.Collections.Generic;
using UnityEngine;
using Verse;
namespace Clutter
{
internal class Wall_Multi : Building
{
public static Graphic SecondaryMaterial = null;
public static Graphic ThirdMaterial = null;
private static Texture2D RebuildIco;
public Graphic_LinkedCornerFiller Graphic2nd = null;
public Graphic_LinkedCornerFiller Graphic3rd = null;
public ClutterThingDefs def2;
private int WallRandom = -1;
public override Graphic Graphic
{
get
{
Graphic result;
if (this.Graphic2nd == null || this.Graphic2nd.MatSingle == null)
{
this.GetGraphics();
if (this.Graphic2nd == null || this.Graphic2nd.MatSingle == null)
{
result = this.def.graphic;
return result;
}
}
if (this.WallRandom >= 56 && this.WallRandom <= 74)
{
result = this.Graphic2nd;
}
else
{
if (this.WallRandom > 75 && this.WallRandom <= 94)
{
result = this.Graphic3rd;
}
else
{
result = this.def.graphic;
}
}
return result;
}
}
public override void SpawnSetup()
{
base.SpawnSetup();
Wall_Multi.RebuildIco = ContentFinder<Texture2D>.Get("Clutter/Ui/Work_ico", true);
this.GetGraphics();
if (this.WallRandom == -1)
{
this.WallRandom = UnityEngine.Random.Range(1, 100);
}
}
public override void PostMake()
{
base.PostMake();
}
public override void ExposeData()
{
base.ExposeData();
Scribe_Values.LookValue<int>(ref this.WallRandom, "WallSelectionNumber", -1, false);
this.GetGraphics();
}
private void GetGraphics()
{
this.def2 = (this.def as ClutterThingDefs);
if (this.Graphic2nd == null || this.Graphic2nd.MatSingle == null)
{
Graphic graphic_Single = GraphicDatabase.Get<Graphic_Single>(this.def2.SecondaryMaterialPath);
this.Graphic2nd = new Graphic_LinkedCornerFiller(graphic_Single);
}
if (this.Graphic3rd == null || this.Graphic3rd.MatSingle == null)
{
Graphic graphic_Single2 = GraphicDatabase.Get<Graphic_Single>(this.def2.ThirdMaterialPath);
this.Graphic3rd = new Graphic_LinkedCornerFiller(graphic_Single2);
}
}
public override IEnumerable<Gizmo> GetGizmos()
{
Command_Action commandAction = new Command_Action();
commandAction.icon = Wall_Multi.RebuildIco;
commandAction.defaultDesc = "Mount Lights";
commandAction.activateSound = SoundDef.Named("Click");
commandAction.action = new Action(this.WallLightSpawn);
commandAction.hotKey = KeyBindingDefOf.Misc2;
commandAction.groupKey = 887769910;
if (commandAction != null)
{
yield return commandAction;
}
yield break;
}
private void WallLightSpawn()
{
this.Destroy(0);
GenConstruct.PlaceBlueprintForBuild(ThingDef.Named("ClutterUWallLight"), base.Position, base.Rotation, Faction.OfColony, null);
}
}
}
Thank you mrofa, that might help. I'll dig into.
Worked like charm. Thank you!