From f34813392f9e9743c3ae22f0b51f0f1213475a8c Mon Sep 17 00:00:00 2001 From: hexagonhexagon Date: Thu, 11 Jun 2020 02:19:44 -0400 Subject: [PATCH 1/2] Add Cut keybind. --- src/js/game/hud/parts/mass_selector.js | 48 ++++++++++++++++++++++++++ src/js/game/key_action_mapper.js | 1 + translations/base-en.yaml | 10 ++++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/js/game/hud/parts/mass_selector.js b/src/js/game/hud/parts/mass_selector.js index f89d4055..e80f5691 100644 --- a/src/js/game/hud/parts/mass_selector.js +++ b/src/js/game/hud/parts/mass_selector.js @@ -22,6 +22,9 @@ export class HUDMassSelector extends BaseHUDPart { .getBinding(KEYMAPPINGS.massSelect.confirmMassDelete) .getKeyCodeString(); const abortKeybinding = this.root.keyMapper.getBinding(KEYMAPPINGS.general.back).getKeyCodeString(); + const cutKeybinding = this.root.keyMapper + .getBinding(KEYMAPPINGS.massSelect.massSelectCut) + .getKeyCodeString(); const copyKeybinding = this.root.keyMapper .getBinding(KEYMAPPINGS.massSelect.massSelectCopy) .getKeyCodeString(); @@ -32,6 +35,7 @@ export class HUDMassSelector extends BaseHUDPart { [], T.ingame.massSelect.infoText .replace("", `${removalKeybinding}`) + .replace("", `${cutKeybinding}`) .replace("", `${copyKeybinding}`) .replace("", `${abortKeybinding}`) ); @@ -54,6 +58,7 @@ export class HUDMassSelector extends BaseHUDPart { this.root.keyMapper .getBinding(KEYMAPPINGS.massSelect.confirmMassDelete) .add(this.confirmDelete, this); + this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectCut).add(this.confirmCut, this); this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectCopy).add(this.startCopy, this); this.domAttach = new DynamicDomAttach(this.root, this.element); @@ -123,6 +128,49 @@ export class HUDMassSelector extends BaseHUDPart { } } + confirmCut() { + if (!this.root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_blueprints)) { + this.root.hud.parts.dialogs.showInfo( + T.dialogs.blueprintsNotUnlocked.title, + T.dialogs.blueprintsNotUnlocked.desc + ); + } else if (this.selectedUids.size > 100) { + const { ok } = this.root.hud.parts.dialogs.showWarning( + T.dialogs.massCutConfirm.title, + T.dialogs.massCutConfirm.desc.replace( + "", + "" + formatBigNumberFull(this.selectedUids.size) + ), + ["cancel:good", "ok:bad"] + ); + ok.add(() => this.doCut()); + } else { + this.doCut(); + } + } + + doCut() { + if (this.selectedUids.size > 0) { + const entityUids = Array.from(this.selectedUids); + + // copy code relies on entities still existing, so must copy before deleting. + this.root.hud.signals.buildingsSelectedForCopy.dispatch(entityUids); + + for (let i = 0; i < entityUids.length; ++i) { + const uid = entityUids[i]; + const entity = this.root.entityMgr.findByUid(uid); + if (!this.root.logic.tryDeleteBuilding(entity)) { + logger.error("Error in mass cut, could not remove building"); + this.selectedUids.delete(uid); + } + } + + this.root.soundProxy.playUiClick(); + } else { + this.root.soundProxy.playUiError(); + } + } + /** * mouse down pre handler * @param {Vector} pos diff --git a/src/js/game/key_action_mapper.js b/src/js/game/key_action_mapper.js index 9de75731..532e53cd 100644 --- a/src/js/game/key_action_mapper.js +++ b/src/js/game/key_action_mapper.js @@ -65,6 +65,7 @@ export const KEYMAPPINGS = { massSelectStart: { keyCode: 17 }, // CTRL massSelectSelectMultiple: { keyCode: 16 }, // SHIFT massSelectCopy: { keyCode: key("C") }, + massSelectCut: { keyCode: key("X") }, confirmMassDelete: { keyCode: 46 }, // DEL }, diff --git a/translations/base-en.yaml b/translations/base-en.yaml index ab054e32..472d542d 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -36,7 +36,7 @@ steamPage: Since shapes can get boring soon you need to mix colors and paint your shapes with it - Combine red, green and blue color resources to produce different colors and paint shapes with it to satisfy the demand. - This game features 18 levels (Which should keep you busy for hours already!) but I'm constantly adding new content - There is a lot planned! + This game features 18 levels (Which should keep you busy for hours already!) but I'm constantly adding new content - There is a lot planned! [b]Standalone Advantages[/b] @@ -250,6 +250,11 @@ dialogs: desc: >- You are deleting a lot of buildings ( to be exact)! Are you sure you want to do this? + massCutConfirm: + title: Confirm cut + desc: >- + You are cutting a lot of buildings ( to be exact)! Are you sure you want to do this? + blueprintsNotUnlocked: title: Not unlocked yet desc: >- @@ -324,7 +329,7 @@ ingame: # Mass select information, this is when you hold CTRL and then drag with your mouse # to select multiple buildings massSelect: - infoText: Press to copy, to remove and to cancel. + infoText: Press to cut, to copy, to remove and to cancel. # The "Upgrades" window shop: @@ -710,6 +715,7 @@ keybindings: massSelectStart: Hold and drag to start massSelectSelectMultiple: Select multiple areas massSelectCopy: Copy area + massSelectCut: Cut area placementDisableAutoOrientation: Disable automatic orientation placeMultiple: Stay in placement mode From e39a86899821a02a73b90e32d6b2ce5b07b30889 Mon Sep 17 00:00:00 2001 From: hexagonhexagon Date: Thu, 11 Jun 2020 17:56:13 -0400 Subject: [PATCH 2/2] Add "Paste last blueprint" keybind. Last blueprint is not preserved on save/exit. --- src/js/game/hud/hud.js | 1 + src/js/game/hud/parts/blueprint_placer.js | 16 +++++++++++++--- src/js/game/hud/parts/building_placer.js | 1 + src/js/game/hud/parts/keybinding_overlay.js | 19 ++++++++++++------- src/js/game/key_action_mapper.js | 1 + translations/base-en.yaml | 2 ++ 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/js/game/hud/hud.js b/src/js/game/hud/hud.js index d6a078f4..3f8ab0e1 100644 --- a/src/js/game/hud/hud.js +++ b/src/js/game/hud/hud.js @@ -74,6 +74,7 @@ export class GameHUD { shapeUnpinRequested: /** @type {TypedSignal<[string]>} */ (new Signal()), notification: /** @type {TypedSignal<[string, enumNotificationType]>} */ (new Signal()), buildingsSelectedForCopy: /** @type {TypedSignal<[Array]>} */ (new Signal()), + pasteBlueprintRequested: new Signal(), }; if (!IS_MOBILE) { diff --git a/src/js/game/hud/parts/blueprint_placer.js b/src/js/game/hud/parts/blueprint_placer.js index 69523bd0..0ffff9b4 100644 --- a/src/js/game/hud/parts/blueprint_placer.js +++ b/src/js/game/hud/parts/blueprint_placer.js @@ -29,6 +29,8 @@ export class HUDBlueprintPlacer extends BaseHUDPart { /** @type {TypedTrackedState} */ this.currentBlueprint = new TrackedState(this.onBlueprintChanged, this); + /** @type {Blueprint?} */ + this.lastBlueprintUsed = null; const keyActionMapper = this.root.keyMapper; keyActionMapper.getBinding(KEYMAPPINGS.general.back).add(this.abortPlacement, this); @@ -36,9 +38,7 @@ export class HUDBlueprintPlacer extends BaseHUDPart { .getBinding(KEYMAPPINGS.placement.abortBuildingPlacement) .add(this.abortPlacement, this); keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateWhilePlacing).add(this.rotateBlueprint, this); - keyActionMapper - .getBinding(KEYMAPPINGS.placement.abortBuildingPlacement) - .add(this.abortPlacement, this); + keyActionMapper.getBinding(KEYMAPPINGS.massSelect.pasteLastBlueprint).add(this.pasteBlueprint, this); this.root.camera.downPreHandler.add(this.onMouseDown, this); this.root.camera.movePreHandler.add(this.onMouseMove, this); @@ -73,6 +73,7 @@ export class HUDBlueprintPlacer extends BaseHUDPart { */ onBlueprintChanged(blueprint) { if (blueprint) { + this.lastBlueprintUsed = blueprint; this.costDisplayText.innerText = "" + blueprint.getCost(); } } @@ -144,6 +145,15 @@ export class HUDBlueprintPlacer extends BaseHUDPart { } } + pasteBlueprint() { + if (this.lastBlueprintUsed !== null) { + this.root.hud.signals.pasteBlueprintRequested.dispatch(); + this.currentBlueprint.set(this.lastBlueprintUsed); + } else { + this.root.soundProxy.playUiError(); + } + } + /** * * @param {DrawParameters} parameters diff --git a/src/js/game/hud/parts/building_placer.js b/src/js/game/hud/parts/building_placer.js index c1179f33..6da065b2 100644 --- a/src/js/game/hud/parts/building_placer.js +++ b/src/js/game/hud/parts/building_placer.js @@ -40,6 +40,7 @@ export class HUDBuildingPlacer extends BaseHUDPart { keyActionMapper.getBinding(KEYMAPPINGS.placement.cycleBuildingVariants).add(this.cycleVariants, this); this.root.hud.signals.buildingsSelectedForCopy.add(this.abortPlacement, this); + this.root.hud.signals.pasteBlueprintRequested.add(this.abortPlacement, this); this.domAttach = new DynamicDomAttach(this.root, this.element, {}); diff --git a/src/js/game/hud/parts/keybinding_overlay.js b/src/js/game/hud/parts/keybinding_overlay.js index 05455065..7b58858a 100644 --- a/src/js/game/hud/parts/keybinding_overlay.js +++ b/src/js/game/hud/parts/keybinding_overlay.js @@ -31,10 +31,10 @@ export class HUDKeybindingOverlay extends BaseHUDPart { ${getKeycode(KEYMAPPINGS.navigation.mapMoveDown)} ${getKeycode(KEYMAPPINGS.navigation.mapMoveRight)} - - - - + + + +
@@ -47,13 +47,18 @@ export class HUDKeybindingOverlay extends BaseHUDPart {
- - + +
+ ${getKeycode(KEYMAPPINGS.massSelect.pasteLastBlueprint)} + +
+ +
- +
${getKeycode(KEYMAPPINGS.placement.abortBuildingPlacement)} diff --git a/src/js/game/key_action_mapper.js b/src/js/game/key_action_mapper.js index 532e53cd..58077f01 100644 --- a/src/js/game/key_action_mapper.js +++ b/src/js/game/key_action_mapper.js @@ -67,6 +67,7 @@ export const KEYMAPPINGS = { massSelectCopy: { keyCode: key("C") }, massSelectCut: { keyCode: key("X") }, confirmMassDelete: { keyCode: 46 }, // DEL + pasteLastBlueprint: { keyCode: key("V") }, }, placementModifiers: { diff --git a/translations/base-en.yaml b/translations/base-en.yaml index 472d542d..c1944695 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -291,6 +291,7 @@ ingame: placeBuilding: Place building createMarker: Create Marker delete: Destroy + pasteLastBlueprint: Paste last blueprint # Everything related to placing buildings (I.e. as soon as you selected a building # from the toolbar) @@ -710,6 +711,7 @@ keybindings: Modifier: Rotate CCW instead cycleBuildingVariants: Cycle Variants confirmMassDelete: Confirm Mass Delete + pasteLastBlueprint: Paste last blueprint cycleBuildings: Cycle Buildings massSelectStart: Hold and drag to start