From e195744480a9cf9a08bc167548568ed9e8abddfc Mon Sep 17 00:00:00 2001 From: EmeraldBlock Date: Wed, 21 Oct 2020 14:44:48 -0500 Subject: [PATCH] Add override shape and swap button for sandbox panel --- src/css/ingame_hud/sandbox_controller.scss | 2 +- src/js/game/hud/parts/sandbox_controller.js | 87 +++++++++++++++++++-- 2 files changed, 82 insertions(+), 7 deletions(-) diff --git a/src/css/ingame_hud/sandbox_controller.scss b/src/css/ingame_hud/sandbox_controller.scss index b1a2e110..fa34cf69 100644 --- a/src/css/ingame_hud/sandbox_controller.scss +++ b/src/css/ingame_hud/sandbox_controller.scss @@ -21,7 +21,7 @@ .plusMinus { @include S(margin-top, 4px); display: grid; - grid-template-columns: 1fr auto auto; + grid-template-columns: 1fr auto auto auto; align-items: center; @include S(grid-gap, 4px); diff --git a/src/js/game/hud/parts/sandbox_controller.js b/src/js/game/hud/parts/sandbox_controller.js index d2738af3..31dc9dac 100644 --- a/src/js/game/hud/parts/sandbox_controller.js +++ b/src/js/game/hud/parts/sandbox_controller.js @@ -2,6 +2,10 @@ import { makeDiv } from "../../../core/utils"; import { BaseHUDPart } from "../base_hud_part"; import { DynamicDomAttach } from "../dynamic_dom_attach"; import { enumNotificationType } from "./notifications"; +import { ShapeDefinition } from "../../shape_definition"; +import { DialogWithForm } from "../../../core/modal_dialog_elements"; +import { FormElementInput, FormElementItemChooser } from "../../../core/modal_dialog_forms"; +import { HubGoals } from "../../hub_goals"; export class HUDSandboxController extends BaseHUDPart { createElements(parent) { @@ -16,30 +20,35 @@ export class HUDSandboxController extends BaseHUDPart {
+
- + +
- + +
- + +
- + +
@@ -50,6 +59,7 @@ export class HUDSandboxController extends BaseHUDPart {
+ ` @@ -60,18 +70,24 @@ export class HUDSandboxController extends BaseHUDPart { bind(".giveBlueprints", this.giveBlueprints); bind(".bigMinus", () => this.modifyAll(-100)); bind(".bigPlus", () => this.modifyAll(100)); + bind(".levelToggle .reset", this.resetLevel); bind(".levelToggle .minus", () => this.modifyLevel(-1)); bind(".levelToggle .plus", () => this.modifyLevel(1)); + bind(".levelOverride", this.promptOverrideLevel); + bind(".upgradesBelt .reset", () => this.resetUpgrade("belt")); bind(".upgradesBelt .minus", () => this.modifyUpgrade("belt", -1)); bind(".upgradesBelt .plus", () => this.modifyUpgrade("belt", 1)); + bind(".upgradesExtraction .reset", () => this.resetUpgrade("miner")); bind(".upgradesExtraction .minus", () => this.modifyUpgrade("miner", -1)); bind(".upgradesExtraction .plus", () => this.modifyUpgrade("miner", 1)); + bind(".upgradesProcessing .reset", () => this.resetUpgrade("processors")); bind(".upgradesProcessing .minus", () => this.modifyUpgrade("processors", -1)); bind(".upgradesProcessing .plus", () => this.modifyUpgrade("processors", 1)); + bind(".upgradesPainting .reset", () => this.resetUpgrade("painting")); bind(".upgradesPainting .minus", () => this.modifyUpgrade("painting", -1)); bind(".upgradesPainting .plus", () => this.modifyUpgrade("painting", 1)); } @@ -91,6 +107,16 @@ export class HUDSandboxController extends BaseHUDPart { this.modifyUpgrade("painting", amount); } + resetUpgrade(id) { + const maxLevel = this.root.gameMode.getUpgrades()[id].length; + + if (this.root.hubGoals.upgradeLevels[id] === maxLevel) { + this.modifyUpgrade(id, -this.root.hubGoals.upgradeLevels[id]); + } else { + this.modifyUpgrade(id, maxLevel - this.root.hubGoals.upgradeLevels[id]); + } + } + modifyUpgrade(id, amount) { const upgradeTiers = this.root.gameMode.getUpgrades()[id]; const maxLevel = upgradeTiers.length; @@ -113,6 +139,16 @@ export class HUDSandboxController extends BaseHUDPart { ); } + resetLevel(a) { + const level = this.root.hubGoals.level; + const levelCount = this.root.gameMode.getLevelDefinitions().length; + if (level === levelCount + 1) { + this.modifyLevel(1 - level); + } else { + this.modifyLevel(levelCount + 1 - level); + } + } + modifyLevel(amount) { const hubGoals = this.root.hubGoals; hubGoals.level = Math.max(1, hubGoals.level + amount); @@ -121,8 +157,6 @@ export class HUDSandboxController extends BaseHUDPart { // Clear all shapes of this level hubGoals.storedShapes[hubGoals.currentGoal.definition.getHash()] = 0; - this.root.hud.parts.pinnedShapes.rerenderFull(); - // Compute gained rewards hubGoals.gainedRewards = {}; const levels = this.root.gameMode.getLevelDefinitions(); @@ -133,12 +167,53 @@ export class HUDSandboxController extends BaseHUDPart { } } + this.root.buffers.cache.get("hub").clear(); + this.root.hud.parts.pinnedShapes.rerenderFull(); + this.root.hud.signals.notification.dispatch( "Changed level to " + hubGoals.level, enumNotificationType.upgrade ); } + promptOverrideLevel() { + const signalValueInput = new FormElementInput({ + id: "signalValue", + label: null, + placeholder: "", + defaultValue: "", + validator: val => ShapeDefinition.isValidShortKey(val), + }); + + const dialog = new DialogWithForm({ + app: this.root.app, + title: "Override Level", + desc: "Enter shape to override with:", + formElements: [signalValueInput], + buttons: ["cancel:bad:escape", "ok:good:enter"], + closeButton: false, + }); + this.root.hud.parts.dialogs.internalShowDialog(dialog); + + dialog.buttonSignals.ok.add(() => this.overrideLevel(signalValueInput.getValue())); + } + + overrideLevel(shape) { + console.log(shape); + const hubGoals = this.root.hubGoals; + hubGoals.currentGoal.definition = this.root.shapeDefinitionMgr.getShapeFromShortKey(shape); + + hubGoals.storedShapes[hubGoals.currentGoal.definition.getHash()] = 0; + + this.root.buffers.cache.get("hub").clear(); + this.root.hud.parts.pinnedShapes.rerenderFull(); + + this.root.hud.signals.notification.dispatch( + "Overrode level to " + hubGoals.currentGoal.definition.getHash(), + enumNotificationType.upgrade + ); + } + initialize() { // Allow toggling the controller overlay this.root.gameState.inputReciever.keydown.add(key => {