Exemplo n.º 1
0
        public static void Postfix(ref Rect rect)
        {
            ITab_Storage tab = ITab_StorageFillTabsPatcher.currentTab;

            if (tab == null)
            {
                return;
            }

            IStoreSettingsParent storeSettingsParent = (IStoreSettingsParent)typeof(ITab_Storage).GetProperty("SelStoreSettingsParent", BindingFlags.NonPublic | BindingFlags.Instance).GetGetMethod(true).Invoke(tab, new object[0]);
            StorageSettings      settings            = storeSettingsParent.GetStoreSettings();

            int  limit    = Limits.GetLimit(settings);
            bool hasLimit = limit != -1;

            Widgets.CheckboxLabeled(new Rect(rect.xMin, rect.yMin - 24f - 3f - 32f, rect.width / 2, 24f), "Total stack limit", ref hasLimit);

            if (hasLimit)
            {
                if (oldSettings != settings)
                {
                    buffer = limit.ToString();
                }

                Widgets.TextFieldNumeric <int>(new Rect(rect.xMin + (rect.width / 2) + 60f, rect.yMin - 24f - 3f - 32f, rect.width / 2 - 60f, 24f), ref limit, ref buffer, 0, max);
            }

            Limits.SetLimit(settings, hasLimit ? limit : -1);

            oldSettings = settings;
        }
Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 3
0
        public static void Before_ITab_Storage_FillTab(ITab_Storage __instance)
        {
            if (ReferenceEquals(__instance.GetType().Assembly, typeof(ITab_Storage).Assembly))
            {
                // only show hysteresis option for non derived (non-custom) storage(s)
                HaulingHysteresis_InjectControls.showHysteresisCount++;

                IStoreSettingsParent selStoreSettingsParent = GetSelStoreSettingsParent(__instance);
                HaulingHysteresis_InjectControls.SettingsQueue.Enqueue(selStoreSettingsParent.GetStoreSettings());
            }
        }
Exemplo n.º 4
0
        public static void Prefix(ref Rect rect)
        {
            ITab_Storage tab = ITab_StorageFillTabsPatcher.currentTab;

            if (tab == null)
            {
                return;
            }

            rect.yMin += 32f;
        }
Exemplo n.º 5
0
        public static void drawFilterButton(ITab_Storage __instance, Vector2 ___WinSize)
        {
            // TabRect.y is top of window
            Rect        TabRect    = Traverse.Create(__instance).Property("TabRect").GetValue <Rect>();
            ThingFilter filter     = Traverse.Create(__instance).Property("SelStoreSettingsParent").GetValue <IStoreSettingsParent>().GetStoreSettings().filter;
            var         buttonSize = new Vector2(80f, 29f);

            if (Widgets.ButtonText(new Rect(180, 10, buttonSize.x, buttonSize.y), "Filter".Translate() + ">>"))
            {
                MaterialFilterWindow w = Find.WindowStack.WindowOfType <MaterialFilterWindow>();
                if (w != null)
                {
                    w.Close();
                }
                else
                {
                    Find.WindowStack.Add(new MaterialFilterWindow(filter, TabRect.y, ___WinSize.x, WindowLayer.GameUI));
                }
            }
        }
Exemplo n.º 6
0
        public static void DrawKanbanSettings(ITab_Storage tab)
        {
            IHaulDestination haulDestination = SelStoreInfo.GetValue(tab, null) as IHaulDestination;

            if (haulDestination == null)
            {
                return;
            }
            StorageSettings settings = haulDestination.GetStoreSettings();

            if (settings == null)
            {
                return;
            }

            //ITab_Storage.WinSize = 300
            float buttonMargin = ITab_Storage_TopAreaHeight_Patch.extraHeight + 4;
            Rect  rect         = new Rect(0f, (float)GetTopAreaHeight.Invoke(tab, new object[] { }) - ITab_Storage_TopAreaHeight_Patch.extraHeight - 2, 280, ITab_Storage_TopAreaHeight_Patch.extraHeight);

            // if Stockpile Ranking is installed, scootch these widgets up so it doesn't overlap
            // https://github.com/alextd/RimWorld-StockpileRanking/blob/master/Source/RankSelection.cs#L18
            if (KanbanStockpileLoader.IsStockpileRankingLoaded)
            {
                rect.y -= 26f;
            }

            rect.x     += buttonMargin;
            rect.width -= buttonMargin * 3;
            Text.Font   = GameFont.Small;

            KanbanSettings ks, tmp;

            ks      = State.Get(settings.owner.ToString());
            tmp.srt = ks.srt;
            tmp.ssl = ks.ssl;

            string stackRefillThresholdLabel = "KS.StackRefillThreshold".Translate(ks.srt);

            string similarStackLimitLabel;

            if (ks.ssl > 0)
            {
                similarStackLimitLabel = "KS.SimilarStackLimit".Translate(ks.ssl);
            }
            else
            {
                similarStackLimitLabel = "KS.SimilarStackLimitOff".Translate();
            }

            //Stack Refill Threshold Slider
            tmp.srt = (int)Widgets.HorizontalSlider(new Rect(0f, rect.yMin + 10f, 150f, 15f),
                                                    ks.srt, 0f, 100f, false, stackRefillThresholdLabel, null, null, 1f);

            //Similar Stack Limit Slider
            tmp.ssl = (int)Widgets.HorizontalSlider(new Rect(155, rect.yMin + 10f, 125f, 15f),
                                                    ks.ssl, 0f, 8f, false, similarStackLimitLabel, null, null, 1f);


            if ((ks.srt != tmp.srt) ||
                (ks.ssl != tmp.ssl))
            {
                // Accept slider changes no faster than 4Hz (250ms) to prevent spamming multiplayer sync lag
                DateTime curTime = DateTime.Now;
                if ((curTime - lastUpdateTime).TotalMilliseconds < 250)
                {
                    return;
                }
                lastUpdateTime = curTime;

                KSLog.Message("[KanbanStockpile] Changed Stack Refill Threshold for settings with haulDestination named: " + settings.owner.ToString());
                ks.srt = tmp.srt;
                ks.ssl = tmp.ssl;
                State.Set(settings.owner.ToString(), ks);
            }
        }
Exemplo n.º 7
0
        public static void FillTab(ITab_Storage tab)
        {
            IStoreSettingsParent storeSettingsParent = (IStoreSettingsParent)ITab_Storage_Detour.SelStoreSettingsParent.GetValue(tab, null);

            Debug.Log(storeSettingsParent);
            StorageSettings settings = storeSettingsParent.GetStoreSettings();
            Rect            position = new Rect(0f, 0f, ITab_Storage_Detour.WinSize.x, ITab_Storage_Detour.WinSize.y).ContractedBy(10f);

            GUI.BeginGroup(position);
            Text.Font = GameFont.Small;
            Rect rect = new Rect(0f, 0f, 160f, 29f);

            if (Widgets.ButtonText(rect, "Priority".Translate() + ": " + settings.Priority.Label(), true, false, true))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (object current in Enum.GetValues(typeof(StoragePriority)))
                {
                    if ((StoragePriority)current > StoragePriority.Unstored)
                    {
                        StoragePriority localPr = (StoragePriority)current;
                        list.Add(new FloatMenuOption(localPr.Label().CapitalizeFirst(), delegate
                        {
                            settings.Priority = localPr;
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                }
                Find.WindowStack.Add(new FloatMenu(list));
            }
            bool   arg_2B9_0 = Widgets.ButtonImage(new Rect(position.width - 33f, 7.5f, 14f, 14f), Widgets.CheckboxOffTex);
            Rect   arg_204_0 = new Rect(165f, 0f, position.width - 160f - 20f, 29f);
            string text      = (ITab_Storage_Detour.searchText != string.Empty || ITab_Storage_Detour.isFocused) ? ITab_Storage_Detour.searchText : "SearchLabel".Translate();
            bool   flag      = Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape;
            bool   flag2     = !Mouse.IsOver(arg_204_0) && Event.current.type == EventType.MouseDown;

            if (!ITab_Storage_Detour.isFocused)
            {
                GUI.color = new Color(1f, 1f, 1f, 0.6f);
            }
            GUI.SetNextControlName("StorageSearchInput");
            string text2 = Widgets.TextField(arg_204_0, text);

            GUI.color = Color.white;
            if (ITab_Storage_Detour.isFocused)
            {
                ITab_Storage_Detour.searchText = text2;
            }
            if ((GUI.GetNameOfFocusedControl() == "StorageSearchInput" || ITab_Storage_Detour.isFocused) && (flag | flag2))
            {
                GUIUtility.keyboardControl    = 0;
                ITab_Storage_Detour.isFocused = false;
            }
            else if (GUI.GetNameOfFocusedControl() == "StorageSearchInput" && !ITab_Storage_Detour.isFocused)
            {
                ITab_Storage_Detour.isFocused = true;
            }
            if (arg_2B9_0)
            {
                ITab_Storage_Detour.searchText = string.Empty;
            }
            UIHighlighter.HighlightOpportunity(rect, "StoragePriority");
            ThingFilter parentFilter = null;

            if (storeSettingsParent.GetParentStoreSettings() != null)
            {
                parentFilter = storeSettingsParent.GetParentStoreSettings().filter;
            }
            Rect    arg_334_0 = new Rect(0f, 35f, position.width, position.height - 70f);
            Vector2 vector    = (Vector2)ITab_Storage_Detour.ScrollPosition.GetValue(tab);

            HelperThingFilterUI.DoThingFilterConfigWindow(arg_334_0, ref vector, settings.filter, parentFilter, 8, null, null, ITab_Storage_Detour.searchText);
            ITab_Storage_Detour.ScrollPosition.SetValue(tab, vector);
            Rect rect2 = new Rect(0f, position.height - 30f, position.width, 30f);
            StorageSettings_Hysteresis storageSettings_Hysteresis = StorageSettings_Mapping.Get(settings);

            if (storageSettings_Hysteresis == null)
            {
                storageSettings_Hysteresis = new StorageSettings_Hysteresis();
            }
            storageSettings_Hysteresis.FillPercent = Widgets.HorizontalSlider(rect2.LeftPart(0.8f), storageSettings_Hysteresis.FillPercent, 0f, 100f, false, "Refill cells less then", null, null, -1f);
            Widgets.Label(rect2.RightPart(0.2f), storageSettings_Hysteresis.FillPercent.ToString("N0") + "%");
            StorageSettings_Mapping.Set(settings, storageSettings_Hysteresis);
            PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.StorageTab, KnowledgeAmount.FrameDisplayed);
            GUI.EndGroup();
        }
Exemplo n.º 8
0
        public static void DrawRanking(ITab_Storage tab)
        {
            IHaulDestination haulDestination = SelStoreInfo.GetValue(tab, null) as IHaulDestination;

            if (haulDestination == null)
            {
                return;
            }
            StorageSettings settings = haulDestination.GetStoreSettings();

            if (settings == null)
            {
                return;
            }

            var comp  = RankComp.Get();
            int count = comp.CountExtraFilters(settings);

            if (curRank > count)
            {
                curRank = count;
            }

            float buttonMargin = TopAreaHeight.rankHeight + 4;

            //ITab_Storage.WinSize = 300
            Rect rect = new Rect(0f, (float)GetTopAreaHeight.Invoke(tab, new object[] { }) - TopAreaHeight.rankHeight - 2, 280, TopAreaHeight.rankHeight);

            //Left Arrow
            Rect leftButtonRect = rect.LeftPartPixels(TopAreaHeight.rankHeight);

            if (curRank > 0)
            {
                if (Widgets.ButtonImage(leftButtonRect, Tex.ArrowLeft))
                {
                    SoundDefOf.Tick_Tiny.PlayOneShotOnCamera();
                    curRank--;
                }
            }

            //Right Arrow
            Rect rightButtonRect = rect.RightPartPixels(TopAreaHeight.rankHeight);

            if (curRank == count)
            {
                if (Widgets.ButtonImage(rightButtonRect, Tex.Plus))
                {
                    SoundDefOf.Click.PlayOneShotOnCamera();
                    comp.AddFilter(settings);
                    curRank++;
                }
            }
            else
            {
                if (Widgets.ButtonImage(rightButtonRect, Tex.ArrowRight))
                {
                    SoundDefOf.Tick_Tiny.PlayOneShotOnCamera();
                    curRank++;
                }
            }

            //Delete rank button
            rightButtonRect.x -= buttonMargin;
            if (curRank > 0)
            {
                if (Widgets.ButtonImage(rightButtonRect, Tex.DeleteX))
                {
                    SoundDefOf.Crunch.PlayOneShotOnCamera();
                    comp.RemoveFilter(settings, curRank--);
                }
            }

            //Label
            rect.x     += buttonMargin;
            rect.width -= buttonMargin * 3;
            Text.Font   = GameFont.Small;
            if (count == 0)
            {
                Widgets.Label(rect, "TD.AddFilter".Translate());
            }
            else
            {
                Widgets.Label(rect, "TD.RankNum".Translate(curRank + 1));
            }
        }
Exemplo n.º 9
0
 public static void Postfix(ITab_Storage __instance)
 {
     //AccessTools.Field(typeof(ITab_Storage), "size").SetValue(__instance, LazySettingsManager.WinSize);
 }
Exemplo n.º 10
0
 public static void Postfix(ITab_Storage __instance)
 {
     ThingFilterPatch.thingFilterCallerStack.Pop();
 }
Exemplo n.º 11
0
 public static void Prefix(ITab_Storage __instance)
 {
     ThingFilterPatch.thingFilterCallerStack.Push(__instance.GetType().GetMethod("get_SelStoreSettingsParent", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(__instance, null));
 }
Exemplo n.º 12
0
 public static void Postfix()
 {
     currentTab = null;
 }
Exemplo n.º 13
0
 public static void Prefix(ITab_Storage __instance)
 {
     currentTab = __instance;
 }
Exemplo n.º 14
0
 public static void Prefix(ITab_Storage __instance)
 {
     visible = true;
     Log.Warning(__instance.ToString());
     lastITab_Storage = __instance;
 }