public SlotLoadable(Thing newOwner) { //Log.Message("Slot started"); owner = newOwner; ThingIDMaker.GiveIDTo(this); slot = new ThingOwner <Thing>(this, false, LookMode.Deep); }
public override void ExposeData() { base.ExposeData(); if (Scribe.mode == LoadSaveMode.Saving) { if (thingIDNumber == -1) { ThingIDMaker.GiveIDTo(this); } } Scribe_Deep.Look(ref slot, nameof(slot), this); Scribe_References.Look(ref owner, nameof(owner)); // Only save slottableThingDefs if it isn't Def.slottableThingDefs (otherwise, save null) to save space. var defSlottableThingDefs = Def?.slottableThingDefs; var savedSlottableThingDefs = slottableThingDefs; if (defSlottableThingDefs != null && slottableThingDefs != null && defSlottableThingDefs.SequenceEqual(slottableThingDefs)) { savedSlottableThingDefs = null; } Scribe_Collections.Look(ref savedSlottableThingDefs, nameof(slottableThingDefs), LookMode.Def); if (slottableThingDefs != null) { slottableThingDefs = savedSlottableThingDefs; } }
// RimWorld.CharacterCardUtility public static void DrawCard(Rect rect, ThingWithComps selectedThing) { GUI.BeginGroup(rect); var compToggleDef = selectedThing.GetComp <CompToggleDef>(); if (compToggleDef != null) { var ts = Text.CalcSize(selectedThing.LabelCap).x; var y = rect.y; var rect2 = new Rect(rect.width / 2 - ts + SpacingOffset, y, rect.width, HeaderSize); y += rect2.height; Text.Font = GameFont.Medium; Widgets.Label(rect2, selectedThing.LabelCap); Text.Font = GameFont.Small; Widgets.ListSeparator(ref y, rect2.width, "Select one of the following:"); // add all the buttons for the toggle defs foreach (var td in compToggleDef.toggleDefs) { var rect3 = new Rect(0f, y, rect.width, 20f); var isactive = false; if (selectedThing.def == td) { isactive = true; } if (Widgets.RadioButtonLabeled(rect3, td.LabelCap, isactive)) { //Log.Message(".. change location to "+td.LabelCap); // CHange def then give it a new id. Hopefully nothing index on the id var map = selectedThing.Map; var loc = selectedThing.Position; var rot = selectedThing.Rotation; selectedThing.DeSpawn(); selectedThing.def = td; selectedThing.thingIDNumber = -1; ThingIDMaker.GiveIDTo(selectedThing); // necessary CompColorable colorable = selectedThing.TryGetComp <CompColorable>(); if (colorable != null) { colorable.Color = selectedThing.def.colorGenerator.NewRandomizedColor(); } // selectedThing.DrawColor = selectedThing.def.colorGenerator.NewRandomizedColor(); Graphic graphic = selectedThing.def.graphicData.GraphicColoredFor(selectedThing); GenSpawn.Spawn(selectedThing, loc, map, rot); FieldInfo subgraphic = typeof(Thing).GetField("graphicInt", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField); Traverse traverse = Traverse.Create(selectedThing); subgraphic.SetValue(selectedThing, graphic); Find.Selector.Select(selectedThing); break; } y += 25f; } } GUI.EndGroup(); }
public SlotLoadable(SlotLoadableDef xmlDef, Thing newOwner) { //Log.Message("Slot Loaded"); def = xmlDef; slottableThingDefs = xmlDef.slottableThingDefs; owner = newOwner; ThingIDMaker.GiveIDTo(this); slot = new ThingOwner <Thing>(this, false, LookMode.Deep); }
public SlotLoadable(Thing newOwner) { Log.Message("Slot started"); SlotLoadableDef def = this.def as SlotLoadableDef; this.slottableThingDefs = def.slottableThingDefs; owner = newOwner; ThingIDMaker.GiveIDTo(this); slot = new ThingOwner <Thing>(this, false, LookMode.Deep); }
public override void ExposeData() { base.ExposeData(); if (Scribe.mode == LoadSaveMode.Saving) { if (thingIDNumber == -1) { ThingIDMaker.GiveIDTo(this); } } Scribe_Deep.Look(ref slot, "slot", this); Scribe_Collections.Look(ref slottableThingDefs, "slottableThingDefs", LookMode.Undefined); Scribe_References.Look(ref owner, "owner"); //Scribe_References.Look<Thing>(ref this.slotOccupant, "slotOccupant"); }
// RimWorld.CharacterCardUtility public static void DrawCard(Rect rect, ThingWithComps selectedThing) { GUI.BeginGroup(rect); var compToggleDef = selectedThing.GetComp <CompToggleDef>(); if (compToggleDef != null) { var ts = Text.CalcSize(selectedThing.LabelCap).x; var y = rect.y; var rect2 = new Rect(rect.width / 2 - ts + SpacingOffset, y, rect.width, HeaderSize); y += rect2.height; Text.Font = GameFont.Medium; Widgets.Label(rect2, selectedThing.LabelCap); Text.Font = GameFont.Small; Widgets.ListSeparator(ref y, rect2.width, "Select one of the following:"); // add all the buttons for the toggle defs foreach (var td in compToggleDef.toggleDefs) { var rect3 = new Rect(0f, y, rect.width, 20f); var isactive = false; if (selectedThing.def == td) { isactive = true; } if (Widgets.RadioButtonLabeled(rect3, td.LabelCap, isactive)) { //Log.Message(".. change location to "+td.LabelCap); // CHange def then give it a new id. Hopefully nothing index on the id var map = selectedThing.Map; var loc = selectedThing.Position; var rot = selectedThing.Rotation; selectedThing.DeSpawn(); selectedThing.def = td; selectedThing.thingIDNumber = -1; ThingIDMaker.GiveIDTo(selectedThing); // necessary GenSpawn.Spawn(selectedThing, loc, map, rot); break; } y += 25f; } } GUI.EndGroup(); }
public virtual Thing CreateThing(bool useOriginalID = false, int stackCount = 0) { var gx = new GameXMLUtils(); Thing thing = gx.FromXml <Thing>(Data); thing.stackCount = stackCount == 0 ? Count : stackCount; if (OriginalID <= 0 || !useOriginalID) { thing.thingIDNumber = -1; ThingIDMaker.GiveIDTo(thing); } else { thing.thingIDNumber = OriginalID; } return(thing); }
public Thing CreateThing(bool useOriginalID, int stackCount = 0) { var gx = new GameXMLUtils(); Thing thing = gx.FromXml <Thing>(Data); thing.stackCount = stackCount == 0 ? Count : stackCount; if (OriginalID <= 0 || useOriginalID) { thing.thingIDNumber = -1; ThingIDMaker.GiveIDTo(thing); } else { thing.thingIDNumber = OriginalID; } return(thing); /* * var def = (ThingDef)GenDefDatabase.GetDef(typeof(ThingDef), DefName); * var stuffDef = !string.IsNullOrEmpty(StuffName) ? (ThingDef)GenDefDatabase.GetDef(typeof(ThingDef), StuffName) : GenStuff.DefaultStuffFor(def); * Thing thing = ThingMaker.MakeThing(def, stuffDef); * thing.stackCount = stackCount == 0 ? Count : stackCount; * * if (HitPoints > 0) thing.HitPoints = HitPoints; * * CompQuality compQuality = thing.TryGetComp<CompQuality>(); * if (compQuality != null) * { * compQuality.SetQuality((QualityCategory)(Quality + 3), ArtGenerationContext.Outsider); * } * * if (WornByCorpse) * { * Apparel thingA = thing as Apparel; * if (thingA != null) * { * typeof(Apparel) * .GetField("wornByCorpseInt", BindingFlags.Instance | BindingFlags.NonPublic) * .SetValue(thingA, true); * } * } * return thing; */ }
public virtual Thing CreateThing(bool useOriginalID = false, int stackCount = 0, bool needPirate = false) { var gx = new GameXMLUtils(); Thing thing = gx.FromXml <Thing>(Data); thing.stackCount = stackCount == 0 ? Count : stackCount; if (OriginalID <= 0 || !useOriginalID) { thing.thingIDNumber = -1; ThingIDMaker.GiveIDTo(thing); } else { thing.thingIDNumber = OriginalID; } SetFaction(thing, isColonist && !needPirate); return(thing); }
public override void PostMake() { ThingIDMaker.GiveIDTo(this); }