public void PrepareMapping()
 {
     HandlerMapping.Add(typeof(GameMenu), typeof(GameMenuHandler));
     HandlerMapping.Add(typeof(ShopMenu), typeof(ShopMenuHandler));
     HandlerMapping.Add(typeof(ItemGrabMenu), typeof(ItemGrabMenuHandler));
     HandlerMapping.Add(typeof(CraftingPage), typeof(CraftingMenuHandler));
     HandlerMapping.Add(typeof(JunimoNoteMenu), typeof(JunimoNoteMenuHandler));
 }
Beispiel #2
0
 public bool TryRegisterMenu(Type menuType)
 {
     if (HandlerMapping.TryGetHandler(menuType, out IMenuHandler handler))
     {
         HandlerMapping.Add(menuType, handler);
         Log.Debug($"API: Registered {menuType}, handled by {handler.GetType()}");
         return(true);
     }
     Log.Error($"API: Don't know how to handle {menuType}, not registered!");
     return(false);
 }
        /// <summary>Raised after a game menu is opened, closed, or replaced.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnMenuChanged(object sender, MenuChangedEventArgs e)
        {
            // menu closed
            if (e.NewMenu == null)
            {
                // close the current handler and unsubscribe from the events
                if (this.CurrentMenuHandler != null)
                {
                    //Log.Trace("[OnMenuClosed] Closing current menu handler");
                    this.CurrentMenuHandler.Close();
                    this.CurrentMenuHandler = null;

                    UnsubscribeHandlerEvents();
                }
                return;
            }

            // ignore resize event
            if (e.OldMenu?.GetType() == e.NewMenu?.GetType() && this.WasResizeEvent)
            {
                this.WasResizeEvent = false;
                return;
            }
            this.WasResizeEvent = false; // Reset

            // switch the currently handler to the one for the new menu type
            var nuMenu = e.NewMenu;

            Log.TraceIfD($"Menu changed from {e.OldMenu} to {nuMenu}");
            if (
                HandlerMapping.TryGetHandler(nuMenu.GetType(), out IMenuHandler handler) ||
                HandlerMapping.TryGetHandler(nuMenu.ToString(), out handler)
                )
            {
                Log.TraceIfD($"{nuMenu} intercepted");
                // Close the current one if still open, it's likely invalid
                if (this.CurrentMenuHandler != null)
                {
                    DequeueMenuHandlerOpener();
                    this.CurrentMenuHandler.Close();
                }
                EnqueueMenuHandlerOpener(nuMenu, handler);
            }
            else
            {
                Log.TraceIfD($"{nuMenu} not intercepted, don't know how");
            }
        }
 private void InterceptOtherMods()
 {
     foreach (var kvp in OtherMods.AsEnumerable())
     {
         string modID = kvp.Key;
         if (!Mod.Registry.IsLoaded(modID))
         {
             continue;
         }
         Log.Debug($"{modID} detected, registering its menus:");
         foreach (var t in kvp.Value)
         {
             HandlerMapping.Add(t.Item1, t.Item2);
             Log.Debug($"  Registered {t.Item1} to be handled by {t.Item2.Name}");
         }
     }
 }