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

Feature/sandy clothing items #344

Open
wants to merge 4 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
2 changes: 2 additions & 0 deletions UIInfoSuite2/Infrastructure/LanguageKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public static class LanguageKeys
public const string CanFindSalmonberry = "CanFindSalmonberry";
public const string CanFindBlackberry = "CanFindBlackberry";
public const string CanFindHazelnut = "CanFindHazelnut";
public const string SandyClothingItemAll = "SandyClothingItemAll";
public const string SandyClothingItemRare = "SandyClothingItemRare";
}
2 changes: 2 additions & 0 deletions UIInfoSuite2/Options/ModOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ internal record ModOptions
public bool ShowSeasonalBerryHazelnut { get; set; } = false;
public bool ShowTodaysGifts { get; set; } = true;
public bool HideBirthdayIfFullFriendShip { get; set; } = true;
public bool ShowOasisClothes { get; set; } = true;
public bool ShowOasisClothesAll { get; set; } = true;
public Dictionary<string, bool> ShowLocationOfFriends { get; set; } = new();
}
22 changes: 21 additions & 1 deletion UIInfoSuite2/Options/ModOptionsPageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public ModOptionsPageHandler(IModHelper helper, ModOptions options, bool showPer
var showRobinBuildingStatusIcon = new ShowRobinBuildingStatusIcon(helper);
var showSeasonalBerry = new ShowSeasonalBerry(helper);
var showTodaysGift = new ShowTodaysGifts(helper);
var showOasisClothes = new ShowOasisClothes(helper);

_elementsToDispose = new List<IDisposable>
{
Expand All @@ -106,7 +107,8 @@ public ModOptionsPageHandler(IModHelper helper, ModOptions options, bool showPer
showQueenOfSauceIcon,
showToolUpgradeStatus,
showRobinBuildingStatusIcon,
showSeasonalBerry
showSeasonalBerry,
showOasisClothes
};

var whichOption = 1;
Expand Down Expand Up @@ -350,6 +352,24 @@ public ModOptionsPageHandler(IModHelper helper, ModOptions options, bool showPer
v => options.ShowTodaysGifts = v
)
);
var showOasisClothesIcon = new ModOptionsCheckbox(
_helper.SafeGetString(nameof(options.ShowOasisClothes)),
whichOption++,
showOasisClothes.ToggleOption,
() => options.ShowOasisClothes,
v => options.ShowOasisClothes = v
);
_optionsElements.Add(showOasisClothesIcon);
_optionsElements.Add(
new ModOptionsCheckbox(
_helper.SafeGetString(nameof(options.ShowOasisClothesAll)),
whichOption++,
showOasisClothes.ToggleShowAllClothes,
() => options.ShowOasisClothesAll,
v => options.ShowOasisClothesAll = v,
showOasisClothesIcon
)
);
}


Expand Down
189 changes: 189 additions & 0 deletions UIInfoSuite2/UIElements/ShowOasisClothes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewModdingAPI.Utilities;
using StardewValley;
using StardewValley.Menus;
using StardewValley.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UIInfoSuite2.Infrastructure;
using UIInfoSuite2.Infrastructure.Extensions;

namespace UIInfoSuite2.UIElements
{
internal class ShowOasisClothes : IDisposable
{
#region Properties

private int[] _valuableIds =
{
20, 23, 24, 41, 42, 44, 46, 47, 50, 55, 57, 61, 77, 81, 83, 85, 88, 91, 109, 110, 111, 119, 120, 121, 122
};

private Clothing? _clothingItem;

private readonly PerScreen<bool> _shouldRenderItem = new();
private readonly PerScreen<ClickableTextureComponent?> _icon = new();
private readonly IModHelper _helper;

private bool Enabled { get; set; }
private bool ShowAllClothes { get; set; }

#endregion

#region Life cycle

public ShowOasisClothes(IModHelper helper)
{
_helper = helper;
ToggleOption(true);
}

public void Dispose()
{
ToggleOption(false);
}

public void ToggleOption(bool enabled)
{
Enabled = enabled;

_helper.Events.Display.RenderingHud -= OnRenderingHud;
_helper.Events.Display.RenderedHud -= OnRenderedHud;
_helper.Events.Display.MenuChanged -= OnMenuChanged;
_helper.Events.GameLoop.DayStarted -= OnDayStarted;
_helper.Events.GameLoop.SaveLoaded -= OnSaveLoaded;

if (enabled)
{
_helper.Events.GameLoop.DayStarted += OnDayStarted;
_helper.Events.Display.RenderingHud += OnRenderingHud;
_helper.Events.Display.RenderedHud += OnRenderedHud;
_helper.Events.Display.MenuChanged += OnMenuChanged;
_helper.Events.GameLoop.SaveLoaded += OnSaveLoaded;
}

UpdateOasisItem();
}

public void ToggleShowAllClothes(bool showAllClothes)
{
ShowAllClothes = showAllClothes;
ToggleOption(Enabled);
}

#endregion

#region Event subscriptions

private void OnDayStarted(object sender, DayStartedEventArgs e)
{
UpdateOasisItem();
}

private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
{
UpdateOasisItem();
}

private void OnMenuChanged(object sender, MenuChangedEventArgs e)
{
// Stop rendering if we visit Sandy
if (e.NewMenu is not ShopMenu || Game1.currentLocation.Name != "SandyHouse") return;
_shouldRenderItem.Value = false;
}

private void OnRenderingHud(object sender, RenderingHudEventArgs e)
{
if (Game1.eventUp || !_shouldRenderItem.Value) return;

Point iconPosition = IconHandler.Handler.GetNewIconPosition();

_icon.Value = new ClickableTextureComponent(
new Rectangle(iconPosition.X, iconPosition.Y, 40, 40),
null,
Rectangle.Empty,
1);
_icon.Value.draw(Game1.spriteBatch);

_clothingItem?.drawInMenu(
Game1.spriteBatch,
new Vector2(iconPosition.X - 12, iconPosition.Y - 12),
1.25f
);
}

private void OnRenderedHud(object sender, RenderedHudEventArgs e)
{
if (_clothingItem == null || !_shouldRenderItem.Value || Game1.IsFakedBlackScreen() ||
!(_icon.Value?.containsPoint(Game1.getMouseX(), Game1.getMouseY()) ?? false)) return;
var formattedStr = GetHoverString();
IClickableMenu.drawHoverText(Game1.spriteBatch, formattedStr, Game1.dialogueFont);
}

#endregion

#region Logic

private string GetHoverString()
{
return ShowAllClothes
? string.Format(_helper.SafeGetString(LanguageKeys.SandyClothingItemAll), _clothingItem?.displayName)
: _helper.SafeGetString(LanguageKeys.SandyClothingItemRare);
}

private static bool HasVisitedDesert()
{
return Game1.player.eventsSeen.Contains("67");
}

private void UpdateOasisItem()
{
_clothingItem = GetClothingItem();
_shouldRenderItem.Value = false;
// Early escape if we don't have an item for some reason
if (_clothingItem == null || !Enabled) return;

// Check to make sure the store is open, and the desert is accessible
if (!HasVisitedDesert())
return;

var isExclusive = _valuableIds.Contains(_clothingItem.ParentSheetIndex - 1000);
if (isExclusive || ShowAllClothes)
{
_shouldRenderItem.Value = true;
}
}

private static Clothing? GetClothingItem()
{
var oasisStock = GetOasisStock();
return oasisStock?.Keys.FirstOrDefault(elem => elem is Clothing) as Clothing;
}

private static Dictionary<ISalable, int[]>? GetOasisStock()
{
var oasis = Game1.getLocationFromName("SandyHouse");
if (oasis == null)
{
return null;
}

var getShopStockMethod =
typeof(GameLocation).GetMethod("sandyShopStock", BindingFlags.Instance | BindingFlags.NonPublic);
if (getShopStockMethod == null)
{
return null;
}

var ret = getShopStockMethod.Invoke(oasis, null);

return ret as Dictionary<ISalable, int[]>;
}

#endregion
}
}
5 changes: 5 additions & 0 deletions UIInfoSuite2/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"LuckStatus4": "Fortuna's Laune ist heute absolut neutral",
"LuckStatus5": "Das Glück ist heute nicht auf deiner Seite",
"LuckStatus6": "Vielleicht solltest du heute zu Hause bleiben",
// Display icons - Merchants
"SandyClothingItemRare": "Sandy has rare clothing for sale", // TODO
"SandyClothingItemAll": "Sandy's Clothing Item: {0}", // TODO
//Settings - General
"ShowLevelUpAnimation": "Zeige Aufstiegsanimation",
"ShowExperienceBar": "Zeige Erfahrungsleiste",
Expand Down Expand Up @@ -91,6 +94,8 @@
"ShowExactValue": "Zeige exakten Wert",
"ShowSeasonalBerry": "Zeige saisonale Früchte",
"ShowSeasonalBerryHazelnut": "Zeige Haselnüsse auf Bäumen",
"ShowOasisClothes": "Show Oasis's rare clothing items", // TODO
"ShowOasisClothesAll": "Show all clothing items", // TODO
//Others
"LevelUp": "Level aufgestiegen"
}
5 changes: 5 additions & 0 deletions UIInfoSuite2/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
"LuckStatus4": "The spirits feel absolutely neutral today",
"LuckStatus5": "Luck will not be on your side today",
"LuckStatus6": "Maybe you should stay home today...",
// Display icons - Merchants
"SandyClothingItemRare": "Sandy has rare clothing for sale",
"SandyClothingItemAll": "Sandy's Clothing Item: {0}",
//Settings - General
"ShowLevelUpAnimation": "Show level up animation",
"ShowExperienceBar": "Show experience bar",
Expand Down Expand Up @@ -94,6 +97,8 @@
"ShowExactValue": "Show exact value",
"ShowSeasonalBerry": "Show seasonal forageables",
"ShowSeasonalBerryHazelnut": "Show hazelnuts on trees",
"ShowOasisClothes": "Show Oasis's rare clothing items",
"ShowOasisClothesAll": "Show all clothing items",
//Others
"LevelUp": "Level Up"
}
5 changes: 5 additions & 0 deletions UIInfoSuite2/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"LuckStatus4": "Los espíritus se sienten absolutamente neutrales hoy",
"LuckStatus5": "La suerte no estará de tu lado hoy",
"LuckStatus6": "Tal vez deberías quedarte en casa hoy...",
// Display icons - Merchants
"SandyClothingItemRare": "Sandy has rare clothing for sale", // TODO
"SandyClothingItemAll": "Sandy's Clothing Item: {0}", // TODO
//Settings - General
"ShowLevelUpAnimation": "Mostrar animación de subida de nivel",
"ShowExperienceBar": "Mostrar barra de experiencia",
Expand Down Expand Up @@ -71,6 +74,8 @@
"ShowExactValue": "Mostrar valor exacto",
"ShowSeasonalBerry": "Mostrar recolectables de temporada",
"ShowSeasonalBerryHazelnut": "Mostrar avellanas en los árboles",
"ShowOasisClothes": "Show Oasis's rare clothing items", // TODO
"ShowOasisClothesAll": "Show all clothing items", // TODO
//Others
"LevelUp": "Subida de nivel"
}
5 changes: 5 additions & 0 deletions UIInfoSuite2/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"LuckStatus4": "Les esprits sont plutôt neutre aujourd'hui.",
"LuckStatus5": "La chance n'est pas avec toi aujourd'hui.",
"LuckStatus6": "Tu ferais mieux de rester à la maison aujourd'hui.",
// Display icons - Merchants
"SandyClothingItemRare": "Sandy has rare clothing for sale", // TODO
"SandyClothingItemAll": "Sandy's Clothing Item: {0}", // TODO
//Settings - General
"ShowLevelUpAnimation": "Montrer l'animation de gain de niveau",
"ShowExperienceBar": "Montrer la barre d'expérience",
Expand Down Expand Up @@ -88,6 +91,8 @@
"ShowExactValue": "Montrer la valeur exacte",
"ShowSeasonalBerry": "Montrer les récoltables de saison\n(buissons de baie)",
"ShowSeasonalBerryHazelnut": "Montrer les noisettes sur les arbres",
"ShowOasisClothes": "Show Oasis's rare clothing items", // TODO
"ShowOasisClothesAll": "Show all clothing items", // TODO
//Others
"LevelUp": "Gain de niveau"
}
5 changes: 5 additions & 0 deletions UIInfoSuite2/i18n/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"LuckStatus4": "Ma a szellemek teljesen semlegesnek érzik magukat!",
"LuckStatus5": "Ma a szerencse nem a te oldaladon áll!",
"LuckStatus6": "Talán ma otthon kellene maradnod!",
// Display icons - Merchants
"SandyClothingItemRare": "Sandy has rare clothing for sale", // TODO
"SandyClothingItemAll": "Sandy's Clothing Item: {0}", // TODO
//Settings - General
"ShowLevelUpAnimation": "Szintlépés animáció megjelenítés",
"ShowExperienceBar": "Tapasztalatpont mérő megjelenítés",
Expand Down Expand Up @@ -71,6 +74,8 @@
"ShowExactValue": "Pontos érték megjelenítés",
"ShowSeasonalBerry": "Szezonális takarmánynövény megjelenítés",
"ShowSeasonalBerryHazelnut": "Mogyoró megjelenítés a fákon",
"ShowOasisClothes": "Show Oasis's rare clothing items", // TODO
"ShowOasisClothesAll": "Show all clothing items", // TODO
//Others
"LevelUp": "Szintlépés"
}
5 changes: 5 additions & 0 deletions UIInfoSuite2/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"LuckStatus4": "Gli spiriti sono neutrali oggi",
"LuckStatus5": "La fortuna non sarà dalla tua parte oggi",
"LuckStatus6": "Forse dovresti restare a casa oggi...",
// Display icons - Merchants
"SandyClothingItemRare": "Sandy has rare clothing for sale", // TODO
"SandyClothingItemAll": "Sandy's Clothing Item: {0}", // TODO
//Settings - General
"ShowLevelUpAnimation": "Mostra animazione di nuovo livello",
"ShowExperienceBar": "Mostra barra dell'esperienza",
Expand Down Expand Up @@ -71,6 +74,8 @@
"ShowExactValue": "Mostra valore esatto",
"ShowSeasonalBerry": "Mostra foraggiabili di stagione",
"ShowSeasonalBerryHazelnut": "Mostra Nocciole sugli alberi",
"ShowOasisClothes": "Show Oasis's rare clothing items", // TODO
"ShowOasisClothesAll": "Show all clothing items", // TODO
//Others
"LevelUp": "Nuovo livello"
}
5 changes: 5 additions & 0 deletions UIInfoSuite2/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"LuckStatus4": "今日の運勢はどっちつかず",
"LuckStatus5": "今日は運が味方してくれそうにない…",
"LuckStatus6": "今日は家で安静にしたほうが良いだろう…",
// Display icons - Merchants
"SandyClothingItemRare": "Sandy has rare clothing for sale", // TODO
"SandyClothingItemAll": "Sandy's Clothing Item: {0}", // TODO
//Settings - General
"ShowLevelUpAnimation": "レベルアップアニメーションを表示する",
"ShowExperienceBar": "経験値バーを表示する",
Expand Down Expand Up @@ -88,6 +91,8 @@
"ShowExactValue": "詳細な値を表示する",
"ShowSeasonalBerry": "季節の採取を表示する",
"ShowSeasonalBerryHazelnut": "ヘーゼルナッツを表示する",
"ShowOasisClothes": "Show Oasis's rare clothing items", // TODO
"ShowOasisClothesAll": "Show all clothing items", // TODO
//Others
"LevelUp": "レベルアップ"
}
5 changes: 5 additions & 0 deletions UIInfoSuite2/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"LuckStatus4": "오늘은 정령들의 기분이 완벽히 중립적이다.",
"LuckStatus5": "오늘은 운이 따라주지 않는 것 같다.",
"LuckStatus6": "오늘은 집에 있는 편이 좋을 것 같다...",
// Display icons - Merchants
"SandyClothingItemRare": "Sandy has rare clothing for sale", // TODO
"SandyClothingItemAll": "Sandy's Clothing Item: {0}", // TODO
//Settings - General
"ShowLevelUpAnimation": "레벨 업 애니메이션 표시",
"ShowExperienceBar": "경험치 바 표시",
Expand Down Expand Up @@ -91,6 +94,8 @@
"ShowExactValue": "정확한 수치 표시",
"ShowSeasonalBerry": "사계절 채집물 표시",
"ShowSeasonalBerryHazelnut": "헤이즐넛이 있는 나무 표시",
"ShowOasisClothes": "Show Oasis's rare clothing items", // TODO
"ShowOasisClothesAll": "Show all clothing items", // TODO
//Others
"LevelUp": "레벨 업"
}
Loading