Skip to content

Commit 318f6bb

Browse files
fix
1 parent a8f13bb commit 318f6bb

File tree

5 files changed

+46
-12
lines changed

5 files changed

+46
-12
lines changed

AdvancedHints/Components/HudManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace AdvancedHints.Components
99
{
1010
using System.Collections.Generic;
11+
using System.IO;
1112
using System.Linq;
1213
using AdvancedHints.Enums;
1314
using AdvancedHints.Models;
@@ -95,10 +96,10 @@ private void OnDestroy()
9596

9697
private void UpdateHints()
9798
{
98-
toFormat = Displays.Values.Select(display => FormatStringForHud(display.Content ?? string.Empty, 6)).ToArray<object>();
99+
toFormat = Displays.Values.Select(display => FormatStringForHud(display.Content ?? string.Empty, Plugin.Singleton.Config.LinesPerPosition)).ToArray<object>();
99100
hint = string.Format(Plugin.Singleton.Config.HudTemplate, toFormat);
100101

101-
player.ShowHint(hint, Plugin.Singleton.Config.HintDuration);
102+
player.ShowHint(Plugin.HintPrefix + hint, Plugin.Singleton.Config.HintDuration);
102103
}
103104

104105
private string FormatStringForHud(string text, int needNewLine)

AdvancedHints/Config.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,24 @@ public class Config : IConfig
3030
[Description("The duration of a single hint, in seconds.")]
3131
public float HintDuration { get; set; } = 2f;
3232

33-
[Description("Whether or not to enable plugin overrides (see below).")]
34-
public bool EnablePluginOverrides { get; set; } = true;
35-
3633
// ReSharper disable once CollectionNeverUpdated.Global
3734
[Description("Messages that will appear if nothing else is quened for the display.")]
3835
public Dictionary<DisplayLocation, string> DefaultMessages { get; set; } = new ()
3936
{
4037
};
4138

39+
[Description("Whether or not to enable message overrides (see below).")]
40+
public bool EnableMessageStartsWithOverrides { get; set; } = true;
41+
42+
[Description("Message overrides for specific hint positions.")]
43+
public Dictionary<string, DisplayLocation> MessageStartsWithOverrides { get; set; } = new ()
44+
{
45+
{ "You will respawn in", DisplayLocation.Middle },
46+
};
47+
48+
[Description("Whether or not to enable plugin overrides (see below).")]
49+
public bool EnablePluginOverrides { get; set; } = true;
50+
4251
[Description("Plugin overrides for specific hint positions.")]
4352
public Dictionary<string, DisplayLocation> PluginOverrides { get; set; } = new ()
4453
{
@@ -47,6 +56,9 @@ public class Config : IConfig
4756

4857
[Description("The template for the hint display.")]
4958
public string HudTemplate { get; set; } =
50-
"\"<line-height=95%><voffset=8.5em><alpha=#ff>\\n\\n\\n<align=center>{0}{1}{2}{3}{4}</align>\"";
59+
"<line-height=95%><voffset=8.5em><alpha=#ff>\\n\\n\\n<align=center>{0}{1}{2}{3}{4}</align>";
60+
61+
[Description("Newlines per position, edit with template.")]
62+
public int LinesPerPosition { get; set; } = 6;
5163
}
5264
}

AdvancedHints/Models/HudDisplay.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ public HudDisplay()
3535
public string DefaultText
3636
{
3737
get => defaultText;
38-
set => defaultText = value ?? string.Empty;
38+
set
39+
{
40+
defaultText = value ?? string.Empty;
41+
if (string.IsNullOrEmpty(Content))
42+
Content = defaultText;
43+
}
3944
}
4045

4146
/// <summary>

AdvancedHints/Patches/ShowHint.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,33 @@ namespace AdvancedHints.Patches
1717
using HarmonyLib;
1818

1919
/// <summary>
20-
/// Hijacks <see cref="Player.ShowHint"/> and directs it towards <see cref="ShowHint"/>.
20+
/// Hijacks <see cref="Player.ShowHint(string, float)"/> and directs it towards <see cref="ShowHint"/>.
2121
/// </summary>
2222
[HarmonyPatch(typeof(Player), nameof(Player.ShowHint), typeof(string), typeof(float))]
2323
internal static class ShowHint
2424
{
25-
private static bool Prefix(Player __instance, string message, float duration = 3f)
25+
private static bool Prefix(Player __instance, ref string message, float duration = 3f)
2626
{
27-
if (message.Contains("You will respawn in"))
27+
if (message.StartsWith(Plugin.HintPrefix))
2828
{
29-
HudManager.ShowHint(__instance, "\n" + message, duration, displayLocation: DisplayLocation.Middle);
30-
return false;
29+
message = message.Substring(Plugin.HintPrefix.Length);
30+
return true;
3131
}
3232

3333
DisplayLocation displayLocation = DisplayLocation.MiddleBottom;
3434

35+
if (Plugin.Singleton.Config.EnableMessageStartsWithOverrides)
36+
{
37+
foreach (var kvp in Plugin.Singleton.Config.MessageStartsWithOverrides)
38+
{
39+
if (message.Contains(kvp.Key))
40+
{
41+
displayLocation = kvp.Value;
42+
break;
43+
}
44+
}
45+
}
46+
3547
if (Plugin.Singleton.Config.EnablePluginOverrides)
3648
{
3749
try

AdvancedHints/Plugin.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace AdvancedHints
1818
/// </summary>
1919
public class Plugin : Plugin<Config>
2020
{
21+
/// <summary>
22+
/// The prefix that makes the patch ignore the hint.
23+
/// </summary>
24+
public const string HintPrefix = "ADVHINTS";
2125
private EventHandlers eventHandlers;
2226
private Harmony harmony;
2327

0 commit comments

Comments
 (0)