-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add multi-action button (see readme.md)
- Loading branch information
Showing
15 changed files
with
751 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
using WindowsInput.Native; | ||
using BarRaider.SdTools; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
// ReSharper disable StringLiteralTypo | ||
|
||
namespace starcitizen.Buttons | ||
{ | ||
|
||
[PluginActionId("com.mhwlng.starcitizen.macro")] | ||
public class Macro : StarCitizenBase | ||
{ | ||
protected class PluginSettings | ||
{ | ||
public static PluginSettings CreateDefaultSettings() | ||
{ | ||
var instance = new PluginSettings | ||
{ | ||
Function = string.Empty, | ||
}; | ||
|
||
return instance; | ||
} | ||
|
||
[JsonProperty(PropertyName = "function")] | ||
public string Function { get; set; } | ||
|
||
[FilenameProperty] | ||
[JsonProperty(PropertyName = "clickSound")] | ||
public string ClickSoundFilename { get; set; } | ||
|
||
[JsonProperty(PropertyName = "delay")] | ||
public string Delay { get; set; } | ||
|
||
} | ||
|
||
|
||
PluginSettings settings; | ||
private CachedSound _clickSound = null; | ||
|
||
private int? _delay = null; | ||
|
||
|
||
public Macro(SDConnection connection, InitialPayload payload) : base(connection, payload) | ||
{ | ||
if (payload.Settings == null || payload.Settings.Count == 0) | ||
{ | ||
//Logger.Instance.LogMessage(TracingLevel.DEBUG, "Repeating Macro Constructor #1"); | ||
|
||
settings = PluginSettings.CreateDefaultSettings(); | ||
Connection.SetSettingsAsync(JObject.FromObject(settings)).Wait(); | ||
|
||
} | ||
else | ||
{ | ||
//Logger.Instance.LogMessage(TracingLevel.DEBUG, "Repeating Macro Constructor #2"); | ||
|
||
settings = payload.Settings.ToObject<PluginSettings>(); | ||
HandleFileNames(); | ||
} | ||
|
||
} | ||
|
||
|
||
public override void KeyPressed(KeyPayload payload) | ||
{ | ||
if (InputRunning || Program.dpReader == null) | ||
{ | ||
ForceStop = true; | ||
return; | ||
} | ||
|
||
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); | ||
} | ||
|
||
if (_clickSound != null) | ||
{ | ||
try | ||
{ | ||
AudioPlaybackEngine.Instance.PlaySound(_clickSound); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.Instance.LogMessage(TracingLevel.FATAL, $"PlaySound: {ex}"); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
public override void KeyReleased(KeyPayload payload) | ||
{ | ||
|
||
|
||
} | ||
|
||
public override void Dispose() | ||
{ | ||
base.Dispose(); | ||
|
||
//Logger.Instance.LogMessage(TracingLevel.DEBUG, "Destructor called #1"); | ||
} | ||
|
||
|
||
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; | ||
} | ||
} | ||
|
||
_clickSound = null; | ||
|
||
if (File.Exists(settings.ClickSoundFilename)) | ||
{ | ||
try | ||
{ | ||
_clickSound = new CachedSound(settings.ClickSoundFilename); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.Instance.LogMessage(TracingLevel.FATAL, $"CachedSound: {settings.ClickSoundFilename} {ex}"); | ||
|
||
_clickSound = null; | ||
settings.ClickSoundFilename = null; | ||
} | ||
} | ||
|
||
Connection.SetSettingsAsync(JObject.FromObject(settings)).Wait(); | ||
} | ||
} | ||
} |
Oops, something went wrong.