removing dependency on windows all around
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-16 13:07:56 +01:00
parent 1e48c041b1
commit 7808363a07
10 changed files with 59 additions and 70 deletions

View File

@ -46,6 +46,17 @@ namespace Sledgemapper
return (localWindow, localContent);
}
public static Window GetContainingWindow(this Widget widget)
{
var container = widget.Parent;
while (!(container is Window) || container is null)
{
container = container.Parent;
}
return container as Window;
}
public static bool ValidateTextbox(this TextBox textBox)
{
var valid = !string.IsNullOrWhiteSpace(textBox.Text);

View File

@ -10,21 +10,19 @@ namespace Sledgemapper.UI
public partial class CampaignList
{
private readonly CommunicationManager CommunicationManager;
private readonly Window Window;
private readonly TinyMessengerHub Messenger;
private bool campaignSelected;
public CampaignList(CommunicationManager communicationManager, Window window, TinyMessengerHub messenger)
public CampaignList(CommunicationManager communicationManager, TinyMessengerHub messenger)
{
BuildUI();
CommunicationManager = communicationManager;
Window = window;
Messenger = messenger;
BtnNewCampaign.Click += (s, e) =>
{
window.Close();
OnMenuCampaignNew(s, e);
this.GetContainingWindow().Close();
};
BtnLoadCampaign.Click += (s, e) =>
@ -33,14 +31,13 @@ namespace Sledgemapper.UI
{
campaignSelected = false;
Messenger.Publish(new CampaignSelectedMessage(this));
window.Close();
this.GetContainingWindow().Close();
}
};
BtnCancelCampaign.Click += (s, e) =>
{
Window.Close();
this.GetContainingWindow().Close();
};
}
@ -56,9 +53,9 @@ namespace Sledgemapper.UI
Title = "New campaign"
};
var content = new CampaignWindow(CommunicationManager, window, Messenger);
var content = new CampaignWindow(CommunicationManager, Messenger);
window.Content = content;
window.ShowModal(Window.Desktop);
window.ShowModal(Desktop);
}
private void OnCampaignSelected(object sender, EventArgs e)

View File

@ -8,17 +8,14 @@ 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)
public CampaignWindow(CommunicationManager communicationManager, TinyMessengerHub messenger)
{
BuildUI();
CommunicationManager = communicationManager;
Window = window;
Messenger = messenger;
BtnNewCampaign.Click += OnButtonNewCampaignClicked;
}
private async void OnButtonNewCampaignClicked(object sender, EventArgs e)
@ -74,7 +71,7 @@ namespace Sledgemapper.UI
// localWindow.Close();
//}
Window.Close();
this.GetContainingWindow().Close();
}
}

View File

@ -9,18 +9,16 @@ using TinyMessenger;
namespace Sledgemapper.UI
{
public partial class LoginRegisterWindow
{
{
private AuthenticateResponse _authResponse;
private readonly CommunicationManager CommunicationManager;
private readonly Window Window;
private readonly TinyMessengerHub _messenger;
public LoginRegisterWindow(CommunicationManager communicationManager, Window window, TinyMessengerHub messenger)
{
BuildUI();
CommunicationManager=communicationManager;
Window=window;
_messenger=messenger;
public LoginRegisterWindow(CommunicationManager communicationManager, TinyMessengerHub messenger)
{
BuildUI();
CommunicationManager = communicationManager;
_messenger = messenger;
#if DEBUG
TxtEmail.Text = "michele.scandura@outlook.com";
@ -38,7 +36,7 @@ namespace Sledgemapper.UI
LblInitials.Visible = false;
BtnLogin.Visible = true;
BtnRegister.Visible = false;
Window.Title = "Login";
this.GetContainingWindow().Title = "Login";
};
RdoRegister.Click += (s, e) =>
@ -51,18 +49,18 @@ namespace Sledgemapper.UI
LblInitials.Visible = true;
BtnLogin.Visible = false;
BtnRegister.Visible = true;
Window.Title = "Register";
this.GetContainingWindow().Title = "Register";
};
BtnRegister.Click += OnButtonRegisterClick;
BtnLogin.Click += OnButtonLoginClick;
//TxtEmail.SetKeyboardFocus();
}
}
private async void OnButtonRegisterClick(object sender, EventArgs e)
private async void OnButtonRegisterClick(object sender, EventArgs e)
{
var button = ((TextButton)sender);
@ -138,8 +136,8 @@ namespace Sledgemapper.UI
}
if (successful)
{
_messenger.Publish(new LoginSuccesfulMessage(this){UserName=_authResponse.Username, Initials=_authResponse.Initials});
localContent.Window.Close();
_messenger.Publish(new LoginSuccesfulMessage(this) { UserName = _authResponse.Username, Initials = _authResponse.Initials });
this.GetContainingWindow().Close();
}
}
@ -207,12 +205,12 @@ namespace Sledgemapper.UI
if (successful)
{
_messenger.Publish(new LoginSuccesfulMessage(this){UserName=_authResponse.Username, Initials=_authResponse.Initials});
_messenger.Publish(new LoginSuccesfulMessage(this) { UserName = _authResponse.Username, Initials = _authResponse.Initials });
localWindow.Close();
}
}
}
}
}

View File

@ -74,6 +74,7 @@ namespace Sledgemapper.UI
lblCampaign.Text = State.Instance.CampaignName;
MenuMapNew.Enabled = true;
MenuMapOpen.Enabled = true;
MenuCampaignPlayers.Enabled = true;
}
private void OnCenterOnTileMessage(CenterOnTileMessage obj)
@ -104,7 +105,6 @@ namespace Sledgemapper.UI
MenuConnectNew.Enabled = true;
MenuConnectJoin.Enabled = true;
MenuCampaignOpen.Enabled = true;
MenuCampaignPlayers.Enabled = true;
MenuCampaingNew.Enabled = true;
lblUsername.Text = $"{obj.UserName} - {obj.Initials}";
@ -140,7 +140,7 @@ namespace Sledgemapper.UI
Title = "Login"
};
var content = new LoginRegisterWindow(CommunicationManager, window, _messenger);
var content = new LoginRegisterWindow(CommunicationManager, _messenger);
window.Content = content;
window.ShowModal(Desktop);
}
@ -158,7 +158,7 @@ namespace Sledgemapper.UI
Title = "New mapping session"
};
var content = new SessionWindow(CommunicationManager, _messenger, window);
var content = new SessionWindow(CommunicationManager, _messenger);
window.Content = content;
window.ShowModal(Desktop);
@ -297,7 +297,7 @@ namespace Sledgemapper.UI
Title = "Join mapping session"
};
var content = new SessionWindow(CommunicationManager, _messenger, window);
var content = new SessionWindow(CommunicationManager, _messenger);
window.Content = content;
@ -321,7 +321,7 @@ namespace Sledgemapper.UI
Title = "Notes"
};
var content = new NoteList(CommunicationManager, _messenger, window);
var content = new NoteList(CommunicationManager, _messenger);
window.Content = content;
window.ShowModal(Desktop);
@ -353,7 +353,7 @@ namespace Sledgemapper.UI
{
Title = "New campaign"
};
var content = new CampaignWindow(CommunicationManager, window, _messenger);
var content = new CampaignWindow(CommunicationManager, _messenger);
window.Content = content;
window.ShowModal(Desktop);
}
@ -370,7 +370,7 @@ namespace Sledgemapper.UI
Title = "Campaigns"
};
var content = new CampaignList(CommunicationManager, window, _messenger);
var content = new CampaignList(CommunicationManager, _messenger);
await content.LoadCampaigns();
window.Content = content;
@ -404,7 +404,7 @@ namespace Sledgemapper.UI
Title = "Players"
};
var content = new PlayerList(CommunicationManager, window);
var content = new PlayerList(CommunicationManager);
await content.LoadPlayers();
window.Content = content;
@ -583,7 +583,7 @@ namespace Sledgemapper.UI
{
Title = $" Note on {note.X}:{note.Y}"
};
var noteWindow = new NoteWindow(CommunicationManager, window, note);
var noteWindow = new NoteWindow(CommunicationManager, note);
window.Content = noteWindow;
window.ShowModal(Desktop);

View File

@ -11,16 +11,13 @@ 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)
public NoteList(CommunicationManager communicationManager, TinyMessengerHub messenger)
{
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);
@ -33,10 +30,11 @@ namespace Sledgemapper.UI
Messenger.Publish(new CenterOnTileMessage(this) { X = note.X, Y = note.Y });
};
item.BtnNoteView.Click += (s, e) => { EditNote(note); window.Close(); };
item.BtnNoteView.Click += (s, e) => { EditNote(note); this.GetContainingWindow().Close(); };
StackNotesList.AddChild(item);
}
}
private void EditNote(Note note)
{
State.Instance.SelectedNote = new Note { X = note.X, Y = note.Y, Text = note.Text };
@ -44,11 +42,10 @@ namespace Sledgemapper.UI
{
Title = $" Note on {note.X}:{note.Y}"
};
var noteWindow = new NoteWindow(CommunicationManager, window, note);
var noteWindow = new NoteWindow(CommunicationManager, note);
window.Content = noteWindow;
window.ShowModal(Window.Desktop);
window.ShowModal(Desktop);
}
}
}

View File

@ -7,15 +7,14 @@ 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)
public NoteWindow(CommunicationManager communicationManager, Note note)
{
BuildUI();
NoteText.Text = note.Text;
Note = note;
Window = window;
CommunicationManager = communicationManager;
BtnOk.Click += OnButtonNoteOkClick;
BtnCancel.Click += OnButtonNoteCancelClick;

View File

@ -6,20 +6,17 @@ namespace Sledgemapper.UI
{
public partial class PlayerList
{
protected readonly Window Window;
protected readonly CommunicationManager CommunicationManager;
public PlayerList(CommunicationManager communicationManager, Window window)
public PlayerList(CommunicationManager communicationManager)
{
BuildUI();
Window = window;
CommunicationManager = communicationManager;
BtnInvitePlayer.Click += (s, e) =>
{
Window.Close();
ShowAddPLayerWindow();
this.GetContainingWindow().Close();
};
}
public async Task LoadPlayers()
@ -37,11 +34,11 @@ namespace Sledgemapper.UI
{
Window window = new()
{
Title = "Invite player",
Content = new PlayerWindow(CommunicationManager, Window)
Title = "Invite player"
};
window.ShowModal(Window.Desktop);
var content = new PlayerWindow(CommunicationManager);
window.Content = content;
window.ShowModal(Desktop);
}
}

View File

@ -7,12 +7,10 @@ namespace Sledgemapper.UI
{
public partial class PlayerWindow
{
protected readonly Window Window;
protected readonly CommunicationManager CommunicationManager;
public PlayerWindow(CommunicationManager communicationManager, Window window)
public PlayerWindow(CommunicationManager communicationManager)
{
Window = window;
CommunicationManager = communicationManager;
BuildUI();
@ -37,8 +35,7 @@ namespace Sledgemapper.UI
{
SentrySdk.CaptureException(ex);
}
localContent.Window.Close();
this.GetContainingWindow().Close();
}
}
}

View File

@ -12,18 +12,14 @@ namespace Sledgemapper.UI
{
public partial class SessionWindow
{
private readonly CommunicationManager CommunicationManager;
private readonly Window Window;
private readonly TinyMessengerHub Messenger;
public SessionWindow(CommunicationManager communicationManager, TinyMessengerHub messenger, Window window)
public SessionWindow(CommunicationManager communicationManager, TinyMessengerHub messenger)
{
BuildUI();
CommunicationManager = communicationManager;
Messenger = messenger;
Window = window;
BtnLogin.Text = "Join";
BtnLogin.Click += OnButtonNewSessionClicked;
}