Esempio n. 1
0
        private void UpdateModTagsLabel(bool isClicking)
        {
            var mymod = ModHelpersMod.Instance;

            if (mymod.Data.ModTagsOpened)
            {
                this.RemoveModTagsMessage();

                ModTagsEditorMenuContext.Initialize(false);
                ModTagsModBrowserMenuContext.Initialize(false);
            }

            bool isHoveringModTagsLabel = this.EnableModTagsLabel?.GetOuterDimensions()
                                          .ToRectangle()
                                          .Contains(Main.mouseX, Main.mouseY)
                                          ?? false;

            if (isClicking && isHoveringModTagsLabel)
            {
                mymod.Data.ModTagsOpened = true;

                this.RemoveModTagsMessage();

                ModTagsEditorMenuContext.Initialize(false);
                ModTagsModBrowserMenuContext.Initialize(false);

                Timers.SetTimer("ModHelpersModBrowserActivate", 5, () => {
                    MainMenuHelpers.OpenModBrowserMenu();
                    return(false);
                });
            }
        }
Esempio n. 2
0
        ////////////////

        private ModRecommendsMenuContext() : base(true, false)
        {
            this.RecommendsList = new UIRecommendsList(this, 198f, 132f, 202f, 40f);

            this.DownloadButton          = new UIMenuButton(UITheme.Vanilla, "Download All", 198f, 26f, 202f, 172f);
            this.DownloadButton.OnClick += (evt, elem) => {
                MainMenuHelpers.LoadMenuModDownloads("Recommended", (List <string>) this.RecommendsList.GetModNames());
            };
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the previous active main menu UI object (if any).
        /// </summary>
        /// <returns></returns>
        public static UIState GetPreviousMenuUI()
        {
            var mymod = ModHelpersMod.Instance;

            if (mymod.MenuContextMngr.PreviousMenuUI == 0)
            {
                return(null);
            }
            return(MainMenuHelpers.GetMenuUI(mymod.MenuContextMngr.PreviousMenuUI));
        }
        /// @private
        public override void OnDeactivation()
        {
            UIState ui = MainMenuHelpers.GetMenuUI(this.MenuDefinitionOfContext);

            this.MyElement.Remove();

            UIElement elem = this.GetInsertElem(ui);

            elem.RemoveChild(this.MyElement);
        }
Esempio n. 5
0
        ////////////////

        protected ModTagsEditorMenuContext(MenuUIDefinition menuDef, string contextName)
            : base(menuDef, contextName)
        {
            UIState uiModInfo = MainMenuHelpers.GetMenuUI(menuDef);

            if (uiModInfo == null || uiModInfo.GetType().Name != "UIModInfo")
            {
                throw new ModHelpersException("UI context not UIModInfo, found "
                                              + (uiModInfo?.GetType().Name ?? "null")
                                              + " (" + menuDef + ")");
            }

            this.Manager = new ModTagsEditorManager(this.InfoDisplay, menuDef, uiModInfo);
        }
        public override void OnDeactivation()
        {
            UIState ui = MainMenuHelpers.GetMenuUI(this.MenuDefinitionOfContext);

            if (ui == null)
            {
                LogHelpers.Warn("Invalid UI.");
                return;
            }

            /*UIElement elem = this.GetContainer( ui );
             * if( ui == null ) {
             *      LogHelpers.Alert( "Container element not found for " + ui.GetType().Name );
             *      return;
             * }
             *
             * elem.Recalculate();*/
        }
        ////////////////

        private void SwitchToUI(UIState ui)
        {
            MenuUIDefinition openingUiDef = 0;
            MenuUIDefinition closingUiDef = this.CurrentMenuUI;

            // Out with the old
            if (closingUiDef != 0 && this.Contexts.ContainsKey(closingUiDef))
            {
                foreach ((string ctxName, MenuContext ctx) in this.Contexts[closingUiDef])
                {
                    ctx.Hide(MainMenuHelpers.GetMenuUI(closingUiDef));
                }
            }

            // Validate
            if (ui != null)
            {
                if (!Enum.TryParse(ui.GetType().Name, out openingUiDef))
                {
                    LogHelpers.WarnOnce("Could not get MenuUIDefinition " + ui.GetType().Name);
                    this.CurrentMenuUI = 0;
                    return;
                }
            }
            else
            {
                this.PreviousMenuUI = this.CurrentMenuUI;
                this.CurrentMenuUI  = 0;
            }

            // In with the new
            if (this.Contexts.ContainsKey(openingUiDef))
            {
                foreach (MenuContext ctx in this.Contexts[openingUiDef].Values.ToArray())
                {
                    ctx.ActivateIfInactive(ui);
                    ctx.Show(ui);
                }
            }

            this.PreviousMenuUI = this.CurrentMenuUI;
            this.CurrentMenuUI  = openingUiDef;
        }
        public override void OnDeactivation()
        {
            UIState modBrowserUi = MainMenuHelpers.GetMenuUI(this.MenuDefinitionOfContext);

            if (modBrowserUi?.GetType().Name != "UIModBrowser")
            {
                LogHelpers.Warn("Invalid UI. Expected UIModBrowser, found " + modBrowserUi?.GetType().Name + ".");
                return;
            }

            UIElement elem;

            if (!ReflectionHelpers.Get(modBrowserUi, "_rootElement", out elem) || elem == null)
            {
                LogHelpers.Alert("_rootElement not found for UIModBrowser.");
                return;
            }

            elem.Left.Pixels -= UITagMenuButton.ButtonWidth;

            elem.Recalculate();
        }
        ////////////////

        private void HideAllForCurrentMenuUI()
        {
            if (this.CurrentMenuUI == 0)
            {
                return;
            }

            MenuUIDefinition menuDef = this.CurrentMenuUI;

            if (!this.Contexts.ContainsKey(menuDef))
            {
                LogHelpers.Warn("Missing menu context " + menuDef);
                return;
            }

            IDictionary <string, MenuContext> contexts = this.Contexts[menuDef];

            foreach (MenuContext context in contexts.Values)
            {
                context.Hide(MainMenuHelpers.GetMenuUI(this.CurrentMenuUI));
            }
        }
Esempio n. 10
0
        public override void OnDeactivation()
        {
            UIState modInfoUi = MainMenuHelpers.GetMenuUI(this.MenuDefinitionOfContext);

            if (modInfoUi.GetType().Name != "UIModInfo")
            {
                LogHelpers.Warn("Invalid UI. Expected UIModInfo, found " + modInfoUi.GetType().Name + ".");
                return;
            }

            UIElement elem;

            if (ReflectionHelpers.Get(modInfoUi, "_uIElement", out elem))
            {
                elem.Left.Pixels -= UITagMenuButton.ButtonWidth;

                elem.Recalculate();
            }
            else
            {
                LogHelpers.Warn("Could not get uiElement for mod info tags context " + modInfoUi.GetType().Name);
            }
        }
        ////////////////

        private void ApplyModsFilter()
        {
            UIState menuUi = MainMenuHelpers.GetMenuUI(this.MenuDefinition);

            IList <string> modNames = new List <string>();

            object items;

            if (!ReflectionHelpers.Get(menuUi, "_items", out items))
            {
                LogHelpers.Warn("No 'items' field in ui " + menuUi);
                return;
            }

            var itemsArr = (Array)items.GetType()
                           .GetMethod("ToArray")
                           .Invoke(items, new object[] { });

            for (int i = 0; i < itemsArr.Length; i++)
            {
                object item = itemsArr.GetValue(i);
                string modName;

                if (ReflectionHelpers.Get(item, "ModName", out modName))
                {
                    modNames.Add(modName);
                }
                else
                {
                    LogHelpers.Warn("No 'ModName' field or property in mod browser list ('_items').");
                    return;
                }
            }

            this.FilterModsAsync(menuUi, modNames, this.HandleFilteredMods);
        }
 public static void PromptModDownloads(string packTitle, List <string> modNames)
 {
     MainMenuHelpers.LoadMenuModDownloads(packTitle, modNames);
 }
        ////////////////

        private void InitializeComponents()
        {
            var mymod = ModHelpersMod.Instance;
            UIModControlPanelTab self  = this;
            ModControlPanelLogic logic = this.Logic;
            float top = 0;

            this.Theme.ApplyPanel(this);


            ////////

            var tip = new UIText("To enable issue reports for your mod, ");

            this.Append((UIElement)tip);

            this.TipUrl = new UIWebUrl(this.Theme, "read this.",
                                       "https://forums.terraria.org/index.php?threads/mod-helpers.63670/#modders",
                                       false, 1f);
            this.TipUrl.Left.Set(tip.GetInnerDimensions().Width, 0f);
            this.TipUrl.Top.Set(-2f, 0f);
            this.Append((UIElement)this.TipUrl);

            this.OpenConfigList = new UITextPanelButton(this.Theme, "Edit Configs");
            this.OpenConfigList.Top.Set(top - 8f, 0f);
            this.OpenConfigList.Left.Set(-188f, 1f);
            this.OpenConfigList.Width.Set(160f, 0f);
            this.OpenConfigList.OnClick += (_, __) => {
                MainMenuHelpers.OpenModConfigListUI();
            };
            this.Append(this.OpenConfigList);

            top += 24f;

            ////

            var modListPanel = new UIPanel();

            {
                modListPanel.Top.Set(top, 0f);
                modListPanel.Width.Set(0f, 1f);
                modListPanel.Height.Set(UIModControlPanelTab.ModListHeight, 0f);
                modListPanel.HAlign = 0f;
                modListPanel.SetPadding(4f);
                modListPanel.PaddingTop      = 0.0f;
                modListPanel.BackgroundColor = this.Theme.ListBgColor;
                modListPanel.BorderColor     = this.Theme.ListEdgeColor;
                this.Append((UIElement)modListPanel);

                this.ModListElem = new UIList();
                {
                    this.ModListElem.Width.Set(-25, 1f);
                    this.ModListElem.Height.Set(0f, 1f);
                    this.ModListElem.HAlign      = 0f;
                    this.ModListElem.ListPadding = 4f;
                    this.ModListElem.SetPadding(0f);
                    modListPanel.Append((UIElement)this.ModListElem);

                    top += UIModControlPanelTab.ModListHeight + this.PaddingTop - 8;

                    UIScrollbar scrollbar = new UIScrollbar();
                    {
                        scrollbar.Top.Set(8f, 0f);
                        scrollbar.Height.Set(-16f, 1f);
                        scrollbar.SetView(100f, 1000f);
                        scrollbar.HAlign = 1f;
                        modListPanel.Append((UIElement)scrollbar);
                        this.ModListElem.SetScrollbar(scrollbar);
                    }
                }
            }

            ////

            this.IssueTitleInput = new UITextInputAreaPanel(this.Theme, "Enter title of mod issue", 128);
            this.IssueTitleInput.Top.Set(top, 0f);
            this.IssueTitleInput.Width.Set(0f, 1f);
            this.IssueTitleInput.Height.Pixels = 36f;
            this.IssueTitleInput.HAlign        = 0f;
            this.IssueTitleInput.SetPadding(8f);
            this.IssueTitleInput.Disable();
            this.IssueTitleInput.OnPreTextChange += (_) => {
                self.RefreshIssueSubmitButton();
                return(true);
            };
            this.Append((UIElement)this.IssueTitleInput);

            top += 36f;

            this.IssueBodyInput = new UITextInputAreaPanel(this.Theme, "Describe mod issue");
            this.IssueBodyInput.Top.Set(top, 0f);
            this.IssueBodyInput.Width.Set(0f, 1f);
            this.IssueBodyInput.Height.Pixels = 36f;
            this.IssueBodyInput.HAlign        = 0f;
            this.IssueBodyInput.SetPadding(8f);
            this.IssueBodyInput.Disable();
            this.IssueBodyInput.OnPreTextChange += (_) => {
                self.RefreshIssueSubmitButton();
                return(true);
            };
            this.Append((UIElement)this.IssueBodyInput);

            top += 36f;

            ////

            this.IssueSubmitButton = new UITextPanelButton(this.Theme, "Submit Issue");
            this.IssueSubmitButton.Top.Set(top, 0f);
            this.IssueSubmitButton.Left.Set(0f, 0f);
            this.IssueSubmitButton.Width.Set(200f, 0f);
            this.IssueSubmitButton.Disable();
            this.IssueSubmitButton.OnClick += (_, __) => {
                if (self.AwaitingReport || !self.IssueSubmitButton.IsEnabled)
                {
                    return;
                }
                self.SubmitIssue();
            };
            this.Append(this.IssueSubmitButton);

            top += 26f;

            this.ModLockButton = new UITextPanelButton(this.Theme, UIModControlPanelTab.ModLockTitle);
            this.ModLockButton.Top.Set(top, 0f);
            this.ModLockButton.Left.Set(0f, 0f);
            this.ModLockButton.Width.Set(0f, 1f);
            if (Main.netMode != 0 || !ModHelpersMod.Config.WorldModLockEnable)
            {
                this.ModLockButton.Disable();
            }
            this.ModLockButton.OnClick += (_, __) => {
                if (!self.ModLockButton.IsEnabled)
                {
                    return;
                }
                self.ToggleModLock();
                Main.PlaySound(SoundID.Unlock);
            };
            this.Append(this.ModLockButton);

            this.RefreshModLockButton();

            top += 26f;

            this.CleanupModTiles = new UITextPanelButton(this.Theme, "Cleanup unused mod tiles");
            this.CleanupModTiles.Top.Set(top, 0f);
            this.CleanupModTiles.Left.Set(0f, 0f);
            this.CleanupModTiles.Width.Set(0f, 1f);
            if (Main.netMode != 0)
            {
                this.CleanupModTiles.Disable();
            }
            this.CleanupModTiles.OnClick += (_, __) => {
                if (!self.CleanupModTiles.IsEnabled)
                {
                    return;
                }

                int cleaned = 0;

                for (int i = 0; i < Main.maxTilesX; i++)
                {
                    for (int j = 0; j < Main.maxTilesY; j++)
                    {
                        Tile tile = Framing.GetTileSafely(i, j);
                        if (TileHelpers.IsAir(tile))
                        {
                            continue;
                        }
                        ModTile modTile = ModContent.GetModTile(tile.type);
                        if (modTile == null)
                        {
                            continue;
                        }

                        if (modTile.mod == null || modTile is MysteryTile)
                        {
                            TileHelpers.KillTile(i, j, false, false);
                            cleaned++;
                        }
                    }
                }

                Main.NewText(cleaned + " modded tiles cleaned up.", Color.Lime);
            };
            this.Append(this.CleanupModTiles);

            top += 32f;

            ////

            /*var modrec_url = new UIWebUrl( this.Theme, "Need mods?", "https://sites.google.com/site/terrariamodsuggestions/" );
             * modrecUrl.Top.Set( top, 0f );
             * modrecUrl.Left.Set( 0f, 0f );
             * this.InnerContainer.Append( modrecUrl );
             *
             * var serverbrowser_url = new UIWebUrl( this.Theme, "Lonely?", "https://forums.terraria.org/index.php?threads/server-browser-early-beta.68346/" );
             * serverbrowser_url.Top.Set( top, 0f );
             * this.InnerContainer.Append( serverbrowser_url );
             * serverbrowser_url.Left.Set( -serverbrowser_url.GetDimensions().Width * 0.5f, 0.5f );*/

            string supportMsg = UIModControlPanelTab.SupportMessages[this.RandomSupportTextIdx];

            this.SupportUrl = new UIWebUrl(this.Theme, supportMsg, "https://www.patreon.com/hamstar0", false);
            this.SupportUrl.Top.Set(top, 0f);
            this.Append(this.SupportUrl);
            //this.SupportUrl.Left.Set( -this.SupportUrl.GetDimensions().Width, 1f );
            this.SupportUrl.Left.Set(-this.SupportUrl.GetDimensions().Width * 0.5f, 0.5f);
        }