Skip to content

Commit 4e6d471

Browse files
committed
use actual Valheim key strings
1 parent 3f13765 commit 4e6d471

5 files changed

Lines changed: 52 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Replace Hugin cartography table tutorial vanilla text to be consistent with the mod's functionality.
1313

14+
### Changed
15+
16+
- Display cartography modifier key hint using actual Valheim key strings instead of raw key code.
17+
1418
## [0.5.5] - 2024-06-08
1519

1620
### Changed

src/Extensions/KeyCode.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using UnityEngine;
2+
using UnityEngine.InputSystem;
3+
using UnityEngine.InputSystem.LowLevel;
4+
5+
namespace BetterCartographyTable.Extensions;
6+
7+
public static class KeyCodeExtensions
8+
{
9+
public static string ToKeyHintString(this KeyCode keyCode)
10+
{
11+
var (isMouseButton, mouseButton) = ZInput.KeyCodeToMouseButton(keyCode, logWarning: false);
12+
if (isMouseButton)
13+
{
14+
var mouseString = mouseButton switch
15+
{
16+
MouseButton.Left => "$button_mouse0",
17+
MouseButton.Right => "$button_mouse1",
18+
MouseButton.Middle => "$button_mouse2",
19+
MouseButton.Forward => Mouse.current?.forwardButton.displayName ?? "Mouse Forward",
20+
MouseButton.Back => Mouse.current?.backButton.displayName ?? "Mouse Back",
21+
_ => null,
22+
};
23+
if (mouseString is not null) return mouseString;
24+
}
25+
26+
var key = ZInput.KeyCodeToKey(keyCode, logWarning: false);
27+
return key switch
28+
{
29+
Key.Comma => ",",
30+
Key.Period => ".",
31+
Key.Space => "$button_space",
32+
Key.LeftShift => "$button_lshift",
33+
Key.RightShift => "$button_rshift",
34+
Key.LeftAlt => "$button_lalt",
35+
Key.RightAlt => "$button_ralt",
36+
Key.LeftCtrl => "$button_lctrl",
37+
Key.RightCtrl => "$button_rctrl",
38+
Key.Enter => "$button_return",
39+
Key.NumpadEnter => "$button_return",
40+
Key.None => "$menu_none",
41+
_ => Keyboard.current?[key].displayName ?? key.ToString(),
42+
};
43+
}
44+
}

src/Model/Managers/MapTableManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public string GetHoverText()
7878
if (!GuildsManager.IsEnabled) return hoverText;
7979

8080
var toggleTo = this.IsGuild ? $"$MapTable_HoverText_MakePublic" : $"$MapTable_HoverText_RestrictToGuild";
81-
return hoverText + $"\n[<b><color=yellow>{Plugin.ModifierKey}</color> + <color=yellow>$KEY_Use</color></b>] {toggleTo}";
81+
return hoverText + $"\n[<b><color=yellow>{Plugin.ModifierKey.ToKeyHintString()}</color> + <color=yellow>$KEY_Use</color></b>] {toggleTo}";
8282
}
8383

8484
private void TryToggleMode(Humanoid user)

src/UI/MinimapKeyHint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class MinimapKeyHint(GameObject keyHint)
88
private readonly GameObject _gameObject = keyHint;
99
public string Text { set => this._gameObject.SetText(value); }
1010

11-
public static MinimapKeyHint Clone(MinimapKeyHint original, string name, KeyCode key)
11+
public static MinimapKeyHint Clone(MinimapKeyHint original, string name, string key)
1212
{
1313
// clone original MinimapKeyHint and set clone as its first sibling
1414
var clone = Object.Instantiate(original._gameObject, original._gameObject.transform.parent);
@@ -22,7 +22,7 @@ public static MinimapKeyHint Clone(MinimapKeyHint original, string name, KeyCode
2222
var keyBkg = KeyHints.m_instance.m_buildHints.transform.Find("Keyboard/AltPlace/key_bkg").gameObject;
2323
var keyBkgClone = Object.Instantiate(keyBkg, clone.transform);
2424
keyBkgClone.name = "key_bkg";
25-
keyBkgClone.SetText(key.ToString());
25+
keyBkgClone.SetText(key);
2626

2727
// hide clone by default
2828
clone.SetActive(false);

src/UI/MinimapUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void PrepareKeyHints()
4646
KeyHints.DoubleClick = new(keyHints.Find("keyboard_hints/AddPin").gameObject);
4747
KeyHints.LeftClick = new(keyHints.Find("keyboard_hints/CrossOffPin").gameObject);
4848
KeyHints.RightClick = new(keyHints.Find("keyboard_hints/RemovePin").gameObject);
49-
KeyHints.ModifierKey = MinimapKeyHint.Clone(KeyHints.DoubleClick, "ModifierKey", Plugin.ModifierKey);
49+
KeyHints.ModifierKey = MinimapKeyHint.Clone(KeyHints.DoubleClick, "ModifierKey", Plugin.ModifierKey.ToKeyHintString());
5050
}
5151

5252
public static void ShowTableUI()

0 commit comments

Comments
 (0)