2019-04-21 16:31:43 -05:00
|
|
|
// 3rd party.
|
2019-04-22 00:45:09 -05:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import React, {useEffect, useState} from 'react';
|
2019-04-21 16:31:43 -05:00
|
|
|
// 2nd party.
|
|
|
|
import {compose} from '@avocado/core';
|
|
|
|
import contempo from 'contempo';
|
2019-04-21 19:27:58 -05:00
|
|
|
// 1st party.
|
|
|
|
import ItemSlot from './item-slot';
|
2019-04-21 16:31:43 -05:00
|
|
|
|
|
|
|
const decorate = compose(
|
|
|
|
contempo(`
|
|
|
|
.hotbar {
|
|
|
|
position: absolute;
|
|
|
|
width: 200px;
|
|
|
|
height: 20px;
|
|
|
|
left: 50%;
|
|
|
|
top: 2px;
|
|
|
|
}
|
|
|
|
.hotbar-inner {
|
|
|
|
transform: translateX(-50%);
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
.hotbar-key {
|
|
|
|
color: white;
|
|
|
|
text-shadow: 0.25px 0.25px 0 black;
|
|
|
|
font-family: monospace;
|
|
|
|
position: absolute;
|
|
|
|
top: -0.5px;
|
|
|
|
left: 0.5px;
|
|
|
|
font-size: 3px;
|
|
|
|
line-height: 4px;
|
2019-04-22 00:45:09 -05:00
|
|
|
}
|
|
|
|
.hotbar .item-slot.active {
|
|
|
|
box-shadow:
|
|
|
|
-.5px -.5px 0 rgba(0, 0, 0, 1),
|
|
|
|
.5px .5px 0 rgba(0, 0, 0, 1),
|
|
|
|
-.5px .5px 0 rgba(0, 0, 0, 1),
|
|
|
|
.5px -.5px 0 rgba(0, 0, 0, 1),
|
|
|
|
inset -.5px -.5px 0 rgba(255, 255, 0, 1),
|
|
|
|
inset .5px .5px 0 rgba(255, 255, 0, 1),
|
|
|
|
inset -.5px .5px 0 rgba(255, 255, 0, 1),
|
|
|
|
inset .5px -.5px 0 rgba(255, 255, 0, 1)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
.hotbar .item-slot.active:hover {
|
|
|
|
box-shadow:
|
|
|
|
-.5px -.5px 0 rgba(0, 0, 0, 1),
|
|
|
|
.5px .5px 0 rgba(0, 0, 0, 1),
|
|
|
|
-.5px .5px 0 rgba(0, 0, 0, 1),
|
|
|
|
.5px -.5px 0 rgba(0, 0, 0, 1),
|
|
|
|
-.5px -.5px 3px rgba(255, 255, 255, 1),
|
|
|
|
.5px .5px 3px rgba(255, 255, 255, 1),
|
|
|
|
-.5px .5px 3px rgba(255, 255, 255, 1),
|
|
|
|
.5px -.5px 3px rgba(255, 255, 255, 1),
|
|
|
|
inset -.5px -.5px 0 rgba(255, 255, 0, 1),
|
|
|
|
inset .5px .5px 0 rgba(255, 255, 0, 1),
|
|
|
|
inset -.5px .5px 0 rgba(255, 255, 0, 1),
|
|
|
|
inset .5px -.5px 0 rgba(255, 255, 0, 1)
|
|
|
|
;
|
|
|
|
transition: none;
|
2019-04-21 16:31:43 -05:00
|
|
|
}
|
|
|
|
`),
|
|
|
|
);
|
|
|
|
|
|
|
|
const HotbarComponent = ({damageProton}) => {
|
2019-04-22 00:45:09 -05:00
|
|
|
const [active, setActive] = useState(0);
|
|
|
|
const hotkeyForSlot = (index) => {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
const slots = [];
|
|
|
|
for (let i = 0; i < 10; ++i) {
|
|
|
|
const slot = <ItemSlot
|
|
|
|
className={classnames(
|
|
|
|
active === i ? 'active' : '',
|
|
|
|
)}
|
|
|
|
key={i}
|
|
|
|
onClick={(event) => {
|
|
|
|
setActive(i);
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
return false;
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="hotbar-key">{hotkeyForSlot(i)}</div>
|
|
|
|
</ItemSlot>;
|
|
|
|
slots.push(slot);
|
|
|
|
}
|
|
|
|
return <div
|
|
|
|
className="hotbar unselectable"
|
|
|
|
onWheel={(event) => {
|
|
|
|
if (event.deltaY > 0) {
|
|
|
|
setActive((active + 1) % 10);
|
|
|
|
}
|
|
|
|
else if (event.deltaY < 0) {
|
|
|
|
setActive((active + 9) % 10);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2019-04-21 16:31:43 -05:00
|
|
|
<div className="hotbar-inner">
|
2019-04-22 00:45:09 -05:00
|
|
|
{slots}
|
2019-04-21 16:31:43 -05:00
|
|
|
</div>
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default decorate(HotbarComponent);
|