1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-16 19:51:50 +00:00
This commit is contained in:
PFedak 2021-09-30 21:36:06 +02:00 committed by GitHub
commit 765d6511b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 34 deletions

View File

@ -235,14 +235,17 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
*/ */
draw(parameters) { draw(parameters) {
if (this.root.camera.getIsMapOverlayActive()) { if (this.root.camera.getIsMapOverlayActive()) {
// Dont allow placing in overview mode
this.domAttach.update(false); this.domAttach.update(false);
this.variantsAttach.update(false); this.variantsAttach.update(false);
return;
}
this.domAttach.update(!!this.currentMetaBuilding.get()); if (!this.isDirectionLockActive) {
this.variantsAttach.update(!!this.currentMetaBuilding.get()); // only draw preview in overlay if this is a belt or wire
return;
}
} else {
this.domAttach.update(!!this.currentMetaBuilding.get());
this.variantsAttach.update(!!this.currentMetaBuilding.get());
}
const metaBuilding = this.currentMetaBuilding.get(); const metaBuilding = this.currentMetaBuilding.get();
if (!metaBuilding) { if (!metaBuilding) {
@ -430,28 +433,32 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
parameters.context.beginCircle(endLine.x, endLine.y, 5); parameters.context.beginCircle(endLine.x, endLine.y, 5);
parameters.context.fill(); parameters.context.fill();
// Draw arrow if (!this.root.camera.getIsMapOverlayActive()) {
const arrowSprite = this.lockIndicatorSprites[this.root.currentLayer]; // Draw arrow
const path = this.computeDirectionLockPath(); const arrowSprite = this.lockIndicatorSprites[this.root.currentLayer];
for (let i = 0; i < path.length - 1; i += 1) { const path = this.computeDirectionLockPath();
const { rotation, tile } = path[i]; for (let i = 0; i < path.length - 1; i += 1) {
const worldPos = tile.toWorldSpaceCenterOfTile(); const { rotation, tile } = path[i];
const angle = Math.radians(rotation); const worldPos = tile.toWorldSpaceCenterOfTile();
const angle = Math.radians(rotation);
parameters.context.translate(worldPos.x, worldPos.y); parameters.context.translate(worldPos.x, worldPos.y);
parameters.context.rotate(angle); parameters.context.rotate(angle);
parameters.context.drawImage( parameters.context.drawImage(
arrowSprite, arrowSprite,
-6, -6,
-globalConfig.halfTileSize - -globalConfig.halfTileSize -
clamp((this.root.time.realtimeNow() * 1.5) % 1.0, 0, 1) * 1 * globalConfig.tileSize + clamp((this.root.time.realtimeNow() * 1.5) % 1.0, 0, 1) *
globalConfig.halfTileSize - 1 *
6, globalConfig.tileSize +
12, globalConfig.halfTileSize -
12 6,
); 12,
parameters.context.rotate(-angle); 12
parameters.context.translate(-worldPos.x, -worldPos.y); );
parameters.context.rotate(-angle);
parameters.context.translate(-worldPos.x, -worldPos.y);
}
} }
} }
} }

View File

@ -45,6 +45,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
*/ */
this.currentMetaBuilding = new TrackedState(this.onSelectedMetaBuildingChanged, this); this.currentMetaBuilding = new TrackedState(this.onSelectedMetaBuildingChanged, this);
/**
* The building selected before being interrupted by an overlay
* @type {MetaBuilding}
*/
this.prevMetaBuilding = null;
/** /**
* The current rotation * The current rotation
* @type {number} * @type {number}
@ -250,7 +256,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
* Aborts any dragging * Aborts any dragging
*/ */
abortDragging() { abortDragging() {
this.currentlyDragging = true; this.currentlyDragging = false;
this.currentlyDeleting = false; this.currentlyDeleting = false;
this.initialPlacementVector = null; this.initialPlacementVector = null;
this.lastDragTile = null; this.lastDragTile = null;
@ -262,6 +268,9 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
update() { update() {
// Abort placement if a dialog was shown in the meantime // Abort placement if a dialog was shown in the meantime
if (this.root.hud.hasBlockingOverlayOpen()) { if (this.root.hud.hasBlockingOverlayOpen()) {
if (this.currentMetaBuilding.get()) {
this.prevMetaBuilding = this.currentMetaBuilding.get();
}
this.abortPlacement(); this.abortPlacement();
return; return;
} }
@ -274,9 +283,14 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
// Make sure we have nothing selected while in overview mode // Make sure we have nothing selected while in overview mode
if (this.root.camera.getIsMapOverlayActive()) { if (this.root.camera.getIsMapOverlayActive()) {
if (this.currentMetaBuilding.get()) { const drawingPath = this.currentlyDragging && this.isDirectionLockActive;
if (this.currentMetaBuilding.get() && !drawingPath) {
this.prevMetaBuilding = this.currentMetaBuilding.get();
this.currentMetaBuilding.set(null); this.currentMetaBuilding.set(null);
} }
} else if (this.prevMetaBuilding && !this.currentMetaBuilding.get()) {
this.currentMetaBuilding.set(this.prevMetaBuilding);
this.prevMetaBuilding = null;
} }
} }
@ -436,8 +450,8 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
* @param {Vector} tile * @param {Vector} tile
*/ */
tryPlaceCurrentBuildingAt(tile) { tryPlaceCurrentBuildingAt(tile) {
if (this.root.camera.getIsMapOverlayActive()) { if (this.root.camera.getIsMapOverlayActive() && !this.isDirectionLockActive) {
// Dont allow placing in overview mode // Only allow placing belt and wire plans in overlay mode
return; return;
} }
@ -825,10 +839,6 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
* Mouse up handler * Mouse up handler
*/ */
onMouseUp() { onMouseUp() {
if (this.root.camera.getIsMapOverlayActive()) {
return;
}
// Check for direction lock // Check for direction lock
if (this.lastDragTile && this.currentlyDragging && this.isDirectionLockActive) { if (this.lastDragTile && this.currentlyDragging && this.isDirectionLockActive) {
this.executeDirectionLockedPlacement(); this.executeDirectionLockedPlacement();