public void Initialize() { //Log.Message("1"); if (!this.isInitialized) { //Log.Message("2"); this.isInitialized = true; if (this.Props != null) { //Log.Message("3"); if (this.Props.slots != null) { //Log.Message("4"); if (this.Props.slots.Count > 0) { //Log.Message("5"); foreach (SlotLoadableDef slot in this.Props.slots) { SlotLoadable newSlot = new SlotLoadable(slot, this.parent); //Log.Message("Added Slot"); this.slots.Add(newSlot); } } } } } }
// This is called on the first tick - not rolled into above Initialize since it's still needed in case subclasses implement it. public void Initialize() { if (!isInitialized) { isInitialized = true; var slots = Props?.slots; if (slots != null) { foreach (var slot in slots) { var newSlot = new SlotLoadable(slot, parent); //Log.Message("Added Slot"); this.slots.Add(newSlot); } } } }
public void ProcessInput(SlotLoadable slot) { var floatList = new List <FloatMenuOption>(); var slotOccupant = slot.SlotOccupant; if (!isGathering) { var map = GetMap; if (slotOccupant == null) { var loadTypes = slot.SlottableTypes; if (loadTypes.Count > 0) { var pawn = GetPawn; foreach (var current in loadTypes) { var thingToLoad = map.listerThings.ThingsOfDef(current) .Find(x => map.reservationManager.CanReserve(pawn, x)); if (thingToLoad != null) { //bool extraPartOnGUI(Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, current); floatList.Add(new FloatMenuOption("Load".Translate() + " " + thingToLoad.def.label, () => TryGiveLoadSlotJob(thingToLoad), extraPartWidth: 29f)); } // Commenting following out since all the unavailable options can clutter the menu. //else //{ // floatList.Add(new FloatMenuOption(string.Format(StringOf.Unavailable, current.label), // () => { })); //} } } if (floatList.Count == 0) { floatList.Add(new FloatMenuOption(StringOf.NoLoadOptions, () => { })); } } } if (slotOccupant != null) { //bool extraPartOnGUI(Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, current); floatList.Add(new FloatMenuOption(string.Format(StringOf.Unload, slotOccupant.Label), () => TryEmptySlot(slot), extraPartWidth: 29f)); } Find.WindowStack.Add(new FloatMenu(floatList)); }
public static void get_Graphic_PostFix(Thing __instance, ref Graphic __result) { ThingWithComps thingWithComps = __instance as ThingWithComps; if (thingWithComps != null) { //Log.Message("3"); CompSlotLoadable CompSlotLoadable = thingWithComps.GetComp <CompSlotLoadable>(); if (CompSlotLoadable != null) { //ThingComp activatableEffect = thingWithComps.AllComps.FirstOrDefault<ThingComp>((ThingComp y) => y.GetType().ToString() == "CompActivatableEffect.CompActivatableEffect"); SlotLoadable slot = CompSlotLoadable.ColorChangingSlot; if (slot != null) { if (!slot.IsEmpty()) { CompSlottedBonus slotBonus = slot.SlotOccupant.TryGetComp <CompSlottedBonus>(); if (slotBonus != null) { //if (activatableEffect != null) //{ // AccessTools.Field(activatableEffect.GetType(), "overrideColor").SetValue(activatableEffect, slot.SlotOccupant.DrawColor); // Log.ErrorOnce("GraphicPostFix_Called_Activatable", 1866); //} //else //{ Graphic tempGraphic = (Graphic)AccessTools.Field(typeof(Thing), "graphicInt").GetValue(__instance); if (tempGraphic != null) { if (tempGraphic.Shader != null) { tempGraphic = tempGraphic.GetColoredVersion(tempGraphic.Shader, slotBonus.Props.color, slotBonus.Props.color); //slot.SlotOccupant.DrawColor; __result = tempGraphic; //Log.Message("SlotLoadableDraw"); } } } //Log.ErrorOnce("GraphicPostFix_Called_5", 1866); //} } } } } }
public static void DrawColorTwoPostFix(Thing __instance, ref Color __result) { if (__instance is ThingWithComps thingWithComps) { //Log.Message("3"); CompSlotLoadable CompSlotLoadable = thingWithComps.GetComp <CompSlotLoadable>(); if (CompSlotLoadable != null) { SlotLoadable slot = CompSlotLoadable.SecondColorChangingSlot; if (slot != null) { if (!slot.IsEmpty()) { __result = slot.SlotOccupant.DrawColor; __instance.Graphic.colorTwo = slot.SlotOccupant.DrawColor; } } } } }
// TODO: Define SpecialDisplayStats to show stat entries in stats window? including hyperlinks to the slottables? public virtual string SlotDesc(SlotLoadable slot) { var s = new StringBuilder(); s.AppendLine(slot.DescriptionFlavor); var slotOccupant = slot.SlotOccupant; if (slotOccupant != null) { s.AppendLine(); s.AppendLine(string.Format(StringOf.CurrentlyLoaded, slotOccupant.LabelCap)); if (slot.Def?.doesChangeColor ?? false) { s.AppendLine(); s.AppendLine(StringOf.Effects); s.AppendLine(" " + StringOf.ChangesPrimaryColor); } if (slot.Def?.doesChangeStats ?? false) { var slotBonus = slotOccupant.TryGetCompSlottedBonus(); if (slotBonus != null) { var first = true; foreach (var statEntry in slotBonus.SpecialDisplayStats()) { if (first) { s.AppendLine(); s.AppendLine(StringOf.StatModifiers); first = false; } s.AppendLine(" " + statEntry.LabelCap + " " + statEntry.ValueString); } } } } return(s.ToString()); }
public bool TryLoadSlot(Thing thing) { //Log.Message("TryLoadSlot Called"); this.isGathering = false; if (this.slots != null) { if (this.slots.Count > 0) { SlotLoadable loadSlot = this.slots.FirstOrDefault((SlotLoadable x) => x.IsEmpty() && x.CanLoad(thing.def)); if (loadSlot == null) { loadSlot = this.slots.FirstOrDefault((SlotLoadable y) => y.CanLoad(thing.def)); } if (loadSlot != null) { if (loadSlot.TryLoadSlot(thing, true)) { return(true); } } } } return(false); }
public void Initialize() { //Log.Message("1"); if (!isInitialized) { //Log.Message("2"); isInitialized = true; if (Props != null) { if (Props.slots != null) { if (Props.slots.Count > 0) { foreach (var slot in Props.slots) { var newSlot = new SlotLoadable(slot, parent); //Log.Message("Added Slot"); slots.Add(newSlot); } } } } } }
public virtual string SlotDesc(SlotLoadable slot) { StringBuilder s = new StringBuilder(); s.AppendLine(slot.GetDescription()); if (!slot.IsEmpty()) { s.AppendLine(); s.AppendLine(string.Format(StringOf.CurrentlyLoaded, new object[] { slot.SlotOccupant.LabelCap })); if (((SlotLoadableDef)slot.def).doesChangeColor) { s.AppendLine(); s.AppendLine(StringOf.Effects); s.AppendLine(" " + StringOf.ChangesPrimaryColor); } if (((SlotLoadableDef)slot.def).doesChangeStats) { CompSlottedBonus slotBonus = slot.SlotOccupant.TryGetComp <CompSlottedBonus>(); if (slotBonus != null) { if (slotBonus.Props != null) { if (slotBonus.Props.statModifiers != null && slotBonus.Props.statModifiers.Count > 0) { s.AppendLine(); s.AppendLine(StringOf.StatModifiers); foreach (StatModifier mod in slotBonus.Props.statModifiers) { float v = DetermineSlottableStatAugment(slot.SlotOccupant, mod.stat); string modstring = mod.stat.ValueToString(v, ToStringNumberSense.Offset); //Log.Message("Determined slot stat augment "+v+" and made string "+modstring); s.AppendLine(" " + mod.stat.LabelCap + " " + modstring); //s.AppendLine("\t" + mod.stat.LabelCap + " " + mod.ToStringAsOffset); } /* * //Log.Message("fix this to display statModifiers"); * List<StatModifier> statMods = slot.SlotOccupant.def.statBases.FindAll( * (StatModifier z) => z.stat.category == StatCategoryDefOf.Weapon || * z.stat.category == StatCategoryDefOf.EquippedStatOffsets); * if (statMods != null && statMods.Count > 0) * { * s.AppendLine(); * s.AppendLine("StatModifiers".Translate() + ":"); * foreach (StatModifier mod in statMods) * { * s.AppendLine("\t" + mod.stat.LabelCap + " " + mod.ToStringAsOffset); * } * } */ } DamageDef damageDef = slotBonus.Props.damageDef; if (damageDef != null) { s.AppendLine(); s.AppendLine(string.Format(StringOf.DamageType, new object[] { damageDef.LabelCap })); } SlotBonusProps_DefensiveHealChance defHealChance = slotBonus.Props.defensiveHealChance; if (defHealChance != null) { string healText = StringOf.all; if (defHealChance.woundLimit != 0) { healText = defHealChance.woundLimit.ToString(); } s.AppendLine(" " + string.Format(StringOf.DefensiveHealChance, new object[] { healText, defHealChance.chance.ToStringPercent() })); } SlotBonusProps_VampiricEffect vampChance = slotBonus.Props.vampiricHealChance; if (vampChance != null) { string vampText = StringOf.all; if (vampChance.woundLimit != 0) { vampText = defHealChance.woundLimit.ToString(); } s.AppendLine(" " + string.Format(StringOf.VampiricChance, new object[] { vampText, vampChance.chance.ToStringPercent() })); } } } } } return(s.ToString()); }
public virtual void TryEmptySlot(SlotLoadable slot) => slot.TryEmptySlot();
public void ProcessInput(SlotLoadable slot) { List <ThingDef> loadTypes = new List <ThingDef>(); List <FloatMenuOption> floatList = new List <FloatMenuOption>(); if (!this.isGathering) { Map map = this.GetMap; loadTypes = slot.SlottableTypes; if (slot.SlotOccupant == null) { if (loadTypes != null) { if (loadTypes.Count != 0) { foreach (ThingDef current in loadTypes) { List <Thing> thingsWithDef = new List <Thing>(map.listerThings.AllThings.FindAll((Thing x) => x.def == current)); if (thingsWithDef != null) { if (thingsWithDef.Count > 0) { Thing thingToLoad = thingsWithDef.FirstOrDefault((Thing x) => map.reservationManager.CanReserve(this.GetPawn, x)); if (thingToLoad != null) { string text = "Load".Translate() + " " + thingToLoad.def.label; //Func<Rect, bool> extraPartOnGUI = (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, current); floatList.Add(new FloatMenuOption(text, delegate { this.TryGiveLoadSlotJob(thingToLoad); }, MenuOptionPriority.Default, null, null, 29f, null, null)); } else { floatList.Add(new FloatMenuOption(string.Format(StringOf.Unavailable, new object[] { current.label }), delegate { }, MenuOptionPriority.Default)); } } else { floatList.Add(new FloatMenuOption(string.Format(StringOf.Unavailable, new object[] { current.label }), delegate { }, MenuOptionPriority.Default)); } } else { floatList.Add(new FloatMenuOption(string.Format(StringOf.Unavailable, new object[] { current.label }), delegate { }, MenuOptionPriority.Default)); } } } else { floatList.Add(new FloatMenuOption(StringOf.NoLoadOptions, delegate { }, MenuOptionPriority.Default)); } } } } else { //TryCancel(); } if (!slot.IsEmpty()) { string text = string.Format(StringOf.Unload, new object[] { slot.SlotOccupant.Label }); //Func<Rect, bool> extraPartOnGUI = (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, current); floatList.Add(new FloatMenuOption(text, delegate { TryEmptySlot(slot); }, MenuOptionPriority.Default, null, null, 29f, null, null)); } Find.WindowStack.Add(new FloatMenu(floatList)); }