public override void Begin(Rect rect)
        {
            currentListing = this;
            Rect viewRect = new Rect(0, 0, rect.width - closeButtonSize.x, CurHeight);

            Widgets.BeginScrollView(rect, ref this.scrollPosition, viewRect, true);
            Rect rect2 = new Rect(0, 0, viewRect.width, CurHeight);

            base.Begin(rect2);
        }
Esempio n. 2
0
        private void SetupListing(Building_Shelf shelf)
        {
            TreeNode_UIOption advancedStockingRootNode = new TreeNode_UIOption("AdvancedStocking.Label".Translate());

            (new TreeNode_UIOption_Checkbox("InRackMode.Label".Translate(),
                                            () => shelf.InRackMode, b => shelf.InRackMode = b, "InRackMode.ToolTip".Translate()))
            .AddAsChildTo(advancedStockingRootNode);

            (new TreeNode_UIOption_Checkbox("InPriorityCyclingMode_label".Translate(),
                                            () => shelf.InPriorityCyclingMode, b => shelf.InPriorityCyclingMode = b, "InPriorityCyclingMode_tooltip".Translate(), false))
            .AddAsChildTo(advancedStockingRootNode);
            //			advancedStockingRootNode.children.Add (new TreeNode_UIOptionCheckbox ("InSingleThingMode_label".Translate(),
            //				() => shelf.InSingleThingMode, b => shelf.InSingleThingMode = b, "Testing", false, () => shelf.InStockingMode));
            (new TreeNode_UIOption_Checkbox("InForbiddenMode_label".Translate(),
                                            () => shelf.InForbiddenMode, b => shelf.InForbiddenMode = b, "InForbiddenMode_tooltip".Translate(), false))
            .AddAsChildTo(advancedStockingRootNode);

            (new TreeNode_UIOption_Checkbox("AutoOrganizeAfterFilling_label".Translate(),
                                            () => shelf.PawnShouldOrganizeAfterFilling, b => shelf.PawnShouldOrganizeAfterFilling = b, "AutoOrganizeAfterFilling_tooltip".Translate(),
                                            false))
            .AddAsChildTo(advancedStockingRootNode);
            TreeNode_UIOption prioritiesSubtree = new TreeNode_UIOption("StockJobPriorities_label".Translate(), "StockJobPriorities_tooltip".Translate());

            prioritiesSubtree.AddAsChildTo(advancedStockingRootNode);

            (new TreeNode_UIOption_EnumMenuButton <StockingPriority>("Fill_Empty_Stock_Priority".Translate(),
                                                                     () => Enum.GetName(typeof(StockingPriority), shelf.FillEmptyStockPriority).Translate(),
                                                                     p => shelf.FillEmptyStockPriority = p,
                                                                     null, ITab_Stock.PriorityButtonWidth, "Fill_Empty_Stock_Priority_Tooltip".Translate(), false))
            .AddAsChildTo(prioritiesSubtree);
            (new TreeNode_UIOption_EnumMenuButton <StockingPriority>("Organize_Stock_Priority".Translate(),
                                                                     () => Enum.GetName(typeof(StockingPriority), shelf.OrganizeStockPriority).Translate(),
                                                                     p => shelf.OrganizeStockPriority = p,
                                                                     null, ITab_Stock.PriorityButtonWidth, "Organize_Stock_Priority_Tooltip".Translate(), false))
            .AddAsChildTo(prioritiesSubtree);

            TreeNode_UIOption stockingLimitsRootNode = new TreeNode_UIOption("StockingLimits.Label".Translate());

            if (shelf.MaxOverlayLimit > 1)
            {
                (new TreeNode_UIOption_Slider("OverlayLimit.Label".Translate(shelf.CurrentOverlaysUsed, shelf.MaxOverlayLimit)
                                              , valGetter: () => (float)shelf.OverlayLimit
                                              , valSetter: val => shelf.OverlayLimit = (int)val
                                              , minGetter: () => shelf.CurrentOverlaysUsed
                                              , maxGetter: () => shelf.MaxOverlayLimit
                                              , roundTo: 1f
                                              , toolTip: "OverlayLimit.ToolTip".Translate()))
                .AddAsChildTo(stockingLimitsRootNode);
            }

            IEnumerable <ThingDef> thingDefsToDisplay = null;

            if (shelf.settings.filter.AllowedDefCount <= Building_Shelf.MAX_UNHELD_STACKLIMITS_TO_DISPLAY)
            {
                thingDefsToDisplay = shelf.settings.filter.AllowedThingDefs;
            }
            else
            {
                thingDefsToDisplay = shelf.slotGroup.HeldThings.Select(thing => thing.def).Distinct();
            }

            foreach (var thingDef in thingDefsToDisplay)
            {
                (new TreeNode_UIOption_Slider(() => "StackLimit.Label".Translate(thingDef.LabelCap, shelf.GetMaxStackLimit(thingDef))
                                              , valGetter: () => (float)shelf.GetStackLimit(thingDef)
                                              , valSetter: value => shelf.SetStackLimit(thingDef, (int)value)
                                              , minGetter: () => 0f
                                              , maxGetter: () => shelf.GetMaxStackLimit(thingDef)
                                              , roundTo: 1f
                                              , toolTip: "StackLimit.ToolTip".Translate()))
                .AddAsChildTo(stockingLimitsRootNode);
            }

            if (stockingLimitsRootNode.children.NullOrEmpty())
            {
                stockingLimitsRootNode.label = "StockingLimits.Label.NoChildren".Translate();
            }

            Action <TreeNode, TreeNode> configureNodeOpenings = null;
            FieldInfo openBitsField = typeof(Verse.TreeNode).GetField("openBits", BindingFlags.Instance | BindingFlags.NonPublic);

            configureNodeOpenings = delegate(TreeNode oldNode, TreeNode newNode) {
                openBitsField.SetValue(newNode, openBitsField.GetValue(oldNode));
                IEnumerator <TreeNode> oldNodeEnum = oldNode.children?.GetEnumerator() ?? Enumerable.Empty <TreeNode>().GetEnumerator();
                IEnumerator <TreeNode> newNodeEnum = newNode.children?.GetEnumerator() ?? Enumerable.Empty <TreeNode>().GetEnumerator();
                while (oldNodeEnum.MoveNext() && newNodeEnum.MoveNext())
                {
                    configureNodeOpenings(oldNodeEnum.Current, newNodeEnum.Current);
                }
            };

            var newListing = new Listing_TreeUIOption(new List <TreeNode_UIOption>()
            {
                stockingLimitsRootNode
                , advancedStockingRootNode
            });
            int maxOptionIndex = Math.Min(this.listing?.RootOptions.Count ?? 0, newListing.RootOptions.Count);

            for (int i = 0; i < maxOptionIndex; i++)
            {
                configureNodeOpenings(this.listing.RootOptions[i], newListing.RootOptions[i]);
            }

            this.displayingFor = shelf;
            this.listing       = newListing;

            RebuildReservationOptions();    //Perform after nodeOpening configuration as reservations will change
        }