Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions SubathonManager.Integration/OBSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,59 @@ public Task StopAsync(CancellationToken cancellationToken = default) {

public event Action? BrowserSourcesChanged;

public Dictionary<string, Dictionary<string, int>> GetCanvases() {
var canvases = new Dictionary<string, Dictionary<string, int>>();
if (!_obs.IsConnected) {
return canvases;
}

var currentCanvas = _obs.GetVideoSettings();

canvases.Add("Default", new () {
{"Width", currentCanvas.BaseWidth},
{"Height", currentCanvas.BaseHeight}
});

var v = _obs.GetVersion();

if (v.AvailableRequests.Contains("GetCanvasList")) {
try {
var response = _obs.SendRequest("GetCanvasList");
var count = 1;
if (response != null && response.TryGetValue("canvases", out JToken? _canvases)) {
foreach (var canvas in _canvases) {

#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
string canvasName = (string)canvas["canvasName"] ?? $"Canvas {count}";

var videoSettings = canvas["canvasVideoSettings"];
var flags = canvas["canvasFlags"];
if ((bool)(flags?["MAIN"] ?? false)) {
canvases.Remove("Default");
}
canvases.Add(canvasName, new () {
{"Width", (int)(videoSettings?["baseWidth"] ?? 1920)},
{"Height", (int)(videoSettings?["baseHeight"] ?? 1080)}
});
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
}
}
}
catch (Exception ex) {
_logger?.LogWarning(ex, "[OBSService] GetCanvasList request failed");
}
}

if (canvases.Count == 0) {
canvases.Add("Default", new () {
{"Width", currentCanvas.BaseWidth},
{"Height", currentCanvas.BaseHeight}
});
}

return canvases;
}

public List<string> GetScenes() {
return _obs.GetSceneList().Scenes
.Select(s => s.Name)
Expand Down
6 changes: 6 additions & 0 deletions SubathonManager.Services/EventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ private async Task LoopAsync() {
///////////////////////////////////////////////////////////////
ev.PointsValue = (int)Math.Floor(subathonValue!.Points);
if (double.TryParse(ev.Value, out double parsedValue)
&& ev.Currency != "viewers"
&& ev.Currency != "sub" && ev.Currency != "member" && ev.Currency != "order" // allow items from orders
&& !_currencyService.IsValidCurrency(ev.Currency)
&& !string.IsNullOrEmpty(ev.Value.Trim())) {
Expand Down Expand Up @@ -215,6 +216,11 @@ private async Task LoopAsync() {
ev.SecondsValue = subathonValue.Seconds;
}

if (ev.EventType.IsRaid()) {
// All raid types are always points per raid never viewer
ev.PointsValue = (int)Math.Floor(subathonValue!.Points);
}

if (ev.EventType.IsCurrencyDonation() && (string.IsNullOrEmpty(ev.Currency) ||
!_currencyService.IsValidCurrency(ev.Currency))) {
ev.PointsValue = 0;
Expand Down
40 changes: 40 additions & 0 deletions SubathonManager.UI/EditRouteWindow.Handlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using SubathonManager.Data;
using SubathonManager.Data.Widgets;
using SubathonManager.UI.Controls;
using SubathonManager.UI.Services;
using SubathonManager.UI.UiUtils;
using SubathonManager.UI.Validation;
using SubathonManager.UI.Views;
Expand All @@ -29,6 +30,8 @@
namespace SubathonManager.UI;

public partial class EditRouteWindow {
private MenuFlyout? _statusFlyout;

#region GeneralHandlers

private void WidgetDirtyBorder_Loaded(object? sender, RoutedEventArgs e) {
Expand Down Expand Up @@ -145,6 +148,38 @@ private async void CopyOverlayUrl_Click(object? sender, RoutedEventArgs e) {
_logger?.LogError(ex, "Failed to copy overlay URL");
}
}

private void ShowObsCanvasSelection_Click(object? sender, RoutedEventArgs e) {
var flyout = new MenuFlyout { Placement = PlacementMode.Bottom };

FillObsCanvases(flyout.Items);///////
flyout.Closed += (_, _) => {
if (ReferenceEquals(_statusFlyout, flyout)) _statusFlyout = null;
};
_statusFlyout = flyout;
flyout.ShowAt(OBSCanvasSyncBtn);
}

private void FillObsCanvases(ItemCollection items) {
items.Clear();
var canvases = ServiceManager.OBS.GetCanvases();
if (canvases.Count == 0) return;

foreach (var canvasData in canvases) {
var width = canvasData.Value["Width"];
var height = canvasData.Value["Height"];
var name = $"{canvasData.Key} (WxH {width}x{height})";
var groupItem = new MenuItem {
Header = name
};
groupItem.Click += async (_, _) => {
RouteHeightBox.Text = $"{height}";
RouteWidthBox.Text = $"{width}";
await SaveCurrentRoute();
};
items.Add(groupItem);
}
}

private void OpenOverlayInBrowser_Click(object? sender, RoutedEventArgs e) {
if (_route == null) return;
Expand Down Expand Up @@ -900,6 +935,11 @@ private async void MoveDown_Click(object? sender, RoutedEventArgs e) {
}

private async void SaveRouteButton_Click(object? sender, RoutedEventArgs e) {
if (_route == null) return;
await SaveCurrentRoute();
}

private async Task SaveCurrentRoute() {
if (_route == null) return;
try {
await SaveAllPendingWidgetChangesAsync();
Expand Down
33 changes: 22 additions & 11 deletions SubathonManager.UI/EditRouteWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,29 @@
<TextBlock Text="Name" FontSize="12" />
<TextBox x:Name="RouteNameBox" Margin="0,4,0,8" PlaceholderText="Overlay Name..."
VerticalContentAlignment="Center" />
<StackPanel Orientation="Horizontal">
<StackPanel Margin="0,2,2,2">
<TextBlock Text="Width" FontSize="12" />
<TextBox x:Name="RouteWidthBox" Width="120" v:NumericInputBehaviour.Mode="Integer"
PlaceholderText="1920" VerticalContentAlignment="Center" />
</StackPanel>
<StackPanel Margin="2,2,0,2">
<TextBlock Text="Height" FontSize="12" />
<TextBox x:Name="RouteHeightBox" Width="120" v:NumericInputBehaviour.Mode="Integer"
PlaceholderText="1080" VerticalContentAlignment="Center" />

<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<StackPanel Margin="0,2,2,2">
<TextBlock Text="Width" FontSize="12" />
<TextBox x:Name="RouteWidthBox" Width="100" v:NumericInputBehaviour.Mode="Integer"
PlaceholderText="1920" VerticalContentAlignment="Center" />
</StackPanel>
<StackPanel Margin="2,2,0,2">
<TextBlock Text="Height" FontSize="12" />
<TextBox x:Name="RouteHeightBox" Width="100" v:NumericInputBehaviour.Mode="Integer"
PlaceholderText="1080" VerticalContentAlignment="Center" />
</StackPanel>
</StackPanel>
</StackPanel>

<Button x:Name="OBSCanvasSyncBtn" HorizontalAlignment="Right" Margin="0 18 2 0"
ToolTip.Tip="Sync Overlay Dimensions to an OBS Canvas"
Click="ShowObsCanvasSelection_Click"
IsVisible="{Binding ObsConnected, RelativeSource={RelativeSource AncestorType=Window}}"
Width="128" Height="32" VerticalAlignment="Center" Cursor="Hand">
Sync to Canvas
</Button>
</Grid>

<Grid Margin="0,10,0,0">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
Expand Down
Loading