import "./hotbar-menu.scss"; import "./hotbar.commands"; import React 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 { HotbarStore } from "../../../common/hotbar-store"; import { 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 hotbarItems() { const hotbar = HotbarStore.getInstance().getActive(); if (!hotbar) { return []; } return hotbar.items.map((item) => catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item.entity.uid)).filter(Boolean); } previous() { HotbarStore.getInstance().switchToPrevious(); } next() { HotbarStore.getInstance().switchToNext(); } openSelector() { CommandOverlay.open(); } render() { const { className } = this.props; const hotbarStore = HotbarStore.getInstance(); const hotbar = hotbarStore.getActive(); const hotbarIndex = hotbarStore.activeHotbarIndex + 1; return (
{this.hotbarItems.map((entity, index) => { return ( entity.onRun(catalogEntityRunContext)} /> ); })}
this.previous()} />
this.openSelector()} /> {hotbar.name}
this.next()} />
); } }