This commit is contained in:
parent
f4c2ad79f2
commit
34863a9984
8 changed files with 207 additions and 333 deletions
|
@ -3,6 +3,8 @@ using System.IO;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Myra.Graphics2D.UI;
|
||||||
|
using Myra.Graphics2D.Brushes;
|
||||||
|
|
||||||
namespace Sledgemapper
|
namespace Sledgemapper
|
||||||
{
|
{
|
||||||
|
@ -30,6 +32,35 @@ namespace Sledgemapper
|
||||||
{
|
{
|
||||||
return new Point(System.Math.Abs(point.X), System.Math.Abs(point.Y));
|
return new Point(System.Math.Abs(point.X), System.Math.Abs(point.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static (Window Window, C Content) GetParentContentInWindow<C>(this Widget widget) where C : Widget
|
||||||
|
{
|
||||||
|
Container container = widget.Parent;
|
||||||
|
while (!(container is Window))
|
||||||
|
{
|
||||||
|
container = container.Parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
var localWindow = (Window)container;
|
||||||
|
var localContent = localWindow.Content as C;
|
||||||
|
return (localWindow, localContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ValidateTextbox(this TextBox textBox)
|
||||||
|
{
|
||||||
|
var valid = !string.IsNullOrWhiteSpace(textBox.Text);
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
textBox.Background = new SolidBrush(Color.Red);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textBox.Background = new SolidBrush(new Color(51, 51, 51)); ;
|
||||||
|
}
|
||||||
|
return valid;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
16
Sledgemapper/Messages/LoginSuccessfulMessage.cs
Normal file
16
Sledgemapper/Messages/LoginSuccessfulMessage.cs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
public class LoginSuccesfulMessage : TinyMessenger.TinyMessageBase
|
||||||
|
{
|
||||||
|
public LoginSuccesfulMessage(object sender) : base(sender)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string UserName { get; internal set; }
|
||||||
|
public string Initials { get; internal set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MapOpenedMessage : TinyMessenger.TinyMessageBase
|
||||||
|
{
|
||||||
|
public MapOpenedMessage(object sender) : base(sender)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
10
Sledgemapper/Messages/SignalrConnectionUpdateMessage.cs
Normal file
10
Sledgemapper/Messages/SignalrConnectionUpdateMessage.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
public class SignalrConnectionUpdateMessage: TinyMessenger.TinyMessageBase
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public SignalrConnectionUpdateMessage(object sender) : base(sender)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsyncAwaitBestPractices;
|
using AsyncAwaitBestPractices;
|
||||||
|
using TinyMessenger;
|
||||||
|
|
||||||
namespace Sledgemapper
|
namespace Sledgemapper
|
||||||
{
|
{
|
||||||
|
@ -46,6 +47,7 @@ namespace Sledgemapper
|
||||||
private RenderTarget2D rendertarget;
|
private RenderTarget2D rendertarget;
|
||||||
private MainWidget _mainWidget;
|
private MainWidget _mainWidget;
|
||||||
private readonly Settings _settings;
|
private readonly Settings _settings;
|
||||||
|
private readonly TinyMessengerHub _messenger;
|
||||||
|
|
||||||
public Sledgemapper()
|
public Sledgemapper()
|
||||||
{
|
{
|
||||||
|
@ -69,6 +71,7 @@ namespace Sledgemapper
|
||||||
_state = new State();
|
_state = new State();
|
||||||
_settings = new Settings();
|
_settings = new Settings();
|
||||||
_vector2Pool = ArrayPool<Vector2>.Create();
|
_vector2Pool = ArrayPool<Vector2>.Create();
|
||||||
|
_messenger = new TinyMessengerHub();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnHubDisconnected(Exception arg)
|
private async Task OnHubDisconnected(Exception arg)
|
||||||
|
@ -97,7 +100,6 @@ namespace Sledgemapper
|
||||||
IsMouseVisible = true;
|
IsMouseVisible = true;
|
||||||
Window.AllowUserResizing = true;
|
Window.AllowUserResizing = true;
|
||||||
Window.ClientSizeChanged += OnClientSizeChanged;
|
Window.ClientSizeChanged += OnClientSizeChanged;
|
||||||
|
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +198,8 @@ namespace Sledgemapper
|
||||||
MyraEnvironment.Game = this;
|
MyraEnvironment.Game = this;
|
||||||
ResetRenderTarget();
|
ResetRenderTarget();
|
||||||
|
|
||||||
_mainWidget = new MainWidget(_communicationManager, _state, _settings, _cachedContent, Window);
|
|
||||||
|
_mainWidget = new MainWidget(_communicationManager, _state, _settings, _cachedContent, _messenger, Window);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,12 @@
|
||||||
<PackageReference Include="polly" Version="7.2.2" />
|
<PackageReference Include="polly" Version="7.2.2" />
|
||||||
<PackageReference Include="polly.extensions.http" Version="3.0.0" />
|
<PackageReference Include="polly.extensions.http" Version="3.0.0" />
|
||||||
<PackageReference Include="Refit.HttpClientFactory" Version="6.0.94" />
|
<PackageReference Include="Refit.HttpClientFactory" Version="6.0.94" />
|
||||||
|
<PackageReference Include="TinyMessenger" Version="1.4.0-alpha3">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
|
||||||
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Content\**\*.xnb">
|
<Content Include="Content\**\*.xnb">
|
||||||
|
|
|
@ -6,6 +6,7 @@ using Microsoft.Xna.Framework;
|
||||||
using Myra.Graphics2D.Brushes;
|
using Myra.Graphics2D.Brushes;
|
||||||
using Myra.Graphics2D.UI;
|
using Myra.Graphics2D.UI;
|
||||||
using Sledgemapper.Shared.Entities;
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using TinyMessenger;
|
||||||
|
|
||||||
namespace Sledgemapper.UI
|
namespace Sledgemapper.UI
|
||||||
{
|
{
|
||||||
|
@ -13,15 +14,16 @@ namespace Sledgemapper.UI
|
||||||
{
|
{
|
||||||
private AuthenticateResponse _authResponse;
|
private AuthenticateResponse _authResponse;
|
||||||
private readonly CommunicationManager CommunicationManager;
|
private readonly CommunicationManager CommunicationManager;
|
||||||
private readonly MainWidget MainWidget;
|
|
||||||
private readonly Window Window;
|
private readonly Window Window;
|
||||||
|
private readonly TinyMessengerHub _messenger;
|
||||||
|
|
||||||
public LoginRegisterWindow(CommunicationManager communicationManager, MainWidget mainWidget, Window window)
|
public LoginRegisterWindow(CommunicationManager communicationManager, Window window, TinyMessengerHub messenger)
|
||||||
{
|
{
|
||||||
BuildUI();
|
BuildUI();
|
||||||
MainWidget=mainWidget;
|
|
||||||
CommunicationManager=communicationManager;
|
CommunicationManager=communicationManager;
|
||||||
Window=window;
|
Window=window;
|
||||||
|
_messenger=messenger;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
TxtEmail.Text = "michele.scandura@outlook.com";
|
TxtEmail.Text = "michele.scandura@outlook.com";
|
||||||
TxtPassword.Text = "slePharland!79";
|
TxtPassword.Text = "slePharland!79";
|
||||||
|
@ -60,21 +62,7 @@ namespace Sledgemapper.UI
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO refactor
|
|
||||||
private bool ValidateTextbox(TextBox textBox)
|
|
||||||
{
|
|
||||||
var valid = !string.IsNullOrWhiteSpace(textBox.Text);
|
|
||||||
if (!valid)
|
|
||||||
{
|
|
||||||
textBox.Background = new SolidBrush(Color.Red);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
textBox.Background = new SolidBrush(new Color(51, 51, 51)); ;
|
|
||||||
}
|
|
||||||
return valid;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void OnButtonRegisterClick(object sender, EventArgs e)
|
private async void OnButtonRegisterClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -88,11 +76,11 @@ namespace Sledgemapper.UI
|
||||||
}
|
}
|
||||||
|
|
||||||
var isValid = true;
|
var isValid = true;
|
||||||
isValid &= ValidateTextbox(TxtEmail);
|
isValid &= TxtEmail.ValidateTextbox();
|
||||||
isValid &= ValidateTextbox(TxtPassword);
|
isValid &= TxtPassword.ValidateTextbox();
|
||||||
isValid &= ValidateTextbox(TxtFirstname);
|
isValid &= TxtFirstname.ValidateTextbox();
|
||||||
isValid &= ValidateTextbox(TxtLastname);
|
isValid &= TxtLastname.ValidateTextbox();
|
||||||
isValid &= ValidateTextbox(TxtInitials);
|
isValid &= TxtInitials.ValidateTextbox();
|
||||||
|
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
|
@ -152,11 +140,7 @@ namespace Sledgemapper.UI
|
||||||
}
|
}
|
||||||
if (successful)
|
if (successful)
|
||||||
{
|
{
|
||||||
MainWidget.MenuConnectNew.Enabled = true;
|
_messenger.Publish(new LoginSuccesfulMessage(this){UserName=_authResponse.Username, Initials=_authResponse.Initials});
|
||||||
MainWidget.MenuConnectJoin.Enabled = true;
|
|
||||||
|
|
||||||
MainWidget.lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
|
||||||
|
|
||||||
localContent.Window.Close();
|
localContent.Window.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,8 +163,8 @@ namespace Sledgemapper.UI
|
||||||
}
|
}
|
||||||
|
|
||||||
var isValid = true;
|
var isValid = true;
|
||||||
isValid &= ValidateTextbox(localContent.TxtEmail);
|
isValid &= localContent.TxtEmail.ValidateTextbox();
|
||||||
isValid &= ValidateTextbox(localContent.TxtPassword);
|
isValid &= localContent.TxtPassword.ValidateTextbox();
|
||||||
|
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
|
@ -225,9 +209,7 @@ namespace Sledgemapper.UI
|
||||||
|
|
||||||
if (successful)
|
if (successful)
|
||||||
{
|
{
|
||||||
MainWidget.MenuConnectNew.Enabled = true;
|
_messenger.Publish(new LoginSuccesfulMessage(this){UserName=_authResponse.Username, Initials=_authResponse.Initials});
|
||||||
MainWidget.MenuConnectJoin.Enabled = true;
|
|
||||||
MainWidget.lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
|
||||||
localWindow.Close();
|
localWindow.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using TinyMessenger;
|
||||||
|
|
||||||
namespace Sledgemapper.UI
|
namespace Sledgemapper.UI
|
||||||
{
|
{
|
||||||
|
@ -23,10 +24,12 @@ namespace Sledgemapper.UI
|
||||||
private readonly CommunicationManager CommunicationManager;
|
private readonly CommunicationManager CommunicationManager;
|
||||||
private State _state;
|
private State _state;
|
||||||
private Settings _settings;
|
private Settings _settings;
|
||||||
private GameWindow _window;
|
private readonly TinyMessengerHub _messenger;
|
||||||
|
|
||||||
private readonly CachedContent _cachedContent;
|
private readonly CachedContent _cachedContent;
|
||||||
public MainWidget(CommunicationManager communicationManager, State state, Settings settings, CachedContent cachedContent, GameWindow window)
|
private readonly GameWindow Window;
|
||||||
|
|
||||||
|
public MainWidget(CommunicationManager communicationManager, State state, Settings settings, CachedContent cachedContent, TinyMessengerHub messenger, GameWindow window)
|
||||||
{
|
{
|
||||||
BuildUI();
|
BuildUI();
|
||||||
|
|
||||||
|
@ -34,7 +37,8 @@ namespace Sledgemapper.UI
|
||||||
_state = state;
|
_state = state;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
_cachedContent = cachedContent;
|
_cachedContent = cachedContent;
|
||||||
_window = window;
|
|
||||||
|
_messenger=messenger;
|
||||||
MenuConnectLogin.Selected += OnMenuConnectLoginSelected;
|
MenuConnectLogin.Selected += OnMenuConnectLoginSelected;
|
||||||
MenuConnectSync.Selected += OnMenuConnectSyncSelected;
|
MenuConnectSync.Selected += OnMenuConnectSyncSelected;
|
||||||
MenuFileLoad.Selected += OnMenuFileLoadSelected;
|
MenuFileLoad.Selected += OnMenuFileLoadSelected;
|
||||||
|
@ -62,9 +66,36 @@ namespace Sledgemapper.UI
|
||||||
BtnToolbarLine.Click += OnBtnToolbarLinClicked;
|
BtnToolbarLine.Click += OnBtnToolbarLinClicked;
|
||||||
BtnToolbarRoom.Click += OnBtnToolbarRoomClicked;
|
BtnToolbarRoom.Click += OnBtnToolbarRoomClicked;
|
||||||
BtnToolbarDelete.Click += OnBtnToolbarDeleteClicked;
|
BtnToolbarDelete.Click += OnBtnToolbarDeleteClicked;
|
||||||
|
_messenger.Subscribe<LoginSuccesfulMessage>(OnLoginSuccesfulMessage);
|
||||||
|
_messenger.Subscribe<SignalrConnectionUpdateMessage>(OnSignalrConnectionUpdateMessage);
|
||||||
|
_messenger.Subscribe<MapOpenedMessage>(OnMapOpenedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnMapOpenedMessage(MapOpenedMessage obj)
|
||||||
|
{
|
||||||
|
lblSessionName.Text = CommunicationManager.SessionData.SessionName;
|
||||||
|
MenuConnectSync.Enabled = true;
|
||||||
|
MenuConnectUpload.Enabled = true;
|
||||||
|
CommunicationManager.SessionData.MapEntityAdded -= OnMapEntityAdded;
|
||||||
|
CommunicationManager.SessionData.MapEntityDeleted -= OnMapEntityDeleted;
|
||||||
|
CommunicationManager.SessionData.MapEntityAdded += OnMapEntityAdded;
|
||||||
|
CommunicationManager.SessionData.MapEntityDeleted += OnMapEntityDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
||||||
|
}
|
||||||
|
|
||||||
public void ClearSelection()
|
public void ClearSelection()
|
||||||
{
|
{
|
||||||
|
@ -96,204 +127,11 @@ namespace Sledgemapper.UI
|
||||||
Title = "Login"
|
Title = "Login"
|
||||||
};
|
};
|
||||||
|
|
||||||
var content = new LoginRegisterWindow(CommunicationManager, this, window);
|
var content = new LoginRegisterWindow(CommunicationManager, window,_messenger);
|
||||||
|
|
||||||
// #if DEBUG
|
|
||||||
// content.TxtEmail.Text = "michele.scandura@outlook.com";
|
|
||||||
// content.TxtPassword.Text = "slePharland!79";
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// content.RdoLogin.IsPressed = true;
|
|
||||||
// content.RdoLogin.Click += (s, e) =>
|
|
||||||
// {
|
|
||||||
// content.TxtFirstname.Visible = false;
|
|
||||||
// content.TxtLastname.Visible = false;
|
|
||||||
// content.TxtInitials.Visible = false;
|
|
||||||
// content.LblFirstname.Visible = false;
|
|
||||||
// content.LblLastname.Visible = false;
|
|
||||||
// content.LblInitials.Visible = false;
|
|
||||||
// content.BtnLogin.Visible = true;
|
|
||||||
// content.BtnRegister.Visible = false;
|
|
||||||
// window.Title = "Login";
|
|
||||||
// };
|
|
||||||
|
|
||||||
// content.RdoRegister.Click += (s, e) =>
|
|
||||||
// {
|
|
||||||
// content.TxtFirstname.Visible = true;
|
|
||||||
// content.TxtLastname.Visible = true;
|
|
||||||
// content.TxtInitials.Visible = true;
|
|
||||||
// content.LblFirstname.Visible = true;
|
|
||||||
// content.LblLastname.Visible = true;
|
|
||||||
// content.LblInitials.Visible = true;
|
|
||||||
// content.BtnLogin.Visible = false;
|
|
||||||
// content.BtnRegister.Visible = true;
|
|
||||||
// window.Title = "Register";
|
|
||||||
// };
|
|
||||||
|
|
||||||
// content.BtnRegister.Click += OnButtonRegisterClick;
|
|
||||||
// content.BtnLogin.Click += OnButtonLoginClick;
|
|
||||||
// content.TxtEmail.SetKeyboardFocus();
|
|
||||||
|
|
||||||
window.Content = content;
|
window.Content = content;
|
||||||
window.ShowModal(Desktop);
|
window.ShowModal(Desktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
// private async void OnButtonRegisterClick(object sender, EventArgs e)
|
|
||||||
// {
|
|
||||||
// var button = ((TextButton)sender);
|
|
||||||
|
|
||||||
// var localContent = GetParentContentInWindow<LoginRegisterWindow>(button);// localWindow.Content as PlayerWindow;
|
|
||||||
|
|
||||||
// if (!button.Enabled)
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var isValid = true;
|
|
||||||
// isValid &= ValidateTextbox(localContent.Content.TxtEmail);
|
|
||||||
// isValid &= ValidateTextbox(localContent.Content.TxtPassword);
|
|
||||||
// isValid &= ValidateTextbox(localContent.Content.TxtFirstname);
|
|
||||||
// isValid &= ValidateTextbox(localContent.Content.TxtLastname);
|
|
||||||
// isValid &= ValidateTextbox(localContent.Content.TxtInitials);
|
|
||||||
|
|
||||||
// if (!isValid)
|
|
||||||
// {
|
|
||||||
// localContent.Content.LblLoginError.Text = "Please complete all the fields";
|
|
||||||
// localContent.Content.LblLoginError.Visible = true;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var successful = false;
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// button.Text = "Wait...";
|
|
||||||
// localContent.Content.LblLoginError.Text = "";
|
|
||||||
// localContent.Content.LblLoginError.Visible = false;
|
|
||||||
|
|
||||||
// var result = await CommunicationManager.Register(new RegisterModel
|
|
||||||
// {
|
|
||||||
// Username = localContent.Content.TxtEmail.Text,
|
|
||||||
// Email = localContent.Content.TxtEmail.Text,
|
|
||||||
// Password = localContent.Content.TxtPassword.Text,
|
|
||||||
// FirstName = localContent.Content.TxtFirstname.Text,
|
|
||||||
// LastName = localContent.Content.TxtLastname.Text,
|
|
||||||
// Initials = localContent.Content.TxtInitials.Text
|
|
||||||
// });
|
|
||||||
// if (result.Result)
|
|
||||||
// {
|
|
||||||
// _authResponse = await CommunicationManager.Login(new AuthenticateModel
|
|
||||||
// {
|
|
||||||
// Username = localContent.Content.TxtEmail.Text,
|
|
||||||
// Password = localContent.Content.TxtPassword.Text
|
|
||||||
// });
|
|
||||||
// successful = true;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// localContent.Content.LblLoginError.Text = result.Errors.FirstOrDefault();
|
|
||||||
// localContent.Content.LblLoginError.Visible = true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch (Refit.ApiException refitException)
|
|
||||||
// {
|
|
||||||
// ExceptionlessClient.Default.SubmitException(refitException);
|
|
||||||
// localContent.Content.LblLoginError.Text = refitException.Content;
|
|
||||||
// localContent.Content.LblLoginError.Visible = true;
|
|
||||||
// }
|
|
||||||
// catch (Exception ex)
|
|
||||||
// {
|
|
||||||
// ExceptionlessClient.Default.SubmitException(ex);
|
|
||||||
// localContent.Content.LblLoginError.Text = "Can't connect to the server";
|
|
||||||
// localContent.Content.LblLoginError.Visible = true;
|
|
||||||
// Debug.Write(ex);
|
|
||||||
// }
|
|
||||||
// finally
|
|
||||||
// {
|
|
||||||
// button.Enabled = true;
|
|
||||||
// button.Text = "Register";
|
|
||||||
// }
|
|
||||||
// if (successful)
|
|
||||||
// {
|
|
||||||
// MenuConnectNew.Enabled = true;
|
|
||||||
// MenuConnectJoin.Enabled = true;
|
|
||||||
|
|
||||||
// lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
|
||||||
|
|
||||||
// localContent.Window.Close();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private async void OnButtonLoginClick(object sender, EventArgs e)
|
|
||||||
// {
|
|
||||||
// var button = ((TextButton)sender);
|
|
||||||
// Container container = button.Parent;
|
|
||||||
// while (!(container is Window))
|
|
||||||
// {
|
|
||||||
// container = container.Parent;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var localWindow = (Window)container;
|
|
||||||
// var localContent = localWindow.Content as LoginRegisterWindow;
|
|
||||||
|
|
||||||
// if (!button.Enabled)
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var isValid = true;
|
|
||||||
// isValid &= ValidateTextbox(localContent.TxtEmail);
|
|
||||||
// isValid &= ValidateTextbox(localContent.TxtPassword);
|
|
||||||
|
|
||||||
// if (!isValid)
|
|
||||||
// {
|
|
||||||
// localContent.LblLoginError.Text = "Username or password is not valid";
|
|
||||||
// localContent.LblLoginError.Visible = true;
|
|
||||||
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var successful = false;
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// button.Text = "Wait...";
|
|
||||||
// localContent.LblLoginError.Text = "";
|
|
||||||
// localContent.LblLoginError.Visible = false;
|
|
||||||
// _authResponse = await CommunicationManager.Login(new AuthenticateModel
|
|
||||||
// {
|
|
||||||
// Username = localContent.TxtEmail.Text,
|
|
||||||
// Email = localContent.TxtEmail.Text,
|
|
||||||
// Password = localContent.TxtPassword.Text
|
|
||||||
// });
|
|
||||||
// successful = _authResponse != null;
|
|
||||||
// }
|
|
||||||
// catch (Refit.ApiException refitException)
|
|
||||||
// {
|
|
||||||
// ExceptionlessClient.Default.SubmitException(refitException);
|
|
||||||
// localContent.LblLoginError.Text = refitException.Content;
|
|
||||||
// localContent.LblLoginError.Visible = true;
|
|
||||||
// }
|
|
||||||
// catch (Exception ex)
|
|
||||||
// {
|
|
||||||
// ExceptionlessClient.Default.SubmitException(ex);
|
|
||||||
// localContent.LblLoginError.Text = "Can't connect to the server";
|
|
||||||
// localContent.LblLoginError.Visible = true;
|
|
||||||
// Debug.Write(ex);
|
|
||||||
// }
|
|
||||||
// finally
|
|
||||||
// {
|
|
||||||
// button.Enabled = true;
|
|
||||||
// button.Text = "Login";
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (successful)
|
|
||||||
// {
|
|
||||||
// MenuConnectNew.Enabled = true;
|
|
||||||
// MenuConnectJoin.Enabled = true;
|
|
||||||
// lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
|
||||||
// localWindow.Close();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
private void OnMenuConnectNewSelected(object sender, EventArgs e)
|
private void OnMenuConnectNewSelected(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -307,96 +145,10 @@ namespace Sledgemapper.UI
|
||||||
Title = "New mapping session"
|
Title = "New mapping session"
|
||||||
};
|
};
|
||||||
|
|
||||||
var content = new SessionWindow();
|
var content = new SessionWindow(CommunicationManager,_messenger,window, _state);
|
||||||
content.BtnLogin.Text = "Join";
|
|
||||||
content.BtnLogin.Click += OnButtonNewSessionClicked;
|
|
||||||
window.Content = content;
|
window.Content = content;
|
||||||
|
|
||||||
window.ShowModal(Desktop);
|
window.ShowModal(Desktop);
|
||||||
content.TxtSession.SetKeyboardFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void OnButtonNewSessionClicked(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var localContent = GetParentContentInWindow<SessionWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
|
|
||||||
|
|
||||||
var isValid = ValidateTextbox(localContent.Content.TxtSession);
|
|
||||||
if (!isValid)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CommunicationManager.Connection.State != HubConnectionState.Connected)
|
|
||||||
{
|
|
||||||
lblConnectionStatus.Text = "Connecting";
|
|
||||||
await CommunicationManager.Connection.StartAsync();
|
|
||||||
UpdateConnectionState(CommunicationManager.Connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
var successful = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var result = await CommunicationManager.Api.NewSession(_state.CampaignName, localContent.Content.TxtSession.Text);
|
|
||||||
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
CommunicationManager.SessionData.SessionName = localContent.Content.TxtSession.Text;
|
|
||||||
CommunicationManager.SessionData.MapEntityAdded -= OnMapEntityAdded;
|
|
||||||
CommunicationManager.SessionData.MapEntityDeleted -= OnMapEntityDeleted;
|
|
||||||
CommunicationManager.SessionData.MapEntityAdded += OnMapEntityAdded;
|
|
||||||
CommunicationManager.SessionData.MapEntityDeleted += OnMapEntityDeleted;
|
|
||||||
}
|
|
||||||
successful = result;
|
|
||||||
var result2 = await CommunicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.Content.TxtSession.Text);
|
|
||||||
CommunicationManager.SessionData.SessionId = result2.SessionId;
|
|
||||||
CommunicationManager.SessionData.SessionName = localContent.Content.TxtSession.Text;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
ExceptionlessClient.Default.SubmitException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (successful)
|
|
||||||
{
|
|
||||||
CommunicationManager.SessionData.SessionName = localContent.Content.TxtSession.Text;
|
|
||||||
CommunicationManager.SessionData.Map = CommunicationManager.SessionData.Map;
|
|
||||||
CommunicationManager.SessionData.Overlays = CommunicationManager.SessionData.Overlays;
|
|
||||||
CommunicationManager.SessionData.Walls = CommunicationManager.SessionData.Walls;
|
|
||||||
lblSessionName.Text = CommunicationManager.SessionData.SessionName;
|
|
||||||
MenuConnectSync.Enabled = true;
|
|
||||||
MenuConnectUpload.Enabled = true;
|
|
||||||
localContent.Window.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO refactor
|
|
||||||
private bool ValidateTextbox(TextBox textBox)
|
|
||||||
{
|
|
||||||
var valid = !string.IsNullOrWhiteSpace(textBox.Text);
|
|
||||||
if (!valid)
|
|
||||||
{
|
|
||||||
textBox.Background = new SolidBrush(Color.Red);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
textBox.Background = new SolidBrush(new Color(51, 51, 51)); ;
|
|
||||||
}
|
|
||||||
return valid;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO Refactor
|
|
||||||
private (Window Window, C Content) GetParentContentInWindow<C>(Widget widget) where C : Widget
|
|
||||||
{
|
|
||||||
Container container = widget.Parent;
|
|
||||||
while (!(container is Window))
|
|
||||||
{
|
|
||||||
container = container.Parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
var localWindow = (Window)container;
|
|
||||||
var localContent = localWindow.Content as C;
|
|
||||||
return (localWindow, localContent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateConnectionState(HubConnection connection)
|
private void UpdateConnectionState(HubConnection connection)
|
||||||
|
@ -585,7 +337,7 @@ namespace Sledgemapper.UI
|
||||||
private void CenterOnTile(int x, int y)
|
private void CenterOnTile(int x, int y)
|
||||||
{
|
{
|
||||||
|
|
||||||
var center = new Point((_window.ClientBounds.Width + 200) / 2 - _state.TileSize / 2, _window.ClientBounds.Height / 2 - _state.TileSize / 2);
|
var center = new Point((Window.ClientBounds.Width + 200) / 2 - _state.TileSize / 2, Window.ClientBounds.Height / 2 - _state.TileSize / 2);
|
||||||
var dx = center.X - x * _state.TileSize - _state.ViewportCenter.X;
|
var dx = center.X - x * _state.TileSize - _state.ViewportCenter.X;
|
||||||
var dy = center.Y - y * _state.TileSize - _state.ViewportCenter.Y;
|
var dy = center.Y - y * _state.TileSize - _state.ViewportCenter.Y;
|
||||||
_state.ViewportCenter = new Vector3(_state.ViewportCenter.X + dx, _state.ViewportCenter.Y + dy, _state.ViewportCenter.Z);
|
_state.ViewportCenter = new Vector3(_state.ViewportCenter.X + dx, _state.ViewportCenter.Y + dy, _state.ViewportCenter.Z);
|
||||||
|
@ -672,7 +424,7 @@ namespace Sledgemapper.UI
|
||||||
private void OnCampaignSelected(object sender, EventArgs e)
|
private void OnCampaignSelected(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var item = sender as UI.ListItem;
|
var item = sender as UI.ListItem;
|
||||||
var localContent = GetParentContentInWindow<Widget>(item);
|
var localContent = item.GetParentContentInWindow<Widget>();
|
||||||
_state.CampaignName = item.ItemName.Text;
|
_state.CampaignName = item.ItemName.Text;
|
||||||
var list = item.Parent as Myra.Graphics2D.UI.Grid;
|
var list = item.Parent as Myra.Graphics2D.UI.Grid;
|
||||||
for (var i = 0; i < list.ChildrenCount; i++)
|
for (var i = 0; i < list.ChildrenCount; i++)
|
||||||
|
@ -687,7 +439,7 @@ namespace Sledgemapper.UI
|
||||||
private void OnMapSelected(object sender, EventArgs e)
|
private void OnMapSelected(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var item = sender as UI.ListItem;
|
var item = sender as UI.ListItem;
|
||||||
var localContent = GetParentContentInWindow<Widget>(item);
|
var localContent = item.GetParentContentInWindow<Widget>();
|
||||||
|
|
||||||
var list = item.Parent as Myra.Graphics2D.UI.Grid;
|
var list = item.Parent as Myra.Graphics2D.UI.Grid;
|
||||||
for (var i = 0; i < list.ChildrenCount; i++)
|
for (var i = 0; i < list.ChildrenCount; i++)
|
||||||
|
@ -790,9 +542,9 @@ namespace Sledgemapper.UI
|
||||||
|
|
||||||
private async void OnButtonJoinSessionClicked(object sender, EventArgs e)
|
private async void OnButtonJoinSessionClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var localContent = GetParentContentInWindow<SessionWindow>(((TextButton)sender));
|
var localContent = ((TextButton)sender).GetParentContentInWindow<SessionWindow>();
|
||||||
|
|
||||||
var isValid = ValidateTextbox(localContent.Content.TxtSession);
|
var isValid = localContent.Content.TxtSession.ValidateTextbox();
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -841,8 +593,8 @@ namespace Sledgemapper.UI
|
||||||
|
|
||||||
private async void OnButtonInvitePlayerClicked(object sender, EventArgs e)
|
private async void OnButtonInvitePlayerClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var localContent = GetParentContentInWindow<PlayerWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
|
var localContent = ((TextButton)sender).GetParentContentInWindow<PlayerWindow>();// localWindow.Content as PlayerWindow;
|
||||||
var isValid = ValidateTextbox(localContent.Content.TxtCampaign);
|
var isValid = localContent.Content.TxtCampaign.ValidateTextbox();
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -896,9 +648,9 @@ namespace Sledgemapper.UI
|
||||||
|
|
||||||
private async void OnButtonNewCampaignClicked(object sender, EventArgs e)
|
private async void OnButtonNewCampaignClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var localContent = GetParentContentInWindow<CampaignWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
|
var localContent = ((TextButton)sender).GetParentContentInWindow<CampaignWindow>();// localWindow.Content as PlayerWindow;
|
||||||
|
|
||||||
var isValid = ValidateTextbox(localContent.Content.TxtCampaign);
|
var isValid = localContent.Content.TxtCampaign.ValidateTextbox();
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -1005,7 +757,7 @@ namespace Sledgemapper.UI
|
||||||
}
|
}
|
||||||
var localWindow = (Window)container;
|
var localWindow = (Window)container;
|
||||||
var localContent = localWindow.Content as MapWindow;
|
var localContent = localWindow.Content as MapWindow;
|
||||||
var isValid = ValidateTextbox(localContent.TxtCampaign);
|
var isValid = localContent.TxtCampaign.ValidateTextbox();
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -1078,7 +830,7 @@ namespace Sledgemapper.UI
|
||||||
private void OnButtonNoteOkClick(object sender, EventArgs e)
|
private void OnButtonNoteOkClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var button = ((TextButton)sender);
|
var button = ((TextButton)sender);
|
||||||
var localContent = GetParentContentInWindow<NoteWindow>(button);
|
var localContent = button.GetParentContentInWindow<NoteWindow>();
|
||||||
var note = new Note
|
var note = new Note
|
||||||
{
|
{
|
||||||
X = _state.SelectedNote.X,
|
X = _state.SelectedNote.X,
|
||||||
|
@ -1092,7 +844,7 @@ namespace Sledgemapper.UI
|
||||||
private void OnButtonNoteCancelClick(object sender, EventArgs e)
|
private void OnButtonNoteCancelClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var button = ((TextButton)sender);
|
var button = ((TextButton)sender);
|
||||||
var content = GetParentContentInWindow<Widget>(button);
|
var content = button.GetParentContentInWindow<Widget>();
|
||||||
content.Window.Close();
|
content.Window.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
75
Sledgemapper/UI/SessionWindow.Custom.cs
Normal file
75
Sledgemapper/UI/SessionWindow.Custom.cs
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/* Generated by MyraPad at 10/11/2020 10:59:36 */
|
||||||
|
using System;
|
||||||
|
using Exceptionless;
|
||||||
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
|
using Myra.Graphics2D.UI;
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using TinyMessenger;
|
||||||
|
|
||||||
|
namespace Sledgemapper.UI
|
||||||
|
{
|
||||||
|
public partial class SessionWindow
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly CommunicationManager CommunicationManager;
|
||||||
|
private readonly Window Window;
|
||||||
|
private readonly TinyMessengerHub Messenger;
|
||||||
|
private readonly State State;
|
||||||
|
|
||||||
|
public SessionWindow(CommunicationManager communicationManager, TinyMessengerHub messenger, Window window, State state)
|
||||||
|
{
|
||||||
|
BuildUI();
|
||||||
|
CommunicationManager=communicationManager;
|
||||||
|
Messenger=messenger;
|
||||||
|
State=state;
|
||||||
|
BtnLogin.Text = "Join";
|
||||||
|
BtnLogin.Click += OnButtonNewSessionClicked;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnButtonNewSessionClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var localContent = ((TextButton)sender).GetParentContentInWindow<SessionWindow>();// localWindow.Content as PlayerWindow;
|
||||||
|
|
||||||
|
var isValid = localContent.Content.TxtSession.ValidateTextbox();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CommunicationManager.Connection.State != HubConnectionState.Connected)
|
||||||
|
{
|
||||||
|
Messenger.Publish(new SignalrConnectionUpdateMessage(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
var successful = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await CommunicationManager.Api.NewSession(State.CampaignName, localContent.Content.TxtSession.Text);
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
CommunicationManager.SessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||||
|
|
||||||
|
}
|
||||||
|
successful = result;
|
||||||
|
var result2 = await CommunicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.Content.TxtSession.Text);
|
||||||
|
CommunicationManager.SessionData.SessionId = result2.SessionId;
|
||||||
|
CommunicationManager.SessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ExceptionlessClient.Default.SubmitException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (successful)
|
||||||
|
{
|
||||||
|
CommunicationManager.SessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||||
|
CommunicationManager.SessionData.Map = CommunicationManager.SessionData.Map;
|
||||||
|
CommunicationManager.SessionData.Overlays = CommunicationManager.SessionData.Overlays;
|
||||||
|
CommunicationManager.SessionData.Walls = CommunicationManager.SessionData.Walls;
|
||||||
|
|
||||||
|
localContent.Window.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue