Make player and drink editor use the editor base class
This commit is contained in:
@@ -18,47 +18,33 @@ namespace EstusShots.Gtk.Dialogs
|
||||
}
|
||||
public delegate void DialogClosedEventHandler<T>(object o, DialogClosedEventArgs<T> args) where T: class, new();
|
||||
|
||||
// TODO remove non-generic version
|
||||
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 abstract class DialogBase<T> where T: class, new()
|
||||
public abstract class DialogBase<T> : Dialog where T: class, new()
|
||||
{
|
||||
protected readonly Builder Builder;
|
||||
protected T EditObject { get; set; }
|
||||
|
||||
[UI] private readonly Dialog _editorDialog = null;
|
||||
[UI] private readonly Button _saveButton = null;
|
||||
[UI] private readonly Button _cancelButton = null;
|
||||
|
||||
public event DialogClosedEventHandler<T> OnDialogClosed;
|
||||
public event DialogClosedEventHandler<T> DialogClosed;
|
||||
|
||||
protected DialogBase(Window parent, Builder builder)
|
||||
protected DialogBase(Window parent, Builder builder) : base(builder.GetObject("_editorDialog").Handle)
|
||||
{
|
||||
builder.Autoconnect(this);
|
||||
|
||||
Builder = builder;
|
||||
Builder.Autoconnect(this);
|
||||
_saveButton.Clicked += OnSaveButtonClicked;
|
||||
_cancelButton.Clicked += (sender, args) =>
|
||||
{
|
||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(false, new T()));
|
||||
_editorDialog.Dispose();
|
||||
DialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(false, new T()));
|
||||
Dispose();
|
||||
};
|
||||
_editorDialog.TransientFor = parent;
|
||||
TransientFor = parent;
|
||||
}
|
||||
|
||||
public void Show()
|
||||
public new void Show()
|
||||
{
|
||||
LoadFromModel();
|
||||
_editorDialog.Show();
|
||||
base.Show();
|
||||
}
|
||||
|
||||
private void OnSaveButtonClicked(object sender, EventArgs e)
|
||||
@@ -66,8 +52,8 @@ namespace EstusShots.Gtk.Dialogs
|
||||
try
|
||||
{
|
||||
LoadToModel();
|
||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(true, EditObject));
|
||||
_editorDialog.Dispose();
|
||||
DialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(true, EditObject));
|
||||
Dispose();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
@@ -2,137 +2,7 @@
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkAdjustment" id="DrinkVolAdjustment">
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">0.10000000000000001</property>
|
||||
<property name="page_increment">10</property>
|
||||
</object>
|
||||
<object class="GtkDialog" id="DrinkEditorDialog">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">Drink</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="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="SaveDrinkButton">
|
||||
<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="CancelDrinkEditorButton">
|
||||
<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="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">Vol. Alcohol</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="DrinkNameEntry">
|
||||
<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="GtkSpinButton" id="DinkVolEntry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="placeholder_text" translatable="yes">%</property>
|
||||
<property name="input_purpose">number</property>
|
||||
<property name="adjustment">DrinkVolAdjustment</property>
|
||||
<property name="climb_rate">0.10000000000000001</property>
|
||||
<property name="digits">1</property>
|
||||
<property name="numeric">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkDialog" id="PlayerEditorDialog">
|
||||
<object class="GtkDialog" id="_editorDialog">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">Player</property>
|
||||
<property name="resizable">False</property>
|
||||
@@ -154,7 +24,7 @@
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="SavePlayerButton">
|
||||
<object class="GtkButton" id="_saveButton">
|
||||
<property name="label">gtk-save</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
@@ -169,7 +39,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="CancelPlayerEditorButton">
|
||||
<object class="GtkButton" id="_cancelButton">
|
||||
<property name="label">gtk-cancel</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
|
||||
@@ -1,63 +1,31 @@
|
||||
using System;
|
||||
using EstusShots.Shared.Dto;
|
||||
using Gtk;
|
||||
using UI = Gtk.Builder.ObjectAttribute;
|
||||
|
||||
namespace EstusShots.Gtk.Dialogs
|
||||
{
|
||||
public class DrinkEditor
|
||||
public class DrinkEditor : DialogBase<Drink>
|
||||
{
|
||||
[UI] private readonly Dialog DrinkEditorDialog = null;
|
||||
[UI] private readonly Entry DrinkNameEntry = null;
|
||||
[UI] private readonly Adjustment DrinkVolAdjustment = null;
|
||||
[UI] private readonly Button SaveDrinkButton = null;
|
||||
[UI] private readonly Button CancelDrinkEditorButton = null;
|
||||
|
||||
private readonly Drink _drink;
|
||||
|
||||
public event DialogClosedEventHandler OnDialogClosed;
|
||||
[UI] private readonly Entry _nameEntry = null;
|
||||
[UI] private readonly Adjustment _volAdjustment = null;
|
||||
|
||||
public DrinkEditor(Window parent, Drink drink)
|
||||
public DrinkEditor(Window parent, Drink drink) : base(parent, new Builder("DrinkEditor.glade"))
|
||||
{
|
||||
_drink = drink;
|
||||
|
||||
EditObject = drink;
|
||||
var builder = new Builder("Dialogs.glade");
|
||||
builder.Autoconnect(this);
|
||||
|
||||
SaveDrinkButton.Clicked += SaveDrinkButtonOnClicked;
|
||||
CancelDrinkEditorButton.Clicked += (sender, args) =>
|
||||
{
|
||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs(false, null));
|
||||
DrinkEditorDialog.Dispose();
|
||||
};
|
||||
|
||||
ReadFromModel();
|
||||
|
||||
DrinkEditorDialog.TransientFor = parent;
|
||||
DrinkEditorDialog.Show();
|
||||
}
|
||||
|
||||
// Events
|
||||
|
||||
private void SaveDrinkButtonOnClicked(object sender, EventArgs e)
|
||||
{
|
||||
ReadToModel();
|
||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs(true, _drink));
|
||||
DrinkEditorDialog.Dispose();
|
||||
}
|
||||
|
||||
// Private Methods
|
||||
|
||||
private void ReadToModel()
|
||||
protected override void LoadToModel()
|
||||
{
|
||||
_drink.Name = DrinkNameEntry.Text;
|
||||
_drink.Vol = DrinkVolAdjustment.Value;
|
||||
EditObject.Name = _nameEntry.Text;
|
||||
EditObject.Vol = _volAdjustment.Value;
|
||||
}
|
||||
|
||||
private void ReadFromModel()
|
||||
protected override void LoadFromModel()
|
||||
{
|
||||
DrinkNameEntry.Text = _drink.Name;
|
||||
DrinkVolAdjustment.Value = _drink.Vol;
|
||||
_nameEntry.Text = EditObject.Name;
|
||||
_volAdjustment.Value = EditObject.Vol;
|
||||
}
|
||||
}
|
||||
}
|
||||
136
EstusShots.Gtk/Dialogs/Glade/DrinkEditor.glade
Normal file
136
EstusShots.Gtk/Dialogs/Glade/DrinkEditor.glade
Normal file
@@ -0,0 +1,136 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkAdjustment" id="_volAdjustment">
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">0.10000000000000001</property>
|
||||
<property name="page_increment">10</property>
|
||||
</object>
|
||||
<object class="GtkDialog" id="_editorDialog">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">Drink</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="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="_saveButton">
|
||||
<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="_cancelButton">
|
||||
<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="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">Vol. Alcohol</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="_nameEntry">
|
||||
<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="GtkSpinButton" id="_volEntry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="text" translatable="yes">0,0</property>
|
||||
<property name="placeholder_text" translatable="yes">%</property>
|
||||
<property name="input_purpose">number</property>
|
||||
<property name="adjustment">_volAdjustment</property>
|
||||
<property name="climb_rate">0.10000000000000001</property>
|
||||
<property name="digits">1</property>
|
||||
<property name="numeric">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
165
EstusShots.Gtk/Dialogs/Glade/PlayerEditor.glade
Normal file
165
EstusShots.Gtk/Dialogs/Glade/PlayerEditor.glade
Normal file
@@ -0,0 +1,165 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkDialog" id="_editorDialog">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">Player</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="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="_saveButton">
|
||||
<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="_cancelButton">
|
||||
<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="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="_nameEntry">
|
||||
<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="_aliasEntry">
|
||||
<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="_anonCheckButton">
|
||||
<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="_hexIdEntry">
|
||||
<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="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
@@ -1,69 +1,35 @@
|
||||
using System;
|
||||
using EstusShots.Shared.Dto;
|
||||
using Gtk;
|
||||
using UI = Gtk.Builder.ObjectAttribute;
|
||||
|
||||
namespace EstusShots.Gtk.Dialogs
|
||||
{
|
||||
public class PlayerEditor
|
||||
public class PlayerEditor : DialogBase<Player>
|
||||
{
|
||||
private readonly Player _player;
|
||||
|
||||
[UI] private readonly Dialog PlayerEditorDialog = 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;
|
||||
[UI] private readonly Entry _nameEntry = null;
|
||||
[UI] private readonly Entry _aliasEntry = null;
|
||||
[UI] private readonly Entry _hexIdEntry = null;
|
||||
[UI] private readonly CheckButton _anonCheckButton = null;
|
||||
|
||||
public PlayerEditor(Window parent, Player player)
|
||||
public PlayerEditor(Window parent, Player player) : base(parent, new Builder("PlayerEditor.glade"))
|
||||
{
|
||||
_player = player;
|
||||
|
||||
var builder = new Builder("Dialogs.glade");
|
||||
builder.Autoconnect(this);
|
||||
|
||||
SavePlayerButton.Clicked += SavePlayerButtonOnClicked;
|
||||
CancelPlayerEditorButton.Clicked += (sender, args) =>
|
||||
{
|
||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs(false, null));
|
||||
PlayerEditorDialog.Dispose();
|
||||
};
|
||||
|
||||
PlayerEditorDialog.TransientFor = parent;
|
||||
PlayerEditorDialog.Show();
|
||||
|
||||
ReadFromModel();
|
||||
}
|
||||
|
||||
// Events
|
||||
|
||||
private void SavePlayerButtonOnClicked(object sender, EventArgs e)
|
||||
{
|
||||
ReadToModel();
|
||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs(true, _player));
|
||||
PlayerEditorDialog.Dispose();
|
||||
}
|
||||
|
||||
// Private Methods
|
||||
|
||||
private void ReadToModel()
|
||||
{
|
||||
_player.Name = PlayerNameEntry.Text;
|
||||
_player.Alias = PlayerAliasEntry.Text;
|
||||
_player.HexId = PlayerHexIdEntry.Text;
|
||||
_player.Anonymous = PlayerAnonymousCheckButton.Active;
|
||||
EditObject = player;
|
||||
}
|
||||
|
||||
private void ReadFromModel()
|
||||
protected override void LoadToModel()
|
||||
{
|
||||
PlayerNameEntry.Text = _player.Name;
|
||||
PlayerAliasEntry.Text = _player.Alias;
|
||||
PlayerHexIdEntry.Text = _player.HexId;
|
||||
PlayerAnonymousCheckButton.Active = _player.Anonymous;
|
||||
EditObject.Name = _nameEntry.Text;
|
||||
EditObject.Alias = _aliasEntry.Text;
|
||||
EditObject.HexId = _hexIdEntry.Text;
|
||||
EditObject.Anonymous = _anonCheckButton.Active;
|
||||
}
|
||||
|
||||
protected override void LoadFromModel()
|
||||
{
|
||||
_nameEntry.Text = EditObject.Name;
|
||||
_aliasEntry.Text = EditObject.Alias;
|
||||
_hexIdEntry.Text = EditObject.HexId;
|
||||
_anonCheckButton.Active = EditObject.Anonymous;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user