I'm cooked, will finish this later.
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.LuaCs.Data;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using OneOf;
|
||||
|
||||
namespace Barotrauma.LuaCs.Configuration;
|
||||
|
||||
public class SettingControl : ISettingControl
|
||||
{
|
||||
public string InternalName { get; }
|
||||
public ContentPackage OwnerPackage { get; }
|
||||
public bool Equals(ISettingBase other)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IConfigDisplayInfo GetDisplayInfo()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Type GetValueType() => typeof(KeyOrMouse);
|
||||
public string GetStringValue() => Value.ToString();
|
||||
|
||||
public string GetDefaultStringValue() => new KeyOrMouse(Keys.NumLock).ToString();
|
||||
|
||||
public bool TrySetValue(OneOf<string, XElement> value)
|
||||
{
|
||||
var newVal = value.Match<KeyOrMouse>(
|
||||
(string v) => GetKeyOrMouse(v),
|
||||
(XElement e) => e.GetAttributeKeyOrMouse("Value", null));
|
||||
|
||||
if (newVal is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Value = newVal;
|
||||
OnValueChanged?.Invoke(this);
|
||||
return true;
|
||||
|
||||
KeyOrMouse GetKeyOrMouse(string strValue)
|
||||
{
|
||||
strValue ??= string.Empty;
|
||||
if (Enum.TryParse(strValue, true, out Microsoft.Xna.Framework.Input.Keys key))
|
||||
{
|
||||
return key;
|
||||
}
|
||||
else if (Enum.TryParse(strValue, out MouseButton mouseButton))
|
||||
{
|
||||
return mouseButton;
|
||||
}
|
||||
else if (int.TryParse(strValue, NumberStyles.Any, CultureInfo.InvariantCulture, out int mouseButtonInt) &&
|
||||
Enum.GetValues<MouseButton>().Contains((MouseButton)mouseButtonInt))
|
||||
{
|
||||
return (MouseButton)mouseButtonInt;
|
||||
}
|
||||
else if (string.Equals(strValue, "LeftMouse", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return !PlayerInput.MouseButtonsSwapped() ? MouseButton.PrimaryMouse : MouseButton.SecondaryMouse;
|
||||
}
|
||||
else if (string.Equals(strValue, "RightMouse", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return !PlayerInput.MouseButtonsSwapped() ? MouseButton.SecondaryMouse : MouseButton.PrimaryMouse;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public event Action<ISettingBase> OnValueChanged;
|
||||
public OneOf<string, XElement> GetSerializableValue()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
|
||||
public KeyOrMouse Value { get; private set; } = new KeyOrMouse(Keys.NumLock);
|
||||
|
||||
public bool TrySetValue(KeyOrMouse value)
|
||||
{
|
||||
Value = value;
|
||||
OnValueChanged?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsDown()
|
||||
{
|
||||
if (this.Value is null)
|
||||
return false;
|
||||
switch (this.Value.MouseButton)
|
||||
{
|
||||
case MouseButton.None:
|
||||
return Barotrauma.PlayerInput.KeyDown(this.Value.Key);
|
||||
case MouseButton.PrimaryMouse:
|
||||
return Barotrauma.PlayerInput.PrimaryMouseButtonHeld();
|
||||
case MouseButton.SecondaryMouse:
|
||||
return Barotrauma.PlayerInput.SecondaryMouseButtonHeld();
|
||||
case MouseButton.MiddleMouse:
|
||||
return Barotrauma.PlayerInput.MidButtonHeld();
|
||||
case MouseButton.MouseButton4:
|
||||
return Barotrauma.PlayerInput.Mouse4ButtonHeld();
|
||||
case MouseButton.MouseButton5:
|
||||
return Barotrauma.PlayerInput.Mouse5ButtonHeld();
|
||||
case MouseButton.MouseWheelUp:
|
||||
return Barotrauma.PlayerInput.MouseWheelUpClicked();
|
||||
case MouseButton.MouseWheelDown:
|
||||
return Barotrauma.PlayerInput.MouseWheelDownClicked();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsHit()
|
||||
{
|
||||
if (this.Value is null)
|
||||
return false;
|
||||
switch (this.Value.MouseButton)
|
||||
{
|
||||
case MouseButton.None:
|
||||
return Barotrauma.PlayerInput.KeyHit(this.Value.Key);
|
||||
case MouseButton.PrimaryMouse:
|
||||
return Barotrauma.PlayerInput.PrimaryMouseButtonClicked();
|
||||
case MouseButton.SecondaryMouse:
|
||||
return Barotrauma.PlayerInput.SecondaryMouseButtonClicked();
|
||||
case MouseButton.MiddleMouse:
|
||||
return Barotrauma.PlayerInput.MidButtonClicked();
|
||||
case MouseButton.MouseButton4:
|
||||
return Barotrauma.PlayerInput.Mouse4ButtonClicked();
|
||||
case MouseButton.MouseButton5:
|
||||
return Barotrauma.PlayerInput.Mouse5ButtonClicked();
|
||||
case MouseButton.MouseWheelUp:
|
||||
return Barotrauma.PlayerInput.MouseWheelUpClicked();
|
||||
case MouseButton.MouseWheelDown:
|
||||
return Barotrauma.PlayerInput.MouseWheelDownClicked();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user