Exemplo n.º 1
0
        private void Update()
        {
            UIState ui = Main.MenuUI.CurrentState;

            if (ui == null)
            {
                return;
            }

            string ui_name = ui.GetType().Name;

            if (!this.Loaders.ContainsKey(ui_name))
            {
                return;
            }

            if (this.Loaders.ContainsKey(ui_name))
            {
                foreach (Action <UIState> loader in this.Loaders[ui_name].Values)
                {
                    loader(ui);
                }

                this.CachedMenus[ui_name] = ui;
                this.Loaders.Remove(ui_name);
            }
        }
        private void LoadUI(UIState ui)
        {
            string prevUiName = this.CurrentMenuUI?.Item1;
            string currUiName = ui?.GetType().Name;

            this.PreviousMenuUI = this.CurrentMenuUI;

            if (prevUiName != null && this.Contexts.ContainsKey(prevUiName))
            {
                var contexts = this.Contexts[prevUiName].Values;

                foreach (MenuContext ctx in contexts)
                {
                    ctx.Hide(this.CurrentMenuUI.Item2);
                }
                //this.Unloaders.Remove( prev_ui_name );
            }

            if (ui == null)
            {
                this.CurrentMenuUI = null;
                return;
            }

            if (this.Contexts.ContainsKey(currUiName))
            {
                foreach (MenuContext ctx in this.Contexts[currUiName].Values)
                {
                    ctx.Show(ui);
                }
            }

            this.CurrentMenuUI = Tuple.Create(currUiName, ui);
        }
Exemplo n.º 3
0
        ////

        /// <summary>
        /// Gets the shown description text from the given mod-representing UI, if applicable.
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public static bool GetModDescriptionFromCurrentMenuUI(out string output)
        {
            UIState modUI = Main.MenuUI.CurrentState;

            if (modUI.GetType().Name != "UIModInfo")
            {
                output = "Not currently viewing mod info.";
                return(false);
            }

            UIPanel msgBox;

            if (modUI == null || !ReflectionHelpers.Get(modUI, "_modInfo", out msgBox))
            {
                output = "No modInfo field.";
                return(false);
            }

            string modDesc;

            if (!ReflectionHelpers.Get(msgBox, "text", out modDesc))
            {
                output = "No modInfo.text field.";
                return(false);
            }

            output = modDesc;
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the mod name of a mod-representing menu UI (sometimes needs the previous UI for context).
        /// </summary>
        /// <param name="prevUi"></param>
        /// <param name="currUi"></param>
        /// <returns></returns>
        public static string GetModName(UIState prevUi, UIState currUi)
        {
            // = uiType.GetField( "_localMod", BindingFlags.NonPublic | BindingFlags.Instance );
            object localmod;                    // <- is a LocalMod class

            if (!ReflectionHelpers.Get(currUi, "_localMod", out localmod))
            {
                LogHelpers.Warn("No '_localMod' field in " + currUi.GetType());
                return(null);
            }

            if (localmod != null)
            {
                return(ModMenuHelpers.GetLocalMod(localmod).name);
            }
            else
            {
                if (prevUi?.GetType().Name == "UIModBrowser")
                {
                    return(ModMenuHelpers.GetSelectedModBrowserModName(prevUi));
                }
            }

            LogHelpers.Alert("No mod loaded.");
            return(null);
        }
Exemplo n.º 5
0
        public static string GetModName(UIState prevUi, UIState currUi)
        {
            Type      uiType          = currUi.GetType();
            FieldInfo uiLocalmodField = uiType.GetField("localMod", BindingFlags.NonPublic | BindingFlags.Instance);

            if (uiLocalmodField == null)
            {
                LogHelpers.Warn("No 'localMod' field in " + uiType);
                return(null);
            }

            object localmod = uiLocalmodField.GetValue(currUi);

            if (localmod != null)
            {
                return(ModMenuHelpers.GetLocalMod(localmod).name);
            }
            else
            {
                if (prevUi?.GetType().Name == "UIModBrowser")
                {
                    return(ModMenuHelpers.GetSelectedModBrowserModName(prevUi));
                }
            }

            LogHelpers.Alert("No mod loaded.");
            return(null);
        }
Exemplo n.º 6
0
        ////////////////

        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(MainMenuLibraries.GetMenuUI(closingUiDef));
                }
            }

            // Validate
            if (ui != null)
            {
                if (!Enum.TryParse(ui.GetType().Name, out openingUiDef))
                {
                    if (ModLibsUIConfig.Instance.DebugModeMenuInfo)
                    {
                        LogLibraries.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 static UIElement GetMenuContainerOuter(UIState ui)
        {
            Type      uiType          = ui.GetType();
            FieldInfo uiOuterBoxField = uiType.GetField("uIElement", BindingFlags.Instance | BindingFlags.NonPublic);
            UIElement uiOuterBox      = (UIElement)uiOuterBoxField.GetValue(ui);

            return(uiOuterBox);
        }
        private void ApplyModBrowserModInfoBindings(UIState modBrowserUi, UIList uiModList)
        {
            if (modBrowserUi?.GetType().Name != "UIModBrowser")
            {
                throw new ModHelpersException("Invalid UIModBrowser");
            }

            object modList;

            if (!ReflectionHelpers.Get(uiModList, "_items", out modList) || modList == null)
            {
                throw new ModHelpersException("Invalid modList._items");
            }

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

            for (int i = 0; i < itemsArr.Length; i++)
            {
                var item = (UIElement)itemsArr.GetValue(i);
                if (item == null)
                {
                    LogHelpers.Warn("Invalid modList._item[" + i + "] (out of " + itemsArr.Length + ")");
                    continue;
                }

                //string modName;
                //if( !ReflectionHelpers.GetField( item, "mod", out modName ) || modName == null ) {
                //	throw new Exception( "Invalid modList._item["+i+"].mod" );
                //}

                UIElement modInfoButton;
                if (!ReflectionHelpers.Get(item, "_moreInfoButton", out modInfoButton) || modInfoButton == null)
                {
                    LogHelpers.Alert("Invalid modList._item[" + i + "]._moreInfoButton");
                    continue;
                }

                MouseEvent modInfoButtonClick = (_, __) => {
                    if (!ReflectionHelpers.Set(modBrowserUi, "SelectedItem", item))
                    {
                        LogHelpers.Alert("Could not set selected item from the mod browser");
                    }
                };

                modInfoButton.OnClick += modInfoButtonClick;
                LoadHooks.AddModUnloadHook(() => {
                    try {
                        modInfoButton.OnClick -= modInfoButtonClick;
                    } catch { }
                });
            }
        }
        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();
        }
Exemplo n.º 10
0
        ////////////////

        public override void OnActivationForModTags(UIState ui)
        {
            if (ui.GetType().Name != "UIModInfo")
            {
                LogHelpers.Warn("Invalid UI. Expected UIModInfo, found " + ui.GetType().Name + ".");
                return;
            }

            UIElement elem;

            if (ReflectionHelpers.Get(ui, "_uIElement", out elem))
            {
                elem.Left.Pixels += UITagMenuButton.ButtonWidth;
                elem.Top.Set(80f, 0f);
                elem.Height.Set(-88f, 1f);

                elem.Recalculate();
            }
            else
            {
                LogHelpers.Warn("Could not get uiElement for mod info tags context " + ui.GetType().Name);
            }
        }
Exemplo n.º 11
0
 public void SetInventory()
 {
     if (currentState.GetType() != typeof(InventoryState))
     {
         Debug.Log("Changing to inventorystate");
         ChangeState(new InventoryState(this));
     }
     else
     {
         Debug.Log("Changing to lobbystate");
         ChangeState(new LobbyState(this));
     }
     //inventory.SetActive(!inventory.activeSelf);
 }
Exemplo n.º 12
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);
            }
        }
        ////////////////

        public override void OnActivationForModTags(UIState ui)
        {
            if (ui.GetType().Name != "UIModBrowser")
            {
                LogHelpers.Warn("Invalid UI. Expected UIModBrowser, found " + ui.GetType().Name + ".");
                return;
            }

            UIElement elem;

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

            elem.Left.Pixels += UITagMenuButton.ButtonWidth;

            elem.Top.Set(80f, 0f);
            elem.Height.Set(-88f, 1f);

            elem.Recalculate();
        }
        private void Update()
        {
            UIState ui = Main.MenuUI.CurrentState;

            string prevUiName = this.CurrentMenuUI?.Item1;
            string currUiName = ui?.GetType().Name;

            if (prevUiName == currUiName)
            {
                return;
            }

            this.LoadUI(ui);
        }
Exemplo n.º 15
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 OnActivationForSession(UIState ui)
        {
            UIElement elem = this.GetContainer(ui);

            if (elem == null)
            {
                LogHelpers.Alert("Container element not found for " + ui.GetType().Name);
                return;
            }

            elem.Top.Set(80f, 0f);
            elem.Height.Set(-88f, 1f);

            elem.Recalculate();
        }
Exemplo n.º 17
0
        /// <summary>
        /// Gets the "outer" container element (the element as positioned on the screen) of a menu's UI class.
        /// </summary>
        /// <param name="ui"></param>
        /// <returns></returns>
        public static UIElement GetMenuContainerOuter(UIState ui)
        {
            UIElement elem;

            if (!ReflectionLibraries.Get(ui, "uIElement", out elem) || elem == null)
            {
                LogLibraries.AlertOnce("No uiElement for " + ui?.GetType().Name);
                return(null);
            }

            return(elem);

            //Type uiType = ui.GetType();
            //FieldInfo uiOuterBoxField = uiType.GetField( "uIElement", BindingFlags.Instance | BindingFlags.NonPublic );
            //UIElement uiOuterBox = (UIElement)uiOuterBoxField.GetValue( ui );
            //
            //return uiOuterBox;
        }
Exemplo n.º 18
0
        ////////////////

        /// <summary>
        /// Adds a piece of menu content to a menu "context" (menu page) by name.
        /// </summary>
        /// <param name="context"></param>
        public static void AddMenuContext(MenuContext context)
        {
            var mymod = ModHelpersMod.Instance;
            MenuUIDefinition menuDef = context.MenuDefinitionOfContext;

            IDictionary <string, MenuContext> contexts = mymod.MenuContextMngr.GetContexts(menuDef);

            contexts[context.ContextName] = context;

            UIState ui = Main.MenuUI.CurrentState;
            string  currUiContextName = ui?.GetType().Name;

            if (Enum.GetName(typeof(MenuUIDefinition), menuDef) == currUiContextName)
            {
                context.ActivateIfInactive(ui);
                context.Show(ui);
            }
        }
Exemplo n.º 19
0
        ////////////////

        /// <summary>
        /// Retrieves the file data for a given mod within a given mod-representing menu UI (typically the Mod Info menu page).
        /// </summary>
        /// <param name="ui"></param>
        /// <returns></returns>
        public static TmodFile GetModFile(UIState ui)
        {
            FieldInfo uiLocalmodField;            // = uiType.GetField( "_localMod", BindingFlags.NonPublic | BindingFlags.Instance );

            if (!ReflectionHelpers.Get(ui, "_localMod", out uiLocalmodField) || uiLocalmodField == null)
            {
                LogHelpers.Warn("No '_localMod' field in " + ui.GetType());
                return(null);
            }

            object localmod = uiLocalmodField.GetValue(ui);

            if (localmod != null)
            {
                return(ModMenuHelpers.GetLocalMod(localmod));
            }

            LogHelpers.Alert("No mod loaded.");
            return(null);
        }
        ////////////////

        public static void AddMenuContext(string uiClassName, string contextName, MenuContext context)
        {
            var mymod = ModHelpersMod.Instance;

            if (!mymod.MenuContextMngr.Contexts.ContainsKey(uiClassName))
            {
                mymod.MenuContextMngr.Contexts[uiClassName] = new Dictionary <string, MenuContext>();
            }
            mymod.MenuContextMngr.Contexts[uiClassName][contextName] = context;

            context.OnContexualize(uiClassName, contextName);

            UIState ui         = Main.MenuUI.CurrentState;
            string  currUiName = ui?.GetType().Name;

            if (uiClassName == currUiName)
            {
                context.Show(ui);
            }
        }
Exemplo n.º 21
0
        ////

        private static string GetSelectedModBrowserModName(UIState modBrowserUi)
        {
            object modDownloadItem;

            if (!ReflectionHelpers.Get(modBrowserUi, "SelectedItem", out modDownloadItem) || modDownloadItem == null)
            {
                LogHelpers.Warn("No 'selectedItem' list item in " + modBrowserUi.GetType().ToString());
                return(null);
            }

            string modName;

            if (!ReflectionHelpers.Get(modDownloadItem, "ModName", out modName))
            {
                LogHelpers.Warn("Invalid 'mod' data in mod browser listed entry.");
                return(null);
            }

            return(modName);
        }
Exemplo n.º 22
0
        ////////////////

        public static TmodFile GetLocalMod(UIState ui)
        {
            Type      uiType          = ui.GetType();
            FieldInfo uiLocalmodField = uiType.GetField("localMod", BindingFlags.NonPublic | BindingFlags.Instance);

            if (uiLocalmodField == null)
            {
                LogHelpers.Warn("No 'localMod' field in " + uiType);
                return(null);
            }

            object localmod = uiLocalmodField.GetValue(ui);

            if (localmod != null)
            {
                return(ModMenuHelpers.GetLocalMod(localmod));
            }

            LogHelpers.Alert("No mod loaded.");
            return(null);
        }
Exemplo n.º 23
0
        ////

        /// <summary>
        /// Gets the shown description text from the given mod-representing UI, if applicable.
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public static bool GetModDescriptionFromCurrentMenuUI(out string output)
        {
            UIState modUI = Main.MenuUI.CurrentState;

            if (modUI == null)
            {
                output = "No current UI state found.";
                return(false);
            }
            if (modUI.GetType().Name != "UIModInfo")
            {
                output = "Not currently viewing mod info (or no such UI found).";
                return(false);
            }

            UIPanel msgBox;

            if (!ReflectionLibraries.Get(modUI, "_modInfo", out msgBox))
            {
                output = "No _modInfo field.";
                return(false);
            }

            string modDesc;

            if (!ReflectionLibraries.Get(msgBox, "_text", out modDesc))
            {
                if (!ReflectionLibraries.Get(msgBox, "text", out modDesc))
                {
                    output = "No modInfo._text or text field.";
                    return(false);
                }
            }

            output = modDesc;
            return(true);
        }
Exemplo n.º 24
0
        private void Update()
        {
            UIState ui = Main.MenuUI.CurrentState;
            string  prevUiName, currUiName;

            if (this.CurrentMenuUI == 0)
            {
                prevUiName = null;
            }
            else
            {
                MenuUIDefinition prevUiDef = this.CurrentMenuUI;
                prevUiName = Enum.GetName(typeof(MenuUIDefinition), prevUiDef);
            }

            currUiName = ui?.GetType().Name;

            if (prevUiName == currUiName)
            {
                return;
            }

            this.SwitchToUI(ui);
        }
        ////////////////

        /// <summary>
        /// Adds a piece of menu content to a menu "context" (menu page) by name.
        /// </summary>
        /// <param name="context"></param>
        public static void AddMenuContext(MenuContext context)
        {
            var menuCtxMngr = ModContent.GetInstance <MenuContextServiceManager>();

            if (menuCtxMngr == null)
            {
                return;
            }

            MenuUIDefinition menuDef = context.MenuDefinitionOfContext;

            IDictionary <string, MenuContext> contexts = menuCtxMngr.GetContexts(menuDef);

            contexts[context.ContextName] = context;

            UIState ui = Main.MenuUI.CurrentState;
            string  currUiContextName = ui?.GetType().Name;

            if (Enum.GetName(typeof(MenuUIDefinition), menuDef) == currUiContextName)
            {
                context.ActivateIfInactive(ui);
                context.Show(ui);
            }
        }
Exemplo n.º 26
0
 void OnStateChanged(UIState state)
 {
     Log.MessageFormat("New UI State: {0}", LogTags.UI, state.GetType());
     UpdateControls();
 }