Compare commits

...

2 Commits

Author SHA1 Message Date
Michele Scandura
7808363a07 removing dependency on windows all around
All checks were successful
continuous-integration/drone/push Build is passing
2021-09-16 13:07:56 +01:00
Michele Scandura
1e48c041b1 small fixes 2021-09-16 12:38:20 +01:00
14 changed files with 97 additions and 88 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

@ -71,7 +71,10 @@ namespace Sledgemapper.UI
private void OnCampaignSelectedMessage(CampaignSelectedMessage obj)
{
lblCampaign.Text = State.Instance.CampaignName;
MenuMapNew.Enabled = true;
MenuMapOpen.Enabled = true;
MenuCampaignPlayers.Enabled = true;
}
private void OnCenterOnTileMessage(CenterOnTileMessage obj)
@ -81,7 +84,7 @@ namespace Sledgemapper.UI
private void OnMapOpenedMessage(MapOpenedMessage obj)
{
lblSessionName.Text = CommunicationManager.SessionData.SessionName;
lblMap.Text = CommunicationManager.SessionData.SessionName;
MenuConnectSync.Enabled = true;
MenuConnectUpload.Enabled = true;
CommunicationManager.SessionData.MapEntityAdded -= OnMapEntityAdded;
@ -102,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}";
@ -138,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);
}
@ -156,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);
@ -295,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;
@ -319,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);
@ -351,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);
}
@ -368,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;
@ -402,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;
@ -488,7 +490,7 @@ namespace Sledgemapper.UI
if (successful)
{
CommunicationManager.SessionData.SessionName = localContent.Content.TxtSession.Text;
lblSessionName.Text = CommunicationManager.SessionData.SessionName;
lblMap.Text = CommunicationManager.SessionData.SessionName;
MenuConnectSync.Enabled = true;
MenuConnectUpload.Enabled = true;
localContent.Window.Close();
@ -581,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

@ -1,9 +1,10 @@
/* Generated by MyraPad at 19/02/2021 14:56:38 */
/* Generated by MyraPad at 16/09/2021 12:26:31 */
using Myra;
using Myra.Graphics2D;
using Myra.Graphics2D.TextureAtlases;
using Myra.Graphics2D.UI;
using Myra.Graphics2D.Brushes;
using Myra.Graphics2D.UI.Properties;
#if MONOGAME || FNA
using Microsoft.Xna.Framework;
@ -292,12 +293,22 @@ namespace Sledgemapper.UI
var verticalSeparator2 = new VerticalSeparator();
var label3 = new Label();
label3.Text = "Session name:";
label3.Text = "Campaign:";
lblSessionName = new Label();
lblSessionName.Text = "n/a";
lblSessionName.MinWidth = 100;
lblSessionName.Id = "lblSessionName";
lblCampaign = new Label();
lblCampaign.Text = "n/a";
lblCampaign.MinWidth = 100;
lblCampaign.Id = "lblCampaign";
var verticalSeparator3 = new VerticalSeparator();
var label4 = new Label();
label4.Text = "Map:";
lblMap = new Label();
lblMap.Text = "n/a";
lblMap.MinWidth = 100;
lblMap.Id = "lblMap";
var horizontalStackPanel1 = new HorizontalStackPanel();
horizontalStackPanel1.Spacing = 10;
@ -314,7 +325,10 @@ namespace Sledgemapper.UI
horizontalStackPanel1.Widgets.Add(lblUsername);
horizontalStackPanel1.Widgets.Add(verticalSeparator2);
horizontalStackPanel1.Widgets.Add(label3);
horizontalStackPanel1.Widgets.Add(lblSessionName);
horizontalStackPanel1.Widgets.Add(lblCampaign);
horizontalStackPanel1.Widgets.Add(verticalSeparator3);
horizontalStackPanel1.Widgets.Add(label4);
horizontalStackPanel1.Widgets.Add(lblMap);
Proportions.Add(new Proportion
@ -366,6 +380,7 @@ namespace Sledgemapper.UI
public TextBox TxtOverlaySearch;
public Label lblConnectionStatus;
public Label lblUsername;
public Label lblSessionName;
public Label lblCampaign;
public Label lblMap;
}
}

View File

@ -1,5 +1,5 @@
<Project>
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="MainWidget" OutputPath="C:\dev\Map\Sledgemapper\UI" />
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="MainWidget" OutputPath="C:\src\Map\Sledgemapper\UI" />
<VerticalStackPanel>
<VerticalStackPanel.Proportions>
<Proportion Type="Auto" />
@ -85,8 +85,11 @@
<Label Text="Username:" />
<Label Text="n/a" MinWidth="100" Id="lblUsername" />
<VerticalSeparator />
<Label Text="Session name:" />
<Label Text="n/a" MinWidth="100" Id="lblSessionName" />
<Label Text="Campaign:" />
<Label Text="n/a" MinWidth="100" Id="lblCampaign" />
<VerticalSeparator />
<Label Text="Map:" />
<Label Text="n/a" MinWidth="100" Id="lblMap" />
</HorizontalStackPanel>
</VerticalStackPanel>
</Project>

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

@ -1,4 +1,4 @@
/* Generated by MyraPad at 28/08/2021 19:49:08 */
/* Generated by MyraPad at 16/09/2021 12:29:41 */
using Myra;
using Myra.Graphics2D;
using Myra.Graphics2D.TextureAtlases;
@ -23,7 +23,7 @@ namespace Sledgemapper.UI
private void BuildUI()
{
var label1 = new Label();
label1.Text = "Campaigns";
label1.Text = "Players";
label1.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center;
StackCampaignsList = new VerticalStackPanel();

View File

@ -1,7 +1,7 @@
<Project>
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="PlayerList" OutputPath="C:\dev\Map\Sledgemapper\UI" />
<Project.ExportOptions Namespace="Sledgemapper.UI" Class="PlayerList" OutputPath="C:\src\Map\Sledgemapper\UI" />
<VerticalStackPanel Spacing="13" Width="400" Padding="10">
<Label Text="Campaigns" HorizontalAlignment="Center" />
<Label Text="Players" HorizontalAlignment="Center" />
<ScrollViewer>
<VerticalStackPanel MinHeight="350" MaxHeight="350" Id="StackCampaignsList" />
</ScrollViewer>

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;
}