Skip to content

Commit

Permalink
ArchaeologyHouseMode: Added support for SMAP 3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix-Dev committed Jan 16, 2019
1 parent 7ba4dcd commit 7c84234
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ namespace StardewMods.ArchaeologyHouseContentManagementHelper.Framework.Services
/// </summary>
internal class CollectionPageExMenuService
{
private IMonitor monitor;
private readonly IMonitor monitor;
private readonly IModEvents events;

private bool running;

private bool ignoreMenuChanged;
Expand All @@ -32,6 +34,7 @@ internal class CollectionPageExMenuService
public CollectionPageExMenuService()
{
monitor = ModEntry.CommonServices.Monitor;
events = ModEntry.CommonServices.Events;

collectionsPageTabIndex = -1;

Expand All @@ -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<IClickableMenu> pages = ModEntry.CommonServices.ReflectionHelper.GetField<List<IClickableMenu>>(gameMenu, "pages").GetValue();
Expand All @@ -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;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
namespace StardewMods.ArchaeologyHouseContentManagementHelper.Framework.Services
{
/// <summary>
/// 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].
/// </summary>
internal class LostBookFoundDialogService
{
private bool showMessage;

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;
}
Expand All @@ -40,8 +43,7 @@ public void Start()

running = true;

MenuEvents.MenuChanged += MenuEvents_MenuChanged;
MenuEvents.MenuClosed += MenuEvents_MenuClosed;
events.Display.MenuChanged += OnMenuChanged;
}

public void Stop()
Expand All @@ -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)
/// <summary>
/// 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].
/// </summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event args.</param>
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<string> dialogues = ModEntry.CommonServices.ReflectionHelper.GetField<List<string>>(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;
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -45,6 +46,7 @@ public MuseumInteractionDialogService()

translationHelper = ModEntry.CommonServices.TranslationHelper;
monitor = ModEntry.CommonServices.Monitor;
events = ModEntry.CommonServices.Events;

running = false;
}
Expand All @@ -58,7 +60,8 @@ public void Start()
}

running = true;
InputEvents.ButtonPressed += InputEvents_ButtonPressed;

events.Input.ButtonPressed += OnButtonPressed;
}

public void Stop()
Expand All @@ -69,16 +72,18 @@ public void Stop()
return;
}

InputEvents.ButtonPressed -= InputEvents_ButtonPressed;
events.Input.ButtonPressed -= OnButtonPressed;
running = false;
}

/// <summary>The method invoked when the player presses a controller, keyboard, or mouse button.</summary>
/// <summary>
/// This method is responsible for showing our custom [Museum Interaction] dialog.
/// </summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event data.</param>
private void InputEvents_ButtonPressed(object sender, EventArgsInput e)
/// <param name="e">The event args.</param>
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);
Expand Down
4 changes: 2 additions & 2 deletions ArchaeologyHouseContentManagementHelper/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions ArchaeologyHouseContentManagementHelper/manifest.json
Original file line number Diff line number Diff line change
@@ -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" ]
}
3 changes: 3 additions & 0 deletions ArchaeologyHouseContentManagementHelper/release-notes.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 7c84234

Please sign in to comment.