Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/TSMapEditor/UI/CursorActions/PlaceWaypointCursorAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ public PlaceWaypointCursorAction(ICursorActionTarget cursorActionTarget) : base(

public override void LeftClick(Point2D cellCoords)
{
PlaceWaypointWindow.Open(cellCoords);
if (Keyboard.IsShiftHeldDown())
{
int availableWaypointNumber = PlaceWaypointWindow.GetAvailableWaypointNumber();
PlaceWaypointWindow.PlaceWaypoint(availableWaypointNumber, cellCoords);
}
else
{
PlaceWaypointWindow.Open(cellCoords);
}
}

public override void DrawPreview(Point2D cellCoords, Point2D cameraTopLeftPoint)
Expand Down
38 changes: 27 additions & 11 deletions src/TSMapEditor/UI/Windows/PlaceWaypointWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,51 +57,67 @@ private void BtnPlace_LeftClick(object sender, EventArgs e)
return;
}

if (tbWaypointNumber.Value < 0 || tbWaypointNumber.Value >= Constants.MaxWaypoint)
int waypointNumber = tbWaypointNumber.Value;

PlaceWaypoint(waypointNumber, cellCoords);
Hide();
}

public void PlaceWaypoint(int waypointNumber, Point2D cellCoords)
{
if (waypointNumber < 0 || waypointNumber >= Constants.MaxWaypoint)
return;

if (map.Waypoints.Exists(w => w.Identifier == tbWaypointNumber.Value))
if (map.Waypoints.Exists(w => w.Identifier == waypointNumber))
{
EditorMessageBox.Show(WindowManager,
Translate(this, "WaypointExists.Title", "Waypoint already exists"),
string.Format(Translate(this, "WaypointExists.Description",
"A waypoint with the given number {0} already exists on the map!"), tbWaypointNumber.Value),
string.Format(Translate(this, "WaypointExists.Description",
"A waypoint with the given number {0} already exists on the map!"), waypointNumber),
MessageBoxButtons.OK);

return;
}

string waypointColor = ddWaypointColor.SelectedItem != null ? ddWaypointColor.SelectedItem.Text : null;

mutationManager.PerformMutation(new PlaceWaypointMutation(mutationTarget, cellCoords, tbWaypointNumber.Value, waypointColor));

Hide();
mutationManager.PerformMutation(new PlaceWaypointMutation(mutationTarget, cellCoords, waypointNumber, waypointColor));
}

public void Open(Point2D cellCoords)
{
this.cellCoords = cellCoords;

int availableWaypointNumber = GetAvailableWaypointNumber();
if (availableWaypointNumber < 0)
return;

tbWaypointNumber.Value = availableWaypointNumber;

Show();
}

public int GetAvailableWaypointNumber()
{
if (map.Waypoints.Count == Constants.MaxWaypoint)
{
EditorMessageBox.Show(WindowManager,
Translate(this, "MaxWaypoints.Title", "Maximum waypoints reached"),
Translate(this, "MaxWaypoints.Description", "All valid waypoints on the map are already in use!"),
MessageBoxButtons.OK);

return;
return -1;
}

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;
return i;
}
}

Show();
return -1;
}
}
}
Loading