mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Improve information when hovering wires
This commit is contained in:
@@ -78,13 +78,13 @@ export class HUDLayerPreview extends BaseHUDPart {
|
||||
|
||||
const content = this.root.map.getLayerContentXY(tileX, tileY, enumLayer.wires);
|
||||
if (content) {
|
||||
MapChunkView.drawSingleWiresOverviewTile(
|
||||
this.context,
|
||||
dx * globalConfig.tileSize,
|
||||
dy * globalConfig.tileSize,
|
||||
content,
|
||||
globalConfig.tileSize
|
||||
);
|
||||
MapChunkView.drawSingleWiresOverviewTile({
|
||||
context: this.context,
|
||||
x: dx * globalConfig.tileSize,
|
||||
y: dy * globalConfig.tileSize,
|
||||
entity: content,
|
||||
tileSizePixels: globalConfig.tileSize,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { BaseHUDPart } from "../base_hud_part";
|
||||
import { enumLayer } from "../../root";
|
||||
import { globalConfig } from "../../../core/config";
|
||||
import { MapChunkView } from "../../map_chunk_view";
|
||||
import { enumLayer } from "../../root";
|
||||
import { WireNetwork } from "../../systems/wire";
|
||||
import { THEME } from "../../theme";
|
||||
import { BaseHUDPart } from "../base_hud_part";
|
||||
import { Loader } from "../../../core/loader";
|
||||
|
||||
export class HUDWireInfo extends BaseHUDPart {
|
||||
initialize() {}
|
||||
initialize() {
|
||||
this.spriteEmpty = Loader.getSprite("sprites/wires/network_empty.png");
|
||||
this.spriteConflict = Loader.getSprite("sprites/wires/network_conflict.png");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -21,38 +28,90 @@ export class HUDWireInfo extends BaseHUDPart {
|
||||
return;
|
||||
}
|
||||
|
||||
const tile = this.root.camera.screenToWorld(mousePos).toTileSpace();
|
||||
const worldPos = this.root.camera.screenToWorld(mousePos);
|
||||
const tile = worldPos.toTileSpace();
|
||||
const entity = this.root.map.getLayerContentXY(tile.x, tile.y, enumLayer.wires);
|
||||
|
||||
if (entity) {
|
||||
const wireComp = entity.components.Wire;
|
||||
if (wireComp) {
|
||||
const screenTile = this.root.camera.worldToScreen(tile.toWorldSpace());
|
||||
parameters.context.fillStyle = "rgba(0, 0, 0, 0.1)";
|
||||
parameters.context.fillRect(
|
||||
screenTile.x,
|
||||
screenTile.y,
|
||||
globalConfig.tileSize * this.root.camera.zoomLevel,
|
||||
globalConfig.tileSize * this.root.camera.zoomLevel
|
||||
);
|
||||
if (!entity) {
|
||||
// No entity
|
||||
return;
|
||||
}
|
||||
|
||||
parameters.context.font = "25px GameFont";
|
||||
const network = wireComp.linkedNetwork;
|
||||
if (!network) {
|
||||
parameters.context.fillStyle = "#333";
|
||||
parameters.context.fillText("empty", mousePos.x, mousePos.y);
|
||||
} else {
|
||||
if (network.valueConflict) {
|
||||
parameters.context.fillStyle = "#a10";
|
||||
parameters.context.fillText("conflict", mousePos.x, mousePos.y);
|
||||
} else if (!network.currentValue) {
|
||||
parameters.context.fillStyle = "#333";
|
||||
parameters.context.fillText("empty", mousePos.x, mousePos.y);
|
||||
} else {
|
||||
network.currentValue.draw(mousePos.x + 20, mousePos.y, parameters, 40);
|
||||
}
|
||||
}
|
||||
if (
|
||||
!this.root.camera.getIsMapOverlayActive() &&
|
||||
!this.root.logic.getIsEntityIntersectedWithMatrix(entity, worldPos)
|
||||
) {
|
||||
// Detailed intersection check
|
||||
return;
|
||||
}
|
||||
|
||||
const networks = this.root.logic.getEntityWireNetworks(entity, tile);
|
||||
if (networks === null) {
|
||||
// This entity will never be able to be connected
|
||||
return;
|
||||
}
|
||||
|
||||
if (networks.length === 0) {
|
||||
// No network at all
|
||||
parameters.context.fillStyle = "#333";
|
||||
this.spriteEmpty.draw(parameters.context, mousePos.x + 10, mousePos.y - 10, 40, 40);
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < networks.length; ++i) {
|
||||
const network = networks[i];
|
||||
this.drawHighlightedNetwork(parameters, network);
|
||||
}
|
||||
|
||||
if (networks.length === 1) {
|
||||
const network = networks[0];
|
||||
|
||||
if (network.valueConflict) {
|
||||
this.spriteConflict.draw(parameters.context, mousePos.x + 10, mousePos.y - 10, 40, 40);
|
||||
} else if (!network.currentValue) {
|
||||
this.spriteEmpty.draw(parameters.context, mousePos.x + 10, mousePos.y - 10, 40, 40);
|
||||
} else {
|
||||
network.currentValue.draw(mousePos.x + 20, mousePos.y, parameters, 40);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {import("../../../core/draw_utils").DrawParameters} parameters
|
||||
* @param {WireNetwork} network
|
||||
*/
|
||||
drawHighlightedNetwork(parameters, network) {
|
||||
parameters.context.globalAlpha = 0.5;
|
||||
|
||||
for (let i = 0; i < network.wires.length; ++i) {
|
||||
const wire = network.wires[i];
|
||||
const staticComp = wire.components.StaticMapEntity;
|
||||
const screenTile = this.root.camera.worldToScreen(staticComp.origin.toWorldSpace());
|
||||
MapChunkView.drawSingleWiresOverviewTile({
|
||||
context: parameters.context,
|
||||
x: screenTile.x,
|
||||
y: screenTile.y,
|
||||
entity: wire,
|
||||
tileSizePixels: globalConfig.tileSize * this.root.camera.zoomLevel,
|
||||
overrideColor: THEME.map.wires.highlightColor,
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < network.tunnels.length; ++i) {
|
||||
const tunnel = network.tunnels[i];
|
||||
const staticComp = tunnel.components.StaticMapEntity;
|
||||
const screenTile = this.root.camera.worldToScreen(staticComp.origin.toWorldSpace());
|
||||
MapChunkView.drawSingleWiresOverviewTile({
|
||||
context: parameters.context,
|
||||
x: screenTile.x,
|
||||
y: screenTile.y,
|
||||
entity: tunnel,
|
||||
tileSizePixels: globalConfig.tileSize * this.root.camera.zoomLevel,
|
||||
overrideColor: THEME.map.wires.highlightColor,
|
||||
});
|
||||
}
|
||||
parameters.context.globalAlpha = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user