public override void Apply() { if (WorldComp != null && Editor != null) { WorldComp.SetEditorValue(Editor, true); } }
public AssignOutfitUI(Building_Dresser dresser) { this.Dresser = dresser; this.closeOnClickedOutside = true; this.doCloseButton = true; this.doCloseX = true; this.absorbInputAroundWindow = true; this.forcePause = true; this.closeOnClickedOutside = false; foreach (Pawn p in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_Colonists) { if (p.Faction == Faction.OfPlayer && p.def.race.Humanlike) { if (!WorldComp.PawnOutfits.ContainsKey(p)) { PawnOutfitTracker po = new PawnOutfitTracker(); po.Pawn = p; Outfit currentOutfit = p.outfits.CurrentOutfit; if (currentOutfit != null) { po.AddOutfit(new DefinedOutfit(currentOutfit, WorldComp.GetOutfitType(currentOutfit))); } WorldComp.PawnOutfits.Add(p, po); } } } }
static void Postfix(ref bool __result, WorkGiver_DoBill __instance, Bill bill, Pawn pawn, Thing billGiver, List <ThingCount> chosen) { if (__result == false && pawn != null && bill != null && bill.recipe != null && bill.Map == pawn.Map && bill.recipe.defName.IndexOf("Weapon") != -1) { IEnumerable <Building_WeaponStorage> storages = WorldComp.GetWeaponStorages(bill.Map); if (storages == null) { Log.Message("MendingWeaponStoragePatch failed to retrieve WeaponStorages"); return; } foreach (Building_WeaponStorage ws in storages) { if ((float)(ws.Position - billGiver.Position).LengthHorizontalSquared < bill.ingredientSearchRadius * bill.ingredientSearchRadius) { foreach (KeyValuePair <ThingDef, LinkedList <ThingWithComps> > kv in ws.StoredWeapons) { FindMatches(ref __result, bill, chosen, ws, kv); } foreach (KeyValuePair <ThingDef, LinkedList <ThingWithComps> > kv in ws.StoredBioEncodedWeapons) { FindMatches(ref __result, bill, chosen, ws, kv); } } } } }
// Used to automatically re-arm turrets static void Postfix(WorkGiver_ReloadTurret __instance, ref Job __result, Pawn pawn, Thing t, bool forced) { if (__result == null) { if (t is Building_TurretGunCE turret) { if (WorldComp.HasStorages(turret.Map) && CombatExtendedUtil.HasAmmo(turret.CompAmmo.SelectedAmmo)) { var storage = GenClosest.ClosestThingReachable( turret.Position, turret.Map, ThingRequest.ForDef(WorldComp.WeaponStorageDef), Verse.AI.PathEndMode.ClosestTouch, TraverseParms.For(pawn, pawn.NormalMaxDanger(), TraverseMode.ByPawn, false), 100); if (storage != null) { // TODO - Add setting where ammo should be dropped //CombatExtendedUtil.TryDropAmmo(turret.CompAmmo.SelectedAmmo, turret.CompAmmo.Props.magazineSize, storage.Position, storage.Map); __result = new Job( DefDatabase <JobDef> .GetNamed("ReloadTurret", true), t, new StoredAmmo( Patch_WorkGiver_ReloadTurret_HasJobOnThing.WS, turret.CompAmmo.SelectedAmmo, turret.CompAmmo.Props.magazineSize, forced)); } } } } }
private void NextWeaponStorage(int increment) { List <Building_WeaponStorage> ws = WorldComp.GetWeaponStorages(); if (this.weaponStorage == null) { this.weaponStorage = ws[(increment < 0) ? ws.Count - 1 : 0]; } else { for (int i = 0; i < ws.Count; ++i) { if (this.weaponStorage == ws[i]) { i += increment; if (i < 0) { this.weaponStorage = ws[ws.Count - 1]; } else if (i >= ws.Count) { this.weaponStorage = ws[0]; } else { this.weaponStorage = ws[i]; } break; } } } this.RebuildPossibleWeapons(); }
/// <summary> /// 检测世界交换物体的缓存 /// </summary> private void CheckWorldItemCaches(ref IShipDockEntitas target) { if (WorldComp.IsDataValid(ref target)) { mWorldItem = WorldComp.GetEntitasData(ref target); if (ShouldAddToWorldItems()) { mWorldItemMapper.Put(mWorldItem.worldItemID, mWorldItem); AfterWorldItemCached(ref target); } } }
// used to manually re-arm turrets static void Postfix(WorkGiver_ReloadTurret __instance, ref bool __result, Pawn pawn, Thing t, bool forced) { Building_TurretGunCE turret = t as Building_TurretGunCE; if (__result == false && turret != null && !turret.def.hasInteractionCell) { if (WorldComp.HasStorages(turret.Map) && CombatExtendedUtil.HasAmmo(turret.CompAmmo.SelectedAmmo)) { WS = GenClosest.ClosestThingReachable(turret.Position, turret.Map, ThingRequest.ForDef(WorldComp.WeaponStorageDef), Verse.AI.PathEndMode.ClosestTouch, TraverseParms.For(pawn, pawn.NormalMaxDanger(), TraverseMode.ByPawn, false), 100) as Building; __result = WS != null; } } }
public override int DropEntitas(IShipDockEntitas target, int entitasID) { mWorldItem = WorldComp.GetEntitasData(ref target); if ((mWorldItem != default) && (mWorldItem.worldItemID != int.MaxValue)) { if (mWorldItemMapper.ContainsKey(mWorldItem.worldItemID)) { DropWorldItem(ref target); } } return(base.DropEntitas(target, entitasID)); }
private void HandleOutfitAssign(bool assign, Outfit outfit, PawnOutfitTracker po) { Pawn pawn = po.Pawn; if (assign) { po.DefinedOutfits.Add(new DefinedOutfit(outfit, WorldComp.GetOutfitType(outfit))); } else { po.Remove(outfit); if (pawn.outfits.CurrentOutfit.Equals(outfit)) { bool newOutfitFound; if (pawn.Drafted) { newOutfitFound = !po.ChangeToBattleOutfit(); } else { newOutfitFound = !po.ChangeToCivilianOutfit(); } if (!newOutfitFound) { Messages.Message( pawn.Name.ToStringShort + " will no longer wear " + outfit.label + ". Could not find another Outfit for them to wear. Please fix this manually.", MessageTypeDefOf.CautionInput); } else { IDresserOutfit o = po.CurrentOutfit; if (o != null) { Messages.Message( pawn.Name.ToStringShort + " will no longer wear " + outfit.label + " and will instead be assigned to wear " + o.Label, MessageTypeDefOf.CautionInput); } else { Messages.Message( pawn.Name.ToStringShort + " will no longer wear " + outfit.label + " but could not be assigned anything else to wear.", MessageTypeDefOf.CautionInput); } } } } }
private void LoadAssignedWeapons() { SelectablePawns p = this.selectablePawns[this.pawnIndex]; if (!WorldComp.TryGetAssignedWeapons(p.Pawn, out this.assignedWeapons)) { this.assignedWeapons = new AssignedWeaponContainer { Pawn = p.Pawn }; if (p.Pawn.equipment.Primary != null) { this.assignedWeapons.Add(p.Pawn.equipment.Primary); } WorldComp.AddAssignedWeapons(p.Pawn, this.assignedWeapons); } this.RebuildPossibleWeapons(); }
static void Postfix(ref bool __result, Bill bill, Pawn pawn, Thing billGiver, bool ignoreHitPoints, ref Thing chosen) { if (__result == false && pawn != null && bill != null && bill.recipe != null && bill.Map == pawn.Map && bill.recipe.defName.IndexOf("Apparel") != -1) { IEnumerable <Building_Dresser> dressers = WorldComp.GetDressers(bill.Map); if (dressers == null) { Log.Message("MendingChangeDresserPatch failed to retrieve ChangeDressers"); return; } foreach (Building_Dresser dresser in dressers) { if ((float)(dresser.Position - billGiver.Position).LengthHorizontalSquared < bill.ingredientSearchRadius * bill.ingredientSearchRadius) { List <Apparel> gotten; if (dresser.TryGetFilteredApparel(bill, bill.ingredientFilter, out gotten, true, true)) { Apparel a = gotten[0]; dresser.Remove(a, false); if (a.Spawned == false) { Log.Error("Failed to spawn apparel-to-mend [" + a.Label + "] from dresser [" + dresser.Label + "]."); __result = false; chosen = null; } else { __result = true; chosen = a; } return; } } } } }
public CustomOutfitUI(Building_Dresser dresser) { #if CUSTOM_OUTFIT_UI Log.Warning("Begin CustomOutfitUI.CustomOutfitUI(Dresser: " + dresser.Label + ")"); #endif this.Dresser = dresser; this.closeOnClickedOutside = false; this.doCloseButton = false; this.doCloseX = false; this.absorbInputAroundWindow = true; this.forcePause = true; WorldComp.CleanupCustomOutfits(); #if CUSTOM_OUTFIT_UI Log.Message(" Populate Selectable Pawns:"); #endif foreach (Pawn p in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_Colonists) { #if CUSTOM_OUTFIT_UI Log.Message(" " + p.Name.ToStringShort + " " + p.Faction + " " + p.def.defName); #endif if (p.Faction == Faction.OfPlayer && p.def.race.Humanlike && p.apparel?.LockedApparel?.Count == 0) { #if CUSTOM_OUTFIT_UI Log.Message(" -- Added"); #endif selectablePawns.Add(p); } } this.UpdateAvailableApparel(); #if CUSTOM_OUTFIT_UI Log.Warning("End CustomOutfitUI.CustomOutfitUI"); #endif }
public override void DoWindowContents(Rect inRect) { try { Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(new Rect(0, 0, 200, 50), "ChangeDresser.ApparelStorageLabel".Translate()); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleLeft; this.Filter = Widgets.TextArea(new Rect(250, 0, 150, 32), this.Filter); Text.Anchor = TextAnchor.MiddleCenter; if (Widgets.ButtonText(new Rect(425, 0, 250, 32), ((this.Dresser == null) ? (string)"ChangeDresser".Translate() : this.Dresser.Label))) { List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (Building_Dresser cd in WorldComp.GetDressers(null)) { options.Add(new FloatMenuOption(cd.Label, delegate() { this.Dresser = cd; })); } Find.WindowStack.Add(new FloatMenu(options)); } if (this.Dresser == null) { return; } Text.Font = GameFont.Small; List <Apparel> wornApparel = (this.Pawn != null) ? this.Pawn.apparel.WornApparel : null; const float cellHeight = 40f; float apparelListWidth = inRect.width * 0.5f - 10f; Rect apparelListRect; Rect apparelScrollRect; if (wornApparel != null) { GUI.Label(new Rect(0, 60, 100, 30), ("ChangeDresser.Worn").Translate(), WidgetUtil.MiddleCenter); apparelListRect = new Rect(0, 90, apparelListWidth, inRect.height - 130); apparelScrollRect = new Rect(0f, 0f, apparelListWidth - 16f, wornApparel.Count * cellHeight); GUI.BeginGroup(apparelListRect); this.scrollPosLeft = GUI.BeginScrollView(new Rect(GenUI.AtZero(apparelListRect)), this.scrollPosLeft, apparelScrollRect); GUI.color = Color.white; Text.Font = GameFont.Medium; for (int i = 0; i < wornApparel.Count; ++i) { Apparel apparel = wornApparel[i]; Rect rowRect = new Rect(0, 2f + i * cellHeight, apparelListRect.width, cellHeight); GUI.BeginGroup(rowRect); Widgets.ThingIcon(new Rect(0f, 0f, cellHeight, cellHeight), apparel); if (Widgets.InfoCardButton(40, 0, apparel)) { Find.WindowStack.Add(new Dialog_InfoCard(apparel)); } Text.Font = GameFont.Small; Widgets.Label(new Rect(35f + cellHeight, 0f, rowRect.width - 110f, cellHeight), apparel.Label); GUI.color = Color.white; if (Widgets.ButtonImage(new Rect(rowRect.width - 35f, 10, 20, 20), WidgetUtil.nextTexture)) { this.Pawn.apparel.Remove(apparel); this.Dresser.AddApparel(apparel); this.cachedApparel.Clear(); this.cachedApparel = null; GUI.EndGroup(); break; } GUI.EndGroup(); } GUI.EndScrollView(); GUI.EndGroup(); } GUI.Label(new Rect((wornApparel == null) ? 0 : inRect.width * 0.5f, 60, (wornApparel == null) ? inRect.width : 100, 30), ("ChangeDresser.Storage").Translate(), WidgetUtil.MiddleCenter); float left = (wornApparel == null) ? 0 : inRect.width - apparelListWidth; float width = (wornApparel == null) ? inRect.width : apparelListWidth; apparelListRect = new Rect(left, 90, width, inRect.height - 130); apparelScrollRect = new Rect(0f, 0f, width - 16f, this.height); this.height = 2f; GUI.BeginGroup(apparelListRect); this.scrollPosRight = GUI.BeginScrollView(new Rect(GenUI.AtZero(apparelListRect)), this.scrollPosRight, apparelScrollRect); string filter = this.Filter.Trim().ToLower(); GUI.color = Color.white; Text.Font = GameFont.Medium; for (int i = 0; i < this.CachedApparel.Count; ++i) { Apparel apparel = this.cachedApparel[i]; if (filter != "" && apparel.Label.ToLower().IndexOf(filter) == -1) { continue; } Rect rowRect = new Rect(0, this.height, apparelScrollRect.width, cellHeight); this.height += cellHeight; GUI.BeginGroup(rowRect); if (this.Pawn != null) { Rect buttonRect = new Rect(5, 10, 20, 20); bool canWear = this.Pawn.apparel.CanWearWithoutDroppingAnything(apparel.def); if (canWear) { if (Widgets.ButtonImage(buttonRect, WidgetUtil.previousTexture)) { if (this.Dresser.TryRemove(apparel, false)) { this.cachedApparel.Clear(); this.cachedApparel = null; PawnOutfitTracker outfits; if (WorldComp.PawnOutfits.TryGetValue(this.Pawn, out outfits)) { outfits.ApplyApparelColor(apparel); } this.Pawn.apparel.Wear(apparel); GUI.EndGroup(); break; } else { Log.Error("Problem dropping " + apparel.Label); } } } else { Widgets.ButtonImage(buttonRect, WidgetUtil.cantTexture); } } Widgets.ThingIcon(new Rect(35f, 0f, cellHeight, cellHeight), apparel); if (Widgets.InfoCardButton(75, 0, apparel)) { Find.WindowStack.Add(new Dialog_InfoCard(apparel)); } Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(new Rect(30 + cellHeight + 15f, 0f, rowRect.width - 110f, cellHeight), apparel.Label); if (Widgets.ButtonImage(new Rect(rowRect.width - 45f, 0f, 20, 20), WidgetUtil.dropTexture)) { if (this.Dresser.TryRemove(apparel, false)) { this.cachedApparel.Clear(); this.cachedApparel = null; GUI.EndGroup(); break; } else { Log.Error("Problem dropping " + apparel.Label); } } GUI.EndGroup(); } GUI.EndScrollView(); GUI.EndGroup(); } catch (Exception e) { Log.Error(this.GetType().Name + " closed due to: " + e.GetType().Name + " " + e.Message); Messages.Message(this.GetType().Name + " closed due to: " + e.GetType().Name + " " + e.Message, MessageTypeDefOf.RejectInput); base.Close(); } finally { Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; } }
public override void DoWindowContents(Rect inRect) { #if TRACE ++i; #endif GUI.color = Color.white; Text.Font = GameFont.Small; try { float x = 0, y = 0; string label = ""; if (Settings.EnableAssignWeapons) { #region Assign To Widgets.Label(new Rect(x, y + 4, 100, 30), "WeaponStorage.AssignTo".Translate()); x += 80; if (this.selectablePawns.Count > 0 && GUI.Button(new Rect(x, y, 30, 30), previousTexture)) { --this.pawnIndex; if (this.pawnIndex < 0 || this.assignedWeapons == null) { this.pawnIndex = this.selectablePawns.Count - 1; } this.LoadAssignedWeapons(); } x += 30; label = (this.assignedWeapons != null) ? SelectablePawns.GetLabelAndStatsFor(this.assignedWeapons.Pawn) : ""; if (Widgets.ButtonText(new Rect(x, y, 400, 30), label)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (SelectablePawns p in this.selectablePawns) { options.Add(new FloatMenuOption(p.LabelAndStats, delegate { this.UpdatePawnIndex(p.Pawn); }, MenuOptionPriority.Default, null, null, 0f, null, null)); } Find.WindowStack.Add(new FloatMenu(options)); } x += 400; if (this.selectablePawns.Count > 0 && GUI.Button(new Rect(x, y, 30, 30), nextTexture)) { ++this.pawnIndex; if (this.pawnIndex >= this.selectablePawns.Count || this.assignedWeapons == null) { this.pawnIndex = 0; } this.LoadAssignedWeapons(); } x += 40; #endregion y += 40; } #region Weapon Storage x = 0; Widgets.Label(new Rect(x, y - 4, 100, 60), "WeaponStorage".Translate()); x += 80; if (WorldComp.HasStorages() && GUI.Button(new Rect(x, y, 30, 30), previousTexture)) { this.NextWeaponStorage(-1); } x += 30; label = (this.weaponStorage != null) ? this.weaponStorage.Label : ""; if (Widgets.ButtonText(new Rect(x, y, 400, 30), label)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (var ws in WorldComp.GetWeaponStorages()) { options.Add(new FloatMenuOption(ws.Label, delegate { this.weaponStorage = ws; this.RebuildPossibleWeapons(); }, MenuOptionPriority.Default, null, null, 0f, null, null)); } Find.WindowStack.Add(new FloatMenu(options)); } x += 400; if (WorldComp.HasStorages() && GUI.Button(new Rect(x, y, 30, 30), nextTexture)) { this.NextWeaponStorage(1); } x += 40; #endregion y += 40; Widgets.Label(new Rect(0, y + 4, 70, 30), "WeaponStorage.Search".Translate()); this.textBuffer = Widgets.TextField(new Rect(80, y, 200, 30), this.textBuffer); y += 40; const int HEIGHT = 30; const int BUFFER = 2; float width = inRect.width - 100; scrollPosition = GUI.BeginScrollView(new Rect(40, y, width, inRect.height - y - 121), scrollPosition, new Rect(0, 0, width - 16, this.PreviousY)); x = y = 0; if (this.PossibleWeapons != null) { ThingWithComps weapon; for (int i = 0; i < this.PossibleWeapons.Count; ++i) { x = 0; weapon = this.PossibleWeapons[i]; bool isChecked = false; if (this.assignedWeapons != null && this.weaponStorage != null) { isChecked = this.IsAssignedWeapon(i); if (!isChecked && !this.IncludeWeapon(weapon)) { continue; } bool backup = isChecked; Widgets.Checkbox(x, y, ref isChecked, 20); x += 20 + BUFFER; if (isChecked != backup) { if (this.IsAssignedWeapon(i)) { if (this.assignedWeapons.Pawn.equipment.Primary == weapon) { this.assignedWeapons.Pawn.equipment.Remove(weapon); if (this.assignedWeapons.Pawn.jobs.curJob.def == JobDefOf.Hunt) { this.assignedWeapons.Pawn.jobs.StopAll(); } } if (this.assignedWeapons.Remove(weapon)) { if (this.weaponStorage == null || (!this.weaponStorage.AddWeapon(weapon) && !WorldComp.Add(weapon))) { BuildingUtil.DropSingleThing(weapon, this.assignedWeapons.Pawn.Position, this.assignedWeapons.Pawn.Map); } } else { Log.Error("Unable to remove weapon " + weapon); } } else { if (this.weaponStorage != null && this.weaponStorage.RemoveNoDrop(weapon)) { this.assignedWeapons.Add(weapon); } else { Log.Error("Unable to remove weapon " + weapon); } } this.RebuildPossibleWeapons(); break; } } if (!isChecked && !this.IncludeWeapon(weapon)) { continue; } Widgets.ThingIcon(new Rect(x, y, HEIGHT, HEIGHT), weapon); x += HEIGHT + BUFFER; if (Widgets.InfoCardButton(x, y, weapon)) { Find.WindowStack.Add(new Dialog_InfoCard(weapon)); } x += HEIGHT + BUFFER; Widgets.Label(new Rect(x, y, 250, HEIGHT), weapon.Label); x += 250 + BUFFER; if (this.weaponStorage != null && Widgets.ButtonImage(new Rect(width - 16 - HEIGHT, y, 20, 20), DropTexture)) { if (this.IsAssignedWeapon(i)) { if (!this.assignedWeapons.Remove(weapon)) { Log.Error("Unable to drop assigned weapon"); } } else { if (this.weaponStorage == null || !this.weaponStorage.Remove(weapon)) { Log.Error("Unable to remove weapon " + weapon); } } this.RebuildPossibleWeapons(); break; } var biocodableComp = weapon.GetComp <CompBiocodable>(); if (biocodableComp?.CodedPawn != null) { y += HEIGHT - 4; Widgets.Label(new Rect(x - 250 - BUFFER, y, 250, 20), biocodableComp.CompInspectStringExtra()); y += 4; } this.PossibleWeapons[i] = weapon; y += HEIGHT + BUFFER; } } else { #if TRACE if (i > 600) { Log.Warning("WeaponStorage DoWindowContents: Display non-checkbox weapons. Count: " + this.weaponStorage.Count); } #endif if (this.weaponStorage != null) { foreach (ThingWithComps t in this.weaponStorage.GetWeapons(false)) { #if TRACE if (i > 600) { Log.Warning("-" + t.Label); } #endif //if (!IncludeWeapon(t)) // continue; if (!this.IncludeWeapon(t)) { continue; } x = 34; Widgets.ThingIcon(new Rect(x, y, HEIGHT, HEIGHT), t); x += HEIGHT + BUFFER; if (Widgets.InfoCardButton(x, y, t)) { Find.WindowStack.Add(new Dialog_InfoCard(t)); } x += HEIGHT + BUFFER; Widgets.Label(new Rect(x, y, 250, HEIGHT), t.Label); x += 250 + BUFFER; if (Widgets.ButtonImage(new Rect(x + 100, y, 20, 20), DropTexture)) { this.weaponStorage.Remove(t); break; } y += HEIGHT + BUFFER; } foreach (ThingWithComps t in this.weaponStorage.GetBioEncodedWeapons()) { #if TRACE if (i > 600) { Log.Warning("-" + t.Label); } #endif //if (!IncludeWeapon(t)) // continue; x = 34; Widgets.ThingIcon(new Rect(x, y, HEIGHT, HEIGHT), t); x += HEIGHT + BUFFER; if (Widgets.InfoCardButton(x, y, t)) { Find.WindowStack.Add(new Dialog_InfoCard(t)); } x += HEIGHT + BUFFER; Widgets.Label(new Rect(x, y, 250, HEIGHT), t.Label); x += 250 + BUFFER; if (Widgets.ButtonImage(new Rect(x + 100, y, 20, 20), DropTexture)) { this.weaponStorage.Remove(t); break; } var biocodableComp = t.GetComp <CompBiocodable>(); if (biocodableComp?.CodedPawn != null) { y += HEIGHT - 4; Widgets.Label(new Rect(x - 250 - BUFFER, y, 250, 20), biocodableComp.CompInspectStringExtra()); y += 4; } y += HEIGHT + BUFFER; } } } GUI.EndScrollView(); this.PreviousY = y; } catch (Exception e) { String msg = this.GetType().Name + " closed due to: " + e.GetType().Name + " " + e.Message; Log.Error(msg); Messages.Message(msg, MessageTypeDefOf.NegativeEvent); base.Close(); } finally { Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; } }