Skip to content

Commit 830679c

Browse files
committed
Fix missing tooltips localisation error
1 parent cce09e1 commit 830679c

File tree

7 files changed

+39
-4
lines changed

7 files changed

+39
-4
lines changed

Patches/LocalisationPatches.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ private static bool GetTootipData(Item __instance, ref IEnumerable<IHaveUIData>
4040
{
4141
return true;
4242
}
43-
// Parse glyphs into the default tooltips if they weren't localised, without overwriting them on the item (fallback if the item was not localised)
4443
string key = __instance.name.Trim().Replace(" ", "") + ShopLocalisation.TooltipsSuffix;
44+
// Attempt to load previously defined tooltips, in case the current locale is not provided (fallback).
4545
IEnumerable<string> locTooltips = __instance.Tooltips.Select(ikt => ikt.m_text);
4646
var ret = new List<ItemKeyTooltip>();
4747
if (ShopLocalisation.TryGetLocaleString(key, out var localeStr))
@@ -50,9 +50,15 @@ private static bool GetTootipData(Item __instance, ref IEnumerable<IHaveUIData>
5050
}
5151
foreach (var tip in locTooltips)
5252
{
53+
if (string.IsNullOrEmpty(tip))
54+
{
55+
continue;
56+
}
5357
string parsedTip = ParseTip(__instance, tip, out IMKbPromptProvider provider, out List<ControllerGlyphs.GlyphType> glyphType);
5458
ret.Add(new ItemKeyTooltip(parsedTip, provider, glyphType));
5559
}
60+
// Set localised tooltips back as a failsafe
61+
__instance.Tooltips = ret;
5662
__result = ret;
5763
return false;
5864
}

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ Note that when localising item tooltips the key must be the item's name, suffixe
9090
| SelfieGlyph | R (Default) |
9191
| ZoomGlyph | Scroll wheel |
9292

93+
> [!IMPORTANT]
94+
> If you don't want to add localisation ( :( ), use the `SetDefaultTooltips` extension method on your `Item` to set default tooltips.
95+
> If you set tooltips in the editor, they won't work: this is a bug on Unity's end, not this mod. (those tooltips are serialised to null when you save them, even if they look right in the inspector)
96+
> Setting a default is recommended in any case, but especially if you don't or only partially provide localisation.
9397
9498
## Compatibility
9599

ShopApiPlugin.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ShopApiPlugin
1717
{
1818
public const string MOD_GUID = "xerren.cwshopapi";
1919
public const string MOD_NAME = "ShopAPI";
20-
public const string MOD_VER = "1.0.0";
20+
public const string MOD_VER = "1.0.1";
2121

2222
#if STEAM
2323
static ShopApiPlugin()

ShopLocalisation.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEngine;
1+
using ShopAPI.Patches;
2+
using UnityEngine;
23
using UnityEngine.Localization.Settings;
34

45
namespace ContentWarningShop.Localisation
@@ -121,5 +122,20 @@ public static bool TryGetLocaleString(string key, out string res)
121122
res = str;
122123
return found;
123124
}
125+
126+
/// <summary>
127+
/// Sets default tooltip string on the item. This will be used if you don't otherwise provide localisation for your item.
128+
/// </summary>
129+
/// <param name="item"></param>
130+
/// <param name="tooltipString">A ";" separated string of item tooltips. See <see href="https://github.com/Xerren09/ContentWarningShopAPI#localisation"/> for more.</param>
131+
public static void SetDefaultTooltips(this Item item, string tooltipString)
132+
{
133+
var tooltips = tooltipString.Split(';');
134+
item.Tooltips = new();
135+
foreach (var tooltip in tooltips)
136+
{
137+
item.Tooltips.Add(new ItemKeyTooltip(tooltip, null, null));
138+
}
139+
}
124140
}
125141
}

publish/thunderstore/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
All notable changes will be documented in this file.
44
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## 1.0.1
7+
- Fix `GetTootipData` patch exception when null tooltips are set on the Item, and no localised strings were provided.
8+
- This is unity's fault. Tooltips should be serialised correctly on Item resources, but they aren't loaded, so the count is correct but the text is null.
9+
- Added `SetDefaultTooltips` extension method to set fallback tooltips.
10+
611
## 1.0.0
712
- Initial Release

publish/thunderstore/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ Note that when localising item tooltips the key must be the item's name, suffixe
7070
| SelfieGlyph | R (Default) |
7171
| ZoomGlyph | Scroll wheel |
7272

73+
> IMPORTANT:
74+
> If you don't want to add localisation ( :( ), use the `SetDefaultTooltips` extension method on your `Item` to set default tooltips.
75+
> If you set tooltips in the editor, they won't work: this is a bug on Unity's end, not this mod. (those tooltips are serialised to null when you save them, even if they look right in the inspector)
76+
> Setting a default is recommended in any case, but especially if you don't or only partially provide localisation.
7377
7478
## Compatibility
7579

publish/thunderstore/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ShopAPI",
3-
"version_number": "1.0.0",
3+
"version_number": "1.0.1",
44
"website_url": "https://github.com/Xerren09/ContentWarningShopAPI",
55
"description": "Exposes an easy-to-use API to add custom items to the in-game shop.",
66
"dependencies": [

0 commit comments

Comments
 (0)