silphius/app/react/components/dom/hotbar.jsx

58 lines
1.3 KiB
React
Raw Normal View History

2024-06-10 22:42:30 -05:00
import styles from './hotbar.module.css';
import Slot from './slot.jsx';
/**
* The hotbar. 10 slots of inventory with an active selection.
*/
2024-07-23 23:27:08 -05:00
export default function Hotbar({
active,
hotbarIsHidden,
onActivate,
slots,
}) {
2024-06-10 22:42:30 -05:00
const Slots = slots.map((slot, i) => (
2024-06-24 05:34:02 -05:00
<div
2024-06-10 22:42:30 -05:00
className={
[styles.slotWrapper, active === i && styles.active]
.filter(Boolean).join(' ')
}
key={i}
>
2024-06-24 05:34:02 -05:00
<Slot
2024-06-28 14:10:44 -05:00
icon={slot?.icon}
2024-06-28 16:37:15 -05:00
onMouseDown={(event) => {
onActivate(i)
event.stopPropagation();
}}
onMouseUp={(event) => {
event.stopPropagation();
}}
2024-06-24 08:14:32 -05:00
onDragOver={(event) => {
event.preventDefault();
}}
onDragStart={(event) => {
if (!slot) {
event.preventDefault();
}
event.dataTransfer.setData('silphius/item', i);
onActivate(i);
}}
onDrop={(event) => {
event.preventDefault();
onActivate(i);
}}
2024-06-28 14:10:44 -05:00
qty={slot?.qty}
2024-06-24 05:34:02 -05:00
/>
</div>
2024-06-10 22:42:30 -05:00
));
return (
<div
className={styles.hotbar}
2024-07-23 23:27:08 -05:00
style={hotbarIsHidden ? {top: '-50px'} : {transition: 'none'}}
2024-06-10 22:42:30 -05:00
>
2024-07-23 23:27:08 -05:00
<p className={styles.label}>{slots[active] && slots[active].label}</p>
2024-06-10 22:42:30 -05:00
{Slots}
</div>
);
}