-
Notifications
You must be signed in to change notification settings - Fork 1
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
bd99031
commit 625cc3b
Showing
6 changed files
with
285 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Microsoft.UI.Xaml.Media; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ACCBroadcaster.Classes | ||
{ | ||
internal class Camera : INotifyPropertyChanged | ||
{ | ||
public string DisplayName { get; set; } | ||
public string InternalName { get; set; } | ||
public bool IsActive { get; set; } | ||
|
||
private SolidColorBrush _BackgroundBrush; | ||
public SolidColorBrush BackgroundBrush | ||
{ | ||
get { return _BackgroundBrush; } | ||
set | ||
{ | ||
_BackgroundBrush = value; | ||
OnPropertyChanged(nameof(BackgroundBrush)); | ||
} | ||
} | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
public void OnPropertyChanged(string propertyName) | ||
{ | ||
if (PropertyChanged != null) | ||
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
|
||
public Camera(string displayName, string internalName) | ||
{ | ||
DisplayName = displayName; | ||
InternalName = internalName; | ||
IsActive = false; | ||
} | ||
|
||
public void SetActive(bool isActive) | ||
{ | ||
IsActive = isActive; | ||
if (isActive) | ||
{ | ||
BackgroundBrush = new SolidColorBrush(Microsoft.UI.Colors.Red); | ||
} | ||
else | ||
{ | ||
BackgroundBrush = null; | ||
} | ||
} | ||
} | ||
} |
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,33 @@ | ||
<Page | ||
x:Class="ACCBroadcaster.Views.Broadcasting.CameraSelectorView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:ACCBroadcaster.Views.Broadcasting" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:classes="using:ACCBroadcaster.Classes" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid> | ||
<StackPanel Orientation="Vertical" Margin="5"> | ||
<TextBlock FontSize="15" FontWeight="Bold">Cameras</TextBlock> | ||
<StackPanel Orientation="Horizontal"> | ||
<ItemsControl ItemsSource="{x:Bind Cameras}"> | ||
<ItemsControl.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="5"/> | ||
</ItemsPanelTemplate> | ||
</ItemsControl.ItemsPanel> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate x:DataType="classes:Camera"> | ||
<Button Name="{x:Bind InternalName}" Background="{x:Bind BackgroundBrush, Mode=OneWay}" Click="OnClick" Content="{x:Bind DisplayName}" Margin="5"></Button> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
<ComboBox Name="OnboardsComboBox" ItemsSource="{x:Bind OnboardCameras}" DisplayMemberPath="DisplayName" PlaceholderText="Onboards" SelectionChanged="OnboardSelectionChanged" DropDownClosed="OnboardDropDownClosed" Margin="0, 10"></ComboBox> | ||
<ComboBox Name="DrivableComboBox" ItemsSource="{x:Bind DrivableCameras}" DisplayMemberPath="DisplayName" PlaceholderText="Drivable" SelectionChanged="DrivableSelectionChanged" DropDownClosed="DrivableDropDownClosed" Margin="10"></ComboBox> | ||
</StackPanel> | ||
</StackPanel> | ||
</Grid> | ||
</Page> |
185 changes: 185 additions & 0 deletions
185
ACCBroadcaster/Views/Broadcasting/CameraSelectorView.xaml.cs
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,185 @@ | ||
using ACCBroadcaster.Classes; | ||
using ksBroadcastingNetwork.Structs; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
|
||
// To learn more about WinUI, the WinUI project structure, | ||
// and more about our project templates, see: http://aka.ms/winui-project-info. | ||
|
||
namespace ACCBroadcaster.Views.Broadcasting | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class CameraSelectorView : Page | ||
{ | ||
private ObservableCollection<Camera> Cameras = new ObservableCollection<Camera>(); | ||
private ObservableCollection<Camera> OnboardCameras = new ObservableCollection<Camera>(); | ||
private ObservableCollection<Camera> DrivableCameras = new ObservableCollection<Camera>(); | ||
private bool OnboardIsActive = false; | ||
private bool DrivableIsActive = false; | ||
|
||
public CameraSelectorView() | ||
{ | ||
Cameras.Add(new Camera("TV Set 1", "set1")); | ||
Cameras.Add(new Camera("TV Set 2", "set2")); | ||
Cameras.Add(new Camera("Helicam", "Helicam")); | ||
Cameras.Add(new Camera("Pitlane", "pitlane")); | ||
OnboardCameras.Add(new Camera("Cockpit", "Onboard0")); | ||
OnboardCameras.Add(new Camera("Driver", "Onboard1")); | ||
OnboardCameras.Add(new Camera("Dashboard", "Onboard2")); | ||
OnboardCameras.Add(new Camera("Rear", "Onboard3")); | ||
DrivableCameras.Add(new Camera("Chase", "Chase")); | ||
DrivableCameras.Add(new Camera("Far Chase", "FarChase")); | ||
DrivableCameras.Add(new Camera("Bonnet", "Bonnet")); | ||
DrivableCameras.Add(new Camera("Dash Pro", "DashPro")); | ||
DrivableCameras.Add(new Camera("Cockpit", "Cockpit")); | ||
DrivableCameras.Add(new Camera("Dash", "Dash")); | ||
DrivableCameras.Add(new Camera("Helmet", "Helmet")); | ||
ACCService.Client.MessageHandler.OnRealtimeUpdate += OnRealtimeUpdate; | ||
this.InitializeComponent(); | ||
} | ||
|
||
void OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
Button button = sender as Button; | ||
Camera camera = Cameras.FirstOrDefault(x => x.InternalName == button.Name); | ||
if (camera != null) | ||
{ | ||
ACCService.Client.MessageHandler.SetCamera(camera.InternalName, "default"); | ||
} | ||
} | ||
|
||
private void OnRealtimeUpdate(string sender, RealtimeUpdate update) | ||
{ | ||
Camera currentCamera = Cameras.FirstOrDefault(x => x.IsActive); | ||
|
||
if (update.ActiveCameraSet == "Onboard") | ||
{ | ||
IsOnboardActive(true); | ||
if (DrivableIsActive) | ||
{ | ||
IsDrivableActive(false); | ||
} | ||
if (currentCamera != null) | ||
{ | ||
currentCamera.SetActive(false); | ||
} | ||
} | ||
else if (update.ActiveCameraSet == "Drivable") | ||
{ | ||
IsDrivableActive(true); | ||
if (OnboardIsActive) | ||
{ | ||
IsOnboardActive(false); | ||
} | ||
if (currentCamera != null) | ||
{ | ||
currentCamera.SetActive(false); | ||
} | ||
} | ||
else | ||
{ | ||
if (currentCamera != null) | ||
{ | ||
if (currentCamera.InternalName != update.ActiveCameraSet) | ||
{ | ||
currentCamera.SetActive(false); | ||
Camera newCamera = Cameras.FirstOrDefault(x => x.InternalName == update.ActiveCameraSet); | ||
newCamera.SetActive(true); | ||
IsDrivableActive(false); | ||
IsOnboardActive(false); | ||
} | ||
} else | ||
{ | ||
Camera newCamera = Cameras.FirstOrDefault(x => x.InternalName == update.ActiveCameraSet); | ||
newCamera.SetActive(true); | ||
IsDrivableActive(false); | ||
IsOnboardActive(false); | ||
} | ||
} | ||
} | ||
|
||
private void OnboardSelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
Camera camera = e.AddedItems[0] as Camera; | ||
ACCService.Client.MessageHandler.SetCamera("Onboard", camera.InternalName); | ||
Camera previousCamera = OnboardCameras.FirstOrDefault(x => x.IsActive == true); | ||
if (previousCamera != null) | ||
{ | ||
previousCamera.IsActive = false; | ||
} | ||
camera.IsActive = true; | ||
} | ||
|
||
private void OnboardDropDownClosed(object sender, object e) | ||
{ | ||
Camera camera = OnboardCameras.FirstOrDefault(x => x.IsActive == true); | ||
if (camera != null) | ||
{ | ||
ACCService.Client.MessageHandler.SetCamera("Onboard", camera.InternalName); | ||
} | ||
} | ||
|
||
private void DrivableSelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
Camera camera = e.AddedItems[0] as Camera; | ||
ACCService.Client.MessageHandler.SetCamera("Drivable", camera.InternalName); | ||
Camera previousCamera = DrivableCameras.FirstOrDefault(x => x.IsActive == true); | ||
if (previousCamera != null) | ||
{ | ||
previousCamera.IsActive = false; | ||
} | ||
camera.IsActive = true; | ||
} | ||
|
||
private void DrivableDropDownClosed(object sender, object e) | ||
{ | ||
Camera camera = DrivableCameras.FirstOrDefault(x => x.IsActive == true); | ||
if (camera != null) | ||
{ | ||
ACCService.Client.MessageHandler.SetCamera("Drivable", camera.InternalName); | ||
} | ||
} | ||
|
||
private void IsOnboardActive(bool IsActive) | ||
{ | ||
if (IsActive) | ||
{ | ||
OnboardIsActive = true; | ||
OnboardsComboBox.Background = new SolidColorBrush(Microsoft.UI.Colors.Red); | ||
} else | ||
{ | ||
OnboardIsActive = false; | ||
OnboardsComboBox.Background = null; | ||
} | ||
} | ||
|
||
private void IsDrivableActive(bool IsActive) | ||
{ | ||
if (IsActive) | ||
{ | ||
DrivableIsActive = true; | ||
DrivableComboBox.Background = new SolidColorBrush(Microsoft.UI.Colors.Red); | ||
} | ||
else | ||
{ | ||
DrivableIsActive = false; | ||
DrivableComboBox.Background = null; | ||
} | ||
} | ||
} | ||
} |
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