status bar
This commit is contained in:
parent
77832db39d
commit
a5d57893c4
2 changed files with 76 additions and 4 deletions
|
@ -14,6 +14,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sledgemapper
|
||||
{
|
||||
|
@ -45,9 +46,27 @@ namespace Sledgemapper
|
|||
_sessionData = new Session();
|
||||
IsFixedTimeStep = false;
|
||||
_communicationManager = new CommunicationManager(_sessionData);
|
||||
_communicationManager.Connection.Reconnected += OnHubReconnected;
|
||||
_communicationManager.Connection.Reconnecting += OnHubReconnecting;
|
||||
_communicationManager.Connection.Closed += OnHubDisconnected;
|
||||
_state = new State();
|
||||
}
|
||||
|
||||
private async Task OnHubDisconnected(Exception arg)
|
||||
{
|
||||
_mainWidget.lblConnectionStatus.Text = "Disconnected";
|
||||
}
|
||||
|
||||
private async Task OnHubReconnecting(Exception arg)
|
||||
{
|
||||
_mainWidget.lblConnectionStatus.Text = "Reconnecting";
|
||||
}
|
||||
|
||||
private async Task OnHubReconnected(string arg)
|
||||
{
|
||||
_mainWidget.lblConnectionStatus.Text = "Connected";
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
IsMouseVisible = true;
|
||||
|
@ -447,6 +466,7 @@ namespace Sledgemapper
|
|||
if (successful)
|
||||
{
|
||||
_sessionData.SessionName = localContent.TxtSession.Text;
|
||||
_mainWidget.lblSessionName.Text = _sessionData.SessionName;
|
||||
localWindow.Close();
|
||||
}
|
||||
}
|
||||
|
@ -468,7 +488,11 @@ namespace Sledgemapper
|
|||
|
||||
if (_communicationManager.Connection.State != HubConnectionState.Connected)
|
||||
{
|
||||
_mainWidget.lblConnectionStatus.Text = "Connecting";
|
||||
await _communicationManager.Connection.StartAsync();
|
||||
UpdateConnectionState(_communicationManager.Connection);
|
||||
|
||||
|
||||
}
|
||||
|
||||
var successful = false;
|
||||
|
@ -500,11 +524,36 @@ namespace Sledgemapper
|
|||
_communicationManager.SessionData.Map = _sessionData.Map;
|
||||
_communicationManager.SessionData.Overlays = _sessionData.Overlays;
|
||||
_communicationManager.SessionData.Walls = _sessionData.Walls;
|
||||
_mainWidget.lblSessionName.Text = _sessionData.SessionName;
|
||||
|
||||
localWindow.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateConnectionState(HubConnection connection)
|
||||
{
|
||||
switch (connection.State)
|
||||
{
|
||||
case HubConnectionState.Connected:
|
||||
_mainWidget.lblConnectionStatus.Text = "Connected";
|
||||
break;
|
||||
case HubConnectionState.Connecting:
|
||||
_mainWidget.lblConnectionStatus.Text = "Connecting";
|
||||
break;
|
||||
case HubConnectionState.Disconnected:
|
||||
_mainWidget.lblConnectionStatus.Text = "Disconnected";
|
||||
|
||||
break;
|
||||
case HubConnectionState.Reconnecting:
|
||||
_mainWidget.lblConnectionStatus.Text = "Reconnecting";
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async void OnButtonLoginClick(object sender, EventArgs e)
|
||||
{
|
||||
Container container = ((TextButton)sender).Parent;
|
||||
|
@ -545,6 +594,8 @@ namespace Sledgemapper
|
|||
_mainWidget.MenuConnectNew.Enabled = true;
|
||||
_mainWidget.MenuConnectJoin.Enabled = true;
|
||||
_mainWidget.MenuConnectSync.Enabled = true;
|
||||
_mainWidget.MenuConnectUpload.Enabled = true;
|
||||
_mainWidget.lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
||||
localWindow.Close();
|
||||
}
|
||||
}
|
||||
|
@ -601,6 +652,7 @@ namespace Sledgemapper
|
|||
_mainWidget.MenuConnectNew.Enabled = true;
|
||||
_mainWidget.MenuConnectJoin.Enabled = true;
|
||||
_mainWidget.MenuConnectSync.Enabled = true;
|
||||
_mainWidget.MenuConnectUpload.Enabled = true;
|
||||
localWindow.Close();
|
||||
}
|
||||
}
|
||||
|
@ -634,6 +686,11 @@ namespace Sledgemapper
|
|||
|
||||
private void OnMenuConnectJoinSelected(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Window window = new()
|
||||
{
|
||||
Title = "Join mapping session"
|
||||
|
@ -691,6 +748,11 @@ namespace Sledgemapper
|
|||
|
||||
private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var serverMap = await _communicationManager.Api.Session(_sessionData.SessionName);
|
||||
_sessionData.Overlays = serverMap.Overlays;
|
||||
_sessionData.Map = serverMap.Map;
|
||||
|
@ -699,11 +761,21 @@ namespace Sledgemapper
|
|||
|
||||
private async void OnMenuConnectUploadSelected(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await _communicationManager.Api.SaveSnapshot(_sessionData, _sessionData.SessionName);
|
||||
}
|
||||
|
||||
private void OnMenuConnectNewSelected(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Window window = new()
|
||||
{
|
||||
Title = "New mapping session"
|
||||
|
@ -754,10 +826,10 @@ namespace Sledgemapper
|
|||
}
|
||||
using StreamReader file = File.OpenText(dialog.FilePath);
|
||||
JsonSerializer serializer = new();
|
||||
var loadData = (Session)serializer.Deserialize(file, typeof(Session));
|
||||
_sessionData.Map=loadData.Map;
|
||||
_sessionData.Overlays=loadData.Overlays;
|
||||
_sessionData.Walls=loadData.Walls;
|
||||
var loadData = (Session)serializer.Deserialize(file, typeof(Session));
|
||||
_sessionData.Map = loadData.Map;
|
||||
_sessionData.Overlays = loadData.Overlays;
|
||||
_sessionData.Walls = loadData.Walls;
|
||||
};
|
||||
|
||||
dialog.ShowModal(_desktop);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue