import "./hotbar-menu.scss"; import "./hotbar.commands"; import React, { ReactNode, useState } from "react"; import { observer } from "mobx-react"; import { HotbarIcon } from "./hotbar-icon"; import { cssNames, IClassName } from "../../utils"; import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import { HotbarItem, HotbarStore } from "../../../common/hotbar-store"; import { CatalogEntity, catalogEntityRunContext } from "../../api/catalog-entity"; import { Icon } from "../icon"; import { Badge } from "../badge"; import { CommandOverlay } from "../command-palette"; import { HotbarSwitchCommand } from "./hotbar-switch-command"; import { Tooltip, TooltipPosition } from "../tooltip"; interface Props { className?: IClassName; } @observer export class HotbarMenu extends React.Component { get hotbar() { return HotbarStore.getInstance().getActive(); } isActive(item: CatalogEntity) { return catalogEntityRegistry.activeEntity?.metadata?.uid == item.getId(); } getEntity(item: HotbarItem) { const hotbar = HotbarStore.getInstance().getActive(); if (!hotbar) { return null; } return item ? catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item.entity.uid) : null; } previous() { HotbarStore.getInstance().switchToPrevious(); } next() { HotbarStore.getInstance().switchToNext(); } openSelector() { CommandOverlay.open(); } renderGrid() { if (!this.hotbar.items.length) return; return this.hotbar.items.map((item, index) => { const entity = this.getEntity(item); return ( {entity && ( entity.onRun(catalogEntityRunContext)} /> )} ); }); } render() { const { className } = this.props; const hotbarStore = HotbarStore.getInstance(); const hotbar = hotbarStore.getActive(); const activeIndexDisplay = hotbarStore.activeHotbarIndex + 1; return (
{this.renderGrid()}
this.previous()} />
this.openSelector()} /> {hotbar.name}
this.next()} />
); } } interface HotbarCellProps { children?: ReactNode; index: number; } function HotbarCell(props: HotbarCellProps) { const [animating, setAnimating] = useState(false); const onAnimationEnd = () => { setAnimating(false); }; const onClick = () => { setAnimating(true); }; return (
{props.children}
); }