Skip to content

Commit 7c84234

Browse files
committed
ArchaeologyHouseMode: Added support for SMAP 3.0.
1 parent 7ba4dcd commit 7c84234

File tree

6 files changed

+63
-42
lines changed

6 files changed

+63
-42
lines changed

ArchaeologyHouseContentManagementHelper/Framework/Services/CollectionPageExMenuService.cs

+23-17
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ namespace StardewMods.ArchaeologyHouseContentManagementHelper.Framework.Services
1616
/// </summary>
1717
internal class CollectionPageExMenuService
1818
{
19-
private IMonitor monitor;
19+
private readonly IMonitor monitor;
20+
private readonly IModEvents events;
21+
2022
private bool running;
2123

2224
private bool ignoreMenuChanged;
@@ -32,6 +34,7 @@ internal class CollectionPageExMenuService
3234
public CollectionPageExMenuService()
3335
{
3436
monitor = ModEntry.CommonServices.Monitor;
37+
events = ModEntry.CommonServices.Events;
3538

3639
collectionsPageTabIndex = -1;
3740

@@ -48,39 +51,41 @@ public void Start()
4851

4952
running = true;
5053

51-
MenuEvents.MenuChanged += MenuEvents_MenuChanged;
52-
MenuEvents.MenuClosed += MenuEvents_MenuClosed;
54+
events.Display.MenuChanged += OnMenuChanged;
5355
}
5456

5557
public void Stop()
5658
{
5759
if (!running)
5860
{
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);
6062
return;
6163
}
6264

63-
MenuEvents.MenuChanged -= MenuEvents_MenuChanged;
64-
MenuEvents.MenuClosed -= MenuEvents_MenuClosed;
65+
events.Display.MenuChanged -= OnMenuChanged;
6566

6667
running = false;
6768
}
6869

69-
private void MenuEvents_MenuClosed(object sender, EventArgsClickableMenuClosed e)
70+
private void OnMenuChanged(object sender, MenuChangedEventArgs e)
7071
{
71-
ignoreMenuChanged = false;
72-
73-
if (e.PriorMenu is LetterViewerMenu && switchBackToCollectionsMenu)
72+
// menu closed
73+
if (e.NewMenu == null)
7474
{
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;
7785
}
7886

79-
switchBackToCollectionsMenu = false;
80-
}
87+
// menu changed or opened
8188

82-
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
83-
{
8489
if (e.NewMenu is GameMenu gameMenu && !ignoreMenuChanged)
8590
{
8691
List<IClickableMenu> pages = ModEntry.CommonServices.ReflectionHelper.GetField<List<IClickableMenu>>(gameMenu, "pages").GetValue();
@@ -96,13 +101,14 @@ private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged
96101
}
97102
}
98103

99-
else if (e.NewMenu is LetterViewerMenu && e.PriorMenu is GameMenu gameMenu2)
104+
else if (e.NewMenu is LetterViewerMenu && e.OldMenu is GameMenu gameMenu2)
100105
{
101106
switchBackToCollectionsMenu = true;
102107
savedGameMenu = gameMenu2;
103108
}
104109

105110
ignoreMenuChanged = false;
111+
106112
}
107113
}
108114
}

ArchaeologyHouseContentManagementHelper/Framework/Services/DialogServices/LostBookFoundDialogService.cs

+20-13
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@
1313
namespace StardewMods.ArchaeologyHouseContentManagementHelper.Framework.Services
1414
{
1515
/// <summary>
16-
/// This class is responsible for firing the [All Lost Books found] message.
16+
/// This class is responsible for displaying a congratulations message when the player has
17+
/// found all [Lost Books].
1718
/// </summary>
1819
internal class LostBookFoundDialogService
1920
{
2021
private bool showMessage;
2122

2223
private bool running;
2324

24-
private IMonitor monitor;
25+
private readonly IMonitor monitor;
26+
private readonly IModEvents events;
2527

2628
public LostBookFoundDialogService()
2729
{
2830
monitor = ModEntry.CommonServices.Monitor;
31+
events = ModEntry.CommonServices.Events;
2932

3033
running = false;
3134
}
@@ -40,8 +43,7 @@ public void Start()
4043

4144
running = true;
4245

43-
MenuEvents.MenuChanged += MenuEvents_MenuChanged;
44-
MenuEvents.MenuClosed += MenuEvents_MenuClosed;
46+
events.Display.MenuChanged += OnMenuChanged;
4547
}
4648

4749
public void Stop()
@@ -52,36 +54,41 @@ public void Stop()
5254
return;
5355
}
5456

55-
MenuEvents.MenuChanged -= MenuEvents_MenuChanged;
56-
MenuEvents.MenuClosed -= MenuEvents_MenuClosed;
57+
events.Display.MenuChanged -= OnMenuChanged;
5758

5859
running = false;
59-
}
60+
}
6061

61-
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
62+
/// <summary>
63+
/// Called after a dialog has been created/changed/closed. Responsible for showing the
64+
/// congratulations message to the player when he/she has found all [Lost Books].
65+
/// </summary>
66+
/// <param name="sender">The event sender.</param>
67+
/// <param name="e">The event args.</param>
68+
private void OnMenuChanged(object sender, MenuChangedEventArgs e)
6269
{
70+
// menu opened or changed
6371
if (e.NewMenu is DialogueBox box)
6472
{
6573
var mostRecentlyGrabbed = Game1.player.mostRecentlyGrabbedItem;
6674
if (mostRecentlyGrabbed != null && mostRecentlyGrabbed.ParentSheetIndex == StardewMods.Common.StardewValley.Constants.ID_GAME_OBJECT_LOST_BOOK)
6775
{
6876
List<string> dialogues = ModEntry.CommonServices.ReflectionHelper.GetField<List<string>>(box, "dialogues").GetValue();
69-
if (dialogues.Count == 1 && dialogues[0].Equals(mostRecentlyGrabbed.checkForSpecialItemHoldUpMeessage())
77+
if (dialogues.Count == 1 && dialogues[0].Equals(mostRecentlyGrabbed.checkForSpecialItemHoldUpMeessage())
7078
&& LibraryMuseumHelper.LibraryBooks == LibraryMuseumHelper.TotalLibraryBooks)
7179
{
7280
showMessage = true;
7381
}
7482
}
7583
}
76-
}
7784

78-
private void MenuEvents_MenuClosed(object sender, EventArgsClickableMenuClosed e)
79-
{
80-
if (e.PriorMenu is DialogueBox box && showMessage)
85+
// menu closed
86+
else if (e.NewMenu == null && e.OldMenu is DialogueBox && showMessage)
8187
{
8288
Game1.drawObjectDialogue(ModEntry.CommonServices.TranslationHelper.Get(Translation.MESSAGE_LIBRARY_BOOKS_COMPLETED));
8389
showMessage = false;
8490
}
91+
8592
}
8693
}
8794
}

ArchaeologyHouseContentManagementHelper/Framework/Services/DialogServices/MuseumInteractionDialogService.cs

+13-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ internal class MuseumInteractionDialogService
3131

3232
private bool running;
3333

34-
private ITranslationHelper translationHelper;
35-
private IMonitor monitor;
34+
private readonly ITranslationHelper translationHelper;
35+
private readonly IMonitor monitor;
36+
private readonly IModEvents events;
3637

3738
public MuseumInteractionDialogService()
3839
{
@@ -45,6 +46,7 @@ public MuseumInteractionDialogService()
4546

4647
translationHelper = ModEntry.CommonServices.TranslationHelper;
4748
monitor = ModEntry.CommonServices.Monitor;
49+
events = ModEntry.CommonServices.Events;
4850

4951
running = false;
5052
}
@@ -58,7 +60,8 @@ public void Start()
5860
}
5961

6062
running = true;
61-
InputEvents.ButtonPressed += InputEvents_ButtonPressed;
63+
64+
events.Input.ButtonPressed += OnButtonPressed;
6265
}
6366

6467
public void Stop()
@@ -69,16 +72,18 @@ public void Stop()
6972
return;
7073
}
7174

72-
InputEvents.ButtonPressed -= InputEvents_ButtonPressed;
75+
events.Input.ButtonPressed -= OnButtonPressed;
7376
running = false;
7477
}
7578

76-
/// <summary>The method invoked when the player presses a controller, keyboard, or mouse button.</summary>
79+
/// <summary>
80+
/// This method is responsible for showing our custom [Museum Interaction] dialog.
81+
/// </summary>
7782
/// <param name="sender">The event sender.</param>
78-
/// <param name="e">The event data.</param>
79-
private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
83+
/// <param name="e">The event args.</param>
84+
private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
8085
{
81-
if (e.IsActionButton && Context.IsPlayerFree && LibraryMuseumHelper.IsPlayerAtCounter(Game1.player))
86+
if (e.Button.IsActionButton() && Context.IsPlayerFree && LibraryMuseumHelper.IsPlayerAtCounter(Game1.player))
8287
{
8388
LibraryMuseum museum = Game1.currentLocation as LibraryMuseum;
8489
bool canDonate = museum.doesFarmerHaveAnythingToDonate(Game1.player);

ArchaeologyHouseContentManagementHelper/ModEntry.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ public override void Entry(IModHelper helper)
5353
collectionPageExMenuService = new CollectionPageExMenuService();
5454
collectionPageExMenuService.Start();
5555

56-
SaveEvents.AfterLoad += Bootstrap;
56+
helper.Events.GameLoop.SaveLoaded += Bootstrap;
5757
}
5858

59-
private void Bootstrap(object sender, EventArgs e)
59+
private void Bootstrap(object sender, SaveLoadedEventArgs e)
6060
{
6161
// Start remaining services
6262
menuInteractDialogService = new MuseumInteractionDialogService();
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"Name": "Archaeology House Content Management Helper",
33
"Author": "Felix-Dev",
4-
"Version": "1.2.1",
4+
"Version": "1.3.0",
55
"Description": "Improves management of the Library/Museum.",
66
"UniqueID": "Felix-Dev.ArchaeologyHouseContentManagementHelper",
77
"EntryDll": "ArchaeologyHouseContentManagementHelper.dll",
8-
"MinimumApiVersion": "2.8",
8+
"MinimumApiVersion": "2.10.1",
99
"UpdateKeys": [ "Nexus:2804" ]
1010
}

ArchaeologyHouseContentManagementHelper/release-notes.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Release notes
2+
## 1.3.0
3+
* Added support for SMAPI 3.0.
4+
25
## 1.2.1
36
* Updated for Stardew Valley 1.3.32.
47
* For Translators: Improved Library-Status-Message newline handling: Line paddings no longer needed.

0 commit comments

Comments
 (0)