-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de2f590
commit d87b094
Showing
15 changed files
with
759 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Newtonsoft.Json.Linq; | ||
using SuchByte.MacroDeck.ActionButton; | ||
using SuchByte.MacroDeck.GUI; | ||
using SuchByte.MacroDeck.GUI.CustomControls; | ||
using SuchByte.MacroDeck.Plugins; | ||
using SuchByte.OBSWebSocketPlugin.Controllers; | ||
using SuchByte.OBSWebSocketPlugin.GUI; | ||
using SuchByte.OBSWebSocketPlugin.Language; | ||
using SuchByte.OBSWebSocketPlugin.Models; | ||
using SuchByte.OBSWebSocketPlugin.Models.Action; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace SuchByte.OBSWebSocketPlugin.Actions | ||
{ | ||
public class InteractAction : ActionBase | ||
{ | ||
public override bool CanConfigure => true; | ||
|
||
public override string Name => PluginLanguageManager.PluginStrings.ActionInteract; | ||
|
||
public override string Description => PluginLanguageManager.PluginStrings.ActionInteractDescription; | ||
|
||
public override ConfigBase GetConfig() => GetConfig<InteractConfig>(); | ||
|
||
public override void Trigger(string clientId, ActionButton actionButton) | ||
{ | ||
var config = GetConfig<InteractConfig>(); | ||
Connection conn = PluginInstance.Main.Connections.GetValueOrDefault(config?.ConnectionName ?? PluginInstance.Main.Connections.FirstOrDefault().Key); | ||
conn?.OBS.UiRequests.OpenInputInteractDialogAsync(config.SourceName); | ||
} | ||
|
||
public override ActionConfigControl GetActionConfigControl(ActionConfigurator actionConfigurator) | ||
{ | ||
return new InteractConfigView(this, actionConfigurator); | ||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,165 @@ | ||
using Newtonsoft.Json.Linq; | ||
using SuchByte.MacroDeck.GUI; | ||
using SuchByte.MacroDeck.GUI.CustomControls; | ||
using SuchByte.MacroDeck.Language; | ||
using SuchByte.MacroDeck.Plugins; | ||
using SuchByte.OBSWebSocketPlugin.Controllers; | ||
using SuchByte.OBSWebSocketPlugin.GUI.Interfaces; | ||
using SuchByte.OBSWebSocketPlugin.Language; | ||
using SuchByte.OBSWebSocketPlugin.Models.Action; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace SuchByte.OBSWebSocketPlugin.GUI | ||
{ | ||
public partial class InteractConfigView : ActionConfigControl, IConnDepConfigs | ||
{ | ||
|
||
PluginAction pluginAction; | ||
InteractConfig config; | ||
|
||
public ConnectionSelector ConnectionSelector => connectionSelector1; | ||
|
||
public InteractConfigView(PluginAction pluginAction, ActionConfigurator actionConfigurator) | ||
{ | ||
this.pluginAction = pluginAction; | ||
InitializeComponent(); | ||
|
||
this.lblConnection.Text = PluginLanguageManager.PluginStrings.Connection; | ||
this.lblScene.Text = PluginLanguageManager.PluginStrings.Scene; | ||
this.lblSource.Text = PluginLanguageManager.PluginStrings.Source; | ||
|
||
LoadConfig(); | ||
ResetValues(); | ||
LoadScenes(); | ||
connectionSelector1.ValueChanged += (sender, args) => LoadScenes(); | ||
} | ||
|
||
public override bool OnActionSave() | ||
{ | ||
var config = JObject.FromObject(new InteractConfig | ||
{ | ||
ConnectionName = this.connectionSelector1.Value, | ||
SceneName = this.scenesBox.Text, | ||
SourceName = this.sourcesBox.Text, | ||
}); | ||
|
||
this.pluginAction.Configuration = config.ToString(); | ||
this.pluginAction.ConfigurationSummary = "Interact with " + (String.IsNullOrWhiteSpace(this.sourcesBox.Text) ? this.scenesBox.Text : this.sourcesBox.Text); | ||
return true; | ||
} | ||
|
||
private void LoadScenes() | ||
{ | ||
var conn = (this as IConnDepConfigs).Conn; | ||
if (conn == null) return; | ||
|
||
if (!conn?.IsConnected ?? false) | ||
{ | ||
using var msgBox = new MacroDeck.GUI.CustomControls.MessageBox(); | ||
msgBox.ShowDialog(LanguageManager.Strings.Error, PluginLanguageManager.PluginStrings.ErrorNotConnected, System.Windows.Forms.MessageBoxButtons.OK); | ||
return; | ||
} | ||
|
||
this.scenesBox.Items.Clear(); | ||
this.scenesBox.Text = String.Empty; | ||
|
||
var self = this; | ||
_ = Task.Run(async () => | ||
{ | ||
var response = await conn.OBS.ScenesRequests.GetSceneListAsync(); | ||
foreach (JObject scene in response.Scenes) | ||
{ | ||
var name = scene["sceneName"]?.ToString(); | ||
if (!name.Equals(String.Empty)) | ||
{ | ||
scenesBox.Invoke((MethodInvoker)delegate { scenesBox.Items.Add(name); }); | ||
} | ||
} | ||
self.Invoke((MethodInvoker)delegate | ||
{ | ||
scenesBox.Text = config?.SceneName; | ||
LoadSources(); | ||
}); | ||
}); | ||
|
||
} | ||
|
||
private void LoadSources() | ||
{ | ||
var conn = (this as IConnDepConfigs).Conn; | ||
if (conn == null) return; | ||
|
||
if (!conn?.IsConnected ?? false) | ||
{ | ||
using var msgBox = new MacroDeck.GUI.CustomControls.MessageBox(); | ||
msgBox.ShowDialog(LanguageManager.Strings.Error, PluginLanguageManager.PluginStrings.ErrorNotConnected, System.Windows.Forms.MessageBoxButtons.OK); | ||
return; | ||
} | ||
|
||
this.sourcesBox.Items.Clear(); | ||
this.sourcesBox.Text = String.Empty; | ||
|
||
var self = this; | ||
var sceneName = scenesBox.Text; | ||
_ = Task.Run(async () => | ||
{ | ||
var response = await conn.OBS.SceneItemsRequests.GetSceneItemListAsync(sceneName); | ||
if (response != null) | ||
{ | ||
foreach (JObject item in response.SceneItems) | ||
{ | ||
var name = item["sourceName"]?.ToString(); | ||
if (!String.IsNullOrEmpty(name)) | ||
{ | ||
sourcesBox.Invoke((MethodInvoker)delegate { sourcesBox.Items.Add(name); }); | ||
} | ||
} | ||
} | ||
self.Invoke((MethodInvoker)delegate | ||
{ | ||
sourcesBox.Text = config?.SourceName; | ||
}); | ||
}); | ||
} | ||
|
||
private void LoadConfig() | ||
{ | ||
if (!String.IsNullOrWhiteSpace(this.pluginAction.Configuration)) | ||
{ | ||
try | ||
{ | ||
config = JObject.Parse(this.pluginAction.Configuration).ToObject<InteractConfig>(); | ||
} | ||
catch { } | ||
} | ||
} | ||
|
||
private void ResetValues() | ||
{ | ||
this.connectionSelector1.Value = config?.ConnectionName; | ||
this.scenesBox.Text = config?.SceneName; | ||
this.sourcesBox.Text = config?.SourceName; | ||
} | ||
|
||
|
||
private void BtnReloadScenes_Click(object sender, EventArgs e) | ||
{ | ||
LoadScenes(); | ||
} | ||
|
||
private void BtnReloadSources_Click(object sender, EventArgs e) | ||
{ | ||
LoadSources(); | ||
} | ||
|
||
private void ScenesBox_SelectedIndexChanged(object sender, EventArgs e) | ||
{ | ||
LoadSources(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.