/// <summary> /// Attaches the delegates that handle the button click and draw method of the tab /// </summary> private void MenuOpened(object sender, EventArgsClickableMenuChanged e) { // copied from MenuClosed GraphicsEvents.OnPostRenderGuiEvent -= RenderTab; GraphicsEvents.OnPreRenderGuiEvent -= HandleJunimo; if (this.tab != null) { this.tab.RemoveListeners(); this.tab = null; } if (this.page != null) { if (e.PriorMenu is GameMenu) { List <IClickableMenu> oldpages = ModEntry.helper.Reflection.GetField <List <IClickableMenu> >((e.PriorMenu as GameMenu), "pages").GetValue(); oldpages.Remove(this.page); } this.page.RemoveListeners(true); this.page = null; ModSettings.pageIndex = null; } if (!(e.NewMenu is GameMenu)) { this.tab = null; this.page = null; ModSettings.pageIndex = null; return; } GameMenu menu = (GameMenu)e.NewMenu; List <IClickableMenu> pages = ModEntry.helper.Reflection.GetField <List <IClickableMenu> >(menu, "pages").GetValue(); var options = pages.Find(x => { return(x is OptionsPage); }); int width = options.width; //List<ClickableComponent> tabs = ModEntry.helper.Reflection.GetPrivateField<List<ClickableComponent>>(menu, "tabs").GetValue(); this.page = new ModOptionsPage(this, menu.xPositionOnScreen, menu.yPositionOnScreen, width, menu.height); ModSettings.pageIndex = pages.Count; pages.Add(page); bool infoSuiteInstalled = Mod.Helper.ModRegistry.IsLoaded("Cdaragorn.UiInfoSuite"); int tabLocation = infoSuiteInstalled ? 9 : 11; this.tab = new ModOptionsTab(this, new Rectangle(menu.xPositionOnScreen + Game1.tileSize * tabLocation, menu.yPositionOnScreen + IClickableMenu.tabYPositionRelativeToMenuY + Game1.tileSize, Game1.tileSize, Game1.tileSize)); GraphicsEvents.OnPostRenderGuiEvent -= RenderTab; GraphicsEvents.OnPostRenderGuiEvent += RenderTab; GraphicsEvents.OnPreRenderGuiEvent -= HandleJunimo; GraphicsEvents.OnPreRenderGuiEvent += HandleJunimo; }
/// <summary> /// Removes the delegates that handle the button click and draw method of the tab /// </summary> private void MenuClosed(object sender, EventArgsClickableMenuClosed e) { GraphicsEvents.OnPostRenderGuiEvent -= RenderTab; GraphicsEvents.OnPreRenderGuiEvent -= HandleJunimo; if (this.tab != null) { this.tab.RemoveListeners(); this.tab = null; } if (this.page != null) { if (e.PriorMenu is GameMenu) { List <IClickableMenu> pages = ModEntry.helper.Reflection.GetField <List <IClickableMenu> >((e.PriorMenu as GameMenu), "pages").GetValue(); pages.Remove(this.page); } this.page.RemoveListeners(true); this.page = null; ModSettings.pageIndex = null; } }