still moving code around
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele 2021-09-15 23:28:30 +01:00
parent b8d27a2a6f
commit 98e5f6bc89
8 changed files with 168 additions and 218 deletions

View File

@ -9,6 +9,29 @@ namespace Sledgemapper
{
public class CachedContent
{
private static readonly CachedContent instance = new CachedContent();
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static CachedContent()
{
}
private CachedContent()
{
}
public static CachedContent Instance
{
get
{
return instance;
}
}
public Texture2D Eye { get; set; }
public Texture2D Location { get; set; }
}

View File

@ -13,4 +13,14 @@ public class MapOpenedMessage : TinyMessenger.TinyMessageBase
public MapOpenedMessage(object sender) : base(sender)
{
}
}
public class CenterOnTileMessage : TinyMessenger.TinyMessageBase
{
public CenterOnTileMessage(object sender) : base(sender)
{
}
public int X { get; internal set; }
public int Y { get; internal set; }
}

View File

@ -73,27 +73,27 @@ namespace Sledgemapper
private async Task OnHubDisconnected(Exception arg)
{
// ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Hub disconnected", Type = "SignalR Client Events", Source = _settings.MachineName });
// ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Hub disconnected", Type = "SignalR Client Events", Source = _settings.MachineName });
_mainWidget.lblConnectionStatus.Text = "Disconnected";
await Task.Yield();
}
private async Task OnHubReconnecting(Exception arg)
{
// ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Reconnecting Hub", Type = "SignalR Client Events", Source = _settings.MachineName });
// ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Reconnecting Hub", Type = "SignalR Client Events", Source = _settings.MachineName });
_mainWidget.lblConnectionStatus.Text = "Reconnecting";
await Task.Yield();
}
private async Task OnHubReconnected(string arg)
{
// ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Hub reconnected", Type = "SignalR Client Events", Source = _settings.MachineName });
// ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Hub reconnected", Type = "SignalR Client Events", Source = _settings.MachineName });
_mainWidget.lblConnectionStatus.Text = "Connected";
await Task.Yield();
}
protected override void Initialize()
{
// ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Initialize", Type = "AppLifecycle", Source = _settings.MachineName });
// ExceptionlessClient.Default.SubmitEvent(new Event { Message = "Initialize", Type = "AppLifecycle", Source = _settings.MachineName });
IsMouseVisible = true;
Window.AllowUserResizing = true;
Window.ClientSizeChanged += OnClientSizeChanged;
@ -189,14 +189,14 @@ namespace Sledgemapper
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
_cachedContent = new CachedContent();
_cachedContent = CachedContent.Instance;
outlineShader = Content.Load<Effect>("shaders/OutlineShader");
MyraEnvironment.Game = this;
ResetRenderTarget();
_mainWidget = new MainWidget(_communicationManager, _settings, _cachedContent, _messenger, Window);
_mainWidget = new MainWidget(_communicationManager, _settings, _messenger, Window);

View File

@ -6,21 +6,21 @@ using TinyMessenger;
namespace Sledgemapper.UI
{
public partial class CampaignList
{
public partial class CampaignList
{
private readonly CommunicationManager CommunicationManager;
private readonly Window Window;
private readonly TinyMessengerHub Messenger;
private readonly Desktop Desktop;
private Settings _settings;
public CampaignList(CommunicationManager communicationManager, Window window, TinyMessengerHub messenger, Settings settings, Desktop desktop)
public CampaignList(CommunicationManager communicationManager, Window window, TinyMessengerHub messenger, Settings settings, Desktop desktop)
{
BuildUI();
CommunicationManager = communicationManager;
Window = window;
Messenger = messenger;
Desktop= desktop;
Desktop = desktop;
_settings = settings;
BtnNewCampaign.Click += (s, e) =>
{
@ -56,16 +56,16 @@ namespace Sledgemapper.UI
Title = "New campaign"
};
var content = new CampaignWindow(CommunicationManager,window,Messenger);
var content = new CampaignWindow(CommunicationManager, window, Messenger);
//content.BtnNewCampaign.Text = "N";
//content.BtnNewCampaign.Click += OnButtonNewCampaignClicked;
window.Content = content;
window.ShowModal(desktop);
window.ShowModal(Desktop);
//content.TxtCampaign.SetKeyboardFocus();
}
private bool campaignSelected;

View File

@ -0,0 +1,8 @@
/* Generated by MyraPad at 03/09/2021 16:19:13 */
namespace Sledgemapper.UI
{
public partial class ListItem
{
}
}

View File

@ -24,17 +24,15 @@ namespace Sledgemapper.UI
private Settings _settings;
private readonly TinyMessengerHub _messenger;
private readonly CachedContent _cachedContent;
private readonly GameWindow Window;
public MainWidget(CommunicationManager communicationManager, Settings settings, CachedContent cachedContent, TinyMessengerHub messenger, GameWindow window)
public MainWidget(CommunicationManager communicationManager, Settings settings, TinyMessengerHub messenger, GameWindow window)
{
BuildUI();
CommunicationManager = communicationManager;
_settings = settings;
_cachedContent = cachedContent;
Window = window;
_messenger = messenger;
MenuConnectLogin.Selected += OnMenuConnectLoginSelected;
@ -72,6 +70,13 @@ namespace Sledgemapper.UI
_messenger.Subscribe<LoginSuccesfulMessage>(OnLoginSuccesfulMessage);
_messenger.Subscribe<SignalrConnectionUpdateMessage>(OnSignalrConnectionUpdateMessage);
_messenger.Subscribe<MapOpenedMessage>(OnMapOpenedMessage);
_messenger.Subscribe<CenterOnTileMessage>(OnCenterOnTileMessage);
}
private void OnCenterOnTileMessage(CenterOnTileMessage obj)
{
CenterOnTile(obj.X, obj.Y);
}
private void OnMapOpenedMessage(MapOpenedMessage obj)
@ -290,14 +295,11 @@ namespace Sledgemapper.UI
Title = "Join mapping session"
};
var content = new SessionWindow();
content.BtnLogin.Text = "Join";
content.BtnLogin.Click += OnButtonJoinSessionClicked;
var content = new SessionWindow(CommunicationManager, _messenger, window);
window.Content = content;
window.ShowModal(Desktop);
content.TxtSession.SetKeyboardFocus();
}
private void OnMenuViewShowCellNUmbersSelected(object sender, EventArgs e)
@ -317,15 +319,15 @@ namespace Sledgemapper.UI
Title = "Notes"
};
var content = new NoteList();
var content = new NoteList(CommunicationManager, _messenger, window);
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(_cachedContent.Location);
item.BtnNoteView.Image = new TextureRegion(_cachedContent.Eye);
item.BtnNoteCenter.Image = new TextureRegion(CachedContent.Instance.Location);
item.BtnNoteView.Image = new TextureRegion(CachedContent.Instance.Eye);
item.BtnNoteCenter.Click += (s, e) => { CenterOnTile(note.X, note.Y); };
item.BtnNoteView.Click += (s, e) => { EditNote(note); window.Close(); };
content.StackNotesList.AddChild(item);
@ -363,12 +365,6 @@ namespace Sledgemapper.UI
};
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)
@ -385,44 +381,10 @@ namespace Sledgemapper.UI
var content = new CampaignList(CommunicationManager, window, _messenger, _settings, Desktop);
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);
//}
//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 void OnMapSelected(object sender, EventArgs e)
@ -461,9 +423,6 @@ namespace Sledgemapper.UI
content.StackCampaignsList.AddChild(item);
}
//content.BtnNewCampaign.Text = "N";
content.BtnInvitePlayer.Click += (s, e) =>
{
@ -474,7 +433,6 @@ namespace Sledgemapper.UI
window.Content = content;
window.ShowModal(Desktop);
// content.TxtCampaign.SetKeyboardFocus();
}
private async void OnMenuMapOpen(object sender, EventArgs e)
{
@ -497,9 +455,6 @@ namespace Sledgemapper.UI
item.TouchUp += OnMapSelected;
content.StackCampaignsList.AddChild(item);
}
//content.BtnNewCampaign.Text = "N";
content.BtnNewCampaign.Click += (s, e) =>
{
@ -510,7 +465,6 @@ namespace Sledgemapper.UI
window.Content = content;
window.ShowModal(Desktop);
// content.TxtCampaign.SetKeyboardFocus();
}
private void ShowAddPLayerWindow()
@ -589,107 +543,19 @@ namespace Sledgemapper.UI
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.Instance.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)
{
Sentry.SentrySdk.CaptureException(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 = ((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();
//}
private void OnBtnToolbarRoomClicked(object sender, EventArgs e)
{
State.Instance.InsertMode = InsertMode.NewRoom;
@ -752,48 +618,17 @@ namespace Sledgemapper.UI
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.Instance.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();
}
@ -801,41 +636,14 @@ namespace Sledgemapper.UI
private void EditNote(Note note)
{
State.Instance.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;
var noteWindow = new NoteWindow(CommunicationManager, window, note);
window.Content = noteWindow;
window.ShowModal(Desktop);
noteWindow.NoteText.SetKeyboardFocus();
}
private void OnButtonNoteOkClick(object sender, EventArgs e)
{
var button = ((TextButton)sender);
var localContent = button.GetParentContentInWindow<NoteWindow>();
var note = new Note
{
X = State.Instance.SelectedNote.X,
Y = State.Instance.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 = button.GetParentContentInWindow<Widget>();
content.Window.Close();
}
}
}

View File

@ -0,0 +1,56 @@
/* Generated by MyraPad at 01/12/2020 11:46:54 */
using System.Linq;
using Myra.Graphics2D.TextureAtlases;
using Myra.Graphics2D.UI;
using Sledgemapper.Shared.Entities;
using TinyMessenger;
namespace Sledgemapper.UI
{
public partial class NoteList
{
private readonly CommunicationManager CommunicationManager;
private readonly Window Window;
private readonly TinyMessengerHub Messenger;
public NoteList(CommunicationManager communicationManager, TinyMessengerHub messenger, Window window)
{
BuildUI();
CommunicationManager = communicationManager;
Messenger = messenger;
Window = window;
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(CachedContent.Instance.Location);
item.BtnNoteView.Image = new TextureRegion(CachedContent.Instance.Eye);
item.BtnNoteCenter.Click += (s, e) =>
{
Messenger.Publish(new CenterOnTileMessage(this) { X = note.X, Y = note.Y });
};
item.BtnNoteView.Click += (s, e) => { EditNote(note); window.Close(); };
StackNotesList.AddChild(item);
}
}
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, window, note);
window.Content = noteWindow;
window.ShowModal(Desktop);
//noteWindow.NoteText.SetKeyboardFocus();
}
}
}

View File

@ -0,0 +1,45 @@
/* Generated by MyraPad at 29/11/2020 23:50:42 */
using System;
using Myra.Graphics2D.UI;
using Sledgemapper.Shared.Entities;
namespace Sledgemapper.UI
{
public partial class NoteWindow
{
private readonly Window Window;
private readonly CommunicationManager CommunicationManager;
private readonly Note Note;
public NoteWindow(CommunicationManager communicationManager, Window window, Note note)
{
BuildUI();
NoteText.Text = note.Text;
Note = note;
Window = window;
CommunicationManager = communicationManager;
BtnOk.Click += OnButtonNoteOkClick;
BtnCancel.Click += OnButtonNoteCancelClick;
}
private void OnButtonNoteOkClick(object sender, EventArgs e)
{
var button = ((TextButton)sender);
var localContent = button.GetParentContentInWindow<NoteWindow>();
var note = new Note
{
X = State.Instance.SelectedNote.X,
Y = State.Instance.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 = button.GetParentContentInWindow<Widget>();
content.Window.Close();
}
}
}