forked from CnCNet/WorldAlteringEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaceWaypointWindow.cs
More file actions
106 lines (85 loc) · 3.67 KB
/
PlaceWaypointWindow.cs
File metadata and controls
106 lines (85 loc) · 3.67 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Globalization;
using Rampastring.XNAUI;
using Rampastring.XNAUI.XNAControls;
using TSMapEditor.GameMath;
using TSMapEditor.Models;
using TSMapEditor.Mutations;
using TSMapEditor.Mutations.Classes;
using TSMapEditor.UI.Controls;
namespace TSMapEditor.UI.Windows
{
public class PlaceWaypointWindow : INItializableWindow
{
public PlaceWaypointWindow(WindowManager windowManager, Map map, MutationManager mutationManager, IMutationTarget mutationTarget) : base(windowManager)
{
this.map = map;
this.mutationManager = mutationManager;
this.mutationTarget = mutationTarget;
}
private readonly Map map;
private readonly MutationManager mutationManager;
private readonly IMutationTarget mutationTarget;
private EditorNumberTextBox tbWaypointNumber;
private XNALabel lblDescription;
private XNADropDown ddWaypointColor;
private Point2D cellCoords;
public override void Initialize()
{
Name = nameof(PlaceWaypointWindow);
base.Initialize();
tbWaypointNumber = FindChild<EditorNumberTextBox>(nameof(tbWaypointNumber));
tbWaypointNumber.MaximumTextLength = (Constants.MaxWaypoint - 1).ToString(CultureInfo.InvariantCulture).Length;
lblDescription = FindChild<XNALabel>(nameof(lblDescription));
lblDescription.Text = $"Input waypoint number (0-{Constants.MaxWaypoint - 1}):";
FindChild<EditorButton>("btnPlace").LeftClick += BtnPlace_LeftClick;
// Init color dropdown options
ddWaypointColor = FindChild<XNADropDown>(nameof(ddWaypointColor));
ddWaypointColor.AddItem("None");
Array.ForEach(Waypoint.SupportedColors, sc => ddWaypointColor.AddItem(sc.Name, sc.Value));
}
private void BtnPlace_LeftClick(object sender, EventArgs e)
{
// Cancel dialog if the user leaves the text box empty
if (tbWaypointNumber.Text == string.Empty)
{
Hide();
return;
}
if (tbWaypointNumber.Value < 0 || tbWaypointNumber.Value >= Constants.MaxWaypoint)
return;
if (map.Waypoints.Exists(w => w.Identifier == tbWaypointNumber.Value))
{
EditorMessageBox.Show(WindowManager,
"Waypoint already exists",
$"A waypoint with the given number {tbWaypointNumber.Value} already exists on the map!",
MessageBoxButtons.OK);
return;
}
string waypointColor = ddWaypointColor.SelectedItem != null ? ddWaypointColor.SelectedItem.Text : null;
mutationManager.PerformMutation(new PlaceWaypointMutation(mutationTarget, cellCoords, tbWaypointNumber.Value, waypointColor));
Hide();
}
public void Open(Point2D cellCoords)
{
this.cellCoords = cellCoords;
if (map.Waypoints.Count == Constants.MaxWaypoint)
{
EditorMessageBox.Show(WindowManager,
"Maximum waypoints reached",
"All valid waypoints on the map are already in use!",
MessageBoxButtons.OK);
return;
}
for (int i = 0; i < Constants.MaxWaypoint; i++)
{
if (!map.Waypoints.Exists(w => w.Identifier == i) && (Constants.IsRA2YR || i != Constants.TS_WAYPT_SPECIAL))
{
tbWaypointNumber.Value = i;
break;
}
}
Show();
}
}
}