Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
QOL-Improvements & Bugfixes
Browse files Browse the repository at this point in the history
- Translation works again
- Drag and Drop of Scene Slots
- Slots are saved when switching scene collections
- KNX & PelcoD disabled, because broken
  • Loading branch information
CShark committed Sep 20, 2021
1 parent 8786c8f commit 0cecdf5
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 17 deletions.
13 changes: 10 additions & 3 deletions BetterMultiview/ObsMultiview/Controls/SceneSlot.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@
Background="#01FFFFFF"
MouseRightButtonUp="SceneSlot_OnMouseRightButtonUp"
MouseLeftButtonDown="SceneSlot_OnMouseLeftButtonDown"
Drop="SceneSlot_OnDrop"
DragOver="SceneSlot_OnDragOver"
MouseDoubleClick="SceneSlot_OnMouseDoubleClick"
AllowDrop="True"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVis" />
<converters:StringToVis x:Key="StringToVis" />
</UserControl.Resources>
<Grid DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}">

<Rectangle Fill="#254682B4" Visibility="{Binding Unconfigured, Converter={StaticResource BoolToVis}}" />
<Rectangle Stroke="ForestGreen" StrokeThickness="7" Margin="-1"
<Rectangle Stroke="DarkGray" StrokeThickness="6" Margin="-6" />
<Rectangle Stroke="ForestGreen" StrokeThickness="7" Margin="-3"
Visibility="{Binding ActivePreview, Converter={StaticResource BoolToVis}}" />
<Rectangle StrokeThickness="7" Margin="-1" Stroke="OrangeRed"
<Rectangle StrokeThickness="7" Margin="-3" Stroke="OrangeRed"
Visibility="{Binding ActiveLive, Converter={StaticResource BoolToVis}}" />
<Rectangle StrokeThickness="7" Margin="-3" Stroke="Gold"
Visibility="{Binding SlotConfiguring, Converter={StaticResource BoolToVis}}" />

<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" Margin="20" Foreground="White"
Background="#83000000" VerticalAlignment="Top" Padding="5" FontSize="20"
Visibility="{Binding Name, Converter={StaticResource StringToVis}}" />

<Rectangle Stroke="DarkGray" StrokeThickness="6" Margin="-6" />

</Grid>
</UserControl>
49 changes: 47 additions & 2 deletions BetterMultiview/ObsMultiview/Controls/SceneSlot.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Printing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -12,10 +13,11 @@ namespace ObsMultiview.Controls {
/// Control for a single slot in the stream view
/// </summary>
public partial class SceneSlot : UserControl {
private readonly UserProfile.DSlot _slot;
private UserProfile.DSlot _slot;
private readonly SceneService _scenes;
private readonly StreamView _owner;
private readonly PluginService _plugins;
private readonly ProfileWatcher _profile;

public static readonly DependencyProperty UnconfiguredProperty = DependencyProperty.Register(
nameof(Unconfigured), typeof(bool), typeof(SceneSlot), new PropertyMetadata(true));
Expand Down Expand Up @@ -49,11 +51,20 @@ public partial class SceneSlot : UserControl {
set { SetValue(NameProperty, value); }
}

public static readonly DependencyProperty SlotConfiguringProperty = DependencyProperty.Register(
nameof(SlotConfiguring), typeof(bool), typeof(SceneSlot), new PropertyMetadata(default(bool)));

public bool SlotConfiguring {
get { return (bool) GetValue(SlotConfiguringProperty); }
set { SetValue(SlotConfiguringProperty, value); }
}

public SceneSlot(UserProfile.DSlot slot, StreamView owner) {
_slot = slot;
_owner = owner;
_scenes = App.Container.Resolve<SceneService>();
_plugins = App.Container.Resolve<PluginService>();
_profile = App.Container.Resolve<ProfileWatcher>();
LoadSlot();

InitializeComponent();
Expand Down Expand Up @@ -102,17 +113,24 @@ public partial class SceneSlot : UserControl {

_plugins.PausePlugins(null, true);

SlotConfiguring = true;
if (config.ShowDialog() == true) {
LoadSlot();
_owner.PrepareObsMultiview();
}

SlotConfiguring = false;
_plugins.PausePlugins(null, false);
}

private void SceneSlot_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
if (!Unconfigured)
if (!Unconfigured) {
_scenes.ActivatePreview(_slot.Id);

var data = new DataObject();
data.SetData(typeof(SceneSlot), this);
DragDrop.DoDragDrop(this, data, DragDropEffects.Move);
}
}

private void SceneSlot_OnMouseDoubleClick(object sender, MouseButtonEventArgs e) {
Expand All @@ -121,5 +139,32 @@ public partial class SceneSlot : UserControl {
e.Handled = true;
}
}

private void SceneSlot_OnDrop(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(typeof(SceneSlot))) {
var data = e.Data.GetData(typeof(SceneSlot));

if (data is SceneSlot slot && slot != this) {
var localSlot = _slot;
var remSlot = slot._slot;

_profile.SwapSlots(localSlot.Id, remSlot.Id);
}
}
}

private void SceneSlot_OnDragOver(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(typeof(SceneSlot))) {
var data = e.Data.GetData(typeof(SceneSlot));

if (data == this) {
e.Effects = DragDropEffects.None;
e.Handled = true;
}
} else {
e.Effects = DragDropEffects.None;
e.Handled = false;
}
}
}
}
2 changes: 1 addition & 1 deletion BetterMultiview/ObsMultiview/Dialogs/PluginConfig.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ResizeMode="NoResize"
SizeToContent="WidthAndHeight"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="StreamDeck"
lex:ResxLocalizationProvider.DefaultAssembly="ObsMultiview"
lex:ResxLocalizationProvider.DefaultDictionary="Dialogs"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Title="{lex:Loc PluginConfig}" Height="450" Width="800">
Expand Down
2 changes: 1 addition & 1 deletion BetterMultiview/ObsMultiview/Dialogs/ProfileConfig.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
WindowStartupLocation="CenterOwner"
ResizeMode="NoResize"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="StreamDeck"
lex:ResxLocalizationProvider.DefaultAssembly="ObsMultiview"
lex:ResxLocalizationProvider.DefaultDictionary="Dialogs"
DataContext="{Binding RelativeSource={RelativeSource Self}, Path=Config}"
Title="{lex:Loc ProfileConfig}" Height="185" Width="307">
Expand Down
2 changes: 1 addition & 1 deletion BetterMultiview/ObsMultiview/Dialogs/SlotConfig.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
MinWidth="345"
WindowStartupLocation="CenterOwner"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="StreamDeck"
lex:ResxLocalizationProvider.DefaultAssembly="ObsMultiview"
lex:ResxLocalizationProvider.DefaultDictionary="Dialogs"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Title="{lex:Loc SlotConfig}" Height="450" Width="345">
Expand Down
2 changes: 1 addition & 1 deletion BetterMultiview/ObsMultiview/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
xmlns:services="clr-namespace:ObsMultiview.Services"
mc:Ignorable="d"
loc:LocalizeDictionary.DesignCulture="en"
loc:ResxLocalizationProvider.DefaultAssembly="StreamDeck"
loc:ResxLocalizationProvider.DefaultAssembly="ObsMultiview"
loc:ResxLocalizationProvider.DefaultDictionary="MainWindow"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Title="Stream Deck" Height="450" Width="800">
Expand Down
25 changes: 24 additions & 1 deletion BetterMultiview/ObsMultiview/Services/ProfileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ public class ProfileWatcher {
/// </summary>
private void ResolveConfig() {
if (_profile.ActiveProfile != null && _obs.IsObsConnected) {
_profile.SaveProfile();

_logger.LogInformation("Resolving active scene collection configuration");
var collection = _obs.WebSocket.GetCurrentSceneCollection();
_logger.LogDebug($"Currently active scene collection: {collection}");

if (collection == null) {
OnActiveProfileChanged(null);
return;
Expand All @@ -67,6 +69,27 @@ public class ProfileWatcher {
}
}

/// <summary>
/// Swap to slot configs
/// </summary>
/// <param name="localSlotId"></param>
/// <param name="remSlotId"></param>
public void SwapSlots(Guid slotA, Guid slotB) {
if (ActiveProfile?.SceneView != null) {
var idxA = ActiveProfile.SceneView.Slots.FindIndex(x => x.Id == slotA);
var idxB = ActiveProfile.SceneView.Slots.FindIndex(x => x.Id == slotB);

if (idxA >= 0 && idxB >= 0) {
var sA = ActiveProfile.SceneView.Slots[idxA];
var sB = ActiveProfile.SceneView.Slots[idxB];

ActiveProfile.SceneView.Slots[idxB] = sA;
ActiveProfile.SceneView.Slots[idxA] = sB;
OnActiveProfileChanged(ActiveProfile);
}
}
}

protected virtual void OnActiveProfileChanged(UserProfile.DObsProfile obj) {
App.Current.Dispatcher.Invoke(() => {
ActiveProfile = obj;
Expand Down
2 changes: 1 addition & 1 deletion BetterMultiview/ObsMultiview/StreamView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
mc:Ignorable="d"
WindowStyle="None"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="StreamDeck"
lex:ResxLocalizationProvider.DefaultAssembly="ObsMultiview"
lex:ResxLocalizationProvider.DefaultDictionary="MainWindow"
ResizeMode="NoResize"
AllowsTransparency="True"
Expand Down
6 changes: 3 additions & 3 deletions BetterMultiview/Plugins/KNX/EditGroups.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:knx="clr-namespace:ObsMultiview.Plugins.KNX"
mc:Ignorable="d"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="StreamDeck.Plugins"
lex:ResxLocalizationProvider.DefaultAssembly="ObsMultiview.Plugins"
lex:ResxLocalizationProvider.DefaultDictionary="KNX"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
WindowStartupLocation="CenterOwner"
Expand Down Expand Up @@ -47,9 +47,9 @@
</DataGrid>
<UniformGrid Grid.Row="1" Columns="2" HorizontalAlignment="Right" Margin="5"
Visibility="{Binding ReadOnly, Converter={StaticResource BoolToVis}}">
<Button Margin="5" Padding="7,2" Content="{lex:Loc StreamDeck:Dialogs:Ok}" IsDefault="True"
<Button Margin="5" Padding="7,2" Content="{lex:Loc ObsMultiview:Dialogs:Ok}" IsDefault="True"
Click="Ok_OnClick" />
<Button Margin="5" Padding="7,2" Content="{lex:Loc StreamDeck:Dialogs:Cancel}" IsCancel="True"
<Button Margin="5" Padding="7,2" Content="{lex:Loc ObsMultiview:Dialogs:Cancel}" IsCancel="True"
Click="Cancel_OnClick" />
</UniformGrid>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion BetterMultiview/Plugins/KNX/GlobalSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
mc:Ignorable="d"
Background="White"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="StreamDeck.Plugins"
lex:ResxLocalizationProvider.DefaultAssembly="ObsMultiview.Plugins"
lex:ResxLocalizationProvider.DefaultDictionary="KNX"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Height="302" Width="336">
Expand Down
2 changes: 1 addition & 1 deletion BetterMultiview/Plugins/KNX/KnxPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ObsMultiview.Plugins.KNX {
/// <summary>
/// A plugin to talk to a KNX/IP Interface
/// </summary>
public class KnxPlugin : PluginBase {
class KnxPlugin : PluginBase {
public override string Name => "KNX";
public override string Author => "Nathanael Schneider";
public override string Version => "1.0";
Expand Down
1 change: 1 addition & 0 deletions BetterMultiview/Plugins/ObsMultiview.Plugins.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="KNX.net" Version="1.1.10" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.IO.Ports" Version="5.0.1" />
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
<PackageReference Include="WPFLocalizeExtension" Version="3.9.0" />
</ItemGroup>
Expand Down
60 changes: 60 additions & 0 deletions BetterMultiview/Plugins/PelcoD/PelcoPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace ObsMultiview.Plugins.PelcoD {
class PelcoPlugin : PluginBase {
public override string Name => "Pelco-D";
public override string Author => "Nathanael Schneider";
public override string Version => "1.0";

private SerialPort _port;

public override void OnEnabled() {
Logger.LogInformation("Enabling Plugin");
var settings = CommandFacade.RequestSettings<PelcoSettings>();
_port = new SerialPort(settings.ComPort, settings.BaudRate, Parity.None, 8, StopBits.One);

try {
_port.Open();
} catch (Exception ex) {
Logger.LogError(ex, "Failed to open port");
}
}

public override void OnDisabled() {
Logger.LogInformation("Disabling Plugin");
try {
_port.Close();
} catch {
}
}

public override void ApplySlot(Guid slot) {
var settings = CommandFacade.RequestSlotSetting<PelcoSlotSettings>(slot);

byte[] message = new byte[7];
message[0] = 0xFF;
message[1] = settings.CameraID;
message[2] = 0x00;
message[3] = 0x07;
message[4] = 0x00;
message[5] = settings.PresetID;
message[6] = message.Skip(1).Take(5).Aggregate((byte) 0, (s, x) => (byte) (s + x));

_port.Write(message, 0, 7);
}

public override SettingsControl GetGlobalSettings() {
throw new NotImplementedException();
}

public override SettingsControl GetSlotSettings(Guid slot) {
throw new NotImplementedException();
}
}
}
17 changes: 17 additions & 0 deletions BetterMultiview/Plugins/PelcoD/PelcoSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ObsMultiview.Plugins.PelcoD {
public class PelcoSettings {
public string ComPort { get; set; }
public int BaudRate { get; set; } = 9600;
}

public class PelcoSlotSettings {
public byte CameraID { get; set; }
public byte PresetID { get; set; }
}
}
2 changes: 1 addition & 1 deletion BetterMultiview/Plugins/qlc/SlotSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:local="clr-namespace:ObsMultiview.Plugins.qlc"
mc:Ignorable="d"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="StreamDeck.Plugins"
lex:ResxLocalizationProvider.DefaultAssembly="ObsMultiview.Plugins"
lex:ResxLocalizationProvider.DefaultDictionary="Qlc"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
d:DesignHeight="450" d:DesignWidth="800">
Expand Down

0 comments on commit 0cecdf5

Please sign in to comment.