moving ui code to mainwidget
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
dc7b2dd8f2
commit
ef2ad6965b
4 changed files with 631 additions and 293 deletions
|
@ -23,9 +23,13 @@ namespace Sledgemapper.Api.Controllers
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("{campaignName}")]
|
[Route("{campaignName}")]
|
||||||
public async Task<bool> Post(string campaignName)
|
public async Task<ActionResult<bool>> Post(string campaignName)
|
||||||
{
|
{
|
||||||
var result = await _mediator.Send(new NewCampaignCommand(campaignName, UserId.ToString()));
|
var result = await _mediator.Send(new NewCampaignCommand(campaignName, UserId.ToString()));
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace Sledgemapper.Api.Handlers
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -45,7 +45,6 @@ namespace Sledgemapper
|
||||||
private Texture2D _location;
|
private Texture2D _location;
|
||||||
private Texture2D _comment;
|
private Texture2D _comment;
|
||||||
private readonly Session _sessionData;
|
private readonly Session _sessionData;
|
||||||
private AuthenticateResponse _authResponse;
|
|
||||||
private RenderTarget2D rendertarget;
|
private RenderTarget2D rendertarget;
|
||||||
private MainWidget _mainWidget;
|
private MainWidget _mainWidget;
|
||||||
private bool _showCellNumbers;
|
private bool _showCellNumbers;
|
||||||
|
@ -198,13 +197,15 @@ namespace Sledgemapper
|
||||||
MyraEnvironment.Game = this;
|
MyraEnvironment.Game = this;
|
||||||
ResetRenderTarget();
|
ResetRenderTarget();
|
||||||
|
|
||||||
_mainWidget = new MainWidget();
|
_mainWidget = new MainWidget(_communicationManager);
|
||||||
|
|
||||||
|
//_mainWidget = new MainWidget();
|
||||||
|
|
||||||
_mainWidget.MenuConnectSync.Selected += OnMenuConnectSyncSelected;
|
_mainWidget.MenuConnectSync.Selected += OnMenuConnectSyncSelected;
|
||||||
_mainWidget.MenuFileLoad.Selected += OnMenuFileLoadSelected;
|
_mainWidget.MenuFileLoad.Selected += OnMenuFileLoadSelected;
|
||||||
_mainWidget.MenuFileSave.Selected += OnMenuFileSaveSelected;
|
_mainWidget.MenuFileSave.Selected += OnMenuFileSaveSelected;
|
||||||
_mainWidget.MenuFileSettings.Selected += OneMenuFileSettingsSelected;
|
_mainWidget.MenuFileSettings.Selected += OneMenuFileSettingsSelected;
|
||||||
_mainWidget.MenuConnectLogin.Selected += OnMenuConnectLoginSelected;
|
//_mainWidget.MenuConnectLogin.Selected += OnMenuConnectLoginSelected;
|
||||||
_mainWidget.MenuConnectNew.Selected += OnMenuConnectNewSelected;
|
_mainWidget.MenuConnectNew.Selected += OnMenuConnectNewSelected;
|
||||||
_mainWidget.MenuConnectJoin.Selected += OnMenuConnectJoinSelected;
|
_mainWidget.MenuConnectJoin.Selected += OnMenuConnectJoinSelected;
|
||||||
_mainWidget.MenuConnectUpload.Selected += OnMenuConnectUploadSelected;
|
_mainWidget.MenuConnectUpload.Selected += OnMenuConnectUploadSelected;
|
||||||
|
@ -218,7 +219,7 @@ namespace Sledgemapper
|
||||||
|
|
||||||
_mainWidget.MenuMapOpen.Selected += OnMenuMapOpen;
|
_mainWidget.MenuMapOpen.Selected += OnMenuMapOpen;
|
||||||
_mainWidget.MenuMapNew.Selected += OnMenuMapNew;
|
_mainWidget.MenuMapNew.Selected += OnMenuMapNew;
|
||||||
|
|
||||||
_mainWidget.MenuConnectNew.Enabled = false;
|
_mainWidget.MenuConnectNew.Enabled = false;
|
||||||
_mainWidget.MenuConnectJoin.Enabled = false;
|
_mainWidget.MenuConnectJoin.Enabled = false;
|
||||||
_mainWidget.MenuConnectSync.Enabled = false;
|
_mainWidget.MenuConnectSync.Enabled = false;
|
||||||
|
@ -283,7 +284,7 @@ namespace Sledgemapper
|
||||||
|
|
||||||
private async void OnButtonNewMapClicked(object sender, EventArgs e)
|
private async void OnButtonNewMapClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Container container = ((TextButton)sender).Parent;
|
Container container = ((TextButton)sender).Parent;
|
||||||
while (!(container is Window))
|
while (!(container is Window))
|
||||||
{
|
{
|
||||||
container = container.Parent;
|
container = container.Parent;
|
||||||
|
@ -357,10 +358,10 @@ namespace Sledgemapper
|
||||||
var campaigns = await _communicationManager.Api.GetMaps(_state.CampaignName);
|
var campaigns = await _communicationManager.Api.GetMaps(_state.CampaignName);
|
||||||
foreach (var campaign in campaigns)
|
foreach (var campaign in campaigns)
|
||||||
{
|
{
|
||||||
var item = new UI.ListItem();
|
var item = new UI.ListItem();
|
||||||
item.ItemName.Text = campaign.SessionName;
|
item.ItemName.Text = campaign.SessionName;
|
||||||
item.TouchUp += OnMapSelected;
|
item.TouchUp += OnMapSelected;
|
||||||
content.StackCampaignsList.AddChild(item);
|
content.StackCampaignsList.AddChild(item);
|
||||||
}
|
}
|
||||||
//content.BtnNewCampaign.Text = "N";
|
//content.BtnNewCampaign.Text = "N";
|
||||||
|
|
||||||
|
@ -369,7 +370,7 @@ namespace Sledgemapper
|
||||||
content.BtnNewCampaign.Click += (s, e) =>
|
content.BtnNewCampaign.Click += (s, e) =>
|
||||||
{
|
{
|
||||||
window.Close();
|
window.Close();
|
||||||
OnMenuCampaignNew(s, e);
|
OnMenuMapNew(s, e);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.Content = content;
|
window.Content = content;
|
||||||
|
@ -394,10 +395,10 @@ namespace Sledgemapper
|
||||||
var players = await _communicationManager.Api.GetPlayers(_state.CampaignName);
|
var players = await _communicationManager.Api.GetPlayers(_state.CampaignName);
|
||||||
foreach (var player in players)
|
foreach (var player in players)
|
||||||
{
|
{
|
||||||
var item = new UI.ListItem();
|
var item = new UI.ListItem();
|
||||||
item.ItemName.Text = player.UserName;
|
item.ItemName.Text = player.UserName;
|
||||||
|
|
||||||
|
|
||||||
content.StackCampaignsList.AddChild(item);
|
content.StackCampaignsList.AddChild(item);
|
||||||
}
|
}
|
||||||
//content.BtnNewCampaign.Text = "N";
|
//content.BtnNewCampaign.Text = "N";
|
||||||
|
@ -518,7 +519,7 @@ namespace Sledgemapper
|
||||||
{
|
{
|
||||||
var item = new UI.ListItem();
|
var item = new UI.ListItem();
|
||||||
item.ItemName.Text = campaign.Name;
|
item.ItemName.Text = campaign.Name;
|
||||||
|
|
||||||
item.TouchUp += OnCampaignSelected;
|
item.TouchUp += OnCampaignSelected;
|
||||||
content.StackCampaignsList.AddChild(item);
|
content.StackCampaignsList.AddChild(item);
|
||||||
}
|
}
|
||||||
|
@ -556,31 +557,31 @@ namespace Sledgemapper
|
||||||
private bool campaignSelected;
|
private bool campaignSelected;
|
||||||
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 = GetParentContentInWindow<Widget>(item);
|
||||||
_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++)
|
||||||
{
|
{
|
||||||
var currentItem = list.GetChild(i) as HorizontalStackPanel;// UI.ListItem;
|
var currentItem = list.GetChild(i) as HorizontalStackPanel;// UI.ListItem;
|
||||||
currentItem.Background= new SolidBrush("#D9D9D9FF");
|
currentItem.Background = new SolidBrush("#D9D9D9FF");
|
||||||
}
|
}
|
||||||
item.Background=new SolidBrush(_settings.OverlayTintColor);
|
item.Background = new SolidBrush(_settings.OverlayTintColor);
|
||||||
campaignSelected = true;
|
campaignSelected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = GetParentContentInWindow<Widget>(item);
|
||||||
|
|
||||||
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++)
|
||||||
{
|
{
|
||||||
var currentItem = list.GetChild(i) as HorizontalStackPanel;// UI.ListItem;
|
var currentItem = list.GetChild(i) as HorizontalStackPanel;// UI.ListItem;
|
||||||
currentItem.Background= new SolidBrush("#D9D9D9FF");
|
currentItem.Background = new SolidBrush("#D9D9D9FF");
|
||||||
}
|
}
|
||||||
item.Background=new SolidBrush(_settings.OverlayTintColor);
|
item.Background = new SolidBrush(_settings.OverlayTintColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OneMenuFileSettingsSelected(object sender, EventArgs e)
|
private void OneMenuFileSettingsSelected(object sender, EventArgs e)
|
||||||
|
@ -2134,7 +2135,7 @@ namespace Sledgemapper
|
||||||
private async void OnButtonJoinSessionClicked(object sender, EventArgs e)
|
private async void OnButtonJoinSessionClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var localContent = GetParentContentInWindow<SessionWindow>(((TextButton)sender));
|
var localContent = GetParentContentInWindow<SessionWindow>(((TextButton)sender));
|
||||||
|
|
||||||
var isValid = ValidateTextbox(localContent.Content.TxtSession);
|
var isValid = ValidateTextbox(localContent.Content.TxtSession);
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
|
@ -2184,7 +2185,7 @@ namespace Sledgemapper
|
||||||
|
|
||||||
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 = GetParentContentInWindow<PlayerWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
|
||||||
var isValid = ValidateTextbox(localContent.Content.TxtCampaign);
|
var isValid = ValidateTextbox(localContent.Content.TxtCampaign);
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
|
@ -2293,58 +2294,58 @@ namespace Sledgemapper
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnButtonNewSessionClicked(object sender, EventArgs e)
|
//private async void OnButtonNewSessionClicked(object sender, EventArgs e)
|
||||||
{
|
//{
|
||||||
var localContent = GetParentContentInWindow<SessionWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
|
// var localContent = GetParentContentInWindow<SessionWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
|
||||||
|
|
||||||
var isValid = ValidateTextbox(localContent.Content.TxtSession);
|
// var isValid = ValidateTextbox(localContent.Content.TxtSession);
|
||||||
if (!isValid)
|
// if (!isValid)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (_communicationManager.Connection.State != HubConnectionState.Connected)
|
// if (_communicationManager.Connection.State != HubConnectionState.Connected)
|
||||||
{
|
// {
|
||||||
_mainWidget.lblConnectionStatus.Text = "Connecting";
|
// _mainWidget.lblConnectionStatus.Text = "Connecting";
|
||||||
await _communicationManager.Connection.StartAsync();
|
// await _communicationManager.Connection.StartAsync();
|
||||||
UpdateConnectionState(_communicationManager.Connection);
|
// UpdateConnectionState(_communicationManager.Connection);
|
||||||
}
|
// }
|
||||||
|
|
||||||
var successful = false;
|
// var successful = false;
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
var result = await _communicationManager.Api.NewSession(_state.CampaignName, localContent.Content.TxtSession.Text);
|
// var result = await _communicationManager.Api.NewSession(_state.CampaignName, localContent.Content.TxtSession.Text);
|
||||||
|
|
||||||
if (result)
|
// if (result)
|
||||||
{
|
// {
|
||||||
_sessionData.SessionName = localContent.Content.TxtSession.Text;
|
// _sessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||||
_sessionData.MapEntityAdded -= OnMapEntityAdded;
|
// _sessionData.MapEntityAdded -= OnMapEntityAdded;
|
||||||
_sessionData.MapEntityDeleted -= OnMapEntityDeleted;
|
// _sessionData.MapEntityDeleted -= OnMapEntityDeleted;
|
||||||
_sessionData.MapEntityAdded += OnMapEntityAdded;
|
// _sessionData.MapEntityAdded += OnMapEntityAdded;
|
||||||
_sessionData.MapEntityDeleted += OnMapEntityDeleted;
|
// _sessionData.MapEntityDeleted += OnMapEntityDeleted;
|
||||||
}
|
// }
|
||||||
successful = result;
|
// successful = result;
|
||||||
var result2 = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.Content.TxtSession.Text);
|
// var result2 = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.Content.TxtSession.Text);
|
||||||
_sessionData.SessionId = result2.SessionId;
|
// _sessionData.SessionId = result2.SessionId;
|
||||||
_sessionData.SessionName = localContent.Content.TxtSession.Text;
|
// _sessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||||
}
|
// }
|
||||||
catch (Exception ex)
|
// catch (Exception ex)
|
||||||
{
|
// {
|
||||||
ExceptionlessClient.Default.SubmitException(ex);
|
// ExceptionlessClient.Default.SubmitException(ex);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (successful)
|
// if (successful)
|
||||||
{
|
// {
|
||||||
_sessionData.SessionName = localContent.Content.TxtSession.Text;
|
// _sessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||||
_communicationManager.SessionData.Map = _sessionData.Map;
|
// _communicationManager.SessionData.Map = _sessionData.Map;
|
||||||
_communicationManager.SessionData.Overlays = _sessionData.Overlays;
|
// _communicationManager.SessionData.Overlays = _sessionData.Overlays;
|
||||||
_communicationManager.SessionData.Walls = _sessionData.Walls;
|
// _communicationManager.SessionData.Walls = _sessionData.Walls;
|
||||||
_mainWidget.lblSessionName.Text = _sessionData.SessionName;
|
// _mainWidget.lblSessionName.Text = _sessionData.SessionName;
|
||||||
_mainWidget.MenuConnectSync.Enabled = true;
|
// _mainWidget.MenuConnectSync.Enabled = true;
|
||||||
_mainWidget.MenuConnectUpload.Enabled = true;
|
// _mainWidget.MenuConnectUpload.Enabled = true;
|
||||||
localContent.Window.Close();
|
// localContent.Window.Close();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
private void UpdateConnectionState(HubConnection connection)
|
private void UpdateConnectionState(HubConnection connection)
|
||||||
{
|
{
|
||||||
|
@ -2367,9 +2368,9 @@ namespace Sledgemapper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private (Window Window ,C Content) GetParentContentInWindow<C>(Widget widget) where C:Widget
|
private (Window Window, C Content) GetParentContentInWindow<C>(Widget widget) where C : Widget
|
||||||
{
|
{
|
||||||
Container container = widget.Parent;
|
Container container = widget.Parent;
|
||||||
while (!(container is Window))
|
while (!(container is Window))
|
||||||
{
|
{
|
||||||
container = container.Parent;
|
container = container.Parent;
|
||||||
|
@ -2377,13 +2378,13 @@ private (Window Window ,C Content) GetParentContentInWindow<C>(Widget widget) wh
|
||||||
|
|
||||||
var localWindow = (Window)container;
|
var localWindow = (Window)container;
|
||||||
var localContent = localWindow.Content as C;
|
var localContent = localWindow.Content as C;
|
||||||
return (localWindow,localContent);
|
return (localWindow, localContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = GetParentContentInWindow<NoteWindow>(button);
|
||||||
var note = new Note
|
var note = new Note
|
||||||
{
|
{
|
||||||
X = _state.SelectedNote.X,
|
X = _state.SelectedNote.X,
|
||||||
|
@ -2400,161 +2401,161 @@ private (Window Window ,C Content) GetParentContentInWindow<C>(Widget widget) wh
|
||||||
var content = GetParentContentInWindow<Widget>(button);
|
var content = GetParentContentInWindow<Widget>(button);
|
||||||
content.Window.Close();
|
content.Window.Close();
|
||||||
}
|
}
|
||||||
private async void OnButtonLoginClick(object sender, EventArgs e)
|
//private async void OnButtonLoginClick(object sender, EventArgs e)
|
||||||
{
|
//{
|
||||||
var button = ((TextButton)sender);
|
// var button = ((TextButton)sender);
|
||||||
Container container = button.Parent;
|
// Container container = button.Parent;
|
||||||
while (!(container is Window))
|
// while (!(container is Window))
|
||||||
{
|
// {
|
||||||
container = container.Parent;
|
// container = container.Parent;
|
||||||
}
|
// }
|
||||||
|
|
||||||
var localWindow = (Window)container;
|
// var localWindow = (Window)container;
|
||||||
var localContent = localWindow.Content as LoginRegisterWindow;
|
// var localContent = localWindow.Content as LoginRegisterWindow;
|
||||||
|
|
||||||
if (!button.Enabled)
|
// if (!button.Enabled)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
var isValid = true;
|
// var isValid = true;
|
||||||
isValid &= ValidateTextbox(localContent.TxtEmail);
|
// isValid &= ValidateTextbox(localContent.TxtEmail);
|
||||||
isValid &= ValidateTextbox(localContent.TxtPassword);
|
// isValid &= ValidateTextbox(localContent.TxtPassword);
|
||||||
|
|
||||||
if (!isValid)
|
// if (!isValid)
|
||||||
{
|
// {
|
||||||
localContent.LblLoginError.Text = "Username or password is not valid";
|
// localContent.LblLoginError.Text = "Username or password is not valid";
|
||||||
localContent.LblLoginError.Visible = true;
|
// localContent.LblLoginError.Visible = true;
|
||||||
|
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
var successful = false;
|
// var successful = false;
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
button.Text = "Wait...";
|
// button.Text = "Wait...";
|
||||||
localContent.LblLoginError.Text = "";
|
// localContent.LblLoginError.Text = "";
|
||||||
localContent.LblLoginError.Visible = false;
|
// localContent.LblLoginError.Visible = false;
|
||||||
_authResponse = await _communicationManager.Login(new AuthenticateModel
|
// _authResponse = await _communicationManager.Login(new AuthenticateModel
|
||||||
{
|
// {
|
||||||
Username = localContent.TxtEmail.Text,
|
// Username = localContent.TxtEmail.Text,
|
||||||
Email = localContent.TxtEmail.Text,
|
// Email = localContent.TxtEmail.Text,
|
||||||
Password = localContent.TxtPassword.Text
|
// Password = localContent.TxtPassword.Text
|
||||||
});
|
// });
|
||||||
successful = _authResponse != null;
|
// successful = _authResponse != null;
|
||||||
}
|
// }
|
||||||
catch (Refit.ApiException refitException)
|
// catch (Refit.ApiException refitException)
|
||||||
{
|
// {
|
||||||
ExceptionlessClient.Default.SubmitException(refitException);
|
// ExceptionlessClient.Default.SubmitException(refitException);
|
||||||
localContent.LblLoginError.Text = refitException.Content;
|
// localContent.LblLoginError.Text = refitException.Content;
|
||||||
localContent.LblLoginError.Visible = true;
|
// localContent.LblLoginError.Visible = true;
|
||||||
}
|
// }
|
||||||
catch (Exception ex)
|
// catch (Exception ex)
|
||||||
{
|
// {
|
||||||
ExceptionlessClient.Default.SubmitException(ex);
|
// ExceptionlessClient.Default.SubmitException(ex);
|
||||||
localContent.LblLoginError.Text = "Can't connect to the server";
|
// localContent.LblLoginError.Text = "Can't connect to the server";
|
||||||
localContent.LblLoginError.Visible = true;
|
// localContent.LblLoginError.Visible = true;
|
||||||
Debug.Write(ex);
|
// Debug.Write(ex);
|
||||||
}
|
// }
|
||||||
finally
|
// finally
|
||||||
{
|
// {
|
||||||
button.Enabled = true;
|
// button.Enabled = true;
|
||||||
button.Text = "Login";
|
// button.Text = "Login";
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (successful)
|
// if (successful)
|
||||||
{
|
// {
|
||||||
_mainWidget.MenuConnectNew.Enabled = true;
|
// _mainWidget.MenuConnectNew.Enabled = true;
|
||||||
_mainWidget.MenuConnectJoin.Enabled = true;
|
// _mainWidget.MenuConnectJoin.Enabled = true;
|
||||||
_mainWidget.lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
// _mainWidget.lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
||||||
localWindow.Close();
|
// localWindow.Close();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
private async void OnButtonRegisterClick(object sender, EventArgs e)
|
//private async void OnButtonRegisterClick(object sender, EventArgs e)
|
||||||
{
|
//{
|
||||||
var button = ((TextButton)sender);
|
// var button = ((TextButton)sender);
|
||||||
|
|
||||||
var localContent = GetParentContentInWindow<LoginRegisterWindow>(button);// localWindow.Content as PlayerWindow;
|
// var localContent = GetParentContentInWindow<LoginRegisterWindow>(button);// localWindow.Content as PlayerWindow;
|
||||||
|
|
||||||
if (!button.Enabled)
|
// if (!button.Enabled)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
var isValid = true;
|
// var isValid = true;
|
||||||
isValid &= ValidateTextbox(localContent.Content.TxtEmail);
|
// isValid &= ValidateTextbox(localContent.Content.TxtEmail);
|
||||||
isValid &= ValidateTextbox(localContent.Content.TxtPassword);
|
// isValid &= ValidateTextbox(localContent.Content.TxtPassword);
|
||||||
isValid &= ValidateTextbox(localContent.Content.TxtFirstname);
|
// isValid &= ValidateTextbox(localContent.Content.TxtFirstname);
|
||||||
isValid &= ValidateTextbox(localContent.Content.TxtLastname);
|
// isValid &= ValidateTextbox(localContent.Content.TxtLastname);
|
||||||
isValid &= ValidateTextbox(localContent.Content.TxtInitials);
|
// isValid &= ValidateTextbox(localContent.Content.TxtInitials);
|
||||||
|
|
||||||
if (!isValid)
|
// if (!isValid)
|
||||||
{
|
// {
|
||||||
localContent.Content.LblLoginError.Text = "Please complete all the fields";
|
// localContent.Content.LblLoginError.Text = "Please complete all the fields";
|
||||||
localContent.Content.LblLoginError.Visible = true;
|
// localContent.Content.LblLoginError.Visible = true;
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
var successful = false;
|
// var successful = false;
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
button.Text = "Wait...";
|
// button.Text = "Wait...";
|
||||||
localContent.Content.LblLoginError.Text = "";
|
// localContent.Content.LblLoginError.Text = "";
|
||||||
localContent.Content.LblLoginError.Visible = false;
|
// localContent.Content.LblLoginError.Visible = false;
|
||||||
|
|
||||||
var result = await _communicationManager.Register(new RegisterModel
|
// var result = await _communicationManager.Register(new RegisterModel
|
||||||
{
|
// {
|
||||||
Username = localContent.Content.TxtEmail.Text,
|
// Username = localContent.Content.TxtEmail.Text,
|
||||||
Email = localContent.Content.TxtEmail.Text,
|
// Email = localContent.Content.TxtEmail.Text,
|
||||||
Password = localContent.Content.TxtPassword.Text,
|
// Password = localContent.Content.TxtPassword.Text,
|
||||||
FirstName = localContent.Content.TxtFirstname.Text,
|
// FirstName = localContent.Content.TxtFirstname.Text,
|
||||||
LastName = localContent.Content.TxtLastname.Text,
|
// LastName = localContent.Content.TxtLastname.Text,
|
||||||
Initials = localContent.Content.TxtInitials.Text
|
// Initials = localContent.Content.TxtInitials.Text
|
||||||
});
|
// });
|
||||||
if (result.Result)
|
// if (result.Result)
|
||||||
{
|
// {
|
||||||
_authResponse = await _communicationManager.Login(new AuthenticateModel
|
// _authResponse = await _communicationManager.Login(new AuthenticateModel
|
||||||
{
|
// {
|
||||||
Username = localContent.Content.TxtEmail.Text,
|
// Username = localContent.Content.TxtEmail.Text,
|
||||||
Password = localContent.Content.TxtPassword.Text
|
// Password = localContent.Content.TxtPassword.Text
|
||||||
});
|
// });
|
||||||
successful = true;
|
// successful = true;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
localContent.Content.LblLoginError.Text = result.Errors.FirstOrDefault();
|
// localContent.Content.LblLoginError.Text = result.Errors.FirstOrDefault();
|
||||||
localContent.Content.LblLoginError.Visible = true;
|
// localContent.Content.LblLoginError.Visible = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
catch (Refit.ApiException refitException)
|
// catch (Refit.ApiException refitException)
|
||||||
{
|
// {
|
||||||
ExceptionlessClient.Default.SubmitException(refitException);
|
// ExceptionlessClient.Default.SubmitException(refitException);
|
||||||
localContent.Content.LblLoginError.Text = refitException.Content;
|
// localContent.Content.LblLoginError.Text = refitException.Content;
|
||||||
localContent.Content.LblLoginError.Visible = true;
|
// localContent.Content.LblLoginError.Visible = true;
|
||||||
}
|
// }
|
||||||
catch (Exception ex)
|
// catch (Exception ex)
|
||||||
{
|
// {
|
||||||
ExceptionlessClient.Default.SubmitException(ex);
|
// ExceptionlessClient.Default.SubmitException(ex);
|
||||||
localContent.Content.LblLoginError.Text = "Can't connect to the server";
|
// localContent.Content.LblLoginError.Text = "Can't connect to the server";
|
||||||
localContent.Content.LblLoginError.Visible = true;
|
// localContent.Content.LblLoginError.Visible = true;
|
||||||
Debug.Write(ex);
|
// Debug.Write(ex);
|
||||||
}
|
// }
|
||||||
finally
|
// finally
|
||||||
{
|
// {
|
||||||
button.Enabled = true;
|
// button.Enabled = true;
|
||||||
button.Text = "Register";
|
// button.Text = "Register";
|
||||||
}
|
// }
|
||||||
if (successful)
|
// if (successful)
|
||||||
{
|
// {
|
||||||
_mainWidget.MenuConnectNew.Enabled = true;
|
// _mainWidget.MenuConnectNew.Enabled = true;
|
||||||
_mainWidget.MenuConnectJoin.Enabled = true;
|
// _mainWidget.MenuConnectJoin.Enabled = true;
|
||||||
|
|
||||||
_mainWidget.lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
// _mainWidget.lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
|
||||||
|
|
||||||
localContent.Window.Close();
|
// localContent.Window.Close();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
private void OnContextMenuNewNoteClick(object sender, EventArgs e)
|
private void OnContextMenuNewNoteClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -2627,54 +2628,54 @@ private (Window Window ,C Content) GetParentContentInWindow<C>(Widget widget) wh
|
||||||
content.TxtSession.SetKeyboardFocus();
|
content.TxtSession.SetKeyboardFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMenuConnectLoginSelected(object sender, EventArgs e)
|
// private void OnMenuConnectLoginSelected(object sender, EventArgs e)
|
||||||
{
|
// {
|
||||||
Window window = new()
|
// Window window = new()
|
||||||
{
|
// {
|
||||||
Title = "Login"
|
// Title = "Login"
|
||||||
};
|
// };
|
||||||
|
|
||||||
var content = new LoginRegisterWindow();
|
// var content = new LoginRegisterWindow();
|
||||||
|
|
||||||
#if DEBUG
|
//#if DEBUG
|
||||||
content.TxtEmail.Text = "michele.scandura@outlook.com";
|
// content.TxtEmail.Text = "michele.scandura@outlook.com";
|
||||||
content.TxtPassword.Text = "slePharland!79";
|
// content.TxtPassword.Text = "slePharland!79";
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
content.RdoLogin.IsPressed = true;
|
// content.RdoLogin.IsPressed = true;
|
||||||
content.RdoLogin.Click += (s, e) =>
|
// content.RdoLogin.Click += (s, e) =>
|
||||||
{
|
// {
|
||||||
content.TxtFirstname.Visible = false;
|
// content.TxtFirstname.Visible = false;
|
||||||
content.TxtLastname.Visible = false;
|
// content.TxtLastname.Visible = false;
|
||||||
content.TxtInitials.Visible = false;
|
// content.TxtInitials.Visible = false;
|
||||||
content.LblFirstname.Visible = false;
|
// content.LblFirstname.Visible = false;
|
||||||
content.LblLastname.Visible = false;
|
// content.LblLastname.Visible = false;
|
||||||
content.LblInitials.Visible = false;
|
// content.LblInitials.Visible = false;
|
||||||
content.BtnLogin.Visible = true;
|
// content.BtnLogin.Visible = true;
|
||||||
content.BtnRegister.Visible = false;
|
// content.BtnRegister.Visible = false;
|
||||||
window.Title = "Login";
|
// window.Title = "Login";
|
||||||
};
|
// };
|
||||||
|
|
||||||
content.RdoRegister.Click += (s, e) =>
|
// content.RdoRegister.Click += (s, e) =>
|
||||||
{
|
// {
|
||||||
content.TxtFirstname.Visible = true;
|
// content.TxtFirstname.Visible = true;
|
||||||
content.TxtLastname.Visible = true;
|
// content.TxtLastname.Visible = true;
|
||||||
content.TxtInitials.Visible = true;
|
// content.TxtInitials.Visible = true;
|
||||||
content.LblFirstname.Visible = true;
|
// content.LblFirstname.Visible = true;
|
||||||
content.LblLastname.Visible = true;
|
// content.LblLastname.Visible = true;
|
||||||
content.LblInitials.Visible = true;
|
// content.LblInitials.Visible = true;
|
||||||
content.BtnLogin.Visible = false;
|
// content.BtnLogin.Visible = false;
|
||||||
content.BtnRegister.Visible = true;
|
// content.BtnRegister.Visible = true;
|
||||||
window.Title = "Register";
|
// window.Title = "Register";
|
||||||
};
|
// };
|
||||||
|
|
||||||
content.BtnRegister.Click += OnButtonRegisterClick;
|
// content.BtnRegister.Click += OnButtonRegisterClick;
|
||||||
content.BtnLogin.Click += OnButtonLoginClick;
|
// content.BtnLogin.Click += OnButtonLoginClick;
|
||||||
|
|
||||||
window.Content = content;
|
// window.Content = content;
|
||||||
window.ShowModal(_desktop);
|
// window.ShowModal(_desktop);
|
||||||
content.TxtEmail.SetKeyboardFocus();
|
// content.TxtEmail.SetKeyboardFocus();
|
||||||
}
|
// }
|
||||||
|
|
||||||
private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
|
private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -2702,26 +2703,26 @@ private (Window Window ,C Content) GetParentContentInWindow<C>(Widget widget) wh
|
||||||
await _communicationManager.Api.SaveSnapshot(_sessionData, _sessionData.SessionName);
|
await _communicationManager.Api.SaveSnapshot(_sessionData, _sessionData.SessionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMenuConnectNewSelected(object sender, EventArgs e)
|
//private void OnMenuConnectNewSelected(object sender, EventArgs e)
|
||||||
{
|
//{
|
||||||
if (!((MenuItem)sender).Enabled)
|
// if (!((MenuItem)sender).Enabled)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Window window = new()
|
// Window window = new()
|
||||||
{
|
// {
|
||||||
Title = "New mapping session"
|
// Title = "New mapping session"
|
||||||
};
|
// };
|
||||||
|
|
||||||
var content = new SessionWindow();
|
// var content = new SessionWindow();
|
||||||
content.BtnLogin.Text = "Join";
|
// content.BtnLogin.Text = "Join";
|
||||||
content.BtnLogin.Click += OnButtonNewSessionClicked;
|
// content.BtnLogin.Click += OnButtonNewSessionClicked;
|
||||||
window.Content = content;
|
// window.Content = content;
|
||||||
|
|
||||||
window.ShowModal(_desktop);
|
// window.ShowModal(_desktop);
|
||||||
content.TxtSession.SetKeyboardFocus();
|
// content.TxtSession.SetKeyboardFocus();
|
||||||
}
|
//}
|
||||||
|
|
||||||
private void OnMenuFileSaveSelected(object sender, EventArgs e)
|
private void OnMenuFileSaveSelected(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,15 +1,36 @@
|
||||||
|
using Exceptionless;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Myra.Graphics2D.Brushes;
|
||||||
using Myra.Graphics2D.UI;
|
using Myra.Graphics2D.UI;
|
||||||
|
using Sledgemapper.Shared.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Sledgemapper.UI
|
namespace Sledgemapper.UI
|
||||||
{
|
{
|
||||||
public partial class MainWidget
|
public partial class MainWidget
|
||||||
{
|
{
|
||||||
public void ClearSelection()
|
private AuthenticateResponse _authResponse;
|
||||||
{
|
private readonly CommunicationManager CommunicationManager;
|
||||||
|
|
||||||
|
public MainWidget(CommunicationManager communicationManager)
|
||||||
|
{
|
||||||
|
BuildUI();
|
||||||
|
|
||||||
|
CommunicationManager = communicationManager;
|
||||||
|
MenuConnectLogin.Selected += OnMenuConnectLoginSelected;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void ClearSelection()
|
||||||
|
{
|
||||||
ClearSelection(GridWalls);
|
ClearSelection(GridWalls);
|
||||||
ClearSelection(GridOverlays);
|
ClearSelection(GridOverlays);
|
||||||
ClearSelection(Toolbar);
|
ClearSelection(Toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearSelection(Grid grid)
|
private void ClearSelection(Grid grid)
|
||||||
{
|
{
|
||||||
|
@ -19,12 +40,324 @@ namespace Sledgemapper.UI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearSelection(HorizontalStackPanel grid)
|
private void ClearSelection(HorizontalStackPanel grid)
|
||||||
{
|
{
|
||||||
foreach (var widget in grid.Widgets)
|
foreach (var widget in grid.Widgets)
|
||||||
{
|
{
|
||||||
widget.Border = null;
|
widget.Border = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void OnMenuConnectLoginSelected(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Window window = new()
|
||||||
|
{
|
||||||
|
Title = "Login"
|
||||||
|
};
|
||||||
|
|
||||||
|
var content = new LoginRegisterWindow();
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
window.Content = content;
|
||||||
|
window.ShowModal(Desktop);
|
||||||
|
content.TxtEmail.SetKeyboardFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
if (!((MenuItem)sender).Enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Window window = new()
|
||||||
|
{
|
||||||
|
Title = "New mapping session"
|
||||||
|
};
|
||||||
|
|
||||||
|
var content = new SessionWindow();
|
||||||
|
content.BtnLogin.Text = "Join";
|
||||||
|
content.BtnLogin.Click += OnButtonNewSessionClicked;
|
||||||
|
window.Content = content;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
_mainWidget.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)
|
||||||
|
{
|
||||||
|
_sessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||||
|
_sessionData.MapEntityAdded -= OnMapEntityAdded;
|
||||||
|
_sessionData.MapEntityDeleted -= OnMapEntityDeleted;
|
||||||
|
_sessionData.MapEntityAdded += OnMapEntityAdded;
|
||||||
|
_sessionData.MapEntityDeleted += OnMapEntityDeleted;
|
||||||
|
}
|
||||||
|
successful = result;
|
||||||
|
var result2 = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.Content.TxtSession.Text);
|
||||||
|
_sessionData.SessionId = result2.SessionId;
|
||||||
|
_sessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ExceptionlessClient.Default.SubmitException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (successful)
|
||||||
|
{
|
||||||
|
_sessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||||
|
_communicationManager.SessionData.Map = _sessionData.Map;
|
||||||
|
_communicationManager.SessionData.Overlays = _sessionData.Overlays;
|
||||||
|
_communicationManager.SessionData.Walls = _sessionData.Walls;
|
||||||
|
_mainWidget.lblSessionName.Text = _sessionData.SessionName;
|
||||||
|
_mainWidget.MenuConnectSync.Enabled = true;
|
||||||
|
_mainWidget.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue