mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Relocated code to the HUD Part
This commit is contained in:
parent
e9206c1057
commit
9478c3eef9
@ -31,6 +31,5 @@ export class ConstantSignalComponent extends Component {
|
|||||||
constructor({ signal = null }) {
|
constructor({ signal = null }) {
|
||||||
super();
|
super();
|
||||||
this.signal = signal;
|
this.signal = signal;
|
||||||
this.clicked = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,18 @@ import { STOP_PROPAGATION } from "../../../core/signal";
|
|||||||
import { Vector } from "../../../core/vector";
|
import { Vector } from "../../../core/vector";
|
||||||
import { enumMouseButton } from "../../camera";
|
import { enumMouseButton } from "../../camera";
|
||||||
import { BaseHUDPart } from "../base_hud_part";
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
|
import { FormElementInput, FormElementItemChooser } from "../../../core/modal_dialog_forms";
|
||||||
|
import { fillInLinkIntoTranslation } from "../../../core/utils";
|
||||||
|
import { T } from "../../../translations";
|
||||||
|
import { THIRDPARTY_URLS } from "../../../core/config";
|
||||||
|
import { BaseItem } from "../../base_item";
|
||||||
|
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON } from "../../items/boolean_item";
|
||||||
|
import { DialogWithForm } from "../../../core/modal_dialog_elements";
|
||||||
|
import { COLOR_ITEM_SINGLETONS } from "../../items/color_item";
|
||||||
|
import { blueprintShape } from "../../upgrades";
|
||||||
|
import trim from "trim";
|
||||||
|
import { ShapeDefinition } from "../../shape_definition";
|
||||||
|
import { enumColors } from "../../colors";
|
||||||
|
|
||||||
export class HUDEditConstantSignal extends BaseHUDPart {
|
export class HUDEditConstantSignal extends BaseHUDPart {
|
||||||
initialize() {
|
initialize() {
|
||||||
@ -14,15 +26,83 @@ export class HUDEditConstantSignal extends BaseHUDPart {
|
|||||||
*/
|
*/
|
||||||
downPreHandler(pos, button) {
|
downPreHandler(pos, button) {
|
||||||
const tile = this.root.camera.screenToWorld(pos).toTileSpace();
|
const tile = this.root.camera.screenToWorld(pos).toTileSpace();
|
||||||
const contents = this.root.map.getLayerContentXY(tile.x, tile.y, "wires");
|
const entity = this.root.map.getLayerContentXY(tile.x, tile.y, "wires");
|
||||||
if (contents) {
|
if (entity) {
|
||||||
const signalComp = contents.components.ConstantSignal;
|
const signalComp = entity.components.ConstantSignal;
|
||||||
if (signalComp) {
|
if (signalComp) {
|
||||||
if (button === enumMouseButton.left) {
|
if (button === enumMouseButton.left) {
|
||||||
signalComp.clicked = true;
|
if (!entity.components.ConstantSignal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ok, query, but also save the uid because it could get stale
|
||||||
|
const uid = entity.uid;
|
||||||
|
|
||||||
|
const signalValueInput = new FormElementInput({
|
||||||
|
id: "signalValue",
|
||||||
|
label: fillInLinkIntoTranslation(
|
||||||
|
T.dialogs.editSignal.descShortKey,
|
||||||
|
THIRDPARTY_URLS.shapeViewer
|
||||||
|
),
|
||||||
|
placeholder: "",
|
||||||
|
defaultValue: signalComp.signal ? signalComp.signal.getAsCopyableKey() : "",
|
||||||
|
validator: val => this.root.systemMgr.systems.constantSignal.parseSignalCode(val),
|
||||||
|
});
|
||||||
|
|
||||||
|
const itemInput = new FormElementItemChooser({
|
||||||
|
id: "signalItem",
|
||||||
|
label: null,
|
||||||
|
items: [
|
||||||
|
BOOL_FALSE_SINGLETON,
|
||||||
|
BOOL_TRUE_SINGLETON,
|
||||||
|
...Object.values(COLOR_ITEM_SINGLETONS),
|
||||||
|
this.root.shapeDefinitionMgr.getShapeItemFromShortKey(blueprintShape),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const dialog = new DialogWithForm({
|
||||||
|
app: this.root.app,
|
||||||
|
title: T.dialogs.editSignal.title,
|
||||||
|
desc: T.dialogs.editSignal.descItems,
|
||||||
|
formElements: [itemInput, signalValueInput],
|
||||||
|
buttons: ["cancel:bad:escape", "ok:good:enter"],
|
||||||
|
closeButton: false,
|
||||||
|
});
|
||||||
|
this.root.hud.parts.dialogs.internalShowDialog(dialog);
|
||||||
|
|
||||||
|
// When confirmed, set the signal
|
||||||
|
const closeHandler = () => {
|
||||||
|
if (!this.root || !this.root.entityMgr) {
|
||||||
|
// Game got stopped
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entityRef = this.root.entityMgr.findByUid(uid, false);
|
||||||
|
if (!entityRef) {
|
||||||
|
// outdated
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const constantComp = entityRef.components.ConstantSignal;
|
||||||
|
if (!constantComp) {
|
||||||
|
// no longer interesting
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemInput.chosenItem) {
|
||||||
|
console.log(itemInput.chosenItem);
|
||||||
|
constantComp.signal = itemInput.chosenItem;
|
||||||
|
} else {
|
||||||
|
constantComp.signal = this.root.systemMgr.systems.constantSignal.parseSignalCode(signalValueInput.getValue());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dialog.buttonSignals.ok.add(closeHandler);
|
||||||
|
dialog.valueChosen.add(closeHandler);
|
||||||
|
|
||||||
return STOP_PROPAGATION;
|
return STOP_PROPAGATION;
|
||||||
} else if (button === enumMouseButton.right) {
|
} else if (button === enumMouseButton.right) {
|
||||||
this.root.logic.tryDeleteBuilding(contents);
|
this.root.logic.tryDeleteBuilding(entity);
|
||||||
return STOP_PROPAGATION;
|
return STOP_PROPAGATION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,77 +27,6 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
|||||||
const entity = this.allEntities[i];
|
const entity = this.allEntities[i];
|
||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
const signalComp = entity.components.ConstantSignal;
|
const signalComp = entity.components.ConstantSignal;
|
||||||
if (signalComp.clicked == true) {
|
|
||||||
signalComp.clicked = false;
|
|
||||||
if (!entity.components.ConstantSignal) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ok, query, but also save the uid because it could get stale
|
|
||||||
const uid = entity.uid;
|
|
||||||
|
|
||||||
const signalValueInput = new FormElementInput({
|
|
||||||
id: "signalValue",
|
|
||||||
label: fillInLinkIntoTranslation(
|
|
||||||
T.dialogs.editSignal.descShortKey,
|
|
||||||
THIRDPARTY_URLS.shapeViewer
|
|
||||||
),
|
|
||||||
placeholder: "",
|
|
||||||
defaultValue: signalComp.signal ? signalComp.signal.getAsCopyableKey() : "",
|
|
||||||
validator: val => this.parseSignalCode(val),
|
|
||||||
});
|
|
||||||
|
|
||||||
const itemInput = new FormElementItemChooser({
|
|
||||||
id: "signalItem",
|
|
||||||
label: null,
|
|
||||||
items: [
|
|
||||||
BOOL_FALSE_SINGLETON,
|
|
||||||
BOOL_TRUE_SINGLETON,
|
|
||||||
...Object.values(COLOR_ITEM_SINGLETONS),
|
|
||||||
this.root.shapeDefinitionMgr.getShapeItemFromShortKey(blueprintShape),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
const dialog = new DialogWithForm({
|
|
||||||
app: this.root.app,
|
|
||||||
title: T.dialogs.editSignal.title,
|
|
||||||
desc: T.dialogs.editSignal.descItems,
|
|
||||||
formElements: [itemInput, signalValueInput],
|
|
||||||
buttons: ["cancel:bad:escape", "ok:good:enter"],
|
|
||||||
closeButton: false,
|
|
||||||
});
|
|
||||||
this.root.hud.parts.dialogs.internalShowDialog(dialog);
|
|
||||||
|
|
||||||
// When confirmed, set the signal
|
|
||||||
const closeHandler = () => {
|
|
||||||
if (!this.root || !this.root.entityMgr) {
|
|
||||||
// Game got stopped
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const entityRef = this.root.entityMgr.findByUid(uid, false);
|
|
||||||
if (!entityRef) {
|
|
||||||
// outdated
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const constantComp = entityRef.components.ConstantSignal;
|
|
||||||
if (!constantComp) {
|
|
||||||
// no longer interesting
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemInput.chosenItem) {
|
|
||||||
console.log(itemInput.chosenItem);
|
|
||||||
constantComp.signal = itemInput.chosenItem;
|
|
||||||
} else {
|
|
||||||
constantComp.signal = this.parseSignalCode(signalValueInput.getValue());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
dialog.buttonSignals.ok.add(closeHandler);
|
|
||||||
dialog.valueChosen.add(closeHandler);
|
|
||||||
}
|
|
||||||
pinsComp.slots[0].value = signalComp.signal;
|
pinsComp.slots[0].value = signalComp.signal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user