예제 #1
0
        private void DoCategory(EntityCategory node, int openMask, int indentLevel)
        {
            if (!node.DescendantThings.Any())
            {
                return;
            }
            base.OpenCloseWidget(node, indentLevel, openMask);
            base.LabelLeft(node.LabelCap, node.Description, indentLevel);
            MultiCheckboxState multiCheckboxState = this.AllowanceStateOf(node);

            if (Widgets.CheckboxMulti(new Vector2(this.LabelWidth, this.curY), multiCheckboxState, this.lineHeight))
            {
                bool allow = multiCheckboxState == MultiCheckboxState.Off;
                foreach (var thing in node.DescendantThings)
                {
                    this.filter.SetAllow(thing, allow);
                }
                foreach (var spFilter in node.catDef.DescendantSpecialEntityFilterDefs)
                {
                    this.filter.SetAllow(spFilter, allow);
                }
            }
            base.EndLine();
            if (node.IsOpen(openMask))
            {
                this.DoCurrent(node, openMask, indentLevel + 1);
            }
        }
예제 #2
0
        public static MultiCheckboxState NextState(this MultiCheckboxState state)
        {
            MultiCheckboxState nextstate;

            // On -> Partial -> Off -> On ...
            switch (state)
            {
            case MultiCheckboxState.On:
                nextstate = MultiCheckboxState.Partial;
                break;

            case MultiCheckboxState.Off:
                nextstate = MultiCheckboxState.On;
                break;

            case MultiCheckboxState.Partial:
                nextstate = MultiCheckboxState.Off;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, null);
            }

            return(nextstate);
        }
예제 #3
0
        public static void CheckBoxLabeledMulti(Rect rect, string label, ref MultiCheckboxState state,
                                                bool disabled = false)
        {
            var anchor = Text.Anchor;

            Text.Anchor = TextAnchor.MiddleLeft;
            Verse.Widgets.Label(rect, label);

            if (!disabled && Verse.Widgets.ButtonInvisible(rect))
            {
                switch (state)
                {
                case MultiCheckboxState.On:
                    state = MultiCheckboxState.Partial;
                    SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera();
                    break;

                case MultiCheckboxState.Partial:
                    state = MultiCheckboxState.Off;
                    SoundDefOf.Checkbox_TurnedOff.PlayOneShotOnCamera();
                    break;

                case MultiCheckboxState.Off:
                    state = MultiCheckboxState.On;
                    SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera();
                    break;
                }
            }

            var r = new Rect(rect.x + rect.width - 24f, rect.y, 24f, 24f);

            Verse.Widgets.CheckboxMulti(r, state);

            Text.Anchor = anchor;
        }
예제 #4
0
        public bool CheckboxPartial(string label, ref MultiCheckboxState state, string tooltip = null, bool enabled = true, bool allowPartialInCycle = false)
        {
            var result = GuiPlus.CheckboxPartial(GetRect(Text.LineHeight), label, ref state, tooltip, enabled, allowPartialInCycle);

            Gap(verticalSpacing);

            return(result);
        }
예제 #5
0
        private static void SaveThreeState(XContainer xRoot, string containerName, MultiCheckboxState state)
        {
            if (state == MultiCheckboxState.Partial)
            {
                return;
            }

            var xContainerElement = new XElement(containerName);

            xRoot.Add(xContainerElement);

            xContainerElement.Add(new XElement(StateNode, state.ToString()));
        }
예제 #6
0
        public void DoCategory(TreeNode_ThingCategory node, int indentLevel, int openMask, Map map)
        {
            base.OpenCloseWidget(node, indentLevel, openMask);
            base.LabelLeft(node.LabelCap, node.catDef.description, indentLevel, 0f);
            MultiCheckboxState multiCheckboxState  = this.AllowanceStateOf(node);
            MultiCheckboxState multiCheckboxState2 = Widgets.CheckboxMulti(new Rect(this.LabelWidth, this.curY, this.lineHeight, this.lineHeight), multiCheckboxState, true);

            if (multiCheckboxState != multiCheckboxState2)
            {
                this.filter.SetAllow(node.catDef, multiCheckboxState2 == MultiCheckboxState.On, this.forceHiddenDefs, this.hiddenSpecialFilters);
            }
            base.EndLine();
            if (node.IsOpen(openMask))
            {
                this.DoCategoryChildren(node, indentLevel + 1, openMask, map, false);
            }
        }
        public void DoCategory(TreeNode_ThingCategory node, int indentLevel, int openMask)
        {
            base.OpenCloseWidget(node, indentLevel, openMask);
            base.LabelLeft(node.LabelCap, node.catDef.description, indentLevel);
            MultiCheckboxState multiCheckboxState = this.AllowanceStateOf(node);

            if (Widgets.CheckboxMulti(new Vector2(this.LabelWidth, this.curY), multiCheckboxState, this.lineHeight))
            {
                bool allow = multiCheckboxState == MultiCheckboxState.Off;
                this.filter.SetAllow(node.catDef, allow, this.forceHiddenDefs, this.hiddenSpecialFilters);
            }
            base.EndLine();
            if (node.IsOpen(openMask))
            {
                this.DoCategoryChildren(node, indentLevel + 1, openMask, false);
            }
        }
        public void DoCategory(TreeNode_ThingCategory node, int indentLevel, int openMask, Map map)
        {
            OpenCloseWidget(node, indentLevel, openMask);
            LabelLeft(node.LabelCap, node.catDef.description, indentLevel);
            MultiCheckboxState multiCheckboxState  = AllowanceStateOf(node);
            MultiCheckboxState multiCheckboxState2 = Widgets.CheckboxMulti(new Rect(LabelWidth, curY, lineHeight, lineHeight), multiCheckboxState, paintable: true);

            if (multiCheckboxState != multiCheckboxState2)
            {
                filter.SetAllow(node.catDef, multiCheckboxState2 == MultiCheckboxState.On, forceHiddenDefs, hiddenSpecialFilters);
            }
            EndLine();
            if (node.IsOpen(openMask))
            {
                DoCategoryChildren(node, indentLevel + 1, openMask, map);
            }
        }
예제 #9
0
 /// <summary>
 ///     Initialize a dictionary from a list of RimWorld definitions (<see cref="Def" />) where keys are <see cref="Def" />
 ///     and values are <see cref="ThreeStateItem" />.
 ///     The propertyChangedName makes it so that if a <see cref="ThreeStateItem" /> item changed an event is fired for the
 ///     whole dictionary rather than the contained item.
 /// </summary>
 /// <typeparam name="T">The type of the items in the list parameter. <b>T</b> should be a RimWorld <see cref="Def" />.</typeparam>
 /// <param name="initList">A list of <see cref="Def" /> (each entry will be used as a dictionary key).</param>
 /// <param name="dictionary">The dictionary to be initialized.</param>
 /// <param name="propertyChangedName">
 ///     The bound property name (the name of the dictionary in this class). Each time a value
 ///     in the dictionary is changed, this fire an event related to the dictionary name and not the contained values.
 /// </param>
 /// <param name="defaultSate">The default state of the <see cref="ThreeStateItem" />.</param>
 protected void InitSelectedDictionary <T>(List <T> initList, Dictionary <T, ThreeStateItem> dictionary,
                                           string propertyChangedName, MultiCheckboxState defaultSate = MultiCheckboxState.Partial)
 {
     dictionary.Clear();
     foreach (var elementDef in initList)
     {
         var item = new ThreeStateItem(defaultSate);
         item.PropertyChanged += delegate
         {
             // cheat! rather than saying that a ThreeState item changed
             //  just pretend the whole dictionary has changed.
             // We don't need a finer grain control than that, as the dictionary will contain just a few elements.
             OnPropertyChanged(propertyChangedName);
         };
         dictionary.Add(elementDef, item);
     }
 }
예제 #10
0
        public static bool CheckBoxLabeledSelectableMulti(Rect rect, string label, ref bool selected,
                                                          ref MultiCheckboxState state, bool disabled = false)
        {
            if (selected)
            {
                Verse.Widgets.DrawHighlight(rect);
            }
            Verse.Widgets.Label(rect, label);
            var flag    = selected;
            var butRect = rect;

            butRect.width -= 24f;
            if (!selected && Verse.Widgets.ButtonInvisible(butRect))
            {
                SoundDefOf.Tick_Tiny.PlayOneShotOnCamera();
                selected = true;
            }
            var color = GUI.color;

            GUI.color = Color.white;
            CheckBoxMultiDraw(rect.xMax - 24f, rect.y, state, false);
            GUI.color = color;
            var butRect2 = new Rect(rect.xMax - 24f, rect.y, 24f, 24f);

            if (Verse.Widgets.ButtonInvisible(butRect2))
            {
                var nextState = state.NextState();
                if ((nextState == MultiCheckboxState.Off) || (state == MultiCheckboxState.Partial))
                {
                    SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera();
                }
                else
                {
                    SoundDefOf.Checkbox_TurnedOff.PlayOneShotOnCamera();
                }

                state = nextState;
            }

            return(selected && !flag);
        }
예제 #11
0
        public static void CheckBoxMultiDraw(float x, float y, MultiCheckboxState state, bool disabled,
                                             float size = 24f)
        {
            var color = GUI.color;

            if (disabled)
            {
                GUI.color = InactiveColor;
            }

            Texture2D image;

            switch (state)
            {
            case MultiCheckboxState.On:
                image = Verse.Widgets.CheckboxOnTex;
                break;

            case MultiCheckboxState.Partial:
                image = Verse.Widgets.CheckboxPartialTex;
                break;

            case MultiCheckboxState.Off:
                image = Verse.Widgets.CheckboxOffTex;
                break;

            default:
                image = Verse.Widgets.CheckboxOffTex;
                break;
            }

            var position = new Rect(x, y, size, size);

            GUI.DrawTexture(position, image);
            if (disabled)
            {
                GUI.color = color;
            }
        }
예제 #12
0
        // View of standard toggles, with multipicker.
        static void DoToggleView(Rect middleRect)
        {
            List <Toggle> groupToggles = ToggleManager.Toggles.Where(x => x.Group.Equals(ActiveGroup)).ToList();
            float         middleY      = (groupToggles.Count() + 5) * 25f;
            var           middleView   = new Listing_Toggles();

            middleView.BeginListing(middleRect, ref scrollPositionMiddle, middleY);

            // Establishes references for checking if Option buttons are disabled further down.
            string optionsEntryButton = $"{ButtonCat.ButtonsEntry}_Options";
            string optionsPlayButton  = $"{ButtonCat.ButtonsPlay}_Options";
            bool   optionsEntryFlag   = ToggleManager.IsActive(optionsEntryButton);
            bool   optionsPlayFlag    = ToggleManager.IsActive(optionsPlayButton);

            // Draw multi picker.
            // Only show if any button has been clicked at start.
            if (!ActiveGroup.NullOrEmpty())
            {
                bool wasPartial = false;

                if (groupToggles.All(x => x.active))
                {
                    state = MultiCheckboxState.On;
                }
                else if (groupToggles.All(x => !x.active))
                {
                    state = MultiCheckboxState.Off;
                }
                else
                {
                    state      = MultiCheckboxState.Partial;
                    wasPartial = true;
                }

                state = middleView.MultiCheckBoxLabel(state, GetHotkeyFloatOptions(groupToggles), "Hotkey".Translate(), ActiveGroup.Translate(), $"{ActiveGroup}Desc".Translate());

                // If partial is clicked, it defaults to off. This workaround turns all on instead, by checking if it was partial before clicking.
                if (state == MultiCheckboxState.On || (wasPartial && state == MultiCheckboxState.Off))
                {
                    groupToggles.ForEach(x => x.active = true);
                }
                else if (state == MultiCheckboxState.Off)
                {
                    groupToggles.ForEach(x => x.active = false);
                }
            }

            middleView.GapLine();

            // Draw toggles in middle view depending on what button is active in left view.
            foreach (Toggle toggle in groupToggles.OrderBy(x => x.PrettyLabel))
            {
                middleView.CheckboxLabeled(toggle.PrettyLabel, toggle.PrettyHotkey, ref toggle.active, GetHotkeyFloatOptions(toggle));
            }

            // Opens confirmation window if user has deactivated the Options button.
            CheckOptionsActive(optionsEntryButton, optionsEntryFlag);
            CheckOptionsActive(optionsPlayButton, optionsPlayFlag);

            middleView.EndListing();
        }
예제 #13
0
        public static bool CheckboxPartial(Rect rect, string label, ref MultiCheckboxState state, string tooltip = null, bool enabled = true, bool allowPartialInCycle = true)
        {
            var prevAnchor = Text.Anchor;

            Text.Anchor = TextAnchor.MiddleLeft;
            Widgets.Label(rect, label);

            if (Mouse.IsOver(rect))
            {
                Widgets.DrawHighlight(rect);
                if (!tooltip.NullOrEmpty())
                {
                    TooltipHandler.TipRegion(rect, tooltip);
                }
            }

            var result = false;

            if (enabled && Widgets.ButtonInvisible(rect))
            {
                if (state == MultiCheckboxState.Off)
                {
                    state = allowPartialInCycle ? MultiCheckboxState.Partial : MultiCheckboxState.On;
                    SoundDefOf.Checkbox_TurnedOff.PlayOneShotOnCamera();
                }
                else if (state == MultiCheckboxState.Partial)
                {
                    state = MultiCheckboxState.On;
                    SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera();
                }
                else
                {
                    state = MultiCheckboxState.Off;
                    SoundDefOf.Checkbox_TurnedOff.PlayOneShotOnCamera();
                }

                result = true;
            }

            var prevColor = GUI.color;

            if (!enabled)
            {
                GUI.color = InactiveColor;
            }

            Texture2D image;

            if (state == MultiCheckboxState.Partial)
            {
                image = Widgets.CheckboxPartialTex;
            }
            else if (state == MultiCheckboxState.On)
            {
                image = Widgets.CheckboxOnTex;
            }
            else
            {
                image = Widgets.CheckboxOffTex;
            }

            GUI.DrawTexture(new Rect((rect.x + rect.width) - CheckboxSize, rect.y, CheckboxSize, CheckboxSize), image);
            if (!enabled)
            {
                GUI.color = prevColor;
            }

            Text.Anchor = prevAnchor;

            return(result);
        }
예제 #14
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="defaultSate">The default state of the item.</param>
 public ThreeStateItem(MultiCheckboxState defaultSate = MultiCheckboxState.Partial)
 {
     _state       = defaultSate;
     DefaultState = defaultSate;
 }
예제 #15
0
        private void DrawPartButtons(ref float curY, Rect partListViewRect, List <Hediff_AddedMutation> mutations, List <BodyPartRecord> parts, MutationLayer layer, string label)
        {
            // Draw the main mutation selection button. It should take up the whole width if there are no mutations, otherwise it will leave a space for the edit button.
            float partButtonWidth = partListViewRect.width - (mutations.NullOrEmpty() ? 0 : editButtonWidth);
            Rect  partButtonRect  = new Rect(partListViewRect.x, curY, partButtonWidth, Text.CalcHeight(label, partButtonWidth - BUTTON_HORIZONTAL_PADDING));

            if (Widgets.ButtonText(partButtonRect, label))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                void removeMutations()
                {
                    foreach (Hediff_AddedMutation mutation in mutations)
                    {
                        addedMutations.RemoveByPartAndLayer(mutation.Part, layer);
                        if (cachedInitialHediffs.Select(m => m.hediff).Contains(mutation))
                        {
                            addedMutations.AddData(mutation.Def, mutation.Part, mutation.Severity, mutation.ProgressionHalted, true);
                        }
                        pawn.health.RemoveHediff(mutation);
                    }
                    recachePreview = true;
                    RecachePawnMutations();
                }

                options.Add(new FloatMenuOption(NO_MUTATIONS_LOC_STRING.Translate(), removeMutations));


                List <MutationDef> mutationDefs = cachedMutationDefsByPartDef[parts.FirstOrDefault().def];
                foreach (MutationDef mutationDef in mutationDefs.Where(m => m.RemoveComp.layer == layer && (DebugSettings.godMode || m.IsTagged())))
                {
                    void addMutation()
                    {
                        foreach (Hediff_AddedMutation mutation in mutations)
                        {
                            pawn.health.RemoveHediff(mutation);
                        }
                        foreach (BodyPartRecord part in parts)
                        {
                            addedMutations.RemoveByPartAndLayer(part, layer);
                            addedMutations.AddData(mutationDef, part, mutationDef.initialSeverity, false, false);
                            MutationUtilities.AddMutation(pawn, mutationDef, part, ancillaryEffects: MutationUtilities.AncillaryMutationEffects.None); //don't give the green puffs
                        }
                        recachePreview = true;
                        RecachePawnMutations();
                    }

                    options.Add(new FloatMenuOption(mutationDef.LabelCap, addMutation));
                }
                Find.WindowStack.Add(new FloatMenu(options));
            }
            curY += partButtonRect.height;

            // If there are actually mutations, draw the edit button.
            if (!mutations.NullOrEmpty())
            {
                Rect editButtonRect = new Rect(partButtonWidth, partButtonRect.y, editButtonWidth, partButtonRect.height);
                if (Widgets.ButtonText(editButtonRect, editButtonText))
                {
                    detailPart = (detailPart.Item1 == parts.FirstOrDefault() && detailPart.Item2 == layer) ? new Tuple <BodyPartRecord, MutationLayer>(new BodyPartRecord(), 0) : new Tuple <BodyPartRecord, MutationLayer>(parts.FirstOrDefault(), layer);
                }
            }

            // If the currently selected part and layer match up with the part to give details for, draw the edit area below the buttons.
            if (detailPart.Item1 == parts.FirstOrDefault() && detailPart.Item2 == layer)
            {
                foreach (MutationDef mutationDef in mutations.Select(m => m.Def).Distinct())
                {
                    List <Hediff_AddedMutation> mutationsOfDef = mutations.Where(m => m.Def == mutationDef).ToList();

                    // Draw the LabelCap of the current Def if there is more than one type of mutation in the current list.
                    if (mutations.Select(m => m.Def).Distinct().Count() > 1)
                    {
                        Widgets.ListSeparator(ref curY, partListViewRect.width, mutationDef.LabelCap);
                    }

                    // Draw the various labels for the severity bar (need to refine this later).
                    string stageLabelText     = $"Stage {mutationsOfDef.FirstOrDefault().CurStageIndex}: {mutationsOfDef.FirstOrDefault().LabelCap}";
                    Rect   severityLabelsRect = new Rect(partListViewRect.x, curY, partListViewRect.width, Text.CalcHeight(stageLabelText, partListViewRect.width));
                    Text.Anchor = TextAnchor.MiddleLeft;
                    Widgets.Label(severityLabelsRect, stageLabelText);
                    Text.Anchor = TextAnchor.MiddleRight;
                    Widgets.Label(severityLabelsRect, mutationsOfDef.FirstOrDefault().Severity.ToString("n2"));
                    Text.Anchor = TextAnchor.UpperLeft;
                    curY       += severityLabelsRect.height;

                    // Draw the severity slider
                    float curSeverity = mutationsOfDef.Select(n => n.Severity).Average();
                    float newSeverity = Widgets.HorizontalSlider(new Rect(partListViewRect.x, curY, partListViewRect.width, SLIDER_HEIGHT), curSeverity, mutationDef.minSeverity, mutationDef.maxSeverity);
                    if (curSeverity != newSeverity)
                    {
                        curSeverity = newSeverity;
                        foreach (Hediff_AddedMutation mutationOfDef in mutationsOfDef)
                        {
                            MutationData relevantEntry = addedMutations.MutationsByPartAndLayer(mutationOfDef.Part, layer);
                            if (relevantEntry != null)
                            {
                                relevantEntry.severity = newSeverity;
                            }
                            else
                            {
                                addedMutations.AddData(mutationOfDef.Def, mutationOfDef.Part, newSeverity, mutationOfDef.ProgressionHalted, false);
                            }
                            mutationOfDef.Severity = newSeverity;
                        }
                        recachePreview = true;
                    }
                    curY += SLIDER_HEIGHT;

                    // If the mutation has the ability to be paused, show the toggle for it.
                    // This is a CheckboxMulti to handle edge cases, but likely could be replaced with a simple Checkbox.
                    if (mutationDef.CompProps <CompProperties_MutationSeverityAdjust>() != null)
                    {
                        float pauseLabelWidth           = partListViewRect.width - IS_PAUSED_CHECKBOX_SIZE.x;
                        Rect  pauseLabelRect            = new Rect(partListViewRect.x, curY, pauseLabelWidth, Text.CalcHeight(IS_PAUSED_LOC_STRING.Translate(), partListViewRect.width));
                        Rect  checkBoxRect              = new Rect(partListViewRect.x + pauseLabelWidth, curY, IS_PAUSED_CHECKBOX_SIZE.x, IS_PAUSED_CHECKBOX_SIZE.y);
                        MultiCheckboxState initialState = !mutationsOfDef.Select(n => n.ProgressionHalted).Contains(true) ? MultiCheckboxState.Off : !mutationsOfDef.Select(n => n.ProgressionHalted).Contains(false) ? MultiCheckboxState.On : MultiCheckboxState.Partial;
                        Widgets.Label(pauseLabelRect, IS_PAUSED_LOC_STRING.Translate());
                        MultiCheckboxState newState = Widgets.CheckboxMulti(checkBoxRect, initialState);
                        if (initialState != newState)
                        {
                            initialState = newState;
                            mutationsOfDef.FirstOrDefault().SeverityAdjust.Halted = !mutationsOfDef.FirstOrDefault().SeverityAdjust.Halted;
                            foreach (Hediff_AddedMutation mutationOfDef in mutationsOfDef)
                            {
                                MutationData relevantEntry = addedMutations.MutationsByPartAndLayer(mutationOfDef.Part, layer);
                                if (cachedInitialHediffs.Select(m => m.hediff).Contains(mutationOfDef))
                                {
                                    bool initialHediffIsHalted = cachedInitialHediffs.Where(m => m.hediff == mutationOfDef).FirstOrDefault().isHalted;
                                    if (newState == MultiCheckboxState.On == initialHediffIsHalted)
                                    {
                                        addedMutations.RemoveByPartAndLayer(mutationOfDef.Part, layer);
                                    }
                                }
                                if (relevantEntry != null)
                                {
                                    relevantEntry.isHalted = newState == MultiCheckboxState.On;
                                }
                                else
                                {
                                    addedMutations.AddData(mutationOfDef.Def, mutationOfDef.Part, mutationOfDef.Severity, newState == MultiCheckboxState.On, false);
                                }
                            }
                        }
                        curY += Math.Max(pauseLabelRect.height, checkBoxRect.height);
                    }
                }
            }

            // Create a zone for updating the lower description box (The one that shows details based on the currently hovered over mutation).
            Rect descriptionUpdateRect = new Rect(partListViewRect.x, partButtonRect.y, partListViewRect.width, curY - partButtonRect.y);

            if (Mouse.IsOver(descriptionUpdateRect))
            {
                foreach (MutationDef mutation in mutations.Select(m => m.def).Distinct())
                {
                    Hediff_AddedMutation firstMutationOfDef = mutations.Where(m => m.def == mutation).FirstOrDefault();
                    partDescBuilder.AppendLine(firstMutationOfDef.LabelCap);
                    partDescBuilder.AppendLine(firstMutationOfDef.Description);
                    partDescBuilder.AppendLine(firstMutationOfDef.TipStringExtra);
                    partDescBuilder.AppendLine();
                }
            }
        }
예제 #16
0
 protected ThreeStateItem InitThreeStateItem(string propertyChanedName,
                                             MultiCheckboxState defaultState = MultiCheckboxState.Partial)
 {
     return(new ThreeStateItem(defaultState));
 }
예제 #17
0
        public void DrawFilters(Rect canvas)
        {
            GUI.BeginGroup(canvas);
            var listing  = new Listing_Standard();
            var viewPort = new Rect(canvas.x, canvas.y, canvas.width - 16f, _filters.Sum(f => f.Height));

            Widgets.BeginScrollView(canvas, ref _scrollPos, viewPort);
            listing.Begin(viewPort);

            foreach (ThingItemFilterCategory category in _filters)
            {
                Rect lineRect = listing.GetRect(Text.LineHeight);

                if (!lineRect.IsVisible(viewPort, _scrollPos) && !category.Expanded)
                {
                    continue;
                }

                Rect arrowIconRect  = new Rect(lineRect.x, lineRect.y, lineRect.height, lineRect.height).ContractedBy(4f);
                Rect checkStateRect = new Rect(arrowIconRect.x + arrowIconRect.width, lineRect.y, lineRect.height, lineRect.height).ContractedBy(4f);

                var categoryTextRect = new Rect(
                    checkStateRect.x + checkStateRect.width + 5f,
                    lineRect.y,
                    lineRect.width - 5f - arrowIconRect.width - checkStateRect.width,
                    lineRect.height
                    );

                GUI.DrawTexture(arrowIconRect.ContractedBy(2f), category.Expanded ? Textures.ExpandedArrow : Textures.CollapsedArrow);

                MultiCheckboxState state = Widgets.CheckboxMulti(checkStateRect, category.CheckState, true);

                if (state != category.CheckState)
                {
                    category.CheckState = state;

                    foreach (ThingItemFilter filter in category.Filters)
                    {
                        switch (category.CheckState)
                        {
                        case MultiCheckboxState.Off:
                            filter.Active = false;

                            break;

                        case MultiCheckboxState.On:
                            filter.Active = true;

                            break;
                        }
                    }
                }

                UiHelper.Label(categoryTextRect, $"TKUtils.FilterTypes.{category.FilterType}".TranslateSimple());

                if (Widgets.ButtonInvisible(arrowIconRect))
                {
                    category.Expanded = !category.Expanded;
                }

                if (category.Expanded)
                {
                    DrawFiltersFor(category, listing, viewPort);
                }
            }

            GUI.EndGroup();
            listing.End();
            Widgets.EndScrollView();
        }
예제 #18
0
        internal MultiCheckboxState MultiCheckBoxLabel(MultiCheckboxState state, List <FloatMenuOption> floatMenuList, string keyGroup, string label = null, string infoText = null)
        {
            float lineHeight = Text.LineHeight;
            Rect  rect       = base.GetRect(lineHeight);

            base.Gap(this.verticalSpacing);
            rect.x     += 10f;
            rect.width -= 10f;

            Texture2D tex;

            if (state == MultiCheckboxState.On)
            {
                tex = Widgets.CheckboxOnTex;
            }
            else if (state == MultiCheckboxState.Off)
            {
                tex = Widgets.CheckboxOffTex;
            }
            else
            {
                tex = Widgets.CheckboxPartialTex;
            }

            Color color = Widgets.NormalOptionColor;

            // Checkbox
            Rect texRect = new Rect(rect.width - texSize.x, rect.y, texSize.x, texSize.y);

            MouseoverSounds.DoRegion(texRect);

            // Info Icon
            Rect      infoRect = new Rect(rect.x, rect.y, 22f, 22f);
            Texture2D infoTex  = ContentFinder <Texture2D> .Get("UI/Buttons/InfoButton", true);

            GUI.DrawTexture(infoRect, infoTex);

            // Text label
            Rect labelRect = new Rect(rect);

            labelRect.x = infoRect.width + 15f;
            Widgets.Label(labelRect, label);

            // InfoText, tooltip
            if (infoText != null)
            {
                TooltipHandler.TipRegion(infoRect, infoText);
            }

            // KeyGroup Button
            MakeFloatMenu(rect, keyGroup, floatMenuList);

            MultiCheckboxState stateCheck = (state != MultiCheckboxState.Off) ? MultiCheckboxState.Off : MultiCheckboxState.On;

            if (AnyPressed(Widgets.ButtonImageDraggable(texRect, tex)))
            {
                if (stateCheck == MultiCheckboxState.On)
                {
                    SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera(null);
                }
                else
                {
                    SoundDefOf.Checkbox_TurnedOff.PlayOneShotOnCamera(null);
                }
                return(stateCheck);
            }
            return(state);
        }