From 0283a75bfdab16f46759ff60dfc36d533b0ce805 Mon Sep 17 00:00:00 2001 From: Marcel Houweling Date: Fri, 9 Dec 2022 14:19:57 +0100 Subject: [PATCH] support streamdeck+ dials --- README.md | 25 +- starcitizen/Buttons/Dial.cs | 334 ++++ starcitizen/Buttons/Macro.cs | 10 +- starcitizen/Buttons/StarCitizenDialBase.cs | 38 + starcitizen/Buttons/StarCitizenKeypadBase.cs | 40 + starcitizen/Buttons/Static.cs | 18 +- ...StarCitizenBase.cs => StreamDeckCommon.cs} | 51 +- starcitizen/Program.cs | 6 + starcitizen/Properties/AssemblyInfo.cs | 4 +- .../PropertyInspector/StarCitizen/Dial.html | 1599 +++++++++++++++++ .../PropertyInspector/StarCitizen/Macro.html | 655 ++++--- .../PropertyInspector/StarCitizen/Static.html | 619 ++++--- starcitizen/SC/DProfileReader.cs | 76 + starcitizen/dialtemplate.html | 69 + starcitizen/manifest.json | 18 +- starcitizen/packages.config | 2 +- starcitizen/starcitizen.csproj | 18 +- 17 files changed, 2881 insertions(+), 701 deletions(-) create mode 100644 starcitizen/Buttons/Dial.cs create mode 100644 starcitizen/Buttons/StarCitizenDialBase.cs create mode 100644 starcitizen/Buttons/StarCitizenKeypadBase.cs rename starcitizen/Buttons/{StarCitizenBase.cs => StreamDeckCommon.cs} (78%) create mode 100644 starcitizen/PropertyInspector/StarCitizen/Dial.html create mode 100644 starcitizen/dialtemplate.html diff --git a/README.md b/README.md index 6e3f7ae..6d3c6a1 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ ![Elgato Stream Deck button plugin for Star Citizen](https://i.imgur.com/FSHsXRG.png) +**At least streamdeck software version 6 is required.** + This plugin gets the key bindings from the Star Citizen game files. The bindings in the streamdeck plugin are automatically updated when changing bindings in Star Citizen options screen. @@ -38,7 +40,26 @@ You can then set up different images for each toggle state. The disadvantage is: that if you would press e.g. the gear up/down toggle button while the ship is still on the ground/powered off, then the button image would be out of sync. -After you install the plugin in the streamdeck software, then there will be a new button type in the streamdeck software. +The plugin also has a Dial button for use with the 4 dials on the Streamdeck+ model. + +There are 5 bindings (They must be keyboard bindings, you can't bind the mouse wheel!) : + +- Dial Clockwise +- Dial Counter-Clockwise +- Dial Press +- Touch screen press +- Touch screen long press + +When a dial is rotated, the 'key down' event is sent to the keyboard once. +When you let go of the dial for at least 100ms : the 'key up' event is sent to the keyboard. + +When a dial button is pushed, the 'key down' event is sent to the keyboard. +When a dial button is released, the 'key up' event is sent to the keyboard. + +When the touch screen is pressed or long-pressed, the behaviour is like the multi-action button : +The 'key down' event is sent to the keyboard. After a user-definable delay (default = 40 ms) the 'key up' event is sent to the keyboard. + +After you install the plugin in the streamdeck software, then there will be new button types in the streamdeck software. Choose a button in the streamdeck software (drag and drop), then choose a Star Citizen function for that button (that must have a keyboard binding in Star Citizen. **A mouse, gamepad or joystick binding won't work!**) @@ -48,7 +69,7 @@ Add an image to a button in this way: ![Button Image](https://i.imgur.com/xkgy7uZ.png) -Animated gif files are supported. +Animated gif files are supported. Dial images can be wider. When the plugin is first started, it finds and opens the game file : diff --git a/starcitizen/Buttons/Dial.cs b/starcitizen/Buttons/Dial.cs new file mode 100644 index 0000000..ad3f13d --- /dev/null +++ b/starcitizen/Buttons/Dial.cs @@ -0,0 +1,334 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using System.Windows.Input; +using WindowsInput.Native; +using BarRaider.SdTools; +using BarRaider.SdTools.Payloads; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System.Threading; +using System.Diagnostics; + +// ReSharper disable StringLiteralTypo + +namespace starcitizen.Buttons +{ + + [PluginActionId("com.mhwlng.starcitizen.dial")] + public class Dial : StarCitizenDialBase + { + protected class PluginSettings + { + public static PluginSettings CreateDefaultSettings() + { + var instance = new PluginSettings + { + FunctionCw = string.Empty, + FunctionCcw = string.Empty, + FunctionPress = string.Empty, + FunctionTouchLongPress = string.Empty, + FunctionTouchPress = string.Empty + }; + + return instance; + } + + [JsonProperty(PropertyName = "functioncw")] + public string FunctionCw { get; set; } + + [JsonProperty(PropertyName = "functionccw")] + public string FunctionCcw { get; set; } + + [JsonProperty(PropertyName = "delay")] + public string Delay { get; set; } + + [JsonProperty(PropertyName = "functionpress")] + public string FunctionPress { get; set; } + + [JsonProperty(PropertyName = "functiontouchpress")] + public string FunctionTouchPress { get; set; } + + [JsonProperty(PropertyName = "functiontouchlongpress")] + public string FunctionTouchLongPress { get; set; } + } + + PluginSettings settings; + private int? _delay = null; + + private bool ccwIsDown; + private bool cwIsDown; + + private int ccwPending; + private int cwPending; + + private DateTime? lastDialTime = null; + + private Thread dialWatcherThread = null; + /// + /// Token to signal that we are no longer watching + /// + private CancellationTokenSource cancellationTokenSource; + + + public Dial(SDConnection connection, InitialPayload payload) : base(connection, payload) + { + if (payload.Settings == null || payload.Settings.Count == 0) + { + //Logger.Instance.LogMessage(TracingLevel.DEBUG, "Repeating Static Constructor #1"); + + settings = PluginSettings.CreateDefaultSettings(); + Connection.SetSettingsAsync(JObject.FromObject(settings)).Wait(); + + } + else + { + //Logger.Instance.LogMessage(TracingLevel.DEBUG, "Repeating Static Constructor #2"); + + settings = payload.Settings.ToObject(); + HandleFileNames(); + } + + cancellationTokenSource = new CancellationTokenSource(); + + dialWatcherThread = new Thread(state => + { + while (true) + { + if (Program.dpReader == null || cancellationTokenSource.IsCancellationRequested) + { + StreamDeckCommon.ForceStop = true; + + return; + } + + var timeDiff = DateTime.Now - (lastDialTime ?? DateTime.Now); + + if ((ccwIsDown || cwIsDown) && timeDiff.TotalMilliseconds >= 100) + { + //Logger.Instance.LogMessage(TracingLevel.INFO, $"DialRotate Released"); + + ReleaseCcw(); + + ReleaseCw(); + + lastDialTime = DateTime.Now; + + } + + Thread.Sleep(100); + + } + + }) + { + Name = "Dial Watcher", + IsBackground = true + }; + dialWatcherThread.Start(); + + } + + public override void Dispose() + { + if (cancellationTokenSource != null) + cancellationTokenSource.Cancel(); + + if (dialWatcherThread != null) + dialWatcherThread.Join(); + + base.Dispose(); + + //Logger.Instance.LogMessage(TracingLevel.DEBUG, "Destructor called #1"); + + } + + public override void TouchPress(TouchpadPressPayload payload) + { + if (Program.dpReader == null) + { + StreamDeckCommon.ForceStop = true; + return; + } + + StreamDeckCommon.ForceStop = false; + + if (payload.IsLongPress) + { + //Logger.Instance.LogMessage(TracingLevel.INFO, $"TouchPress: LongPress"); + + var action = Program.dpReader.GetBinding(settings.FunctionTouchLongPress); + if (action != null) + { + Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); + + StreamDeckCommon.SendKeypress(CommandTools.ConvertKeyString(action.Keyboard), _delay ?? 40); + } + } + else + { + //Logger.Instance.LogMessage(TracingLevel.INFO, $"TouchPress: Press"); + + var action = Program.dpReader.GetBinding(settings.FunctionTouchPress); + if (action != null) + { + Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); + + StreamDeckCommon.SendKeypress(CommandTools.ConvertKeyString(action.Keyboard), _delay ?? 40); + } + } + } + + public override void DialPress(DialPressPayload payload) + { + + if (Program.dpReader == null) + { + StreamDeckCommon.ForceStop = true; + return; + } + + StreamDeckCommon.ForceStop = false; + + if (payload.IsDialPressed) + { + //Logger.Instance.LogMessage(TracingLevel.INFO, $"DialPress: Press"); + var action = Program.dpReader.GetBinding(settings.FunctionPress); + if (action != null) + { + Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); + + StreamDeckCommon.SendKeypressDown(CommandTools.ConvertKeyString(action.Keyboard)); + } + } + else + { + //Logger.Instance.LogMessage(TracingLevel.INFO, $"DialPress: Release"); + var action = Program.dpReader.GetBinding(settings.FunctionPress); + if (action != null) + { + Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); + + StreamDeckCommon.SendKeypressUp(CommandTools.ConvertKeyString(action.Keyboard)); + } + } + } + + private void ReleaseCw() + { + if (cwIsDown) + { + var action = Program.dpReader.GetBinding(settings.FunctionCw); + if (action != null) + { + Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); + + StreamDeckCommon.SendKeypressUp(CommandTools.ConvertKeyString(action.Keyboard)); + Thread.Sleep(100); + cwIsDown = false; + cwPending = 0; + } + } + } + + private void ReleaseCcw() + { + if (ccwIsDown) + { + var action = Program.dpReader.GetBinding(settings.FunctionCcw); + if (action != null) + { + Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); + + StreamDeckCommon.SendKeypressUp(CommandTools.ConvertKeyString(action.Keyboard)); + Thread.Sleep(100); + ccwIsDown = false; + ccwPending = 0; + } + } + } + public override void DialRotate(DialRotatePayload payload) + { + + if (Program.dpReader == null) + { + StreamDeckCommon.ForceStop = true; + return; + } + + StreamDeckCommon.ForceStop = false; + + lastDialTime = DateTime.Now; + + if (payload.Ticks > 0) + { + ReleaseCcw(); + + //Logger.Instance.LogMessage(TracingLevel.INFO, $"DialRotate CW: {payload.Ticks}"); + + if (!cwIsDown) + { + var action = Program.dpReader.GetBinding(settings.FunctionCw); + if (action != null) + { + Logger.Instance.LogMessage(TracingLevel.INFO, + CommandTools.ConvertKeyString(action.Keyboard)); + + StreamDeckCommon.SendKeypressDown(CommandTools.ConvertKeyString(action.Keyboard)); + cwIsDown = true; + cwPending += payload.Ticks; + } + } + } + else if (payload.Ticks < 0) + { + ReleaseCw(); + + //Logger.Instance.LogMessage(TracingLevel.INFO, $"DialRotate CCW: {payload.Ticks}"); + + if (!ccwIsDown) + { + var action = Program.dpReader.GetBinding(settings.FunctionCcw); + if (action != null) + { + + Logger.Instance.LogMessage(TracingLevel.INFO, + CommandTools.ConvertKeyString(action.Keyboard)); + + StreamDeckCommon.SendKeypressDown(CommandTools.ConvertKeyString(action.Keyboard)); + ccwIsDown = true; + ccwPending += -payload.Ticks; + } + } + } + + } + + + + public override void ReceivedSettings(ReceivedSettingsPayload payload) + { + //Logger.Instance.LogMessage(TracingLevel.DEBUG, "ReceivedSettings"); + + // New in StreamDeck-Tools v2.0: + BarRaider.SdTools.Tools.AutoPopulateSettings(settings, payload.Settings); + HandleFileNames(); + } + + private void HandleFileNames() + { + _delay = null; + + if (!string.IsNullOrEmpty(settings.Delay)) + { + var ok = int.TryParse(settings.Delay, out var delay); + if (ok && (delay > 0)) + { + _delay = delay; + } + } + + Connection.SetSettingsAsync(JObject.FromObject(settings)).Wait(); + } + } +} diff --git a/starcitizen/Buttons/Macro.cs b/starcitizen/Buttons/Macro.cs index 959271a..ac102f3 100644 --- a/starcitizen/Buttons/Macro.cs +++ b/starcitizen/Buttons/Macro.cs @@ -13,7 +13,7 @@ namespace starcitizen.Buttons { [PluginActionId("com.mhwlng.starcitizen.macro")] - public class Macro : StarCitizenBase + public class Macro : StarCitizenKeypadBase { protected class PluginSettings { @@ -69,20 +69,20 @@ public Macro(SDConnection connection, InitialPayload payload) : base(connection, public override void KeyPressed(KeyPayload payload) { - if (InputRunning || Program.dpReader == null) + if (Program.dpReader == null) { - ForceStop = true; + StreamDeckCommon.ForceStop = true; return; } - ForceStop = false; + StreamDeckCommon.ForceStop = false; var action = Program.dpReader.GetBinding(settings.Function); if (action != null) { Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); - SendKeypress(CommandTools.ConvertKeyString(action.Keyboard), _delay ?? 40); + StreamDeckCommon.SendKeypress(CommandTools.ConvertKeyString(action.Keyboard), _delay ?? 40); } if (_clickSound != null) diff --git a/starcitizen/Buttons/StarCitizenDialBase.cs b/starcitizen/Buttons/StarCitizenDialBase.cs new file mode 100644 index 0000000..22c791b --- /dev/null +++ b/starcitizen/Buttons/StarCitizenDialBase.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using WindowsInput; +using WindowsInput.Native; +using BarRaider.SdTools; + +namespace starcitizen.Buttons +{ + public abstract class StarCitizenDialBase : EncoderBase + { + protected StarCitizenDialBase(SDConnection connection, InitialPayload payload) : base(connection, payload) + { + //Logger.Instance.LogMessage(TracingLevel.INFO, "aa"); + } + + public override void Dispose() + { + //Logger.Instance.LogMessage(TracingLevel.INFO, "bb"); + } + + + public override void OnTick() + { + //Logger.Instance.LogMessage(TracingLevel.INFO, "dd"); + + //var deviceInfo = Connection.DeviceInfo(); + + } + + public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload) { } + + + } +} diff --git a/starcitizen/Buttons/StarCitizenKeypadBase.cs b/starcitizen/Buttons/StarCitizenKeypadBase.cs new file mode 100644 index 0000000..fe6e6df --- /dev/null +++ b/starcitizen/Buttons/StarCitizenKeypadBase.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using WindowsInput; +using WindowsInput.Native; +using BarRaider.SdTools; + +namespace starcitizen.Buttons +{ + public abstract class StarCitizenKeypadBase : KeypadBase + { + protected StarCitizenKeypadBase(SDConnection connection, InitialPayload payload) : base(connection, payload) + { + //Logger.Instance.LogMessage(TracingLevel.INFO, "aa"); + } + + public override void Dispose() + { + //Logger.Instance.LogMessage(TracingLevel.INFO, "bb"); + } + + public override void KeyReleased(KeyPayload payload) { } + + + public override void OnTick() + { + //Logger.Instance.LogMessage(TracingLevel.INFO, "dd"); + + //var deviceInfo = Connection.DeviceInfo(); + + } + + public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload) { } + + + } +} diff --git a/starcitizen/Buttons/Static.cs b/starcitizen/Buttons/Static.cs index ef6a241..1d57002 100644 --- a/starcitizen/Buttons/Static.cs +++ b/starcitizen/Buttons/Static.cs @@ -13,7 +13,7 @@ namespace starcitizen.Buttons { [PluginActionId("com.mhwlng.starcitizen.static")] - public class Static : StarCitizenBase + public class Static : StarCitizenKeypadBase { protected class PluginSettings { @@ -64,20 +64,20 @@ public Static(SDConnection connection, InitialPayload payload) : base(connection public override void KeyPressed(KeyPayload payload) { - if (InputRunning || Program.dpReader == null) + if (Program.dpReader == null) { - ForceStop = true; + StreamDeckCommon.ForceStop = true; return; } - ForceStop = false; + StreamDeckCommon.ForceStop = false; var action = Program.dpReader.GetBinding(settings.Function); if (action != null) { Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); - SendKeypressDown(CommandTools.ConvertKeyString(action.Keyboard)); + StreamDeckCommon.SendKeypressDown(CommandTools.ConvertKeyString(action.Keyboard)); } if (_clickSound != null) @@ -98,20 +98,20 @@ public override void KeyPressed(KeyPayload payload) public override void KeyReleased(KeyPayload payload) { - if (InputRunning || Program.dpReader == null) + if (Program.dpReader == null) { - ForceStop = true; + StreamDeckCommon.ForceStop = true; return; } - ForceStop = false; + StreamDeckCommon.ForceStop = false; var action = Program.dpReader.GetBinding(settings.Function); if (action != null) { Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); - SendKeypressUp(CommandTools.ConvertKeyString(action.Keyboard)); + StreamDeckCommon.SendKeypressUp(CommandTools.ConvertKeyString(action.Keyboard)); } } diff --git a/starcitizen/Buttons/StarCitizenBase.cs b/starcitizen/Buttons/StreamDeckCommon.cs similarity index 78% rename from starcitizen/Buttons/StarCitizenBase.cs rename to starcitizen/Buttons/StreamDeckCommon.cs index b4d6b37..b2c02f9 100644 --- a/starcitizen/Buttons/StarCitizenBase.cs +++ b/starcitizen/Buttons/StreamDeckCommon.cs @@ -10,7 +10,7 @@ namespace starcitizen.Buttons { - public abstract class StarCitizenBase : PluginBase + static class StreamDeckCommon { [DllImport("user32.dll")] private static extern uint MapVirtualKeyEx(uint uCode, uint uMapType, IntPtr dwhkl); @@ -25,33 +25,9 @@ public abstract class StarCitizenBase : PluginBase private static extern IntPtr GetKeyboardLayout(int WindowsThreadProcessID); private static Dictionary _lastStatus = new Dictionary(); - - protected bool InputRunning; - protected bool ForceStop = false; - protected StarCitizenBase(SDConnection connection, InitialPayload payload) : base(connection, payload) - { - //Logger.Instance.LogMessage(TracingLevel.INFO, "aa"); - } - - public override void Dispose() - { - //Logger.Instance.LogMessage(TracingLevel.INFO, "bb"); - } - - public override void KeyReleased(KeyPayload payload) { } - - - public override void OnTick() - { - //Logger.Instance.LogMessage(TracingLevel.INFO, "dd"); - - //var deviceInfo = Connection.DeviceInfo(); - - } - - public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload) { } - - private void SendInput(string inputText, int delay) + + public static bool ForceStop = false; + private static void SendInput(string inputText, int delay) { var text = inputText; @@ -64,7 +40,7 @@ private void SendInput(string inputText, int delay) HandleMacro(macro, delay); } } - private void SendInputDown(string inputText) + private static void SendInputDown(string inputText) { var text = inputText; @@ -78,7 +54,7 @@ private void SendInputDown(string inputText) } } - private void SendInputUp(string inputText) + private static void SendInputUp(string inputText) { var text = inputText; @@ -92,7 +68,7 @@ private void SendInputUp(string inputText) } } - public static void HandleMacro(string macro, int delay) + private static void HandleMacro(string macro, int delay) { var keyStrokes = CommandTools.ExtractKeyStrokes(macro); @@ -119,7 +95,7 @@ public static void HandleMacro(string macro, int delay) } } - private void HandleMacroDown(string macro) + private static void HandleMacroDown(string macro) { var keyStrokes = CommandTools.ExtractKeyStrokes(macro); @@ -143,7 +119,7 @@ private void HandleMacroDown(string macro) } - private void HandleMacroUp(string macro) + private static void HandleMacroUp(string macro) { var keyStrokes = CommandTools.ExtractKeyStrokes(macro); @@ -166,15 +142,18 @@ private void HandleMacroUp(string macro) } } - protected void SendKeypress(string keyInfo, int delay) + public static void SendKeypress(string keyInfo, int delay) { if (!string.IsNullOrEmpty(keyInfo)) { SendInput("{" + keyInfo + "}", delay); + + //Thread.Sleep(delay); + } } - protected void SendKeypressDown(string keyInfo) + public static void SendKeypressDown(string keyInfo) { if (!string.IsNullOrEmpty(keyInfo)) { @@ -183,7 +162,7 @@ protected void SendKeypressDown(string keyInfo) } - protected void SendKeypressUp(string keyInfo) + public static void SendKeypressUp(string keyInfo) { if (!string.IsNullOrEmpty(keyInfo)) { diff --git a/starcitizen/Program.cs b/starcitizen/Program.cs index 6b4b76d..fb3e2f9 100644 --- a/starcitizen/Program.cs +++ b/starcitizen/Program.cs @@ -86,6 +86,8 @@ class Program public static string statictemplate; + public static string dialtemplate; + public static string macrotemplate; public static void HandleKeyBindingEvents(object sender, object evt) @@ -118,6 +120,8 @@ private static void GetKeyBindings(Object threadContext) dpReader.CreateStaticHtml(statictemplate); + dpReader.CreateDialHtml(dialtemplate); + dpReader.CreateMacroHtml(macrotemplate); dpReader.CreateCsv(); @@ -139,6 +143,8 @@ static void Main(string[] args) statictemplate = File.ReadAllText("statictemplate.html"); + dialtemplate = File.ReadAllText("dialtemplate.html"); + macrotemplate = File.ReadAllText("macrotemplate.html"); profile = SCDefaultProfile.DefaultProfile(); diff --git a/starcitizen/Properties/AssemblyInfo.cs b/starcitizen/Properties/AssemblyInfo.cs index fc2370b..1a66493 100644 --- a/starcitizen/Properties/AssemblyInfo.cs +++ b/starcitizen/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.9.0")] -[assembly: AssemblyFileVersion("1.0.9.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] diff --git a/starcitizen/PropertyInspector/StarCitizen/Dial.html b/starcitizen/PropertyInspector/StarCitizen/Dial.html new file mode 100644 index 0000000..65890d6 --- /dev/null +++ b/starcitizen/PropertyInspector/StarCitizen/Dial.html @@ -0,0 +1,1599 @@ + + + + + + + + Mhwlng's Star Citizen + + + + + + + +
+ +
+
Dial CW
+ +
+ +
+
Dial CCW
+ +
+ +
+
Dial Press
+ +
+ +
+
Touch Press
+ +
+ +
+
Touch Longpress
+ +
+ +
+
Touch Delay (ms)
+ +
+
+ + diff --git a/starcitizen/PropertyInspector/StarCitizen/Macro.html b/starcitizen/PropertyInspector/StarCitizen/Macro.html index 59a3527..756017f 100644 --- a/starcitizen/PropertyInspector/StarCitizen/Macro.html +++ b/starcitizen/PropertyInspector/StarCitizen/Macro.html @@ -1,4 +1,4 @@ - + @@ -13,340 +13,337 @@ -
+
-
-
Function
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - -
-
-
Sound
-
- - - -
-
+ +
+ +
+
Sound
+
+ + + +
+
-
-
Delay (ms)
- +
+
Delay (ms)
+
-
+
diff --git a/starcitizen/PropertyInspector/StarCitizen/Static.html b/starcitizen/PropertyInspector/StarCitizen/Static.html index 4eb1e48..c514563 100644 --- a/starcitizen/PropertyInspector/StarCitizen/Static.html +++ b/starcitizen/PropertyInspector/StarCitizen/Static.html @@ -1,4 +1,4 @@ - + @@ -19,316 +19,313 @@
Function
diff --git a/starcitizen/SC/DProfileReader.cs b/starcitizen/SC/DProfileReader.cs index 696a118..58d2300 100644 --- a/starcitizen/SC/DProfileReader.cs +++ b/starcitizen/SC/DProfileReader.cs @@ -429,6 +429,11 @@ public void fromXML(string xml) public Action GetBinding(string key) { + if (string.IsNullOrEmpty(key)) + { + return null; + } + if (actions.ContainsKey(key)) { return actions[key]; @@ -661,6 +666,77 @@ public void CreateStaticHtml(string statictemplate) } + public void CreateDialHtml(string dialtemplate) + { + try + { + var keyboard = KeyboardLayouts.GetThreadKeyboardLayout(); + + CultureInfo culture; + + try + { + culture = new CultureInfo(keyboard.KeyboardId); + } + catch + { + culture = new CultureInfo("en-US"); + } + + Logger.Instance.LogMessage(TracingLevel.INFO, $"Keyboard Detected, language : {keyboard.LanguageId:X} keyboard : {keyboard.KeyboardId:X} culture : {culture.Name}"); + + var dropdownHtml = new StringBuilder(); + + var mapsList = + actions + .Where(x => !string.IsNullOrWhiteSpace(x.Value.Keyboard)) + .OrderBy(x => x.Value.MapUILabel) + .GroupBy(x => x.Value.MapUILabel) + .Select(x => x.Key); + + + foreach (var map in mapsList) + { + var options = actions + .Where(x => x.Value.MapUILabel == map && !string.IsNullOrWhiteSpace(x.Value.Keyboard)) + .OrderBy(x => x.Value.MapUICategory) + .ThenBy(x => x.Value.MapUILabel) + .ThenBy(x => x.Value.UILabel); + + if (options.Any()) + { + var htmlline = $""; + + dropdownHtml.AppendLine(htmlline); + + foreach (var action in options) + { + var keyString = CommandTools.ConvertKeyStringToLocale(action.Value.Keyboard, culture.Name); + + var key = keyString.Replace("Dik", "").Replace("}{", "+").Replace("}", "").Replace("{", ""); + + htmlline = $" "; + + dropdownHtml.AppendLine(htmlline); + } + + htmlline = $""; + + dropdownHtml.AppendLine(htmlline); + } + + } + + File.WriteAllText(Path.Combine(@"PropertyInspector\StarCitizen", "Dial.html"), + dialtemplate.Replace("[DROPDOWN]", dropdownHtml.ToString())); + } + catch (Exception ex) + { + Logger.Instance.LogMessage(TracingLevel.ERROR, $"CreateDialHtml {ex}"); + } + + } + public void CreateMacroHtml(string macrotemplate) { try diff --git a/starcitizen/dialtemplate.html b/starcitizen/dialtemplate.html new file mode 100644 index 0000000..5dafb44 --- /dev/null +++ b/starcitizen/dialtemplate.html @@ -0,0 +1,69 @@ + + + + + + + + Mhwlng's Star Citizen + + + + + + + +
+ +
+
Dial CW
+ +
+ +
+
Dial CCW
+ +
+ +
+
Dial Press
+ +
+ +
+
Touch Press
+ +
+ +
+
Touch Longpress
+ +
+ +
+
Touch Delay (ms)
+ +
+
+ + diff --git a/starcitizen/manifest.json b/starcitizen/manifest.json index ee31160..7bd9275 100644 --- a/starcitizen/manifest.json +++ b/starcitizen/manifest.json @@ -29,6 +29,20 @@ "Tooltip": "Star Citizen Multi-Action Button", "UUID": "com.mhwlng.starcitizen.macro", "PropertyInspectorPath": "PropertyInspector/StarCitizen/Macro.html" + }, + { + "Icon": "Images/pluginIcon", + "Name": "Dial Button", + "Controllers": [ "Encoder" ], + "States": [ + { + "Image": "Images/pluginIcon" + } + ], + "SupportedInMultiActions": false, + "Tooltip": "Star Citizen Dial Button", + "UUID": "com.mhwlng.starcitizen.dial", + "PropertyInspectorPath": "PropertyInspector/StarCitizen/Dial.html" } ], "Author": "mhwlng", @@ -36,7 +50,7 @@ "Name": "Star Citizen", "Icon": "Images/pluginIcon", "URL": "https://github.com/mhwlng/streamdeck-starcitizen", - "Version": "1.0.9", + "Version": "1.1.0", "CodePath": "com.mhwlng.starcitizen", "Category": "Star Citizen", "CategoryIcon": "Images/categoryIcon", @@ -48,7 +62,7 @@ ], "SDKVersion": 2, "Software": { - "MinimumVersion": "4.6.1" + "MinimumVersion": "6.0" }, "Profiles": [ diff --git a/starcitizen/packages.config b/starcitizen/packages.config index 39892d5..ec86c4f 100644 --- a/starcitizen/packages.config +++ b/starcitizen/packages.config @@ -14,7 +14,7 @@ - + diff --git a/starcitizen/starcitizen.csproj b/starcitizen/starcitizen.csproj index 663d7f7..5e5fb4c 100644 --- a/starcitizen/starcitizen.csproj +++ b/starcitizen/starcitizen.csproj @@ -42,7 +42,7 @@ 4 - AnyCPU + x64 none true bin\Release\com.mhwlng.starcitizen.sdPlugin\ @@ -54,6 +54,7 @@ *.pdb; *.xml + false OnOutputUpdated @@ -95,8 +96,8 @@ ..\packages\streamdeck-client-csharp.4.3.0\lib\netstandard2.0\streamdeck-client-csharp.dll - - ..\packages\StreamDeck-Tools.3.2.0\lib\net472\StreamDeckTools.dll + + ..\packages\StreamDeck-Tools.5.9.0-Beta1\lib\netstandard2.0\StreamDeckTools.dll @@ -158,7 +159,10 @@ - + + + + @@ -267,6 +271,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -291,6 +298,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest