Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Nov 24, 2021
1 parent 9e98a92 commit 182d98d
Show file tree
Hide file tree
Showing 13 changed files with 497 additions and 2 deletions.
2 changes: 1 addition & 1 deletion FarmerHelper/MethodPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static bool Object_placementAction_Prefix(Object __instance, GameLocatio
}
private static void IClickableMenu_drawToolTip_Prefix(string hoverText, ref string hoverTitle, Item hoveredItem)
{
if (!Config.EnableMod || !Config.LabelLatePlanting)
if (!Config.EnableMod || !Config.LabelLatePlanting || hoveredItem == null)
return;

Crop crop = new Crop(hoveredItem.ParentSheetIndex, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion FarmerHelper/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Farmer Helper",
"Author": "aedenthorn",
"Version": "0.1.0",
"Version": "0.1.1",
"Description": "Farmer Helper.",
"UniqueID": "aedenthorn.FarmerHelper",
"EntryDll": "FarmerHelper.dll",
Expand Down
10 changes: 10 additions & 0 deletions StardewValleyMods.sln
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FarmerHelper", "FarmerHelpe
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Screenshot", "Screenshot\Screenshot.csproj", "{9A912B3A-946D-4D9F-8144-031A5B7669EC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UtilityGrid", "UtilityGrid\UtilityGrid.csproj", "{528604C2-9C7D-4161-BB3F-D2175CC21432}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
_releases\_releases.projitems*{047040e0-3d07-46e5-852b-d1d45cd57bb8}*SharedItemsImports = 13
Expand Down Expand Up @@ -881,6 +883,14 @@ Global
{9A912B3A-946D-4D9F-8144-031A5B7669EC}.Release|Any CPU.Build.0 = Release|Any CPU
{9A912B3A-946D-4D9F-8144-031A5B7669EC}.Release|x86.ActiveCfg = Release|Any CPU
{9A912B3A-946D-4D9F-8144-031A5B7669EC}.Release|x86.Build.0 = Release|Any CPU
{528604C2-9C7D-4161-BB3F-D2175CC21432}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{528604C2-9C7D-4161-BB3F-D2175CC21432}.Debug|Any CPU.Build.0 = Debug|Any CPU
{528604C2-9C7D-4161-BB3F-D2175CC21432}.Debug|x86.ActiveCfg = Debug|Any CPU
{528604C2-9C7D-4161-BB3F-D2175CC21432}.Debug|x86.Build.0 = Debug|Any CPU
{528604C2-9C7D-4161-BB3F-D2175CC21432}.Release|Any CPU.ActiveCfg = Release|Any CPU
{528604C2-9C7D-4161-BB3F-D2175CC21432}.Release|Any CPU.Build.0 = Release|Any CPU
{528604C2-9C7D-4161-BB3F-D2175CC21432}.Release|x86.ActiveCfg = Release|Any CPU
{528604C2-9C7D-4161-BB3F-D2175CC21432}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 9 additions & 0 deletions UtilityGrid/Game1Patches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using StardewValley;

namespace UtilityGrid
{
/// <summary>The mod entry point.</summary>
public partial class ModEntry
{
}
}
49 changes: 49 additions & 0 deletions UtilityGrid/IGenericModConfigMenuApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewModdingAPI.Utilities;
using StardewValley;

namespace UtilityGrid
{
/// <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 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>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);
}
}
19 changes: 19 additions & 0 deletions UtilityGrid/ModConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

using Microsoft.Xna.Framework;
using StardewModdingAPI;

namespace UtilityGrid
{
public class ModConfig
{
public bool EnableMod { get; set; } = true;

public SButton ToggleGrid { get; set; } = SButton.Home;
public SButton SwitchGrid { get; set; } = SButton.Delete;
public SButton SwitchTile { get; set; } = SButton.PageUp;
public SButton RotateTile { get; set; } = SButton.PageDown;
public SButton PlaceTile { get; set; } = SButton.MouseLeft;
public Color WaterColor { get; set; } = Color.Aqua;
public Color ElectricityColor { get; set; } = Color.Yellow;
}
}
214 changes: 214 additions & 0 deletions UtilityGrid/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewValley;
using System;
using System.Collections.Generic;

namespace UtilityGrid
{
/// <summary>The mod entry point.</summary>
public partial class ModEntry : Mod
{

public static IMonitor SMonitor;
public static IModHelper SHelper;
public static ModConfig Config;

public static ModEntry context;
public static Texture2D pipeTexture;

public static bool ShowingGrid { get; set; } = false;
public static bool ElectricGrid { get; set; } = false;
public static int CurrentTile { get; set; } = 0;
public static int CurrentRotation { get; set; } = 0;

public static int[][] intakeArray = { new int[]{0, 1, 1, 1}, new int[]{1, 0, 0, 1}, new int[]{1, 0, 0, 0}, new int[]{0, 1, 0, 1}, new int[]{1, 1, 1, 1} };

public Dictionary<Vector2, Point> waterPipes = new Dictionary<Vector2, Point>();
public Dictionary<Vector2, Point> electricPipes = new Dictionary<Vector2, Point>();
public List<PipeGroup> waterGroups = new List<PipeGroup>();
public List<PipeGroup> electricGroups = new List<PipeGroup>();

/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="helper">Provides simplified APIs for writing mods.</param>
public override void Entry(IModHelper helper)
{
Config = Helper.ReadConfig<ModConfig>();

if (!Config.EnableMod)
return;

context = this;

SMonitor = Monitor;
SHelper = helper;

helper.Events.Input.ButtonPressed += Input_ButtonPressed;
helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched;
helper.Events.Display.RenderedWorld += Display_RenderedWorld;

var harmony = new Harmony(ModManifest.UniqueID);

// Game1 Patches
/*
harmony.Patch(
original: AccessTools.Method(typeof(Game1), "_newDayAfterFade"),
prefix: new HarmonyMethod(typeof(ModEntry), nameof(ModEntry.Game1__newDayAfterFade_Prefix))
);
*/

pipeTexture = Helper.Content.Load<Texture2D>("assets/pipes.png");

}
private void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e)
{
if (!Config.EnableMod || !(Game1.currentLocation is Farm) || !Game1.currentLocation.IsOutdoors)
return;

if (e.Button == Config.ToggleGrid)
{
Helper.Input.Suppress(e.Button);
ShowingGrid = !ShowingGrid;
Monitor.Log($"Showing grid: {ShowingGrid}");
}
if (!ShowingGrid)
return;
if (e.Button == Config.SwitchGrid)
{
Helper.Input.Suppress(e.Button);
ElectricGrid = !ElectricGrid;
Monitor.Log($"Showing Electric grid: {ElectricGrid}");
}
else if (e.Button == Config.SwitchTile)
{
Helper.Input.Suppress(e.Button);
CurrentTile++;
CurrentTile %= 6;
CurrentRotation = 0;
Monitor.Log($"Showing tile: {CurrentTile},{CurrentRotation}");
}
else if (e.Button == Config.RotateTile)
{
Helper.Input.Suppress(e.Button);
CurrentRotation++;
if (CurrentTile < 3)
CurrentRotation %= 4;
else if (CurrentTile == 3)
CurrentRotation %= 2;
else
CurrentRotation = 0;
Monitor.Log($"Showing tile: {CurrentTile},{CurrentRotation}");
}
else if (e.Button == Config.PlaceTile)
{
Helper.Input.Suppress(e.Button);
Dictionary<Vector2, Point> pipeDict;
if (ElectricGrid)
{
pipeDict = electricPipes;
}
else
{
pipeDict = waterPipes;
}
if(CurrentTile == 5)
pipeDict.Remove(Game1.lastCursorTile);
else
pipeDict[Game1.lastCursorTile] = new Point(CurrentTile, CurrentRotation);
RemakeGroups(ElectricGrid);
Monitor.Log($"Placing tile: {CurrentTile},{CurrentRotation} at {Game1.currentCursorTile}; connected? {PipeIsPowered(Game1.currentCursorTile, ElectricGrid)}");
}
}
private void Display_RenderedWorld(object sender, StardewModdingAPI.Events.RenderedWorldEventArgs e)
{
if (!Config.EnableMod || !ShowingGrid)
return;
Dictionary<Vector2, Point> pipeDict;
Color color;
if (ElectricGrid)
{
pipeDict = electricPipes;
color = Config.ElectricityColor;
}
else
{
pipeDict = waterPipes;
color = Config.WaterColor;
}
foreach (var kvp in pipeDict)
{
if (kvp.Key == Game1.currentCursorTile)
{
continue;
}
if (Utility.isOnScreen(new Vector2(kvp.Key.X * 64 + 32, kvp.Key.Y * 64 + 32), 32))
{
if (kvp.Value.X == 4)
DrawTile(e.SpriteBatch, kvp.Key, new Point(3, 2), ElectricGrid, PipeIsPowered(kvp.Key, ElectricGrid) ? color : Color.White);
else
DrawTile(e.SpriteBatch, kvp.Key, kvp.Value, ElectricGrid, PipeIsPowered(kvp.Key, ElectricGrid) ? color : Color.White);
}
}
if (CurrentTile == 4)
DrawTile(e.SpriteBatch, Game1.currentCursorTile, new Point(3, 2), ElectricGrid, color);
else if(CurrentTile != 5)
DrawTile(e.SpriteBatch, Game1.currentCursorTile, new Point(CurrentTile, CurrentRotation), ElectricGrid, color);
}



private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e)
{
// get Generic Mod Config Menu's API (if it's installed)
var configMenu = Helper.ModRegistry.GetApi<IGenericModConfigMenuApi>("spacechase0.GenericModConfigMenu");
if (configMenu is null)
return;

// register mod
configMenu.Register(
mod: ModManifest,
reset: () => Config = new ModConfig(),
save: () => Helper.WriteConfig(Config)
);

configMenu.AddBoolOption(
mod: ModManifest,
name: () => "Mod Enabled?",
getValue: () => Config.EnableMod,
setValue: value => Config.EnableMod = value
);
configMenu.AddKeybind(
mod: ModManifest,
name: () => "Toggle Grid Key",
getValue: () => Config.ToggleGrid,
setValue: value => Config.ToggleGrid = value
);
configMenu.AddKeybind(
mod: ModManifest,
name: () => "Switch Grid Key",
getValue: () => Config.ToggleGrid,
setValue: value => Config.ToggleGrid = value
);
configMenu.AddKeybind(
mod: ModManifest,
name: () => "Change Tile Key",
getValue: () => Config.SwitchTile,
setValue: value => Config.SwitchTile = value
);
configMenu.AddKeybind(
mod: ModManifest,
name: () => "Rotate Tile Key",
getValue: () => Config.RotateTile,
setValue: value => Config.RotateTile = value
);
configMenu.AddKeybind(
mod: ModManifest,
name: () => "Place Tile Key",
getValue: () => Config.PlaceTile,
setValue: value => Config.PlaceTile = value
);
}
}
}
11 changes: 11 additions & 0 deletions UtilityGrid/PipeGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Xna.Framework;
using System.Collections.Generic;

namespace UtilityGrid
{
public class PipeGroup
{
public List<Vector2> pipes;
public float power;
}
}
23 changes: 23 additions & 0 deletions UtilityGrid/UtilityGrid.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<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-beta.20210916" />
</ItemGroup>

<ItemGroup>
<None Update="assets\numbers.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="assets\pipes.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="manifest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Loading

0 comments on commit 182d98d

Please sign in to comment.