first commit
This commit is contained in:
40
NitroxClient/MonoBehaviours/Gui/Input/KeyBindingManager.cs
Normal file
40
NitroxClient/MonoBehaviours/Gui/Input/KeyBindingManager.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NitroxClient.MonoBehaviours.Gui.Input.KeyBindings;
|
||||
using NitroxClient.MonoBehaviours.Gui.Input.KeyBindings.Actions;
|
||||
using NitroxClient.Serialization;
|
||||
using NitroxModel.Helper;
|
||||
|
||||
namespace NitroxClient.MonoBehaviours.Gui.Input
|
||||
{
|
||||
public class KeyBindingManager
|
||||
{
|
||||
public List<KeyBinding> KeyboardKeyBindings { get; }
|
||||
|
||||
public KeyBindingManager()
|
||||
{
|
||||
ClientConfig cfg = ClientConfig.Load(NitroxUser.AppDataPath);
|
||||
KeyboardKeyBindings = new List<KeyBinding>
|
||||
{
|
||||
// new bindings should not be set to a value equivalent to a pre-existing GameInput.Button enum or another custom binding
|
||||
new((int)KeyBindingValues.CHAT, "Chat", GameInput.Device.Keyboard, new ChatKeyBindingAction(), cfg.OpenChatKeybindPrimary, cfg.OpenChatKeybindSecondary),
|
||||
new((int)KeyBindingValues.FOCUS_DISCORD, "Focus Discord (Alt +)", GameInput.Device.Keyboard, new DiscordFocusBindingAction(), cfg.FocusDiscordKeybindPrimary, cfg.FocusDiscordKeybindSecondary),
|
||||
};
|
||||
}
|
||||
|
||||
// Returns highest custom key binding value. If no custom key bindings, returns 0.
|
||||
public int GetHighestKeyBindingValue()
|
||||
{
|
||||
return KeyboardKeyBindings.Select(keyBinding => (int)keyBinding.Button).DefaultIfEmpty(0).Max();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refers the keybinding values used for button creation in the options menu, to a more clear form
|
||||
/// </summary>
|
||||
public enum KeyBindingValues
|
||||
{
|
||||
CHAT = 45,
|
||||
FOCUS_DISCORD = 46
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
using NitroxClient.GameLogic.ChatUI;
|
||||
using NitroxModel.Core;
|
||||
|
||||
namespace NitroxClient.MonoBehaviours.Gui.Input.KeyBindings.Actions
|
||||
{
|
||||
public class ChatKeyBindingAction : KeyBindingAction
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
// If no other UWE input field is currently active then allow chat to open.
|
||||
if (FPSInputModule.current.lastGroup == null)
|
||||
{
|
||||
NitroxServiceLocator.LocateService<PlayerChatManager>().SelectChat();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
using NitroxClient.MonoBehaviours.Discord;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.MonoBehaviours.Gui.Input.KeyBindings.Actions;
|
||||
|
||||
public class DiscordFocusBindingAction : KeyBindingAction
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
if (UnityEngine.Input.GetKey(KeyCode.LeftAlt))
|
||||
{
|
||||
DiscordJoinRequestGui.Select();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
namespace NitroxClient.MonoBehaviours.Gui.Input.KeyBindings.Actions
|
||||
{
|
||||
public abstract class KeyBindingAction
|
||||
{
|
||||
public abstract void Execute();
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
namespace NitroxClient.MonoBehaviours.Gui.Input.KeyBindings
|
||||
{
|
||||
public class DefaultKeyBinding
|
||||
{
|
||||
public string Binding { get; }
|
||||
public GameInput.BindingSet BindingSet { get; }
|
||||
|
||||
public DefaultKeyBinding(string defaultBinding, GameInput.BindingSet defaultBindingSet)
|
||||
{
|
||||
Binding = defaultBinding;
|
||||
BindingSet = defaultBindingSet;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
using NitroxClient.MonoBehaviours.Gui.Input.KeyBindings.Actions;
|
||||
using NitroxModel.Helper;
|
||||
|
||||
namespace NitroxClient.MonoBehaviours.Gui.Input.KeyBindings;
|
||||
|
||||
public class KeyBinding
|
||||
{
|
||||
public GameInput.Button Button { get; }
|
||||
public GameInput.Device Device { get; }
|
||||
public string Label { get; }
|
||||
public string PrimaryKey { get; }
|
||||
public string SecondaryKey { get; }
|
||||
public KeyBindingAction Action { get; }
|
||||
|
||||
public KeyBinding(int keyBindingValue, string buttonLabel, GameInput.Device buttonDevice, KeyBindingAction buttonAction, string primaryKey, string secondaryKey = null)
|
||||
{
|
||||
Validate.NotNull(primaryKey);
|
||||
|
||||
Button = (GameInput.Button)keyBindingValue;
|
||||
Device = buttonDevice;
|
||||
Label = buttonLabel;
|
||||
Action = buttonAction;
|
||||
PrimaryKey = primaryKey;
|
||||
SecondaryKey = secondaryKey;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user