Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Aug 2, 2023
1 parent 94e68da commit 9b56373
Show file tree
Hide file tree
Showing 29 changed files with 2,097 additions and 328 deletions.
6 changes: 3 additions & 3 deletions Alarms/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ private void CheckForSound(int time)
if (sound.enabled
&& (sound.hours < 0 || sound.hours == time / 100)
&& (sound.minutes < 0 || sound.minutes == time % 100)
&& (sound.daysOfWeek is null || sound.daysOfWeek[Game1.dayOfMonth % 7])
&& (sound.daysOfWeek is null || sound.daysOfWeek[Game1.dayOfMonth % 7])
&& (sound.daysOfMonth is null || sound.daysOfMonth[Game1.dayOfMonth])
&& (sound.daysOfWeek is null || sound.daysOfWeek[(Game1.dayOfMonth - 1) % 7])
&& (sound.daysOfMonth is null || sound.daysOfMonth[Game1.dayOfMonth - 1])
&& (sound.seasons is null || sound.seasons[Utility.getSeasonNumber(Game1.currentSeason)])
)
{
if (sound.notification is not null)
Expand Down
2 changes: 1 addition & 1 deletion Alarms/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Alarms",
"Author": "aedenthorn",
"Version": "0.1.2",
"Version": "0.1.3",
"Description": "Alarms.",
"UniqueID": "aedenthorn.Alarms",
"EntryDll": "Alarms.dll",
Expand Down
373 changes: 357 additions & 16 deletions ContentPatcherEditor/ChangeSet.cs

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions ContentPatcherEditor/ClockSound.cs

This file was deleted.

20 changes: 20 additions & 0 deletions ContentPatcherEditor/ConfigSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Xna.Framework;
using StardewValley.Menus;
using System.Collections.Generic;

namespace ContentPatcherEditor
{
public class ConfigSetup
{
public string oldKey;
public Dictionary<Vector2, string> labels = new();
public TextBox Key;
public TextBox Default;
public List<TextBox> AllowValues = new();
public ClickableTextureComponent DeleteCC;
public ClickableTextureComponent AllowValuesAddCC;
public List<ClickableTextureComponent> AllowValuesSubCCs = new();
public ClickableTextureComponent AllowBlank;
public ClickableTextureComponent AllowMultiple;
}
}
1,196 changes: 988 additions & 208 deletions ContentPatcherEditor/ContentPackMenu.cs

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion ContentPatcherEditor/ContentPatcherContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ public class ContentPatcherContent
{
public string Format;
public List<JObject> Changes;
public Dictionary<string, JObject> ConfigSchema;
public Dictionary<string, ConfigVar> ConfigSchema;
public List<Dictionary<string, List<KeyValuePair<string, JToken?>>>> lists;
}

public class ConfigVar
{
public string AllowValues;
public bool AllowBlank;
public bool AllowMultiple;
public string Default;
}
}
107 changes: 86 additions & 21 deletions ContentPatcherEditor/ContentPatcherMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using StardewModdingAPI;
using StardewValley;
using StardewValley.BellsAndWhistles;
Expand All @@ -13,13 +14,14 @@
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Threading;

namespace ContentPatcherEditor
{
public class ContentPatcherMenu : IClickableMenu
{
public static int scrolled;
public static int setsPerPage = 18;
public static int setsPerPage = 17;
public static int windowWidth = 64 * 24;
public static ContentPatcherMenu instance;
public List<ContentPatcherPack> contentPatcherPacks = new();
Expand All @@ -29,11 +31,42 @@ public class ContentPatcherMenu : IClickableMenu
public ClickableTextureComponent downCC;
public string hoverText;
public string hoveredItem;
private ClickableTextureComponent scrollBar;
private Rectangle scrollBarRunner;
private bool scrolling;

public ContentPatcherMenu() : base(Game1.uiViewport.Width / 2 - (windowWidth + borderWidth * 2) / 2, -borderWidth, windowWidth + borderWidth * 2, Game1.uiViewport.Height, false)
{
setsPerPage = 18;
scrolled = 0;
setsPerPage = 17;
width = 64 * 24;

foreach (var dir in Directory.GetDirectories(Path.Combine(Constants.GamePath, "Mods"), "*", SearchOption.AllDirectories))
{
if (File.Exists(Path.Combine(dir, "manifest.json")) && File.Exists(Path.Combine(dir, "content.json")))
{
try
{
MyManifest manifest = JsonConvert.DeserializeObject<MyManifest>(File.ReadAllText(Path.Combine(dir, "manifest.json")));
if (manifest.ContentPackFor?.UniqueID == "Pathoschild.ContentPatcher")
{
var pack = new ContentPatcherPack()
{
directory = dir,
manifest = manifest,
content = JsonConvert.DeserializeObject<ContentPatcherContent>(File.ReadAllText(Path.Combine(dir, "content.json"))),
};
ModEntry.RebuildLists(pack);
contentPatcherPacks.Add(pack);
}
}
catch(Exception ex)
{
ModEntry.SMonitor.Log($"Error loading mod at {dir}: \n\n{ex}", LogLevel.Error);
}
}
}

RepopulateComponentList();

exitFunction = emergencyShutDown;
Expand All @@ -43,7 +76,6 @@ public ContentPatcherMenu() : base(Game1.uiViewport.Width / 2 - (windowWidth + b

private void RepopulateComponentList()
{
contentPatcherPacks.Clear();
allComponents.Clear();

int count = 0;
Expand All @@ -56,28 +88,14 @@ private void RepopulateComponentList()
int domWidth = 40;
int monthWidth = domWidth * 7 + 12;
Texture2D textBox = Game1.content.Load<Texture2D>("LooseSprites\\textBox");
foreach(var dir in Directory.GetDirectories(Path.Combine(Constants.GamePath, "Mods"), "*", SearchOption.AllDirectories))
{
if(File.Exists(Path.Combine(dir, "manifest.json")) && File.Exists(Path.Combine(dir, "content.json")))
{
MyManifest manifest = JsonConvert.DeserializeObject<MyManifest>(File.ReadAllText(Path.Combine(dir, "manifest.json")));
if(manifest.ContentPackFor?.UniqueID == "Pathoschild.ContentPatcher")
{
contentPatcherPacks.Add(new ContentPatcherPack()
{
directory = dir,
manifest = manifest,
content = JsonConvert.DeserializeObject<ContentPatcherContent>(File.ReadAllText(Path.Combine(dir, "content.json")))
});
}
}
}

for (int i = scrolled; i < Math.Min(setsPerPage + scrolled, contentPatcherPacks.Count); i++)
{
int xStart = xPositionOnScreen + spaceToClearSideBorder + borderWidth;
int yStart = yPositionOnScreen + borderWidth + spaceToClearTopBorder - 24 + count * setHeight;
int baseID = count * 1000;
allComponents.Add(new ClickableComponent(new Rectangle(xStart, yStart, width, setHeight), contentPatcherPacks[i].manifest.Name, contentPatcherPacks[i].manifest.UniqueID )

allComponents.Add(new ClickableComponent(new Rectangle(xStart, yStart + 96, width, setHeight), contentPatcherPacks[i].manifest.Name, contentPatcherPacks[i].manifest.UniqueID)
{
myID = baseID,
downNeighborID = baseID + 1000,
Expand All @@ -86,7 +104,7 @@ private void RepopulateComponentList()
});
count++;
}
addCC = new ClickableTextureComponent("Add", new Rectangle(xPositionOnScreen + width - 128, yPositionOnScreen - 128 + height, 56, 56), "", ModEntry.SHelper.Translation.Get("add"), Game1.mouseCursors, new Rectangle(1, 412, 14, 14), 4)
addCC = new ClickableTextureComponent("Add", new Rectangle(xPositionOnScreen + width - 100, yPositionOnScreen - 96 + height, 56, 56), "", ModEntry.SHelper.Translation.Get("add"), Game1.mouseCursors, new Rectangle(1, 412, 14, 14), 4)
{
myID = count * 1000,
upNeighborID = (count - 1) * 1000,
Expand Down Expand Up @@ -115,12 +133,23 @@ private void RepopulateComponentList()
}
else
downCC = null;
if (contentPatcherPacks.Count > setsPerPage)
{
scrollBar = new ClickableTextureComponent(new Rectangle(xPositionOnScreen + width + 40 + 8, yPositionOnScreen + 132, 24, 40), Game1.mouseCursors, new Rectangle(435, 463, 6, 10), 4f, false);
scrollBarRunner = new Rectangle(scrollBar.bounds.X, scrollBar.bounds.Y, scrollBar.bounds.Width, height - 200);
float interval = (scrollBarRunner.Height - scrollBar.bounds.Height) / (float)(contentPatcherPacks.Count - setsPerPage);
scrollBar.bounds.Y = Math.Min(scrollBarRunner.Y + (int)Math.Round(interval * scrolled), scrollBarRunner.Bottom - scrollBar.bounds.Height);

}
populateClickableComponentList();
}


public override void draw(SpriteBatch b)
{
Game1.drawDialogueBox(xPositionOnScreen, yPositionOnScreen, width, height, false, true, null, false, true);
SpriteText.drawStringHorizontallyCenteredAt(b, ModEntry.SHelper.Translation.Get("content-packs"), Game1.viewport.Width / 2, yPositionOnScreen + spaceToClearTopBorder + borderWidth / 2);
b.Draw(Game1.menuTexture, new Rectangle(xPositionOnScreen + 32, yPositionOnScreen + borderWidth + spaceToClearTopBorder + 48, width - 64, 16), new Rectangle(40, 16, 1, 16), Color.White);
int count = 0;
foreach(var set in allComponents)
{
Expand All @@ -130,6 +159,12 @@ public override void draw(SpriteBatch b)
addCC.draw(b);
upCC?.draw(b);
downCC?.draw(b);
b.Draw(Game1.menuTexture, new Rectangle(xPositionOnScreen + spaceToClearSideBorder + 16, yPositionOnScreen + height - 112, width - 64, 8), new Rectangle(40, 16, 1, 16), Color.White);
if (scrollBar is not null)
{
IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(403, 383, 6, 6), this.scrollBarRunner.X, this.scrollBarRunner.Y, this.scrollBarRunner.Width, this.scrollBarRunner.Height, Color.White, 4f, true, -1f);
scrollBar.draw(b);
}
if (hoverText != null && hoveredItem == null)
{
drawHoverText(b, hoverText, Game1.smallFont, 0, 0, -1, null, -1, null, null, 0, -1, -1, -1, -1, 1f, null, null);
Expand Down Expand Up @@ -173,6 +208,11 @@ public override void receiveLeftClick(int x, int y, bool playSound = true)
}
return;
}
if (scrollBar?.containsPoint(x, y) == true)
{
scrolling = true;
return;
}
}


Expand Down Expand Up @@ -286,6 +326,31 @@ public override void emergencyShutDown()
{
base.emergencyShutDown();
}
public override void leftClickHeld(int x, int y)
{
base.leftClickHeld(x, y);
if (scrolling)
{
float interval = (scrollBarRunner.Height - scrollBar.bounds.Height) / (float)(contentPatcherPacks.Count - setsPerPage);

float percent = (y - scrollBarRunner.Y) / (float)scrollBarRunner.Height;
int which = (int)Math.Round(scrollBarRunner.Height / interval * percent);

int newScroll = Math.Max(0, Math.Min(contentPatcherPacks.Count - setsPerPage, which));
if (newScroll != scrolled)
{
Game1.playSound("shiny4");
scrolled = newScroll;
RepopulateComponentList();
}
}
}

public override void releaseLeftClick(int x, int y)
{
base.releaseLeftClick(x, y);
scrolling = false;
}

}
}
8 changes: 5 additions & 3 deletions ContentPatcherEditor/ContentPatcherPack.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using StardewModdingAPI;
using System.Collections.Generic;

namespace ContentPatcherEditor
{
public class ContentPatcherPack
{
internal MyManifest manifest;
internal ContentPatcherContent content;
internal string directory;
public MyManifest manifest;
public ContentPatcherContent content;
public string directory;
public List<KeyValuePair<string, ConfigVar>> config;
}
}
2 changes: 1 addition & 1 deletion ContentPatcherEditor/ManifestContentPackFor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ContentPatcherEditor
{
internal class ManifestContentPackFor
public class ManifestContentPackFor
{
public string UniqueID = "PathosChild.ContentPatcher";

Expand Down
2 changes: 1 addition & 1 deletion ContentPatcherEditor/ManifestDependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ContentPatcherEditor
{
internal class ManifestDependency
public class ManifestDependency
{
public string UniqueID = "PathosChild.ContentPatcher";

Expand Down
Loading

0 comments on commit 9b56373

Please sign in to comment.