From 8acefda778fd1d04906a8aa0a8dd32f968098727 Mon Sep 17 00:00:00 2001 From: isaisstillalive Date: Sun, 5 Jul 2020 21:19:14 +0900 Subject: [PATCH] Show edit marker dialog instead deleting marker --- src/js/game/hud/parts/waypoints.js | 57 ++++++++++++++++++++++++++++-- translations/base-en.yaml | 4 +++ translations/base-ja.yaml | 4 +++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/js/game/hud/parts/waypoints.js b/src/js/game/hud/parts/waypoints.js index 365ccbba..095db815 100644 --- a/src/js/game/hud/parts/waypoints.js +++ b/src/js/game/hud/parts/waypoints.js @@ -169,7 +169,7 @@ export class HUDWaypoints extends BaseHUDPart { if (this.isWaypointDeletable(waypoint)) { const deleteButton = makeDiv(element, null, ["deleteButton"]); - this.trackClicks(deleteButton, () => this.deleteWaypoint(waypoint)); + this.trackClicks(deleteButton, () => this.requestEditMarker(waypoint)); } if (!waypoint.label) { @@ -284,6 +284,59 @@ export class HUDWaypoints extends BaseHUDPart { this.rerenderWaypointList(); } + /** + * Requests to edit a marker. + * @param {Waypoint} waypoint + */ + requestEditMarker(waypoint) { + // Construct dialog with input field + const markerNameInput = new FormElementInput({ + id: "markerName", + label: null, + placeholder: "", + defaultValue: 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.editMarker.title, + desc: T.dialogs.editMarker.desc, + formElements: [markerNameInput], + extraButton: "delete:bad", + }); + this.root.hud.parts.dialogs.internalShowDialog(dialog); + + dialog.buttonSignals.ok.add(() => { + // Actually rename the waypoint + this.renameWaypoint(waypoint, markerNameInput.getValue()); + }); + dialog.buttonSignals.delete.add(() => { + // Actually delete the waypoint + this.deleteWaypoint(waypoint); + }); + } + + /** + * Renames a waypoint with the given label + * @param {Waypoint} waypoint + * @param {string} label + */ + renameWaypoint(waypoint, label) { + waypoint.label = label; + + this.sort(); + + // 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 */ @@ -387,7 +440,7 @@ export class HUDWaypoints extends BaseHUDPart { } else if (button === enumMouseButton.right) { if (this.isWaypointDeletable(waypoint)) { this.root.soundProxy.playUiClick(); - this.deleteWaypoint(waypoint); + this.requestEditMarker(waypoint); } else { this.root.soundProxy.playUiError(); } diff --git a/translations/base-en.yaml b/translations/base-en.yaml index c126f7b9..a5d89ed2 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -284,6 +284,10 @@ dialogs: title: New Marker desc: Give it a meaningful name, you can also include a short key of a shape (Which you can generate here) + editMarker: + title: Edit Marker + desc: Give it a new meaningful name, you can also include a short key of a shape (Which you can generate here) + markerDemoLimit: desc: You can only create two custom markers in the demo. Get the standalone for unlimited markers! diff --git a/translations/base-ja.yaml b/translations/base-ja.yaml index 3e6ba511..f25fa9bb 100644 --- a/translations/base-ja.yaml +++ b/translations/base-ja.yaml @@ -255,6 +255,10 @@ dialogs: title: マーカーを設置 desc: わかりやすい名前をつけてください。形を表す短いキーを含めることもできます。(ここから生成できます) + editMarker: + title: マーカーを編集 + desc: わかりやすい名前をつけてください。形を表す短いキーを含めることもできます。(ここから生成できます) + markerDemoLimit: desc: デモ版ではマーカー設置は2つまでに制限されています。スタンドアローン版は無制限です!