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

@ -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();
}
}
}