@@ -16,7 +16,9 @@ namespace StardewMods.ArchaeologyHouseContentManagementHelper.Framework.Services
16
16
/// </summary>
17
17
internal class CollectionPageExMenuService
18
18
{
19
- private IMonitor monitor ;
19
+ private readonly IMonitor monitor ;
20
+ private readonly IModEvents events ;
21
+
20
22
private bool running ;
21
23
22
24
private bool ignoreMenuChanged ;
@@ -32,6 +34,7 @@ internal class CollectionPageExMenuService
32
34
public CollectionPageExMenuService ( )
33
35
{
34
36
monitor = ModEntry . CommonServices . Monitor ;
37
+ events = ModEntry . CommonServices . Events ;
35
38
36
39
collectionsPageTabIndex = - 1 ;
37
40
@@ -48,39 +51,41 @@ public void Start()
48
51
49
52
running = true ;
50
53
51
- MenuEvents . MenuChanged += MenuEvents_MenuChanged ;
52
- MenuEvents . MenuClosed += MenuEvents_MenuClosed ;
54
+ events . Display . MenuChanged += OnMenuChanged ;
53
55
}
54
56
55
57
public void Stop ( )
56
58
{
57
59
if ( ! running )
58
60
{
59
- monitor . Log ( "[LostBookFoundDialogService ] is not running or has already been stopped!" , LogLevel . Info ) ;
61
+ monitor . Log ( "[CollectionPageExMenuService ] is not running or has already been stopped!" , LogLevel . Info ) ;
60
62
return ;
61
63
}
62
64
63
- MenuEvents . MenuChanged -= MenuEvents_MenuChanged ;
64
- MenuEvents . MenuClosed -= MenuEvents_MenuClosed ;
65
+ events . Display . MenuChanged -= OnMenuChanged ;
65
66
66
67
running = false ;
67
68
}
68
69
69
- private void MenuEvents_MenuClosed ( object sender , EventArgsClickableMenuClosed e )
70
+ private void OnMenuChanged ( object sender , MenuChangedEventArgs e )
70
71
{
71
- ignoreMenuChanged = false ;
72
-
73
- if ( e . PriorMenu is LetterViewerMenu && switchBackToCollectionsMenu )
72
+ // menu closed
73
+ if ( e . NewMenu == null )
74
74
{
75
- ignoreMenuChanged = true ;
76
- Game1 . activeClickableMenu = savedGameMenu ;
75
+ ignoreMenuChanged = false ;
76
+
77
+ if ( e . OldMenu is LetterViewerMenu && switchBackToCollectionsMenu )
78
+ {
79
+ ignoreMenuChanged = true ;
80
+ Game1 . activeClickableMenu = savedGameMenu ;
81
+ }
82
+
83
+ switchBackToCollectionsMenu = false ;
84
+ return ;
77
85
}
78
86
79
- switchBackToCollectionsMenu = false ;
80
- }
87
+ // menu changed or opened
81
88
82
- private void MenuEvents_MenuChanged ( object sender , EventArgsClickableMenuChanged e )
83
- {
84
89
if ( e . NewMenu is GameMenu gameMenu && ! ignoreMenuChanged )
85
90
{
86
91
List < IClickableMenu > pages = ModEntry . CommonServices . ReflectionHelper . GetField < List < IClickableMenu > > ( gameMenu , "pages" ) . GetValue ( ) ;
@@ -96,13 +101,14 @@ private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged
96
101
}
97
102
}
98
103
99
- else if ( e . NewMenu is LetterViewerMenu && e . PriorMenu is GameMenu gameMenu2 )
104
+ else if ( e . NewMenu is LetterViewerMenu && e . OldMenu is GameMenu gameMenu2 )
100
105
{
101
106
switchBackToCollectionsMenu = true ;
102
107
savedGameMenu = gameMenu2 ;
103
108
}
104
109
105
110
ignoreMenuChanged = false ;
111
+
106
112
}
107
113
}
108
114
}
0 commit comments