refactoring code out of main class
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
1395d93fbc
commit
9c688d363f
4 changed files with 1321 additions and 595 deletions
|
@ -276,5 +276,7 @@ namespace Sledgemapper
|
|||
|
||||
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,6 +22,8 @@ namespace Sledgemapper
|
|||
|
||||
public InsertMode InsertMode;
|
||||
public string CampaignName { get; set; }
|
||||
public bool ShowCellNumbers { get; set; }
|
||||
public Vector3 ViewportCenter { get; set; }
|
||||
|
||||
public State()
|
||||
{
|
||||
|
@ -35,6 +37,7 @@ namespace Sledgemapper
|
|||
SelectedNote = new() { X = 1, Y = 1 };
|
||||
TileSize = 30;
|
||||
LineWidth=1;
|
||||
ViewportCenter = new(0, 0, 0);
|
||||
}
|
||||
|
||||
public void SelectClosestWall(Point mousePosition)
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
using Exceptionless;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Myra.Graphics2D.Brushes;
|
||||
using Myra.Graphics2D.TextureAtlases;
|
||||
using Myra.Graphics2D.UI;
|
||||
using Myra.Graphics2D.UI.File;
|
||||
using Myra.Graphics2D.UI.Properties;
|
||||
using Newtonsoft.Json;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sledgemapper.UI
|
||||
|
@ -14,14 +21,45 @@ namespace Sledgemapper.UI
|
|||
{
|
||||
private AuthenticateResponse _authResponse;
|
||||
private readonly CommunicationManager CommunicationManager;
|
||||
|
||||
public MainWidget(CommunicationManager communicationManager)
|
||||
private readonly State _state;
|
||||
private readonly Settings _settings;
|
||||
private Texture2D _eye;
|
||||
private Texture2D _location;
|
||||
public MainWidget(CommunicationManager communicationManager, State state, Settings settings)
|
||||
{
|
||||
BuildUI();
|
||||
|
||||
_eye = Content.Load<Texture2D>("eye");
|
||||
_location = Content.Load<Texture2D>("location");
|
||||
CommunicationManager = communicationManager;
|
||||
_state = state;
|
||||
_settings = settings;
|
||||
MenuConnectLogin.Selected += OnMenuConnectLoginSelected;
|
||||
MenuConnectSync.Selected += OnMenuConnectSyncSelected;
|
||||
MenuFileLoad.Selected += OnMenuFileLoadSelected;
|
||||
MenuFileSave.Selected += OnMenuFileSaveSelected;
|
||||
MenuFileSettings.Selected += OneMenuFileSettingsSelected;
|
||||
//MenuConnectLogin.Selected += OnMenuConnectLoginSelected;
|
||||
//MenuConnectNew.Selected += OnMenuConnectNewSelected;
|
||||
MenuConnectJoin.Selected += OnMenuConnectJoinSelected;
|
||||
MenuConnectUpload.Selected += OnMenuConnectUploadSelected;
|
||||
MenuViewCenterOnSelection.Selected += OnMenuViewCenterOnSelectionSelected;
|
||||
MenuViewShowCellNUmbers.Selected += OnMenuViewShowCellNUmbersSelected;
|
||||
MenuViewShowNotes.Selected += OnMenuViewNotesSelected;
|
||||
|
||||
MenuCampaingNew.Selected += OnMenuCampaignNew;
|
||||
MenuCampaignOpen.Selected += OnMenuCampaignOpen;
|
||||
MenuCampaignPlayers.Selected += OnMenuCampaignPlayersSelected;
|
||||
|
||||
MenuMapOpen.Selected += OnMenuMapOpen;
|
||||
MenuMapNew.Selected += OnMenuMapNew;
|
||||
|
||||
MenuConnectNew.Enabled = false;
|
||||
MenuConnectJoin.Enabled = false;
|
||||
MenuConnectSync.Enabled = false;
|
||||
MenuConnectUpload.Enabled = false;
|
||||
BtnToolbarLine.Click += OnBtnToolbarLinClicked;
|
||||
BtnToolbarRoom.Click += OnBtnToolbarRoomClicked;
|
||||
BtnToolbarDelete.Click += OnBtnToolbarDeleteClicked;
|
||||
}
|
||||
|
||||
|
||||
|
@ -288,7 +326,7 @@ namespace Sledgemapper.UI
|
|||
|
||||
if (CommunicationManager.Connection.State != HubConnectionState.Connected)
|
||||
{
|
||||
_mainWidget.lblConnectionStatus.Text = "Connecting";
|
||||
lblConnectionStatus.Text = "Connecting";
|
||||
await CommunicationManager.Connection.StartAsync();
|
||||
UpdateConnectionState(CommunicationManager.Connection);
|
||||
}
|
||||
|
@ -300,16 +338,16 @@ namespace Sledgemapper.UI
|
|||
|
||||
if (result)
|
||||
{
|
||||
_sessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||
_sessionData.MapEntityAdded -= OnMapEntityAdded;
|
||||
_sessionData.MapEntityDeleted -= OnMapEntityDeleted;
|
||||
_sessionData.MapEntityAdded += OnMapEntityAdded;
|
||||
_sessionData.MapEntityDeleted += OnMapEntityDeleted;
|
||||
CommunicationManager.SessionData.SessionName = localContent.Content.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.Content.TxtSession.Text);
|
||||
_sessionData.SessionId = result2.SessionId;
|
||||
_sessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||
CommunicationManager.SessionData.SessionId = result2.SessionId;
|
||||
CommunicationManager.SessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -318,11 +356,11 @@ namespace Sledgemapper.UI
|
|||
|
||||
if (successful)
|
||||
{
|
||||
_sessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||
CommunicationManager.SessionData.Map = _sessionData.Map;
|
||||
CommunicationManager.SessionData.Overlays = _sessionData.Overlays;
|
||||
CommunicationManager.SessionData.Walls = _sessionData.Walls;
|
||||
lblSessionName.Text = _sessionData.SessionName;
|
||||
CommunicationManager.SessionData.SessionName = localContent.Content.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;
|
||||
localContent.Window.Close();
|
||||
|
@ -359,6 +397,702 @@ namespace Sledgemapper.UI
|
|||
return (localWindow, localContent);
|
||||
}
|
||||
|
||||
private void UpdateConnectionState(HubConnection connection)
|
||||
{
|
||||
switch (connection.State)
|
||||
{
|
||||
case HubConnectionState.Connected:
|
||||
lblConnectionStatus.Text = "Connected";
|
||||
break;
|
||||
case HubConnectionState.Connecting:
|
||||
lblConnectionStatus.Text = "Connecting";
|
||||
break;
|
||||
case HubConnectionState.Disconnected:
|
||||
lblConnectionStatus.Text = "Disconnected";
|
||||
|
||||
break;
|
||||
case HubConnectionState.Reconnecting:
|
||||
lblConnectionStatus.Text = "Reconnecting";
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMapEntityAdded(object sender, MapEntityAddedEventArgs e)
|
||||
{
|
||||
CommunicationManager.Enqueue(e.MapEntity, TileAction.Add);
|
||||
}
|
||||
|
||||
private void OnMapEntityDeleted(object sender, MapEntityDeletedEventArgs e)
|
||||
{
|
||||
CommunicationManager.Enqueue(e.MapEntity, TileAction.Delete);
|
||||
}
|
||||
|
||||
private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var serverMap = await CommunicationManager.Api.Session(CommunicationManager.SessionData.SessionName);
|
||||
CommunicationManager.SessionData.Overlays = serverMap.Overlays;
|
||||
CommunicationManager.SessionData.Map = serverMap.Map;
|
||||
CommunicationManager.SessionData.Walls = serverMap.Walls;
|
||||
CommunicationManager.SessionData.Notes = serverMap.Notes;
|
||||
CommunicationManager.SessionData.Lines = serverMap.Lines;
|
||||
CommunicationManager.SessionData.Rooms = serverMap.Rooms;
|
||||
}
|
||||
|
||||
private async void OnMenuConnectUploadSelected(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await CommunicationManager.Api.SaveSnapshot(CommunicationManager.SessionData, CommunicationManager.SessionData.SessionName);
|
||||
}
|
||||
|
||||
private void OnMenuFileSaveSelected(object sender, EventArgs e)
|
||||
{
|
||||
FileDialog dialog = new(FileDialogMode.SaveFile)
|
||||
{
|
||||
Filter = "*.map"
|
||||
};
|
||||
|
||||
dialog.Closed += (s, a) =>
|
||||
{
|
||||
if (!dialog.Result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using StreamWriter file = File.CreateText(dialog.FilePath);
|
||||
JsonSerializer serializer = new();
|
||||
serializer.Serialize(file, CommunicationManager.SessionData);
|
||||
};
|
||||
|
||||
dialog.ShowModal(Desktop);
|
||||
}
|
||||
|
||||
private void OnMenuFileLoadSelected(object sender, EventArgs e)
|
||||
{
|
||||
var dialog = new FileDialog(FileDialogMode.OpenFile)
|
||||
{
|
||||
Filter = "*.map"
|
||||
};
|
||||
|
||||
dialog.Closed += (s, a) =>
|
||||
{
|
||||
if (!dialog.Result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
using StreamReader file = File.OpenText(dialog.FilePath);
|
||||
JsonSerializer serializer = new();
|
||||
var loadData = (Session)serializer.Deserialize(file, typeof(Session));
|
||||
CommunicationManager.SessionData.Map = loadData.Map;
|
||||
CommunicationManager.SessionData.Overlays = loadData.Overlays;
|
||||
CommunicationManager.SessionData.Walls = loadData.Walls;
|
||||
CommunicationManager.SessionData.Rooms = loadData.Rooms;
|
||||
CommunicationManager.SessionData.Lines = loadData.Lines;
|
||||
};
|
||||
|
||||
dialog.ShowModal(Desktop);
|
||||
}
|
||||
|
||||
private void OneMenuFileSettingsSelected(object sender, EventArgs e)
|
||||
{
|
||||
var propertyGrid = new PropertyGrid
|
||||
{
|
||||
Object = _settings,
|
||||
Width = 350
|
||||
};
|
||||
|
||||
var _windowEditor = new Window
|
||||
{
|
||||
Title = "Object Editor",
|
||||
Content = propertyGrid
|
||||
};
|
||||
_windowEditor.ShowModal(Desktop);
|
||||
}
|
||||
|
||||
private void OnMenuConnectJoinSelected(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Window window = new()
|
||||
{
|
||||
Title = "Join mapping session"
|
||||
};
|
||||
|
||||
var content = new SessionWindow();
|
||||
content.BtnLogin.Text = "Join";
|
||||
content.BtnLogin.Click += OnButtonJoinSessionClicked;
|
||||
|
||||
window.Content = content;
|
||||
|
||||
window.ShowModal(Desktop);
|
||||
content.TxtSession.SetKeyboardFocus();
|
||||
}
|
||||
|
||||
private void OnMenuViewShowCellNUmbersSelected(object sender, EventArgs e)
|
||||
{
|
||||
_state.ShowCellNumbers = !_state.ShowCellNumbers;
|
||||
}
|
||||
|
||||
private void OnMenuViewCenterOnSelectionSelected(object sender, EventArgs e)
|
||||
{
|
||||
CenterOnSelectedTile();
|
||||
}
|
||||
|
||||
private void OnMenuViewNotesSelected(object sender, EventArgs e)
|
||||
{
|
||||
Window window = new()
|
||||
{
|
||||
Title = "Notes"
|
||||
};
|
||||
|
||||
var content = new NoteList();
|
||||
|
||||
for (var i = 0; i < CommunicationManager.SessionData.Notes.Values.Count; i++)
|
||||
{
|
||||
var note = CommunicationManager.SessionData.Notes.Values.ElementAt(i);
|
||||
var item = new NoteListItem();
|
||||
item.LblNoteText.Text = $"{note.ToString()} - {note.Text}";
|
||||
item.BtnNoteCenter.Image = new TextureRegion(_location);
|
||||
item.BtnNoteView.Image = new TextureRegion(_eye);
|
||||
item.BtnNoteCenter.Click += (s, e) => { CenterOnTile(note.X, note.Y); };
|
||||
item.BtnNoteView.Click += (s, e) => { EditNote(note); window.Close(); };
|
||||
content.StackNotesList.AddChild(item);
|
||||
}
|
||||
|
||||
window.Content = content;
|
||||
window.ShowModal(Desktop);
|
||||
}
|
||||
|
||||
private void CenterOnSelectedTile()
|
||||
{
|
||||
CenterOnTile(_state.SelectedTile.X, _state.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.X += dx;
|
||||
_state.ViewportCenter.Y += dy;
|
||||
}
|
||||
|
||||
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 async void OnMenuCampaignOpen(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Window window = new()
|
||||
{
|
||||
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;
|
||||
|
||||
item.TouchUp += OnCampaignSelected;
|
||||
content.StackCampaignsList.AddChild(item);
|
||||
}
|
||||
//content.BtnNewCampaign.Text = "N";
|
||||
|
||||
|
||||
|
||||
content.BtnNewCampaign.Click += (s, e) =>
|
||||
{
|
||||
window.Close();
|
||||
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;
|
||||
var localContent = GetParentContentInWindow<Widget>(item);
|
||||
_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;
|
||||
var localContent = GetParentContentInWindow<Widget>(item);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private async void OnMenuCampaignPlayersSelected(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Window window = new()
|
||||
{
|
||||
Title = "Players"
|
||||
};
|
||||
|
||||
var content = new PlayerList();
|
||||
var players = await CommunicationManager.Api.GetPlayers(_state.CampaignName);
|
||||
foreach (var player in players)
|
||||
{
|
||||
var item = new UI.ListItem();
|
||||
item.ItemName.Text = player.UserName;
|
||||
|
||||
|
||||
content.StackCampaignsList.AddChild(item);
|
||||
}
|
||||
//content.BtnNewCampaign.Text = "N";
|
||||
|
||||
|
||||
|
||||
content.BtnInvitePlayer.Click += (s, e) =>
|
||||
{
|
||||
window.Close();
|
||||
ShowAddPLayerWindow();
|
||||
};
|
||||
|
||||
window.Content = content;
|
||||
|
||||
window.ShowModal(Desktop);
|
||||
// content.TxtCampaign.SetKeyboardFocus();
|
||||
}
|
||||
private async void OnMenuMapOpen(object sender, EventArgs e)
|
||||
{
|
||||
if (!((MenuItem)sender).Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Window window = new()
|
||||
{
|
||||
Title = "Maps"
|
||||
};
|
||||
|
||||
var content = new MapList();
|
||||
var campaigns = await CommunicationManager.Api.GetMaps(_state.CampaignName);
|
||||
foreach (var campaign in campaigns)
|
||||
{
|
||||
var item = new UI.ListItem();
|
||||
item.ItemName.Text = campaign.SessionName;
|
||||
item.TouchUp += OnMapSelected;
|
||||
content.StackCampaignsList.AddChild(item);
|
||||
}
|
||||
//content.BtnNewCampaign.Text = "N";
|
||||
|
||||
|
||||
|
||||
content.BtnNewCampaign.Click += (s, e) =>
|
||||
{
|
||||
window.Close();
|
||||
OnMenuMapNew(s, e);
|
||||
};
|
||||
|
||||
window.Content = content;
|
||||
|
||||
window.ShowModal(Desktop);
|
||||
// content.TxtCampaign.SetKeyboardFocus();
|
||||
}
|
||||
|
||||
private void ShowAddPLayerWindow()
|
||||
{
|
||||
Window window = new()
|
||||
{
|
||||
Title = "Invite player"
|
||||
};
|
||||
|
||||
var content = new PlayerWindow();
|
||||
//content.BtnNewCampaign.Text = "N";
|
||||
content.BtnNewCampaign.Click += OnButtonInvitePlayerClicked;
|
||||
window.Content = content;
|
||||
|
||||
window.ShowModal(Desktop);
|
||||
content.TxtCampaign.SetKeyboardFocus();
|
||||
}
|
||||
|
||||
private async void OnButtonJoinSessionClicked(object sender, EventArgs e)
|
||||
{
|
||||
var localContent = GetParentContentInWindow<SessionWindow>(((TextButton)sender));
|
||||
|
||||
var isValid = ValidateTextbox(localContent.Content.TxtSession);
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (CommunicationManager.Connection.State != HubConnectionState.Connected)
|
||||
{
|
||||
lblConnectionStatus.Text = "Connecting";
|
||||
await CommunicationManager.Connection.StartAsync();
|
||||
UpdateConnectionState(CommunicationManager.Connection);
|
||||
}
|
||||
|
||||
var successful = false;
|
||||
try
|
||||
{
|
||||
var result = await CommunicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.Content.TxtSession.Text);
|
||||
if (result != null)
|
||||
{
|
||||
CommunicationManager.SessionData.Map = result.Map;
|
||||
CommunicationManager.SessionData.Walls = result.Walls;
|
||||
CommunicationManager.SessionData.Overlays = result.Overlays;
|
||||
|
||||
CommunicationManager.SessionData.MapEntityAdded -= OnMapEntityAdded;
|
||||
CommunicationManager.SessionData.MapEntityDeleted -= OnMapEntityDeleted;
|
||||
CommunicationManager.SessionData.MapEntityAdded += OnMapEntityAdded;
|
||||
CommunicationManager.SessionData.MapEntityDeleted += OnMapEntityDeleted;
|
||||
CommunicationManager.SessionData.SessionId = result.SessionId;
|
||||
CommunicationManager.SessionData.SessionName = result.SessionName;
|
||||
}
|
||||
successful = result != null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
if (successful)
|
||||
{
|
||||
CommunicationManager.SessionData.SessionName = localContent.Content.TxtSession.Text;
|
||||
lblSessionName.Text = CommunicationManager.SessionData.SessionName;
|
||||
MenuConnectSync.Enabled = true;
|
||||
MenuConnectUpload.Enabled = true;
|
||||
localContent.Window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnButtonInvitePlayerClicked(object sender, EventArgs e)
|
||||
{
|
||||
var localContent = GetParentContentInWindow<PlayerWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
|
||||
var isValid = ValidateTextbox(localContent.Content.TxtCampaign);
|
||||
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.InvitePlayer(_state.CampaignName, 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();
|
||||
|
||||
}
|
||||
|
||||
private async void OnButtonNewCampaignClicked(object sender, EventArgs e)
|
||||
{
|
||||
var localContent = GetParentContentInWindow<CampaignWindow>(((TextButton)sender));// localWindow.Content as PlayerWindow;
|
||||
|
||||
var isValid = ValidateTextbox(localContent.Content.TxtCampaign);
|
||||
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();
|
||||
|
||||
}
|
||||
private void OnBtnToolbarRoomClicked(object sender, EventArgs e)
|
||||
{
|
||||
_state.InsertMode = InsertMode.NewRoom;
|
||||
ClearSelection();
|
||||
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
|
||||
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
|
||||
|
||||
}
|
||||
|
||||
private void OnBtnToolbarLinClicked(object sender, EventArgs e)
|
||||
{
|
||||
_state.InsertMode = InsertMode.NewLine;
|
||||
ClearSelection();
|
||||
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
|
||||
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
|
||||
}
|
||||
|
||||
private void OnBtnToolbarDeleteClicked(object sender, EventArgs e)
|
||||
{
|
||||
_state.InsertMode = InsertMode.NewDelete;
|
||||
|
||||
ClearSelection();
|
||||
((ImageTextButton)sender).Border = new SolidBrush(Color.Red);
|
||||
((ImageTextButton)sender).BorderThickness = new Myra.Graphics2D.Thickness(2);
|
||||
}
|
||||
|
||||
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)
|
||||
//{
|
||||
// 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)
|
||||
//{
|
||||
// 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();
|
||||
//}
|
||||
|
||||
localWindow.Close();
|
||||
}
|
||||
|
||||
//TODO Refactor
|
||||
private void EditNote(Note note)
|
||||
{
|
||||
_state.SelectedNote = new Note { X = note.X, Y = note.Y, Text = note.Text };
|
||||
var noteWindow = new NoteWindow();
|
||||
|
||||
Window window = new()
|
||||
{
|
||||
Title = $" Note on {note.X}:{note.Y}"
|
||||
};
|
||||
noteWindow.NoteText.Text = note.Text;
|
||||
noteWindow.BtnOk.Click += OnButtonNoteOkClick;
|
||||
noteWindow.BtnCancel.Click += OnButtonNoteCancelClick;
|
||||
|
||||
window.Content = noteWindow;
|
||||
window.ShowModal(Desktop);
|
||||
noteWindow.NoteText.SetKeyboardFocus();
|
||||
}
|
||||
|
||||
private void OnButtonNoteOkClick(object sender, EventArgs e)
|
||||
{
|
||||
var button = ((TextButton)sender);
|
||||
var localContent = GetParentContentInWindow<NoteWindow>(button);
|
||||
var note = new Note
|
||||
{
|
||||
X = _state.SelectedNote.X,
|
||||
Y = _state.SelectedNote.Y,
|
||||
Text = localContent.Content.NoteText.Text
|
||||
};
|
||||
CommunicationManager.SessionData.NewNote(note);
|
||||
localContent.Window.Close();
|
||||
}
|
||||
|
||||
private void OnButtonNoteCancelClick(object sender, EventArgs e)
|
||||
{
|
||||
var button = ((TextButton)sender);
|
||||
var content = GetParentContentInWindow<Widget>(button);
|
||||
content.Window.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue