コード例 #1
0
        private void ToggleModOptions(object sender, MenuChangedEventArgs e)
        {
            // Remove from old menu
            if (e.OldMenu != null)
            {
                _helper.Events.Display.RenderedActiveMenu -= DrawButton;
                if (_modOptionsPageButton != null)
                {
                    _modOptionsPageButton.OnLeftClicked -= OnButtonLeftClicked;
                }

                if (e.OldMenu is GameMenu gameMenu)
                {
                    List <IClickableMenu> tabPages = gameMenu.pages;
                    tabPages.Remove(_modOptionsPage);
                }
            }

            // Add to new menu
            if (e.NewMenu is GameMenu newMenu)
            {
                if (_modOptionsPageButton == null)
                {
                    _modOptionsPage       = new ModOptionsPage(_optionsElements, _helper.Events);
                    _modOptionsPageButton = new ModOptionsPageButton(_helper.Events);
                }

                _helper.Events.Display.RenderedActiveMenu += DrawButton;
                _modOptionsPageButton.OnLeftClicked       += OnButtonLeftClicked;
                List <IClickableMenu> tabPages = newMenu.pages;

                _modOptionsTabPageNumber = tabPages.Count;
                tabPages.Add(_modOptionsPage);
            }
        }
コード例 #2
0
        private void AddModOptionsToMenu(object sender, EventArgsClickableMenuChanged e)
        {
            if (Game1.activeClickableMenu is GameMenu)
            {
                if (_modOptionsPageButton == null)
                {
                    _modOptionsPage       = new ModOptionsPage(_optionsElements);
                    _modOptionsPageButton = new ModOptionsPageButton();
                }
                GraphicsEvents.OnPostRenderGuiEvent += DrawButton;
                _modOptionsPageButton.OnLeftClicked += OnButtonLeftClicked;
                List <IClickableMenu> tabPages = _helper.Reflection.GetField <List <IClickableMenu> >(Game1.activeClickableMenu, "pages").GetValue();

                _modOptionsTabPageNumber = tabPages.Count;
                tabPages.Add(_modOptionsPage);
            }
        }