|
|
|
/* typehints:start */
|
|
|
|
import { Application } from "../application";
|
|
|
|
/* typehints:end */
|
|
|
|
|
|
|
|
import { Signal, STOP_PROPAGATION } from "./signal";
|
|
|
|
import { arrayDeleteValue, waitNextFrame } from "./utils";
|
|
|
|
import { ClickDetector } from "./click_detector";
|
|
|
|
import { SOUNDS } from "../platform/sound";
|
|
|
|
import { InputReceiver } from "./input_receiver";
|
|
|
|
import { FormElement } from "./modal_dialog_forms";
|
|
|
|
import { globalConfig } from "./config";
|
|
|
|
import { getStringForKeyCode } from "../game/key_action_mapper";
|
|
|
|
import { createLogger } from "./logging";
|
|
|
|
import { T } from "../translations";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ***************************************************
|
|
|
|
*
|
|
|
|
* LEGACY CODE WARNING
|
|
|
|
*
|
|
|
|
* This is old code from yorg3.io and needs to be refactored
|
|
|
|
* @TODO
|
|
|
|
*
|
|
|
|
* ***************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
const kbEnter = 13;
|
|
|
|
const kbCancel = 27;
|
|
|
|
|
|
|
|
const logger = createLogger("dialogs");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic text based dialog
|
|
|
|
*/
|
|
|
|
export class Dialog {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Constructs a new dialog with the given options
|
|
|
|
* @param {object} param0
|
|
|
|
* @param {Application} param0.app
|
|
|
|
* @param {string} param0.title Title of the dialog
|
|
|
|
* @param {string} param0.contentHTML Inner dialog html
|
|
|
|
* @param {Array<string>} param0.buttons
|
|
|
|
* Button list, each button contains of up to 3 parts separated by ':'.
|
|
|
|
* Part 0: The id, one of the one defined in dialog_buttons.yaml
|
|
|
|
* Part 1: The style, either good, bad or misc
|
|
|
|
* Part 2 (optional): Additional parameters separated by '/', available are:
|
|
|
|
* timeout: This button is only available after some waiting time
|
|
|
|
* kb_enter: This button is triggered by the enter key
|
|
|
|
* kb_escape This button is triggered by the escape key
|
|
|
|
* @param {string=} param0.type The dialog type, either "info" or "warn"
|
|
|
|
* @param {boolean=} param0.closeButton Whether this dialog has a close button
|
|
|
|
*/
|
|
|
|
constructor({ app, title, contentHTML, buttons, type = "info", closeButton = false }) {
|
|
|
|
this.app = app;
|
|
|
|
this.title = title;
|
|
|
|
this.contentHTML = contentHTML;
|
|
|
|
this.type = type;
|
|
|
|
this.buttonIds = buttons;
|
|
|
|
this.closeButton = closeButton;
|
|
|
|
|
|
|
|
this.closeRequested = new Signal();
|
|
|
|
this.buttonSignals = {};
|
|
|
|
|
|
|
|
for (let i = 0; i < buttons.length; ++i) {
|
|
|
|
if (G_IS_DEV && globalConfig.debug.disableTimedButtons) {
|
|
|
|
this.buttonIds[i] = this.buttonIds[i].replace(":timeout", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
const buttonId = this.buttonIds[i].split(":")[0];
|
|
|
|
this.buttonSignals[buttonId] = new Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.valueChosen = new Signal();
|
|
|
|
|
|
|
|
this.timeouts = [];
|
|
|
|
this.clickDetectors = [];
|
|
|
|
|
|
|
|
this.inputReciever = new InputReceiver("dialog-" + this.title);
|
|
|
|
|
|
|
|
this.inputReciever.keydown.add(this.handleKeydown, this);
|
|
|
|
|
|
|
|
this.enterHandler = null;
|
|
|
|
this.escapeHandler = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal keydown handler
|
|
|
|
* @param {object} param0
|
|
|
|
* @param {number} param0.keyCode
|
|
|
|
* @param {boolean} param0.shift
|
|
|
|
* @param {boolean} param0.alt
|
Mod Support - 1.5.0 Update (#1361)
* initial modloader draft
* modloader features
* Refactor mods to use signals
* Add support for modifying and registering new transltions
* Minor adjustments
* Support for string building ids for mods
* Initial support for adding new buildings
* Refactor how mods are loaded to resolve circular dependencies and prepare for future mod loading
* Lazy Load mods to make sure all dependencies are loaded
* Expose all exported members automatically to mods
* Fix duplicate exports
* Allow loading mods from standalone
* update changelog
* Fix mods folder incorrect path
* Fix modloading in standalone
* Fix sprites not getting replaced, update demo mod
* Load dev mod via raw loader
* Improve mod developing so mods are directly ready to be deployed, load mods from local file server
* Proper mods ui
* Allow mods to register game systems and draw stuff
* Change mods path
* Fix sprites not loading
* Minor adjustments, closes #1333
* Add support for loading atlases via mods
* Add support for loading mods from external sources in DEV
* Add confirmation when loading mods
* Fix circular dependency
* Minor Keybindings refactor, add support for keybindings to mods, add support for dialogs to mods
* Add some mod signals
* refactor game loading states
* Make shapez exports global
* Start to make mods safer
* Refactor file system electron event handling
* Properly isolate electron renderer process
* Update to latest electron
* Show errors when loading mods
* Update confirm dialgo
* Minor restructure, start to add mod examples
* Allow adding custom themesw
* Add more examples and allow defining custom item processor operations
* Add interface to register new buildings
* Fixed typescript type errors (#1335)
* Refactor building registry, make it easier for mods to add new buildings
* Allow overriding existing methods
* Add more examples and more features
* More mod examples
* Make mod loading simpler
* Add example how to add custom drawings
* Remove unused code
* Minor modloader adjustments
* Support for rotation variants in mods (was broken previously)
* Allow mods to replace builtin sub shapes
* Add helper methods to extend classes
* Fix menu bar on mac os
* Remember window state
* Add support for paste signals
* Add example how to add custom components and systems
* Support for mod settings
* Add example for adding a new item type
* Update class extensions
* Minor adjustments
* Fix typo
* Add notification blocks mod example
* Add small tutorial
* Update readme
* Add better instructions
* Update JSDoc for Replacing Methods (#1336)
* upgraded types for overriding methods
* updated comments
Co-authored-by: Edward Badel <you@example.com>
* Direction lock now indicates when there is a building inbetween
* Fix mod examples
* Fix linter error
* Game state register (#1341)
* Added a gamestate register helper
Added a gamestate register helper
* Update mod_interface.js
* export build options
* Fix runBeforeMethod and runAfterMethod
* Minor game system code cleanup
* Belt path drawing optimization
* Fix belt path optimization
* Belt drawing improvements, again
* Do not render belts in statics disabled view
* Allow external URL to load more than one mod (#1337)
* Allow external URL to load more than one mod
Instead of loading the text returned from the remote server, load a JSON object with a `mods` field, containing strings of all the mods. This lets us work on more than one mod at a time or without separate repos. This will break tooling such as `create-shapezio-mod` though.
* Update modloader.js
* Prettier fixes
* Added link to create-shapezio-mod npm page (#1339)
Added link to create-shapezio-mod npm page: https://www.npmjs.com/package/create-shapezio-mod
* allow command line switch to load more than one mod (#1342)
* Fixed class handle type (#1345)
* Fixed class handle type
* Fixed import game state
* Minor adjustments
* Refactor item acceptor to allow only single direction slots
* Allow specifying minimumGameVersion
* Add sandbox example
* Replaced concatenated strings with template literals (#1347)
* Mod improvements
* Make wired pins component optional on the storage
* Fix mod examples
* Bind `this` for method overriding JSDoc (#1352)
* fix entity debugger reaching HTML elements (#1353)
* Store mods in savegame and show warning when it differs
* Closes #1357
* Fix All Shapez Exports Being Const (#1358)
* Allowed setting of variables inside webpack modules
* remove console log
* Fix stringification of things inside of eval
Co-authored-by: Edward Badel <you@example.com>
* Fix building placer intersection warning
* Add example for storing data in the savegame
* Fix double painter bug (#1349)
* Add example on how to extend builtin buildings
* update readme
* Disable steam achievements when playing with mods
* Update translations
Co-authored-by: Thomas (DJ1TJOO) <44841260+DJ1TJOO@users.noreply.github.com>
Co-authored-by: Bagel03 <70449196+Bagel03@users.noreply.github.com>
Co-authored-by: Edward Badel <you@example.com>
Co-authored-by: Emerald Block <69981203+EmeraldBlock@users.noreply.github.com>
Co-authored-by: saile515 <63782477+saile515@users.noreply.github.com>
Co-authored-by: Sense101 <67970865+Sense101@users.noreply.github.com>
2 years ago
|
|
|
* @param {boolean} param0.ctrl
|
|
|
|
*/
|
Mod Support - 1.5.0 Update (#1361)
* initial modloader draft
* modloader features
* Refactor mods to use signals
* Add support for modifying and registering new transltions
* Minor adjustments
* Support for string building ids for mods
* Initial support for adding new buildings
* Refactor how mods are loaded to resolve circular dependencies and prepare for future mod loading
* Lazy Load mods to make sure all dependencies are loaded
* Expose all exported members automatically to mods
* Fix duplicate exports
* Allow loading mods from standalone
* update changelog
* Fix mods folder incorrect path
* Fix modloading in standalone
* Fix sprites not getting replaced, update demo mod
* Load dev mod via raw loader
* Improve mod developing so mods are directly ready to be deployed, load mods from local file server
* Proper mods ui
* Allow mods to register game systems and draw stuff
* Change mods path
* Fix sprites not loading
* Minor adjustments, closes #1333
* Add support for loading atlases via mods
* Add support for loading mods from external sources in DEV
* Add confirmation when loading mods
* Fix circular dependency
* Minor Keybindings refactor, add support for keybindings to mods, add support for dialogs to mods
* Add some mod signals
* refactor game loading states
* Make shapez exports global
* Start to make mods safer
* Refactor file system electron event handling
* Properly isolate electron renderer process
* Update to latest electron
* Show errors when loading mods
* Update confirm dialgo
* Minor restructure, start to add mod examples
* Allow adding custom themesw
* Add more examples and allow defining custom item processor operations
* Add interface to register new buildings
* Fixed typescript type errors (#1335)
* Refactor building registry, make it easier for mods to add new buildings
* Allow overriding existing methods
* Add more examples and more features
* More mod examples
* Make mod loading simpler
* Add example how to add custom drawings
* Remove unused code
* Minor modloader adjustments
* Support for rotation variants in mods (was broken previously)
* Allow mods to replace builtin sub shapes
* Add helper methods to extend classes
* Fix menu bar on mac os
* Remember window state
* Add support for paste signals
* Add example how to add custom components and systems
* Support for mod settings
* Add example for adding a new item type
* Update class extensions
* Minor adjustments
* Fix typo
* Add notification blocks mod example
* Add small tutorial
* Update readme
* Add better instructions
* Update JSDoc for Replacing Methods (#1336)
* upgraded types for overriding methods
* updated comments
Co-authored-by: Edward Badel <you@example.com>
* Direction lock now indicates when there is a building inbetween
* Fix mod examples
* Fix linter error
* Game state register (#1341)
* Added a gamestate register helper
Added a gamestate register helper
* Update mod_interface.js
* export build options
* Fix runBeforeMethod and runAfterMethod
* Minor game system code cleanup
* Belt path drawing optimization
* Fix belt path optimization
* Belt drawing improvements, again
* Do not render belts in statics disabled view
* Allow external URL to load more than one mod (#1337)
* Allow external URL to load more than one mod
Instead of loading the text returned from the remote server, load a JSON object with a `mods` field, containing strings of all the mods. This lets us work on more than one mod at a time or without separate repos. This will break tooling such as `create-shapezio-mod` though.
* Update modloader.js
* Prettier fixes
* Added link to create-shapezio-mod npm page (#1339)
Added link to create-shapezio-mod npm page: https://www.npmjs.com/package/create-shapezio-mod
* allow command line switch to load more than one mod (#1342)
* Fixed class handle type (#1345)
* Fixed class handle type
* Fixed import game state
* Minor adjustments
* Refactor item acceptor to allow only single direction slots
* Allow specifying minimumGameVersion
* Add sandbox example
* Replaced concatenated strings with template literals (#1347)
* Mod improvements
* Make wired pins component optional on the storage
* Fix mod examples
* Bind `this` for method overriding JSDoc (#1352)
* fix entity debugger reaching HTML elements (#1353)
* Store mods in savegame and show warning when it differs
* Closes #1357
* Fix All Shapez Exports Being Const (#1358)
* Allowed setting of variables inside webpack modules
* remove console log
* Fix stringification of things inside of eval
Co-authored-by: Edward Badel <you@example.com>
* Fix building placer intersection warning
* Add example for storing data in the savegame
* Fix double painter bug (#1349)
* Add example on how to extend builtin buildings
* update readme
* Disable steam achievements when playing with mods
* Update translations
Co-authored-by: Thomas (DJ1TJOO) <44841260+DJ1TJOO@users.noreply.github.com>
Co-authored-by: Bagel03 <70449196+Bagel03@users.noreply.github.com>
Co-authored-by: Edward Badel <you@example.com>
Co-authored-by: Emerald Block <69981203+EmeraldBlock@users.noreply.github.com>
Co-authored-by: saile515 <63782477+saile515@users.noreply.github.com>
Co-authored-by: Sense101 <67970865+Sense101@users.noreply.github.com>
2 years ago
|
|
|
handleKeydown({ keyCode, shift, alt, ctrl }) {
|
|
|
|
if (keyCode === kbEnter && this.enterHandler) {
|
|
|
|
this.internalButtonHandler(this.enterHandler);
|
|
|
|
return STOP_PROPAGATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keyCode === kbCancel && this.escapeHandler) {
|
|
|
|
this.internalButtonHandler(this.escapeHandler);
|
|
|
|
return STOP_PROPAGATION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internalButtonHandler(id, ...payload) {
|
|
|
|
this.app.inputMgr.popReciever(this.inputReciever);
|
|
|
|
|
|
|
|
if (id !== "close-button") {
|
|
|
|
this.buttonSignals[id].dispatch(...payload);
|
|
|
|
}
|
|
|
|
this.closeRequested.dispatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
createElement() {
|
|
|
|
const elem = document.createElement("div");
|
|
|
|
elem.classList.add("ingameDialog");
|
|
|
|
|
|
|
|
this.dialogElem = document.createElement("div");
|
|
|
|
this.dialogElem.classList.add("dialogInner");
|
|
|
|
|
|
|
|
if (this.type) {
|
|
|
|
this.dialogElem.classList.add(this.type);
|
|
|
|
}
|
|
|
|
elem.appendChild(this.dialogElem);
|
|
|
|
|
|
|
|
const title = document.createElement("h1");
|
|
|
|
title.innerText = this.title;
|
|
|
|
title.classList.add("title");
|
|
|
|
this.dialogElem.appendChild(title);
|
|
|
|
|
|
|
|
if (this.closeButton) {
|
|
|
|
this.dialogElem.classList.add("hasCloseButton");
|
|
|
|
|
|
|
|
const closeBtn = document.createElement("button");
|
|
|
|
closeBtn.classList.add("closeButton");
|
|
|
|
|
|
|
|
this.trackClicks(closeBtn, () => this.internalButtonHandler("close-button"), {
|
|
|
|
applyCssClass: "pressedSmallElement",
|
|
|
|
});
|
|
|
|
|
|
|
|
title.appendChild(closeBtn);
|
|
|
|
this.inputReciever.backButton.add(() => this.internalButtonHandler("close-button"));
|
|
|
|
}
|
|
|
|
|
|
|
|
const content = document.createElement("div");
|
|
|
|
content.classList.add("content");
|
|
|
|
content.innerHTML = this.contentHTML;
|
|
|
|
this.dialogElem.appendChild(content);
|
|
|
|
|
|
|
|
if (this.buttonIds.length > 0) {
|
|
|
|
const buttons = document.createElement("div");
|
|
|
|
buttons.classList.add("buttons");
|
|
|
|
|
|
|
|
// Create buttons
|
|
|
|
for (let i = 0; i < this.buttonIds.length; ++i) {
|
|
|
|
const [buttonId, buttonStyle, rawParams] = this.buttonIds[i].split(":");
|
|
|
|
|
|
|
|
const button = document.createElement("button");
|
|
|
|
button.classList.add("button");
|
|
|
|
button.classList.add("styledButton");
|
|
|
|
button.classList.add(buttonStyle);
|
|
|
|
button.innerText = T.dialogs.buttons[buttonId];
|
|
|
|
|
|
|
|
const params = (rawParams || "").split("/");
|
|
|
|
const useTimeout = params.indexOf("timeout") >= 0;
|
|
|
|
|
|
|
|
const isEnter = params.indexOf("enter") >= 0;
|
|
|
|
const isEscape = params.indexOf("escape") >= 0;
|
|
|
|
|
|
|
|
if (isEscape && this.closeButton) {
|
|
|
|
logger.warn("Showing dialog with close button, and additional cancel button");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useTimeout) {
|
|
|
|
button.classList.add("timedButton");
|
|
|
|
const timeout = setTimeout(() => {
|
|
|
|
button.classList.remove("timedButton");
|
|
|
|
arrayDeleteValue(this.timeouts, timeout);
|
|
|
|
}, 3000);
|
|
|
|
this.timeouts.push(timeout);
|
|
|
|
}
|
|
|
|
if (isEnter || isEscape) {
|
|
|
|
// if (this.app.settings.getShowKeyboardShortcuts()) {
|
|
|
|
// Show keybinding
|
|
|
|
const spacer = document.createElement("code");
|
|
|
|
spacer.classList.add("keybinding");
|
|
|
|
spacer.innerHTML = getStringForKeyCode(isEnter ? kbEnter : kbCancel);
|
|
|
|
button.appendChild(spacer);
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (isEnter) {
|
|
|
|
this.enterHandler = buttonId;
|
|
|
|
}
|
|
|
|
if (isEscape) {
|
|
|
|
this.escapeHandler = buttonId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.trackClicks(button, () => this.internalButtonHandler(buttonId));
|
|
|
|
buttons.appendChild(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dialogElem.appendChild(buttons);
|
|
|
|
} else {
|
|
|
|
this.dialogElem.classList.add("buttonless");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.element = elem;
|
|
|
|
this.app.inputMgr.pushReciever(this.inputReciever);
|
|
|
|
|
|
|
|
return this.element;
|
|
|
|
}
|
|
|
|
|
|
|
|
setIndex(index) {
|
|
|
|
this.element.style.zIndex = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
if (!this.element) {
|
|
|
|
assert(false, "Tried to destroy dialog twice");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// We need to do this here, because if the backbutton event gets
|
|
|
|
// dispatched to the modal dialogs, it will not call the internalButtonHandler,
|
|
|
|
// and thus our receiver stays attached the whole time
|
|
|
|
this.app.inputMgr.destroyReceiver(this.inputReciever);
|
|
|
|
|
|
|
|
for (let i = 0; i < this.clickDetectors.length; ++i) {
|
|
|
|
this.clickDetectors[i].cleanup();
|
|
|
|
}
|
|
|
|
this.clickDetectors = [];
|
|
|
|
|
|
|
|
this.element.remove();
|
|
|
|
this.element = null;
|
|
|
|
|
|
|
|
for (let i = 0; i < this.timeouts.length; ++i) {
|
|
|
|
clearTimeout(this.timeouts[i]);
|
|
|
|
}
|
|
|
|
this.timeouts = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
this.element.classList.remove("visible");
|
|
|
|
}
|
|
|
|
|
|
|
|
show() {
|
|
|
|
this.element.classList.add("visible");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method to track clicks on an element
|
|
|
|
* @param {Element} elem
|
|
|
|
* @param {function():void} handler
|
|
|
|
* @param {import("./click_detector").ClickDetectorConstructorArgs=} args
|
|
|
|
* @returns {ClickDetector}
|
|
|
|
*/
|
|
|
|
trackClicks(elem, handler, args = {}) {
|
|
|
|
const detector = new ClickDetector(elem, args);
|
|
|
|
detector.click.add(handler, this);
|
|
|
|
this.clickDetectors.push(detector);
|
|
|
|
return detector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog which simply shows a loading spinner
|
|
|
|
*/
|
|
|
|
export class DialogLoading extends Dialog {
|
Puzzle DLC (#1172)
* Puzzle mode (#1135)
* Add mode button to main menu
* [WIP] Add mode menu. Add factory-based gameMode creation
* Add savefile migration, serialize, deserialize
* Add hidden HUD elements, zone, and zoom, boundary constraints
* Clean up lint issues
* Add building, HUD exclusion, building exclusion, and refactor
- [WIP] Add ConstantProducer building that combines ConstantSignal
and ItemProducer functionality. Currently using temp assets.
- Add pre-placement check to the zone
- Use Rectangles for zone and boundary
- Simplify zone drawing
- Account for exclusion in savegame data
- [WIP] Add puzzle play and edit buttons in puzzle mode menu
* [WIP] Add building, component, and systems for producing and
accepting user-specified items and checking goal criteria
* Add ingame puzzle mode UI elements
- Add minimal menus in puzzle mode for back, next navigation
- Add lower menu for changing zone dimenensions
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
* Performance optimizations (#1154)
* 1.3.1 preparations
* Minor fixes, update translations
* Fix achievements not working
* Lots of belt optimizations, ~15% performance boost
* Puzzle mode, part 1
* Puzzle mode, part 2
* Fix missing import
* Puzzle mode, part 3
* Fix typo
* Puzzle mode, part 4
* Puzzle Mode fixes: Correct zone restrictions and more (#1155)
* Hide Puzzle Editor Controls in regular game mode, fix typo
* Disallow shrinking zone if there are buildings
* Fix multi-tile buildings for shrinking
* Puzzle mode, Refactor hud
* Puzzle mode
* Fixed typo in latest puzzle commit (#1156)
* Allow completing puzzles
* Puzzle mode, almost done
* Bump version to 1.4.0
* Fixes
* [puzzle] Prevent pipette cheats (miners, emitters) (#1158)
* Puzzle mode, almost done
* Allow clearing belts with 'B'
* Multiple users for the puzzle dlc
* Bump api key
* Minor adjustments
* Update
* Minor fixes
* Fix throughput
* Fix belts
* Minor puzzle adjustments
* New difficulty
* Minor puzzle improvements
* Fix belt path
* Update translations
* Added a button to return to the menu after a puzzle is completed (#1170)
* added another button to return to the menu
* improved menu return
* fixed continue button to not go back to menu
* [Puzzle] Added ability to lock buildings in the puzzle editor! (#1164)
* initial test
* tried to get it to work
* added icon
* added test exclusion
* reverted css
* completed flow for building locking
* added lock option
* finalized look and changed locked building to same sprite
* removed unused art
* added clearing every goal acceptor on lock to prevent creating impossible puzzles
* heavily improved validation and prevented autocompletion
* validation only checks every 100 ticks to improve performance
* validation only checks every 100 ticks to improve performance
* removed clearing goal acceptors as it isn't needed because of validation
* Add soundtrack, puzzle dlc fixes
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
Co-authored-by: dengr1065 <dengr1065@gmail.com>
Co-authored-by: Sense101 <67970865+Sense101@users.noreply.github.com>
3 years ago
|
|
|
constructor(app, text = "") {
|
|
|
|
super({
|
|
|
|
app,
|
|
|
|
title: "",
|
|
|
|
contentHTML: "",
|
|
|
|
buttons: [],
|
|
|
|
type: "loading",
|
|
|
|
});
|
|
|
|
|
|
|
|
// Loading dialog can not get closed with back button
|
|
|
|
this.inputReciever.backButton.removeAll();
|
|
|
|
this.inputReciever.context = "dialog-loading";
|
Puzzle DLC (#1172)
* Puzzle mode (#1135)
* Add mode button to main menu
* [WIP] Add mode menu. Add factory-based gameMode creation
* Add savefile migration, serialize, deserialize
* Add hidden HUD elements, zone, and zoom, boundary constraints
* Clean up lint issues
* Add building, HUD exclusion, building exclusion, and refactor
- [WIP] Add ConstantProducer building that combines ConstantSignal
and ItemProducer functionality. Currently using temp assets.
- Add pre-placement check to the zone
- Use Rectangles for zone and boundary
- Simplify zone drawing
- Account for exclusion in savegame data
- [WIP] Add puzzle play and edit buttons in puzzle mode menu
* [WIP] Add building, component, and systems for producing and
accepting user-specified items and checking goal criteria
* Add ingame puzzle mode UI elements
- Add minimal menus in puzzle mode for back, next navigation
- Add lower menu for changing zone dimenensions
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
* Performance optimizations (#1154)
* 1.3.1 preparations
* Minor fixes, update translations
* Fix achievements not working
* Lots of belt optimizations, ~15% performance boost
* Puzzle mode, part 1
* Puzzle mode, part 2
* Fix missing import
* Puzzle mode, part 3
* Fix typo
* Puzzle mode, part 4
* Puzzle Mode fixes: Correct zone restrictions and more (#1155)
* Hide Puzzle Editor Controls in regular game mode, fix typo
* Disallow shrinking zone if there are buildings
* Fix multi-tile buildings for shrinking
* Puzzle mode, Refactor hud
* Puzzle mode
* Fixed typo in latest puzzle commit (#1156)
* Allow completing puzzles
* Puzzle mode, almost done
* Bump version to 1.4.0
* Fixes
* [puzzle] Prevent pipette cheats (miners, emitters) (#1158)
* Puzzle mode, almost done
* Allow clearing belts with 'B'
* Multiple users for the puzzle dlc
* Bump api key
* Minor adjustments
* Update
* Minor fixes
* Fix throughput
* Fix belts
* Minor puzzle adjustments
* New difficulty
* Minor puzzle improvements
* Fix belt path
* Update translations
* Added a button to return to the menu after a puzzle is completed (#1170)
* added another button to return to the menu
* improved menu return
* fixed continue button to not go back to menu
* [Puzzle] Added ability to lock buildings in the puzzle editor! (#1164)
* initial test
* tried to get it to work
* added icon
* added test exclusion
* reverted css
* completed flow for building locking
* added lock option
* finalized look and changed locked building to same sprite
* removed unused art
* added clearing every goal acceptor on lock to prevent creating impossible puzzles
* heavily improved validation and prevented autocompletion
* validation only checks every 100 ticks to improve performance
* validation only checks every 100 ticks to improve performance
* removed clearing goal acceptors as it isn't needed because of validation
* Add soundtrack, puzzle dlc fixes
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
Co-authored-by: dengr1065 <dengr1065@gmail.com>
Co-authored-by: Sense101 <67970865+Sense101@users.noreply.github.com>
3 years ago
|
|
|
|
|
|
|
this.text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
createElement() {
|
|
|
|
const elem = document.createElement("div");
|
|
|
|
elem.classList.add("ingameDialog");
|
|
|
|
elem.classList.add("loadingDialog");
|
|
|
|
this.element = elem;
|
|
|
|
|
Puzzle DLC (#1172)
* Puzzle mode (#1135)
* Add mode button to main menu
* [WIP] Add mode menu. Add factory-based gameMode creation
* Add savefile migration, serialize, deserialize
* Add hidden HUD elements, zone, and zoom, boundary constraints
* Clean up lint issues
* Add building, HUD exclusion, building exclusion, and refactor
- [WIP] Add ConstantProducer building that combines ConstantSignal
and ItemProducer functionality. Currently using temp assets.
- Add pre-placement check to the zone
- Use Rectangles for zone and boundary
- Simplify zone drawing
- Account for exclusion in savegame data
- [WIP] Add puzzle play and edit buttons in puzzle mode menu
* [WIP] Add building, component, and systems for producing and
accepting user-specified items and checking goal criteria
* Add ingame puzzle mode UI elements
- Add minimal menus in puzzle mode for back, next navigation
- Add lower menu for changing zone dimenensions
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
* Performance optimizations (#1154)
* 1.3.1 preparations
* Minor fixes, update translations
* Fix achievements not working
* Lots of belt optimizations, ~15% performance boost
* Puzzle mode, part 1
* Puzzle mode, part 2
* Fix missing import
* Puzzle mode, part 3
* Fix typo
* Puzzle mode, part 4
* Puzzle Mode fixes: Correct zone restrictions and more (#1155)
* Hide Puzzle Editor Controls in regular game mode, fix typo
* Disallow shrinking zone if there are buildings
* Fix multi-tile buildings for shrinking
* Puzzle mode, Refactor hud
* Puzzle mode
* Fixed typo in latest puzzle commit (#1156)
* Allow completing puzzles
* Puzzle mode, almost done
* Bump version to 1.4.0
* Fixes
* [puzzle] Prevent pipette cheats (miners, emitters) (#1158)
* Puzzle mode, almost done
* Allow clearing belts with 'B'
* Multiple users for the puzzle dlc
* Bump api key
* Minor adjustments
* Update
* Minor fixes
* Fix throughput
* Fix belts
* Minor puzzle adjustments
* New difficulty
* Minor puzzle improvements
* Fix belt path
* Update translations
* Added a button to return to the menu after a puzzle is completed (#1170)
* added another button to return to the menu
* improved menu return
* fixed continue button to not go back to menu
* [Puzzle] Added ability to lock buildings in the puzzle editor! (#1164)
* initial test
* tried to get it to work
* added icon
* added test exclusion
* reverted css
* completed flow for building locking
* added lock option
* finalized look and changed locked building to same sprite
* removed unused art
* added clearing every goal acceptor on lock to prevent creating impossible puzzles
* heavily improved validation and prevented autocompletion
* validation only checks every 100 ticks to improve performance
* validation only checks every 100 ticks to improve performance
* removed clearing goal acceptors as it isn't needed because of validation
* Add soundtrack, puzzle dlc fixes
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
Co-authored-by: dengr1065 <dengr1065@gmail.com>
Co-authored-by: Sense101 <67970865+Sense101@users.noreply.github.com>
3 years ago
|
|
|
if (this.text) {
|
|
|
|
const text = document.createElement("div");
|
|
|
|
text.classList.add("text");
|
|
|
|
text.innerText = this.text;
|
|
|
|
elem.appendChild(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
const loader = document.createElement("div");
|
|
|
|
loader.classList.add("prefab_LoadingTextWithAnim");
|
|
|
|
loader.classList.add("loadingIndicator");
|
|
|
|
elem.appendChild(loader);
|
|
|
|
|
|
|
|
this.app.inputMgr.pushReciever(this.inputReciever);
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DialogOptionChooser extends Dialog {
|
|
|
|
constructor({ app, title, options }) {
|
|
|
|
let html = "<div class='optionParent'>";
|
|
|
|
|
|
|
|
options.options.forEach(({ value, text, desc = null, iconPrefix = null }) => {
|
|
|
|
const descHtml = desc ? `<span class="desc">${desc}</span>` : "";
|
|
|
|
let iconHtml = iconPrefix ? `<span class="icon icon-${iconPrefix}-${value}"></span>` : "";
|
|
|
|
html += `
|
|
|
|
<div class='option ${value === options.active ? "active" : ""} ${
|
|
|
|
iconPrefix ? "hasIcon" : ""
|
|
|
|
}' data-optionvalue='${value}'>
|
Puzzle DLC (#1172)
* Puzzle mode (#1135)
* Add mode button to main menu
* [WIP] Add mode menu. Add factory-based gameMode creation
* Add savefile migration, serialize, deserialize
* Add hidden HUD elements, zone, and zoom, boundary constraints
* Clean up lint issues
* Add building, HUD exclusion, building exclusion, and refactor
- [WIP] Add ConstantProducer building that combines ConstantSignal
and ItemProducer functionality. Currently using temp assets.
- Add pre-placement check to the zone
- Use Rectangles for zone and boundary
- Simplify zone drawing
- Account for exclusion in savegame data
- [WIP] Add puzzle play and edit buttons in puzzle mode menu
* [WIP] Add building, component, and systems for producing and
accepting user-specified items and checking goal criteria
* Add ingame puzzle mode UI elements
- Add minimal menus in puzzle mode for back, next navigation
- Add lower menu for changing zone dimenensions
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
* Performance optimizations (#1154)
* 1.3.1 preparations
* Minor fixes, update translations
* Fix achievements not working
* Lots of belt optimizations, ~15% performance boost
* Puzzle mode, part 1
* Puzzle mode, part 2
* Fix missing import
* Puzzle mode, part 3
* Fix typo
* Puzzle mode, part 4
* Puzzle Mode fixes: Correct zone restrictions and more (#1155)
* Hide Puzzle Editor Controls in regular game mode, fix typo
* Disallow shrinking zone if there are buildings
* Fix multi-tile buildings for shrinking
* Puzzle mode, Refactor hud
* Puzzle mode
* Fixed typo in latest puzzle commit (#1156)
* Allow completing puzzles
* Puzzle mode, almost done
* Bump version to 1.4.0
* Fixes
* [puzzle] Prevent pipette cheats (miners, emitters) (#1158)
* Puzzle mode, almost done
* Allow clearing belts with 'B'
* Multiple users for the puzzle dlc
* Bump api key
* Minor adjustments
* Update
* Minor fixes
* Fix throughput
* Fix belts
* Minor puzzle adjustments
* New difficulty
* Minor puzzle improvements
* Fix belt path
* Update translations
* Added a button to return to the menu after a puzzle is completed (#1170)
* added another button to return to the menu
* improved menu return
* fixed continue button to not go back to menu
* [Puzzle] Added ability to lock buildings in the puzzle editor! (#1164)
* initial test
* tried to get it to work
* added icon
* added test exclusion
* reverted css
* completed flow for building locking
* added lock option
* finalized look and changed locked building to same sprite
* removed unused art
* added clearing every goal acceptor on lock to prevent creating impossible puzzles
* heavily improved validation and prevented autocompletion
* validation only checks every 100 ticks to improve performance
* validation only checks every 100 ticks to improve performance
* removed clearing goal acceptors as it isn't needed because of validation
* Add soundtrack, puzzle dlc fixes
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
Co-authored-by: dengr1065 <dengr1065@gmail.com>
Co-authored-by: Sense101 <67970865+Sense101@users.noreply.github.com>
3 years ago
|
|
|
${iconHtml}
|
|
|
|
<span class='title'>${text}</span>
|
|
|
|
${descHtml}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
});
|
|
|
|
|
|
|
|
html += "</div>";
|
|
|
|
super({
|
|
|
|
app,
|
|
|
|
title,
|
|
|
|
contentHTML: html,
|
|
|
|
buttons: [],
|
|
|
|
type: "info",
|
|
|
|
closeButton: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.options = options;
|
|
|
|
this.initialOption = options.active;
|
|
|
|
|
|
|
|
this.buttonSignals.optionSelected = new Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
createElement() {
|
|
|
|
const div = super.createElement();
|
|
|
|
this.dialogElem.classList.add("optionChooserDialog");
|
|
|
|
|
|
|
|
div.querySelectorAll("[data-optionvalue]").forEach(handle => {
|
|
|
|
const value = handle.getAttribute("data-optionvalue");
|
|
|
|
if (!handle) {
|
|
|
|
logger.error("Failed to bind option value in dialog:", value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Need click detector here to forward elements, otherwise scrolling does not work
|
|
|
|
const detector = new ClickDetector(handle, {
|
|
|
|
consumeEvents: false,
|
|
|
|
preventDefault: false,
|
|
|
|
clickSound: null,
|
|
|
|
applyCssClass: "pressedOption",
|
|
|
|
targetOnly: true,
|
|
|
|
});
|
|
|
|
this.clickDetectors.push(detector);
|
|
|
|
|
|
|
|
if (value !== this.initialOption) {
|
|
|
|
detector.click.add(() => {
|
|
|
|
const selected = div.querySelector(".option.active");
|
|
|
|
if (selected) {
|
|
|
|
selected.classList.remove("active");
|
|
|
|
} else {
|
|
|
|
logger.warn("No selected option");
|
|
|
|
}
|
|
|
|
handle.classList.add("active");
|
|
|
|
this.app.sound.playUiSound(SOUNDS.uiClick);
|
|
|
|
this.internalButtonHandler("optionSelected", value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DialogWithForm extends Dialog {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {object} param0
|
|
|
|
* @param {Application} param0.app
|
|
|
|
* @param {string} param0.title
|
|
|
|
* @param {string} param0.desc
|
|
|
|
* @param {array=} param0.buttons
|
|
|
|
* @param {string=} param0.confirmButtonId
|
|
|
|
* @param {string=} param0.extraButton
|
|
|
|
* @param {boolean=} param0.closeButton
|
|
|
|
* @param {Array<FormElement>} param0.formElements
|
|
|
|
*/
|
|
|
|
constructor({
|
|
|
|
app,
|
|
|
|
title,
|
|
|
|
desc,
|
|
|
|
formElements,
|
|
|
|
buttons = ["cancel", "ok:good"],
|
|
|
|
confirmButtonId = "ok",
|
|
|
|
closeButton = true,
|
|
|
|
}) {
|
|
|
|
let html = "";
|
|
|
|
html += desc + "<br>";
|
|
|
|
for (let i = 0; i < formElements.length; ++i) {
|
|
|
|
html += formElements[i].getHtml();
|
|
|
|
}
|
|
|
|
|
|
|
|
super({
|
|
|
|
app,
|
|
|
|
title: title,
|
|
|
|
contentHTML: html,
|
|
|
|
buttons: buttons,
|
|
|
|
type: "info",
|
|
|
|
closeButton,
|
|
|
|
});
|
|
|
|
this.confirmButtonId = confirmButtonId;
|
|
|
|
this.formElements = formElements;
|
|
|
|
|
|
|
|
this.enterHandler = confirmButtonId;
|
|
|
|
}
|
|
|
|
|
|
|
|
internalButtonHandler(id, ...payload) {
|
|
|
|
if (id === this.confirmButtonId) {
|
|
|
|
if (this.hasAnyInvalid()) {
|
|
|
|
this.dialogElem.classList.remove("errorShake");
|
|
|
|
waitNextFrame().then(() => {
|
|
|
|
if (this.dialogElem) {
|
|
|
|
this.dialogElem.classList.add("errorShake");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.app.sound.playUiSound(SOUNDS.uiError);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super.internalButtonHandler(id, payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
hasAnyInvalid() {
|
|
|
|
for (let i = 0; i < this.formElements.length; ++i) {
|
|
|
|
if (!this.formElements[i].isValid()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
createElement() {
|
|
|
|
const div = super.createElement();
|
|
|
|
|
|
|
|
for (let i = 0; i < this.formElements.length; ++i) {
|
|
|
|
const elem = this.formElements[i];
|
|
|
|
elem.bindEvents(div, this.clickDetectors);
|
Puzzle DLC (#1172)
* Puzzle mode (#1135)
* Add mode button to main menu
* [WIP] Add mode menu. Add factory-based gameMode creation
* Add savefile migration, serialize, deserialize
* Add hidden HUD elements, zone, and zoom, boundary constraints
* Clean up lint issues
* Add building, HUD exclusion, building exclusion, and refactor
- [WIP] Add ConstantProducer building that combines ConstantSignal
and ItemProducer functionality. Currently using temp assets.
- Add pre-placement check to the zone
- Use Rectangles for zone and boundary
- Simplify zone drawing
- Account for exclusion in savegame data
- [WIP] Add puzzle play and edit buttons in puzzle mode menu
* [WIP] Add building, component, and systems for producing and
accepting user-specified items and checking goal criteria
* Add ingame puzzle mode UI elements
- Add minimal menus in puzzle mode for back, next navigation
- Add lower menu for changing zone dimenensions
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
* Performance optimizations (#1154)
* 1.3.1 preparations
* Minor fixes, update translations
* Fix achievements not working
* Lots of belt optimizations, ~15% performance boost
* Puzzle mode, part 1
* Puzzle mode, part 2
* Fix missing import
* Puzzle mode, part 3
* Fix typo
* Puzzle mode, part 4
* Puzzle Mode fixes: Correct zone restrictions and more (#1155)
* Hide Puzzle Editor Controls in regular game mode, fix typo
* Disallow shrinking zone if there are buildings
* Fix multi-tile buildings for shrinking
* Puzzle mode, Refactor hud
* Puzzle mode
* Fixed typo in latest puzzle commit (#1156)
* Allow completing puzzles
* Puzzle mode, almost done
* Bump version to 1.4.0
* Fixes
* [puzzle] Prevent pipette cheats (miners, emitters) (#1158)
* Puzzle mode, almost done
* Allow clearing belts with 'B'
* Multiple users for the puzzle dlc
* Bump api key
* Minor adjustments
* Update
* Minor fixes
* Fix throughput
* Fix belts
* Minor puzzle adjustments
* New difficulty
* Minor puzzle improvements
* Fix belt path
* Update translations
* Added a button to return to the menu after a puzzle is completed (#1170)
* added another button to return to the menu
* improved menu return
* fixed continue button to not go back to menu
* [Puzzle] Added ability to lock buildings in the puzzle editor! (#1164)
* initial test
* tried to get it to work
* added icon
* added test exclusion
* reverted css
* completed flow for building locking
* added lock option
* finalized look and changed locked building to same sprite
* removed unused art
* added clearing every goal acceptor on lock to prevent creating impossible puzzles
* heavily improved validation and prevented autocompletion
* validation only checks every 100 ticks to improve performance
* validation only checks every 100 ticks to improve performance
* removed clearing goal acceptors as it isn't needed because of validation
* Add soundtrack, puzzle dlc fixes
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
Co-authored-by: dengr1065 <dengr1065@gmail.com>
Co-authored-by: Sense101 <67970865+Sense101@users.noreply.github.com>
3 years ago
|
|
|
// elem.valueChosen.add(this.closeRequested.dispatch, this.closeRequested);
|
|
|
|
elem.valueChosen.add(this.valueChosen.dispatch, this.valueChosen);
|
|
|
|
}
|
|
|
|
|
|
|
|
waitNextFrame().then(() => {
|
|
|
|
this.formElements[this.formElements.length - 1].focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
}
|