Dialog for editing players
This commit is contained in:
174
EstusShots.Gtk/Dialogs/Dialogs.glade
Normal file
174
EstusShots.Gtk/Dialogs/Dialogs.glade
Normal file
@@ -0,0 +1,174 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkDialog" id="PlayerEditorDialog">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="resizable">False</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="window_position">center-on-parent</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<property name="deletable">False</property>
|
||||
<property name="gravity">center</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkBox">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">2</property>
|
||||
<child internal-child="action_area">
|
||||
<object class="GtkButtonBox">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="SavePlayerButton">
|
||||
<property name="label">gtk-save</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<accelerator key="Return" signal="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="CancelPlayerEditorButton">
|
||||
<property name="label">gtk-cancel</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkOverlay" id="PlayerEditorOverlay">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
<property name="row_spacing">5</property>
|
||||
<property name="column_spacing">7</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">Name:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">Alias:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="PlayerNameEntry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="PlayerAliasEntry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="PlayerAnonymousCheckButton">
|
||||
<property name="label" translatable="yes">Anonymous</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="label" translatable="yes">Hex ID:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="PlayerHexIdEntry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="max_length">4</property>
|
||||
<property name="placeholder_text" translatable="yes">0x00</property>
|
||||
<property name="input_purpose">alpha</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="index">-1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
78
EstusShots.Gtk/Dialogs/PlayerEditor.cs
Normal file
78
EstusShots.Gtk/Dialogs/PlayerEditor.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,12 +344,11 @@
|
||||
<property name="spacing">5</property>
|
||||
<property name="layout_style">start</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="SavePlayerButton">
|
||||
<property name="label">gtk-save</property>
|
||||
<object class="GtkButton" id="NewPlayerButton">
|
||||
<property name="label" translatable="yes">New Player</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
@@ -358,18 +357,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="DeletePlayerButton">
|
||||
<property name="label">gtk-delete</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user