|
4 | 4 |
|
5 | 5 | namespace ModdingToolkit.Config; |
6 | 6 |
|
7 | | -public sealed class ConfigControl : IConfigControl |
| 7 | +public sealed class ConfigControl : IConfigControl, IDisplayable |
8 | 8 | { |
9 | 9 | private event System.Func<KeyOrMouse, bool>? _validateInput; |
10 | 10 | private event System.Action? _onValueChanged; |
11 | | - public string Name { get; set; } = String.Empty; |
| 11 | + public string Name { get; private set; } = String.Empty; |
12 | 12 | public Type SubTypeDef => typeof(KeyOrMouse); |
13 | | - public string ModName { get; set; } = String.Empty; |
14 | | - public IConfigBase.Category MenuCategory => IConfigBase.Category.Ignore; |
| 13 | + public string ModName { get; private set; } = String.Empty; |
| 14 | + public string DisplayName { get; private set; } |
| 15 | + public string DisplayModName { get; private set; } |
| 16 | + public string DisplayCategory { get; private set; } |
| 17 | + public string Tooltip { get; private set; } |
| 18 | + public string ImageIcon { get; private set; } |
| 19 | + public Category MenuCategory => Category.Controls; |
15 | 20 | public NetworkSync NetSync => NetworkSync.NoSync; |
16 | 21 |
|
17 | 22 | public string GetStringValue() |
@@ -48,7 +53,22 @@ public void SetValueAsDefault() |
48 | 53 | this.Value = new KeyOrMouse(DefaultValue.MouseButton); |
49 | 54 | } |
50 | 55 |
|
51 | | - public IConfigBase.DisplayType GetDisplayType() => IConfigBase.DisplayType.KeyOrMouse; |
| 56 | + public DisplayType GetDisplayType() => DisplayType.KeyOrMouse; |
| 57 | + |
| 58 | + public void InitializeDisplay(string? name = "", string? modName = "", string? displayName = "", string? displayModName = "", |
| 59 | + string? displayCategory = "", string? tooltip = "", string? imageIcon = "", Category menuCategory = Category.Gameplay) |
| 60 | + { |
| 61 | + if (!displayName.IsNullOrWhiteSpace()) |
| 62 | + this.DisplayName = displayName; |
| 63 | + if (!displayModName.IsNullOrWhiteSpace()) |
| 64 | + this.DisplayModName = displayModName; |
| 65 | + if (!displayCategory.IsNullOrWhiteSpace()) |
| 66 | + this.DisplayCategory = displayCategory; |
| 67 | + if (!tooltip.IsNullOrWhiteSpace()) |
| 68 | + this.Tooltip = tooltip; |
| 69 | + if (!imageIcon.IsNullOrWhiteSpace()) |
| 70 | + this.ImageIcon = imageIcon; |
| 71 | + } |
52 | 72 |
|
53 | 73 | private KeyOrMouse? _value; |
54 | 74 | public KeyOrMouse? Value |
@@ -87,6 +107,34 @@ public bool Validate(KeyOrMouse? newValue) |
87 | 107 | return this._validateInput?.Invoke(newValue) ?? true; |
88 | 108 | } |
89 | 109 |
|
| 110 | + public bool IsHit() |
| 111 | + { |
| 112 | + if (this.Value is null) |
| 113 | + return false; |
| 114 | + switch (this.Value.MouseButton) |
| 115 | + { |
| 116 | + case MouseButton.None: |
| 117 | + return Barotrauma.PlayerInput.KeyHit(this.Value.Key); |
| 118 | + case MouseButton.PrimaryMouse: |
| 119 | + case MouseButton.LeftMouse: |
| 120 | + return Barotrauma.PlayerInput.PrimaryMouseButtonClicked(); |
| 121 | + case MouseButton.SecondaryMouse: |
| 122 | + case MouseButton.RightMouse: |
| 123 | + return Barotrauma.PlayerInput.SecondaryMouseButtonClicked(); |
| 124 | + case MouseButton.MiddleMouse: |
| 125 | + return Barotrauma.PlayerInput.MidButtonClicked(); |
| 126 | + case MouseButton.MouseButton4: |
| 127 | + return Barotrauma.PlayerInput.Mouse4ButtonClicked(); |
| 128 | + case MouseButton.MouseButton5: |
| 129 | + return Barotrauma.PlayerInput.Mouse5ButtonClicked(); |
| 130 | + case MouseButton.MouseWheelUp: |
| 131 | + return Barotrauma.PlayerInput.MouseWheelUpClicked(); |
| 132 | + case MouseButton.MouseWheelDown: |
| 133 | + return Barotrauma.PlayerInput.MouseWheelDownClicked(); |
| 134 | + } |
| 135 | + return false; |
| 136 | + } |
| 137 | + |
90 | 138 | public bool ValidateString(string value) |
91 | 139 | { |
92 | 140 | if (Enum.IsDefined(typeof(Keys), value)) |
|
0 commit comments