import { BaseHUDPart } from "../base_hud_part"; import { makeDiv } from "../../../core/utils"; import { getStringForKeyCode } from "../../key_action_mapper"; import { TrackedState } from "../../../core/tracked_state"; export class HUDKeybindingOverlay extends BaseHUDPart { initialize() { this.shiftDownTracker = new TrackedState(this.onShiftStateChanged, this); this.root.hud.signals.selectedPlacementBuildingChanged.add( this.onSelectedBuildingForPlacementChanged, this ); } onShiftStateChanged(shiftDown) { this.element.classList.toggle("shiftDown", shiftDown); } createElements(parent) { const mapper = this.root.gameState.keyActionMapper; const getKeycode = id => { return getStringForKeyCode(mapper.getBinding(id).keyCode); }; this.element = makeDiv( parent, "ingame_HUD_KeybindingOverlay", [], `
${getKeycode("center_map")}
${getKeycode("map_move_up")} ${getKeycode("map_move_left")} ${getKeycode("map_move_down")} ${getKeycode("map_move_right")}
ALT+
${getKeycode("building_abort_placement")}
${getKeycode("rotate_while_placing")}
⇧ SHIFT
ALT
` ); } onSelectedBuildingForPlacementChanged(selectedMetaBuilding) { this.element.classList.toggle("placementActive", !!selectedMetaBuilding); } update() { this.shiftDownTracker.set(this.root.app.inputMgr.shiftIsDown); } }