-
Notifications
You must be signed in to change notification settings - Fork 0
/
CityNameWindow.xaml.cs
61 lines (56 loc) · 1.83 KB
/
CityNameWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Windows;
using ErsatzCivLib;
using ErsatzCivLib.Model;
namespace ErsatzCiv
{
/// <summary>
/// Interaction logic of the window.
/// </summary>
public partial class CityNameWindow : Window
{
private readonly EnginePivot _engine;
/// <summary>
/// The city built; <c>Null</c> by default.
/// </summary>
public CityPivot City { get; private set; }
/// <summary>
/// The unit used to built the city.
/// </summary>
public UnitPivot UnitUsed { get; private set; }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="engine">The <see cref="EnginePivot"/>.</param>
public CityNameWindow(EnginePivot engine)
{
InitializeComponent();
_engine = engine;
City = null;
TextBoxCityName.Text = _engine.HumanPlayer.GetNextCityName;
}
private void ButtonValidate_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(TextBoxCityName.Text))
{
UnitUsed = _engine.HumanPlayer.CurrentUnit; // important because "BuildCity()" changes the "CurrentUnit" value !
City = _engine.BuildCity(TextBoxCityName.Text.Trim(), out bool nonUniquenameError);
if (nonUniquenameError)
{
MessageBox.Show("Please specify a unique city name.", "ErsatzCiv");
}
else
{
Close();
}
}
else
{
MessageBox.Show("Please specify a non-empty city name.", "ErsatzCiv");
}
}
private void ButtonCancel_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}