Beispiel #1
0
        public static void Init()
        {
            if (Instance == null)
            {
                Instance = BeatSaberUI.CreateCustomMenu <CustomMenu>($"{Plugin.instance.Name} has been updated");

                CustomViewController middleViewController = BeatSaberUI.CreateViewController <CustomViewController>();


                Instance.SetMainViewController(middleViewController, true, (firstActivation, type) =>
                {
                    if (firstActivation)
                    {
                        TMPro.TextMeshProUGUI t = middleViewController.CreateText($"{Plugin.instance.Name} has been updated to v{Plugin.instance.UpdatedVersion}. Restart your game to take effect.", new Vector2(0f, 0f));
                        t.alignment             = TMPro.TextAlignmentOptions.Center;
                    }
                });
                Instance.Present();
                if (PluginUI.MultiplayerButton != null)
                {
                    PluginUI.MultiplayerButton.interactable = false;
                    PluginUI.MultiplayerButton.hintText     = "You cannot access multiplayer until you restart your game";
                    for (int i = PluginUI.MultiplayerButton.buttons.Count - 1; i >= 0; i--)
                    {
                        BeatSaberUI.AddHintText(PluginUI.MultiplayerButton.buttons[i].transform as RectTransform, PluginUI.MultiplayerButton.hintText);
                    }
                }
            }
        }
        private static IEnumerator AddModListButton()
        {
            yield return(_bottomPanelExists);

            Logger.log.Debug("Adding button to main menu");

            lock (Instance)
            {
                if (menuFlow == null)
                {
                    menuFlow = new GameObject("BSIPA Mod List Flow Controller").AddComponent <ModListFlowCoordinator>();
                }
                if (panel == null)
                {
                    panel = GameObject.Find(ControllerPanel).transform as RectTransform;
                }

                if (button == null)
                {
                    button = BeatSaberUI.CreateUIButton(panel, CopyButton, () =>
                    {
                        menuFlow.Present();
                    }, "Mod List");
                    panel.Find(CopyButton).SetAsLastSibling();

                    hintText = BeatSaberUI.AddHintText(button.transform as RectTransform, "View and control updates for installed mods");
                }

                yield break;
            }
        }
        public T AddStringSetting <T>(string name, string hintText) where T : ListSettingsController
        {
            var        volumeSettings    = Resources.FindObjectsOfTypeAll <VolumeSettingsController>().FirstOrDefault();
            GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform);

            newSettingsObject.name = name;
            newSettingsObject.transform.Find("Value").gameObject.GetComponent <HorizontalLayoutGroup>().spacing += 2;
            newSettingsObject.transform.Find("Value").Find("DecButton").gameObject.SetActive(false);
            //var bgIcon = newSettingsObject.transform.Find("Value").Find("IncButton").Find("BG").gameObject.GetComponent<Image>();
            //(bgIcon.transform as RectTransform).localScale *= new Vector2(0.9f, 0.9f);
            var arrowIcon = newSettingsObject.transform.Find("Value").Find("IncButton").Find("Arrow").gameObject.GetComponent <Image>();

            arrowIcon.sprite = UIUtilities.EditIcon;
            var valueText = newSettingsObject.transform.Find("Value").Find("ValueText").gameObject.GetComponent <TextMeshProUGUI>();

            valueText.alignment          = TextAlignmentOptions.MidlineRight;
            valueText.enableWordWrapping = false;
            BeatSaberUI.AddHintText(valueText.rectTransform, hintText);

            VolumeSettingsController volume = newSettingsObject.GetComponent <VolumeSettingsController>();
            T newListSettingsController     = (T)ReflectionUtil.CopyComponent(volume, typeof(ListSettingsController), typeof(T), newSettingsObject);

            MonoBehaviour.DestroyImmediate(volume);

            var tmpText = newSettingsObject.GetComponentInChildren <TMP_Text>();

            tmpText.text = name;
            BeatSaberUI.AddHintText(tmpText.rectTransform, hintText);

            return(newListSettingsController);
        }
Beispiel #4
0
        public T AddIconSegmentsSetting <T>(string name, string hintText, IconSegmentedControl.DataItem[] icons) where T : SegmentedControlViewController
        {
            var        volumeSettings    = GetVolumeSettings();
            GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform);

            newSettingsObject.name = name;

            ListSettingsController volume       = newSettingsObject.GetComponent <ListSettingsController>();
            T newTextSegmentsSettingsController = (T)ReflectionUtil.CopyComponent(volume, typeof(ListSettingsController), typeof(T), newSettingsObject);

            MonoBehaviour.DestroyImmediate(volume);

            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("DecButton").gameObject);
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("ValueText").gameObject);
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("IncButton").gameObject);

            IconSegmentedControl segmentedControl = BeatSaberUI.CreateIconSegmentedControl(newSettingsObject.transform.Find("Value") as RectTransform, new Vector2(0f, 0f), new Vector2(40f, 7f));

            newTextSegmentsSettingsController.segmentedControl = segmentedControl;
            segmentedControl.SetData(icons);

            var tmpText = newSettingsObject.GetComponentInChildren <TMP_Text>();

            tmpText.text = name;
            if (hintText != String.Empty)
            {
                BeatSaberUI.AddHintText(tmpText.rectTransform, hintText);
            }

            viewController?.AddSubmenuOption(newSettingsObject);
            AddHooks(newTextSegmentsSettingsController);
            return(newTextSegmentsSettingsController);
        }
        public T AddSliderSetting <T>(string name, string hintText, float min, float max, bool intValues) where T : IncDecSettingsController
        {
            var        volumeSettings    = Resources.FindObjectsOfTypeAll <WindowModeSettingsController>().FirstOrDefault();
            GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform);

            newSettingsObject.name = name;

            WindowModeSettingsController volume = newSettingsObject.GetComponent <WindowModeSettingsController>();
            T newSliderSettingsController       = (T)ReflectionUtil.CopyComponent(volume, typeof(IncDecSettingsController), typeof(T), newSettingsObject);

            MonoBehaviour.DestroyImmediate(volume);

            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("DecButton").gameObject);
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("ValueText").gameObject);
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("IncButton").gameObject);

            HMUI.Scrollbar slider = GameObject.Instantiate(Resources.FindObjectsOfTypeAll <HMUI.Scrollbar>().First(),
                                                           newSettingsObject.transform.Find("Value"), false);
            SliderProperties sliderProperties = slider.gameObject.AddComponent <SliderProperties>();

            sliderProperties.FromValue = min;
            sliderProperties.ToValue   = max;
            sliderProperties.IntValues = intValues;
            slider.GetComponentInChildren <TextMeshProUGUI>().enableWordWrapping = false;
            (slider.transform as RectTransform).sizeDelta = new Vector2(39.5f, 7.5f);
            (slider.transform as RectTransform).anchorMin = new Vector2(0, 0.5f);

            var tmpText = newSettingsObject.GetComponentInChildren <TMP_Text>();

            tmpText.text = name;
            BeatSaberUI.AddHintText(tmpText.rectTransform, hintText);

            return(newSliderSettingsController);
        }
Beispiel #6
0
        public T AddListSetting <T>(string name, string hintText) where T : ListSettingsController
        {
            var        volumeSettings    = GetVolumeSettings();
            GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform);

            newSettingsObject.name = name;

            var incBg = newSettingsObject.transform.Find("Value").Find("IncButton").Find("BG").gameObject.GetComponent <Image>();

            (incBg.transform as RectTransform).localScale *= new Vector2(0.8f, 0.8f);
            var decBg = newSettingsObject.transform.Find("Value").Find("DecButton").Find("BG").gameObject.GetComponent <Image>();

            (decBg.transform as RectTransform).localScale *= new Vector2(0.8f, 0.8f);

            ListSettingsController volume = newSettingsObject.GetComponent <ListSettingsController>();
            T newListSettingsController   = (T)ReflectionUtil.CopyComponent(volume, typeof(ListSettingsController), typeof(T), newSettingsObject);

            MonoBehaviour.DestroyImmediate(volume);

            var tmpText = newSettingsObject.GetComponentInChildren <TMP_Text>();

            tmpText.text = name;
            if (hintText != String.Empty)
            {
                BeatSaberUI.AddHintText(tmpText.rectTransform, hintText);
            }

            viewController?.AddSubmenuOption(newSettingsObject);
            AddHooks(newListSettingsController);
            return(newListSettingsController);
        }
        public override TableCell CellForRow(int row)
        {
            LevelListTableCell _tableCell = Instantiate(_songListTableCellInstance);

            RequestBot.SongRequest request = SongInfoForRow(row);
            JSONObject             song    = request.song;

            BeatSaberUI.AddHintText(_tableCell.transform as RectTransform, $"Requested by {request.requestor.displayName}");
            _tableCell.songName = song["songName"];
            _tableCell.author   = song["authorName"];
            if (SongLoader.AreSongsLoaded)
            {
                CustomLevel level = CustomLevelForRow(row);
                if (level)
                {
                    _tableCell.coverImage = level.coverImage;
                }
            }
            if (_tableCell.coverImage == null)
            {
                string url = song["coverUrl"];
                _tableCell.coverImage = GetSongCoverArt(url, (sprite) => { _cachedSprites[url] = sprite; _customListTableView.ReloadData(); });
            }

            _tableCell.reuseIdentifier = "CustomListCell";
            return(_tableCell);
        }
Beispiel #8
0
        private SubMenu AddSubMenu_Internal(string text, string hintText, bool addBackButton, SubMenu subMenu = null)
        {
            if (viewController == null)
            {
                throw new Exception("You cannot add a submenu using this method outside of the settings menu.");
            }

            if (subMenu == null)
            {
                _subSubMenus.TryGetValue(text, out subMenu);
                if (subMenu == null)
                {
                    subMenu            = SettingsUI.CreateSubMenu(text, false);
                    _subSubMenus[text] = subMenu;
                    if (addBackButton)
                    {
                        subMenu.AddSubMenu("Back", "Go back to the previous menu", this);
                    }
                }
            }

            GameObject gameObj = new GameObject("CustomUIText");

            gameObj.SetActive(false);

            ClickableText clickableText = gameObj.AddComponent <ClickableText>();

            clickableText.font = GameObject.Instantiate(Resources.FindObjectsOfTypeAll <TMP_FontAsset>().First(t => t.name == "Teko-Medium SDF No Glow"));
            clickableText.rectTransform.SetParent(transform, false);
            clickableText.text     = text;
            clickableText.fontSize = 5;
            clickableText.color    = Color.white;

            clickableText.rectTransform.anchorMin = new Vector2(0f, -3);
            clickableText.rectTransform.anchorMax = new Vector2(0f, -3);
            //clickableText.rectTransform.anchoredPosition = new Vector2(0f, -1f);

            clickableText.OnClickEvent += (eventData) => {
                var settingsFlowCoordinator = Resources.FindObjectsOfTypeAll <SettingsFlowCoordinator>().FirstOrDefault();
                if (settingsFlowCoordinator)
                {
                    var navigationController = settingsFlowCoordinator.GetPrivateField <SettingsNavigationController>("_settingsNavigationController");
                    settingsFlowCoordinator.InvokePrivateMethod("PopViewControllerFromNavigationController", new object[] { navigationController, null, true });
                    settingsFlowCoordinator.InvokePrivateMethod("PushViewControllerToNavigationController", new object[] { navigationController, subMenu.viewController, null, true });
                }
            };

            gameObj.SetActive(true);

            if (hintText != String.Empty)
            {
                BeatSaberUI.AddHintText(clickableText.rectTransform, hintText);
            }

            viewController?.AddSubmenuOption(clickableText.gameObject);
            return(subMenu);
        }
Beispiel #9
0
        protected override void DidActivate(bool firstActivation, ActivationType activationType)
        {
            if (!firstActivation)
            {
                return;
            }
            instance = this;
            TextMeshProUGUI name, version, creator;
            Button          github, issues, donate;

            name                  = BeatSaberUI.CreateText(rectTransform, "Counters+", Vector2.zero);
            name.fontSize         = 11;
            name.alignment        = TextAlignmentOptions.Center;
            name.characterSpacing = 2;
            setPositioning(name.rectTransform, 0, 0.7f, 1, 0.166f, 0.5f);

            version = BeatSaberUI.CreateText(rectTransform,
                                             $"Version <color={(Plugin.UpToDate ? "#00FF00" : "#FF0000")}>{Plugin.PluginVersion}</color>", Vector2.zero);
            version.fontSize  = 3;
            version.alignment = TextAlignmentOptions.Center;
            setPositioning(version.rectTransform, 0, 0.5f, 1, 0.166f, 0.5f);

            if (!Plugin.UpToDate)
            {
                TextMeshProUGUI warning = BeatSaberUI.CreateText(rectTransform,
                                                                 $"<color=#FF0000>Version {Plugin.WebVersion} available for download!</color>", Vector2.zero);
                warning.fontSize  = 3;
                warning.alignment = TextAlignmentOptions.Center;
                setPositioning(warning.rectTransform, 0, 0.47f, 1, 0.166f, 0.5f);
            }

            creator           = BeatSaberUI.CreateText(rectTransform, "Developed by: <color=#00c0ff>Caeden117</color>", Vector2.zero);
            creator.fontSize  = 5;
            creator.alignment = TextAlignmentOptions.Center;
            setPositioning(creator.rectTransform, 0, 0.35f, 1, 0.166f, 0.5f);

            try //attempt to load BSML's button cuz it messes with layout
            {
                github = BeatSaberUI.CreateUIButton(rectTransform, "SettingsButton(Clone)", Vector2.left, null, "GitHub");
            }
            catch { github = BeatSaberUI.CreateUIButton(rectTransform, "SettingsButton", Vector2.left, null, "GitHub"); }
            github.onClick.AddListener(() => { GoTo("https://github.com/Caeden117/CountersPlus", github); });
            setPositioning(github.transform as RectTransform, 0f, 0f, 0.39f, 0.125f, 0.5f);
            BeatSaberUI.AddHintText(github.transform as RectTransform, "Opens in a new browser tab on your desktop. Feel free to explore the source code! Maybe try out experimental versions?");

            issues = BeatSaberUI.CreateUIButton(rectTransform, "QuitButton", Vector2.right, null, "Report an Issue");
            issues.onClick.AddListener(() => { GoTo("https://github.com/Caeden117/CountersPlus/issues", issues); });
            setPositioning(issues.transform as RectTransform, 0.5f, 0f, 0.5f, 0.125f, 0.5f);
            BeatSaberUI.AddHintText(issues.transform as RectTransform, "Opens in a new browser tab on your desktop. Be sure to read the Issue template thoroughly!");

            donate = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", Vector2.zero, null, "<3");
            donate.onClick.AddListener(() => { GoTo("https://ko-fi.com/Caeden117", donate); });
            BeatSaberUI.AddHintText(donate.transform as RectTransform, "Buy me a coffee if you feel like I'm deserving of one.");
            setPositioning(donate.transform as RectTransform, 0.36f, 0f, 0.17f, 0.125f, 0.5f);
        }
Beispiel #10
0
        public override TableCell CellForIdx(int row)
        {
            TableCell _tableCell = Instantiate(_modListTableCellInstance);

            for (int i = 0; i < buttonsPerRow; i++)
            {
                int index = row * buttonsPerRow + i;
                if (buttons.Count > index)
                {
                    var menuButton = buttons.ElementAt(index);

                    RectTransform container = new GameObject("container", typeof(RectTransform)).GetComponent <RectTransform>();
                    container.SetParent(_tableCell.transform);
                    container.sizeDelta = buttonSize;

                    Button newButton = BeatSaberUI.CreateUIButton(container, "QuitButton", new Vector2(0, 0), buttonSize, menuButton.onClick, menuButton.text, menuButton.icon);
                    newButton.GetComponentInChildren <HorizontalLayoutGroup>().padding = new RectOffset(6, 8, 0, 0);
                    newButton.GetComponentInChildren <TextMeshProUGUI>().lineSpacing   = -65;
                    newButton.name = menuButton.text;
                    if (menuButton.hintText != String.Empty)
                    {
                        BeatSaberUI.AddHintText(newButton.transform as RectTransform, menuButton.hintText);
                    }
                    menuButton.buttons.Add(newButton);
                    newButton.interactable = menuButton.interactable;

                    //  sub button
                    var pinButton = BeatSaberUI.CreateUIButton(container, "QuitButton", new Vector2(-6, 0), new Vector2(8, 8), null, "", null);

                    if (_highlightedClip == null)
                    {
                        _highlightedClip = pinButton.GetComponent <ButtonStaticAnimations>().GetPrivateField <AnimationClip>("_highlightedClip");
                    }
                    if (_normalClip == null)
                    {
                        _normalClip = pinButton.GetComponent <ButtonStaticAnimations>().GetPrivateField <AnimationClip>("_normalClip");
                    }

                    PinButtonPushEffect(pinButton, menuButton);
                    (pinButton.transform as RectTransform).anchorMin                   = new Vector2(1, 0.5f);
                    (pinButton.transform as RectTransform).anchorMax                   = new Vector2(1, 0.5f);
                    (pinButton.transform as RectTransform).anchoredPosition            = new Vector2(-4, 0);
                    pinButton.GetComponentInChildren <HorizontalLayoutGroup>().padding = new RectOffset(0, 0, 0, 0);
                    pinButton.onClick.AddListener(() => { pinButtonPushed?.Invoke(menuButton); PinButtonPushEffect(pinButton, menuButton); });
                }
            }

            return(_tableCell);
        }
Beispiel #11
0
        private void FirstActivation()
        {
            string helpText = "<size=150%><b>Instructions</b> \n" +
                              "\n" +
                              "<size=120%>1 - Adjust your sabers using the options provided in Saber Forge.\n" +
                              "\n" +
                              "2 - Open the Custom Sabers mod menu and choose the 'Saber Forge' sabers. \n" +
                              "\n" +
                              "3 - Hit bloq"
            ;

            RectTransform verticalLayout = UIFunctions.CreateVerticalLayoutObj(new RectOffset(6, 6, 6, 6), 1, TextAnchor.UpperCenter);

            UIFunctions.SetRect(verticalLayout, transform, new Vector2(0, 1), new Vector2(0, 1), new Vector2(85, -40), new Vector2(150, 80));

            TextMeshProUGUI matLabelText = BeatSaberUI.CreateText(verticalLayout, helpText, new Vector2(0, 0), new Vector2(100, 80));

            //format
            matLabelText.alignment = TextAlignmentOptions.Top;

            //donate button
            Button donate = BeatSaberUI.CreateUIButton(transform as RectTransform, "PlayButton", new Vector2(-50, -33), new Vector2(50, 16), null, "DONATE <3");

            donate.onClick.AddListener(() => { GoTo("https://ko-fi.com/frostdragonliz", donate); });
            BeatSaberUI.AddHintText(donate.transform as RectTransform, "Kofi $$ will go towards future mod and part development, ta!");


            //reload assets button TO DO
            //  Button reload = BeatSaberUI.CreateUIButton(transform as RectTransform, "PlayButton", new Vector2(0, -33), new Vector2(50, 16), null, "USER TEXTURES");
            //  reload.onClick.AddListener(() => { Plugin.ReloadAssets(); });
            //  BeatSaberUI.AddHintText(reload.transform as RectTransform, "Force a reload of SaberForge Assets");

            //tutes button
            Button tutorials = BeatSaberUI.CreateUIButton(transform as RectTransform, "PlayButton", new Vector2(8, -33), new Vector2(50, 16), null, "TUTORIALS");

            tutorials.onClick.AddListener(() => { GoTo("https://www.youtube.com/playlist?list=PLyJh_4G6B76PPdL-rAmb44-475D0_0UBs", tutorials); });
            BeatSaberUI.AddHintText(tutorials.transform as RectTransform, "YouTube Tutorials");


            //github button
            Button github = BeatSaberUI.CreateUIButton(transform as RectTransform, "PlayButton", new Vector2(60, -33), new Vector2(50, 16), null, "SOURCE");

            github.onClick.AddListener(() => { GoTo("https://github.com/lizfrost/SaberForge", github); });
            BeatSaberUI.AddHintText(github.transform as RectTransform, "Source and mod info");
        }
Beispiel #12
0
        public static void CreateButton(string text, UnityAction onClick, string hintText)
        {
            Logger.log.Debug("Creating button with message: " + text);
            ResultsViewController controller = UnityEngine.Object.FindObjectOfType <ResultsViewController>();
            RectTransform         panel      = controller.GetComponent <RectTransform>();

            if (panel == null)
            {
                return;
            }
            Logger.log.Debug("Non-null panel!");

            Button button = BeatSaberUI.CreateUIButton(panel, CopyButton, onClick, text);

            panel.Find(CopyButton).SetAsLastSibling();

            BeatSaberUI.AddHintText(button.transform as RectTransform, hintText);
        }
Beispiel #13
0
        private void SetupTweaks()
        {
            YouTubeDownloader.Instance.downloadProgress += VideoDownloaderDownloadProgress;

            _videoFlowCoordinator = gameObject.AddComponent <VideoFlowCoordinator>();

            _videoFlowCoordinator.finished += VideoFlowCoordinatorFinished;
            _videoFlowCoordinator.Init();

            BSEvents.levelSelected += HandleDidSelectLevel;

            var _levelDetailViewController = Resources.FindObjectsOfTypeAll <StandardLevelDetailViewController>().First();

            var _buttons        = _levelDetailViewController.transform.Find("LevelDetail/PlayContainer/PlayButtons");
            var _playbutton     = _buttons.GetComponentsInChildren <Button>().First(x => x.name == "PlayButton");
            var _practiceButton = _buttons.GetComponentsInChildren <Button>().First(x => x.name == "PracticeButton");

            var _coverImage = _levelDetailViewController.transform.Find("LevelDetail/Level/CoverImage");

            _videoButton      = Instantiate(_practiceButton, _coverImage);
            _videoButton.name = "VideoButton";
            _videoButton.SetButtonIcon(Base64Sprites.PlayIcon);
            (_videoButton.transform as RectTransform).anchoredPosition = new Vector2(0, 0);
            (_videoButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
            (_videoButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
            (_videoButton.transform as RectTransform).sizeDelta        = new Vector2(8, 8);
            _videoButton.onClick.AddListener(delegate() { _videoFlowCoordinator.Present(); });

            _videoButtonHint = BeatSaberUI.AddHintText(_videoButton.transform as RectTransform, "Download a video");

            var glow         = _playbutton.GetComponentsInChildren <RectTransform>().First(x => x.name == "GlowContainer");
            var videoWrapper = _videoButton.GetComponentsInChildren <RectTransform>().First(x => x.name == "Wrapper");

            _videoButtonGlow = Instantiate(glow.gameObject, videoWrapper).gameObject.GetComponentInChildren <Image>();

            var hlg = _videoButton.GetComponentsInChildren <HorizontalLayoutGroup>().First(x => x.name == "Content");

            hlg.padding = new RectOffset(3, 2, 2, 2);

            _progressCircle            = videoWrapper.GetComponentsInChildren <Image>().First(x => x.name == "Stroke");
            _progressCircle.type       = Image.Type.Filled;
            _progressCircle.fillMethod = Image.FillMethod.Radial360;
            _progressCircle.fillAmount = 1f;
        }
        public T AddIntSetting <T>(string name, string hintText) where T : IntSettingsController
        {
            var        volumeSettings    = Resources.FindObjectsOfTypeAll <WindowModeSettingsController>().FirstOrDefault();
            GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform);

            newSettingsObject.name = name;

            WindowModeSettingsController volume = newSettingsObject.GetComponent <WindowModeSettingsController>();
            T newToggleSettingsController       = (T)ReflectionUtil.CopyComponent(volume, typeof(IncDecSettingsController), typeof(T), newSettingsObject);

            MonoBehaviour.DestroyImmediate(volume);

            var tmpText = newSettingsObject.GetComponentInChildren <TMP_Text>();

            tmpText.text = name;
            BeatSaberUI.AddHintText(tmpText.rectTransform, hintText);

            return(newToggleSettingsController);
        }
        private void AddButtonToMainMenu(MenuButton button)
        {
            if (buttonsInCurrentRow >= ButtonsPerRow)
            {
                AddRow();
            }

            Button newButton = BeatSaberUI.CreateUIButton(currentRow, "QuitButton", button.onClick, button.text, button.icon);

            newButton.GetComponentInChildren <HorizontalLayoutGroup>().padding = new RectOffset(6, 6, 0, 0);
            newButton.name = button.text;
            if (button.hintText != String.Empty)
            {
                BeatSaberUI.AddHintText(newButton.transform as RectTransform, button.hintText);
            }
            button.buttons.Add(newButton);
            newButton.interactable = button.interactable;
            buttonsInCurrentRow++;
        }
Beispiel #16
0
        public T AddSliderSetting <T>(string name, string hintText, float min, float max, float increment, bool intValues) where T : IncDecSettingsController
        {
            var        volumeSettings    = GetWindowSettings();
            GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform);

            newSettingsObject.name = name;

            SwitchSettingsController volume = newSettingsObject.GetComponent <SwitchSettingsController>();
            T newSliderSettingsController   = (T)ReflectionUtil.CopyComponent(volume, typeof(IncDecSettingsController), typeof(T), newSettingsObject);

            MonoBehaviour.DestroyImmediate(volume);

            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("DecButton").gameObject);
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("ValueText").gameObject);
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("IncButton").gameObject);

            CustomSlider slider = newSliderSettingsController.gameObject.AddComponent <CustomSlider>();

            slider.Scrollbar      = GameObject.Instantiate(Resources.FindObjectsOfTypeAll <HMUI.Scrollbar>().First(s => s.name != "CustomUISlider"), newSettingsObject.transform.Find("Value"), false);
            slider.Scrollbar.name = "CustomUISlider";
            slider.Scrollbar.GetComponentInChildren <TextMeshProUGUI>().enableWordWrapping = false;
            (slider.Scrollbar.transform as RectTransform).sizeDelta = new Vector2(39.5f, 4.5f);
            (slider.Scrollbar.transform as RectTransform).anchorMin = new Vector2(0, 0.5f);


            slider.Scrollbar.numberOfSteps = (int)((max - min) / increment) + 1;
            slider.MinValue   = min;
            slider.MaxValue   = max;
            slider.IsIntValue = intValues;

            var tmpText = newSettingsObject.GetComponentInChildren <TMP_Text>();

            tmpText.text = name;
            if (hintText != String.Empty)
            {
                BeatSaberUI.AddHintText(tmpText.rectTransform, hintText);
            }

            viewController?.AddSubmenuOption(newSettingsObject);
            AddHooks(newSliderSettingsController);
            return(newSliderSettingsController);
        }
Beispiel #17
0
        private void SetupTweaks()
        {
            YouTubeDownloader.Instance.downloadProgress += VideoDownloaderDownloadProgress;

            _videoFlowCoordinator = gameObject.AddComponent <VideoFlowCoordinator>();

            _videoFlowCoordinator.finished += VideoFlowCoordinatorFinished;
            _videoFlowCoordinator.Init();

            _difficultyViewController = Resources.FindObjectsOfTypeAll <BeatmapDifficultyViewController>().FirstOrDefault();
            _difficultyViewController.didSelectDifficultyEvent += DifficultyViewControllerDidSelectDifficultyEvent;

            var _detailViewController = Resources.FindObjectsOfTypeAll <StandardLevelDetailViewController>().First(x => x.name == "StandardLevelDetailViewController");

            RectTransform buttonsRect     = _detailViewController.GetComponentsInChildren <RectTransform>().First(x => x.name == "Buttons");
            var           _playbutton     = buttonsRect.GetComponentsInChildren <Button>().First(x => x.name == "PlayButton");
            var           _practiceButton = buttonsRect.GetComponentsInChildren <Button>().First(x => x.name == "PracticeButton");

            _videoButton      = Instantiate(_practiceButton, buttonsRect.parent);
            _videoButton.name = "VideoButton";
            _videoButton.SetButtonIcon(Base64Sprites.PlayIcon);
            (_videoButton.transform as RectTransform).anchoredPosition = new Vector2(46, -6);
            (_videoButton.transform as RectTransform).sizeDelta        = new Vector2(8, 8);
            _videoButton.onClick.AddListener(delegate() { _videoFlowCoordinator.Present(); });

            _videoButtonHint = BeatSaberUI.AddHintText(_videoButton.transform as RectTransform, "Download a video");

            var glow         = _playbutton.GetComponentsInChildren <RectTransform>().First(x => x.name == "GlowContainer");
            var videoWrapper = _videoButton.GetComponentsInChildren <RectTransform>().First(x => x.name == "Wrapper");

            _videoButtonGlow = Instantiate(glow.gameObject, videoWrapper).gameObject.GetComponentInChildren <Image>();

            var hlg = _videoButton.GetComponentsInChildren <HorizontalLayoutGroup>().First(x => x.name == "Content");

            hlg.padding = new RectOffset(3, 2, 2, 2);

            _progressCircle            = videoWrapper.GetComponentsInChildren <Image>().First(x => x.name == "Stroke");
            _progressCircle.type       = Image.Type.Filled;
            _progressCircle.fillMethod = Image.FillMethod.Radial360;
            _progressCircle.fillAmount = 1f;
        }
Beispiel #18
0
        private void CreateOnlineButton()
        {
            _newVersionText             = BeatSaberUI.CreateText(_mainMenuRectTransform, "A new version of the mod\nis available!", new Vector2(55.5f, 33f));
            _newVersionText.fontSize    = 5f;
            _newVersionText.lineSpacing = -52;
            _newVersionText.gameObject.SetActive(false);

            Button[] mainButtons = Resources.FindObjectsOfTypeAll <RectTransform>().First(x => x.name == "MainButtons" && x.parent.name == "MainMenuViewController").GetComponentsInChildren <Button>();

            foreach (var item in mainButtons)
            {
                (item.transform as RectTransform).sizeDelta = new Vector2(35f, 30f);
            }

            _multiplayerButton = BeatSaberUI.CreateUIButton(_mainMenuRectTransform, "CampaignButton");
            Destroy(_multiplayerButton.GetComponentInChildren <LocalizedTextMeshProUGUI>());
            Destroy(_multiplayerButton.GetComponentInChildren <HoverHint>());
            _multiplayerButton.transform.SetParent(mainButtons.First(x => x.name == "CampaignButton").transform.parent);
            _multiplayerButton.transform.SetAsLastSibling();

            _multiplayerButton.SetButtonText("Online");
            _multiplayerButton.SetButtonIcon(Sprites.onlineIcon);
            BeatSaberUI.AddHintText(_multiplayerButton.transform as RectTransform, "Play with your friends online!");

            _multiplayerButton.onClick.AddListener(delegate()
            {
                try
                {
                    MainFlowCoordinator mainFlow = Resources.FindObjectsOfTypeAll <MainFlowCoordinator>().First();

                    mainFlow.InvokeMethod("PresentFlowCoordinator", modeSelectionFlowCoordinator, null, false, false);
                }
                catch (Exception e)
                {
                    Plugin.log.Critical($"Unable to present flow coordinator! Exception: {e}");
                }
            });
        }
Beispiel #19
0
        public T AddColorPickerSetting <T>(string name, string hintText, Color color, out ColorPickerPreviewClickable clickablePreview) where T : MonoBehaviour
        {
            var        volumeSettings    = Resources.FindObjectsOfTypeAll <SwitchSettingsController>().FirstOrDefault();
            GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform);

            newSettingsObject.name = name;

            SwitchSettingsController volume    = newSettingsObject.GetComponent <SwitchSettingsController>();
            T newColorPickerSettingsController = (T)ReflectionUtil.CopyComponent(volume, typeof(MonoBehaviour), typeof(T), newSettingsObject);

            MonoBehaviour.DestroyImmediate(volume);

            GameObject.Destroy(newSettingsObject.GetComponentInChildren <HorizontalLayoutGroup>());
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("DecButton").gameObject);
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("ValueText").gameObject);
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("IncButton").gameObject);

            ColorPickerPreviewClickable cppc = new GameObject("ColorPickerPreviewClickable").AddComponent <ColorPickerPreviewClickable>();

            cppc.transform.SetParent(newSettingsObject.transform.Find("Value"), false);
            cppc.ImagePreview.color = color;
            (cppc.transform as RectTransform).localScale     = new Vector2(0.06f, 0.06f);
            (cppc.transform as RectTransform).localPosition += new Vector3(3f, 0.1f);
            clickablePreview = cppc;

            var tmpText = newSettingsObject.GetComponentInChildren <TMP_Text>();

            tmpText.text = name;
            if (hintText != String.Empty)
            {
                BeatSaberUI.AddHintText(tmpText.rectTransform, hintText);
            }

            viewController?.AddSubmenuOption(newSettingsObject);
            AddHooks(newColorPickerSettingsController);
            return(newColorPickerSettingsController);
        }
        public static void OnLoad()
        {
            _levelSelectionFlowCoordinator = Resources.FindObjectsOfTypeAll <SoloFreePlayFlowCoordinator>().First();
            if (_levelSelectionFlowCoordinator)
            {
                _levelSelectionNavigationController = _levelSelectionFlowCoordinator.GetPrivateField <DismissableNavigationController>("_navigationController");
            }

            if (_levelSelectionNavigationController)
            {
                if (_songRequestMenu == null)
                {
                    _songRequestMenu = BeatSaberUI.CreateCustomMenu <CustomMenu>("Song Request Queue");
                    _songRequestListViewController = BeatSaberUI.CreateViewController <RequestBotListViewController>();
                    _songRequestMenu.SetMainViewController(_songRequestListViewController, true);
                }

                _requestButton = BeatSaberUI.CreateUIButton(_levelSelectionNavigationController.rectTransform, "QuitButton", new Vector2(60f, 36.8f),
                                                            new Vector2(15.0f, 5.5f), () => { _requestButton.interactable = false; _songRequestMenu.Present(); _requestButton.interactable = true; }, "Song Requests");

                _requestButton.gameObject.GetComponentInChildren <TextMeshProUGUI>().enableWordWrapping = false;
                _requestButton.SetButtonTextSize(2.0f);
                _requestButton.interactable = FinalRequestQueue.Count > 0;
                _requestButton.gameObject.GetComponentInChildren <Image>().color = FinalRequestQueue.Count > 0 ? Color.green : Color.red;
                BeatSaberUI.AddHintText(_requestButton.transform as RectTransform, $"{(!Config.Instance.SongRequestBot ? "To enable the song request bot, look in the Enhanced Twitch Chat settings menu." : "Manage the current request queue")}");
                Plugin.Log("Created request button!");
            }

            SongListUtils.Initialize();

            if (Instance)
            {
                return;
            }
            new GameObject("EnhancedTwitchChatRequestBot").AddComponent <RequestBot>();
        }
Beispiel #21
0
        public static GameObject CreateMaterialSwapPanel(Transform parent, PartEditor.MatList matList, string panelLabel)
        {
            RectTransform newPanel = CreateRectPanel(parent, panelLabel);

            TextMeshProUGUI matNameText = BeatSaberUI.CreateText(newPanel, "mat name", new Vector2(20, 0), new Vector2(30, 10));

            matNameText.alignment = TextAlignmentOptions.Center;
            matNameText.fontSize  = 4;

            HoverHint matHoverHint = BeatSaberUI.AddHintText(matNameText.gameObject.GetComponent <RectTransform>(), "hint");

            LabelTextGroup textGroup = new LabelTextGroup(matNameText, matHoverHint, matList);

            matTextGroups.Add(textGroup);

            //cry
            BeatSaberUI.CreateUIButton(newPanel, "DecButton", new Vector2(0, 0), new Vector2(8, 8), delegate { PartEditor.MoveThroughMatList(-1, matList); });
            BeatSaberUI.CreateUIButton(newPanel, "IncButton", new Vector2(50, 0), new Vector2(8, 8), delegate { PartEditor.MoveThroughMatList(1, matList); });

            //to set name and hint strings
            UpdateMatLabelText(textGroup);

            return(newPanel.gameObject);
        }
Beispiel #22
0
        public static GameObject CreateModelSwapPanel(Transform parent, PartEditor.PartList partList, string panelLabel)
        {
            RectTransform newPanel = CreateRectPanel(parent, panelLabel);

            TextMeshProUGUI partNameText = BeatSaberUI.CreateText(newPanel, "part name", new Vector2(20, 0), new Vector2(30, 10));

            partNameText.alignment = TextAlignmentOptions.Center;
            partNameText.fontSize  = 4;

            HoverHint modelHoverHint = BeatSaberUI.AddHintText(partNameText.gameObject.GetComponent <RectTransform>(), "hint");

            LabelTextGroup textGroup = new LabelTextGroup(partNameText, modelHoverHint, partList);

            partTextGroups.Add(textGroup);

            //cry delegate won't let me pass int as a ref, hence faff with index arrays
            BeatSaberUI.CreateUIButton(newPanel, "DecButton", new Vector2(0, 0), new Vector2(8, 8), delegate { PartEditor.MoveThroughPartList(-1, partList); });
            BeatSaberUI.CreateUIButton(newPanel, "IncButton", new Vector2(50, 0), new Vector2(8, 8), delegate { PartEditor.MoveThroughPartList(1, partList); });

            //to set name and hint strings
            UpdatePartLabelText(textGroup);

            return(newPanel.gameObject);
        }
        public T AddColorPickerSetting <T>(string name, string hintText) where T : SimpleSettingsController
        {
            var        volumeSettings    = Resources.FindObjectsOfTypeAll <WindowModeSettingsController>().FirstOrDefault();
            GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform);

            newSettingsObject.name = name;

            WindowModeSettingsController volume = newSettingsObject.GetComponent <WindowModeSettingsController>();
            T newColorPickerSettingsController  = (T)ReflectionUtil.CopyComponent(volume, typeof(SimpleSettingsController), typeof(T), newSettingsObject);

            MonoBehaviour.DestroyImmediate(volume);

            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("DecButton").gameObject);
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("ValueText").gameObject);
            GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("IncButton").gameObject);

            ColorPickerPreviewClickable cppc = new GameObject("ColorPickerPreviewClickable").AddComponent <ColorPickerPreviewClickable>();

            cppc.ImagePreview.sprite = null;

            //cppc.transform.localScale = new Vector3(sizeDelta.x, sizeDelta.y, colorPicker.transform.localScale.z);
            cppc.transform.SetParent(newSettingsObject.transform.Find("Value"), false);

            //cppc.transform.localScale = new Vector3(0.2f, 0.15f);
            //(cppc.transform as RectTransform).anchorMin = new Vector2(0, 0.5f);
            //(cppc.transform as RectTransform).anchorMax = new Vector2(0, 0.5f);
            //(cppc.transform as RectTransform).anchoredPosition = new Vector2(-50, 0);
            (cppc.transform as RectTransform).sizeDelta = new Vector2(39.5f, 7f);

            var tmpText = newSettingsObject.GetComponentInChildren <TMP_Text>();

            tmpText.text = name;
            BeatSaberUI.AddHintText(tmpText.rectTransform, hintText);

            return(newColorPickerSettingsController);
        }
Beispiel #24
0
        private void FirstActivation()
        {
            RectTransform containerRect = new GameObject("AvatarSettingsContainer", typeof(RectTransform)).transform as RectTransform;

            containerRect.SetParent(rectTransform, false);
            containerRect.anchorMin = new Vector2(0.05f, 0.0f);
            containerRect.anchorMax = new Vector2(0.95f, 1.0f);
            containerRect.sizeDelta = new Vector2(0, 0);

            SubMenu container = new SubMenu(containerRect);

            System.Action <RectTransform, float, float, float, float, float, float> relative_layout =
                (RectTransform rt, float x, float y, float w, float h, float pivotx, float pivoty) =>
            {
                rt.anchorMin        = new Vector2(x, y);
                rt.anchorMax        = new Vector2(x + w, y + h);
                rt.pivot            = new Vector2(pivotx, pivoty);
                rt.sizeDelta        = Vector2.zero;
                rt.anchoredPosition = Vector2.zero;
            };

            gameObject.SetActive(false);

            TextMeshProUGUI text = BeatSaberUI.CreateText(containerRect, "AVATAR SETTINGS (buttons don't work, use the hotkeys)", Vector2.zero);

            text.fontSize  = 6.0f;
            text.alignment = TextAlignmentOptions.Center;
            relative_layout(text.rectTransform, 0f, 0.85f, 1f, 0.166f, 0.5f, 1f);

            var boolFirstPerson = container.AddList("[HOME] Visible In First Person View", new float[] { 0, 1 });

            boolFirstPerson.applyImmediately = true;
            relative_layout(boolFirstPerson.transform as RectTransform, 0, 0.66f, 1, 0.166f, 0, 1f);
            BeatSaberUI.AddHintText(boolFirstPerson.transform as RectTransform, "Allows you to see the avatar inside of VR");

            var boolRotatePreviewAvatar = container.AddList("Rotate Avatar Preview", new float[] { 0, 1 });

            boolRotatePreviewAvatar.applyImmediately = true;
            relative_layout(boolRotatePreviewAvatar.transform as RectTransform, 0, 0.55f, 1, 0.166f, 0, 1f);
            BeatSaberUI.AddHintText(boolRotatePreviewAvatar.transform as RectTransform, "Slowly rotate the preview model");

            var listResizePolicy = container.AddList("[END] Resize Avatars To Player's", new float[] { 0, 1, 2 });

            listResizePolicy.applyImmediately = true;
            relative_layout(listResizePolicy.transform as RectTransform, 0, 0.44f, 1, 0.166f, 0, 1f);
            BeatSaberUI.AddHintText(listResizePolicy.transform as RectTransform, "Use 'Arms Length' to resize the avatar based on your proportions, 'Height' to resize based on your height, and 'Never' to not resize");

            var boolFloorMovePolicy = container.AddList("[Insert] Floor Height Adjust", new float[] { 0, 1 });

            boolFloorMovePolicy.applyImmediately = true;
            relative_layout(boolFloorMovePolicy.transform as RectTransform, 0, 0.33f, 1, 0.166f, 0, 1f);
            BeatSaberUI.AddHintText(boolFloorMovePolicy.transform as RectTransform, "Move the floor to compensate for height when using 'Arms Length' resize, requires CustomPlatforms");

            var labelMeasure = BeatSaberUI.CreateText(containerRect, $"Hand To Hand Length = {Mathf.Ceil(Plugin.Instance.AvatarTailor.PlayerArmLength * 100.0f) / 100.0f}", Vector2.zero);

            relative_layout(labelMeasure.transform as RectTransform, 0f, 0.18f, 0.5f, 0.11f, 0, .5f);
            BeatSaberUI.AddHintText(labelMeasure.transform as RectTransform, "Value used for 'Arms Length' resize, press on the 'MEASURE!' button and T-Pose");
            labelMeasure.fontSize  = 5f;
            labelMeasure.alignment = TextAlignmentOptions.MidlineLeft;

            gameObject.SetActive(true);

            var buttonMeasure = BeatSaberUI.CreateUIButton(containerRect, "QuitButton", () =>
            {
                labelMeasure.text = "Measuring ...";
                Plugin.Instance.AvatarTailor.MeasurePlayerArmLength((value) =>
                {
                    labelMeasure.text = $"Measuring ... {Mathf.Ceil(value * 100.0f) / 100.0f}";
                },
                                                                    (result) =>
                {
                    labelMeasure.text = $"Hand To Hand Length = {Mathf.Ceil(result * 100.0f) / 100.0f}";
                    if (Plugin.Instance.AvatarTailor.ResizePolicy == AvatarTailor.ResizePolicyType.AlignArmLength)
                    {
                        Plugin.Instance.PlayerAvatarManager.ResizePlayerAvatar();
                    }
                });
            }, "Measure!");

            relative_layout(buttonMeasure.transform as RectTransform, 0.65f, 0.18f, 0.35f, 0.11f, .5f, .5f);
            BeatSaberUI.AddHintText(buttonMeasure.transform as RectTransform, "Press this and T-Pose to measure your arms, needed to use 'Arms Length' resize");

            boolFirstPerson.GetTextForValue = (value) => (value != 0f) ? "ON" : "OFF";
            boolFirstPerson.GetValue        = () => Plugin.Instance.FirstPersonEnabled ? 1f : 0f;
            boolFirstPerson.SetValue        = (value) => Plugin.Instance.FirstPersonEnabled = value != 0f;
            boolFirstPerson.Init();

            boolRotatePreviewAvatar.GetTextForValue = (value) => value != 0f ? "ON" : "OFF";
            boolRotatePreviewAvatar.GetValue        = () => Plugin.Instance.RotatePreviewEnabled ? 1f : 0f;
            boolRotatePreviewAvatar.SetValue        = (value) => Plugin.Instance.RotatePreviewEnabled = value != 0f;
            boolRotatePreviewAvatar.Init();

            listResizePolicy.GetTextForValue = (value) => new string[] { "Arms Length", "Height", "Never" }[(int)value];
            listResizePolicy.GetValue        = () => (int)Plugin.Instance.AvatarTailor.ResizePolicy;
            listResizePolicy.SetValue        = (value) =>
            {
                Plugin.Instance.AvatarTailor.ResizePolicy = (AvatarTailor.ResizePolicyType)(int) value;
                Plugin.Instance.PlayerAvatarManager.ResizePlayerAvatar();
            };
            listResizePolicy.Init();

            boolFloorMovePolicy.GetTextForValue = (value) => (value != 0f) ? "ON" : "OFF";
            boolFloorMovePolicy.GetValue        = () => Plugin.Instance.AvatarTailor.FloorMovePolicy == AvatarTailor.FloorMovePolicyType.AllowMove ? 1f : 0f;
            boolFloorMovePolicy.SetValue        = (value) =>
            {
                Plugin.Instance.AvatarTailor.FloorMovePolicy = (value != 0f) ? AvatarTailor.FloorMovePolicyType.AllowMove : AvatarTailor.FloorMovePolicyType.NeverMove;
                Plugin.Instance.PlayerAvatarManager.ResizePlayerAvatar();
            };
            boolFloorMovePolicy.Init();
        }
Beispiel #25
0
        public void Init()
        {
            if (_isInitialized)
            {
                return;
            }

            // since we're using BeatSaverDownloader's votedSong.json file, we need the mod to be present
            if (!Tweaks.BeatSaverDownloaderTweaks.ModLoaded)
            {
                var noModMessage = BeatSaberUI.CreateText(null, "<color=#FFAAAA>Sorry!\n\n<size=80%>This filter requires the BeatSaverDownloader mod\n to be installed.</size></color>", Vector2.zero);
                noModMessage.alignment = TextAlignmentOptions.Center;
                noModMessage.fontSize  = 5.5f;

                Controls[0] = new FilterControl(noModMessage.gameObject, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(80f, 50f), new Vector2(0f, 10f));
            }
            else
            {
                var container = new GameObject("VotedFilterContainer");
                Controls[0] = new FilterControl(container, new Vector2(0f, 0.95f), new Vector2(1f, 0.95f), new Vector2(0.5f, 0.5f), Vector2.zero, Vector2.zero,
                                                delegate()
                {
                    _upvotedToggle.isOn   = _upvotedStagingValue;
                    _noVoteToggle.isOn    = _noVoteStagingValue;
                    _downvotedToggle.isOn = _downvotedStagingValue;
                });

                // blank image assigned to container so it'll have a RectTransform
                var unused = container.AddComponent <Image>();
                unused.color    = new Color(0f, 0f, 0f, 0f);
                unused.material = Utilities.NoGlowMaterial;

                var text = BeatSaberUI.CreateText(container.transform as RectTransform, "Keep Songs That You Voted", Vector2.zero);
                text.fontSize = 5.5f;
                var rt = text.rectTransform;
                rt.anchorMin = new Vector2(0f, 1f);
                rt.anchorMax = rt.anchorMin;
                rt.pivot     = rt.anchorMin;
                BeatSaberUI.AddHintText(text.rectTransform, "Keep songs depending on how you have voted (or not voted)");

                var togglePrefab = Utilities.GetTogglePrefab();

                _upvotedToggle = CreateToggleControl(container.transform as RectTransform, "Upvoted Songs", 0, togglePrefab.toggle);
                _upvotedToggle.onValueChanged.AddListener(delegate(bool value)
                {
                    _upvotedStagingValue = value;
                    SettingChanged?.Invoke();
                });

                _noVoteToggle = CreateToggleControl(container.transform as RectTransform, "Songs With No Vote", 1, togglePrefab.toggle);
                _noVoteToggle.onValueChanged.AddListener(delegate(bool value)
                {
                    _noVoteStagingValue = value;
                    SettingChanged?.Invoke();
                });

                _downvotedToggle = CreateToggleControl(container.transform as RectTransform, "Downvoted Songs", 2, togglePrefab.toggle, false);
                _downvotedToggle.onValueChanged.AddListener(delegate(bool value)
                {
                    _downvotedStagingValue = value;
                    SettingChanged?.Invoke();
                });

                Object.Destroy(togglePrefab.gameObject);
            }

            _isInitialized = true;
        }
Beispiel #26
0
            public KEY(KEYBOARD kb, Vector2 position, string text, float width, float height, Color color)
            {
                value   = text;
                this.kb = kb;

                name     = text;
                mybutton = Button.Instantiate(kb.BaseButton, kb.container, false);

                (mybutton.transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f);
                (mybutton.transform as RectTransform).anchorMax = new Vector2(0.5f, 0.5f);

                TMP_Text txt = mybutton.GetComponentInChildren <TMP_Text>();

                mybutton.ToggleWordWrapping(false);

                mybutton.transform.localScale = new Vector3(kb.scale, kb.scale, 1.0f);
                mybutton.SetButtonTextSize(5f);
                mybutton.SetButtonText(text);
                mybutton.GetComponentInChildren <Image>().color = color;

                if (width == 0)
                {
                    Vector2 v = txt.GetPreferredValues(text);
                    v.x  += 10f;
                    v.y  += 2f;
                    width = v.x;
                }

                // Adjust starting position so button aligns to upper left of current drawing position

                position.x += kb.scale * width / 2;
                position.y -= kb.scale * height / 2;
                (mybutton.transform as RectTransform).anchoredPosition = position;

                (mybutton.transform as RectTransform).sizeDelta = new Vector2(width, height);

                kb.currentposition.x += width * kb.scale + kb.padding;

                mybutton.onClick.RemoveAllListeners();

                mybutton.onClick.AddListener(delegate()
                {
                    if (keyaction != null)
                    {
                        keyaction(this);
                        kb.DrawCursor();
                        return;
                    }

                    if (value.EndsWith("%CR%"))
                    {
                        kb.KeyboardText.text += value.Substring(0, value.Length - 4);
                        kb.Enter(this);
                        kb.DrawCursor();

                        return;
                    }

                    {
                        string x = kb.Shift ? shifted : value;
                        if (x == "")
                        {
                            x = value;
                        }
                        if (kb.Caps)
                        {
                            x = value.ToUpper();
                        }
                        kb.KeyboardText.text += x;
                        kb.DrawCursor();
                    }
                });
                HoverHint _MyHintText = BeatSaberUI.AddHintText(mybutton.transform as RectTransform, value);
            }
        public override void Instantiate()
        {
            var volumeSettings = Resources.FindObjectsOfTypeAll <FormattedFloatListSettingsController>().FirstOrDefault();

            gameObject      = UnityEngine.Object.Instantiate(volumeSettings.gameObject, Container);
            gameObject.name = optionName;
            gameObject.GetComponentInChildren <TMP_Text>().text = optionName;

            // Add a separator for this menu option
            AddSeparator(Container);

            //This magical nonsense is courtesy of Taz and his SettingsUI class
            ListSettingsController volume = gameObject.GetComponent <ListSettingsController>();

            multiSelectController = (ListViewController)ReflectionUtil.CopyComponent(volume, typeof(ListSettingsController), typeof(ListViewController), gameObject);
            UnityEngine.Object.DestroyImmediate(volume);

            multiSelectController.applyImmediately = true;
            multiSelectController.values           = _options.Keys.ToList();
            multiSelectController.SetValue         = OnChange;
            multiSelectController.GetValue         = () =>
            {
                if (GetValue != null)
                {
                    return(GetValue.Invoke());
                }
                return(_options.Keys.ElementAt(0));
            };
            multiSelectController.GetTextForValue = (v) =>
            {
                if (_options.ContainsKey(v))
                {
                    return(_options[v] != null ? _options[v] : v.ToString());
                }
                return("UNKNOWN");
            };
            //Initialize the controller, as if we had just opened the settings menu
            multiSelectController.Init();
            var      value           = multiSelectController.gameObject.transform.Find("Value");
            var      valueText       = value.Find("ValueText");
            TMP_Text valueTextObject = valueText.GetComponent <TMP_Text>();

            valueTextObject.lineSpacing = -50;
            valueTextObject.alignment   = TextAlignmentOptions.CenterGeoAligned;

            var nameText = multiSelectController.gameObject.transform.Find("NameText");

            nameText.localScale = new Vector3(0.85f, 0.85f, 0.85f);
            value.localScale    = new Vector3(0.7f, 0.7f, 0.7f);
            if (hintText != String.Empty)
            {
                BeatSaberUI.AddHintText(nameText as RectTransform, hintText);
            }

            var dec = value.Find("DecButton");

            dec.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);
            var inc = value.Find("IncButton");

            inc.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);
            value.localPosition     -= new Vector3(8, 0.3f);

            gameObject.SetActive(false);
            initialized = true;
        }
        private void CreateOnlineButton()
        {
            _newVersionText             = BeatSaberUI.CreateText(_mainMenuRectTransform, "A new version of the mod\nis available!", new Vector2(55.5f, 33f));
            _newVersionText.fontSize    = 5f;
            _newVersionText.lineSpacing = -52;
            _newVersionText.gameObject.SetActive(false);

            Button[] mainButtons = Resources.FindObjectsOfTypeAll <RectTransform>().First(x => x.name == "MainButtons" && x.parent.name == "MainMenuViewController").GetComponentsInChildren <Button>();

            foreach (var item in mainButtons)
            {
                (item.transform as RectTransform).sizeDelta = new Vector2(35f, 30f);
            }

            _multiplayerButton = BeatSaberUI.CreateUIButton(_mainMenuRectTransform, "SoloFreePlayButton");
            Destroy(_multiplayerButton.GetComponentInChildren <LocalizedTextMeshProUGUI>());
            Destroy(_multiplayerButton.GetComponentInChildren <HoverHint>());
            _multiplayerButton.transform.SetParent(mainButtons.First(x => x.name == "SoloFreePlayButton").transform.parent);
            _multiplayerButton.transform.SetAsLastSibling();

            _multiplayerButton.SetButtonText("Online");
            _multiplayerButton.SetButtonIcon(Sprites.onlineIcon);
            BeatSaberUI.AddHintText(_multiplayerButton.transform as RectTransform, "Play with your friends online!");

            _multiplayerButton.onClick.AddListener(delegate()
            {
                try
                {
                    MainFlowCoordinator mainFlow = Resources.FindObjectsOfTypeAll <MainFlowCoordinator>().First();

                    if (_noUserInfoWarning == null)
                    {
                        var dialogOrig     = ReflectionUtil.GetPrivateField <SimpleDialogPromptViewController>(mainFlow, "_simpleDialogPromptViewController");
                        _noUserInfoWarning = Instantiate(dialogOrig.gameObject).GetComponent <SimpleDialogPromptViewController>();
                    }

                    if (GetUserInfo.GetUserID() == 0 && string.IsNullOrWhiteSpace(GetUserInfo.GetUserName()) || GetUserInfo.GetUserID() == 0)
                    {
                        _noUserInfoWarning.Init("Invalid username and ID", $"Your username and ID are invalid\nMake sure you are logged in", "Go back", "Continue anyway",
                                                (selectedButton) =>
                        {
                            mainFlow.InvokeMethod("DismissViewController", _noUserInfoWarning, null, selectedButton == 1);
                            if (selectedButton == 1)
                            {
                                mainFlow.InvokeMethod("PresentFlowCoordinator", modeSelectionFlowCoordinator, null, true, false);
                            }
                        });

                        mainFlow.InvokeMethod("PresentViewController", _noUserInfoWarning, null, false);
                    }
                    else
                    {
                        mainFlow.InvokeMethod("PresentFlowCoordinator", modeSelectionFlowCoordinator, null, false, false);
                    }
                }
                catch (Exception e)
                {
                    Plugin.log.Critical($"Unable to present flow coordinator! Exception: {e}");
                }
            });
        }
Beispiel #29
0
        public void Init()
        {
            // Buttons
            _backButton = BeatSaberUI.CreateBackButton(rectTransform as RectTransform, delegate() { backButtonPressed?.Invoke(); });

            _listButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(60, 30), new Vector2(30, 8), () =>
            {
                listButtonPressed?.Invoke();
            }, "Search");

            _downloadDeleteButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(60, 20), new Vector2(30, 8), () =>
            {
                downloadDeleteButtonPressed?.Invoke();
            }, "Delete");
            _downloadDeleteButton.GetComponentInChildren <HorizontalLayoutGroup>().padding = new RectOffset(0, 0, 0, 0);

            _previewButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(60, -30), new Vector2(30, 8), () =>
            {
                previewButtonPressed?.Invoke();
            }, "Preview");

            _loopButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(60, -20), new Vector2(30, 8), () =>
            {
                loopButtonPressed?.Invoke();
            }, "Loop");

            _addOffset = BeatSaberUI.CreateUIButton(rectTransform, "QuitButton", new Vector2(71, -10), new Vector2(8, 8), null, "+");
            foreach (StackLayoutGroup stack in _addOffset.GetComponentsInChildren <StackLayoutGroup>())
            {
                stack.childForceExpandHeight = false;
                stack.childForceExpandWidth  = false;
                stack.padding = new RectOffset(0, 0, 0, 0);
            }

            _addOffset.GetComponentInChildren <HorizontalLayoutGroup>().padding = new RectOffset(0, 0, 0, 0);

            _addOffset.GetComponentInChildren <TextMeshProUGUI>().margin      = new Vector4(0, 0, 0, 0);
            (_addOffset.transform.Find("Wrapper") as RectTransform).sizeDelta = new Vector2(8, 8);

            _subOffset = Instantiate(_addOffset, rectTransform);
            (_subOffset.transform as RectTransform).anchoredPosition = new Vector2(49, -10);
            _subOffset.SetButtonText("-");
            _subOffset.onClick.AddListener(() => { subOffsetPressed?.Invoke(); });
            _addOffset.onClick.AddListener(() => { addOffsetPressed?.Invoke(); });

            BeatSaberUI.AddHintText(_addOffset.transform as RectTransform, "Video lags behind music\nStart the video earlier");
            BeatSaberUI.AddHintText(_subOffset.transform as RectTransform, "Video is ahead of music\nStart the video later");

            _offsetText = BeatSaberUI.CreateText(rectTransform, "?", new Vector2(60, -10));
            _offsetText.rectTransform.sizeDelta = new Vector2(14, 8);
            _offsetText.alignment = TextAlignmentOptions.Center;
            _offsetText.color     = Color.white;

            var _offsetTitle = BeatSaberUI.CreateText(rectTransform, "Video Offset (ms)", new Vector2(60, -3));

            _offsetTitle.rectTransform.sizeDelta = new Vector2(30, 8);
            _offsetTitle.alignment = TextAlignmentOptions.Center;

            // Video data
            _thumbnail = Instantiate(Resources.FindObjectsOfTypeAll <Image>().First(x => x.name == "CoverImage"), rectTransform);
            _thumbnail.rectTransform.anchorMin        = new Vector2(0.5f, 1f);
            _thumbnail.rectTransform.anchorMax        = new Vector2(0.5f, 1f);
            _thumbnail.rectTransform.pivot            = new Vector2(0.5f, 1);
            _thumbnail.rectTransform.anchoredPosition = new Vector2(0, -5);
            var height = 30f;
            var width  = 16f / 9f * height;

            _thumbnail.rectTransform.sizeDelta = new Vector2(width, height);
            _thumbnail.preserveAspect          = false;
            _thumbnail.sprite = null;
            _thumbnail.transform.SetAsLastSibling();

            _title                         = BeatSaberUI.CreateText(rectTransform, "TITLE", new Vector2(0, 0));
            _title.alignment               = TextAlignmentOptions.Top;
            _title.maxVisibleLines         = 1;
            _title.fontSize                = 6;
            _title.rectTransform.sizeDelta = new Vector2(100, 10);

            _uploader           = BeatSaberUI.CreateText(rectTransform, "UPLOADER", new Vector2(0, -7));
            _uploader.alignment = TextAlignmentOptions.Left;
            _uploader.color     = Color.white * 0.9f;
            _uploader.rectTransform.sizeDelta = new Vector2(80, 5);

            _duration           = BeatSaberUI.CreateText(rectTransform, "[00:00]", new Vector2(0, -7));
            _duration.alignment = TextAlignmentOptions.Right;
            _duration.color     = Color.white * 0.9f;
            _duration.rectTransform.sizeDelta = new Vector2(80, 5);

            _description = BeatSaberUI.CreateText(rectTransform,
                                                  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                                                  new Vector2(0, -14));
            _description.alignment = TextAlignmentOptions.TopLeft;
            _description.rectTransform.sizeDelta = new Vector2(80, 10);
            _description.enableWordWrapping      = true;
            _description.maxVisibleLines         = 5;

            // Download Progress ring
            var buttonsRect = Resources.FindObjectsOfTypeAll <RectTransform>().First(x => x.name == "PlayButtons");
            var _playbutton = buttonsRect.GetComponentsInChildren <Button>().First(x => x.name == "PlayButton");

            var _progressButton = Instantiate(_playbutton, _thumbnail.transform);

            _progressButton.name = "DownloadProgress";
            (_progressButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
            (_progressButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
            (_progressButton.transform as RectTransform).anchoredPosition = new Vector2(0, 0);
            (_progressButton.transform as RectTransform).pivot            = new Vector2(0.5f, 0.5f);
            (_progressButton.transform as RectTransform).sizeDelta        = new Vector2(18, 18);
            _progressText      = _progressButton.GetComponentInChildren <TextMeshProUGUI>();
            _progressText.text = "100%";
            _progressRingGlow  = _progressButton.GetComponentsInChildren <Image>().First(x => x.name == "Glow");
            Destroy(_progressButton);
            _progressRingGlow.gameObject.SetActive(false);

            var hlg = _progressButton.GetComponentsInChildren <HorizontalLayoutGroup>().First(x => x.name == "Content");

            hlg.padding = new RectOffset(2, 2, 2, 2);

            _progressCircle            = _progressButton.GetComponentsInChildren <Image>().First(x => x.name == "Stroke");
            _progressCircle.type       = Image.Type.Filled;
            _progressCircle.fillMethod = Image.FillMethod.Radial360;
            _progressCircle.fillAmount = 1f;

            _hoverHint = BeatSaberUI.AddHintText(_thumbnail.transform as RectTransform, "Banana banana banana");
        }
        private void CreateDifficultyToggles(Transform parent)
        {
            var gameplayToggle = Utilities.GetTogglePrefab();

            var text = BeatSaberUI.CreateText(parent as RectTransform, "Difficulties To Filter NJS", Vector2.zero, new Vector2(50f, 6f));

            text.rectTransform.anchorMin = new Vector2(0f, 1f);
            text.rectTransform.anchorMax = new Vector2(0f, 1f);
            text.rectTransform.pivot     = new Vector2(0f, 1f);
            text.fontSize = 5.5f;
            BeatSaberUI.AddHintText(text.rectTransform, "Song is kept if at least one of the checked difficulties passes the filter. Songs without a checked difficulty and OST songs are not removed.");

            // easy
            var toggle = CreateToggleFromPrefab(gameplayToggle.toggle, parent, Vector2.zero, new Vector2(0.2f, 0.5f));

            toggle.onValueChanged.AddListener(delegate(bool value)
            {
                _difficultiesStagingValue[0] = value;

                if (_minEnabledStagingValue || _maxEnabledStagingValue)
                {
                    SettingChanged?.Invoke();
                }
            });
            _difficultyToggles[0] = toggle;

            text = BeatSaberUI.CreateText(parent as RectTransform, "Easy", new Vector2(0f, -2f), new Vector2(8f, 4f));
            text.rectTransform.anchorMin = new Vector2(0.1f, 0.5f);
            text.rectTransform.anchorMax = new Vector2(0.1f, 0.5f);
            text.rectTransform.pivot     = new Vector2(0.5f, 0f);
            text.enableWordWrapping      = false;
            text.alignment = TextAlignmentOptions.Bottom;
            text.fontSize  = 3.5f;

            // normal
            toggle = CreateToggleFromPrefab(gameplayToggle.toggle, parent, new Vector2(0.2f, 0f), new Vector2(0.4f, 0.5f));
            toggle.onValueChanged.AddListener(delegate(bool value)
            {
                _difficultiesStagingValue[1] = value;

                if (_minEnabledStagingValue || _maxEnabledStagingValue)
                {
                    SettingChanged?.Invoke();
                }
            });
            _difficultyToggles[1] = toggle;

            text = BeatSaberUI.CreateText(parent as RectTransform, "Normal", new Vector2(0f, -2f), new Vector2(8f, 4f));
            text.rectTransform.anchorMin = new Vector2(0.3f, 0.5f);
            text.rectTransform.anchorMax = new Vector2(0.3f, 0.5f);
            text.rectTransform.pivot     = new Vector2(0.5f, 0f);
            text.enableWordWrapping      = false;
            text.alignment = TextAlignmentOptions.Bottom;
            text.fontSize  = 3.5f;

            // hard
            toggle = CreateToggleFromPrefab(gameplayToggle.toggle, parent, new Vector2(0.4f, 0f), new Vector2(0.6f, 0.5f));
            toggle.onValueChanged.AddListener(delegate(bool value)
            {
                _difficultiesStagingValue[2] = value;

                if (_minEnabledStagingValue || _maxEnabledStagingValue)
                {
                    SettingChanged?.Invoke();
                }
            });
            _difficultyToggles[2] = toggle;

            text = BeatSaberUI.CreateText(parent as RectTransform, "Hard", new Vector2(0f, -2f), new Vector2(8f, 4f));
            text.rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
            text.rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
            text.rectTransform.pivot     = new Vector2(0.5f, 0f);
            text.enableWordWrapping      = false;
            text.alignment = TextAlignmentOptions.Bottom;
            text.fontSize  = 3.5f;

            // expert
            toggle = CreateToggleFromPrefab(gameplayToggle.toggle, parent, new Vector2(0.6f, 0f), new Vector2(0.8f, 0.5f));
            toggle.onValueChanged.AddListener(delegate(bool value)
            {
                _difficultiesStagingValue[3] = value;

                if (_minEnabledStagingValue || _maxEnabledStagingValue)
                {
                    SettingChanged?.Invoke();
                }
            });
            _difficultyToggles[3] = toggle;

            text = BeatSaberUI.CreateText(parent as RectTransform, "Expert", new Vector2(0f, -2f), new Vector2(8f, 4f));
            text.rectTransform.anchorMin = new Vector2(0.7f, 0.5f);
            text.rectTransform.anchorMax = new Vector2(0.7f, 0.5f);
            text.rectTransform.pivot     = new Vector2(0.5f, 0f);
            text.enableWordWrapping      = false;
            text.alignment = TextAlignmentOptions.Bottom;
            text.fontSize  = 3.5f;

            // expert+
            toggle = CreateToggleFromPrefab(gameplayToggle.toggle, parent, new Vector2(0.8f, 0f), new Vector2(1f, 0.5f));
            toggle.onValueChanged.AddListener(delegate(bool value)
            {
                _difficultiesStagingValue[4] = value;

                if (_minEnabledStagingValue || _maxEnabledStagingValue)
                {
                    SettingChanged?.Invoke();
                }
            });
            _difficultyToggles[4] = toggle;

            text = BeatSaberUI.CreateText(parent as RectTransform, "Expert+", new Vector2(0f, -2f), new Vector2(8f, 4f));
            text.rectTransform.anchorMin = new Vector2(0.9f, 0.5f);
            text.rectTransform.anchorMax = new Vector2(0.9f, 0.5f);
            text.rectTransform.pivot     = new Vector2(0.5f, 0f);
            text.enableWordWrapping      = false;
            text.alignment = TextAlignmentOptions.Bottom;
            text.fontSize  = 3.5f;

            Object.Destroy(gameplayToggle.gameObject);
        }