Пример #1
0
        private static void NoStorageBlockersIn_Lazy_PostFix(IntVec3 c, Map map, Thing thing, ref bool __result)
        {
            Zone_Stockpile generic = map.zoneManager.ZoneAt(c) as Zone_Stockpile;

            if (__result && generic != null)
            {
                LazySettings stockPile = LazySettingsManager.AddOrGetSettings(generic.settings);
                if (stockPile == null)
                {
                    //Log.Error("The stockpile settings are not Lazy. Will not utilize lazy settings at all.");
                    return;
                }
                if (stockPile.type == LazyType.Cache)
                {
                    List <Thing> list = map.thingGrid.ThingsListAt(c);
                    for (int i = 0; i < list.Count; i++)
                    {
                        Thing potentialBlocker = list[i];
                        if (potentialBlocker.def.EverStorable(false) && potentialBlocker.Ratio() > stockPile.CacheThreshold)
                        {
                            __result = false;
                            return;
                        }
                    }
                }
                else if (stockPile.type == LazyType.Buffer)
                {
                    //if the thing we are trying to place is trying to go into the same stockpile that it is already in, and the stockpile is a lazy buffer, do not let it place itself back in
                    //this should only be reached because the buffer is trying to get rid of the stack (greater than the threshold)
                    LazySettings thingStock = LazySettingsManager.AddOrGetSettings(thing.GetSlotGroup()?.Settings);
                    __result = stockPile != thingStock;
                }
            }
        }
Пример #2
0
        public static void ITab_Storage_Patch(ITab_Storage instance, StorageSettings settings)
        {
            //Log.Message("ITab_Storage_Patch was called");
            //if (!logged)
            //{
            //    Log.Message($"ITab_Storage instance == null: {instance == null}");
            //    Log.Message($"StorageSettings settings == null: {settings == null}");
            //    logged = true;
            //}
            object  o    = AccessTools.Field(typeof(ITab_Storage), "size").GetValue(instance);
            Vector2 size = (Vector2)o;
            //Log.Message($"[NOTICE] ITab_Storage size -> x: {size.x} y: {size.y}");
            Vector2 WinSize = new Vector2(300f, 575f);

            Text.Font = GameFont.Small;
            Rect         rect      = new Rect(0f, 35f, 160f, 35f - 6f);
            LazySettings stockpile = LazySettingsManager.AddOrGetSettings(settings);

            if (stockpile == null)
            {
                Log.ErrorOnce(string.Format($"Lazy Tab Error: Attempted to load settings as LazySettings, when it was of type {settings.GetType()}"), 0);
            }
            else
            {
                //Type Button
                if (Widgets.ButtonText(rect, "Type: " + stockpile.type.ToString(), true, false, true))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    foreach (LazyType type in Enum.GetValues(typeof(LazyType)))
                    {
                        LazyType localTy = type;
                        list.Add(new FloatMenuOption(type.ToString(), delegate
                        {
                            stockpile.type = type;
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                        Find.WindowStack.Add(new FloatMenu(list));
                    }
                }
                //Cache Threshold Slider
                if (stockpile.type == LazyType.Cache)
                {
                    Rect             sliderRect = new Rect(0f, 66f, WinSize.x - 20f, 70f);
                    Listing_Standard stand      = new Listing_Standard();
                    stand.Begin(sliderRect);
                    stand.Label(string.Format($"Cache Threshold: {stockpile.CacheThreshold * 100:0}%"));
                    stockpile.CacheThreshold = stand.Slider(stockpile.CacheThreshold, 0f, 0.75f);
                    stand.End();
                }
                //Buffer Threshold Slider
                else if (stockpile.type == LazyType.Buffer)
                {
                    Rect             sliderRect = new Rect(0f, 66f, WinSize.x - 20f, 70f);
                    Listing_Standard stand      = new Listing_Standard();
                    stand.Begin(sliderRect);
                    stand.Label(string.Format($"Buffer Threshold: {stockpile.BufferThreshold * 100:0}%"));
                    stockpile.BufferThreshold = stand.Slider(stockpile.BufferThreshold, 0.25f, 1f);
                    stand.End();
                }
            }
        }
Пример #3
0
 public static void Postfix(StorageSettings __instance)
 {
     LazySettings settings = LazySettingsManager.AddOrGetSettings(__instance);
     {
         Scribe_Values.Look(ref settings.type, "settings.type", LazyType.Normal);
         Scribe_Values.Look(ref settings.CacheThreshold, "settings.CacheThreshold", LazySettings.DefaultCache);
         Scribe_Values.Look(ref settings.BufferThreshold, "settings.BufferThreshold", LazySettings.DefaultBuffer);
     }
 }
Пример #4
0
        public static float VariableTabHeight(StorageSettings settings)
        {
            LazySettings lazySett  = LazySettingsManager.AddOrGetSettings(settings);
            float        baseValue = 35f;

            if (lazySett?.type != LazyType.Normal)
            {
                baseValue += 40f;
            }
            return(baseValue);
        }
Пример #5
0
        public static void TryFindBestBetterStoreCellFor_Prefix(Thing t, ref StoragePriority currentPriority)
        {
            LazySettings l = LazySettingsManager.AddOrGetSettings(t.GetSlotGroup()?.Settings);

            if (l != null)
            {
                if (l.type == LazyType.Buffer)
                {
                    if (t.Ratio() >= l.BufferThreshold)
                    {
                        currentPriority = StoragePriority.Unstored; //Have the method consider the thing to not be stored at all
                    }
                }
            }
        }
Пример #6
0
 public static void IsInValidBestStorage(Thing t, ref bool __result)
 {
     if (__result) //to prevent uneccessary work
     {
         StorageSettings test = t.GetSlotGroup()?.Settings;
         if (test != null)
         {
             LazySettings settings = LazySettingsManager.AddOrGetSettings(test);
             if (settings != null)
             {
                 __result = !(settings.type == LazyType.Buffer && t.Ratio() >= settings.BufferThreshold);
             }
         }
     }
 }
Пример #7
0
        public static void AllowedToAccept_Postfix(ref bool __result, ref StorageSettings __instance, Thing t)
        {
            if (__result)
            {
                LazySettings target = LazySettingsManager.AddOrGetSettings(__instance);

                if (target?.type == LazyType.Buffer)
                {
                    SlotGroup sourceGroup = t.GetSlotGroup();
                    if (sourceGroup == null)
                    {
                        return;
                    }
                    //if the item is targetting its own buffer and ratio is too high, IsInValidBestStorage harmony patch will take care of it
                    __result = sourceGroup.Settings == __instance;
                }
            }
        }
Пример #8
0
        protected override void FillTab()
        {
            IStoreSettingsParent selStoreSettingsParent = this.SelStoreSettingsParent;
            StorageSettings      settings = selStoreSettingsParent.GetStoreSettings();

            Rect position = new Rect(0f, 0f, ITab_Lazy.WinSize.x, ITab_Lazy.WinSize.y).ContractedBy(10f);

            GUI.BeginGroup(position);
            if (this.IsPrioritySettingVisible)
            {
                Text.Font = GameFont.Small;
                Rect rect = new Rect(0f, 0f, 160f, this.TopAreaHeight - 6f);
                if (Widgets.ButtonText(rect, "Priority".Translate() + ": " + settings.Priority.Label(), true, false, true))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    foreach (StoragePriority storagePriority in Enum.GetValues(typeof(StoragePriority)))
                    {
                        if (storagePriority != StoragePriority.Unstored)
                        {
                            StoragePriority localPr = storagePriority;
                            list.Add(new FloatMenuOption(localPr.Label().CapitalizeFirst(), delegate
                            {
                                settings.Priority = localPr;
                            }, MenuOptionPriority.Default, null, null, 0f, null, null));
                        }
                    }
                    Find.WindowStack.Add(new FloatMenu(list));
                }
                UIHighlighter.HighlightOpportunity(rect, "StoragePriority");
            }
            //Lazy button & Threshold Sliders
            {
                Text.Font = GameFont.Small;
                Rect         rect      = new Rect(0f, 35f, 160f, this.TopAreaHeight - 6f);
                LazySettings stockpile = LazySettingsManager.AddOrGetSettings(settings);
                if (stockpile == null)
                {
                    Log.Error(string.Format($"Lazy Tab Error: Attempted to load {SelObject} settings as LazySettings, when it was of type {settings.GetType()}"));
                }
                else
                {
                    //Type Button
                    if (Widgets.ButtonText(rect, "Type: " + stockpile.type.ToString(), true, false, true))
                    {
                        List <FloatMenuOption> list = new List <FloatMenuOption>();
                        foreach (LazyType type in Enum.GetValues(typeof(LazyType)))
                        {
                            LazyType localTy = type;
                            list.Add(new FloatMenuOption(type.ToString(), delegate
                            {
                                stockpile.type = type;
                            }, MenuOptionPriority.Default, null, null, 0f, null, null));
                            Find.WindowStack.Add(new FloatMenu(list));
                        }
                    }
                    //Cache Threshold Slider
                    if (stockpile.type == LazyType.Cache)
                    {
                        Rect             sliderRect = new Rect(0f, 66f, WinSize.x - 20f, 70f);
                        Listing_Standard stand      = new Listing_Standard();
                        stand.Begin(sliderRect);
                        stand.Label(string.Format($"Cache Threshold: {stockpile.CacheThreshold * 100:0}%"));
                        stockpile.CacheThreshold = stand.Slider(stockpile.CacheThreshold, 0f, 0.75f);
                        stand.End();
                    }
                    //Buffer Threshold Slider
                    else if (stockpile.type == LazyType.Buffer)
                    {
                        Rect             sliderRect = new Rect(0f, 66f, WinSize.x - 20f, 70f);
                        Listing_Standard stand      = new Listing_Standard();
                        stand.Begin(sliderRect);
                        stand.Label(string.Format($"Buffer Threshold: {stockpile.BufferThreshold * 100:0}%"));
                        stockpile.BufferThreshold = stand.Slider(stockpile.BufferThreshold, 0.25f, 1f);
                        stand.End();
                    }
                }
            }


            ThingFilter parentFilter = null;

            if (selStoreSettingsParent.GetParentStoreSettings() != null)
            {
                parentFilter = selStoreSettingsParent.GetParentStoreSettings().filter;
            }
            Rect rect2 = new Rect(0f, (this.TopAreaHeight * 3) + 5, position.width, position.height - (this.TopAreaHeight * 2));

            Bill[] first = (from b in BillUtility.GlobalBills()
                            where b is Bill_Production && b.GetStoreZone() == selStoreSettingsParent && b.recipe.WorkerCounter.CanPossiblyStoreInStockpile((Bill_Production)b, b.GetStoreZone())
                            select b).ToArray();


            ThingFilterUI.DoThingFilterConfigWindow(rect2, ref this.scrollPosition, settings.filter, parentFilter, 8, null, null, false, null, null);

            Bill[] second = (from b in BillUtility.GlobalBills()
                             where b is Bill_Production && b.GetStoreZone() == selStoreSettingsParent && b.recipe.WorkerCounter.CanPossiblyStoreInStockpile((Bill_Production)b, b.GetStoreZone())
                             select b).ToArray();

            IEnumerable <Bill> enumerable = first.Except(second);

            foreach (Bill item in enumerable)
            {
                Messages.Message("MessageBillValidationStoreZoneInsufficient".Translate(item.LabelCap, item.billStack.billGiver.LabelShort.CapitalizeFirst(), item.GetStoreZone().label), item.billStack.billGiver as Thing, MessageTypeDefOf.RejectInput, false);
            }

            PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.StorageTab, KnowledgeAmount.FrameDisplayed);
            GUI.EndGroup();
        }