more ui refactoring
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-15 11:51:59 +01:00
parent 09c32c605e
commit 9033151006
6 changed files with 375 additions and 166 deletions

View file

@ -67,7 +67,7 @@ namespace Sledgemapper
_communicationManager.Connection.Reconnected += OnHubReconnected;
_communicationManager.Connection.Reconnecting += OnHubReconnecting;
_communicationManager.Connection.Closed += OnHubDisconnected;
_state = new State();
_state = State.Instance;
_settings = new Settings();
_vector2Pool = ArrayPool<Vector2>.Create();
_messenger = new TinyMessengerHub();
@ -198,7 +198,7 @@ namespace Sledgemapper
ResetRenderTarget();
_mainWidget = new MainWidget(_communicationManager, _state, _settings, _cachedContent, _messenger, Window);
_mainWidget = new MainWidget(_communicationManager, _settings, _cachedContent, _messenger, Window);

View file

@ -5,8 +5,44 @@ using System.Collections.Generic;
namespace Sledgemapper
{
public class State
public sealed class State
{
private static readonly State instance = new State();
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static State()
{
}
private State()
{
CurrentTileId = "";
CurrentWallId = "";
CurrentOverlayId = "";
SelectedTile = new() { X = 1, Y = 1 };
HoveredTile = new() { X = 1, Y = 1 };
SelectedWall = new() { X = 1, Y = 1 };
SelectedOverlay = new() { X = 1, Y = 1 };
SelectedNote = new() { X = 1, Y = 1 };
TileSize = 30;
LineWidth = 1;
ViewportCenter = new(0, 0, 0);
}
public static State Instance
{
get
{
return instance;
}
}
public Tile SelectedTile { get; set; }
public Tile HoveredTile { get; set; }
public Wall SelectedWall { get; set; }
@ -25,20 +61,20 @@ namespace Sledgemapper
public bool ShowCellNumbers { get; set; }
public Vector3 ViewportCenter { get; set; }
public State()
{
CurrentTileId = "";
CurrentWallId = "";
CurrentOverlayId = "";
SelectedTile = new() { X = 1, Y = 1 };
HoveredTile = new() { X = 1, Y = 1 };
SelectedWall = new() { X = 1, Y = 1 };
SelectedOverlay = new() { X = 1, Y = 1 };
SelectedNote = new() { X = 1, Y = 1 };
TileSize = 30;
LineWidth=1;
ViewportCenter = new(0, 0, 0);
}
//public State()
//{
// CurrentTileId = "";
// CurrentWallId = "";
// CurrentOverlayId = "";
// SelectedTile = new() { X = 1, Y = 1 };
// HoveredTile = new() { X = 1, Y = 1 };
// SelectedWall = new() { X = 1, Y = 1 };
// SelectedOverlay = new() { X = 1, Y = 1 };
// SelectedNote = new() { X = 1, Y = 1 };
// TileSize = 30;
// LineWidth=1;
// ViewportCenter = new(0, 0, 0);
//}
public void SelectClosestWall(Point mousePosition)
{

View file

@ -0,0 +1,158 @@
using Exceptionless;
using Myra.Graphics2D.Brushes;
using Myra.Graphics2D.UI;
using System;
using System.Threading.Tasks;
using TinyMessenger;
namespace Sledgemapper.UI
{
public partial class CampaignList
{
private readonly CommunicationManager CommunicationManager;
private readonly Window Window;
private readonly TinyMessengerHub Messenger;
private Settings _settings;
public CampaignList(CommunicationManager communicationManager, Window window, TinyMessengerHub messenger, Settings settings)
{
BuildUI();
CommunicationManager = communicationManager;
Window = window;
Messenger = messenger;
_settings = settings;
BtnNewCampaign.Click += (s, e) =>
{
window.Close();
OnMenuCampaignNew(s, e);
};
BtnLoadCampaign.Click += (s, e) =>
{
if (campaignSelected)
{
campaignSelected = false;
window.Close();
}
};
BtnCancelCampaign.Click += (s, e) =>
{
Window.Close();
};
}
private void OnMenuCampaignNew(object sender, EventArgs e)
{
if (sender is MenuItem && !((MenuItem)sender).Enabled)
{
return;
}
Window window = new()
{
Title = "New campaign"
};
var content = new CampaignWindow();
//content.BtnNewCampaign.Text = "N";
content.BtnNewCampaign.Click += OnButtonNewCampaignClicked;
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;
var localContent = item.GetParentContentInWindow<Widget>();
State.Instance.CampaignName = item.ItemName.Text;
var list = item.Parent as Myra.Graphics2D.UI.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.OverlayTintColor);
campaignSelected = true;
}
private async void OnButtonNewCampaignClicked(object sender, EventArgs e)
{
var localContent = ((TextButton)sender).GetParentContentInWindow<CampaignWindow>();// localWindow.Content as PlayerWindow;
var isValid = localContent.Content.TxtCampaign.ValidateTextbox();
if (!isValid)
{
return;
}
//if (CommunicationManager.Connection.State != HubConnectionState.Connected)
//{
// lblConnectionStatus.Text = "Connecting";
// await CommunicationManager.Connection.StartAsync();
// UpdateConnectionState(CommunicationManager.Connection);
//}
var successful = false;
try
{
await CommunicationManager.Api.NewCampaign(localContent.Content.TxtCampaign.Text);
//if (result)
//{
// CommunicationManager.SessionData.SessionName = localContent.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.TxtSession.Text);
//CommunicationManager.SessionData.SessionId = result2.SessionId;
//CommunicationManager.SessionData.SessionName = localContent.TxtSession.Text;
}
catch (Exception ex)
{
ExceptionlessClient.Default.SubmitException(ex);
}
//if (successful)
//{
// //CommunicationManager.SessionData.SessionName = localContent.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;
// localWindow.Close();
//}
localContent.Window.Close();
}
public async Task LoadCampaigns()
{
var campaigns = await CommunicationManager.Api.GetCampaigns();
foreach (var campaign in campaigns)
{
var item = new UI.ListItem();
item.ItemName.Text = campaign.Name;
item.TouchUp += OnCampaignSelected;
StackCampaignsList.AddChild(item);
}
}
}
}

View file

@ -0,0 +1,25 @@
using Myra.Graphics2D.UI;
using System.Threading.Tasks;
using TinyMessenger;
namespace Sledgemapper.UI
{
public partial class CampaignWindow
{
private readonly CommunicationManager CommunicationManager;
private readonly Window Window;
private readonly TinyMessengerHub Messenger;
public CampaignWindow(CommunicationManager communicationManager, Window window, TinyMessengerHub messenger)
{
BuildUI();
CommunicationManager = communicationManager;
Window = window;
Messenger = messenger;
}
}
}

View file

@ -20,25 +20,24 @@ namespace Sledgemapper.UI
{
public partial class MainWidget
{
private AuthenticateResponse _authResponse;
private readonly CommunicationManager CommunicationManager;
private State _state;
private Settings _settings;
private readonly TinyMessengerHub _messenger;
private readonly CachedContent _cachedContent;
private readonly GameWindow Window;
public MainWidget(CommunicationManager communicationManager, State state, Settings settings, CachedContent cachedContent, TinyMessengerHub messenger, GameWindow window)
public MainWidget(CommunicationManager communicationManager, Settings settings, CachedContent cachedContent, TinyMessengerHub messenger, GameWindow window)
{
BuildUI();
CommunicationManager = communicationManager;
_state = state;
_settings = settings;
_cachedContent = cachedContent;
_messenger=messenger;
Window = window;
_messenger = messenger;
MenuConnectLogin.Selected += OnMenuConnectLoginSelected;
MenuConnectSync.Selected += OnMenuConnectSyncSelected;
MenuFileLoad.Selected += OnMenuFileLoadSelected;
@ -63,6 +62,11 @@ namespace Sledgemapper.UI
MenuConnectJoin.Enabled = false;
MenuConnectSync.Enabled = false;
MenuConnectUpload.Enabled = false;
MenuCampaignOpen.Enabled = false;
MenuCampaignPlayers.Enabled = false;
MenuCampaingNew.Enabled = false;
MenuMapNew.Enabled = false;
MenuMapOpen.Enabled = false;
BtnToolbarLine.Click += OnBtnToolbarLinClicked;
BtnToolbarRoom.Click += OnBtnToolbarRoomClicked;
BtnToolbarDelete.Click += OnBtnToolbarDeleteClicked;
@ -74,27 +78,30 @@ namespace Sledgemapper.UI
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;
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);
await CommunicationManager.Connection.StartAsync();
UpdateConnectionState(CommunicationManager.Connection);
}
private void OnLoginSuccesfulMessage(LoginSuccesfulMessage obj)
{
MenuConnectNew.Enabled = true;
MenuConnectJoin.Enabled = true;
MenuConnectNew.Enabled = true;
MenuConnectJoin.Enabled = true;
MenuCampaignOpen.Enabled = true;
MenuCampaignPlayers.Enabled = true;
MenuCampaingNew.Enabled = true;
lblUsername.Text = $"{_authResponse.Username} - {_authResponse.Initials}";
lblUsername.Text = $"{obj.UserName} - {obj.Initials}";
}
public void ClearSelection()
@ -127,7 +134,7 @@ namespace Sledgemapper.UI
Title = "Login"
};
var content = new LoginRegisterWindow(CommunicationManager, window,_messenger);
var content = new LoginRegisterWindow(CommunicationManager, window, _messenger);
window.Content = content;
window.ShowModal(Desktop);
}
@ -145,7 +152,7 @@ namespace Sledgemapper.UI
Title = "New mapping session"
};
var content = new SessionWindow(CommunicationManager,_messenger,window, _state);
var content = new SessionWindow(CommunicationManager, _messenger, window);
window.Content = content;
window.ShowModal(Desktop);
@ -296,7 +303,7 @@ namespace Sledgemapper.UI
private void OnMenuViewShowCellNUmbersSelected(object sender, EventArgs e)
{
_state.ShowCellNumbers = !_state.ShowCellNumbers;
State.Instance.ShowCellNumbers = !State.Instance.ShowCellNumbers;
}
private void OnMenuViewCenterOnSelectionSelected(object sender, EventArgs e)
@ -331,16 +338,16 @@ namespace Sledgemapper.UI
private void CenterOnSelectedTile()
{
CenterOnTile(_state.SelectedTile.X, _state.SelectedTile.Y);
CenterOnTile(State.Instance.SelectedTile.X, State.Instance.SelectedTile.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 dx = center.X - x * _state.TileSize - _state.ViewportCenter.X;
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);
var center = new Point((Window.ClientBounds.Width + 200) / 2 - State.Instance.TileSize / 2, Window.ClientBounds.Height / 2 - State.Instance.TileSize / 2);
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);
}
@ -357,12 +364,12 @@ namespace Sledgemapper.UI
};
var content = new CampaignWindow();
//content.BtnNewCampaign.Text = "N";
content.BtnNewCampaign.Click += OnButtonNewCampaignClicked;
window.Content = content;
////content.BtnNewCampaign.Text = "N";
//content.BtnNewCampaign.Click += OnButtonNewCampaignClicked;
//window.Content = content;
window.ShowModal(Desktop);
content.TxtCampaign.SetKeyboardFocus();
//window.ShowModal(Desktop);
//content.TxtCampaign.SetKeyboardFocus();
}
private async void OnMenuCampaignOpen(object sender, EventArgs e)
@ -377,40 +384,41 @@ namespace Sledgemapper.UI
Title = "Campaigns"
};
var content = new CampaignList();
var campaigns = await CommunicationManager.Api.GetCampaigns();
foreach (var campaign in campaigns)
{
var item = new UI.ListItem();
item.ItemName.Text = campaign.Name;
var content = new CampaignList(CommunicationManager, window, _messenger, _settings);
await content.LoadCampaigns();
//var campaigns = await CommunicationManager.Api.GetCampaigns();
//foreach (var campaign in campaigns)
//{
// var item = new UI.ListItem();
// item.ItemName.Text = campaign.Name;
item.TouchUp += OnCampaignSelected;
content.StackCampaignsList.AddChild(item);
}
// item.TouchUp += OnCampaignSelected;
// content.StackCampaignsList.AddChild(item);
//}
//content.BtnNewCampaign.Text = "N";
content.BtnNewCampaign.Click += (s, e) =>
{
window.Close();
OnMenuCampaignNew(s, e);
};
//content.BtnNewCampaign.Click += (s, e) =>
//{
// window.Close();
// OnMenuCampaignNew(s, e);
//};
content.BtnLoadCampaign.Click += (s, e) =>
{
if (campaignSelected)
{
campaignSelected = false;
window.Close();
}
};
//content.BtnLoadCampaign.Click += (s, e) =>
//{
// if (campaignSelected)
// {
// campaignSelected = false;
// window.Close();
// }
//};
content.BtnCancelCampaign.Click += (s, e) =>
{
//content.BtnCancelCampaign.Click += (s, e) =>
//{
window.Close();
};
// window.Close();
//};
window.Content = content;
@ -418,24 +426,6 @@ namespace Sledgemapper.UI
// content.TxtCampaign.SetKeyboardFocus();
}
private bool campaignSelected;
private void OnCampaignSelected(object sender, EventArgs e)
{
var item = sender as UI.ListItem;
var localContent = item.GetParentContentInWindow<Widget>();
_state.CampaignName = item.ItemName.Text;
var list = item.Parent as Myra.Graphics2D.UI.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.OverlayTintColor);
campaignSelected = true;
}
private void OnMapSelected(object sender, EventArgs e)
{
var item = sender as UI.ListItem;
@ -463,7 +453,7 @@ namespace Sledgemapper.UI
};
var content = new PlayerList();
var players = await CommunicationManager.Api.GetPlayers(_state.CampaignName);
var players = await CommunicationManager.Api.GetPlayers(State.Instance.CampaignName);
foreach (var player in players)
{
var item = new UI.ListItem();
@ -500,7 +490,7 @@ namespace Sledgemapper.UI
};
var content = new MapList();
var campaigns = await CommunicationManager.Api.GetMaps(_state.CampaignName);
var campaigns = await CommunicationManager.Api.GetMaps(State.Instance.CampaignName);
foreach (var campaign in campaigns)
{
var item = new UI.ListItem();
@ -610,7 +600,7 @@ namespace Sledgemapper.UI
var successful = false;
try
{
await CommunicationManager.Api.InvitePlayer(_state.CampaignName, localContent.Content.TxtCampaign.Text);
await CommunicationManager.Api.InvitePlayer(State.Instance.CampaignName, localContent.Content.TxtCampaign.Text);
//if (result)
//{
@ -646,64 +636,64 @@ namespace Sledgemapper.UI
}
private async void OnButtonNewCampaignClicked(object sender, EventArgs e)
{
var localContent = ((TextButton)sender).GetParentContentInWindow<CampaignWindow>();// localWindow.Content as PlayerWindow;
//private async void OnButtonNewCampaignClicked(object sender, EventArgs e)
//{
// var localContent = ((TextButton)sender).GetParentContentInWindow<CampaignWindow>();// localWindow.Content as PlayerWindow;
var isValid = localContent.Content.TxtCampaign.ValidateTextbox();
if (!isValid)
{
return;
}
// var isValid = localContent.Content.TxtCampaign.ValidateTextbox();
// if (!isValid)
// {
// return;
// }
//if (CommunicationManager.Connection.State != HubConnectionState.Connected)
//{
// lblConnectionStatus.Text = "Connecting";
// await CommunicationManager.Connection.StartAsync();
// UpdateConnectionState(CommunicationManager.Connection);
//}
// //if (CommunicationManager.Connection.State != HubConnectionState.Connected)
// //{
// // lblConnectionStatus.Text = "Connecting";
// // await CommunicationManager.Connection.StartAsync();
// // UpdateConnectionState(CommunicationManager.Connection);
// //}
var successful = false;
try
{
await CommunicationManager.Api.NewCampaign(localContent.Content.TxtCampaign.Text);
// var successful = false;
// try
// {
// await CommunicationManager.Api.NewCampaign(localContent.Content.TxtCampaign.Text);
//if (result)
//{
// CommunicationManager.SessionData.SessionName = localContent.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.TxtSession.Text);
//CommunicationManager.SessionData.SessionId = result2.SessionId;
//CommunicationManager.SessionData.SessionName = localContent.TxtSession.Text;
}
catch (Exception ex)
{
ExceptionlessClient.Default.SubmitException(ex);
}
// //if (result)
// //{
// // CommunicationManager.SessionData.SessionName = localContent.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.TxtSession.Text);
// //CommunicationManager.SessionData.SessionId = result2.SessionId;
// //CommunicationManager.SessionData.SessionName = localContent.TxtSession.Text;
// }
// catch (Exception ex)
// {
// ExceptionlessClient.Default.SubmitException(ex);
// }
//if (successful)
//{
// //CommunicationManager.SessionData.SessionName = localContent.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;
// localWindow.Close();
//}
// //if (successful)
// //{
// // //CommunicationManager.SessionData.SessionName = localContent.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;
// // localWindow.Close();
// //}
localContent.Window.Close();
// localContent.Window.Close();
}
//}
private void OnBtnToolbarRoomClicked(object sender, EventArgs e)
{
_state.InsertMode = InsertMode.NewRoom;
State.Instance.InsertMode = InsertMode.NewRoom;
ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
@ -712,7 +702,7 @@ namespace Sledgemapper.UI
private void OnBtnToolbarLinClicked(object sender, EventArgs e)
{
_state.InsertMode = InsertMode.NewLine;
State.Instance.InsertMode = InsertMode.NewLine;
ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
@ -720,7 +710,7 @@ namespace Sledgemapper.UI
private void OnBtnToolbarDeleteClicked(object sender, EventArgs e)
{
_state.InsertMode = InsertMode.NewDelete;
State.Instance.InsertMode = InsertMode.NewDelete;
ClearSelection();
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
@ -773,7 +763,7 @@ namespace Sledgemapper.UI
var successful = false;
try
{
await CommunicationManager.Api.NewSession(_state.CampaignName, localContent.TxtCampaign.Text);
await CommunicationManager.Api.NewSession(State.Instance.CampaignName, localContent.TxtCampaign.Text);
//if (result)
//{
@ -811,7 +801,7 @@ namespace Sledgemapper.UI
//TODO Refactor
private void EditNote(Note note)
{
_state.SelectedNote = new Note { X = note.X, Y = note.Y, Text = note.Text };
State.Instance.SelectedNote = new Note { X = note.X, Y = note.Y, Text = note.Text };
var noteWindow = new NoteWindow();
Window window = new()
@ -833,8 +823,8 @@ namespace Sledgemapper.UI
var localContent = button.GetParentContentInWindow<NoteWindow>();
var note = new Note
{
X = _state.SelectedNote.X,
Y = _state.SelectedNote.Y,
X = State.Instance.SelectedNote.X,
Y = State.Instance.SelectedNote.Y,
Text = localContent.Content.NoteText.Text
};
CommunicationManager.SessionData.NewNote(note);

View file

@ -8,25 +8,25 @@ using TinyMessenger;
namespace Sledgemapper.UI
{
public partial class SessionWindow
{
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)
public SessionWindow(CommunicationManager communicationManager, TinyMessengerHub messenger, Window window)
{
BuildUI();
CommunicationManager=communicationManager;
Messenger=messenger;
State=state;
BuildUI();
CommunicationManager = communicationManager;
Messenger = messenger;
Window = window;
BtnLogin.Text = "Join";
BtnLogin.Click += OnButtonNewSessionClicked;
}
}
private async void OnButtonNewSessionClicked(object sender, EventArgs e)
private async void OnButtonNewSessionClicked(object sender, EventArgs e)
{
var localContent = ((TextButton)sender).GetParentContentInWindow<SessionWindow>();// localWindow.Content as PlayerWindow;
@ -44,7 +44,7 @@ namespace Sledgemapper.UI
var successful = false;
try
{
var result = await CommunicationManager.Api.NewSession(State.CampaignName, localContent.Content.TxtSession.Text);
var result = await CommunicationManager.Api.NewSession(State.Instance.CampaignName, localContent.Content.TxtSession.Text);
if (result)
{
@ -67,9 +67,9 @@ namespace Sledgemapper.UI
CommunicationManager.SessionData.Map = CommunicationManager.SessionData.Map;
CommunicationManager.SessionData.Overlays = CommunicationManager.SessionData.Overlays;
CommunicationManager.SessionData.Walls = CommunicationManager.SessionData.Walls;
localContent.Window.Close();
}
}
}
}
}