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/unlock_notification.js

157 lines
5.4 KiB
JavaScript
Raw Normal View History

2020-05-14 19:54:11 +00:00
import { globalConfig } from "../../../core/config";
2020-05-09 14:45:23 +00:00
import { gMetaBuildingRegistry } from "../../../core/global_registries";
2020-05-14 19:54:11 +00:00
import { makeDiv } from "../../../core/utils";
import { SOUNDS } from "../../../platform/sound";
2020-05-23 08:30:54 +00:00
import { T } from "../../../translations";
import { defaultBuildingVariant } from "../../meta_building";
import { enumHubGoalRewards } from "../../tutorial_goals";
2020-05-14 19:54:11 +00:00
import { BaseHUDPart } from "../base_hud_part";
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { enumHubGoalRewardsToContentUnlocked } from "../../tutorial_goals_mappings";
import { InputReceiver } from "../../../core/input_receiver";
2020-05-09 14:45:23 +00:00
export class HUDUnlockNotification extends BaseHUDPart {
initialize() {
this.visible = false;
this.domAttach = new DynamicDomAttach(this.root, this.element, {
timeToKeepSeconds: 0,
});
if (!(G_IS_DEV && globalConfig.debug.disableUnlockDialog)) {
this.root.signals.storyGoalCompleted.add(this.showForLevel, this);
}
2020-05-23 08:30:54 +00:00
this.buttonShowTimeout = null;
2020-05-09 14:45:23 +00:00
}
createElements(parent) {
this.inputReciever = new InputReceiver("unlock-notification");
this.element = makeDiv(parent, "ingame_HUD_UnlockNotification", ["noBlur"]);
2020-05-09 14:45:23 +00:00
const dialog = makeDiv(this.element, null, ["dialog"]);
2020-05-17 10:12:13 +00:00
this.elemTitle = makeDiv(dialog, null, ["title"]);
this.elemSubTitle = makeDiv(dialog, null, ["subTitle"], T.ingame.levelCompleteNotification.completed);
2020-05-09 14:45:23 +00:00
2020-05-17 10:12:13 +00:00
this.elemContents = makeDiv(dialog, null, ["contents"]);
2020-05-09 14:45:23 +00:00
this.btnClose = document.createElement("button");
this.btnClose.classList.add("close", "styledButton");
this.btnClose.innerText = "Next level";
dialog.appendChild(this.btnClose);
this.trackClicks(this.btnClose, this.requestClose);
2020-05-09 14:45:23 +00:00
}
2020-05-14 19:54:11 +00:00
/**
* @param {number} level
* @param {enumHubGoalRewards} reward
*/
2020-05-09 14:45:23 +00:00
showForLevel(level, reward) {
this.root.app.inputMgr.makeSureAttachedAndOnTop(this.inputReciever);
2020-05-17 10:12:13 +00:00
this.elemTitle.innerText = T.ingame.levelCompleteNotification.levelTitle.replace(
"<level>",
("" + level).padStart(2, "0")
);
2020-05-23 08:30:54 +00:00
const rewardName = T.storyRewards[reward].title;
let html = `
<div class="rewardName">
${T.ingame.levelCompleteNotification.unlockText.replace("<reward>", rewardName)}
</div>
<div class="rewardDesc">
${T.storyRewards[reward].desc}
</div>
`;
html += "<div class='images'>";
const gained = enumHubGoalRewardsToContentUnlocked[reward];
if (gained) {
gained.forEach(([metaBuildingClass, variant]) => {
const metaBuilding = gMetaBuildingRegistry.findByClass(metaBuildingClass);
html += `<div class="buildingExplanation" data-icon="building_tutorials/${
metaBuilding.getId() + (variant === defaultBuildingVariant ? "" : "-" + variant)
}.png"></div>`;
});
2020-05-09 14:45:23 +00:00
}
2020-05-23 08:30:54 +00:00
html += "</div>";
2020-05-09 14:45:23 +00:00
this.elemContents.innerHTML = html;
this.visible = true;
2020-05-14 17:12:58 +00:00
this.root.soundProxy.playUi(SOUNDS.levelComplete);
2020-05-23 08:30:54 +00:00
if (this.buttonShowTimeout) {
clearTimeout(this.buttonShowTimeout);
}
this.element.querySelector("button.close").classList.remove("unlocked");
2020-05-30 15:50:29 +00:00
if (this.root.app.settings.getAllSettings().offerHints) {
this.buttonShowTimeout = setTimeout(
() => this.element.querySelector("button.close").classList.add("unlocked"),
G_IS_DEV ? 100 : 5000
);
} else {
this.element.querySelector("button.close").classList.add("unlocked");
}
2020-05-23 08:30:54 +00:00
}
cleanup() {
this.root.app.inputMgr.makeSureDetached(this.inputReciever);
2020-05-23 08:30:54 +00:00
if (this.buttonShowTimeout) {
clearTimeout(this.buttonShowTimeout);
this.buttonShowTimeout = null;
}
2020-05-09 14:45:23 +00:00
}
requestClose() {
this.root.app.adProvider.showVideoAd().then(() => {
this.close();
2020-05-28 17:40:48 +00:00
if (!this.root.app.settings.getAllSettings().offerHints) {
return;
}
2020-05-25 18:23:47 +00:00
if (this.root.hubGoals.level === 3) {
const { showUpgrades } = this.root.hud.parts.dialogs.showInfo(
T.dialogs.upgradesIntroduction.title,
T.dialogs.upgradesIntroduction.desc,
["showUpgrades:good:timeout"]
);
showUpgrades.add(() => this.root.hud.parts.shop.show());
}
2020-05-28 13:36:38 +00:00
if (this.root.hubGoals.level === 5) {
const { showKeybindings } = this.root.hud.parts.dialogs.showInfo(
T.dialogs.keybindingsIntroduction.title,
T.dialogs.keybindingsIntroduction.desc,
["showKeybindings:misc", "ok:good:timeout"]
);
showKeybindings.add(() => this.root.gameState.goToKeybindings());
}
});
}
2020-05-09 14:45:23 +00:00
close() {
this.root.app.inputMgr.makeSureDetached(this.inputReciever);
2020-05-23 08:30:54 +00:00
if (this.buttonShowTimeout) {
clearTimeout(this.buttonShowTimeout);
this.buttonShowTimeout = null;
}
2020-05-09 14:45:23 +00:00
this.visible = false;
}
update() {
this.domAttach.update(this.visible);
2020-05-23 08:30:54 +00:00
if (!this.visible && this.buttonShowTimeout) {
clearTimeout(this.buttonShowTimeout);
this.buttonShowTimeout = null;
}
2020-05-09 14:45:23 +00:00
}
}