1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00
tobspr_shapez.io/src/js/game/hud/parts/puzzle_complete_notification.js

106 lines
3.6 KiB
JavaScript
Raw Normal View History

2021-05-03 13:07:03 +00:00
/* typehints:start */
import { PuzzlePlayGameMode } from "../../modes/puzzle_play";
/* typehints:end */
2021-05-01 16:04:33 +00:00
import { InputReceiver } from "../../../core/input_receiver";
import { makeDiv } from "../../../core/utils";
import { SOUNDS } from "../../../platform/sound";
import { T } from "../../../translations";
import { enumColors } from "../../colors";
import { ColorItem } from "../../items/color_item";
import { finalGameShape, rocketShape } from "../../modes/regular";
import { BaseHUDPart } from "../base_hud_part";
import { DynamicDomAttach } from "../dynamic_dom_attach";
2021-05-03 13:07:03 +00:00
import { ShapeItem } from "../../items/shape_item";
import { ShapeDefinition } from "../../shape_definition";
2021-05-01 16:04:33 +00:00
export class HUDPuzzleCompleteNotification extends BaseHUDPart {
initialize() {
this.visible = false;
this.domAttach = new DynamicDomAttach(this.root, this.element, {
timeToKeepSeconds: 0,
});
this.root.signals.puzzleComplete.add(this.show, this);
2021-05-03 21:02:33 +00:00
this.userDidLikePuzzle = false;
2021-05-01 16:04:33 +00:00
this.timeOfCompletion = 0;
}
createElements(parent) {
this.inputReciever = new InputReceiver("puzzle-complete");
this.element = makeDiv(parent, "ingame_HUD_PuzzleCompleteNotification", ["noBlur"]);
const dialog = makeDiv(this.element, null, ["dialog"]);
this.elemTitle = makeDiv(dialog, null, ["title"], T.ingame.puzzleCompletion.title);
this.elemContents = makeDiv(dialog, null, ["contents"]);
2021-05-03 13:07:03 +00:00
this.elemActions = makeDiv(dialog, null, ["actions"]);
2021-05-01 16:04:33 +00:00
const stepLike = makeDiv(this.elemContents, null, ["step", "stepLike"]);
makeDiv(stepLike, null, ["title"], T.ingame.puzzleCompletion.titleLike);
2021-05-03 13:07:03 +00:00
const likeButtons = makeDiv(stepLike, null, ["buttons"]);
2021-05-01 16:04:33 +00:00
this.buttonLikeYes = document.createElement("button");
this.buttonLikeYes.classList.add("liked-yes");
2021-05-03 13:07:03 +00:00
likeButtons.appendChild(this.buttonLikeYes);
2021-05-01 16:04:33 +00:00
this.trackClicks(this.buttonLikeYes, () => {
2021-05-03 21:02:33 +00:00
this.userDidLikePuzzle = !this.userDidLikePuzzle;
2021-05-01 16:04:33 +00:00
this.updateState();
});
this.continueBtn = document.createElement("button");
this.continueBtn.classList.add("close", "styledButton");
this.continueBtn.innerText = T.ingame.puzzleCompletion.continueBtn;
dialog.appendChild(this.continueBtn);
this.menuBtn = document.createElement("button");
this.menuBtn.classList.add("close", "styledButton");
this.menuBtn.innerText = T.ingame.puzzleCompletion.menuBtn;
dialog.appendChild(this.menuBtn);
this.trackClicks(this.continueBtn, this.close);
this.trackClicks(this.menuBtn, () => {
this.close(true);
});
2021-05-01 16:04:33 +00:00
}
updateState() {
2021-05-03 21:02:33 +00:00
this.buttonLikeYes.classList.toggle("active", this.userDidLikePuzzle === true);
2021-05-01 16:04:33 +00:00
}
show() {
this.root.soundProxy.playUi(SOUNDS.levelComplete);
this.root.app.inputMgr.makeSureAttachedAndOnTop(this.inputReciever);
this.visible = true;
this.timeOfCompletion = this.root.time.now();
}
cleanup() {
this.root.app.inputMgr.makeSureDetached(this.inputReciever);
}
isBlockingOverlay() {
return this.visible;
}
close(toMenu = false) {
2021-05-01 16:04:33 +00:00
/** @type {PuzzlePlayGameMode} */ (this.root.gameMode)
2021-05-03 21:02:33 +00:00
.trackCompleted(this.userDidLikePuzzle, Math.round(this.timeOfCompletion))
2021-05-01 16:04:33 +00:00
.then(() => {
if (toMenu) {
this.root.gameState.moveToState("PuzzleMenuState");
}
2021-05-03 20:06:13 +00:00
this.visible = false;
this.cleanup();
2021-05-01 16:04:33 +00:00
});
}
update() {
this.domAttach.update(this.visible);
}
}