Пример #1
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);
        }
Пример #3
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));
            }
        }
Пример #8
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);
        }