Skip to content

Commit 8dec64f

Browse files
committed
Merge branch 'dev'
2 parents 79f7341 + 2d67a17 commit 8dec64f

3 files changed

Lines changed: 101 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66

77
## [Unreleased]
88

9+
## [1.0.1] - 2025-02-18
10+
11+
### Changed
12+
13+
- Inventory items will attempt to use a derived texture based on `Item.drawInMenu` for mod-created items with no registration data, e.g. the Net from Nature In The Valley.
14+
15+
### Fixed
16+
17+
- Fishing rod no longer immediately recasts when using X to dismiss the catch dialog.
18+
- Actions page in configuration menu should no longer intermittently fail to display the correct info for Library Actions.
19+
920
## [1.0.0] - 2025-02-14
1021

1122
### Fixed
@@ -178,18 +189,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
178189
- Custom shortcuts menu via right trigger (default).
179190
- [Generic Mod Config Menu](https://www.nexusmods.com/stardewvalley/mods/5098) pages for control scheme, appearance and custom shortcuts.
180191

181-
[Unreleased]: https://github.com/focustense/StardewRadialMenu/compare/v1.0.0...HEAD
182-
[1.0.0]: https://github.com/focustense/StardewRadialMenu/compare/v1.0.0-beta...v1.0.0
183-
[1.0.0-beta]: https://github.com/focustense/StardewRadialMenu/compare/v1.0.0-alpha2...v1.0.0-beta
184-
[1.0.0-alpha2]: https://github.com/focustense/StardewRadialMenu/compare/v1.0.0-alpha1...v1.0.0-alpha2
185-
[1.0.0-alpha1]: https://github.com/focustense/StardewRadialMenu/compare/v0.2.2...v1.0.0-alpha1
186-
[0.2.2]: https://github.com/focustense/StardewRadialMenu/compare/v0.2.1...v0.2.2
187-
[0.2.1]: https://github.com/focustense/StardewRadialMenu/compare/v0.2.0...v0.2.1
188-
[0.2.0]: https://github.com/focustense/StardewRadialMenu/compare/v0.1.6...v0.2.0
189-
[0.1.6]: https://github.com/focustense/StardewRadialMenu/compare/v0.1.5...v0.1.6
190-
[0.1.5]: https://github.com/focustense/StardewRadialMenu/compare/v0.1.4...v0.1.5
191-
[0.1.4]: https://github.com/focustense/StardewRadialMenu/compare/v0.1.3-alpha...v0.1.4
192-
[0.1.3-alpha]: https://github.com/focustense/StardewRadialMenu/compare/v0.1.2-alpha...v0.1.3-alpha
193-
[0.1.2-alpha]: https://github.com/focustense/StardewRadialMenu/compare/v0.1.1-alpha...v0.1.2-alpha
194-
[0.1.1-alpha]: https://github.com/focustense/StardewRadialMenu/compare/v0.1.0-alpha...v0.1.1-alpha
195-
[0.1.0-alpha]: https://github.com/focustense/StardewRadialMenu/tree/v0.1.0-alpha
192+
[Unreleased]: https://github.com/focustense/StardewControllers/compare/v1.0.1...HEAD
193+
[1.0.1]: https://github.com/focustense/StardewControllers/compare/v1.0.0...v1.0.1
194+
[1.0.0]: https://github.com/focustense/StardewControllers/compare/v1.0.0-beta...v1.0.0
195+
[1.0.0-beta]: https://github.com/focustense/StardewControllers/compare/v1.0.0-alpha2...v1.0.0-beta
196+
[1.0.0-alpha2]: https://github.com/focustense/StardewControllers/compare/v1.0.0-alpha1...v1.0.0-alpha2
197+
[1.0.0-alpha1]: https://github.com/focustense/StardewControllers/compare/v0.2.2...v1.0.0-alpha1
198+
[0.2.2]: https://github.com/focustense/StardewControllers/compare/v0.2.1...v0.2.2
199+
[0.2.1]: https://github.com/focustense/StardewControllers/compare/v0.2.0...v0.2.1
200+
[0.2.0]: https://github.com/focustense/StardewControllers/compare/v0.1.6...v0.2.0
201+
[0.1.6]: https://github.com/focustense/StardewControllers/compare/v0.1.5...v0.1.6
202+
[0.1.5]: https://github.com/focustense/StardewControllers/compare/v0.1.4...v0.1.5
203+
[0.1.4]: https://github.com/focustense/StardewControllers/compare/v0.1.3-alpha...v0.1.4
204+
[0.1.3-alpha]: https://github.com/focustense/StardewControllers/compare/v0.1.2-alpha...v0.1.3-alpha
205+
[0.1.2-alpha]: https://github.com/focustense/StardewControllers/compare/v0.1.1-alpha...v0.1.2-alpha
206+
[0.1.1-alpha]: https://github.com/focustense/StardewControllers/compare/v0.1.0-alpha...v0.1.1-alpha
207+
[0.1.0-alpha]: https://github.com/focustense/StardewControllers/tree/v0.1.0-alpha

StarControl.ApiTestMod/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Name": "Star Control API Example",
33
"Author": "focustense",
4-
"Version": "1.0.0-alpha1",
4+
"Version": "1.0.0",
55
"Description": "Mod for testing the Star Control API",
66
"UniqueID": "focustense.StarControlApiTestMod",
77
"EntryDll": "StarControlApiTestMod.dll",

StarControl/Menus/InventoryMenuItem.cs

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text;
1+
using System.Runtime.CompilerServices;
2+
using System.Text;
23
using Microsoft.Xna.Framework.Graphics;
34
using StardewValley.Enchantments;
45
using StardewValley.ItemTypeDefinitions;
@@ -35,6 +36,8 @@ internal class InventoryMenuItem : IRadialMenuItem
3536

3637
public Color? TintColor { get; }
3738

39+
private static readonly ConditionalWeakTable<Item, Texture2D?> DerivedTextures = [];
40+
3841
public InventoryMenuItem(Item item)
3942
{
4043
Logger.Log(LogCategory.Menus, "Starting refresh of inventory menu.");
@@ -43,10 +46,29 @@ public InventoryMenuItem(Item item)
4346
Description = UnparseText(item.getDescription());
4447

4548
var data = ItemRegistry.GetDataOrErrorItem(item.QualifiedItemId);
46-
var textureData = GetTextureRedirect(item);
47-
Texture = textureData?.GetTexture() ?? data.GetTexture();
48-
SourceRectangle = textureData?.GetSourceRect() ?? data.GetSourceRect();
49-
(TintRectangle, TintColor) = GetTinting(item, textureData ?? data);
49+
// Workaround for some mods creating items without registering item data; these mods
50+
// typically only implement drawInMenu. This is not a good thing to do, and tends to cause
51+
// other problems, but we can still attempt to show an icon.
52+
if (
53+
data.IsErrorItem
54+
// Exclude vanilla item classes; hacked items only apply to mods, and if we found an
55+
// instance with a vanilla type, it means the item truly is missing (e.g. source mod is
56+
// no longer installed, or the item is simply invalid) and we'd only waste time trying
57+
// to derive a texture.
58+
&& item.GetType().Assembly != typeof(SObject).Assembly
59+
&& GetDerivedTexture(item) is { } texture
60+
)
61+
{
62+
Texture = texture;
63+
SourceRectangle = texture.Bounds;
64+
}
65+
else
66+
{
67+
var textureData = GetTextureRedirect(item);
68+
Texture = textureData?.GetTexture() ?? data.GetTexture();
69+
SourceRectangle = textureData?.GetSourceRect() ?? data.GetSourceRect();
70+
(TintRectangle, TintColor) = GetTinting(item, textureData ?? data);
71+
}
5072
}
5173

5274
public ItemActivationResult Activate(
@@ -187,6 +209,52 @@ string defaultSound
187209
return Item is Tool && activationType == ItemActivationType.Instant ? null : defaultSound;
188210
}
189211

212+
private static Texture2D? GetDerivedTexture(Item item)
213+
{
214+
if (!DerivedTextures.TryGetValue(item, out var texture))
215+
{
216+
try
217+
{
218+
var graphicsDevice = Game1.graphics.GraphicsDevice;
219+
var spriteBatch = Game1.spriteBatch;
220+
var previousTargets = graphicsDevice.GetRenderTargets();
221+
var renderTarget = new RenderTarget2D(graphicsDevice, 64, 64);
222+
graphicsDevice.SetRenderTarget(renderTarget);
223+
graphicsDevice.Clear(Color.Transparent);
224+
spriteBatch.Begin(
225+
SpriteSortMode.Deferred,
226+
BlendState.AlphaBlend,
227+
rasterizerState: new() { MultiSampleAntiAlias = false },
228+
samplerState: SamplerState.PointClamp
229+
);
230+
try
231+
{
232+
item.drawInMenu(spriteBatch, Vector2.Zero, 1f);
233+
texture = renderTarget;
234+
DerivedTextures.Add(item, texture);
235+
}
236+
catch
237+
{
238+
renderTarget.Dispose();
239+
throw;
240+
}
241+
finally
242+
{
243+
spriteBatch.End();
244+
graphicsDevice.SetRenderTargets(previousTargets);
245+
}
246+
}
247+
catch (Exception ex)
248+
{
249+
Logger.Log(
250+
$"Error deriving texture for item '{item.Name}' ({item.QualifiedItemId}): {ex}",
251+
LogLevel.Error
252+
);
253+
}
254+
}
255+
return texture;
256+
}
257+
190258
public bool IsActivating()
191259
{
192260
return Item is Tool tool && Game1.player.CurrentTool == tool && Game1.player.UsingTool;

0 commit comments

Comments
 (0)