Skip to content

Commit aae3df8

Browse files
committed
feat(HoverTips): enhance content source hover tips configuration
- Added new settings for displaying source hover tips for various content types including cards, relics, potions, powers, orbs, enchantments, afflictions, keywords, events, creatures, and game terms. - Implemented a migration to ensure default values for new settings are set to true. - Introduced a dedicated settings page for configuring content source hover tips visibility, improving user experience and customization options. - Updated existing hover tip logic to respect new settings, ensuring only enabled tips are displayed during gameplay.
1 parent f869110 commit aae3df8

18 files changed

Lines changed: 444 additions & 48 deletions

Content/ContentSourceHoverTipFactory.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ internal static bool TryResolve(AbstractModel model, out ContentSourceInfo sourc
4747
return false;
4848
}
4949

50+
if (!IsModelSectionEnabled(model))
51+
{
52+
source = default;
53+
return false;
54+
}
55+
5056
source = model is IContentSourceSupplier supplier
5157
? Resolve(supplier)
5258
: Resolve(model.GetType());
@@ -58,6 +64,21 @@ internal static bool ShouldShow(ContentSourceInfo source)
5864
return !source.IsVanilla || RitsuLibSettingsStore.ShouldIncludeVanillaModSourceHoverTips();
5965
}
6066

67+
private static bool IsModelSectionEnabled(AbstractModel model)
68+
{
69+
return model switch
70+
{
71+
CardModel => RitsuLibSettingsStore.ShouldShowCardModSourceHoverTips(),
72+
RelicModel => RitsuLibSettingsStore.ShouldShowRelicModSourceHoverTips(),
73+
PotionModel => RitsuLibSettingsStore.ShouldShowPotionModSourceHoverTips(),
74+
PowerModel => RitsuLibSettingsStore.ShouldShowPowerModSourceHoverTips(),
75+
OrbModel => RitsuLibSettingsStore.ShouldShowOrbModSourceHoverTips(),
76+
EnchantmentModel => RitsuLibSettingsStore.ShouldShowEnchantmentModSourceHoverTips(),
77+
AfflictionModel => RitsuLibSettingsStore.ShouldShowAfflictionModSourceHoverTips(),
78+
_ => true,
79+
};
80+
}
81+
6182
private static HoverTip CreateTip(ContentSourceInfo source)
6283
{
6384
return new(GetTitle(), source.Format())

Content/Patches/ContentSourceHoverTipPatches.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ internal static void UpdateEventSourceBadge(NEventLayout layout, EventModel even
7676
{
7777
var existing = layout.GetNodeOrNull<NHoverTipSet>(EventBadgeNodeName);
7878
var existingHotZone = layout.GetNodeOrNull<Control>(EventDrawerHotZoneName);
79-
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled())
79+
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled() ||
80+
!RitsuLibSettingsStore.ShouldShowEventModSourceHoverTips())
8081
{
8182
RemoveBadge(layout, existing);
8283
RemoveBadge(layout, existingHotZone);
@@ -262,7 +263,8 @@ public static ModPatchTarget[] GetTargets()
262263
public static void Postfix(CardKeyword keyword, ref IHoverTip __result)
263264
// ReSharper restore once InconsistentNaming
264265
{
265-
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled())
266+
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled() ||
267+
!RitsuLibSettingsStore.ShouldShowKeywordModSourceHoverTips())
266268
return;
267269

268270
var info = ContentSourceHoverTipFactory.ResolveKeyword(keyword);
@@ -293,7 +295,8 @@ public static ModPatchTarget[] GetTargets()
293295
public static void Postfix(ref IHoverTip __result)
294296
// ReSharper restore once InconsistentNaming
295297
{
296-
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled())
298+
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled() ||
299+
!RitsuLibSettingsStore.ShouldShowGameTermModSourceHoverTips())
297300
return;
298301

299302
var info = ContentSourceHoverTipFactory.ContentSourceInfo.Vanilla;
@@ -324,7 +327,8 @@ public static ModPatchTarget[] GetTargets()
324327
public static void Postfix(ref IHoverTip __result)
325328
// ReSharper restore once InconsistentNaming
326329
{
327-
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled())
330+
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled() ||
331+
!RitsuLibSettingsStore.ShouldShowGameTermModSourceHoverTips())
328332
return;
329333

330334
var info = ContentSourceHoverTipFactory.ContentSourceInfo.Vanilla;
@@ -370,18 +374,7 @@ public static void Postfix(AbstractModel __instance, ref HoverTip __result)
370374
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled())
371375
return;
372376

373-
if (__instance is IContentSourceSupplier supplier)
374-
{
375-
var source = ContentSourceHoverTipFactory.Resolve(supplier);
376-
if (!ContentSourceHoverTipFactory.ShouldShow(source))
377-
return;
378-
379-
ContentSourceHoverTipPatchHelper.Append(source, ref __result);
380-
return;
381-
}
382-
383-
var info = ContentSourceHoverTipFactory.Resolve(__instance.GetType());
384-
if (!ContentSourceHoverTipFactory.ShouldShow(info))
377+
if (!ContentSourceHoverTipFactory.TryResolve(__instance, out var info))
385378
return;
386379

387380
ContentSourceHoverTipPatchHelper.Append(info, ref __result);
@@ -522,7 +515,8 @@ private static void AppendTip<T>(FieldInfo? listField, FieldInfo? indexField, Co
522515
public static void Prefix(Control owner, ref IEnumerable<IHoverTip> hoverTips)
523516
// ReSharper restore once InconsistentNaming
524517
{
525-
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled())
518+
if (!RitsuLibSettingsStore.IsModSourceHoverTipsEnabled() ||
519+
!RitsuLibSettingsStore.ShouldShowCreatureModSourceHoverTips())
526520
return;
527521

528522
switch (owner)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Text.Json.Nodes;
2+
using STS2RitsuLib.Utils.Persistence.Migration;
3+
4+
namespace STS2RitsuLib.Data.Migrations
5+
{
6+
internal sealed class RitsuLibSettingsV10ToV11Migration : IMigration
7+
{
8+
public int FromVersion => 10;
9+
10+
public int ToVersion => 11;
11+
12+
public bool Migrate(JsonObject data)
13+
{
14+
data["mod_source_hover_tips_cards"] ??= true;
15+
data["mod_source_hover_tips_relics"] ??= true;
16+
data["mod_source_hover_tips_potions"] ??= true;
17+
data["mod_source_hover_tips_powers"] ??= true;
18+
data["mod_source_hover_tips_orbs"] ??= true;
19+
data["mod_source_hover_tips_enchantments"] ??= true;
20+
data["mod_source_hover_tips_afflictions"] ??= true;
21+
data["mod_source_hover_tips_keywords"] ??= true;
22+
data["mod_source_hover_tips_events"] ??= true;
23+
data["mod_source_hover_tips_creatures"] ??= true;
24+
data["mod_source_hover_tips_game_terms"] ??= true;
25+
return true;
26+
}
27+
}
28+
}

Data/Models/RitsuLibSettings.cs

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class RitsuLibSettings
1313
/// Current schema version written by the library when creating or normalizing settings.
1414
/// 库在创建或规范化设置时写入的当前 schema 版本。
1515
/// </summary>
16-
public const int CurrentSchemaVersion = 10;
16+
public const int CurrentSchemaVersion = 11;
1717

1818
/// <summary>
1919
/// Persisted schema version used by the migration pipeline
@@ -90,6 +90,83 @@ public sealed class RitsuLibSettings
9090
[JsonPropertyName("mod_source_hover_tips_include_non_details")]
9191
public bool ModSourceHoverTipsIncludeNonDetails { get; set; }
9292

93+
/// <summary>
94+
/// Shows source hover tips for cards.
95+
/// 为卡牌显示来源悬停提示。
96+
/// </summary>
97+
[JsonPropertyName("mod_source_hover_tips_cards")]
98+
public bool ModSourceHoverTipsCards { get; set; } = true;
99+
100+
/// <summary>
101+
/// Shows source hover tips for relics.
102+
/// 为遗物显示来源悬停提示。
103+
/// </summary>
104+
[JsonPropertyName("mod_source_hover_tips_relics")]
105+
public bool ModSourceHoverTipsRelics { get; set; } = true;
106+
107+
/// <summary>
108+
/// Shows source hover tips for potions.
109+
/// 为药水显示来源悬停提示。
110+
/// </summary>
111+
[JsonPropertyName("mod_source_hover_tips_potions")]
112+
public bool ModSourceHoverTipsPotions { get; set; } = true;
113+
114+
/// <summary>
115+
/// Shows source hover tips for powers.
116+
/// 为能力显示来源悬停提示。
117+
/// </summary>
118+
[JsonPropertyName("mod_source_hover_tips_powers")]
119+
public bool ModSourceHoverTipsPowers { get; set; } = true;
120+
121+
/// <summary>
122+
/// Shows source hover tips for orbs.
123+
/// 为充能球显示来源悬停提示。
124+
/// </summary>
125+
[JsonPropertyName("mod_source_hover_tips_orbs")]
126+
public bool ModSourceHoverTipsOrbs { get; set; } = true;
127+
128+
/// <summary>
129+
/// Shows source hover tips for enchantments.
130+
/// 为附魔显示来源悬停提示。
131+
/// </summary>
132+
[JsonPropertyName("mod_source_hover_tips_enchantments")]
133+
public bool ModSourceHoverTipsEnchantments { get; set; } = true;
134+
135+
/// <summary>
136+
/// Shows source hover tips for afflictions.
137+
/// 为苦痛显示来源悬停提示。
138+
/// </summary>
139+
[JsonPropertyName("mod_source_hover_tips_afflictions")]
140+
public bool ModSourceHoverTipsAfflictions { get; set; } = true;
141+
142+
/// <summary>
143+
/// Shows source hover tips for keyword tooltips.
144+
/// 为关键词悬停提示显示来源。
145+
/// </summary>
146+
[JsonPropertyName("mod_source_hover_tips_keywords")]
147+
public bool ModSourceHoverTipsKeywords { get; set; } = true;
148+
149+
/// <summary>
150+
/// Shows source hover tips for event layouts.
151+
/// 为事件界面显示来源提示。
152+
/// </summary>
153+
[JsonPropertyName("mod_source_hover_tips_events")]
154+
public bool ModSourceHoverTipsEvents { get; set; } = true;
155+
156+
/// <summary>
157+
/// Shows source hover tips for creature hover tips.
158+
/// 为生物悬停提示显示来源。
159+
/// </summary>
160+
[JsonPropertyName("mod_source_hover_tips_creatures")]
161+
public bool ModSourceHoverTipsCreatures { get; set; } = true;
162+
163+
/// <summary>
164+
/// Shows source hover tips for base game term tooltips such as block and energy.
165+
/// 为格挡、能量等基础游戏术语悬停提示显示来源。
166+
/// </summary>
167+
[JsonPropertyName("mod_source_hover_tips_game_terms")]
168+
public bool ModSourceHoverTipsGameTerms { get; set; } = true;
169+
93170
/// <summary>
94171
/// Absolute path or Godot <c>user://</c> path for Harmony patch dump output (text log).
95172
/// Harmony 补丁转储输出(文本日志)的绝对路径或 Godot <c>user://</c> 路径。

Data/RitsuLibSettingsStore.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ internal static void Initialize()
4848
new RitsuLibSettingsV7ToV8Migration(),
4949
new RitsuLibSettingsV8ToV9Migration(),
5050
new RitsuLibSettingsV9ToV10Migration(),
51+
new RitsuLibSettingsV10ToV11Migration(),
5152
]);
5253
}
5354

@@ -136,6 +137,72 @@ internal static bool ShouldIncludeNonDetailModSourceHoverTips()
136137
return GetSettings().ModSourceHoverTipsIncludeNonDetails;
137138
}
138139

140+
internal static bool ShouldShowCardModSourceHoverTips()
141+
{
142+
Initialize();
143+
return GetSettings().ModSourceHoverTipsCards;
144+
}
145+
146+
internal static bool ShouldShowRelicModSourceHoverTips()
147+
{
148+
Initialize();
149+
return GetSettings().ModSourceHoverTipsRelics;
150+
}
151+
152+
internal static bool ShouldShowPotionModSourceHoverTips()
153+
{
154+
Initialize();
155+
return GetSettings().ModSourceHoverTipsPotions;
156+
}
157+
158+
internal static bool ShouldShowPowerModSourceHoverTips()
159+
{
160+
Initialize();
161+
return GetSettings().ModSourceHoverTipsPowers;
162+
}
163+
164+
internal static bool ShouldShowOrbModSourceHoverTips()
165+
{
166+
Initialize();
167+
return GetSettings().ModSourceHoverTipsOrbs;
168+
}
169+
170+
internal static bool ShouldShowEnchantmentModSourceHoverTips()
171+
{
172+
Initialize();
173+
return GetSettings().ModSourceHoverTipsEnchantments;
174+
}
175+
176+
internal static bool ShouldShowAfflictionModSourceHoverTips()
177+
{
178+
Initialize();
179+
return GetSettings().ModSourceHoverTipsAfflictions;
180+
}
181+
182+
internal static bool ShouldShowKeywordModSourceHoverTips()
183+
{
184+
Initialize();
185+
return GetSettings().ModSourceHoverTipsKeywords;
186+
}
187+
188+
internal static bool ShouldShowEventModSourceHoverTips()
189+
{
190+
Initialize();
191+
return GetSettings().ModSourceHoverTipsEvents;
192+
}
193+
194+
internal static bool ShouldShowCreatureModSourceHoverTips()
195+
{
196+
Initialize();
197+
return GetSettings().ModSourceHoverTipsCreatures;
198+
}
199+
200+
internal static bool ShouldShowGameTermModSourceHoverTips()
201+
{
202+
Initialize();
203+
return GetSettings().ModSourceHoverTipsGameTerms;
204+
}
205+
139206
private static RitsuLibSettings GetSettings()
140207
{
141208
return Store.Get<RitsuLibSettings>(Const.SettingsKey);

0 commit comments

Comments
 (0)