Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MailboxMenu] Update to 1.6 #128

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions MailboxMenu/CodePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@
using StardewModdingAPI;
using StardewValley;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using StardewValley.Tools;

namespace MailboxMenu
{
public partial class ModEntry
{

[HarmonyPatch(typeof(GameLocation), nameof(GameLocation.mailbox))]
public class GameLocation_mailbox_Patch
{
private static bool UsingMailServices() {
if (!isMailServicesActive) return false;

return Game1.player.ActiveObject != null ||
Game1.player.CurrentTool is Axe ||
Game1.player.CurrentTool is Pickaxe ||
Game1.player.CurrentTool is Hoe ||
Game1.player.CurrentTool is WateringCan;
}

public static bool Prefix(GameLocation __instance)
{
if (!Config.ModEnabled || !Config.MenuOnMailbox || (Config.ModKey != SButton.None && !SHelper.Input.IsDown(Config.ModKey)))
if (!Config.ModEnabled ||
!Config.MenuOnMailbox ||
(Config.ModKey != SButton.None && !SHelper.Input.IsDown(Config.ModKey)) ||
UsingMailServices())
return true;

List<string> list = new List<string>();
foreach(var str in Game1.mailbox)
{
Expand All @@ -25,6 +36,7 @@ public static bool Prefix(GameLocation __instance)
list.Add(str);
}
}

if(list.Count > 0)
{
foreach (var str in Game1.mailbox)
Expand All @@ -39,6 +51,7 @@ public static bool Prefix(GameLocation __instance)
}
return true;
}

Game1.activeClickableMenu = new MailMenu();
return false;
}
Expand Down
119 changes: 112 additions & 7 deletions MailboxMenu/IGenericModConfigMenuApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,51 @@ public interface IGenericModConfigMenuApi
/// <remarks>Each mod can only be registered once, unless it's deleted via <see cref="Unregister"/> before calling this again.</remarks>
void Register(IManifest mod, Action reset, Action save, bool titleScreenOnly = false);

/// <summary>Add a key binding at the current position in the form.</summary>

/****
** Basic options
****/
/// <summary>Add a section title at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="text">The title text shown in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the title, or <c>null</c> to disable the tooltip.</param>
void AddSectionTitle(IManifest mod, Func<string> text, Func<string> tooltip = null);

/// <summary>Add a paragraph of text at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="text">The paragraph text to display.</param>
void AddParagraph(IManifest mod, Func<string> text);

/// <summary>Add an image at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="texture">The image texture to display.</param>
/// <param name="texturePixelArea">The pixel area within the texture to display, or <c>null</c> to show the entire image.</param>
/// <param name="scale">The zoom factor to apply to the image.</param>
void AddImage(IManifest mod, Func<Texture2D> texture, Rectangle? texturePixelArea = null, int scale = Game1.pixelZoom);

/// <summary>Add a boolean option at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="getValue">Get the current value from the mod config.</param>
/// <param name="setValue">Set a new value in the mod config.</param>
/// <param name="name">The label text to show in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddKeybind(IManifest mod, Func<SButton> getValue, Action<SButton> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null);
void AddBoolOption(IManifest mod, Func<bool> getValue, Action<bool> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null);

/// <summary>Add a boolean option at the current position in the form.</summary>
/// <summary>Add an integer option at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="getValue">Get the current value from the mod config.</param>
/// <param name="setValue">Set a new value in the mod config.</param>
/// <param name="name">The label text to show in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param>
/// <param name="min">The minimum allowed value, or <c>null</c> to allow any.</param>
/// <param name="max">The maximum allowed value, or <c>null</c> to allow any.</param>
/// <param name="interval">The interval of values that can be selected.</param>
/// <param name="formatValue">Get the display text to show for a value, or <c>null</c> to show the number as-is.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddBoolOption(IManifest mod, Func<bool> getValue, Action<bool> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null);
void AddNumberOption(IManifest mod, Func<int> getValue, Action<int> setValue, Func<string> name, Func<string> tooltip = null, int? min = null, int? max = null, int? interval = null, Func<int, string> formatValue = null, string fieldId = null);

/// <summary>Add an integer option at the current position in the form.</summary>
/// <summary>Add a float option at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="getValue">Get the current value from the mod config.</param>
/// <param name="setValue">Set a new value in the mod config.</param>
Expand All @@ -51,8 +77,9 @@ public interface IGenericModConfigMenuApi
/// <param name="min">The minimum allowed value, or <c>null</c> to allow any.</param>
/// <param name="max">The maximum allowed value, or <c>null</c> to allow any.</param>
/// <param name="interval">The interval of values that can be selected.</param>
/// <param name="formatValue">Get the display text to show for a value, or <c>null</c> to show the number as-is.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddNumberOption(IManifest mod, Func<int> getValue, Action<int> setValue, Func<string> name, Func<string> tooltip = null, int? min = null, int? max = null, int? interval = null, string fieldId = null);
void AddNumberOption(IManifest mod, Func<float> getValue, Action<float> setValue, Func<string> name, Func<string> tooltip = null, float? min = null, float? max = null, float? interval = null, Func<float, string> formatValue = null, string fieldId = null);

/// <summary>Add a string option at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
Expand All @@ -65,8 +92,86 @@ public interface IGenericModConfigMenuApi
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddTextOption(IManifest mod, Func<string> getValue, Action<string> setValue, Func<string> name, Func<string> tooltip = null, string[] allowedValues = null, Func<string, string> formatAllowedValue = null, string fieldId = null);

/// <summary>Add a key binding at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="getValue">Get the current value from the mod config.</param>
/// <param name="setValue">Set a new value in the mod config.</param>
/// <param name="name">The label text to show in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddKeybind(IManifest mod, Func<SButton> getValue, Action<SButton> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null);

/// <summary>Add a key binding list at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="getValue">Get the current value from the mod config.</param>
/// <param name="setValue">Set a new value in the mod config.</param>
/// <param name="name">The label text to show in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
void AddKeybindList(IManifest mod, Func<KeybindList> getValue, Action<KeybindList> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null);


/****
** Multi-page management
****/
/// <summary>Start a new page in the mod's config UI, or switch to that page if it already exists. All options registered after this will be part of that page.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="pageId">The unique page ID.</param>
/// <param name="pageTitle">The page title shown in its UI, or <c>null</c> to show the <paramref name="pageId"/> value.</param>
/// <remarks>You must also call <see cref="AddPageLink"/> to make the page accessible. This is only needed to set up a multi-page config UI. If you don't call this method, all options will be part of the mod's main config UI instead.</remarks>
void AddPage(IManifest mod, string pageId, Func<string> pageTitle = null);

/// <summary>Add a link to a page added via <see cref="AddPage"/> at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="pageId">The unique ID of the page to open when the link is clicked.</param>
/// <param name="text">The link text shown in the form.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the link, or <c>null</c> to disable the tooltip.</param>
void AddPageLink(IManifest mod, string pageId, Func<string> text, Func<string> tooltip = null);


/****
** Advanced
****/
/// <summary>Add an option at the current position in the form using custom rendering logic.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="name">The label text to show in the form.</param>
/// <param name="draw">Draw the option in the config UI. This is called with the sprite batch being rendered and the pixel position at which to start drawing.</param>
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the field, or <c>null</c> to disable the tooltip.</param>
/// <param name="beforeMenuOpened">A callback raised just before the menu containing this option is opened.</param>
/// <param name="beforeSave">A callback raised before the form's current values are saved to the config (i.e. before the <c>save</c> callback passed to <see cref="Register"/>).</param>
/// <param name="afterSave">A callback raised after the form's current values are saved to the config (i.e. after the <c>save</c> callback passed to <see cref="Register"/>).</param>
/// <param name="beforeReset">A callback raised before the form is reset to its default values (i.e. before the <c>reset</c> callback passed to <see cref="Register"/>).</param>
/// <param name="afterReset">A callback raised after the form is reset to its default values (i.e. after the <c>reset</c> callback passed to <see cref="Register"/>).</param>
/// <param name="beforeMenuClosed">A callback raised just before the menu containing this option is closed.</param>
/// <param name="height">The pixel height to allocate for the option in the form, or <c>null</c> for a standard input-sized option. This is called and cached each time the form is opened.</param>
/// <param name="fieldId">The unique field ID for use with <see cref="OnFieldChanged"/>, or <c>null</c> to auto-generate a randomized ID.</param>
/// <remarks>The custom logic represented by the callback parameters is responsible for managing its own state if needed. For example, you can store state in a static field or use closures to use a state variable.</remarks>
void AddComplexOption(IManifest mod, Func<string> name, Action<SpriteBatch, Vector2> draw, Func<string> tooltip = null, Action beforeMenuOpened = null, Action beforeSave = null, Action afterSave = null, Action beforeReset = null, Action afterReset = null, Action beforeMenuClosed = null, Func<int> height = null, string fieldId = null);

/// <summary>Set whether the options registered after this point can only be edited from the title screen.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="titleScreenOnly">Whether the options can only be edited from the title screen.</param>
/// <remarks>This lets you have different values per-field. Most mods should just set it once in <see cref="Register"/>.</remarks>
void SetTitleScreenOnlyForNextOptions(IManifest mod, bool titleScreenOnly);

/// <summary>Register a method to notify when any option registered by this mod is edited through the config UI.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="onChange">The method to call with the option's unique field ID and new value.</param>
/// <remarks>Options use a randomized ID by default; you'll likely want to specify the <c>fieldId</c> argument when adding options if you use this.</remarks>
void OnFieldChanged(IManifest mod, Action<string, object> onChange);

/// <summary>Open the config UI for a specific mod.</summary>
/// <param name="mod">The mod's manifest.</param>
void OpenModMenu(IManifest mod);

/// <summary>Get the currently-displayed mod config menu, if any.</summary>
/// <param name="mod">The manifest of the mod whose config menu is being shown, or <c>null</c> if not applicable.</param>
/// <param name="page">The page ID being shown for the current config menu, or <c>null</c> if not applicable. This may be <c>null</c> even if a mod config menu is shown (e.g. because the mod doesn't have pages).</param>
/// <returns>Returns whether a mod config menu is being shown.</returns>
bool TryGetCurrentMenu(out IManifest mod, out string page);

/// <summary>Remove a mod from the config UI and delete all its options and pages.</summary>
/// <param name="mod">The mod's manifest.</param>
void Unregister(IManifest mod);
}
}
}
12 changes: 6 additions & 6 deletions MailboxMenu/MailMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ private void PopulateMailList()
{
List<string> strings = new List<string>();
int count = 0;
for (int i = 0; i < Game1.player.mailReceived.Count; i++)
{
string id = Game1.player.mailReceived[i];
foreach (var id in Game1.player.mailReceived) {
if (!mail.TryGetValue(id, out string mailData))
continue;
if (Game1.mailbox.Contains(id))
Expand All @@ -157,7 +155,7 @@ private void PopulateMailList()
}
if (count >= mainScrolled * ModEntry.Config.GridColumns)
{
AddMail(id, count - mainScrolled * ModEntry.Config.GridColumns, mailData);
AddMail(id, count - mainScrolled * ModEntry.Config.GridColumns, mailData);
}
count++;
}
Expand Down Expand Up @@ -347,8 +345,10 @@ public override void draw(SpriteBatch b)
lines++;
}
}
SpriteText.drawString(b, ModEntry.Config.InboxText, inboxButton.bounds.X, inboxButton.bounds.Y, color: whichTab == 0 ? 0 : 8);
SpriteText.drawString(b, ModEntry.Config.ArchiveText, allMailButton.bounds.X, allMailButton.bounds.Y, color: whichTab == 1 ? 0 : 8);
SpriteText.drawString(b, ModEntry.Config.InboxText, inboxButton.bounds.X, inboxButton.bounds.Y,
color: whichTab == 0 ? Color.Black : Color.DarkGray);
SpriteText.drawString(b, ModEntry.Config.ArchiveText, allMailButton.bounds.X, allMailButton.bounds.Y,
color: whichTab == 1 ? Color.Black : Color.DarkGray);
for(int i = 0; i < senders.Count; i++)
{
string str = senders[i].name;
Expand Down
2 changes: 1 addition & 1 deletion MailboxMenu/MailboxMenu.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.0.0</Version>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<EnableHarmony>true</EnableHarmony>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
Expand Down
Loading