mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Ability to edit Constant Signals
- Ability to edit constant signals by clicking on them - Will show the last signal as a defualt input for easier editing
This commit is contained in:
parent
9c75e1777d
commit
cf01cab2e3
@ -31,5 +31,6 @@ export class ConstantSignalComponent extends Component {
|
|||||||
constructor({ signal = null }) {
|
constructor({ signal = null }) {
|
||||||
super();
|
super();
|
||||||
this.signal = signal;
|
this.signal = signal;
|
||||||
|
this.clicked = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import { HUDSandboxController } from "./parts/sandbox_controller";
|
|||||||
import { HUDWiresToolbar } from "./parts/wires_toolbar";
|
import { HUDWiresToolbar } from "./parts/wires_toolbar";
|
||||||
import { HUDWireInfo } from "./parts/wire_info";
|
import { HUDWireInfo } from "./parts/wire_info";
|
||||||
import { HUDLeverToggle } from "./parts/lever_toggle";
|
import { HUDLeverToggle } from "./parts/lever_toggle";
|
||||||
|
import { HUDEditConstantSignal } from "./parts/edit_constant_signal"
|
||||||
import { HUDLayerPreview } from "./parts/layer_preview";
|
import { HUDLayerPreview } from "./parts/layer_preview";
|
||||||
import { HUDMinerHighlight } from "./parts/miner_highlight";
|
import { HUDMinerHighlight } from "./parts/miner_highlight";
|
||||||
import { HUDBetaOverlay } from "./parts/beta_overlay";
|
import { HUDBetaOverlay } from "./parts/beta_overlay";
|
||||||
@ -71,6 +72,7 @@ export class GameHUD {
|
|||||||
waypoints: new HUDWaypoints(this.root),
|
waypoints: new HUDWaypoints(this.root),
|
||||||
wireInfo: new HUDWireInfo(this.root),
|
wireInfo: new HUDWireInfo(this.root),
|
||||||
leverToggle: new HUDLeverToggle(this.root),
|
leverToggle: new HUDLeverToggle(this.root),
|
||||||
|
editConstantSignal: new HUDEditConstantSignal(this.root),
|
||||||
|
|
||||||
// Must always exist
|
// Must always exist
|
||||||
pinnedShapes: new HUDPinnedShapes(this.root),
|
pinnedShapes: new HUDPinnedShapes(this.root),
|
||||||
|
31
src/js/game/hud/parts/edit_constant_signal.js
Normal file
31
src/js/game/hud/parts/edit_constant_signal.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { STOP_PROPAGATION } from "../../../core/signal";
|
||||||
|
import { Vector } from "../../../core/vector";
|
||||||
|
import { enumMouseButton } from "../../camera";
|
||||||
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
|
|
||||||
|
export class HUDEditConstantSignal extends BaseHUDPart {
|
||||||
|
initialize() {
|
||||||
|
this.root.camera.downPreHandler.add(this.downPreHandler, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Vector} pos
|
||||||
|
* @param {enumMouseButton} button
|
||||||
|
*/
|
||||||
|
downPreHandler(pos, button) {
|
||||||
|
const tile = this.root.camera.screenToWorld(pos).toTileSpace();
|
||||||
|
const contents = this.root.map.getLayerContentXY(tile.x, tile.y, "wires");
|
||||||
|
if (contents) {
|
||||||
|
const signalComp = contents.components.ConstantSignal;
|
||||||
|
if (signalComp) {
|
||||||
|
if (button === enumMouseButton.left) {
|
||||||
|
signalComp.clicked = true;
|
||||||
|
return STOP_PROPAGATION;
|
||||||
|
} else if (button === enumMouseButton.right) {
|
||||||
|
this.root.logic.tryDeleteBuilding(contents);
|
||||||
|
return STOP_PROPAGATION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,75 @@ 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