From 7c84234f73005d08cb7d0a3de34d2c85687984fd Mon Sep 17 00:00:00 2001 From: Felix Date: Wed, 16 Jan 2019 21:25:26 +0100 Subject: [PATCH] ArchaeologyHouseMode: Added support for SMAP 3.0. --- .../Services/CollectionPageExMenuService.cs | 40 +++++++++++-------- .../LostBookFoundDialogService.cs | 33 +++++++++------ .../MuseumInteractionDialogService.cs | 21 ++++++---- .../ModEntry.cs | 4 +- .../manifest.json | 4 +- .../release-notes.md | 3 ++ 6 files changed, 63 insertions(+), 42 deletions(-) diff --git a/ArchaeologyHouseContentManagementHelper/Framework/Services/CollectionPageExMenuService.cs b/ArchaeologyHouseContentManagementHelper/Framework/Services/CollectionPageExMenuService.cs index f2612da..3d22239 100644 --- a/ArchaeologyHouseContentManagementHelper/Framework/Services/CollectionPageExMenuService.cs +++ b/ArchaeologyHouseContentManagementHelper/Framework/Services/CollectionPageExMenuService.cs @@ -16,7 +16,9 @@ namespace StardewMods.ArchaeologyHouseContentManagementHelper.Framework.Services /// internal class CollectionPageExMenuService { - private IMonitor monitor; + private readonly IMonitor monitor; + private readonly IModEvents events; + private bool running; private bool ignoreMenuChanged; @@ -32,6 +34,7 @@ internal class CollectionPageExMenuService public CollectionPageExMenuService() { monitor = ModEntry.CommonServices.Monitor; + events = ModEntry.CommonServices.Events; collectionsPageTabIndex = -1; @@ -48,39 +51,41 @@ public void Start() running = true; - MenuEvents.MenuChanged += MenuEvents_MenuChanged; - MenuEvents.MenuClosed += MenuEvents_MenuClosed; + events.Display.MenuChanged += OnMenuChanged; } public void Stop() { if (!running) { - monitor.Log("[LostBookFoundDialogService] is not running or has already been stopped!", LogLevel.Info); + monitor.Log("[CollectionPageExMenuService] is not running or has already been stopped!", LogLevel.Info); return; } - MenuEvents.MenuChanged -= MenuEvents_MenuChanged; - MenuEvents.MenuClosed -= MenuEvents_MenuClosed; + events.Display.MenuChanged -= OnMenuChanged; running = false; } - private void MenuEvents_MenuClosed(object sender, EventArgsClickableMenuClosed e) + private void OnMenuChanged(object sender, MenuChangedEventArgs e) { - ignoreMenuChanged = false; - - if (e.PriorMenu is LetterViewerMenu && switchBackToCollectionsMenu) + // menu closed + if (e.NewMenu == null) { - ignoreMenuChanged = true; - Game1.activeClickableMenu = savedGameMenu; + ignoreMenuChanged = false; + + if (e.OldMenu is LetterViewerMenu && switchBackToCollectionsMenu) + { + ignoreMenuChanged = true; + Game1.activeClickableMenu = savedGameMenu; + } + + switchBackToCollectionsMenu = false; + return; } - switchBackToCollectionsMenu = false; - } + // menu changed or opened - private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) - { if (e.NewMenu is GameMenu gameMenu && !ignoreMenuChanged) { List pages = ModEntry.CommonServices.ReflectionHelper.GetField>(gameMenu, "pages").GetValue(); @@ -96,13 +101,14 @@ private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged } } - else if (e.NewMenu is LetterViewerMenu && e.PriorMenu is GameMenu gameMenu2) + else if (e.NewMenu is LetterViewerMenu && e.OldMenu is GameMenu gameMenu2) { switchBackToCollectionsMenu = true; savedGameMenu = gameMenu2; } ignoreMenuChanged = false; + } } } diff --git a/ArchaeologyHouseContentManagementHelper/Framework/Services/DialogServices/LostBookFoundDialogService.cs b/ArchaeologyHouseContentManagementHelper/Framework/Services/DialogServices/LostBookFoundDialogService.cs index 37c344b..182f229 100644 --- a/ArchaeologyHouseContentManagementHelper/Framework/Services/DialogServices/LostBookFoundDialogService.cs +++ b/ArchaeologyHouseContentManagementHelper/Framework/Services/DialogServices/LostBookFoundDialogService.cs @@ -13,7 +13,8 @@ namespace StardewMods.ArchaeologyHouseContentManagementHelper.Framework.Services { /// - /// This class is responsible for firing the [All Lost Books found] message. + /// This class is responsible for displaying a congratulations message when the player has + /// found all [Lost Books]. /// internal class LostBookFoundDialogService { @@ -21,11 +22,13 @@ internal class LostBookFoundDialogService private bool running; - private IMonitor monitor; + private readonly IMonitor monitor; + private readonly IModEvents events; public LostBookFoundDialogService() { monitor = ModEntry.CommonServices.Monitor; + events = ModEntry.CommonServices.Events; running = false; } @@ -40,8 +43,7 @@ public void Start() running = true; - MenuEvents.MenuChanged += MenuEvents_MenuChanged; - MenuEvents.MenuClosed += MenuEvents_MenuClosed; + events.Display.MenuChanged += OnMenuChanged; } public void Stop() @@ -52,36 +54,41 @@ public void Stop() return; } - MenuEvents.MenuChanged -= MenuEvents_MenuChanged; - MenuEvents.MenuClosed -= MenuEvents_MenuClosed; + events.Display.MenuChanged -= OnMenuChanged; running = false; - } + } - private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) + /// + /// Called after a dialog has been created/changed/closed. Responsible for showing the + /// congratulations message to the player when he/she has found all [Lost Books]. + /// + /// The event sender. + /// The event args. + private void OnMenuChanged(object sender, MenuChangedEventArgs e) { + // menu opened or changed if (e.NewMenu is DialogueBox box) { var mostRecentlyGrabbed = Game1.player.mostRecentlyGrabbedItem; if (mostRecentlyGrabbed != null && mostRecentlyGrabbed.ParentSheetIndex == StardewMods.Common.StardewValley.Constants.ID_GAME_OBJECT_LOST_BOOK) { List dialogues = ModEntry.CommonServices.ReflectionHelper.GetField>(box, "dialogues").GetValue(); - if (dialogues.Count == 1 && dialogues[0].Equals(mostRecentlyGrabbed.checkForSpecialItemHoldUpMeessage()) + if (dialogues.Count == 1 && dialogues[0].Equals(mostRecentlyGrabbed.checkForSpecialItemHoldUpMeessage()) && LibraryMuseumHelper.LibraryBooks == LibraryMuseumHelper.TotalLibraryBooks) { showMessage = true; } } } - } - private void MenuEvents_MenuClosed(object sender, EventArgsClickableMenuClosed e) - { - if (e.PriorMenu is DialogueBox box && showMessage) + // menu closed + else if (e.NewMenu == null && e.OldMenu is DialogueBox && showMessage) { Game1.drawObjectDialogue(ModEntry.CommonServices.TranslationHelper.Get(Translation.MESSAGE_LIBRARY_BOOKS_COMPLETED)); showMessage = false; } + } } } diff --git a/ArchaeologyHouseContentManagementHelper/Framework/Services/DialogServices/MuseumInteractionDialogService.cs b/ArchaeologyHouseContentManagementHelper/Framework/Services/DialogServices/MuseumInteractionDialogService.cs index f6c8bbb..3335e66 100644 --- a/ArchaeologyHouseContentManagementHelper/Framework/Services/DialogServices/MuseumInteractionDialogService.cs +++ b/ArchaeologyHouseContentManagementHelper/Framework/Services/DialogServices/MuseumInteractionDialogService.cs @@ -31,8 +31,9 @@ internal class MuseumInteractionDialogService private bool running; - private ITranslationHelper translationHelper; - private IMonitor monitor; + private readonly ITranslationHelper translationHelper; + private readonly IMonitor monitor; + private readonly IModEvents events; public MuseumInteractionDialogService() { @@ -45,6 +46,7 @@ public MuseumInteractionDialogService() translationHelper = ModEntry.CommonServices.TranslationHelper; monitor = ModEntry.CommonServices.Monitor; + events = ModEntry.CommonServices.Events; running = false; } @@ -58,7 +60,8 @@ public void Start() } running = true; - InputEvents.ButtonPressed += InputEvents_ButtonPressed; + + events.Input.ButtonPressed += OnButtonPressed; } public void Stop() @@ -69,16 +72,18 @@ public void Stop() return; } - InputEvents.ButtonPressed -= InputEvents_ButtonPressed; + events.Input.ButtonPressed -= OnButtonPressed; running = false; } - /// The method invoked when the player presses a controller, keyboard, or mouse button. + /// + /// This method is responsible for showing our custom [Museum Interaction] dialog. + /// /// The event sender. - /// The event data. - private void InputEvents_ButtonPressed(object sender, EventArgsInput e) + /// The event args. + private void OnButtonPressed(object sender, ButtonPressedEventArgs e) { - if (e.IsActionButton && Context.IsPlayerFree && LibraryMuseumHelper.IsPlayerAtCounter(Game1.player)) + if (e.Button.IsActionButton() && Context.IsPlayerFree && LibraryMuseumHelper.IsPlayerAtCounter(Game1.player)) { LibraryMuseum museum = Game1.currentLocation as LibraryMuseum; bool canDonate = museum.doesFarmerHaveAnythingToDonate(Game1.player); diff --git a/ArchaeologyHouseContentManagementHelper/ModEntry.cs b/ArchaeologyHouseContentManagementHelper/ModEntry.cs index e45244e..30cceaa 100644 --- a/ArchaeologyHouseContentManagementHelper/ModEntry.cs +++ b/ArchaeologyHouseContentManagementHelper/ModEntry.cs @@ -53,10 +53,10 @@ public override void Entry(IModHelper helper) collectionPageExMenuService = new CollectionPageExMenuService(); collectionPageExMenuService.Start(); - SaveEvents.AfterLoad += Bootstrap; + helper.Events.GameLoop.SaveLoaded += Bootstrap; } - private void Bootstrap(object sender, EventArgs e) + private void Bootstrap(object sender, SaveLoadedEventArgs e) { // Start remaining services menuInteractDialogService = new MuseumInteractionDialogService(); diff --git a/ArchaeologyHouseContentManagementHelper/manifest.json b/ArchaeologyHouseContentManagementHelper/manifest.json index de88252..ec5be13 100644 --- a/ArchaeologyHouseContentManagementHelper/manifest.json +++ b/ArchaeologyHouseContentManagementHelper/manifest.json @@ -1,10 +1,10 @@ { "Name": "Archaeology House Content Management Helper", "Author": "Felix-Dev", - "Version": "1.2.1", + "Version": "1.3.0", "Description": "Improves management of the Library/Museum.", "UniqueID": "Felix-Dev.ArchaeologyHouseContentManagementHelper", "EntryDll": "ArchaeologyHouseContentManagementHelper.dll", - "MinimumApiVersion": "2.8", + "MinimumApiVersion": "2.10.1", "UpdateKeys": [ "Nexus:2804" ] } \ No newline at end of file diff --git a/ArchaeologyHouseContentManagementHelper/release-notes.md b/ArchaeologyHouseContentManagementHelper/release-notes.md index d280f07..6cf9743 100644 --- a/ArchaeologyHouseContentManagementHelper/release-notes.md +++ b/ArchaeologyHouseContentManagementHelper/release-notes.md @@ -1,4 +1,7 @@ # Release notes +## 1.3.0 +* Added support for SMAPI 3.0. + ## 1.2.1 * Updated for Stardew Valley 1.3.32. * For Translators: Improved Library-Status-Message newline handling: Line paddings no longer needed.