error message, broken build
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-21 16:53:04 +01:00
parent 7e3e645fc9
commit 79edfcc4d3
19 changed files with 396 additions and 312 deletions

View File

@ -3,8 +3,6 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using Sledgemapper.Entities;
using Sledgemapper.Models.Users;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
@ -12,6 +10,8 @@ using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Sledgemapper.Api.Core.Entities;
using Sledgemapper.Api.Models;
namespace Sledgemapper.Api.Controllers
{

View File

@ -1,6 +1,6 @@
using MediatR;
using Microsoft.AspNetCore.SignalR;
using Sledgemapper.Clients;
using Sledgemapper.Shared.Clients;
using System.Threading;
using System.Threading.Tasks;
using Sledgemapper.Api.Hubs;

View File

@ -2,9 +2,9 @@ using MediatR;
using Microsoft.AspNetCore.SignalR;
using Sledgemapper.Api.Hubs;
using Sledgemapper.Api.Notifications;
using Sledgemapper.Clients;
using System.Threading;
using System.Threading.Tasks;
using Sledgemapper.Shared.Clients;
namespace Sledgemapper.Api.Handlers
{

View File

@ -1,10 +1,10 @@
using MediatR;
using Microsoft.AspNetCore.SignalR;
using Sledgemapper.Api.Notifications;
using Sledgemapper.Clients;
using System.Threading;
using System.Threading.Tasks;
using Sledgemapper.Api.Hubs;
using Sledgemapper.Shared.Clients;
namespace Sledgemapper.Api.Handlers
{

View File

@ -4,11 +4,12 @@ using System.Linq;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using Sledgemapper.Shared.Entities;
using Sledgemapper.Clients;
using System;
using Sledgemapper.Api.Infrastructure.Data;
using Microsoft.AspNetCore.Authorization;
using Sledgemapper.Api.Core.Entities;
using Sledgemapper.Api.Models;
using Sledgemapper.Shared.Clients;
namespace Sledgemapper.Api.Hubs
{

View File

@ -0,0 +1,9 @@
namespace Sledgemapper.Api.Models
{
public class LoginResponse : AuthResult
{
public string Username { get; set; }
public string Initials { get; set; }
public string Id { get; internal set; }
}
}

View File

@ -1,16 +1,7 @@
using Sledgemapper.Models.Users;
namespace Sledgemapper.Api.Models
{
public class RegistrationResponse : AuthResult
{
}
public class LoginResponse : AuthResult
{
public string Username { get; set; }
public string Initials { get; set; }
public string Id { get; internal set; }
}
}

View File

@ -1,5 +1,6 @@
using MediatR;
using System;
using Sledgemapper.Shared.Entities;
namespace Sledgemapper.Api.Notifications
{
@ -8,9 +9,9 @@ namespace Sledgemapper.Api.Notifications
public double Timestamp { get; private set; }
public string UserId { get; private set; }
public int SessionId { get; set; }
public Models.Session Session { get; set; }
public Session Session { get; set; }
public BaseNotification(Models.Session session, string userId)
public BaseNotification(Session session, string userId)
{
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
Session = session; ;

View File

@ -6,7 +6,7 @@ namespace Sledgemapper.Api.Notifications
{
public Note Note { get; private set; }
public NewNoteNotification(Models.Session session, Note note, string userId) : base(session, userId)
public NewNoteNotification(Session session, Note note, string userId) : base(session, userId)
{
Note = note;
}

View File

@ -6,7 +6,7 @@ namespace Sledgemapper.Api.Notifications
{
public Wall Wall { get; private set; }
public NewWallNotification(Models.Session session, Wall wall, string userId) : base(session, userId)
public NewWallNotification(Session session, Wall wall, string userId) : base(session, userId)
{
Wall = wall;
}

View File

@ -3,6 +3,9 @@ using System.IO;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Myra.Graphics2D.UI;
using Myra.Graphics2D.Brushes;
@ -81,6 +84,18 @@ namespace Sledgemapper
window.ShowModal(desktop);
}
public static void Toast(this Widget widget, Desktop desktop, string title)
{
Window window = new()
{
Content = widget
};
window.Show(desktop, new Point(desktop.BoundsFetcher().X-200, desktop.BoundsFetcher().Y - 200));
Task.Delay(500).ContinueWith(_=>window.Close()).SafeFireAndForget();
}
}
//public interface IExtendedWidget

View File

@ -0,0 +1,12 @@
namespace Sledgemapper.Messages
{
public class ErrorMessage : TinyMessenger.TinyMessageBase
{
public string Message { get; }
public ErrorMessage(object sender, string message) : base(sender)
{
Message = message;
}
}
}

View File

@ -82,6 +82,11 @@
<DependentUpon>$([System.String]::Concat(%(Filename), ".cs"))</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<Compile Update="UI\ErrorWindow.Custom.cs">
<DependentUpon>$([System.String]::Copy(%(Filename)).Replace(".Generated",".cs"))</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,17 @@
using Myra.Graphics2D.Brushes;
using Myra.Graphics2D.UI;
namespace Sledgemapper.UI
{
partial class ErrorWindow : VerticalStackPanel
{
public ErrorWindow(string message)
{
BuildUI();
TxtError.Text = message;
}
}
}

View File

@ -0,0 +1,42 @@
/* Generated by MyraPad at 21/09/2021 16:37:58 */
using Myra;
using Myra.Graphics2D;
using Myra.Graphics2D.TextureAtlases;
using Myra.Graphics2D.UI;
using Myra.Graphics2D.Brushes;
using Myra.Graphics2D.UI.Properties;
#if MONOGAME || FNA
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#elif STRIDE
using Stride.Core.Mathematics;
#else
using System.Drawing;
using System.Numerics;
#endif
namespace Sledgemapper.UI
{
partial class ErrorWindow: VerticalStackPanel
{
private void BuildUI()
{
TxtError = new Label();
TxtError.Text = "Error Message";
TxtError.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center;
TxtError.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center;
TxtError.Id = "TxtError";
Width = 400;
Height = 40;
Padding = new Thickness(10);
Background = new SolidBrush("#FE3930FF");
Widgets.Add(TxtError);
}
public Label TxtError;
}
}

View File

@ -0,0 +1,11 @@
/* Generated by MyraPad at 21/09/2021 16:37:58 */
namespace Sledgemapper.UI
{
public partial class ErrorWindow
{
public ErrorWindow()
{
BuildUI();
}
}
}

View File

@ -0,0 +1,7 @@
<Project>
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="ErrorWindow" OutputPath="C:\src\Map\Sledgemapper\UI" />
<VerticalStackPanel Width="400" Height="40" Padding="10" Background="#FE3930FF" >
<Label Text="Error Message" HorizontalAlignment="Center" VerticalAlignment="Center" Id="TxtError" />
</VerticalStackPanel>
</Project>

View File

@ -1,5 +1,8 @@
using System;
using System.IO;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Xna.Framework;
using Myra.Graphics2D;
using Myra.Graphics2D.Brushes;
using Myra.Graphics2D.UI;
using Myra.Graphics2D.UI.File;
@ -7,10 +10,7 @@ using Myra.Graphics2D.UI.Properties;
using Newtonsoft.Json;
using Sledgemapper.Messages;
using Sledgemapper.Shared.Entities;
using System;
using System.IO;
using TinyMessenger;
using Session = Sledgemapper.Shared.Entities.Session;
namespace Sledgemapper.UI
{
@ -67,68 +67,22 @@ namespace Sledgemapper.UI
Messenger.Subscribe<MapOpenedMessage>(OnMapOpenedMessage);
Messenger.Subscribe<CenterOnTileMessage>(OnCenterOnTileMessage);
Messenger.Subscribe<CampaignSelectedMessage>(OnCampaignSelectedMessage);
Messenger.Subscribe<ErrorMessage>(OnErrorMessage);
}
private void OnCampaignSelectedMessage(CampaignSelectedMessage obj)
private void CenterOnSelectedTile()
{
lblCampaign.Text = State.Instance.CampaignName;
MenuMapNew.Enabled = true;
MenuMapOpen.Enabled = true;
MenuCampaignPlayers.Enabled = true;
CenterOnTile(State.Instance.SelectedTile.X, State.Instance.SelectedTile.Y);
}
private void OnCenterOnTileMessage(CenterOnTileMessage obj)
private void CenterOnTile(int x, int y)
{
CenterOnTile(obj.X, obj.Y);
}
private async void OnMapOpenedMessage(MapOpenedMessage obj)
{
lblMap.Text = obj.MapName;
State.Instance.MapId = obj.MapId;
State.Instance.MapName = obj.MapName;
CommunicationManager.SessionData.SessionName = obj.MapName;
CommunicationManager.SessionData.SessionId = obj.MapId;
MenuConnectSync.Enabled = true;
MenuConnectUpload.Enabled = true;
CommunicationManager.SessionData.MapEntityAdded -= OnMapEntityAdded;
CommunicationManager.SessionData.MapEntityDeleted -= OnMapEntityDeleted;
CommunicationManager.SessionData.MapEntityAdded += OnMapEntityAdded;
CommunicationManager.SessionData.MapEntityDeleted += OnMapEntityDeleted;
var serverMap = await CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
if (CommunicationManager.Connection.State != HubConnectionState.Connected)
{
await CommunicationManager.Connection.StartAsync();
UpdateConnectionState(CommunicationManager.Connection);
}
var result = await CommunicationManager.Connection?.InvokeAsync<bool>("JoinSession", State.Instance.MapId);
CommunicationManager.SessionData.Overlays = serverMap.Overlays;
CommunicationManager.SessionData.Map = serverMap.Map;
CommunicationManager.SessionData.Walls = serverMap.Walls;
CommunicationManager.SessionData.Notes = serverMap.Notes;
CommunicationManager.SessionData.Lines = serverMap.Lines;
CommunicationManager.SessionData.Rooms = serverMap.Rooms;
}
private async void OnSignalrConnectionUpdateMessage(SignalrConnectionUpdateMessage obj)
{
lblConnectionStatus.Text = "Connecting";
await CommunicationManager.Connection.StartAsync();
UpdateConnectionState(CommunicationManager.Connection);
}
private void OnLoginSuccesfulMessage(LoginSuccesfulMessage obj)
{
//MenuConnectNew.Enabled = true;
//MenuConnectJoin.Enabled = true;
MenuCampaignOpen.Enabled = true;
MenuCampaingNew.Enabled = true;
lblUsername.Text = $"{obj.Initials}";
var center = new Point((Window.ClientBounds.Width + 200) / 2 - State.Instance.TileSize / 2,
Window.ClientBounds.Height / 2 - State.Instance.TileSize / 2);
var dx = center.X - x * State.Instance.TileSize - State.Instance.ViewportCenter.X;
var dy = center.Y - y * State.Instance.TileSize - State.Instance.ViewportCenter.Y;
State.Instance.ViewportCenter = new Vector3(State.Instance.ViewportCenter.X + dx,
State.Instance.ViewportCenter.Y + dy, State.Instance.ViewportCenter.Z);
}
public void ClearSelection()
@ -140,234 +94,37 @@ namespace Sledgemapper.UI
private void ClearSelection(Grid grid)
{
foreach (var widget in grid.Widgets)
{
widget.Border = null;
}
foreach (var widget in grid.Widgets) widget.Border = null;
}
private void ClearSelection(HorizontalStackPanel grid)
{
foreach (var widget in grid.Widgets)
{
widget.Border = null;
}
foreach (var widget in grid.Widgets) widget.Border = null;
}
private void OnMenuConnectLoginSelected(object sender, EventArgs e)
//TODO Refactor
private void EditNote(Note note)
{
Window window = new()
{
Title = "Login"
};
var content = new LoginRegisterWindow(CommunicationManager, Messenger);
window.Content = content;
window.ShowModal(Desktop);
State.Instance.SelectedNote = new Note { X = note.X, Y = note.Y, Text = note.Text };
new NoteWindow(CommunicationManager, note).ShowInModalWindow(Desktop, $" Note on {note.X}:{note.Y}");
}
private void UpdateConnectionState(HubConnection connection)
private void OnBtnToolbarDeleteClicked(object sender, EventArgs e)
{
switch (connection.State)
{
case HubConnectionState.Connected:
lblConnectionStatus.Text = "Connected";
break;
case HubConnectionState.Connecting:
lblConnectionStatus.Text = "Connecting";
break;
case HubConnectionState.Disconnected:
lblConnectionStatus.Text = "Disconnected";
Messenger.Publish(new ErrorMessage(this,"test"));
State.Instance.InsertMode = InsertMode.NewDelete;
break;
case HubConnectionState.Reconnecting:
lblConnectionStatus.Text = "Reconnecting";
break;
}
ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Thickness(2);
}
private void OnMapEntityAdded(object sender, MapEntityAddedEventArgs e)
private void OnBtnToolbarLinClicked(object sender, EventArgs e)
{
CommunicationManager.Enqueue(e.MapEntity, TileAction.Add);
}
private void OnMapEntityDeleted(object sender, MapEntityDeletedEventArgs e)
{
CommunicationManager.Enqueue(e.MapEntity, TileAction.Delete);
}
private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled)
{
return;
}
var serverMap = await CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
CommunicationManager.SessionData.Overlays = serverMap.Overlays;
CommunicationManager.SessionData.Map = serverMap.Map;
CommunicationManager.SessionData.Walls = serverMap.Walls;
CommunicationManager.SessionData.Notes = serverMap.Notes;
CommunicationManager.SessionData.Lines = serverMap.Lines;
CommunicationManager.SessionData.Rooms = serverMap.Rooms;
}
private async void OnMenuConnectUploadSelected(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled)
{
return;
}
await CommunicationManager.Api.SaveSnapshot(CommunicationManager.SessionData, State.Instance.MapId);
}
private void OnMenuFileSaveSelected(object sender, EventArgs e)
{
FileDialog dialog = new(FileDialogMode.SaveFile)
{
Filter = "*.map"
};
dialog.Closed += (s, a) =>
{
if (!dialog.Result)
{
return;
}
using StreamWriter file = File.CreateText(dialog.FilePath);
JsonSerializer serializer = new();
serializer.Serialize(file, CommunicationManager.SessionData);
};
dialog.ShowModal(Desktop);
}
private void OnMenuFileLoadSelected(object sender, EventArgs e)
{
var dialog = new FileDialog(FileDialogMode.OpenFile)
{
Filter = "*.map"
};
dialog.Closed += (s, a) =>
{
if (!dialog.Result)
{
return;
}
using StreamReader file = File.OpenText(dialog.FilePath);
JsonSerializer serializer = new();
var loadData = (Session)serializer.Deserialize(file, typeof(Session));
CommunicationManager.SessionData.Map = loadData.Map;
CommunicationManager.SessionData.Overlays = loadData.Overlays;
CommunicationManager.SessionData.Walls = loadData.Walls;
CommunicationManager.SessionData.Rooms = loadData.Rooms;
CommunicationManager.SessionData.Lines = loadData.Lines;
};
dialog.ShowModal(Desktop);
}
private void OneMenuFileSettingsSelected(object sender, EventArgs e)
{
var propertyGrid = new PropertyGrid
{
Object = Settings.Instance,
Width = 350
};
var _windowEditor = new Window
{
Title = "Object Editor",
Content = propertyGrid
};
_windowEditor.ShowModal(Desktop);
}
private void OnMenuViewShowCellNUmbersSelected(object sender, EventArgs e)
{
State.Instance.ShowCellNumbers = !State.Instance.ShowCellNumbers;
}
private void OnMenuViewCenterOnSelectionSelected(object sender, EventArgs e)
{
CenterOnSelectedTile();
}
private void OnMenuViewNotesSelected(object sender, EventArgs e)
{
Window window = new()
{
Title = "Notes"
};
new NoteList(CommunicationManager, Messenger).ShowInModalWindow(Desktop, "Notes");
}
private void CenterOnSelectedTile()
{
CenterOnTile(State.Instance.SelectedTile.X, State.Instance.SelectedTile.Y);
}
private void CenterOnTile(int x, int y)
{
var center = new Point((Window.ClientBounds.Width + 200) / 2 - State.Instance.TileSize / 2, Window.ClientBounds.Height / 2 - State.Instance.TileSize / 2);
var dx = center.X - x * State.Instance.TileSize - State.Instance.ViewportCenter.X;
var dy = center.Y - y * State.Instance.TileSize - State.Instance.ViewportCenter.Y;
State.Instance.ViewportCenter = new Vector3(State.Instance.ViewportCenter.X + dx, State.Instance.ViewportCenter.Y + dy, State.Instance.ViewportCenter.Z);
}
private void OnMenuCampaignNew(object sender, EventArgs e)
{
if (sender is MenuItem && !((MenuItem)sender).Enabled)
{
return;
}
new CampaignWindow(CommunicationManager, Messenger).ShowInModalWindow(Desktop, "New campaign"); ;
}
private async void OnMenuCampaignOpen(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled)
{
return;
}
var content = new CampaignList(CommunicationManager, Messenger);
await content.LoadCampaigns();
content.ShowInModalWindow(Desktop, "Campaigns");
}
private async void OnMenuCampaignPlayersSelected(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled)
{
return;
}
var content = new PlayerList(CommunicationManager);
await content.LoadPlayers();
content.ShowInModalWindow(Desktop, "Players");
}
private async void OnMenuMapOpen(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled)
{
return;
}
var content = new MapList(CommunicationManager, Messenger);
await content.LoadMaps();
content.ShowInModalWindow(Desktop, "Maps");
State.Instance.InsertMode = InsertMode.NewLine;
ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Thickness(2);
}
//private async void OnButtonJoinSessionClicked(object sender, EventArgs e)
@ -425,42 +182,258 @@ namespace Sledgemapper.UI
State.Instance.InsertMode = InsertMode.NewRoom;
ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
((ImageTextButton)sender).BorderThickness = new Thickness(2);
}
private void OnBtnToolbarLinClicked(object sender, EventArgs e)
private void OnCampaignSelectedMessage(CampaignSelectedMessage obj)
{
State.Instance.InsertMode = InsertMode.NewLine;
ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
lblCampaign.Text = State.Instance.CampaignName;
MenuMapNew.Enabled = true;
MenuMapOpen.Enabled = true;
MenuCampaignPlayers.Enabled = true;
}
private void OnBtnToolbarDeleteClicked(object sender, EventArgs e)
private void OnCenterOnTileMessage(CenterOnTileMessage obj)
{
State.Instance.InsertMode = InsertMode.NewDelete;
CenterOnTile(obj.X, obj.Y);
}
ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
private void OnErrorMessage(ErrorMessage obj)
{
new ErrorWindow(obj.Message).Toast(Desktop,null);
}
private void OneMenuFileSettingsSelected(object sender, EventArgs e)
{
var propertyGrid = new PropertyGrid
{
Object = Settings.Instance,
Width = 350
};
var _windowEditor = new Window
{
Title = "Object Editor",
Content = propertyGrid
};
_windowEditor.ShowModal(Desktop);
}
private void OnLoginSuccesfulMessage(LoginSuccesfulMessage obj)
{
//MenuConnectNew.Enabled = true;
//MenuConnectJoin.Enabled = true;
MenuCampaignOpen.Enabled = true;
MenuCampaingNew.Enabled = true;
lblUsername.Text = $"{obj.Initials}";
}
private void OnMapEntityAdded(object sender, MapEntityAddedEventArgs e)
{
CommunicationManager.Enqueue(e.MapEntity, TileAction.Add);
}
private void OnMapEntityDeleted(object sender, MapEntityDeletedEventArgs e)
{
CommunicationManager.Enqueue(e.MapEntity, TileAction.Delete);
}
private async void OnMapOpenedMessage(MapOpenedMessage obj)
{
lblMap.Text = obj.MapName;
State.Instance.MapId = obj.MapId;
State.Instance.MapName = obj.MapName;
CommunicationManager.SessionData.SessionName = obj.MapName;
CommunicationManager.SessionData.SessionId = obj.MapId;
MenuConnectSync.Enabled = true;
MenuConnectUpload.Enabled = true;
CommunicationManager.SessionData.MapEntityAdded -= OnMapEntityAdded;
CommunicationManager.SessionData.MapEntityDeleted -= OnMapEntityDeleted;
CommunicationManager.SessionData.MapEntityAdded += OnMapEntityAdded;
CommunicationManager.SessionData.MapEntityDeleted += OnMapEntityDeleted;
var serverMap = await CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
if (CommunicationManager.Connection.State != HubConnectionState.Connected)
{
await CommunicationManager.Connection.StartAsync();
UpdateConnectionState(CommunicationManager.Connection);
}
var result = await CommunicationManager.Connection?.InvokeAsync<bool>("JoinSession", State.Instance.MapId);
CommunicationManager.SessionData.Overlays = serverMap.Overlays;
CommunicationManager.SessionData.Map = serverMap.Map;
CommunicationManager.SessionData.Walls = serverMap.Walls;
CommunicationManager.SessionData.Notes = serverMap.Notes;
CommunicationManager.SessionData.Lines = serverMap.Lines;
CommunicationManager.SessionData.Rooms = serverMap.Rooms;
}
private void OnMenuCampaignNew(object sender, EventArgs e)
{
if (sender is MenuItem && !((MenuItem)sender).Enabled) return;
new CampaignWindow(CommunicationManager, Messenger).ShowInModalWindow(Desktop, "New campaign");
;
}
private async void OnMenuCampaignOpen(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled) return;
var content = new CampaignList(CommunicationManager, Messenger);
await content.LoadCampaigns();
content.ShowInModalWindow(Desktop, "Campaigns");
}
private async void OnMenuCampaignPlayersSelected(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled) return;
var content = new PlayerList(CommunicationManager);
await content.LoadPlayers();
content.ShowInModalWindow(Desktop, "Players");
}
private void OnMenuConnectLoginSelected(object sender, EventArgs e)
{
Window window = new()
{
Title = "Login"
};
var content = new LoginRegisterWindow(CommunicationManager, Messenger);
window.Content = content;
window.ShowModal(Desktop);
}
private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled) return;
var serverMap = await CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
CommunicationManager.SessionData.Overlays = serverMap.Overlays;
CommunicationManager.SessionData.Map = serverMap.Map;
CommunicationManager.SessionData.Walls = serverMap.Walls;
CommunicationManager.SessionData.Notes = serverMap.Notes;
CommunicationManager.SessionData.Lines = serverMap.Lines;
CommunicationManager.SessionData.Rooms = serverMap.Rooms;
}
private async void OnMenuConnectUploadSelected(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled) return;
await CommunicationManager.Api.SaveSnapshot(CommunicationManager.SessionData, State.Instance.MapId);
}
private void OnMenuFileLoadSelected(object sender, EventArgs e)
{
var dialog = new FileDialog(FileDialogMode.OpenFile)
{
Filter = "*.map"
};
dialog.Closed += (s, a) =>
{
if (!dialog.Result) return;
using var file = File.OpenText(dialog.FilePath);
JsonSerializer serializer = new();
var loadData = (Session)serializer.Deserialize(file, typeof(Session));
CommunicationManager.SessionData.Map = loadData.Map;
CommunicationManager.SessionData.Overlays = loadData.Overlays;
CommunicationManager.SessionData.Walls = loadData.Walls;
CommunicationManager.SessionData.Rooms = loadData.Rooms;
CommunicationManager.SessionData.Lines = loadData.Lines;
};
dialog.ShowModal(Desktop);
}
private void OnMenuFileSaveSelected(object sender, EventArgs e)
{
FileDialog dialog = new(FileDialogMode.SaveFile)
{
Filter = "*.map"
};
dialog.Closed += (s, a) =>
{
if (!dialog.Result) return;
using var file = File.CreateText(dialog.FilePath);
JsonSerializer serializer = new();
serializer.Serialize(file, CommunicationManager.SessionData);
};
dialog.ShowModal(Desktop);
}
private void OnMenuMapNew(object sender, EventArgs e)
{
if (sender is MenuItem && !((MenuItem)sender).Enabled)
{
return;
}
if (sender is MenuItem && !((MenuItem)sender).Enabled) return;
new MapWindow(CommunicationManager, Messenger).ShowInModalWindow(Desktop, "New map");
}
//TODO Refactor
private void EditNote(Note note)
private async void OnMenuMapOpen(object sender, EventArgs e)
{
State.Instance.SelectedNote = new Note { X = note.X, Y = note.Y, Text = note.Text };
new NoteWindow(CommunicationManager, note).ShowInModalWindow(Desktop, $" Note on {note.X}:{note.Y}");
if (!((MenuItem)sender).Enabled) return;
var content = new MapList(CommunicationManager, Messenger);
await content.LoadMaps();
content.ShowInModalWindow(Desktop, "Maps");
}
private void OnMenuViewCenterOnSelectionSelected(object sender, EventArgs e)
{
CenterOnSelectedTile();
}
private void OnMenuViewNotesSelected(object sender, EventArgs e)
{
Window window = new()
{
Title = "Notes"
};
new NoteList(CommunicationManager, Messenger).ShowInModalWindow(Desktop, "Notes");
}
private void OnMenuViewShowCellNUmbersSelected(object sender, EventArgs e)
{
State.Instance.ShowCellNumbers = !State.Instance.ShowCellNumbers;
}
private async void OnSignalrConnectionUpdateMessage(SignalrConnectionUpdateMessage obj)
{
lblConnectionStatus.Text = "Connecting";
await CommunicationManager.Connection.StartAsync();
UpdateConnectionState(CommunicationManager.Connection);
}
private void UpdateConnectionState(HubConnection connection)
{
switch (connection.State)
{
case HubConnectionState.Connected:
lblConnectionStatus.Text = "Connected";
break;
case HubConnectionState.Connecting:
lblConnectionStatus.Text = "Connecting";
break;
case HubConnectionState.Disconnected:
lblConnectionStatus.Text = "Disconnected";
break;
case HubConnectionState.Reconnecting:
lblConnectionStatus.Text = "Reconnecting";
break;
}
}
}
}