mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-02-12 19:09:21 +00:00
Added a shape tooltip for buildings to help with no belt puzzles
This commit is contained in:
parent
631359c739
commit
ed7ba4e21f
@ -11,6 +11,7 @@ import { typeItemSingleton } from "../item_resolver";
|
|||||||
* pos: Vector,
|
* pos: Vector,
|
||||||
* direction: enumDirection,
|
* direction: enumDirection,
|
||||||
* item: BaseItem,
|
* item: BaseItem,
|
||||||
|
* lastItem: BaseItem,
|
||||||
* progress: number?,
|
* progress: number?,
|
||||||
* cachedDestSlot?: import("./item_acceptor").ItemAcceptorLocatedSlot,
|
* cachedDestSlot?: import("./item_acceptor").ItemAcceptorLocatedSlot,
|
||||||
* cachedBeltPath?: BeltPath,
|
* cachedBeltPath?: BeltPath,
|
||||||
@ -67,6 +68,7 @@ export class ItemEjectorComponent extends Component {
|
|||||||
pos: slot.pos,
|
pos: slot.pos,
|
||||||
direction: slot.direction,
|
direction: slot.direction,
|
||||||
item: null,
|
item: null,
|
||||||
|
lastItem: null,
|
||||||
progress: 0,
|
progress: 0,
|
||||||
cachedDestSlot: null,
|
cachedDestSlot: null,
|
||||||
cachedTargetEntity: null,
|
cachedTargetEntity: null,
|
||||||
@ -131,6 +133,7 @@ export class ItemEjectorComponent extends Component {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.slots[slotIndex].item = item;
|
this.slots[slotIndex].item = item;
|
||||||
|
this.slots[slotIndex].lastItem = item;
|
||||||
this.slots[slotIndex].progress = 0;
|
this.slots[slotIndex].progress = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -189,6 +189,7 @@ export class GameHUD {
|
|||||||
"colorBlindHelper",
|
"colorBlindHelper",
|
||||||
"changesDebugger",
|
"changesDebugger",
|
||||||
"minerHighlight",
|
"minerHighlight",
|
||||||
|
"shapeTooltip",
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let i = 0; i < partsOrder.length; ++i) {
|
for (let i = 0; i < partsOrder.length; ++i) {
|
||||||
|
|||||||
129
src/js/game/hud/parts/shape_tooltip.js
Normal file
129
src/js/game/hud/parts/shape_tooltip.js
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
import { DrawParameters } from "../../../core/draw_parameters";
|
||||||
|
import { createLogger } from "../../../core/logging";
|
||||||
|
import { Vector } from "../../../core/vector";
|
||||||
|
import { enumMouseButton } from "../../camera";
|
||||||
|
import { Entity } from "../../entity";
|
||||||
|
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||||
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
|
|
||||||
|
const logger = createLogger("hud/mass_selector");
|
||||||
|
|
||||||
|
export class HUDShapeTooltip extends BaseHUDPart {
|
||||||
|
createElements(parent) {}
|
||||||
|
|
||||||
|
initialize() {
|
||||||
|
/** @type {Vector} */
|
||||||
|
this.currentTile = null;
|
||||||
|
|
||||||
|
/** @type {Entity} */
|
||||||
|
this.currentEntity = null;
|
||||||
|
|
||||||
|
/** @type {Array<import("../../../core/global_registries").BaseItem>} */
|
||||||
|
this.cachedItems = null;
|
||||||
|
|
||||||
|
this.isPlacingBuilding = false;
|
||||||
|
this.active = false;
|
||||||
|
|
||||||
|
this.root.camera.movePreHandler.add(this.onMouseMove, this);
|
||||||
|
|
||||||
|
const keyActionMapper = this.root.keyMapper;
|
||||||
|
|
||||||
|
keyActionMapper.getBinding(KEYMAPPINGS.placement.pipette).add(this.clear, this);
|
||||||
|
|
||||||
|
this.root.hud.signals.pasteBlueprintRequested.add(this.clear, this);
|
||||||
|
this.root.hud.signals.selectedPlacementBuildingChanged.add(
|
||||||
|
this.onSelectedPlacementBuildingChanged,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
this.root.hud.signals.buildingsSelectedForCopy.add(this.clear, this);
|
||||||
|
this.root.signals.entityQueuedForDestroy.add(this.clear, this);
|
||||||
|
this.root.signals.editModeChanged.add(this.clear, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
// need to make sure not to show when anything else is active
|
||||||
|
|
||||||
|
this.active =
|
||||||
|
this.currentTile &&
|
||||||
|
!this.isPlacingBuilding &&
|
||||||
|
this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.showShapeTooltip).pressed &&
|
||||||
|
!this.root.hud.parts.massSelector.currentSelectionStartWorld &&
|
||||||
|
this.root.hud.parts.massSelector.selectedUids.size < 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the selected meta building was changed
|
||||||
|
* @param {import("../../../core/global_registries").MetaBuilding} metaBuilding
|
||||||
|
*/
|
||||||
|
onSelectedPlacementBuildingChanged(metaBuilding) {
|
||||||
|
if (metaBuilding) {
|
||||||
|
this.isPlacingBuilding = true;
|
||||||
|
this.clear();
|
||||||
|
} else {
|
||||||
|
this.isPlacingBuilding = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears everything
|
||||||
|
*/
|
||||||
|
clear() {
|
||||||
|
this.currentTile = null;
|
||||||
|
this.currentEntity = null;
|
||||||
|
this.cachedItems = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mouse move pre handler
|
||||||
|
* @param {Vector} pos
|
||||||
|
*/
|
||||||
|
onMouseMove(pos) {
|
||||||
|
const newTile = this.root.camera.screenToWorld(pos.copy()).toTileSpace();
|
||||||
|
|
||||||
|
if (!(this.currentTile && newTile.equals(this.currentTile))) {
|
||||||
|
this.currentTile = newTile;
|
||||||
|
|
||||||
|
const entity = this.root.map.getLayerContentXY(
|
||||||
|
this.currentTile.x,
|
||||||
|
this.currentTile.y,
|
||||||
|
this.root.currentLayer
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!(entity && entity.components.ItemProcessor && entity.components.ItemEjector)) {
|
||||||
|
this.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentEntity = entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {DrawParameters} parameters
|
||||||
|
*/
|
||||||
|
draw(parameters) {
|
||||||
|
if (this.active && this.currentEntity) {
|
||||||
|
const ejectorComp = this.currentEntity.components.ItemEjector;
|
||||||
|
const staticComp = this.currentEntity.components.StaticMapEntity;
|
||||||
|
|
||||||
|
for (let i = 0; i < ejectorComp.slots.length; ++i) {
|
||||||
|
const slot = ejectorComp.slots[i];
|
||||||
|
|
||||||
|
if (!slot.lastItem || slot.lastItem._type != "shape") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {Vector} */
|
||||||
|
let drawPos = null;
|
||||||
|
if (ejectorComp.slots.length == 1) {
|
||||||
|
drawPos = staticComp.getTileSpaceBounds().getCenter().toWorldSpace();
|
||||||
|
} else {
|
||||||
|
drawPos = staticComp.localTileToWorld(slot.pos).toWorldSpaceCenterOfTile();
|
||||||
|
}
|
||||||
|
|
||||||
|
slot.lastItem.drawItemCenteredClipped(drawPos.x, drawPos.y, parameters, 25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -32,6 +32,8 @@ export const KEYMAPPINGS = {
|
|||||||
toggleFPSInfo: { keyCode: 115 }, // F4
|
toggleFPSInfo: { keyCode: 115 }, // F4
|
||||||
|
|
||||||
switchLayers: { keyCode: key("E") },
|
switchLayers: { keyCode: key("E") },
|
||||||
|
|
||||||
|
showShapeTooltip: { keyCode: 18 }, // ALT
|
||||||
},
|
},
|
||||||
|
|
||||||
navigation: {
|
navigation: {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import { enumGameModeTypes, GameMode } from "../game_mode";
|
|||||||
import { HUDPuzzleBackToMenu } from "../hud/parts/puzzle_back_to_menu";
|
import { HUDPuzzleBackToMenu } from "../hud/parts/puzzle_back_to_menu";
|
||||||
import { HUDPuzzleDLCLogo } from "../hud/parts/puzzle_dlc_logo";
|
import { HUDPuzzleDLCLogo } from "../hud/parts/puzzle_dlc_logo";
|
||||||
import { HUDMassSelector } from "../hud/parts/mass_selector";
|
import { HUDMassSelector } from "../hud/parts/mass_selector";
|
||||||
|
import { HUDShapeTooltip } from "../hud/parts/shape_tooltip";
|
||||||
|
|
||||||
export class PuzzleGameMode extends GameMode {
|
export class PuzzleGameMode extends GameMode {
|
||||||
static getType() {
|
static getType() {
|
||||||
@ -32,6 +33,7 @@ export class PuzzleGameMode extends GameMode {
|
|||||||
puzzleBackToMenu: HUDPuzzleBackToMenu,
|
puzzleBackToMenu: HUDPuzzleBackToMenu,
|
||||||
puzzleDlcLogo: HUDPuzzleDLCLogo,
|
puzzleDlcLogo: HUDPuzzleDLCLogo,
|
||||||
massSelector: HUDMassSelector,
|
massSelector: HUDMassSelector,
|
||||||
|
shapeTooltip: HUDShapeTooltip,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.zoneWidth = data.zoneWidth || 8;
|
this.zoneWidth = data.zoneWidth || 8;
|
||||||
|
|||||||
@ -1363,6 +1363,8 @@ keybindings:
|
|||||||
placeMultiple: Stay in placement mode
|
placeMultiple: Stay in placement mode
|
||||||
placeInverse: Invert automatic belt orientation
|
placeInverse: Invert automatic belt orientation
|
||||||
|
|
||||||
|
showShapeTooltip: Show shape output tooltip
|
||||||
|
|
||||||
about:
|
about:
|
||||||
title: About this Game
|
title: About this Game
|
||||||
body: >-
|
body: >-
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user