more ui fixes, small code cleanup
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele 2021-09-03 19:25:48 +01:00
parent 4149d744e8
commit dc7b2dd8f2
7 changed files with 66 additions and 200 deletions

View File

@ -532,12 +532,28 @@ namespace Sledgemapper
OnMenuCampaignNew(s, e);
};
content.BtnLoadCampaign.Click += (s, e) =>
{
if (campaignSelected)
{
campaignSelected = false;
window.Close();
}
};
content.BtnCancelCampaign.Click += (s, e) =>
{
window.Close();
};
window.Content = content;
window.ShowModal(_desktop);
// content.TxtCampaign.SetKeyboardFocus();
}
private bool campaignSelected;
private void OnCampaignSelected(object sender, EventArgs e)
{
var item = sender as UI.ListItem;
@ -550,6 +566,7 @@ namespace Sledgemapper
currentItem.Background= new SolidBrush("#D9D9D9FF");
}
item.Background=new SolidBrush(_settings.OverlayTintColor);
campaignSelected = true;
}
private void OnMapSelected(object sender, EventArgs e)
@ -2116,14 +2133,9 @@ namespace Sledgemapper
private async void OnButtonJoinSessionClicked(object sender, EventArgs e)
{
Container container = ((TextButton)sender).Parent;
while (!(container is Window))
{
container = container.Parent;
}
var localWindow = (Window)container;
var localContent = localWindow.Content as SessionWindow;
var isValid = ValidateTextbox(localContent.TxtSession);
var localContent = GetParentContentInWindow<SessionWindow>(((TextButton)sender));
var isValid = ValidateTextbox(localContent.Content.TxtSession);
if (!isValid)
{
return;
@ -2139,7 +2151,7 @@ namespace Sledgemapper
var successful = false;
try
{
var result = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.TxtSession.Text);
var result = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.Content.TxtSession.Text);
if (result != null)
{
_sessionData.Map = result.Map;
@ -2162,24 +2174,18 @@ namespace Sledgemapper
if (successful)
{
_sessionData.SessionName = localContent.TxtSession.Text;
_sessionData.SessionName = localContent.Content.TxtSession.Text;
_mainWidget.lblSessionName.Text = _sessionData.SessionName;
_mainWidget.MenuConnectSync.Enabled = true;
_mainWidget.MenuConnectUpload.Enabled = true;
localWindow.Close();
localContent.Window.Close();
}
}
private async void OnButtonInvitePlayerClicked(object sender, EventArgs e)
{
Container container = ((TextButton)sender).Parent;
while (!(container is Window))
{
container = container.Parent;
}
var localWindow = (Window)container;
var localContent = localWindow.Content as PlayerWindow;
var isValid = ValidateTextbox(localContent.TxtCampaign);
var localContent = GetParentContentInWindow<PlayerWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
var isValid = ValidateTextbox(localContent.Content.TxtCampaign);
if (!isValid)
{
return;
@ -2195,7 +2201,7 @@ namespace Sledgemapper
var successful = false;
try
{
await _communicationManager.Api.InvitePlayer(_state.CampaignName, localContent.TxtCampaign.Text);
await _communicationManager.Api.InvitePlayer(_state.CampaignName, localContent.Content.TxtCampaign.Text);
//if (result)
//{
@ -2227,20 +2233,15 @@ namespace Sledgemapper
// localWindow.Close();
//}
localWindow.Close();
localContent.Window.Close();
}
private async void OnButtonNewCampaignClicked(object sender, EventArgs e)
{
Container container = ((TextButton)sender).Parent;
while (!(container is Window))
{
container = container.Parent;
}
var localWindow = (Window)container;
var localContent = localWindow.Content as CampaignWindow;
var isValid = ValidateTextbox(localContent.TxtCampaign);
var localContent = GetParentContentInWindow<CampaignWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
var isValid = ValidateTextbox(localContent.Content.TxtCampaign);
if (!isValid)
{
return;
@ -2256,7 +2257,7 @@ namespace Sledgemapper
var successful = false;
try
{
await _communicationManager.Api.NewCampaign(localContent.TxtCampaign.Text);
await _communicationManager.Api.NewCampaign(localContent.Content.TxtCampaign.Text);
//if (result)
//{
@ -2288,20 +2289,15 @@ namespace Sledgemapper
// localWindow.Close();
//}
localWindow.Close();
localContent.Window.Close();
}
private async void OnButtonNewSessionClicked(object sender, EventArgs e)
{
Container container = ((TextButton)sender).Parent;
while (!(container is Window))
{
container = container.Parent;
}
var localWindow = (Window)container;
var localContent = localWindow.Content as SessionWindow;
var isValid = ValidateTextbox(localContent.TxtSession);
var localContent = GetParentContentInWindow<SessionWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
var isValid = ValidateTextbox(localContent.Content.TxtSession);
if (!isValid)
{
return;
@ -2317,20 +2313,20 @@ namespace Sledgemapper
var successful = false;
try
{
var result = await _communicationManager.Api.NewSession(_state.CampaignName, localContent.TxtSession.Text);
var result = await _communicationManager.Api.NewSession(_state.CampaignName, localContent.Content.TxtSession.Text);
if (result)
{
_sessionData.SessionName = localContent.TxtSession.Text;
_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.TxtSession.Text);
var result2 = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.Content.TxtSession.Text);
_sessionData.SessionId = result2.SessionId;
_sessionData.SessionName = localContent.TxtSession.Text;
_sessionData.SessionName = localContent.Content.TxtSession.Text;
}
catch (Exception ex)
{
@ -2339,14 +2335,14 @@ namespace Sledgemapper
if (successful)
{
_sessionData.SessionName = localContent.TxtSession.Text;
_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;
localWindow.Close();
localContent.Window.Close();
}
}
@ -2478,14 +2474,8 @@ private (Window Window ,C Content) GetParentContentInWindow<C>(Widget widget) wh
private async void OnButtonRegisterClick(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;
var localContent = GetParentContentInWindow<LoginRegisterWindow>(button);// localWindow.Content as PlayerWindow;
if (!button.Enabled)
{
@ -2493,16 +2483,16 @@ private (Window Window ,C Content) GetParentContentInWindow<C>(Widget widget) wh
}
var isValid = true;
isValid &= ValidateTextbox(localContent.TxtEmail);
isValid &= ValidateTextbox(localContent.TxtPassword);
isValid &= ValidateTextbox(localContent.TxtFirstname);
isValid &= ValidateTextbox(localContent.TxtLastname);
isValid &= ValidateTextbox(localContent.TxtInitials);
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.LblLoginError.Text = "Please complete all the fields";
localContent.LblLoginError.Visible = true;
localContent.Content.LblLoginError.Text = "Please complete all the fields";
localContent.Content.LblLoginError.Visible = true;
return;
}
@ -2510,44 +2500,44 @@ private (Window Window ,C Content) GetParentContentInWindow<C>(Widget widget) wh
try
{
button.Text = "Wait...";
localContent.LblLoginError.Text = "";
localContent.LblLoginError.Visible = false;
localContent.Content.LblLoginError.Text = "";
localContent.Content.LblLoginError.Visible = false;
var result = await _communicationManager.Register(new RegisterModel
{
Username = localContent.TxtEmail.Text,
Email = localContent.TxtEmail.Text,
Password = localContent.TxtPassword.Text,
FirstName = localContent.TxtFirstname.Text,
LastName = localContent.TxtLastname.Text,
Initials = localContent.TxtInitials.Text
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.TxtEmail.Text,
Password = localContent.TxtPassword.Text
Username = localContent.Content.TxtEmail.Text,
Password = localContent.Content.TxtPassword.Text
});
successful = true;
}
else
{
localContent.LblLoginError.Text = result.Errors.FirstOrDefault();
localContent.LblLoginError.Visible = true;
localContent.Content.LblLoginError.Text = result.Errors.FirstOrDefault();
localContent.Content.LblLoginError.Visible = true;
}
}
catch (Refit.ApiException refitException)
{
ExceptionlessClient.Default.SubmitException(refitException);
localContent.LblLoginError.Text = refitException.Content;
localContent.LblLoginError.Visible = true;
localContent.Content.LblLoginError.Text = refitException.Content;
localContent.Content.LblLoginError.Visible = true;
}
catch (Exception ex)
{
ExceptionlessClient.Default.SubmitException(ex);
localContent.LblLoginError.Text = "Can't connect to the server";
localContent.LblLoginError.Visible = true;
localContent.Content.LblLoginError.Text = "Can't connect to the server";
localContent.Content.LblLoginError.Visible = true;
Debug.Write(ex);
}
finally
@ -2562,7 +2552,7 @@ private (Window Window ,C Content) GetParentContentInWindow<C>(Widget widget) wh
_mainWidget.lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
localWindow.Close();
localContent.Window.Close();
}
}

View File

@ -1,45 +0,0 @@
/* Generated by MyraPad at 02/09/2021 22:56:13 */
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 CampaignListItem: HorizontalStackPanel
{
private void BuildUI()
{
TxtCampaignName = new Label();
TxtCampaignName.Text = "Highfell";
TxtCampaignName.TextColor = ColorStorage.CreateColor(32, 32, 32, 255);
TxtCampaignName.Margin = new Thickness(10, 0, 0, 0);
TxtCampaignName.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center;
TxtCampaignName.Id = "TxtCampaignName";
VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center;
Height = 30;
BorderThickness = new Thickness(2);
Padding = new Thickness(5);
Background = new SolidBrush("#D9D9D9FF");
Id = "PnlCampaignItem";
Widgets.Add(TxtCampaignName);
}
public Label TxtCampaignName;
}
}

View File

@ -1,11 +0,0 @@
/* Generated by MyraPad at 03/06/2021 16:00:11 */
namespace Sledgemapper.UI
{
public partial class CampaignListItem
{
public CampaignListItem()
{
BuildUI();
}
}
}

View File

@ -1,45 +0,0 @@
/* Generated by MyraPad at 28/08/2021 19:49:48 */
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 PlayerListItem: HorizontalStackPanel
{
private void BuildUI()
{
TxtPlayerName = new Label();
TxtPlayerName.Text = "Highfell";
TxtPlayerName.TextColor = ColorStorage.CreateColor(102, 102, 102, 255);
TxtPlayerName.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center;
TxtPlayerName.Background = new SolidBrush("#00000000");
TxtPlayerName.Id = "TxtPlayerName";
VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center;
Width = 300;
Height = 30;
BorderThickness = new Thickness(2);
Padding = new Thickness(10);
Id = "PnlPlayerItem";
Widgets.Add(TxtPlayerName);
}
public Label TxtPlayerName;
}
}

View File

@ -1,11 +0,0 @@
/* Generated by MyraPad at 28/08/2021 19:49:48 */
namespace Sledgemapper.UI
{
public partial class PlayerListItem
{
public PlayerListItem()
{
BuildUI();
}
}
}

View File

@ -1,6 +0,0 @@
<Project>
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="CampaignListItem" OutputPath="C:\dev\Map\Sledgemapper\UI" />
<HorizontalStackPanel VerticalAlignment="Center" Height="30" BorderThickness="2" Padding="5" Background="#D9D9D9FF" Id="PnlCampaignItem" >
<Label Text="Highfell" TextColor="#202020FF" Margin="10, 0, 0, 0" VerticalAlignment="Center" Id="TxtCampaignName" />
</HorizontalStackPanel>
</Project>

View File

@ -1,6 +0,0 @@
<Project>
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="PlayerListItem" OutputPath="C:\dev\Map\Sledgemapper\UI" />
<HorizontalStackPanel VerticalAlignment="Center" Width="300" Height="30" BorderThickness="2" Padding="10" Id="PnlPlayerItem">
<Label Text="Highfell" TextColor="#666666FF" VerticalAlignment="Center" Background="#00000000" Id="TxtPlayerName" />
</HorizontalStackPanel>
</Project>