public static void Postfix(Building_Storage __instance, Thing newItem)
 {
     if (__instance.TryGetComp <CompCachedDeepStorage>() is CompCachedDeepStorage comp)
     {
         Utils.Mess(Utils.DBF.Cache, $"Place {newItem.LabelCap} in {__instance.LabelCapNoCount}");
         comp.CellStorages.Add(newItem);
     }
 }
Пример #2
0
        public static void Postfix(Building_Storage __instance, Thing newItem)
        {
            CompDeepStorage cds;

            if ((cds = __instance.TryGetComp <CompDeepStorage>()) == null)
            {
                return;
            }

            /****************** Put DSU at top of list *******************/
            /*  This is important for selecting next objects?  I think?  */
            List <Thing> list = newItem.Map.thingGrid.ThingsListAt(newItem.Position);

            list.Remove(__instance);
            list.Add(__instance);

            /****************** Set display for items correctly *******************/
            /*** Clean up old "what was on top" ***/
            foreach (Thing t in list)
            {
                Utils.TopThingInDeepStorage.Remove(t);
            }

            /*** Complex meshes have a few rules for DeepStorage ***/
            if (newItem.def.drawerType != DrawerType.MapMeshOnly)
            {
                //  If they are on top, they should be drawn on top:
                if (cds.showContents)
                {
                    Utils.TopThingInDeepStorage.Add(newItem);
                }
                else // If we are not showing contents, don't draw them:
                {
                    __instance.Map.dynamicDrawManager.DeRegisterDrawable(newItem);
                }
            }

            /*** Gui overlay - remove if the DSU draws it, or if the item is invisible ***/
            if (cds.cdsProps.overlayType != GuiOverlayType.Normal || !cds.showContents)
            {
                // Remove gui overlay - this includes number of stackabe item, quality, etc
                __instance.Map.listerThings.ThingsInGroup(ThingRequestGroup.HasGUIOverlay).Remove(newItem);
            }

            if (!cds.showContents)
            {
                return;                    // anything after is for invisible items
            }
            /*** tool tip, dirt mesh, etc ***/
            __instance.Map.tooltipGiverList.Notify_ThingDespawned(newItem); // should this go with guioverlays?
            newItem.DirtyMapMesh(newItem.Map);                              // for items with a map mesh; probably unnecessary?
            // Note: not removing linker here b/c I don't think it's applicable to DS?
        }
        static void Postfix_I_Would_Like_To_Use(Building_Storage __instance, Thing newItem)
        {
            Utils.TopThingInDeepStorage.Remove(newItem);
            if (__instance.TryGetComp <CompDeepStorage>() == null)
            {
                return;
            }
            List <Thing> list = newItem.Map.thingGrid.ThingsListAt(newItem.Position);

            for (int i = list.Count - 1; i > 0; i--)
            {
                if (!list[i].def.EverStorable(false))
                {
                    continue;
                }
                Utils.TopThingInDeepStorage.Add(list[i]);
                return;
            }
        }
Пример #4
0
        protected override void FillTab()
        {
            Building_Storage storage = this.SelThing as Building_Storage;

            this.container = storage.TryGetComp <CompContainer>();
            if (container == null)
            {
                Log.Error("No CompContainer included for this Building_Storage");
                return;
            }
            List <Thing> list        = container.itemsList;
            float        fieldHeight = 30.0f;

            this.size = new Vector2(300f, 55f + container.compProps.itemsCap * fieldHeight);

            ConceptDatabase.KnowledgeDemonstrated(ConceptDefOf.PrisonerTab, KnowledgeAmount.GuiFrame);
            Text.Font = GameFont.Small;

            Rect  innerRect  = GenUI.ContractedBy(new Rect(0.0f, 0.0f, this.size.x, this.size.y), 10f);
            float innerRectX = innerRect.x;

            GUI.BeginGroup(innerRect);
            {
                Widgets.TextField(new Rect(0.0f, 0.0f, this.size.x - 40f, fieldHeight), GetTitle());

                Rect thingIconRect   = new Rect(10f, fieldHeight + 5f, 30f, fieldHeight);
                Rect thingLabelRect  = new Rect(thingIconRect.x + 35f, thingIconRect.y + 5.0f, innerRect.width - 35f, fieldHeight);
                Rect thingButtonRect = new Rect(thingIconRect.x, thingIconRect.y, innerRect.width, fieldHeight);

                //float startY = 0.0f;
                //Widgets.ListSeparator(ref startY, innerRect.width, GetTitle());

                foreach (var thing in list)
                {
                    Widgets.ThingIcon(thingIconRect, thing);
                    Widgets.Label(thingLabelRect, thing.Label);

                    if (Widgets.InvisibleButton(thingButtonRect))
                    {
                        List <FloatMenuOption> options = new List <FloatMenuOption>();
                        options.Add(new FloatMenuOption("Container_Info".Translate(), () =>
                        {
                            // NOTE ?
                            Find.WindowStack.Add(new Dialog_InfoCard(thing));
                        }));
                        options.Add(new FloatMenuOption("Container_Drop".Translate(), () =>
                        {
                            IntVec3 bestSpot = IntVec3.Invalid;
                            if (JobDriver_HaulToCell.TryFindPlaceSpotNear(storage.Position, thing, out bestSpot))
                            {
                                thing.Position = bestSpot;
                            }
                            else
                            {
                                Log.Error("No free spot for " + thing);
                            }
                        }));

                        Find.WindowStack.Add(new FloatMenu(options, "", false, false));
                    }

                    thingIconRect.y   += fieldHeight;
                    thingLabelRect.y  += fieldHeight;
                    thingButtonRect.y += fieldHeight;
                }
            }
            GUI.EndGroup();
        }