示例#1
0
 // Asks for confirmation of deactiving Options buttons.
 static void CheckOptionsActive(string optionsString, bool optionsFlag)
 {
     if (optionsFlag != ToggleManager.IsActive(optionsString) && !ToggleManager.IsActive(optionsString))
     {
         Toggle toggle = ToggleManager.Toggles.Find(x => x.Label.Equals(optionsString));
         toggle.active = true;
         Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("DeactivateOptions".Translate(), delegate { toggle.active = false; }, true, null));
     }
 }
示例#2
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();
        }