Exemplo n.º 1
0
        public void Init(Sprite icon, string name, string version, string author, string description, PluginLoader.PluginMetadata updateInfo, PluginManifest.LinksObject links = null)
        {
            Icon        = icon;
            Name        = name;
            Version     = version;
            Author      = author;
            Description = description;
            UpdateInfo  = updateInfo;

            if (rowTransformOriginal == null)
            {
                rowTransformOriginal = MenuButtonUI.Instance.GetPrivateField <RectTransform>("menuButtonsOriginal");
            }

            // i also have no clue why this is necessary
            rectTransform.anchorMin = new Vector2(0f, 0f);
            rectTransform.anchorMax = new Vector2(0.5f, 1f);

            var go = new GameObject("Info View", typeof(RectTransform));

            go.SetActive(false);
            go.AddComponent <RectMask2D>();
            view = go.AddComponent <ModInfoView>();
            var rt = view.transform as RectTransform;

            rt.SetParent(transform);
            rt.anchorMin        = new Vector2(0f, 0f);
            rt.anchorMax        = new Vector2(1f, 1f);
            rt.anchoredPosition = new Vector2(0f, 0);
            view.Init(this);
            go.SetActive(true);

            SetupLinks(links);
        }
        public void Init(Sprite icon, string name, string version, string author, string description, PluginLoader.PluginMetadata updateInfo, PluginManifest.LinksObject links = null, bool showEnDis = false, ModListFlowCoordinator mlfc = null)
        {
            showEnableDisable      = showEnDis;
            Plugin.OnConfigChaned -= OptHideButton;

            Icon        = icon;
            Name        = name;
            Version     = version;
            Author      = author;
            Description = description;
            UpdateInfo  = updateInfo;

            enabled = !PluginManager.IsDisabled(updateInfo);

            flowController = mlfc;

            if (rowTransformOriginal == null)
            {
                rowTransformOriginal = MenuButtonUI.Instance.GetPrivateField <RectTransform>("menuButtonsOriginal");
            }

            // i also have no clue why this is necessary
            rectTransform.anchorMin = new Vector2(0f, 0f);
            rectTransform.anchorMax = new Vector2(0.5f, 1f);

            var go = new GameObject("Info View", typeof(RectTransform));

            go.SetActive(false);
            go.AddComponent <RectMask2D>();
            view = go.AddComponent <ModInfoView>();
            var rt = view.transform as RectTransform;

            rt.SetParent(transform);
            rt.anchorMin        = new Vector2(0f, 0f);
            rt.anchorMax        = new Vector2(1f, 1f);
            rt.anchoredPosition = new Vector2(0f, 0);
            view.Init(this);
            go.SetActive(true);

            if (showEnDis)
            {
                restartMessage          = BeatSaberUI.CreateText(rectTransform, "A restart is required to apply", new Vector2(11f, 33.5f));
                restartMessage.fontSize = 4f;
                restartMessage.gameObject.SetActive(false);

                enableDisableButton = BeatSaberUI.CreateUIButton(rectTransform, "CreditsButton", new Vector2(33, 32), new Vector2(25, 10), ToggleEnable);
                enableDisableButton.GetComponentInChildren <StartMiddleEndButtonBackgroundController>().SetMiddleSprite();
                UpdateButtonText();

                Plugin.OnConfigChaned += OptHideButton;
                OptHideButton(Plugin.config.Value);
            }

            SetupLinks(links);
        }
        public void Init(Sprite icon, string name, string version, string author, string description, PluginLoader.PluginMetadata updateInfo, PluginManifest.LinksObject links = null)
        {
            Icon        = icon;
            Name        = name;
            Version     = version;
            Author      = author;
            Description = description;
            UpdateInfo  = updateInfo;

            if (rowTransformOriginal == null)
            {
                rowTransformOriginal = MenuButtonUI.Instance.GetPrivateField <RectTransform>("menuButtonsOriginal");
            }

            // i also have no clue why this is necessary
            rectTransform.anchorMin = new Vector2(0f, 0f);
            rectTransform.anchorMax = new Vector2(0.5f, 1f);

            var go = new GameObject("Info View", typeof(RectTransform));

            go.SetActive(false);
            go.AddComponent <RectMask2D>();
            view = go.AddComponent <ModInfoView>();
            var rt = view.transform as RectTransform;

            rt.SetParent(transform);
            rt.anchorMin        = new Vector2(0f, 0f);
            rt.anchorMax        = new Vector2(1f, 1f);
            rt.anchoredPosition = new Vector2(0f, 0);
            view.Init(this);
            go.SetActive(true);

            if (links != null)
            {
                rowTransform                  = Instantiate(rowTransformOriginal, rectTransform);
                rowTransform.anchorMin        = new Vector2(0f, 0f);
                rowTransform.anchorMax        = new Vector2(1f, .15f);
                rowTransform.anchoredPosition = new Vector2(-3.5f, -2f);

                foreach (Transform child in rowTransform)
                {
                    child.name = string.Empty;
                    Destroy(child.gameObject);
                }

                if (links.ProjectHome != null)
                {
                    linkHomeButton = BeatSaberUI.CreateUIButton(rowTransform, "QuitButton", buttonText: "Home",
                                                                onClick: () => Process.Start(links.ProjectHome.ToString()));
                    linkHomeButton.GetComponentInChildren <HorizontalLayoutGroup>().padding = new RectOffset(6, 6, 0, 0);
                }
                if (links.ProjectSource != null)
                {
                    linkSourceButton = BeatSaberUI.CreateUIButton(rowTransform, "QuitButton", buttonText: "Source",
                                                                  onClick: () => Process.Start(links.ProjectSource.ToString()));
                    linkSourceButton.GetComponentInChildren <HorizontalLayoutGroup>().padding = new RectOffset(6, 6, 0, 0);
                }
                if (links.Donate != null)
                {
                    linkDonateButton = BeatSaberUI.CreateUIButton(rowTransform, "QuitButton", buttonText: "Donate",
                                                                  onClick: () => Process.Start(links.Donate.ToString()));
                    linkDonateButton.GetComponentInChildren <HorizontalLayoutGroup>().padding = new RectOffset(6, 6, 0, 0);
                }
            }
        }