forked from aedenthorn/StardewValleyMods
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21a3858
commit c2135f5
Showing
20 changed files
with
1,072 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<Version>1.0.0</Version> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<EnableHarmony>true</EnableHarmony> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="manifest.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using StardewValley; | ||
using StardewValley.Menus; | ||
|
||
namespace AdvancedMenuPositioning | ||
{ | ||
public partial class ModEntry | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using StardewModdingAPI; | ||
using System; | ||
|
||
namespace AdvancedMenuPositioning | ||
{ | ||
/// <summary>The API which lets other mods add a config UI through Generic Mod Config Menu.</summary> | ||
public interface IGenericModConfigMenuApi | ||
{ | ||
/********* | ||
** Methods | ||
*********/ | ||
/**** | ||
** Must be called first | ||
****/ | ||
/// <summary>Register a mod whose config can be edited through the UI.</summary> | ||
/// <param name="mod">The mod's manifest.</param> | ||
/// <param name="reset">Reset the mod's config to its default values.</param> | ||
/// <param name="save">Save the mod's current config to the <c>config.json</c> file.</param> | ||
/// <param name="titleScreenOnly">Whether the options can only be edited from the title screen.</param> | ||
/// <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 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 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 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 AddBoolOption(IManifest mod, Func<bool> getValue, Action<bool> setValue, Func<string> name, Func<string> tooltip = null, string fieldId = null); | ||
|
||
|
||
/// <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="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); | ||
|
||
/// <summary>Add a string 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="allowedValues">The values that can be selected, or <c>null</c> to allow any.</param> | ||
/// <param name="formatAllowedValue">Get the display text to show for a value from <paramref name="allowedValues"/>, or <c>null</c> to show the values 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 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>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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
using HarmonyLib; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Input; | ||
using StardewModdingAPI; | ||
using StardewValley; | ||
using StardewValley.Menus; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Rectangle = Microsoft.Xna.Framework.Rectangle; | ||
|
||
namespace AdvancedMenuPositioning | ||
{ | ||
public partial class ModEntry : Mod | ||
{ | ||
|
||
private static void AdjustMenu(IClickableMenu menu, Point delta, bool first = false) | ||
{ | ||
if (first) | ||
{ | ||
adjustedMenus.Clear(); | ||
adjustedComponents.Clear(); | ||
} | ||
if (menu is null || adjustedMenus.Contains(menu)) | ||
return; | ||
menu.xPositionOnScreen += delta.X; | ||
menu.yPositionOnScreen += delta.Y; | ||
var types = AccessTools.GetDeclaredFields(menu.GetType()); | ||
if (menu is ItemGrabMenu) | ||
{ | ||
types.AddRange(AccessTools.GetDeclaredFields(typeof(MenuWithInventory))); | ||
} | ||
foreach (var f in types) | ||
{ | ||
|
||
if (f.FieldType.IsSubclassOf(typeof(ClickableComponent)) || f.FieldType == typeof(ClickableComponent)) | ||
{ | ||
AdjustComponent((ClickableComponent)f.GetValue(menu), delta); | ||
|
||
} | ||
else if (f.FieldType.IsSubclassOf(typeof(IClickableMenu)) || f.FieldType == typeof(IClickableMenu)) | ||
{ | ||
AdjustMenu((IClickableMenu)f.GetValue(menu), delta); | ||
|
||
} | ||
else if (f.FieldType == typeof(InventoryMenu)) | ||
{ | ||
AdjustMenu((IClickableMenu)f.GetValue(menu), delta); | ||
} | ||
else if (f.Name == "scrollBarRunner") | ||
{ | ||
var c = (Rectangle)f.GetValue(menu); | ||
c = new Rectangle(c.X + delta.X, c.Y + delta.Y, c.Width, c.Height); | ||
f.SetValue(menu, c); | ||
} | ||
else if (f.FieldType == typeof(List<ClickableComponent>)) | ||
{ | ||
var ol = (List<ClickableComponent>)f.GetValue(menu); | ||
if (ol is null) | ||
continue; | ||
foreach (var o in ol) | ||
{ | ||
AdjustComponent(o, delta); | ||
} | ||
} | ||
else if (f.FieldType == typeof(List<IClickableMenu>)) | ||
{ | ||
var ol = (List<IClickableMenu>)f.GetValue(menu); | ||
if (ol is null) | ||
continue; | ||
foreach (var o in ol) | ||
{ | ||
AdjustMenu(o, delta); | ||
} | ||
} | ||
else if (f.FieldType == typeof(Dictionary<int, ClickableTextureComponent>)) | ||
{ | ||
var ol = (Dictionary<int, ClickableTextureComponent>)f.GetValue(menu); | ||
if (ol is null) | ||
continue; | ||
foreach (var o in ol.Values) | ||
{ | ||
AdjustComponent(o, delta); | ||
} | ||
} | ||
else if (f.FieldType == typeof(Dictionary<int, ClickableComponent>)) | ||
{ | ||
var ol = (Dictionary<int, ClickableComponent>)f.GetValue(menu); | ||
if (ol is null) | ||
continue; | ||
foreach (var o in ol.Values) | ||
{ | ||
AdjustComponent(o, delta); | ||
} | ||
} | ||
else if (f.FieldType == typeof(Dictionary<int, List<List<ClickableTextureComponent>>>)) | ||
{ | ||
var ol = (Dictionary<int, List<List<ClickableTextureComponent>>>)f.GetValue(menu); | ||
if (ol is null) | ||
continue; | ||
foreach (var o in ol.Values) | ||
{ | ||
foreach (var o2 in o) | ||
{ | ||
foreach (var o3 in o2) | ||
{ | ||
AdjustComponent(o3, delta); | ||
} | ||
} | ||
} | ||
} | ||
else if (f.FieldType == typeof(Dictionary<int, List<List<ClickableComponent>>>)) | ||
{ | ||
var ol = (Dictionary<int, List<List<ClickableComponent>>>)f.GetValue(menu); | ||
if (ol is null) | ||
continue; | ||
foreach (var o in ol.Values) | ||
{ | ||
foreach (var o2 in o) | ||
{ | ||
foreach (var o3 in o2) | ||
{ | ||
AdjustComponent(o3, delta); | ||
} | ||
} | ||
} | ||
} | ||
else if (f.FieldType == typeof(List<ClickableTextureComponent>)) | ||
{ | ||
var ol = (List<ClickableTextureComponent>)f.GetValue(menu); | ||
if (ol is null) | ||
continue; | ||
foreach (var o in ol) | ||
{ | ||
AdjustComponent(o, delta); | ||
} | ||
} | ||
} | ||
if (menu is GameMenu) | ||
{ | ||
for (int i = 0; i < (menu as GameMenu).pages.Count; i++) | ||
{ | ||
if (i != (menu as GameMenu).currentTab) | ||
AdjustMenu((menu as GameMenu).pages[i], delta); | ||
} | ||
} | ||
AdjustComponent(menu.upperRightCloseButton, delta); | ||
adjustedMenus.Add(menu); | ||
} | ||
|
||
private static void AdjustComponent(ClickableComponent c, Point delta) | ||
{ | ||
if (c is not null && !adjustedComponents.Contains(c)) | ||
{ | ||
c.bounds = new Rectangle(c.bounds.X + delta.X, c.bounds.Y + delta.Y, c.bounds.Width, c.bounds.Height); | ||
adjustedComponents.Add(c); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
| ||
using StardewModdingAPI; | ||
|
||
namespace AdvancedMenuPositioning | ||
{ | ||
public class ModConfig | ||
{ | ||
public bool EnableMod { get; set; } = true; | ||
public SButton DetachKey { get; set; } = SButton.X; | ||
public SButton MoveKey { get; set; } = SButton.MouseLeft; | ||
public SButton CloseKey { get; set; } = SButton.Z; | ||
public SButton DetachModKey { get; set; } = SButton.LeftShift; | ||
public SButton MoveModKey { get; set; } = SButton.LeftShift; | ||
public SButton CloseModKey { get; set; } = SButton.LeftShift; | ||
} | ||
} |
Oops, something went wrong.