From ec2416719e92ec7918c579725ad818e6f79cbe9b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 16 Jul 2020 16:04:18 +0200 Subject: [PATCH] store all ui controls keybinds in an array --- MLEM.Ui/UiControls.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MLEM.Ui/UiControls.cs b/MLEM.Ui/UiControls.cs index efe923c..9edb9a2 100644 --- a/MLEM.Ui/UiControls.cs +++ b/MLEM.Ui/UiControls.cs @@ -1,5 +1,7 @@ +using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input.Touch; @@ -79,6 +81,11 @@ namespace MLEM.Ui { /// public readonly Keybind RightButtons = new Keybind().Add(Buttons.DPadRight).Add(Buttons.LeftThumbstickRight); /// + /// All instances used by these ui controls. + /// This can be used to easily serialize and deserialize all ui keybinds. + /// + public readonly Keybind[] Keybinds; + /// /// The zero-based index of the used for gamepad input. /// If this index is lower than 0, every connected gamepad will trigger input. /// @@ -120,6 +127,9 @@ namespace MLEM.Ui { this.System = system; this.Input = inputHandler ?? new InputHandler(); this.IsInputOurs = inputHandler == null; + this.Keybinds = typeof(UiControls).GetFields() + .Where(f => f.FieldType == typeof(Keybind)) + .Select(f => (Keybind) f.GetValue(this)).ToArray(); // enable all required gestures InputHandler.EnableGestures(GestureType.Tap, GestureType.Hold);