add new map to campaign
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-02 16:37:14 +01:00
parent 4d40add598
commit 12080cf6da
5 changed files with 261 additions and 22 deletions

View File

@ -12,8 +12,8 @@ namespace Sledgemapper
[Get("/session/{sessionName}")]
Task<Session> Session(string sessionName);
[Post("/session/{sessionName}")]
Task<bool> NewSession(string sessionName);
[Post("/map/{campaignName}/{sessionName}")]
Task<bool> NewSession(string campaignName, string sessionName);
[Post("/session/{sessionName}/snapshot")]
Task SaveSnapshot([Body] Session session, string sessionName);
@ -73,6 +73,10 @@ namespace Sledgemapper
[Get("/campaign/{campaignName}/players")]
Task<List<Player>> GetPlayers(string campaignName);
[Get("/campaign/{campaignName}/maps")]
Task<List<Session>> GetMaps(string campaignName);
[Post("/campaign/{campaignName}/players/{email}")]
Task InvitePlayer(string campaignName, string email);
}

View File

@ -217,7 +217,8 @@ namespace Sledgemapper
_mainWidget.MenuCampaignPlayers.Selected += OnMenuCampaignPlayersSelected;
_mainWidget.MenuMapOpen.Selected += OnMenuMapOpen;
_mainWidget.MenuMapNew.Selected += OnMenuMapNew;
_mainWidget.MenuConnectNew.Enabled = false;
_mainWidget.MenuConnectJoin.Enabled = false;
_mainWidget.MenuConnectSync.Enabled = false;
@ -259,6 +260,87 @@ namespace Sledgemapper
_whiteRectangle.SetData(new[] { Color.White });
}
private void OnMenuMapNew(object sender, EventArgs e)
{
if (sender is MenuItem && !((MenuItem)sender).Enabled)
{
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 = ValidateTextbox(localContent.TxtCampaign);
if (!isValid)
{
return;
}
//if (_communicationManager.Connection.State != HubConnectionState.Connected)
//{
// _mainWidget.lblConnectionStatus.Text = "Connecting";
// await _communicationManager.Connection.StartAsync();
// UpdateConnectionState(_communicationManager.Connection);
//}
var successful = false;
try
{
await _communicationManager.Api.NewSession(_state.CampaignName, localContent.TxtCampaign.Text);
//if (result)
//{
// _sessionData.SessionName = localContent.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);
//_sessionData.SessionId = result2.SessionId;
//_sessionData.SessionName = localContent.TxtSession.Text;
}
catch (Exception ex)
{
ExceptionlessClient.Default.SubmitException(ex);
}
//if (successful)
//{
// //_sessionData.SessionName = localContent.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();
//}
localWindow.Close();
}
private async void OnMenuMapOpen(object sender, EventArgs e)
{
if (!((MenuItem)sender).Enabled)
@ -272,23 +354,23 @@ namespace Sledgemapper
};
var content = new CampaignList();
//var campaigns = await _communicationManager.Api.GetMaps();
//foreach (var campaign in campaigns)
//{
// var item = new CampaignListItem();
// item.TxtCampaignName.Text = campaign.Name;
// item.Background = new NinePatchRegion(
// Content.Load<Texture2D>("listBackground"), new Rectangle(0, 0, 418, 25),
// new Myra.Graphics2D.Thickness
// {
// Left = 11,
// Right = 11,
// Top = 11,
// Bottom = 11
// });
// item.TouchUp += OnCampaignSelected;
// content.StackCampaignsList.AddChild(item);
//}
var campaigns = await _communicationManager.Api.GetMaps(_state.CampaignName);
foreach (var campaign in campaigns)
{
var item = new CampaignListItem();
item.TxtCampaignName.Text = campaign.SessionName;
item.Background = new NinePatchRegion(
Content.Load<Texture2D>("listBackground"), new Rectangle(0, 0, 418, 25),
new Myra.Graphics2D.Thickness
{
Left = 11,
Right = 11,
Top = 11,
Bottom = 11
});
item.TouchUp += OnCampaignSelected;
content.StackCampaignsList.AddChild(item);
}
//content.BtnNewCampaign.Text = "N";
@ -428,7 +510,7 @@ namespace Sledgemapper
var content = new CampaignWindow();
//content.BtnNewCampaign.Text = "N";
content.BtnNewCampaign.Click += OnButtonInvitePlayerClicked;
content.BtnNewCampaign.Click += OnButtonNewCampaignClicked;
window.Content = content;
window.ShowModal(_desktop);
@ -2152,6 +2234,67 @@ namespace Sledgemapper
}
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);
if (!isValid)
{
return;
}
//if (_communicationManager.Connection.State != HubConnectionState.Connected)
//{
// _mainWidget.lblConnectionStatus.Text = "Connecting";
// await _communicationManager.Connection.StartAsync();
// UpdateConnectionState(_communicationManager.Connection);
//}
var successful = false;
try
{
await _communicationManager.Api.NewCampaign(localContent.TxtCampaign.Text);
//if (result)
//{
// _sessionData.SessionName = localContent.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);
//_sessionData.SessionId = result2.SessionId;
//_sessionData.SessionName = localContent.TxtSession.Text;
}
catch (Exception ex)
{
ExceptionlessClient.Default.SubmitException(ex);
}
//if (successful)
//{
// //_sessionData.SessionName = localContent.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();
//}
localWindow.Close();
}
private async void OnButtonNewSessionClicked(object sender, EventArgs e)
{
Container container = ((TextButton)sender).Parent;
@ -2177,7 +2320,7 @@ namespace Sledgemapper
var successful = false;
try
{
var result = await _communicationManager.Api.NewSession(localContent.TxtSession.Text);
var result = await _communicationManager.Api.NewSession(_state.CampaignName, localContent.TxtSession.Text);
if (result)
{

View File

@ -0,0 +1,67 @@
/* Generated by MyraPad at 02/09/2021 16:26:04 */
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 MapWindow: VerticalStackPanel
{
private void BuildUI()
{
var label1 = new Label();
label1.Text = "Map";
TxtCampaign = new TextBox();
TxtCampaign.GridColumn = 1;
TxtCampaign.Id = "TxtCampaign";
var grid1 = new Grid();
grid1.ColumnSpacing = 25;
grid1.RowSpacing = 10;
grid1.ColumnsProportions.Add(new Proportion
{
Type = Myra.Graphics2D.UI.ProportionType.Pixels,
Value = 60,
});
grid1.ColumnsProportions.Add(new Proportion
{
Type = Myra.Graphics2D.UI.ProportionType.Fill,
});
grid1.Widgets.Add(label1);
grid1.Widgets.Add(TxtCampaign);
BtnNewCampaign = new TextButton();
BtnNewCampaign.Text = "New";
BtnNewCampaign.Padding = new Thickness(10, 5);
BtnNewCampaign.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center;
BtnNewCampaign.Id = "BtnNewCampaign";
Spacing = 16;
HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center;
VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center;
Width = 300;
Padding = new Thickness(10);
Widgets.Add(grid1);
Widgets.Add(BtnNewCampaign);
}
public TextBox TxtCampaign;
public TextButton BtnNewCampaign;
}
}

View File

@ -0,0 +1,11 @@
/* Generated by MyraPad at 02/09/2021 16:26:04 */
namespace Sledgemapper.UI
{
public partial class MapWindow
{
public MapWindow()
{
BuildUI();
}
}
}

View File

@ -0,0 +1,14 @@
<Project>
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="MapWindow" OutputPath="C:\src\Map\Sledgemapper\UI" />
<VerticalStackPanel Spacing="16" HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" Padding="10">
<Grid ColumnSpacing="25" RowSpacing="10">
<Grid.ColumnsProportions>
<Proportion Type="Pixels" Value="60" />
<Proportion Type="Fill" />
</Grid.ColumnsProportions>
<Label Text="Map" />
<TextBox GridColumn="1" Id="TxtCampaign" />
</Grid>
<TextButton Text="New" Padding="10, 5" HorizontalAlignment="Center" Id="BtnNewCampaign" />
</VerticalStackPanel>
</Project>