public static bool Create(Vector3 clickPosition, Pawn pawn) { var c = IntVec3.FromVector3(clickPosition); if (!pawn.IsColonistPlayerControlled) { return(false); } if (pawn.Downed) { Messages.Message("IsIncapped".Translate((NamedArgument)pawn.LabelCap, (NamedArgument)pawn), pawn, MessageTypeDefOf.RejectInput, false); } else { if (pawn.Map != Find.CurrentMap) { return(false); } } var buildingList = StaticHelper.GetBuildings(c, pawn.Map); if (buildingList.NullOrEmpty()) { return(true); } ThingComp target = null; foreach (var building in buildingList) { target = building.AllComps.Find(x => x is IHoldMultipleThings.IHoldMultipleThings); } if (target == null) { return(true); } var thingList = new List <Thing>(c.GetThingList(pawn.Map)); if (thingList.NullOrEmpty()) { var cells = target.parent.GetSlotGroup().CellsList; foreach (var cell in cells) { thingList.AddRange(cell.GetThingList(pawn.Map)); } } Find.WindowStack.Add(new DSGUI_ListModal(pawn, thingList, clickPosition)); return(false); }
public static bool Create(Vector3 clickPosition, Pawn pawn) { var c = IntVec3.FromVector3(clickPosition); if (!pawn.IsColonistPlayerControlled || pawn.Downed || pawn.Map != Find.CurrentMap) { Log.Message("[DSGUI] Pawn is not player controlled, downed, or on the current map."); return(true); } var buildingList = StaticHelper.GetBuildings(c, pawn.Map).ToList(); // var building = c.GetFirstBuilding(pawn.Map); if (buildingList.EnumerableNullOrEmpty()) { Log.Message("[DSGUI] Building List is empty."); return(true); } var storageUnit = buildingList.Find(building => building.AllComps.Find(x => x is IHoldMultipleThings.IHoldMultipleThings) != null); if (storageUnit == null || storageUnit.DestroyedOrNull()) { Log.Message("[DSGUI] Found no valid target."); return(true); } // var thingList = new List<Thing>(c.GetThingList(pawn.Map)); List <Thing> thingList; if (DSGUIMain.modSimplyLoaded && storageUnit.def.modContentPack.PackageId == "jangodsoul.simplestorage") { var storageComp = (CompDeepStorage)storageUnit.AllComps.Find(x => x is CompDeepStorage); thingList = new List <Thing>(storageComp.getContentsHeader(out _, out _)); } else { thingList = new List <Thing>(c.GetThingList(pawn.Map)); } thingList.RemoveAll(t => t.def.category != ThingCategory.Item || t is Mote); if (thingList.EnumerableNullOrEmpty()) { Log.Message("[DSGUI] Thing List is empty."); return(true); } Find.WindowStack.Add(new DSGUI_ListModal(pawn, thingList, clickPosition)); return(false); }
public static bool Create(Vector3 clickPosition, Pawn pawn, bool ordersOnly = false) { List <Thing> thingList, tileThingList; var c = IntVec3.FromVector3(clickPosition); if (!pawn.IsColonistPlayerControlled || pawn.Downed || pawn.Map != Find.CurrentMap) { Log.Message("[DSGUI] Pawn is not player controlled, downed, or on the current map. Handing execution to vanilla again."); return(true); } var buildingList = StaticHelper.GetBuildings(c, pawn.Map).ToList(); if (buildingList.OptimizedNullOrEmpty()) { Log.Message("[DSGUI] Building List is empty. Handing execution to vanilla again."); return(true); } var storageUnit = buildingList.Find(building => building.AllComps.Find(x => x is IHoldMultipleThings.IHoldMultipleThings) != null); if (storageUnit == null || storageUnit.DestroyedOrNull()) { Log.Message("[DSGUI] Found no valid target. Handing execution to vanilla again."); return(true); } if (DSGUIMain.ModSimpleLoaded && storageUnit.def.modContentPack.PackageId == DSGUIMain.PidSimpleStorage || DSGUIMain.ModSimpleRefLoaded && storageUnit.def.modContentPack.PackageId == DSGUIMain.PidSimpleRefStorage) { var storageComp = (CompDeepStorage)storageUnit.AllComps.Find(x => x is CompDeepStorage); thingList = new List <Thing>(storageComp.getContentsHeader(out _, out _)); } else { thingList = new List <Thing>(c.GetThingList(pawn.Map)); } if (thingList.OptimizedNullOrEmpty()) { Log.Message("[DSGUI] Thing List is empty. Handing execution to vanilla again."); return(true); } if (ordersOnly) { thingList = new List <Thing>(c.GetThingList(pawn.Map)); tileThingList = thingList.Where(t => t.def.category != ThingCategory.Item).ToList(); // TODO: Move the entire ThingList trickery into its own function var index = pawn.Map.cellIndices.CellToIndex(c); var listArray = (List <Thing>[])ThingListTG.GetValue(pawn.Map.thingGrid); var origList = new List <Thing>(listArray[index]); listArray[index] = new List <Thing>(tileThingList); var orders = (List <FloatMenuOption>)CAF.Invoke(null, new object[] { clickPosition, pawn }); listArray[index] = origList; if (orders.Count <= 0) { return(true); } Elements.TryMakeFloatMenu(orders, "DSGUI_List_Tile".TranslateSimple()); return(false); } tileThingList = thingList.Where(t => t.def.category != ThingCategory.Item).ToList(); thingList.RemoveAll(t => t.def.category != ThingCategory.Item || t is Mote); Find.WindowStack.Add(new DSGUI_ListModal(pawn, thingList, clickPosition, storageUnit, tileThingList)); return(false); }