@ -109,9 +109,7 @@ export class HUDWaypoints extends BaseHUDPart {
// Catch mouse and key events
this . root . camera . downPreHandler . add ( this . onMouseDown , this ) ;
this . root . keyMapper
. getBinding ( KEYMAPPINGS . navigation . createMarker )
. add ( this . requestCreateMarker , this ) ;
this . root . keyMapper . getBinding ( KEYMAPPINGS . navigation . createMarker ) . add ( this . requestSaveMarker , this ) ;
/ * *
* Stores at how much opacity the markers should be rendered on the map .
@ -168,8 +166,8 @@ export class HUDWaypoints extends BaseHUDPart {
}
if ( this . isWaypointDeletable ( waypoint ) ) {
const del ete Button = makeDiv ( element , null , [ " del ete Button"] ) ;
this . trackClicks ( del ete Button, ( ) => this . deleteWaypoint( waypoint ) ) ;
const edi tButton = makeDiv ( element , null , [ " edi tButton"] ) ;
this . trackClicks ( edi tButton, ( ) => this . requestSaveMarker( { waypoint } ) ) ;
}
if ( ! waypoint . label ) {
@ -220,42 +218,61 @@ export class HUDWaypoints extends BaseHUDPart {
}
/ * *
* Requests to creat e a marker at the current camera position . If worldPos is set ,
* Requests to sav e a marker at the current camera position . If worldPos is set ,
* uses that position instead .
* @ param { Vector = } worldPos Override the world pos , otherwise it is the camera position
* @ param { object } param0
* @ param { Vector = } param0 . worldPos Override the world pos , otherwise it is the camera position
* @ param { Waypoint = } param0 . waypoint Waypoint to be edited . If omitted , create new
* /
requestCreateMarker ( worldPos = null ) {
request SaveMarker( { worldPos = null , waypoint = null } ) {
// Construct dialog with input field
const markerNameInput = new FormElementInput ( {
id : "markerName" ,
label : null ,
placeholder : "" ,
defaultValue : waypoint ? waypoint . label : "" ,
validator : val =>
val . length > 0 && ( val . length < MAX _LABEL _LENGTH || ShapeDefinition . isValidShortKey ( val ) ) ,
} ) ;
const dialog = new DialogWithForm ( {
app : this . root . app ,
title : T. dialogs . createMarker . title ,
title : waypoint ? T . dialogs . createMarker . titleEdit : T. dialogs . createMarker . title ,
desc : T . dialogs . createMarker . desc ,
formElements : [ markerNameInput ] ,
buttons : waypoint ? [ "delete:bad" , "cancel" , "ok:good" ] : [ "cancel" , "ok:good" ] ,
} ) ;
this . root . hud . parts . dialogs . internalShowDialog ( dialog ) ;
// Compute where to create the marker
const center = worldPos || this . root . camera . center ;
dialog . buttonSignals . ok . add ( ( ) => {
// Show info that you can have only N markers in the demo,
// actually show this *after* entering the name so you want the
// standalone even more (I'm evil :P)
if ( IS _DEMO && this . waypoints . length > 2 ) {
this . root . hud . parts . dialogs . showFeatureRestrictionInfo ( "" , T . dialogs . markerDemoLimit . desc ) ;
return ;
}
// Edit marker
if ( waypoint ) {
dialog . buttonSignals . ok . add ( ( ) => {
// Actually rename the waypoint
this . renameWaypoint ( waypoint , markerNameInput . getValue ( ) ) ;
} ) ;
dialog . buttonSignals . delete . add ( ( ) => {
// Actually delete the waypoint
this . deleteWaypoint ( waypoint ) ;
} ) ;
} else {
// Compute where to create the marker
const center = worldPos || this . root . camera . center ;
dialog . buttonSignals . ok . add ( ( ) => {
// Show info that you can have only N markers in the demo,
// actually show this *after* entering the name so you want the
// standalone even more (I'm evil :P)
if ( IS _DEMO && this . waypoints . length > 2 ) {
this . root . hud . parts . dialogs . showFeatureRestrictionInfo (
"" ,
T . dialogs . markerDemoLimit . desc
) ;
return ;
}
// Actually create the waypoint
this . addWaypoint ( markerNameInput . getValue ( ) , center ) ;
} ) ;
// Actually create the waypoint
this . addWaypoint ( markerNameInput . getValue ( ) , center ) ;
} ) ;
}
}
/ * *
@ -272,18 +289,7 @@ export class HUDWaypoints extends BaseHUDPart {
zoomLevel : Math . max ( this . root . camera . zoomLevel , globalConfig . mapChunkOverviewMinZoom + 0.05 ) ,
} ) ;
// Sort waypoints by name
this . waypoints . sort ( ( a , b ) => {
if ( ! a . label ) {
return - 1 ;
}
if ( ! b . label ) {
return 1 ;
}
return this . getWaypointLabel ( a )
. padEnd ( MAX _LABEL _LENGTH , "0" )
. localeCompare ( this . getWaypointLabel ( b ) . padEnd ( MAX _LABEL _LENGTH , "0" ) ) ;
} ) ;
this . sortWaypoints ( ) ;
// Show notification about creation
this . root . hud . signals . notification . dispatch (
@ -295,6 +301,26 @@ export class HUDWaypoints extends BaseHUDPart {
this . rerenderWaypointList ( ) ;
}
/ * *
* Renames a waypoint with the given label
* @ param { Waypoint } waypoint
* @ param { string } label
* /
renameWaypoint ( waypoint , label ) {
waypoint . label = label ;
this . sortWaypoints ( ) ;
// Show notification about renamed
this . root . hud . signals . notification . dispatch (
T . ingame . waypoints . creationSuccessNotification ,
enumNotificationType . success
) ;
// Re-render the list and thus add it
this . rerenderWaypointList ( ) ;
}
/ * *
* Called every frame to update stuff
* /
@ -304,6 +330,23 @@ export class HUDWaypoints extends BaseHUDPart {
}
}
/ * *
* Sort waypoints by name
* /
sortWaypoints ( ) {
this . waypoints . sort ( ( a , b ) => {
if ( ! a . label ) {
return - 1 ;
}
if ( ! b . label ) {
return 1 ;
}
return this . getWaypointLabel ( a )
. padEnd ( MAX _LABEL _LENGTH , "0" )
. localeCompare ( this . getWaypointLabel ( b ) . padEnd ( MAX _LABEL _LENGTH , "0" ) ) ;
} ) ;
}
/ * *
* Returns the label for a given waypoint
* @ param { Waypoint } waypoint
@ -381,7 +424,7 @@ export class HUDWaypoints extends BaseHUDPart {
} else if ( button === enumMouseButton . right ) {
if ( this . isWaypointDeletable ( waypoint ) ) {
this . root . soundProxy . playUiClick ( ) ;
this . deleteWaypoint( waypoint ) ;
this . requestSaveMarker( { waypoint } ) ;
} else {
this . root . soundProxy . playUiError ( ) ;
}
@ -393,7 +436,7 @@ export class HUDWaypoints extends BaseHUDPart {
if ( button === enumMouseButton . right ) {
if ( this . root . camera . getIsMapOverlayActive ( ) ) {
const worldPos = this . root . camera . screenToWorld ( pos ) ;
this . request CreateMarker( worldPos ) ;
this . request SaveMarker( { worldPos } ) ;
return STOP _PROPAGATION ;
}
}