diff --git a/EstusShots.Gtk/Dialogs/Dialogs.glade b/EstusShots.Gtk/Dialogs/Dialogs.glade new file mode 100644 index 0000000..ce0584e --- /dev/null +++ b/EstusShots.Gtk/Dialogs/Dialogs.glade @@ -0,0 +1,174 @@ + + + + + + False + False + True + center-on-parent + True + dialog + False + center + + + + + + False + vertical + 2 + + + False + end + + + gtk-save + True + True + True + True + + + + True + True + 0 + + + + + gtk-cancel + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + True + False + + + True + False + 10 + 10 + 5 + 7 + + + True + False + end + Name: + + + 0 + 0 + + + + + True + False + end + Alias: + + + 0 + 1 + + + + + True + True + + + 1 + 0 + + + + + True + True + + + 1 + 1 + + + + + Anonymous + True + True + False + True + + + 1 + 3 + + + + + True + False + end + Hex ID: + + + 0 + 2 + + + + + True + True + 4 + 0x00 + alpha + + + 1 + 2 + + + + + + + + -1 + + + + + True + True + 1 + + + + + + diff --git a/EstusShots.Gtk/Dialogs/PlayerEditor.cs b/EstusShots.Gtk/Dialogs/PlayerEditor.cs new file mode 100644 index 0000000..8eada13 --- /dev/null +++ b/EstusShots.Gtk/Dialogs/PlayerEditor.cs @@ -0,0 +1,78 @@ +using System; +using EstusShots.Shared.Dto; +using Gtk; +using UI = Gtk.Builder.ObjectAttribute; + +namespace EstusShots.Gtk.Dialogs +{ + public class DialogClosedEventArgs : EventArgs + { + public bool Ok { get; } + public object Model { get; } + + public DialogClosedEventArgs(bool ok, object model) + { + Ok = ok; + Model = model; + } + } + public delegate void DialogClosedEventHandler(object o, DialogClosedEventArgs args); + + public class PlayerEditor + { + private Builder _builder; + private Player _player; + + [UI] private readonly Dialog PlayerEditorDialog = null; + [UI] private readonly Overlay PlayerEditorOverlay = null; + [UI] private readonly Entry PlayerNameEntry = null; + [UI] private readonly Entry PlayerAliasEntry = null; + [UI] private readonly Entry PlayerHexIdEntry = null; + [UI] private readonly CheckButton PlayerAnonymousCheckButton = null; + [UI] private readonly Button CancelPlayerEditorButton = null; + [UI] private readonly Button SavePlayerButton = null; + + public event DialogClosedEventHandler OnDialogClosed; + + public PlayerEditor(Window parent, Player player) + { + _player = player; + + _builder = new Builder("Dialogs.glade"); + _builder.Autoconnect(this); + + SavePlayerButton.Clicked += SavePlayerButtonOnClicked; + + PlayerEditorDialog.Parent = parent; + PlayerEditorDialog.TransientFor = parent; + + ReadFromModel(); + } + + // Events + + private void SavePlayerButtonOnClicked(object sender, EventArgs e) + { + ReadToModel(); + OnDialogClosed?.Invoke(this, new DialogClosedEventArgs(true, _player)); + } + + // Private Methods + + private void ReadToModel() + { + _player.Name = PlayerNameEntry.Text; + _player.Alias = PlayerAliasEntry.Text; + _player.HexId = PlayerHexIdEntry.Text; + _player.Anonymous = PlayerAnonymousCheckButton.Active; + } + + private void ReadFromModel() + { + PlayerNameEntry.Text = _player.Name; + PlayerAliasEntry.Text = _player.Alias; + PlayerHexIdEntry.Text = _player.HexId; + PlayerAnonymousCheckButton.Active = _player.Anonymous; + } + } +} \ No newline at end of file diff --git a/EstusShots.Gtk/MainWindow.glade b/EstusShots.Gtk/MainWindow.glade index 85c7b00..11f9c94 100644 --- a/EstusShots.Gtk/MainWindow.glade +++ b/EstusShots.Gtk/MainWindow.glade @@ -344,12 +344,11 @@ 5 start - - gtk-save + + New Player True True True - True True @@ -358,18 +357,7 @@ - - gtk-delete - True - True - True - True - - - True - True - 1 - + diff --git a/EstusShots.Gtk/Pages/PlayersPage.cs b/EstusShots.Gtk/Pages/PlayersPage.cs index 19da251..6e9334b 100644 --- a/EstusShots.Gtk/Pages/PlayersPage.cs +++ b/EstusShots.Gtk/Pages/PlayersPage.cs @@ -1,3 +1,6 @@ +using System; +using EstusShots.Gtk.Dialogs; +using EstusShots.Shared.Dto; using Gtk; using UI = Gtk.Builder.ObjectAttribute; @@ -8,14 +11,28 @@ namespace EstusShots.Gtk [UI] public readonly Box PlayersPage = null; [UI] public readonly Overlay PlayersOverlay = null; [UI] public readonly TreeView PlayersTreeView = null; - [UI] public readonly Button SavePlayerButton = null; - [UI] public readonly Button DeletePlayerButton = null; + [UI] public readonly Button NewPlayerButton = null; [UI] public readonly Box PlayerEditorContainer = null; private void InitPlayersPage() { - + NewPlayerButton.Clicked += NewPlayerButtonOnClicked; + } + + // Events + + private void NewPlayerButtonOnClicked(object sender, EventArgs e) + { + var dialog = new PlayerEditor(this, new Player()); + dialog.OnDialogClosed += PlayerEditorClosed; + } + + private void PlayerEditorClosed(object o, DialogClosedEventArgs args) + { + if (!args.Ok || !(args.Model is Player player)) return; + // TODO + // Client.Players.SavePlayer(); } } } \ No newline at end of file