internal void SubmitTags()
        {
            if (string.IsNullOrEmpty(this.CurrentModName))
            {
                this.CurrentModName = ModMenuHelpers.GetModName(MenuContextService.GetPreviousMenuUI(), MenuContextService.GetCurrentMenuUI())
                                      ?? "";
                if (string.IsNullOrEmpty(this.CurrentModName))
                {
                    throw new HamstarException("Invalid mod name.");
                }
            }

            Action <string> onSuccess = delegate(string output) {
                this.InfoDisplay?.SetText(output, Color.Lime);
                ErrorLogger.Log("Mod info submit result: " + output);
            };

            Action <Exception, string> onFail = (e, output) => {
                this.InfoDisplay?.SetText("Error: " + (string.IsNullOrEmpty(output)?e.Message:output), Color.Red);
                LogHelpers.Log(e.ToString());
            };

            ISet <string> newTags = this.GetTagsOfState(1);

            // Update snapshot of tags for the given mod (locally)
            if (this.AllModTagsSnapshot != null)
            {
                this.AllModTagsSnapshot[this.CurrentModName] = newTags;
            }

            PostModInfo.SubmitModInfo(this.CurrentModName, newTags, onSuccess, onFail);

            this.FinishButton.Lock();
            this.ResetButton.Lock();
        }
Example #2
0
        ////////////////

        private void ShowGeneral(UIState ui)
        {
            string modName = ModMenuHelpers.GetModName(MenuContextService.GetCurrentMenuUI(), ui);

            this.InfoDisplay.SetDefaultText("");

            if (modName == null)
            {
                LogHelpers.Warn("Could not load mod tags; no mod found");
            }
            else
            {
                this.ResetUIState(modName);
                this.SetCurrentMod(ui, modName);
                this.RecalculateMenuObjects();
            }


            UIElement elem;

            if (ReflectionHelpers.Get(ui, "uIElement", out elem))
            {
                elem.Left.Pixels += UITagButton.ColumnWidth;
                elem.Recalculate();
            }
        }
Example #3
0
        ////////////////

        private void PopulateList(string modName)
        {
            string currModName = ModMenuHelpers.GetModName(MenuContextService.GetPreviousMenuUI(),
                                                           this.MyUI ?? MenuContextService.GetCurrentMenuUI());

            if (modName != currModName)
            {
                return;
            }

            this.RecommendsList.Clear();

            string err = "";
            IList <Tuple <string, string> > recommends = this.GetRecommendsFromActiveMod(modName) ??
                                                         this.GetRecommendsFromUI(modName, ref err);

            if (string.IsNullOrEmpty(err))
            {
                this.RecommendsList.AddModEntriesAsync(modName, recommends.Take(ModRecommendsMenuContext.Limit));
            }
            else
            {
                LogHelpers.Log("!ModHelpers.ModRecommendsMenuContext.PopulateList - " + err);
            }
        }
        public void SubmitTags()
        {
            if (string.IsNullOrEmpty(this.CurrentModName))
            {
                UIState prevMenuUI = MenuContextService.GetPreviousMenuUI();
                UIState currMenuUI = MenuContextService.GetCurrentMenuUI();
                this.CurrentModName = ModMenuHelpers.GetModName(prevMenuUI, currMenuUI) ?? "";

                if (string.IsNullOrEmpty(this.CurrentModName))
                {
                    throw new ModHelpersException("Invalid mod name.");
                }
            }

            Action <Exception, string> onError = (e, output) => {
                this.SetInfoText("Error: " + (string.IsNullOrEmpty(output) ? e.Message : output), Color.Red);
                LogHelpers.Log(e.ToString());
            };

            ISet <string> newTags = this.GetTagsWithGivenState(1);

            // Update snapshot of tags for the given mod (locally)
            if (this.AllModTagsSnapshot != null)
            {
                this.AllModTagsSnapshot[this.CurrentModName] = newTags;
            }

            PostModInfo.SubmitModInfo(this.CurrentModName, newTags, onError, this.PostSubmitTags);

            ModTagsManager.RecentTaggedMods.Add(this.CurrentModName);
        }
Example #5
0
        public override void OnContexualize(string uiClassName, string contextName)
        {
            base.OnContexualize(uiClassName, contextName);

            var recomWidgetCtx = new WidgetMenuContext(this.RecommendsList, false);
            var dlWidgetCtx    = new WidgetMenuContext(this.DownloadButton, false);

            MenuContextService.AddMenuContext(uiClassName, contextName + " Recommendations List", recomWidgetCtx);
            MenuContextService.AddMenuContext(uiClassName, contextName + " Download Button", dlWidgetCtx);
        }
Example #6
0
        public static void Initialize()
        {
            if (ModHelpersMod.Instance.Config.DisableModMenuUpdates)
            {
                return;
            }

            var ctx = new ModUpdatesMenuContext();

            MenuContextService.AddMenuContext("UIMods", "ModHelpers: Mod Updates", ctx);
        }
Example #7
0
        ////////////////

        public static void Initialize()
        {
            if (ModHelpersMod.Instance.Config.DisableModRecommendations)
            {
                return;
            }

            var ctx = new ModRecommendsMenuContext();

            MenuContextService.AddMenuContext("UIModInfo", "ModHelpers: Mod Recommendations", ctx);
        }
        public static void Initialize()
        {
            if (ModHelpersMod.Instance.Config.DisableModTags)
            {
                return;
            }

            var ctx = new ModBrowserTagsMenuContext();

            MenuContextService.AddMenuContext("UIModBrowser", "ModHelpers: Mod Browser", ctx);
        }
Example #9
0
        public static void Initialize()
        {
            if (ModHelpersMod.Config.DisableModMenuUpdates)
            {
                return;
            }

            var ctx = new ModUpdatesMenuContext(MenuUIDefinition.UIMods, "ModHelpers: Mod Updates");

            MenuContextService.AddMenuContext(ctx);
        }
Example #10
0
        ////

        public override void OnContexualize(string uiClassName, string contextName)
        {
            base.OnContexualize(uiClassName, contextName);

            var hiddenWidgetCtx       = new WidgetMenuContext(this.HiddenPanel, false);
            var finishButtonWidgetCtx = new WidgetMenuContext(this.FinishButton, false);
            var resetButtonWidgetCtx  = new WidgetMenuContext(this.ResetButton, false);

            MenuContextService.AddMenuContext(uiClassName, contextName + " Hidden", hiddenWidgetCtx);
            MenuContextService.AddMenuContext(uiClassName, contextName + " Tag Finish Button", finishButtonWidgetCtx);
            MenuContextService.AddMenuContext(uiClassName, contextName + " Tag Reset Button", resetButtonWidgetCtx);
        }
        public static void Initialize(bool onModLoad)
        {
            if (ModHelpersMod.Config.DisableModTags)
            {
                return;
            }

            if (!onModLoad)
            {
                var ctx = new ModTagsModBrowserMenuContext(MenuUIDefinition.UIModBrowser, "ModHelpers: Mod Browser");
                MenuContextService.AddMenuContext(ctx);
            }
        }
Example #12
0
        ////////////////

        public void AddModEntriesAsync(string forModName, IEnumerable <Tuple <string, string> > recomMods)
        {
            foreach (var recomMod in recomMods)
            {
                string recomModName       = recomMod.Item1;
                string recommendedBecause = recomMod.Item2;

                Mod mod = ModLoader.GetMod(recomModName);

                this.AddRawModEntry(mod?.DisplayName, recomModName, recommendedBecause);
            }

            Promises.AddValidatedPromise <ModInfoListPromiseArguments>(GetModInfo.ModInfoListPromiseValidator, (args) => {
                string currModName = ModMenuHelpers.GetModName(MenuContextService.GetPreviousMenuUI(),
                                                               this.MenuContext.MyUI ?? MenuContextService.GetCurrentMenuUI());

                // Validate we're in the same UI
                if (this.MenuContext.MyUI.GetType().Name != "UIModInfo")
                {
                    return(false);
                }
                // Validate we're viewing the mod we started with
                if (forModName != currModName)
                {
                    return(false);
                }

                this.List.RemoveAllChildren();
                this.ModNameList.Clear();

                foreach (var recomMod in recomMods)
                {
                    string recomModName       = recomMod.Item1;
                    string recommendedBecause = recomMod.Item2;

                    if (args.ModInfo.ContainsKey(recomModName))
                    {
                        this.AddModEntry(args.ModInfo[recomModName].DisplayName, recomModName, recommendedBecause);
                    }
                    else
                    {
                        this.AddRawModEntry(null, recomModName, recommendedBecause);
                    }
                }

                return(false);
            });

            this.EmptyText.Remove();
            this.Recalculate();
        }
        ////////////////

        private UIElement GetInsertElem(UIState ui)
        {
            if (this.IsInner)
            {
                UIElement uiOuterContainer = MenuContextService.GetMenuContainerOuter(ui);
                UIElement uiInnerContainer = MenuContextService.GetMenuContainerInner(uiOuterContainer);

                return(MenuContextService.GetMenuContainerInsertPoint(uiInnerContainer));
            }
            else
            {
                return(ui);               //uiOuterContainer;
            }
        }
Example #14
0
        ////////////////

        public override void Show(UIState ui)
        {
            base.Show(ui);

            string modName = ModMenuHelpers.GetModName(MenuContextService.GetCurrentMenuUI(), ui);

            if (modName == null)
            {
                LogHelpers.Log("Could not load mod recommendations; no mod found.");
                return;
            }

            this.PopulateList(modName);
        }
        public override void OnContexualize(string uiClassName, string contextName)
        {
            base.OnContexualize(uiClassName, contextName);

            int i = 0;

            foreach (UITagButton button in this.TagButtons.Values)
            {
                var buttonWidgetCtx = new WidgetMenuContext(button, false);

                MenuContextService.AddMenuContext(uiClassName, contextName + " Tag " + i, buttonWidgetCtx);
                i++;
            }
        }
        ////////////////

        public override void ApplyMenuContext(MenuUIDefinition menuDef, string baseContextName)
        {
            base.ApplyMenuContext(menuDef, baseContextName);

            var finishButtonWidgetCtx = new WidgetMenuContext(menuDef,
                                                              baseContextName + " Tag Finish Button",
                                                              this.EditButton,
                                                              false);
            var hiddenWidgetCtx = new WidgetMenuContext(menuDef,
                                                        baseContextName + " Hidden",
                                                        this.HiddenPanel,
                                                        false);

            MenuContextService.AddMenuContext(hiddenWidgetCtx);
            MenuContextService.AddMenuContext(finishButtonWidgetCtx);
        }
        public override void OnContexualize(string uiClassName, string contextName)
        {
            base.OnContexualize(uiClassName, contextName);

            var blankRecomPanel    = new UIMenuPanel(UITheme.Vanilla, 198f, 132f, 202f, 40f);
            var blankDlButtonPanel = new UIMenuPanel(UITheme.Vanilla, 198f, 26f, 202f, 172f);

            //var blankButtonWidgetCtx = new WidgetMenuContext( this.BlankButton, false );
            var resetButtonWidgetCtx = new WidgetMenuContext(this.ResetButton, false);
            var blankRecomWidgetCtx  = new WidgetMenuContext(blankRecomPanel, false);
            var blankDlWidgetCtx     = new WidgetMenuContext(blankDlButtonPanel, false);

            //MenuContextService.AddMenuContext( uiClassName, contextName + " Tag Blank Button", blankButtonWidgetCtx );
            MenuContextService.AddMenuContext(uiClassName, contextName + " Tag Reset Button", resetButtonWidgetCtx);
            MenuContextService.AddMenuContext(uiClassName, contextName + " Blank Recommendations List", blankRecomWidgetCtx);
            MenuContextService.AddMenuContext(uiClassName, contextName + " Blank Download Button", blankDlWidgetCtx);
        }
        /// <summary>
        /// Loads the mod browser menu.
        /// </summary>
        public static void OpenModBrowserMenu()
        {
            Type interfaceType = ReflectionHelpers.GetMainAssembly()
                                 .GetType("Terraria.ModLoader.UI.Interface");

            int modBrowserMenuMode;

            if (!ReflectionHelpers.Get(interfaceType, null, "modBrowserID", out modBrowserMenuMode))
            {
                LogHelpers.Warn("Could not switch to mod browser menu context.");
                return;
            }

            Main.PlaySound(SoundID.MenuTick);
            Main.menuMode = modBrowserMenuMode;

            UIState modBrowserUi;

            if (!ReflectionHelpers.Get(interfaceType, null, "modBrowser", out modBrowserUi))
            {
                LogHelpers.Warn("Could not acquire mod browser UI.");
                return;
            }

            Timers.SetTimer("ModHelpersModDownloadPrompt", 5, () => {
                if (MenuContextService.GetCurrentMenuUI()?.GetType().Name != "UIModBrowser")
                {
                    return(false);
                }

                bool isLoading;
                if (!ReflectionHelpers.Get(modBrowserUi, "loading", out isLoading))
                {
                    return(false);
                }

                if (isLoading)
                {
                    return(true);
                }

                ModMenuHelpers.ApplyModBrowserFilter("", false, new List <string>());
                return(false);
            });
        }
        public override void OnContexualize(string uiClassName, string contextName)
        {
            if (this.DisplayInfo)
            {
                WidgetMenuContext widgetCtx;

                if (MenuContextService.GetMenuContext(uiClassName, "ModHelpers: Info Display") == null)
                {
                    widgetCtx = new WidgetMenuContext(this.InfoDisplay, false);
                    MenuContextService.AddMenuContext(uiClassName, "ModHelpers: Info Display", widgetCtx);
                }
                else
                {
                    widgetCtx        = (WidgetMenuContext)MenuContextService.GetMenuContext(uiClassName, "ModHelpers: Info Display");
                    this.InfoDisplay = (UIInfoDisplay)widgetCtx.MyElement;
                }
            }
        }
        private static void InitializeOpenConfigButton()
        {
            var button = new UITextPanelButton(UITheme.Vanilla, "Open Mod Config Folder");

            button.Top.Set(11f, 0f);
            button.Left.Set(-104f, 0.5f);
            button.Width.Set(208f, 0f);
            button.Height.Set(20f, 0f);
            button.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
                string fullpath = Main.SavePath + Path.DirectorySeparatorChar + HamstarHelpersConfigData.RelativePath;

                try {
                    Process.Start(fullpath);
                } catch (Exception) { }
            };

            var buttonWidgetCtx = new WidgetMenuContext(button, true);

            MenuContextService.AddMenuContext("UIMods", "ModHelpers: Mod Menu Config Folder Button", buttonWidgetCtx);
        }
        public static void Initialize()
        {
            if (ModHelpersMod.Config.DisableModMenuTweaks)
            {
                return;
            }

            MenuTweaksMenuContext ctx;

            ctx = new MenuTweaksMenuContext(MenuUIDefinition.UIMods, "ModHelpers: Mods Menu Tweaks");
            MenuContextService.AddMenuContext(ctx);

            ctx = new MenuTweaksMenuContext(MenuUIDefinition.UIModPacks, "ModHelpers: Mod Packs Menu Tweaks");
            MenuContextService.AddMenuContext(ctx);

            ctx = new MenuTweaksMenuContext(MenuUIDefinition.UIModSources, "ModHelpers: Mod Sources Menu Tweaks");
            MenuContextService.AddMenuContext(ctx);

            ctx = new MenuTweaksMenuContext(MenuUIDefinition.UIModConfig, "ModHelpers: Mod Config Menu Tweaks");
            MenuContextService.AddMenuContext(ctx);
        }
        ////////////////

        /// @private
        public sealed override void OnActivation(UIState ui)
        {
            var menuDef = this.MenuDefinitionOfContext;

            if (this.DisplayInfo)
            {
                WidgetMenuContext widgetCtx;

                if (MenuContextService.GetMenuContext(menuDef, "ModLibsUI: Info Display") == null)
                {
                    widgetCtx = new WidgetMenuContext(menuDef, "ModLibsUI: Info Display", this.InfoDisplay, false);
                    MenuContextService.AddMenuContext(widgetCtx);
                }
                else
                {
                    widgetCtx        = (WidgetMenuContext)MenuContextService.GetMenuContext(menuDef, "ModLibsUI: Info Display");
                    this.InfoDisplay = (UIInfoDisplay)widgetCtx.MyElement;
                }
            }

            this.OnActivationForSession(ui);
        }
Example #23
0
        ////////////////

        private static void _Draw(GameTime gt)
        {
            if (!Main.gameMenu)
            {
                return;
            }
            if (Main.spriteBatch == null)
            {
                return;
            }

            var mymod = ModHelpersMod.Instance;

            if (mymod == null || mymod.Config == null || mymod.Config.DisableSupportLinks || Main.MenuUI == null)
            {
                return;
            }

            try {
                if (Main.MenuUI.CurrentState != null)
                {
                    Type uiType = Main.MenuUI.CurrentState.GetType();

                    if (uiType.Name != "UIMods" && MenuContextService.ContainsMenuContexts(uiType.Name))
                    {
                        return;
                    }
                }

                bool _;
                XnaHelpers.DrawBatch((sb) => {
                    mymod.SupportInfo?.Update();
                    mymod.SupportInfo?.Draw(sb);
                }, out _);
            } catch (Exception e) {
                LogHelpers.LogOnce(e.ToString());
            }
        }
        public override void Show(UIState ui)
        {
            base.Show(ui);

            UIState prevUi = MenuContextService.GetCurrentMenuUI();

            if (prevUi == ui)
            {
                prevUi = MenuContextService.GetPreviousMenuUI();
            }

            string modName = ModMenuHelpers.GetModName(prevUi, ui);

            this.InfoDisplay.SetDefaultText("");
            this.MyManager.MyTagsUI.ResetTagButtonOnStates(true);

            if (modName == null)
            {
                LogHelpers.Warn("Could not load mod tags; no mod found");
                return;
            }

            this.MyManager.SetCurrentModAsync(modName);
        }
Example #25
0
        ////////////////

        public virtual void ApplyMenuContext(MenuUIDefinition menuDef, string baseContextName)
        {
            var thisWidgetCtx = new WidgetMenuContext(menuDef, baseContextName + " Tags Panel", this, false);

            MenuContextService.AddMenuContext(thisWidgetCtx);

            int i = 0;

            foreach (UIMenuButton categoryButton in this.CategoryButtons.Values)
            {
                var buttonWidgetCtx = new WidgetMenuContext(menuDef,
                                                            baseContextName + " Tag Category " + i,
                                                            categoryButton,
                                                            false);
                MenuContextService.AddMenuContext(buttonWidgetCtx);
                i++;
            }

            i = 0;
            foreach (UITagMenuButton tagButton in this.TagButtons.Values)
            {
                var buttonWidgetCtx = new WidgetMenuContext(menuDef,
                                                            baseContextName + " Tag " + i,
                                                            tagButton,
                                                            false);
                MenuContextService.AddMenuContext(buttonWidgetCtx);
                i++;
            }

            var resetButtonWidgetCtx = new WidgetMenuContext(menuDef,
                                                             baseContextName + " Tag Reset Button",
                                                             this.ResetButton,
                                                             false);

            MenuContextService.AddMenuContext(resetButtonWidgetCtx);
        }
        /// <summary>
        /// Loads the mod browser menu with a given set of mods to one-click bulk download
        /// (via. `ModMenuHelpers.ApplyModBrowserFilter(...)`).
        /// </summary>
        /// <param name="packTitle">Name of the set.</param>
        /// <param name="modNames">Mod (internal) names of the set.</param>
        public static void OpenModBrowserWithDownloadList(string packTitle, List <string> modNames)
        {
            Type interfaceType = ReflectionHelpers.GetMainAssembly()
                                 .GetType("Terraria.ModLoader.UI.Interface");

            int modBrowserMenuMode;

            if (!ReflectionHelpers.Get(interfaceType, null, "modBrowserID", out modBrowserMenuMode))
            {
                LogHelpers.Warn("Could not switch to mod browser menu context.");
                return;
            }

            Main.PlaySound(SoundID.MenuTick);
            Main.menuMode = modBrowserMenuMode;

            UIState modBrowserUi;

            if (!ReflectionHelpers.Get(interfaceType, null, "modBrowser", out modBrowserUi))
            {
                LogHelpers.Warn("Could not acquire mod browser UI.");
                return;
            }

            Timers.SetTimer("ModHelpersModDownloadPrompt", 5, () => {
                if (MenuContextService.GetCurrentMenuUI()?.GetType().Name != "UIModBrowser")
                {
                    return(false);
                }

                bool isLoading;
                if (!ReflectionHelpers.Get(modBrowserUi, "loading", out isLoading))
                {
                    return(false);
                }

                if (isLoading)
                {
                    return(true);
                }

                ModMenuHelpers.ApplyModBrowserFilter(packTitle, true, modNames);
                return(false);
            });

            /*Assembly tmlAsm = typeof( ModLoader ).Assembly;
             * Type interfaceType = tmlAsm.GetType( "Interface" );
             *
             * Type uiModDlType = tmlAsm.GetType( "UIModDownloadItem" );
             * object uiModDl = Activator.CreateInstance( uiModDlType, "ModName", "0.0.0", "hamstar", "", ModSide.Both, "", "http://javid.ddns.net/tModLoader/download.php?Down=mods/HamstarHelpers.tmod", 0, 0, "", false, false, null );
             * //UIModDownloadItem modItem = new UIModDownloadItem( displayname, name, version, author, modreferences, modside, modIconURL, download, downloads, hot, timeStamp, update, updateIsDowngrade, installed );
             * items.Add( modItem );
             *
             * Interface.downloadMods.SetDownloading( packTitle );
             * Interface.downloadMods.SetModsToDownload( modFilter, items );
             * Interface.modBrowser.updateNeeded = true;
             *
             * int menuMode;
             * if( !ReflectionHelpers.GetField<int>( interfaceType, null, "downloadModsID", out menuMode ) ) {
             *      LogHelpers.Log( "Could not switch to downloads menu." );
             *      return;
             * }
             * Main.PlaySound( SoundID.MenuTick );
             * Main.menuMode = menuMode;*/
        }