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();
|
public delegate void DialogClosedEventHandler<T>(object o, DialogClosedEventArgs<T> args) where T: class, new();
|
||||||
|
|
||||||
// TODO remove non-generic version
|
public abstract class DialogBase<T> : Dialog where T: class, new()
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
|
protected readonly Builder Builder;
|
||||||
protected T EditObject { get; set; }
|
protected T EditObject { get; set; }
|
||||||
|
|
||||||
[UI] private readonly Dialog _editorDialog = null;
|
|
||||||
[UI] private readonly Button _saveButton = null;
|
[UI] private readonly Button _saveButton = null;
|
||||||
[UI] private readonly Button _cancelButton = 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;
|
_saveButton.Clicked += OnSaveButtonClicked;
|
||||||
_cancelButton.Clicked += (sender, args) =>
|
_cancelButton.Clicked += (sender, args) =>
|
||||||
{
|
{
|
||||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(false, new T()));
|
DialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(false, new T()));
|
||||||
_editorDialog.Dispose();
|
Dispose();
|
||||||
};
|
};
|
||||||
_editorDialog.TransientFor = parent;
|
TransientFor = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Show()
|
public new void Show()
|
||||||
{
|
{
|
||||||
LoadFromModel();
|
LoadFromModel();
|
||||||
_editorDialog.Show();
|
base.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSaveButtonClicked(object sender, EventArgs e)
|
private void OnSaveButtonClicked(object sender, EventArgs e)
|
||||||
@@ -66,8 +52,8 @@ namespace EstusShots.Gtk.Dialogs
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
LoadToModel();
|
LoadToModel();
|
||||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(true, EditObject));
|
DialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(true, EditObject));
|
||||||
_editorDialog.Dispose();
|
Dispose();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,137 +2,7 @@
|
|||||||
<!-- Generated with glade 3.22.1 -->
|
<!-- Generated with glade 3.22.1 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
<object class="GtkAdjustment" id="DrinkVolAdjustment">
|
<object class="GtkDialog" id="_editorDialog">
|
||||||
<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">
|
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="title" translatable="yes">Player</property>
|
<property name="title" translatable="yes">Player</property>
|
||||||
<property name="resizable">False</property>
|
<property name="resizable">False</property>
|
||||||
@@ -154,7 +24,7 @@
|
|||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="layout_style">end</property>
|
<property name="layout_style">end</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="SavePlayerButton">
|
<object class="GtkButton" id="_saveButton">
|
||||||
<property name="label">gtk-save</property>
|
<property name="label">gtk-save</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
@@ -169,7 +39,7 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="CancelPlayerEditorButton">
|
<object class="GtkButton" id="_cancelButton">
|
||||||
<property name="label">gtk-cancel</property>
|
<property name="label">gtk-cancel</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
|
|||||||
@@ -1,63 +1,31 @@
|
|||||||
using System;
|
|
||||||
using EstusShots.Shared.Dto;
|
using EstusShots.Shared.Dto;
|
||||||
using Gtk;
|
using Gtk;
|
||||||
using UI = Gtk.Builder.ObjectAttribute;
|
using UI = Gtk.Builder.ObjectAttribute;
|
||||||
|
|
||||||
namespace EstusShots.Gtk.Dialogs
|
namespace EstusShots.Gtk.Dialogs
|
||||||
{
|
{
|
||||||
public class DrinkEditor
|
public class DrinkEditor : DialogBase<Drink>
|
||||||
{
|
{
|
||||||
[UI] private readonly Dialog DrinkEditorDialog = null;
|
[UI] private readonly Entry _nameEntry = null;
|
||||||
[UI] private readonly Entry DrinkNameEntry = null;
|
[UI] private readonly Adjustment _volAdjustment = null;
|
||||||
[UI] private readonly Adjustment DrinkVolAdjustment = null;
|
|
||||||
[UI] private readonly Button SaveDrinkButton = null;
|
|
||||||
[UI] private readonly Button CancelDrinkEditorButton = null;
|
|
||||||
|
|
||||||
private readonly Drink _drink;
|
public DrinkEditor(Window parent, Drink drink) : base(parent, new Builder("DrinkEditor.glade"))
|
||||||
|
|
||||||
public event DialogClosedEventHandler OnDialogClosed;
|
|
||||||
|
|
||||||
public DrinkEditor(Window parent, Drink drink)
|
|
||||||
{
|
{
|
||||||
_drink = drink;
|
EditObject = drink;
|
||||||
|
|
||||||
var builder = new Builder("Dialogs.glade");
|
var builder = new Builder("Dialogs.glade");
|
||||||
builder.Autoconnect(this);
|
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
|
protected override void LoadToModel()
|
||||||
|
|
||||||
private void SaveDrinkButtonOnClicked(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
ReadToModel();
|
EditObject.Name = _nameEntry.Text;
|
||||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs(true, _drink));
|
EditObject.Vol = _volAdjustment.Value;
|
||||||
DrinkEditorDialog.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods
|
protected override void LoadFromModel()
|
||||||
|
|
||||||
private void ReadToModel()
|
|
||||||
{
|
{
|
||||||
_drink.Name = DrinkNameEntry.Text;
|
_nameEntry.Text = EditObject.Name;
|
||||||
_drink.Vol = DrinkVolAdjustment.Value;
|
_volAdjustment.Value = EditObject.Vol;
|
||||||
}
|
|
||||||
|
|
||||||
private void ReadFromModel()
|
|
||||||
{
|
|
||||||
DrinkNameEntry.Text = _drink.Name;
|
|
||||||
DrinkVolAdjustment.Value = _drink.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 EstusShots.Shared.Dto;
|
||||||
using Gtk;
|
using Gtk;
|
||||||
using UI = Gtk.Builder.ObjectAttribute;
|
using UI = Gtk.Builder.ObjectAttribute;
|
||||||
|
|
||||||
namespace EstusShots.Gtk.Dialogs
|
namespace EstusShots.Gtk.Dialogs
|
||||||
{
|
{
|
||||||
public class PlayerEditor
|
public class PlayerEditor : DialogBase<Player>
|
||||||
{
|
{
|
||||||
private readonly Player _player;
|
[UI] private readonly Entry _nameEntry = null;
|
||||||
|
[UI] private readonly Entry _aliasEntry = null;
|
||||||
|
[UI] private readonly Entry _hexIdEntry = null;
|
||||||
|
[UI] private readonly CheckButton _anonCheckButton = null;
|
||||||
|
|
||||||
[UI] private readonly Dialog PlayerEditorDialog = null;
|
public PlayerEditor(Window parent, Player player) : base(parent, new Builder("PlayerEditor.glade"))
|
||||||
[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;
|
EditObject = 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
|
protected override void LoadToModel()
|
||||||
|
|
||||||
private void SavePlayerButtonOnClicked(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
ReadToModel();
|
EditObject.Name = _nameEntry.Text;
|
||||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs(true, _player));
|
EditObject.Alias = _aliasEntry.Text;
|
||||||
PlayerEditorDialog.Dispose();
|
EditObject.HexId = _hexIdEntry.Text;
|
||||||
|
EditObject.Anonymous = _anonCheckButton.Active;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods
|
protected override void LoadFromModel()
|
||||||
|
|
||||||
private void ReadToModel()
|
|
||||||
{
|
{
|
||||||
_player.Name = PlayerNameEntry.Text;
|
_nameEntry.Text = EditObject.Name;
|
||||||
_player.Alias = PlayerAliasEntry.Text;
|
_aliasEntry.Text = EditObject.Alias;
|
||||||
_player.HexId = PlayerHexIdEntry.Text;
|
_hexIdEntry.Text = EditObject.HexId;
|
||||||
_player.Anonymous = PlayerAnonymousCheckButton.Active;
|
_anonCheckButton.Active = EditObject.Anonymous;
|
||||||
}
|
|
||||||
|
|
||||||
private void ReadFromModel()
|
|
||||||
{
|
|
||||||
PlayerNameEntry.Text = _player.Name;
|
|
||||||
PlayerAliasEntry.Text = _player.Alias;
|
|
||||||
PlayerHexIdEntry.Text = _player.HexId;
|
|
||||||
PlayerAnonymousCheckButton.Active = _player.Anonymous;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,12 @@ namespace EstusShots.Gtk
|
|||||||
new DataColumnDouble(nameof(Drink.Vol)) {Title = "%"}
|
new DataColumnDouble(nameof(Drink.Vol)) {Title = "%"}
|
||||||
};
|
};
|
||||||
_drinksControl = new BindableListControl<Drink>(drinkColumns, nameof(Drink.DrinkId), DrinksTreeView);
|
_drinksControl = new BindableListControl<Drink>(drinkColumns, nameof(Drink.DrinkId), DrinksTreeView);
|
||||||
|
_drinksControl.ItemActivated += item =>
|
||||||
|
{
|
||||||
|
var drinkEditor = new DrinkEditor(this, item);
|
||||||
|
drinkEditor.DialogClosed += DrinkEditorClosed;
|
||||||
|
drinkEditor.Show();
|
||||||
|
};
|
||||||
|
|
||||||
// TODO Only Load when navigated to
|
// TODO Only Load when navigated to
|
||||||
Task _;
|
Task _;
|
||||||
@@ -51,32 +57,36 @@ namespace EstusShots.Gtk
|
|||||||
_ = ReloadDrinks();
|
_ = ReloadDrinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
|
|
||||||
private void PlayersControlActivated(Player player)
|
private void PlayersControlActivated(Player player)
|
||||||
{
|
{
|
||||||
var dialog = new PlayerEditor(this, player);
|
var dialog = new PlayerEditor(this, player);
|
||||||
dialog.OnDialogClosed += PlayerEditorClosed;
|
dialog.DialogClosed += PlayerEditorClosed;
|
||||||
|
dialog.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NewPlayerButtonOnClicked(object sender, EventArgs e)
|
private void NewPlayerButtonOnClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var dialog = new PlayerEditor(this, new Player());
|
var dialog = new PlayerEditor(this, new Player());
|
||||||
dialog.OnDialogClosed += PlayerEditorClosed;
|
dialog.DialogClosed += PlayerEditorClosed;
|
||||||
|
dialog.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NewDrinkButtonOnClicked(object sender, EventArgs e)
|
private void NewDrinkButtonOnClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var dialog = new DrinkEditor(this, new Drink());
|
var dialog = new DrinkEditor(this, new Drink());
|
||||||
dialog.OnDialogClosed += DialogOnOnDialogClosed;
|
dialog.DialogClosed += DrinkEditorClosed;
|
||||||
|
dialog.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void DialogOnOnDialogClosed(object o, DialogClosedEventArgs args)
|
private async void DrinkEditorClosed(object o, DialogClosedEventArgs<Drink> args)
|
||||||
{
|
{
|
||||||
if (!args.Ok || !(args.Model is Drink drink)) return;
|
if (!args.Ok) return;
|
||||||
|
|
||||||
var res = await Task.Factory.StartNew(()
|
var res = await Task.Factory.StartNew(()
|
||||||
=> Client.Drinks.SaveDrink(new SaveDrinkParameter(drink)).Result);
|
=> Client.Drinks.SaveDrink(new SaveDrinkParameter(args.Model)).Result);
|
||||||
|
|
||||||
if (!res.OperationResult.Success)
|
if (!res.OperationResult.Success)
|
||||||
{
|
{
|
||||||
@@ -88,11 +98,11 @@ namespace EstusShots.Gtk
|
|||||||
await ReloadDrinks();
|
await ReloadDrinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void PlayerEditorClosed(object o, DialogClosedEventArgs args)
|
private async void PlayerEditorClosed(object o, DialogClosedEventArgs<Player> args)
|
||||||
{
|
{
|
||||||
if (!args.Ok || !(args.Model is Player player)) return;
|
if (!args.Ok) return;
|
||||||
var res = await Task.Factory.StartNew(()
|
var res = await Task.Factory.StartNew(()
|
||||||
=> Client.Players.SavePlayer(new SavePlayerParameter(player)).Result);
|
=> Client.Players.SavePlayer(new SavePlayerParameter(args.Model)).Result);
|
||||||
if (!res.OperationResult.Success)
|
if (!res.OperationResult.Success)
|
||||||
{
|
{
|
||||||
Info($"Unable to save: {res.OperationResult.ShortMessage}");
|
Info($"Unable to save: {res.OperationResult.ShortMessage}");
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace EstusShots.Gtk
|
|||||||
private void NewSeasonButtonOnClicked(object sender, EventArgs e)
|
private void NewSeasonButtonOnClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var dialog = new SeasonEditor(this, new Season());
|
var dialog = new SeasonEditor(this, new Season());
|
||||||
dialog.OnDialogClosed += SeasonEditorClosed;
|
dialog.DialogClosed += SeasonEditorClosed;
|
||||||
dialog.Show();
|
dialog.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ namespace EstusShots.Gtk
|
|||||||
private void SeasonsControlItemActivated(Season item)
|
private void SeasonsControlItemActivated(Season item)
|
||||||
{
|
{
|
||||||
var dialog = new SeasonEditor(this, item);
|
var dialog = new SeasonEditor(this, item);
|
||||||
dialog.OnDialogClosed += SeasonEditorClosed;
|
dialog.DialogClosed += SeasonEditorClosed;
|
||||||
dialog.Show();
|
dialog.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user