mirror of
https://github.com/jwetzell/qController.git
synced 2026-08-08 08:53:46 +00:00
762472d945
* QSelectedCueCell.cs: Continue UI work * QSelectedCueOptionsCell.cs: Start work on Converting to Popup Style * ShadowButton.cs: Button in Frame with Shadow * ControlPage.xaml: * ControlPage.xaml.cs: Continue work on UI
331 lines
13 KiB
C#
331 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Xamarin.Forms;
|
|
using System.Collections;
|
|
using Acr.UserDialogs;
|
|
namespace qController
|
|
{
|
|
public partial class ControlPage : ContentPage
|
|
{
|
|
QController qController;
|
|
QSelectedCueCell qCell;
|
|
QSelectedCueOptionsCell qSelectedCueOptions;
|
|
ShadowButton showLevelsButton;
|
|
Grid mainG;
|
|
QControlsBlock qControlsBlock;
|
|
public ControlPage(string name, string address)
|
|
{
|
|
InitializeComponent();
|
|
|
|
qController = new QController(address, 53000);
|
|
qController.qClient.qParser.WorkspaceInfoReceived += WorkspaceInfoReceived;
|
|
qController.qClient.qParser.WorkspaceUpdated += WorkspaceUpdated;
|
|
qController.qClient.qParser.PlaybackPositionUpdated += PlaybackPositionUpdated;
|
|
qController.qClient.qParser.CueInfoUpdated += OnCueUpdateReceived;
|
|
qController.qClient.qParser.ChildrenUpdated += OnChildrenUpdated;
|
|
App.rootPage.MenuItemSelected += OnMenuItemSelected;
|
|
|
|
instanceName.Text = name;
|
|
|
|
InitGUI();
|
|
|
|
qController.KickOff();
|
|
}
|
|
|
|
private void WorkspaceInfoReceived(object source, WorkspaceInfoArgs args)
|
|
{
|
|
if(args.WorkspaceInfo.Count > 1)
|
|
{
|
|
Console.WriteLine("MULTIPLE WORKSPACES ON SELECTED COMPUTER");
|
|
PromptForWorkspace(args.WorkspaceInfo);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("ONLY ONE WORKSPACE ON SELECTED COMPUTER");
|
|
qController.Connect(args.WorkspaceInfo[0].uniqueID);
|
|
|
|
Device.BeginInvokeOnMainThread(() => {
|
|
FinishUI();
|
|
});
|
|
}
|
|
}
|
|
|
|
private void PromptForWorkspace(List<QInfo> workspaces)
|
|
{
|
|
ActionSheetConfig config = new ActionSheetConfig();
|
|
config.SetTitle("Select Workspace");
|
|
for (int i = 0; i < workspaces.Count; i++)
|
|
{
|
|
QInfo workspace = workspaces[i];
|
|
config.Add(workspace.displayName, new Action(() => {
|
|
Console.WriteLine("Workspace Selected: " + workspace.displayName);
|
|
qController.Connect(workspace.uniqueID);
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
{
|
|
FinishUI();
|
|
});
|
|
}));
|
|
}
|
|
UserDialogs.Instance.ActionSheet(config);
|
|
}
|
|
|
|
private void InitGUI()
|
|
{
|
|
App.rootPage.MenuPage.ChangeToControl();
|
|
NavigationPage.SetHasNavigationBar(this, false);
|
|
|
|
topBar.BackgroundColor = Color.FromHex("71AEFF");
|
|
|
|
|
|
BackgroundColor = Color.FromHex("4A4A4A");
|
|
menuButton.Text = QIcon.MENU;
|
|
|
|
qCell = new QSelectedCueCell();
|
|
|
|
|
|
qCell.SelectedCueEdited += OnSelectedCueEdited;
|
|
AbsoluteLayout.SetLayoutFlags(qCell, AbsoluteLayoutFlags.All);
|
|
|
|
|
|
switch (Device.RuntimePlatform)
|
|
{
|
|
case Device.iOS:
|
|
AbsoluteLayout.SetLayoutBounds(qCell, new Rectangle(0, 0.13, 1, 0.30));
|
|
topBar.HeightRequest = Math.Max(App.Height * .09, 65);
|
|
menuButton.Margin = new Thickness(App.WidthUnit * 2, 0, 0, App.WidthUnit * 2);
|
|
menuButton.FontSize = App.Height * .04;
|
|
break;
|
|
case Device.Android:
|
|
AbsoluteLayout.SetLayoutBounds(qCell, new Rectangle(0, 0.13, 1, 0.35));
|
|
topBar.HeightRequest = App.Height * .08;
|
|
menuButton.Margin = new Thickness(App.WidthUnit * 2, 0, 0, App.WidthUnit * 2);
|
|
menuButton.FontSize = App.Height * .05;
|
|
break;
|
|
}
|
|
var menuButtonGesture = new TapGestureRecognizer();
|
|
|
|
menuButtonGesture.Tapped += ShowMenu;
|
|
menuButton.GestureRecognizers.Add(menuButtonGesture);
|
|
|
|
|
|
|
|
sLayout.Children.Add(qCell);
|
|
}
|
|
|
|
private void OnSelectedCueEdited(object source, CueEditArgs args)
|
|
{
|
|
string address = "/workspace/" + qController.qWorkspace.workspace_id + "/cue_id/" + args.CueID + "/" + args.Property;
|
|
qController.qClient.sendArgsUDP(address, args.NewValue);
|
|
}
|
|
void FinishUI()
|
|
{
|
|
string workspace_prefix = "/workspace/" + qController.qWorkspace.workspace_id;
|
|
|
|
qSelectedCueOptions = new QSelectedCueOptionsCell();
|
|
|
|
qSelectedCueOptions.mainSlider.ValueChanged += (sender, args) =>
|
|
{
|
|
qController.qClient.sendArgs(workspace_prefix + "/cue_id/" + qSelectedCueOptions.activeCue + "/sliderLevel/0", (float)args.NewValue);
|
|
};
|
|
qSelectedCueOptions.leftSlider.ValueChanged += (sender, args) =>
|
|
{
|
|
qController.qClient.sendArgs(workspace_prefix + "/cue_id/" + qSelectedCueOptions.activeCue + "/sliderLevel/1", (float)args.NewValue);
|
|
};
|
|
qSelectedCueOptions.rightSlider.ValueChanged += (sender, args) =>
|
|
{
|
|
qController.qClient.sendArgs(workspace_prefix + "/cue_id/" + qSelectedCueOptions.activeCue + "/sliderLevel/2", (float)args.NewValue);
|
|
};
|
|
|
|
|
|
qControlsBlock = new QControlsBlock(qController);
|
|
|
|
switch (Device.RuntimePlatform)
|
|
{
|
|
case Device.iOS:
|
|
AbsoluteLayout.SetLayoutBounds(qControlsBlock, new Rectangle(0, 0.53, 1, 0.25));
|
|
AbsoluteLayout.SetLayoutFlags(qControlsBlock, AbsoluteLayoutFlags.All);
|
|
AbsoluteLayout.SetLayoutBounds(qSelectedCueOptions, new Rectangle(0,0.50,1,0.25));
|
|
AbsoluteLayout.SetLayoutFlags(qSelectedCueOptions, AbsoluteLayoutFlags.All);
|
|
break;
|
|
case Device.Android:
|
|
AbsoluteLayout.SetLayoutBounds(qControlsBlock, new Rectangle(0, 0.58, 1, 0.25));
|
|
AbsoluteLayout.SetLayoutFlags(qControlsBlock, AbsoluteLayoutFlags.All);
|
|
AbsoluteLayout.SetLayoutBounds(qSelectedCueOptions, new Rectangle(0,0.70,1,0.25));
|
|
AbsoluteLayout.SetLayoutFlags(qSelectedCueOptions, AbsoluteLayoutFlags.All);
|
|
break;
|
|
}
|
|
sLayout.Children.Add(qControlsBlock);
|
|
|
|
sLayout.Children.Add(qSelectedCueOptions);
|
|
|
|
|
|
Button b = new Button{
|
|
Text = QIcon.SLIDERS,
|
|
TextColor = Color.Black,
|
|
FontFamily = App.QFont,
|
|
FontSize = App.HeightUnit * 4,
|
|
VerticalOptions = LayoutOptions.FillAndExpand,
|
|
HorizontalOptions =LayoutOptions.FillAndExpand,
|
|
HeightRequest = App.HeightUnit * 8,
|
|
WidthRequest = App.HeightUnit * 8,
|
|
CornerRadius = (int)(App.HeightUnit * 4),
|
|
BackgroundColor = Color.LightBlue
|
|
};
|
|
b.Clicked += (s, e) =>
|
|
{
|
|
qSelectedCueOptions.IsVisible = !qSelectedCueOptions.IsVisible;
|
|
};
|
|
|
|
showLevelsButton = new ShadowButton(b);
|
|
|
|
switch (Device.RuntimePlatform)
|
|
{
|
|
case Device.iOS:
|
|
AbsoluteLayout.SetLayoutBounds(showLevelsButton, new Rectangle(0.04, 0.34, App.HeightUnit * 8, App.HeightUnit * 8));
|
|
AbsoluteLayout.SetLayoutFlags(showLevelsButton, AbsoluteLayoutFlags.PositionProportional);
|
|
break;
|
|
case Device.Android:
|
|
AbsoluteLayout.SetLayoutBounds(showLevelsButton, new Rectangle(0.04, 0.39, App.HeightUnit * 8, App.HeightUnit * 8));
|
|
AbsoluteLayout.SetLayoutFlags(showLevelsButton, AbsoluteLayoutFlags.PositionProportional);
|
|
break;
|
|
}
|
|
|
|
|
|
sLayout.Children.Add(showLevelsButton);
|
|
}
|
|
|
|
void ShowMenu(object sender, EventArgs e)
|
|
{
|
|
App.MenuIsPresented = true;
|
|
}
|
|
|
|
void Back()
|
|
{
|
|
qController.Disconnect();
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
{
|
|
App.rootPage.MenuPage.ChangeToHome();
|
|
});
|
|
App.NavigationPage.Navigation.PopAsync();
|
|
}
|
|
|
|
public void WorkspaceUpdated(object sender, WorkspaceEventArgs e)
|
|
{
|
|
if(e.UpdatedWorkspace.data.Count > 0)
|
|
{
|
|
qController.qWorkspace = e.UpdatedWorkspace;
|
|
qController.qWorkspace.CheckPopulated();
|
|
|
|
if (qController.qWorkspace.IsPopulated)
|
|
{
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
{
|
|
App.rootPage.MenuPage.ChangeToWorkspace(e.UpdatedWorkspace);
|
|
});
|
|
if (qCell.activeCue == null)
|
|
{
|
|
Device.BeginInvokeOnMainThread(() => {
|
|
QCue noSelect = new QCue();
|
|
noSelect.listName = "No Cue Selected";
|
|
noSelect.type = "";
|
|
noSelect.notes = "Workspace has loaded but no cue is selected";
|
|
noSelect.number = "!";
|
|
qCell.UpdateSelectedCue(noSelect);
|
|
});
|
|
qController.qClient.UpdateSelectedCue(qController.qWorkspace.workspace_id);
|
|
}
|
|
Console.WriteLine("Workspace updated in ControlPage: " + qController.qWorkspace.workspace_id);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void PlaybackPositionUpdated(object sender, PlaybackPositionArgs e)
|
|
{
|
|
qController.playbackPosition = e.PlaybackPosition;
|
|
Console.WriteLine("Playback Position updated in ControlPage: " + qController.playbackPosition);
|
|
QCue cue = qController.qWorkspace.GetCue(qController.playbackPosition);
|
|
if(cue != null)
|
|
{
|
|
Device.BeginInvokeOnMainThread(() => {
|
|
if (cue.levels != null)
|
|
showLevelsButton.IsVisible = true;
|
|
else
|
|
showLevelsButton.IsVisible = false;
|
|
qCell.UpdateSelectedCue(cue);
|
|
});
|
|
}
|
|
}
|
|
|
|
public void OnCueUpdateReceived(object sender, CueEventArgs args)
|
|
{
|
|
qController.qWorkspace.UpdateCue(args.Cue);
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
{
|
|
App.rootPage.MenuPage.ChangeCueName(args.Cue.uniqueID, args.Cue.listName);
|
|
});
|
|
if (qController.playbackPosition == null)
|
|
{
|
|
qController.playbackPosition = args.Cue.uniqueID;
|
|
}
|
|
|
|
if (args.Cue.uniqueID == qController.playbackPosition)
|
|
{
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
{
|
|
Console.WriteLine("Refreshing Currently Displayed Cue");
|
|
if (args.Cue.levels != null)
|
|
showLevelsButton.IsVisible = true;
|
|
else
|
|
showLevelsButton.IsVisible = false;
|
|
qCell.UpdateSelectedCue(args.Cue);
|
|
//if (!mainG.IsVisible)
|
|
// mainG.IsVisible = true;
|
|
if(qSelectedCueOptions != null)
|
|
{
|
|
qSelectedCueOptions.activeCue = args.Cue.uniqueID;
|
|
if (args.Cue.levels != null)
|
|
{
|
|
qSelectedCueOptions.UpdateLevels(args.Cue.levels[0]);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void OnChildrenUpdated(object source, ChildrenEventArgs args)
|
|
{
|
|
Console.WriteLine("Children Updated in ControlPage: " + args.cue_id);
|
|
qController.qWorkspace.UpdateChildren(args.cue_id, args.children);
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
{
|
|
App.rootPage.MenuPage.ChangeToControl();
|
|
App.rootPage.MenuPage.ChangeToWorkspace(qController.qWorkspace);
|
|
});
|
|
}
|
|
|
|
private void OnMenuItemSelected(object source, MenuEventArgs args)
|
|
{
|
|
if (args.Command.Contains("/"))
|
|
{
|
|
qController.qClient.sendStringUDP(args.Command);
|
|
}
|
|
else if (args.Command == "disconnect")
|
|
{
|
|
Back();
|
|
}
|
|
}
|
|
|
|
protected override void OnDisappearing()
|
|
{
|
|
base.OnDisappearing();
|
|
Console.WriteLine("Disappeared");
|
|
qController.Kill();
|
|
}
|
|
protected override void OnAppearing()
|
|
{
|
|
base.OnAppearing();
|
|
Console.WriteLine("Appeared");
|
|
}
|
|
}
|
|
}
|