even more cleanup
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-16 15:27:03 +01:00
parent 7808363a07
commit 4179143fdb
15 changed files with 192 additions and 183 deletions

View File

@ -113,10 +113,13 @@ namespace Sledgemapper.Api.Controllers
{
var jwtToken = GenerateJwtToken(existingUser);
return Ok(new RegistrationResponse()
return Ok(new LoginResponse()
{
Result = true,
Token = jwtToken
Token = jwtToken,
Username = existingUser.Email,
Initials = existingUser.Initials,
Id = existingUser.Id
});
}
else

View File

@ -4,4 +4,11 @@ namespace Sledgemapper.Models.Users
{
}
public class LoginResponse : AuthResult
{
public string Username { get; set; }
public string Initials { get; set; }
public string Id { get; internal set; }
}
}

View File

@ -70,6 +70,23 @@ namespace Sledgemapper
}
return valid;
}
public static void ShowInModalWindow(this Widget widget, Desktop desktop, string title)
{
Window window = new()
{
Title = title,
Content=widget
};
window.ShowModal(desktop);
}
}
//public interface IExtendedWidget
//{
// void ShowInModalWindow(this Widget widget, string title)
//}
}

View File

@ -82,4 +82,6 @@
<DependentUpon>$([System.String]::Concat(%(Filename), ".cs"))</DependentUpon>
</None>
</ItemGroup>
</Project>

View File

@ -48,14 +48,7 @@ namespace Sledgemapper.UI
return;
}
Window window = new()
{
Title = "New campaign"
};
var content = new CampaignWindow(CommunicationManager, Messenger);
window.Content = content;
window.ShowModal(Desktop);
new CampaignWindow(CommunicationManager, Messenger).ShowInModalWindow(Desktop, "New campaign");
}
private void OnCampaignSelected(object sender, EventArgs e)

View File

@ -54,18 +54,12 @@ namespace Sledgemapper.UI
BtnRegister.Click += OnButtonRegisterClick;
BtnLogin.Click += OnButtonLoginClick;
//TxtEmail.SetKeyboardFocus();
}
private async void OnButtonRegisterClick(object sender, EventArgs e)
{
var button = ((TextButton)sender);
var localContent = this;// GetParentContentInWindow<LoginRegisterWindow>(button);// localWindow.Content as PlayerWindow;
if (!button.Enabled)
{
return;

View File

@ -62,6 +62,7 @@ namespace Sledgemapper.UI
BtnToolbarLine.Click += OnBtnToolbarLinClicked;
BtnToolbarRoom.Click += OnBtnToolbarRoomClicked;
BtnToolbarDelete.Click += OnBtnToolbarDeleteClicked;
_messenger.Subscribe<LoginSuccesfulMessage>(OnLoginSuccesfulMessage);
_messenger.Subscribe<SignalrConnectionUpdateMessage>(OnSignalrConnectionUpdateMessage);
_messenger.Subscribe<MapOpenedMessage>(OnMapOpenedMessage);
@ -107,7 +108,7 @@ namespace Sledgemapper.UI
MenuCampaignOpen.Enabled = true;
MenuCampaingNew.Enabled = true;
lblUsername.Text = $"{obj.UserName} - {obj.Initials}";
lblUsername.Text = $"{obj.Initials}";
}
public void ClearSelection()
@ -292,16 +293,7 @@ namespace Sledgemapper.UI
return;
}
Window window = new()
{
Title = "Join mapping session"
};
var content = new SessionWindow(CommunicationManager, _messenger);
window.Content = content;
window.ShowModal(Desktop);
new SessionWindow(CommunicationManager, _messenger).ShowInModalWindow(Desktop, "Join mapping session");
}
private void OnMenuViewShowCellNUmbersSelected(object sender, EventArgs e)
@ -321,10 +313,7 @@ namespace Sledgemapper.UI
Title = "Notes"
};
var content = new NoteList(CommunicationManager, _messenger);
window.Content = content;
window.ShowModal(Desktop);
new NoteList(CommunicationManager, _messenger).ShowInModalWindow(Desktop, "Notes");
}
private void CenterOnSelectedTile()
@ -339,7 +328,6 @@ namespace Sledgemapper.UI
var dx = center.X - x * State.Instance.TileSize - State.Instance.ViewportCenter.X;
var dy = center.Y - y * State.Instance.TileSize - State.Instance.ViewportCenter.Y;
State.Instance.ViewportCenter = new Vector3(State.Instance.ViewportCenter.X + dx, State.Instance.ViewportCenter.Y + dy, State.Instance.ViewportCenter.Z);
}
private void OnMenuCampaignNew(object sender, EventArgs e)
@ -349,13 +337,7 @@ namespace Sledgemapper.UI
return;
}
Window window = new()
{
Title = "New campaign"
};
var content = new CampaignWindow(CommunicationManager, _messenger);
window.Content = content;
window.ShowModal(Desktop);
new CampaignWindow(CommunicationManager, _messenger).ShowInModalWindow(Desktop, "New campaign"); ;
}
private async void OnMenuCampaignOpen(object sender, EventArgs e)
@ -365,31 +347,9 @@ namespace Sledgemapper.UI
return;
}
Window window = new()
{
Title = "Campaigns"
};
var content = new CampaignList(CommunicationManager, _messenger);
await content.LoadCampaigns();
window.Content = content;
window.ShowModal(Desktop);
}
private void OnMapSelected(object sender, EventArgs e)
{
var item = sender as ListItem;
var localContent = item.GetParentContentInWindow<Widget>();
var list = item.Parent as Grid;
for (var i = 0; i < list.ChildrenCount; i++)
{
var currentItem = list.GetChild(i) as HorizontalStackPanel;// UI.ListItem;
currentItem.Background = new SolidBrush("#D9D9D9FF");
}
item.Background = new SolidBrush(Settings.Instance.OverlayTintColor);
content.ShowInModalWindow(Desktop, "Campaigns");
}
private async void OnMenuCampaignPlayersSelected(object sender, EventArgs e)
@ -399,18 +359,11 @@ namespace Sledgemapper.UI
return;
}
Window window = new()
{
Title = "Players"
};
var content = new PlayerList(CommunicationManager);
await content.LoadPlayers();
window.Content = content;
window.ShowModal(Desktop);
content.ShowInModalWindow(Desktop, "Players");
}
private async void OnMenuMapOpen(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled)
@ -418,34 +371,11 @@ namespace Sledgemapper.UI
return;
}
Window window = new()
{
Title = "Maps"
};
var content = new MapList();
var campaigns = await CommunicationManager.Api.GetMaps(State.Instance.CampaignName);
foreach (var campaign in campaigns)
{
var item = new ListItem();
item.ItemName.Text = campaign.SessionName;
item.TouchUp += OnMapSelected;
content.StackCampaignsList.AddChild(item);
}
content.BtnNewCampaign.Click += (s, e) =>
{
window.Close();
OnMenuMapNew(s, e);
};
window.Content = content;
window.ShowModal(Desktop);
var content = new MapList(CommunicationManager);
await content.LoadMaps();
content.ShowInModalWindow(Desktop, "Maps");
}
private async void OnButtonJoinSessionClicked(object sender, EventArgs e)
{
var localContent = ((TextButton)sender).GetParentContentInWindow<SessionWindow>();
@ -496,9 +426,6 @@ namespace Sledgemapper.UI
localContent.Window.Close();
}
}
private void OnBtnToolbarRoomClicked(object sender, EventArgs e)
{
State.Instance.InsertMode = InsertMode.NewRoom;
@ -532,61 +459,14 @@ namespace Sledgemapper.UI
return;
}
Window window = new()
{
Title = "New map"
};
var content = new MapWindow();
//content.BtnNewCampaign.Text = "N";
content.BtnNewCampaign.Click += OnButtonNewMapClicked;
window.Content = content;
window.ShowModal(Desktop);
content.TxtCampaign.SetKeyboardFocus();
}
private async void OnButtonNewMapClicked(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 MapWindow;
var isValid = localContent.TxtCampaign.ValidateTextbox();
if (!isValid)
{
return;
}
var successful = false;
try
{
await CommunicationManager.Api.NewSession(State.Instance.CampaignName, localContent.TxtCampaign.Text);
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
}
localWindow.Close();
new MapWindow(CommunicationManager).ShowInModalWindow(Desktop, "New map");
}
//TODO Refactor
private void EditNote(Note note)
{
State.Instance.SelectedNote = new Note { X = note.X, Y = note.Y, Text = note.Text };
Window window = new()
{
Title = $" Note on {note.X}:{note.Y}"
};
var noteWindow = new NoteWindow(CommunicationManager, note);
window.Content = noteWindow;
window.ShowModal(Desktop);
new NoteWindow(CommunicationManager, note).ShowInModalWindow(Desktop, $" Note on {note.X}:{note.Y}");
}
}
}

View File

@ -1,4 +1,4 @@
/* Generated by MyraPad at 16/09/2021 12:26:31 */
/* Generated by MyraPad at 16/09/2021 14:53:34 */
using Myra;
using Myra.Graphics2D;
using Myra.Graphics2D.TextureAtlases;
@ -254,8 +254,9 @@ namespace Sledgemapper.UI
ScrOverlay.Content = GridOverlays;
TxtOverlaySearch = new TextBox();
TxtOverlaySearch.Height = 40;
TxtOverlaySearch.Margin = new Thickness(0, 4);
TxtOverlaySearch.Height = 25;
TxtOverlaySearch.BorderThickness = new Thickness(1);
TxtOverlaySearch.Border = new SolidBrush("#000000FF");
TxtOverlaySearch.Id = "TxtOverlaySearch";
var verticalStackPanel2 = new VerticalStackPanel();
@ -273,21 +274,21 @@ namespace Sledgemapper.UI
verticalSplitPane1.Widgets.Add(verticalStackPanel2);
var label1 = new Label();
label1.Text = "Connection status:";
label1.Text = "Connection:";
lblConnectionStatus = new Label();
lblConnectionStatus.Text = "Disconnected";
lblConnectionStatus.MinWidth = 100;
lblConnectionStatus.MinWidth = 50;
lblConnectionStatus.Id = "lblConnectionStatus";
var verticalSeparator1 = new VerticalSeparator();
var label2 = new Label();
label2.Text = "Username:";
label2.Text = "Initials:";
lblUsername = new Label();
lblUsername.Text = "n/a";
lblUsername.MinWidth = 100;
lblUsername.MinWidth = 50;
lblUsername.Id = "lblUsername";
var verticalSeparator2 = new VerticalSeparator();
@ -297,7 +298,7 @@ namespace Sledgemapper.UI
lblCampaign = new Label();
lblCampaign.Text = "n/a";
lblCampaign.MinWidth = 100;
lblCampaign.MinWidth = 50;
lblCampaign.Id = "lblCampaign";
var verticalSeparator3 = new VerticalSeparator();
@ -307,7 +308,7 @@ namespace Sledgemapper.UI
lblMap = new Label();
lblMap.Text = "n/a";
lblMap.MinWidth = 100;
lblMap.MinWidth = 50;
lblMap.Id = "lblMap";
var horizontalStackPanel1 = new HorizontalStackPanel();

View File

@ -72,24 +72,24 @@
<Grid.DefaultRowProportion Type="Pixels" Value="40" />
</Grid>
</ScrollViewer>
<TextBox Height="40" Margin="0, 4" Id="TxtOverlaySearch" />
<TextBox Height="25" BorderThickness="1" Border="#000000FF" Id="TxtOverlaySearch" />
</VerticalStackPanel>
</VerticalSplitPane>
<HorizontalStackPanel Spacing="10" Height="25" Background="#333333FF">
<HorizontalStackPanel.Proportions>
<Proportion Type="Auto" />
</HorizontalStackPanel.Proportions>
<Label Text="Connection status:" />
<Label Text="Disconnected" MinWidth="100" Id="lblConnectionStatus" />
<Label Text="Connection:" />
<Label Text="Disconnected" MinWidth="50" Id="lblConnectionStatus" />
<VerticalSeparator />
<Label Text="Username:" />
<Label Text="n/a" MinWidth="100" Id="lblUsername" />
<Label Text="Initials:" />
<Label Text="n/a" MinWidth="50" Id="lblUsername" />
<VerticalSeparator />
<Label Text="Campaign:" />
<Label Text="n/a" MinWidth="100" Id="lblCampaign" />
<Label Text="n/a" MinWidth="50" Id="lblCampaign" />
<VerticalSeparator />
<Label Text="Map:" />
<Label Text="n/a" MinWidth="100" Id="lblMap" />
<Label Text="n/a" MinWidth="50" Id="lblMap" />
</HorizontalStackPanel>
</VerticalStackPanel>
</Project>

View File

@ -0,0 +1,55 @@
/* Generated by MyraPad at 03/09/2021 17:13:57 */
using Myra.Graphics2D.Brushes;
using Myra.Graphics2D.UI;
using System;
using System.Threading.Tasks;
namespace Sledgemapper.UI
{
public partial class MapList
{
public CommunicationManager CommunicationManager { get; }
public MapList(CommunicationManager communicationManager)
{
CommunicationManager= communicationManager;
BuildUI();
BtnNewCampaign.Click += (s, e) =>
{
OnMenuMapNew(s, e);
this.GetContainingWindow().Close();
};
}
public async Task LoadMaps()
{
var campaigns = await CommunicationManager.Api.GetMaps(State.Instance.CampaignName);
foreach (var campaign in campaigns)
{
var item = new ListItem();
item.ItemName.Text = campaign.SessionName;
item.TouchUp += OnMapSelected;
StackCampaignsList.AddChild(item);
}
}
private void OnMapSelected(object sender, EventArgs e)
{
var item = sender as ListItem;
var localContent = item.GetParentContentInWindow<Widget>();
var list = item.Parent as Grid;
for (var i = 0; i < list.ChildrenCount; i++)
{
var currentItem = list.GetChild(i) as HorizontalStackPanel;// UI.ListItem;
currentItem.Background = new SolidBrush("#D9D9D9FF");
}
item.Background = new SolidBrush(Settings.Instance.OverlayTintColor);
}
private void OnMenuMapNew(object sender, EventArgs e)
{
new MapWindow(CommunicationManager).ShowInModalWindow(Desktop, "New map");
}
}
}

View File

@ -0,0 +1,16 @@
<Project>
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="MapList" OutputPath="C:\src\Map\Sledgemapper\UI" />
<VerticalStackPanel Spacing="13" Width="400" Padding="10">
<Label Text="Maps" HorizontalAlignment="Center" />
<ScrollViewer Height="250">
<VerticalStackPanel Id="StackCampaignsList">
<VerticalStackPanel.DefaultProportion Type="Auto" />
</VerticalStackPanel>
</ScrollViewer>
<HorizontalStackPanel Spacing="15" HorizontalAlignment="Right">
<TextButton Text="New" Width="70" Height="20" Padding="5" HorizontalAlignment="Center" Id="BtnNewCampaign" />
<TextButton Text="Load" Width="70" Height="20" Padding="5" HorizontalAlignment="Center" Id="BtnLoadCampaign" />
<TextButton Text="Cancel" Width="70" Height="20" Padding="5" HorizontalAlignment="Center" Id="BtnCancelCampaign" />
</HorizontalStackPanel>
</VerticalStackPanel>
</Project>

View File

@ -0,0 +1,48 @@
/* Generated by MyraPad at 02/09/2021 16:26:04 */
using Myra.Graphics2D.UI;
using Sentry;
using System;
namespace Sledgemapper.UI
{
public partial class MapWindow
{
public CommunicationManager CommunicationManager { get; }
public MapWindow(CommunicationManager communicationManager)
{
CommunicationManager= communicationManager;
BuildUI();
BtnNewCampaign.Click += OnButtonNewMapClicked;
}
private async void OnButtonNewMapClicked(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 MapWindow;
var isValid = localContent.TxtCampaign.ValidateTextbox();
if (!isValid)
{
return;
}
var successful = false;
try
{
await CommunicationManager.Api.NewSession(State.Instance.CampaignName, localContent.TxtCampaign.Text);
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
}
localWindow.Close();
}
}
}

View File

@ -1,4 +1,8 @@
/* Generated by MyraPad at 02/09/2021 16:26:04 */
using Myra.Graphics2D.UI;
using Sentry;
using System;
namespace Sledgemapper.UI
{
public partial class MapWindow
@ -6,6 +10,9 @@ namespace Sledgemapper.UI
public MapWindow()
{
BuildUI();
}
}
}
}
}

View File

@ -38,14 +38,7 @@ namespace Sledgemapper.UI
private void EditNote(Note note)
{
State.Instance.SelectedNote = new Note { X = note.X, Y = note.Y, Text = note.Text };
Window window = new()
{
Title = $" Note on {note.X}:{note.Y}"
};
var noteWindow = new NoteWindow(CommunicationManager, note);
window.Content = noteWindow;
window.ShowModal(Desktop);
new NoteWindow(CommunicationManager, note).ShowInModalWindow(Desktop, $" Note on {note.X}:{note.Y}");
}
}
}

View File

@ -32,14 +32,7 @@ namespace Sledgemapper.UI
private void ShowAddPLayerWindow()
{
Window window = new()
{
Title = "Invite player"
};
var content = new PlayerWindow(CommunicationManager);
window.Content = content;
window.ShowModal(Desktop);
new PlayerWindow(CommunicationManager).ShowInModalWindow(Desktop, "Invite player");
}
}
}