mirror of
https://github.com/Stone-Red-Code/StoneRed.LogicSimulator.git
synced 2026-09-04 00:56:23 +02:00
Implement custom dialogs
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<Project StylesheetPath="stylesheet/default_ui_skin.xmms">
|
||||
<Project.ExportOptions />
|
||||
<Window Title="" Left="393" Top="188">
|
||||
<VerticalStackPanel Spacing="5" Margin="10, 0, 10, 10">
|
||||
<Label Text="Cool info!" Id="info" />
|
||||
<HorizontalStackPanel Spacing="10" HorizontalAlignment="Right" Margin="5, 5, 0, 5">
|
||||
<TextButton Text="Ok" Padding="5, 5, 8, 5" Id="ok" />
|
||||
</HorizontalStackPanel>
|
||||
</VerticalStackPanel>
|
||||
</Window>
|
||||
</Project>
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project StylesheetPath="stylesheet/default_ui_skin.xmms">
|
||||
<Project.ExportOptions />
|
||||
<Window Title="" Left="384" Top="176">
|
||||
<VerticalStackPanel Spacing="5" Margin="10, 0, 10, 10">
|
||||
<Label Text="Enter something:" Id="label" />
|
||||
<TextBox Id="textBox" />
|
||||
<HorizontalStackPanel Spacing="10" HorizontalAlignment="Right" Margin="5, 5, 0, 5">
|
||||
<TextButton Text="Ok" Padding="5, 5, 8, 5" Id="ok" />
|
||||
<TextButton Text="Cancel" Padding="5, 5, 8, 5" Id="cancel" />
|
||||
</HorizontalStackPanel>
|
||||
</VerticalStackPanel>
|
||||
</Window>
|
||||
</Project>
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project StylesheetPath="stylesheet/default_ui_skin.xmms">
|
||||
<Project.ExportOptions />
|
||||
<Window Title="" Left="393" Top="188">
|
||||
<VerticalStackPanel Spacing="5" Margin="10, 0, 10, 10">
|
||||
<Label Text="Are you sure?" Id="label" />
|
||||
<HorizontalStackPanel Spacing="10" HorizontalAlignment="Right" Margin="5, 5, 0, 5">
|
||||
<TextButton Text="Ok" Padding="5, 5, 8, 5" Id="ok" />
|
||||
<TextButton Text="Cancel" Padding="5, 5, 8, 5" Id="cancel" />
|
||||
</HorizontalStackPanel>
|
||||
</VerticalStackPanel>
|
||||
</Window>
|
||||
</Project>
|
||||
@@ -38,9 +38,18 @@
|
||||
<None Update="Content\ContextMenu.xmmp">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Content\InfoDialog.xmmp">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Content\InputDialog.xmmp">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Content\LoadingScreen.xmmp">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Content\OkCancelDialog.xmmp">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Content\SaveWorldWindow.xmmp">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
@@ -4,6 +4,7 @@ using Microsoft.Xna.Framework;
|
||||
|
||||
using Myra.Graphics2D.UI;
|
||||
|
||||
using StoneRed.LogicSimulator.UserInterface.Windows;
|
||||
using StoneRed.LogicSimulator.WorldSaveSystem;
|
||||
|
||||
using System;
|
||||
@@ -48,7 +49,8 @@ internal class LoadingScreen : SrlsScreen<VerticalStackPanel>
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.CreateMessageBox("Error", string.Join(',', result.Errors.Select(e => e.Message))).Show(srls.Desktop);
|
||||
srls.ShowWindow(new InfoDialog(string.Join(',', result.Errors.Select(e => e.Message))));
|
||||
srls.LoadScreen<StartScreen>();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ internal class StartScreen : SrlsScreen<VerticalStackPanel>
|
||||
protected override void Initialize()
|
||||
{
|
||||
VerticalMenu menu = Root.FindChildById<VerticalMenu>("menu");
|
||||
menu.FindMenuItemById("menuQuit").Selected += (s, a) => srls.Exit();
|
||||
menu.FindMenuItemById("menuSettings").Selected += (s, a) => srls.ShowWindow<SettingsWindow>();
|
||||
menu.FindMenuItemById("menuStartNew").Selected += (s, a) => srls.LoadScreen<WorldScreen>();
|
||||
menu.FindMenuItemById("menuLoad").Selected += MenuLoad_Selected;
|
||||
menu.FindMenuItemById("menuQuit").Selected += (s, e) => srls.Exit();
|
||||
menu.FindMenuItemById("menuSettings").Selected += (s, e) => srls.ShowWindow<SettingsWindow>();
|
||||
menu.FindMenuItemById("menuStartNew").Selected += (s, e) => srls.LoadScreen<WorldScreen>();
|
||||
menu.FindMenuItemById("menuLoad").Selected += (s, e) => srls.ShowWindow<LoadWorldWindow>();
|
||||
}
|
||||
|
||||
protected override void Draw(GameTime gameTime)
|
||||
@@ -26,9 +26,4 @@ internal class StartScreen : SrlsScreen<VerticalStackPanel>
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
}
|
||||
|
||||
private void MenuLoad_Selected(object? sender, System.EventArgs e)
|
||||
{
|
||||
srls.ShowWindow<LoadWorldWindow>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Myra.Graphics2D.UI;
|
||||
|
||||
using System;
|
||||
|
||||
namespace StoneRed.LogicSimulator.UserInterface.Windows;
|
||||
|
||||
internal class InfoDialog : SrlsWindow
|
||||
{
|
||||
public event EventHandler? Ok;
|
||||
|
||||
private readonly string infoText;
|
||||
protected override string XmmpPath => "InfoDialog.xmmp";
|
||||
|
||||
public InfoDialog(string infoText)
|
||||
{
|
||||
this.infoText = infoText;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
Label label = window.FindChildById<Label>("info");
|
||||
TextButton okButton = window.FindChildById<TextButton>("ok");
|
||||
|
||||
label.Text = infoText;
|
||||
|
||||
okButton.Click += OkButton_Click;
|
||||
}
|
||||
|
||||
private void OkButton_Click(object? sender, EventArgs e)
|
||||
{
|
||||
Ok?.Invoke(this, EventArgs.Empty);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using Myra.Graphics2D.UI;
|
||||
|
||||
using System;
|
||||
|
||||
namespace StoneRed.LogicSimulator.UserInterface.Windows;
|
||||
|
||||
internal class InputDialog : SrlsWindow
|
||||
{
|
||||
public event EventHandler<InputDialogEventArgs>? Ok;
|
||||
|
||||
public event EventHandler? Cancel;
|
||||
|
||||
private readonly string labelText;
|
||||
private readonly string okButtonText;
|
||||
private readonly string cancelButtonText;
|
||||
private TextBox textBox = null!;
|
||||
|
||||
protected override string XmmpPath => "InputDialog.xmmp";
|
||||
|
||||
public InputDialog(string labelText)
|
||||
{
|
||||
this.labelText = labelText;
|
||||
okButtonText = "Ok";
|
||||
cancelButtonText = "Cancel";
|
||||
}
|
||||
|
||||
public InputDialog(string labelText, string okButtonText, string cancelButtonText)
|
||||
{
|
||||
this.labelText = labelText;
|
||||
this.okButtonText = okButtonText;
|
||||
this.cancelButtonText = cancelButtonText;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
textBox = window.FindChildById<TextBox>("textBox");
|
||||
Label label = window.FindChildById<Label>("label");
|
||||
TextButton okButton = window.FindChildById<TextButton>("ok");
|
||||
TextButton cancelButton = window.FindChildById<TextButton>("cancel");
|
||||
|
||||
label.Text = labelText;
|
||||
okButton.Text = okButtonText;
|
||||
cancelButton.Text = cancelButtonText;
|
||||
|
||||
okButton.Click += OkButton_Click;
|
||||
cancelButton.Click += CancelButton_Click;
|
||||
}
|
||||
|
||||
private void OkButton_Click(object? sender, EventArgs e)
|
||||
{
|
||||
Ok?.Invoke(this, new(textBox.Text));
|
||||
Close();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object? sender, EventArgs e)
|
||||
{
|
||||
Cancel?.Invoke(this, EventArgs.Empty);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
internal class InputDialogEventArgs : EventArgs
|
||||
{
|
||||
public string Text { get; set; }
|
||||
|
||||
public InputDialogEventArgs(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using Myra.Graphics2D.UI;
|
||||
|
||||
using System;
|
||||
|
||||
namespace StoneRed.LogicSimulator.UserInterface.Windows;
|
||||
|
||||
internal class OkCancelDialog : SrlsWindow
|
||||
{
|
||||
public event EventHandler? Ok;
|
||||
|
||||
public event EventHandler? Cancel;
|
||||
|
||||
private readonly string labelText;
|
||||
private readonly string okButtonText;
|
||||
private readonly string cancelButtonText;
|
||||
protected override string XmmpPath => "OkCancelDialog.xmmp";
|
||||
|
||||
public OkCancelDialog(string labelText)
|
||||
{
|
||||
this.labelText = labelText;
|
||||
okButtonText = "Ok";
|
||||
cancelButtonText = "Cancel";
|
||||
}
|
||||
|
||||
public OkCancelDialog(string labelText, string okButtonText, string cancelButtonText)
|
||||
{
|
||||
this.labelText = labelText;
|
||||
this.okButtonText = okButtonText;
|
||||
this.cancelButtonText = cancelButtonText;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
Label label = window.FindChildById<Label>("label");
|
||||
TextButton okButton = window.FindChildById<TextButton>("ok");
|
||||
TextButton cancelButton = window.FindChildById<TextButton>("cancel");
|
||||
|
||||
label.Text = labelText;
|
||||
okButton.Text = okButtonText;
|
||||
cancelButton.Text = cancelButtonText;
|
||||
|
||||
okButton.Click += OkButton_Click;
|
||||
cancelButton.Click += CancelButton_Click;
|
||||
}
|
||||
|
||||
private void OkButton_Click(object? sender, EventArgs e)
|
||||
{
|
||||
Ok?.Invoke(this, EventArgs.Empty);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object? sender, EventArgs e)
|
||||
{
|
||||
Cancel?.Invoke(this, EventArgs.Empty);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
@@ -20,27 +20,28 @@ internal class QuickMenu : SrlsWindow
|
||||
{
|
||||
VerticalMenu menu = window.FindChildById<VerticalMenu>("menu");
|
||||
|
||||
menu.FindMenuItemById("menuMainMenu").Selected += (s, a) => srls.LoadScreen<StartScreen>();
|
||||
menu.FindMenuItemById("menuMainMenu").Selected += MenuMainMenu_Selected;
|
||||
menu.FindMenuItemById("menuSettings").Selected += (s, a) => srls.ShowWindow<SettingsWindow>();
|
||||
menu.FindMenuItemById("menuSave").Selected += (s, a) => srls.ShowWindow(new SaveWorldWindow(worldData));
|
||||
menu.FindMenuItemById("menuLoad").Selected += (s, a) => srls.ShowWindow<LoadWorldWindow>();
|
||||
menu.FindMenuItemById("menuQuit").Selected += QuickMenu_Selected;
|
||||
menu.FindMenuItemById("menuQuit").Selected += MenuQuit_Selected;
|
||||
}
|
||||
|
||||
private void QuickMenu_Selected(object? sender, System.EventArgs e)
|
||||
private void MenuMainMenu_Selected(object? sender, System.EventArgs e)
|
||||
{
|
||||
Dialog dialog = Dialog.CreateMessageBox("Quit?", "Would you like to quit?");
|
||||
OkCancelDialog okCancelDialog = new OkCancelDialog("Do you really want to go to the main menu?", "Yes", "No");
|
||||
|
||||
dialog.Closed += (s, a) =>
|
||||
{
|
||||
if (!dialog.Result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
okCancelDialog.Ok += (s, a) => srls.LoadScreen<StartScreen>();
|
||||
|
||||
srls.Exit();
|
||||
};
|
||||
srls.ShowWindow(okCancelDialog);
|
||||
}
|
||||
|
||||
dialog.ShowModal(srls.Desktop);
|
||||
private void MenuQuit_Selected(object? sender, System.EventArgs e)
|
||||
{
|
||||
OkCancelDialog okCancelDialog = new OkCancelDialog("Do you really want to quit?", "Yes", "No");
|
||||
|
||||
okCancelDialog.Ok += (s, a) => srls.Exit();
|
||||
|
||||
srls.ShowWindow(okCancelDialog);
|
||||
}
|
||||
}
|
||||
@@ -34,10 +34,18 @@ internal class SaveWorldWindow : SrlsWindow
|
||||
saveButton.Click += SaveButton_Clicked;
|
||||
newSaveButton.Click += NewSaveButton_Click;
|
||||
|
||||
int index = 0;
|
||||
foreach (string directories in Directory.GetDirectories(Paths.GetWorldSavesPath()))
|
||||
{
|
||||
string saveName = Path.GetFileName(directories) ?? string.Empty;
|
||||
savesListBox.Items.Add(new(saveName));
|
||||
|
||||
if (saveName == worldData.SaveName)
|
||||
{
|
||||
savesListBox.SelectedIndex = index;
|
||||
saveButton.Enabled = true;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
savesListBox.SelectedIndexChanged += SavesListBox_SelectedIndexChanged;
|
||||
@@ -48,9 +56,23 @@ internal class SaveWorldWindow : SrlsWindow
|
||||
saveButton.Enabled = savesListBox.SelectedItem is not null;
|
||||
}
|
||||
|
||||
private async void NewSaveButton_Click(object? sender, EventArgs e)
|
||||
private void NewSaveButton_Click(object? sender, EventArgs e)
|
||||
{
|
||||
worldData.SaveName = "New Save";
|
||||
InputDialog inputDialog = new InputDialog("Enter a name for the new save");
|
||||
inputDialog.Ok += NewSaveInputDialog_Ok;
|
||||
|
||||
srls.ShowWindow(inputDialog);
|
||||
}
|
||||
|
||||
private async void NewSaveInputDialog_Ok(object? sender, InputDialogEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(e.Text))
|
||||
{
|
||||
srls.ShowWindow(new InfoDialog("Please enter a valid name"));
|
||||
return;
|
||||
}
|
||||
|
||||
worldData.SaveName = e.Text;
|
||||
await Save();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user