@@ -57,51 +57,67 @@ private void BtnPlace_LeftClick(object sender, EventArgs e)
5757 return ;
5858 }
5959
60- if ( tbWaypointNumber . Value < 0 || tbWaypointNumber . Value >= Constants . MaxWaypoint )
60+ int waypointNumber = tbWaypointNumber . Value ;
61+
62+ PlaceWaypoint ( waypointNumber , cellCoords ) ;
63+ Hide ( ) ;
64+ }
65+
66+ public void PlaceWaypoint ( int waypointNumber , Point2D cellCoords )
67+ {
68+ if ( waypointNumber < 0 || waypointNumber >= Constants . MaxWaypoint )
6169 return ;
6270
63- if ( map . Waypoints . Exists ( w => w . Identifier == tbWaypointNumber . Value ) )
71+ if ( map . Waypoints . Exists ( w => w . Identifier == waypointNumber ) )
6472 {
6573 EditorMessageBox . Show ( WindowManager ,
6674 Translate ( this , "WaypointExists.Title" , "Waypoint already exists" ) ,
67- string . Format ( Translate ( this , "WaypointExists.Description" ,
68- "A waypoint with the given number {0} already exists on the map!" ) , tbWaypointNumber . Value ) ,
75+ string . Format ( Translate ( this , "WaypointExists.Description" ,
76+ "A waypoint with the given number {0} already exists on the map!" ) , waypointNumber ) ,
6977 MessageBoxButtons . OK ) ;
7078
7179 return ;
7280 }
7381
7482 string waypointColor = ddWaypointColor . SelectedItem != null ? ddWaypointColor . SelectedItem . Text : null ;
7583
76- mutationManager . PerformMutation ( new PlaceWaypointMutation ( mutationTarget , cellCoords , tbWaypointNumber . Value , waypointColor ) ) ;
77-
78- Hide ( ) ;
84+ mutationManager . PerformMutation ( new PlaceWaypointMutation ( mutationTarget , cellCoords , waypointNumber , waypointColor ) ) ;
7985 }
8086
8187 public void Open ( Point2D cellCoords )
8288 {
8389 this . cellCoords = cellCoords ;
8490
91+ int availableWaypointNumber = GetAvailableWaypointNumber ( ) ;
92+ if ( availableWaypointNumber < 0 )
93+ return ;
94+
95+ tbWaypointNumber . Value = availableWaypointNumber ;
96+
97+ Show ( ) ;
98+ }
99+
100+ public int GetAvailableWaypointNumber ( )
101+ {
85102 if ( map . Waypoints . Count == Constants . MaxWaypoint )
86103 {
87104 EditorMessageBox . Show ( WindowManager ,
88105 Translate ( this , "MaxWaypoints.Title" , "Maximum waypoints reached" ) ,
89106 Translate ( this , "MaxWaypoints.Description" , "All valid waypoints on the map are already in use!" ) ,
90107 MessageBoxButtons . OK ) ;
91108
92- return ;
109+ return - 1 ;
93110 }
94111
95112 for ( int i = 0 ; i < Constants . MaxWaypoint ; i ++ )
96113 {
97114 if ( ! map . Waypoints . Exists ( w => w . Identifier == i ) && ( Constants . IsRA2YR || i != Constants . TS_WAYPT_SPECIAL ) )
98115 {
99- tbWaypointNumber . Value = i ;
100- break ;
116+ return i ;
101117 }
102118 }
103119
104- Show ( ) ;
120+ return - 1 ;
105121 }
106122 }
107123}
0 commit comments