From 6a279923e303277d2edccec98a4a7726ef5f6154 Mon Sep 17 00:00:00 2001 From: isaisstillalive Date: Fri, 3 Jul 2020 21:10:16 +0900 Subject: [PATCH 1/2] If cost is low, copy instead of cut --- src/js/game/hud/parts/mass_selector.js | 29 ++++++++++++++++++++------ translations/base-en.yaml | 1 + translations/base-ja.yaml | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/js/game/hud/parts/mass_selector.js b/src/js/game/hud/parts/mass_selector.js index fb55676e..2c17c595 100644 --- a/src/js/game/hud/parts/mass_selector.js +++ b/src/js/game/hud/parts/mass_selector.js @@ -13,6 +13,7 @@ import { T } from "../../../translations"; import { KEYMAPPINGS } from "../../key_action_mapper"; import { THEME } from "../../theme"; import { enumHubGoalRewards } from "../../tutorial_goals"; +import { enumNotificationType } from "./notifications"; const logger = createLogger("hud/mass_selector"); @@ -148,14 +149,30 @@ export class HUDMassSelector extends BaseHUDPart { // 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); + let canPaste = false; + const placer = this.root.hud.parts.blueprintPlacer; + if (placer) { + const blueprint = placer.currentBlueprint.get(); + if (blueprint) { + canPaste = blueprint.canAfford(this.root); } } + if (canPaste) { + 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); + } + } + } else { + this.selectedUids = new Set(); + this.root.hud.signals.notification.dispatch( + T.ingame.notifications.massCutInsufficient, + enumNotificationType.success + ); + } this.root.soundProxy.playUiClick(); } else { diff --git a/translations/base-en.yaml b/translations/base-en.yaml index ed1999b7..0a17ca6e 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -337,6 +337,7 @@ ingame: notifications: newUpgrade: A new upgrade is available! gameSaved: Your game has been saved. + massCutInsufficient: The cost for pasting is insufficient! # The "Upgrades" window shop: diff --git a/translations/base-ja.yaml b/translations/base-ja.yaml index d6d5139f..26106019 100644 --- a/translations/base-ja.yaml +++ b/translations/base-ja.yaml @@ -325,6 +325,7 @@ ingame: notifications: newUpgrade: 新しいアップグレードが利用可能です! gameSaved: ゲームをセーブしました。 + massCutInsufficient: 設置コストが不足しています! # The "Upgrades" window shop: From 0ba4722be61a8db6c767ab3a1c58a45f8e6452e5 Mon Sep 17 00:00:00 2001 From: isaisstillalive Date: Sun, 5 Jul 2020 11:06:42 +0900 Subject: [PATCH 2/2] Show confirm dialog instead of notification --- src/js/game/hud/parts/mass_selector.js | 30 ++++++++++++-------------- translations/base-en.yaml | 6 +++++- translations/base-ja.yaml | 6 +++++- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/js/game/hud/parts/mass_selector.js b/src/js/game/hud/parts/mass_selector.js index 2c17c595..dda09756 100644 --- a/src/js/game/hud/parts/mass_selector.js +++ b/src/js/game/hud/parts/mass_selector.js @@ -13,7 +13,7 @@ import { T } from "../../../translations"; import { KEYMAPPINGS } from "../../key_action_mapper"; import { THEME } from "../../theme"; import { enumHubGoalRewards } from "../../tutorial_goals"; -import { enumNotificationType } from "./notifications"; +import { Blueprint } from "../../blueprint"; const logger = createLogger("hud/mass_selector"); @@ -146,18 +146,10 @@ export class HUDMassSelector extends BaseHUDPart { 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); + const cutAction = () => { + // copy code relies on entities still existing, so must copy before deleting. + this.root.hud.signals.buildingsSelectedForCopy.dispatch(entityUids); - let canPaste = false; - const placer = this.root.hud.parts.blueprintPlacer; - if (placer) { - const blueprint = placer.currentBlueprint.get(); - if (blueprint) { - canPaste = blueprint.canAfford(this.root); - } - } - if (canPaste) { for (let i = 0; i < entityUids.length; ++i) { const uid = entityUids[i]; const entity = this.root.entityMgr.findByUid(uid); @@ -166,12 +158,18 @@ export class HUDMassSelector extends BaseHUDPart { this.selectedUids.delete(uid); } } + }; + + const blueprint = Blueprint.fromUids(this.root, entityUids); + if (blueprint.canAfford(this.root)) { + cutAction(); } else { - this.selectedUids = new Set(); - this.root.hud.signals.notification.dispatch( - T.ingame.notifications.massCutInsufficient, - enumNotificationType.success + const { cancel, ok } = this.root.hud.parts.dialogs.showWarning( + T.dialogs.massCutInsufficientConfirm.title, + T.dialogs.massCutInsufficientConfirm.desc, + ["cancel:good:escape", "ok:bad:enter"] ); + ok.add(cutAction); } this.root.soundProxy.playUiClick(); diff --git a/translations/base-en.yaml b/translations/base-en.yaml index 0a17ca6e..c6f03666 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -243,6 +243,11 @@ dialogs: desc: >- You are cutting a lot of buildings ( to be exact)! Are you sure you want to do this? + massCutInsufficientConfirm: + title: Confirm cut + desc: >- + The cost for pasting is insufficient! Are you sure you want to do this? + blueprintsNotUnlocked: title: Not unlocked yet desc: >- @@ -337,7 +342,6 @@ ingame: notifications: newUpgrade: A new upgrade is available! gameSaved: Your game has been saved. - massCutInsufficient: The cost for pasting is insufficient! # The "Upgrades" window shop: diff --git a/translations/base-ja.yaml b/translations/base-ja.yaml index 26106019..3e6ba511 100644 --- a/translations/base-ja.yaml +++ b/translations/base-ja.yaml @@ -263,6 +263,11 @@ dialogs: desc: >- 多数の建造物をカットしようとしています! ( 個の選択) 続行しますか? + massCutInsufficientConfirm: + title: カット確認 + desc: >- + 設置コストが不足しています! 続行しますか? + exportScreenshotWarning: title: スクリーンショット出力 desc: >- @@ -325,7 +330,6 @@ ingame: notifications: newUpgrade: 新しいアップグレードが利用可能です! gameSaved: ゲームをセーブしました。 - massCutInsufficient: 設置コストが不足しています! # The "Upgrades" window shop: