@rpg-engine/long-bow 0.1.77 → 0.1.792
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +181 -181
- package/dist/components/store/UI.store.d.ts +3 -0
- package/dist/long-bow.cjs.development.js +14 -5
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +14 -5
- package/dist/long-bow.esm.js.map +1 -1
- package/dist/mocks/skills.mocks.d.ts +6 -0
- package/package.json +96 -96
- package/src/components/Abstractions/SlotsContainer.tsx +42 -42
- package/src/components/Button.tsx +29 -29
- package/src/components/Chat/Chat.tsx +193 -193
- package/src/components/CheckButton.tsx +65 -65
- package/src/components/DraggableContainer.tsx +150 -150
- package/src/components/Dropdown.tsx +57 -57
- package/src/components/Equipment/EquipmentSet.tsx +180 -179
- package/src/components/Input.tsx +11 -11
- package/src/components/Item/Cards/ItemCard.tsx +36 -36
- package/src/components/Item/Inventory/ItemContainer.tsx +113 -113
- package/src/components/Item/Inventory/ItemSlot.tsx +158 -158
- package/src/components/Item/Inventory/itemContainerHelper.ts +81 -81
- package/src/components/ListMenu.tsx +65 -65
- package/src/components/Multitab/Tab.tsx +57 -57
- package/src/components/Multitab/TabBody.tsx +13 -13
- package/src/components/Multitab/TabsContainer.tsx +97 -97
- package/src/components/NPCDialog/NPCDialog.tsx +145 -145
- package/src/components/NPCDialog/NPCDialogText.tsx +53 -53
- package/src/components/NPCDialog/QuestionDialog/QuestionDialog.tsx +242 -242
- package/src/components/ProgressBar.tsx +91 -91
- package/src/components/RPGUIContainer.tsx +47 -47
- package/src/components/RPGUIRoot.tsx +14 -14
- package/src/components/RadioButton.tsx +53 -53
- package/src/components/RangeSlider.tsx +68 -68
- package/src/components/ScrollList.tsx +77 -77
- package/src/components/SimpleProgressBar.tsx +62 -62
- package/src/components/SkillProgressBar.tsx +124 -124
- package/src/components/SkillsContainer.tsx +235 -235
- package/src/components/TextArea.tsx +11 -11
- package/src/components/Truncate.tsx +25 -25
- package/src/components/shared/Column.tsx +16 -16
- package/src/components/shared/SpriteFromAtlas.tsx +99 -99
- package/src/components/shared/SpriteIcon.tsx +67 -67
- package/src/components/store/UI.store.ts +205 -192
- package/src/components/typography/DynamicText.tsx +49 -49
- package/src/constants/uiColors.ts +10 -10
- package/src/hooks/useEventListener.ts +21 -21
- package/src/hooks/useOutsideAlerter.ts +25 -25
- package/src/index.tsx +25 -25
- package/src/libs/StringHelpers.ts +3 -3
- package/src/mocks/atlas/icons/icons.json +303 -303
- package/src/mocks/atlas/items/items.json +5195 -5195
- package/src/mocks/equipmentSet.mocks.ts +347 -347
- package/src/mocks/itemContainer.mocks.ts +249 -249
- package/src/mocks/skills.mocks.ts +122 -116
- package/src/types/eventTypes.ts +4 -4
- package/src/types/index.d.ts +2 -2
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
import { IItem, IItemContainer, ItemSocketEvents } from '@rpg-engine/shared';
|
|
2
|
-
import { observer } from 'mobx-react';
|
|
3
|
-
import React, { useState } from 'react';
|
|
4
|
-
import styled from 'styled-components';
|
|
5
|
-
import { IPosition } from '../../../types/eventTypes';
|
|
6
|
-
import { SlotsContainer } from '../../Abstractions/SlotsContainer';
|
|
7
|
-
import { ListMenu } from '../../ListMenu';
|
|
8
|
-
import { uiStore } from '../../store/UI.store';
|
|
9
|
-
import { ItemCard } from '../Cards/ItemCard';
|
|
10
|
-
import { ItemSlot, SlotContainerType } from './ItemSlot';
|
|
11
|
-
|
|
12
|
-
export interface IItemContainerProps {
|
|
13
|
-
itemContainer: IItemContainer;
|
|
14
|
-
onClose?: () => void;
|
|
15
|
-
onMouseOver?: (e: any, slotIndex: number, item: IItem | null) => void;
|
|
16
|
-
onActionSelected?: (payload: any) => void;
|
|
17
|
-
initialPosition?: { x: number; y: number };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const ItemContainer: React.FC<IItemContainerProps> = observer(
|
|
21
|
-
({
|
|
22
|
-
itemContainer,
|
|
23
|
-
onClose,
|
|
24
|
-
onMouseOver,
|
|
25
|
-
onActionSelected,
|
|
26
|
-
initialPosition = { x: 0, y: 0 },
|
|
27
|
-
}) => {
|
|
28
|
-
// we use this draggable position to offset the menu position, after the container is dragged (otherwise, it bugs!)
|
|
29
|
-
const [draggablePosition, setDraggablePosition] = useState<IPosition>(
|
|
30
|
-
initialPosition
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
const handleOnMouseHover = (
|
|
34
|
-
event: any,
|
|
35
|
-
slotIndex: number,
|
|
36
|
-
item: IItem | null,
|
|
37
|
-
x: number,
|
|
38
|
-
y: number
|
|
39
|
-
) => {
|
|
40
|
-
uiStore.handleOnMouseHover(event, slotIndex, item, x, y, onMouseOver);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const onSelected = (selectedActionId: ItemSocketEvents | string): void => {
|
|
44
|
-
uiStore.onSelected(selectedActionId, onActionSelected);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const onRenderSlots = () => {
|
|
48
|
-
const slots = [];
|
|
49
|
-
|
|
50
|
-
for (let i = 0; i < itemContainer.slotQty; i++) {
|
|
51
|
-
slots.push(
|
|
52
|
-
<ItemSlot
|
|
53
|
-
key={i}
|
|
54
|
-
slotIndex={i}
|
|
55
|
-
item={itemContainer.slots?.[i] || null}
|
|
56
|
-
slotContainerType={SlotContainerType.INVENTORY}
|
|
57
|
-
onMouseOver={handleOnMouseHover}
|
|
58
|
-
onClick={uiStore.handleOnItemClick}
|
|
59
|
-
onMouseOut={() => {
|
|
60
|
-
uiStore.clearItemHoverDetail();
|
|
61
|
-
}}
|
|
62
|
-
onCancelContextMenu={() => {
|
|
63
|
-
uiStore.clearContextMenu();
|
|
64
|
-
}}
|
|
65
|
-
/>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
return slots;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<SlotsContainer
|
|
73
|
-
title={itemContainer.name || 'Container'}
|
|
74
|
-
onPositionChange={({ x, y }) => {
|
|
75
|
-
setDraggablePosition({ x, y });
|
|
76
|
-
}}
|
|
77
|
-
onOutsideClick={() => {
|
|
78
|
-
uiStore.clearContextMenu();
|
|
79
|
-
uiStore.clearItemHoverDetail();
|
|
80
|
-
}}
|
|
81
|
-
onClose={onClose}
|
|
82
|
-
>
|
|
83
|
-
<ItemsContainer className="item-container-body">
|
|
84
|
-
{onRenderSlots()}
|
|
85
|
-
</ItemsContainer>
|
|
86
|
-
|
|
87
|
-
{uiStore.contextMenu?.visible ? (
|
|
88
|
-
<ListMenu
|
|
89
|
-
x={uiStore.contextMenu.posX - draggablePosition.x}
|
|
90
|
-
y={uiStore.contextMenu.posY - draggablePosition.y}
|
|
91
|
-
options={uiStore.contextMenu.contextActions}
|
|
92
|
-
onSelected={onSelected}
|
|
93
|
-
/>
|
|
94
|
-
) : null}
|
|
95
|
-
|
|
96
|
-
{uiStore.onHoverDetail?.visible ? (
|
|
97
|
-
<ItemCard
|
|
98
|
-
item={uiStore.onHoverDetail.item}
|
|
99
|
-
x={uiStore.onHoverDetail.posX - draggablePosition.x}
|
|
100
|
-
y={uiStore.onHoverDetail.posY - draggablePosition.y}
|
|
101
|
-
/>
|
|
102
|
-
) : null}
|
|
103
|
-
</SlotsContainer>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const ItemsContainer = styled.div`
|
|
109
|
-
max-width: 280px;
|
|
110
|
-
display: flex;
|
|
111
|
-
justify-content: center;
|
|
112
|
-
flex-wrap: wrap;
|
|
113
|
-
`;
|
|
1
|
+
import { IItem, IItemContainer, ItemSocketEvents } from '@rpg-engine/shared';
|
|
2
|
+
import { observer } from 'mobx-react';
|
|
3
|
+
import React, { useState } from 'react';
|
|
4
|
+
import styled from 'styled-components';
|
|
5
|
+
import { IPosition } from '../../../types/eventTypes';
|
|
6
|
+
import { SlotsContainer } from '../../Abstractions/SlotsContainer';
|
|
7
|
+
import { ListMenu } from '../../ListMenu';
|
|
8
|
+
import { uiStore } from '../../store/UI.store';
|
|
9
|
+
import { ItemCard } from '../Cards/ItemCard';
|
|
10
|
+
import { ItemSlot, SlotContainerType } from './ItemSlot';
|
|
11
|
+
|
|
12
|
+
export interface IItemContainerProps {
|
|
13
|
+
itemContainer: IItemContainer;
|
|
14
|
+
onClose?: () => void;
|
|
15
|
+
onMouseOver?: (e: any, slotIndex: number, item: IItem | null) => void;
|
|
16
|
+
onActionSelected?: (payload: any) => void;
|
|
17
|
+
initialPosition?: { x: number; y: number };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ItemContainer: React.FC<IItemContainerProps> = observer(
|
|
21
|
+
({
|
|
22
|
+
itemContainer,
|
|
23
|
+
onClose,
|
|
24
|
+
onMouseOver,
|
|
25
|
+
onActionSelected,
|
|
26
|
+
initialPosition = { x: 0, y: 0 },
|
|
27
|
+
}) => {
|
|
28
|
+
// we use this draggable position to offset the menu position, after the container is dragged (otherwise, it bugs!)
|
|
29
|
+
const [draggablePosition, setDraggablePosition] = useState<IPosition>(
|
|
30
|
+
initialPosition
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const handleOnMouseHover = (
|
|
34
|
+
event: any,
|
|
35
|
+
slotIndex: number,
|
|
36
|
+
item: IItem | null,
|
|
37
|
+
x: number,
|
|
38
|
+
y: number
|
|
39
|
+
) => {
|
|
40
|
+
uiStore.handleOnMouseHover(event, slotIndex, item, x, y, onMouseOver);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const onSelected = (selectedActionId: ItemSocketEvents | string): void => {
|
|
44
|
+
uiStore.onSelected(selectedActionId, onActionSelected);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const onRenderSlots = () => {
|
|
48
|
+
const slots = [];
|
|
49
|
+
|
|
50
|
+
for (let i = 0; i < itemContainer.slotQty; i++) {
|
|
51
|
+
slots.push(
|
|
52
|
+
<ItemSlot
|
|
53
|
+
key={i}
|
|
54
|
+
slotIndex={i}
|
|
55
|
+
item={itemContainer.slots?.[i] || null}
|
|
56
|
+
slotContainerType={SlotContainerType.INVENTORY}
|
|
57
|
+
onMouseOver={handleOnMouseHover}
|
|
58
|
+
onClick={uiStore.handleOnItemClick}
|
|
59
|
+
onMouseOut={() => {
|
|
60
|
+
uiStore.clearItemHoverDetail();
|
|
61
|
+
}}
|
|
62
|
+
onCancelContextMenu={() => {
|
|
63
|
+
uiStore.clearContextMenu();
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return slots;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<SlotsContainer
|
|
73
|
+
title={itemContainer.name || 'Container'}
|
|
74
|
+
onPositionChange={({ x, y }) => {
|
|
75
|
+
setDraggablePosition({ x, y });
|
|
76
|
+
}}
|
|
77
|
+
onOutsideClick={() => {
|
|
78
|
+
uiStore.clearContextMenu();
|
|
79
|
+
uiStore.clearItemHoverDetail();
|
|
80
|
+
}}
|
|
81
|
+
onClose={onClose}
|
|
82
|
+
>
|
|
83
|
+
<ItemsContainer className="item-container-body">
|
|
84
|
+
{onRenderSlots()}
|
|
85
|
+
</ItemsContainer>
|
|
86
|
+
|
|
87
|
+
{uiStore.contextMenu?.visible ? (
|
|
88
|
+
<ListMenu
|
|
89
|
+
x={uiStore.contextMenu.posX - draggablePosition.x}
|
|
90
|
+
y={uiStore.contextMenu.posY - draggablePosition.y}
|
|
91
|
+
options={uiStore.contextMenu.contextActions}
|
|
92
|
+
onSelected={onSelected}
|
|
93
|
+
/>
|
|
94
|
+
) : null}
|
|
95
|
+
|
|
96
|
+
{uiStore.onHoverDetail?.visible ? (
|
|
97
|
+
<ItemCard
|
|
98
|
+
item={uiStore.onHoverDetail.item}
|
|
99
|
+
x={uiStore.onHoverDetail.posX - draggablePosition.x}
|
|
100
|
+
y={uiStore.onHoverDetail.posY - draggablePosition.y}
|
|
101
|
+
/>
|
|
102
|
+
) : null}
|
|
103
|
+
</SlotsContainer>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const ItemsContainer = styled.div`
|
|
109
|
+
max-width: 280px;
|
|
110
|
+
display: flex;
|
|
111
|
+
justify-content: center;
|
|
112
|
+
flex-wrap: wrap;
|
|
113
|
+
`;
|
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
import { IItem, IItemContainer, ItemSlotType } from '@rpg-engine/shared';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import styled from 'styled-components';
|
|
4
|
-
import atlasJSON from '../../../mocks/atlas/items/items.json';
|
|
5
|
-
import atlasIMG from '../../../mocks/atlas/items/items.png';
|
|
6
|
-
import { SpriteFromAtlas } from '../../shared/SpriteFromAtlas';
|
|
7
|
-
|
|
8
|
-
export enum SlotContainerType {
|
|
9
|
-
INVENTORY = 'Inventory',
|
|
10
|
-
EQUIPMENT_SET = 'EquipmentSet',
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const EquipmentSlotSpriteByType: any = {
|
|
14
|
-
Neck: 'accessories/corruption-necklace.png',
|
|
15
|
-
LeftHand: 'swords/broad-sword.png',
|
|
16
|
-
Ring: 'rings/iron-ring.png',
|
|
17
|
-
Head: 'helmets/viking-helmet.png',
|
|
18
|
-
Torso: 'armors/iron-armor.png',
|
|
19
|
-
Legs: 'legs/studded-legs.png',
|
|
20
|
-
Feet: 'boots/iron-boots.png',
|
|
21
|
-
Inventory: 'containers/bag.png',
|
|
22
|
-
RightHand: 'shields/plate-shield.png',
|
|
23
|
-
Accessory: 'gloves/plate-gloves.png',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
interface IProps {
|
|
27
|
-
slotIndex: number;
|
|
28
|
-
item: IItem | null;
|
|
29
|
-
itemContainer?: IItemContainer | null;
|
|
30
|
-
slotContainerType: SlotContainerType | null;
|
|
31
|
-
slotSpriteMask?: ItemSlotType | null;
|
|
32
|
-
onMouseOver: (
|
|
33
|
-
event: any,
|
|
34
|
-
slotIndex: number,
|
|
35
|
-
item: IItem | null,
|
|
36
|
-
x: number,
|
|
37
|
-
y: number
|
|
38
|
-
) => void;
|
|
39
|
-
onMouseOut: () => void;
|
|
40
|
-
onClick: (
|
|
41
|
-
item: IItem,
|
|
42
|
-
posX: number,
|
|
43
|
-
posY: number,
|
|
44
|
-
slotContainerType: SlotContainerType | null
|
|
45
|
-
) => void;
|
|
46
|
-
onCancelContextMenu: () => void;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const ItemSlot: React.FC<IProps> = ({
|
|
50
|
-
slotIndex,
|
|
51
|
-
item,
|
|
52
|
-
slotContainerType,
|
|
53
|
-
slotSpriteMask,
|
|
54
|
-
onMouseOver,
|
|
55
|
-
onMouseOut,
|
|
56
|
-
onClick,
|
|
57
|
-
onCancelContextMenu,
|
|
58
|
-
}) => {
|
|
59
|
-
const getLeftPositionValue = (quantity: number) => {
|
|
60
|
-
if (quantity > 0 && quantity < 10) return '2.5rem';
|
|
61
|
-
else if (quantity > 9 && quantity < 100) return '2.0rem';
|
|
62
|
-
else if (quantity > 99) return '1rem';
|
|
63
|
-
return '2.5rem';
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const renderItem = (itemToRender: IItem | null) => {
|
|
67
|
-
const element = [];
|
|
68
|
-
if (itemToRender?.texturePath) {
|
|
69
|
-
element.push(
|
|
70
|
-
<SpriteFromAtlas
|
|
71
|
-
atlasIMG={atlasIMG}
|
|
72
|
-
atlasJSON={atlasJSON}
|
|
73
|
-
spriteKey={itemToRender.texturePath}
|
|
74
|
-
imgScale={3}
|
|
75
|
-
/>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
if (itemToRender?.isStackable && itemToRender?.stackQty) {
|
|
79
|
-
element.push(
|
|
80
|
-
<ItemQty left={getLeftPositionValue(itemToRender.stackQty)}>
|
|
81
|
-
{' '}
|
|
82
|
-
{itemToRender.stackQty}{' '}
|
|
83
|
-
</ItemQty>
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
return element;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const renderEquipment = (itemToRender: IItem | null) => {
|
|
90
|
-
if (
|
|
91
|
-
itemToRender?.texturePath &&
|
|
92
|
-
itemToRender.allowedEquipSlotType?.includes(slotSpriteMask!)
|
|
93
|
-
) {
|
|
94
|
-
return (
|
|
95
|
-
<SpriteFromAtlas
|
|
96
|
-
atlasIMG={atlasIMG}
|
|
97
|
-
atlasJSON={atlasJSON}
|
|
98
|
-
spriteKey={itemToRender.texturePath}
|
|
99
|
-
imgScale={3}
|
|
100
|
-
/>
|
|
101
|
-
);
|
|
102
|
-
} else {
|
|
103
|
-
return (
|
|
104
|
-
<SpriteFromAtlas
|
|
105
|
-
atlasIMG={atlasIMG}
|
|
106
|
-
atlasJSON={atlasJSON}
|
|
107
|
-
spriteKey={EquipmentSlotSpriteByType[slotSpriteMask!]}
|
|
108
|
-
imgScale={3}
|
|
109
|
-
grayScale={true}
|
|
110
|
-
opacity={0.4}
|
|
111
|
-
/>
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const onRenderSlot = (itemToRender: IItem | null) => {
|
|
117
|
-
if (slotContainerType === SlotContainerType.EQUIPMENT_SET)
|
|
118
|
-
return renderEquipment(itemToRender);
|
|
119
|
-
return renderItem(itemToRender);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<Container
|
|
124
|
-
className="rpgui-icon empty-slot"
|
|
125
|
-
onMouseOver={event =>
|
|
126
|
-
onMouseOver(event, slotIndex, item, event.clientX, event.clientY)
|
|
127
|
-
}
|
|
128
|
-
onMouseOut={() => onMouseOut()}
|
|
129
|
-
onClick={e => {
|
|
130
|
-
if (item) {
|
|
131
|
-
onClick(item, e.clientX, e.clientY, slotContainerType);
|
|
132
|
-
} else {
|
|
133
|
-
onCancelContextMenu();
|
|
134
|
-
}
|
|
135
|
-
}}
|
|
136
|
-
>
|
|
137
|
-
{onRenderSlot(item)}
|
|
138
|
-
</Container>
|
|
139
|
-
);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const Container = styled.div`
|
|
143
|
-
margin: 0.1rem;
|
|
144
|
-
.sprite-from-atlas-img {
|
|
145
|
-
position: relative;
|
|
146
|
-
top: 1.5rem;
|
|
147
|
-
left: 1.5rem;
|
|
148
|
-
}
|
|
149
|
-
`;
|
|
150
|
-
|
|
151
|
-
interface IItemQtyProps {
|
|
152
|
-
left: string;
|
|
153
|
-
}
|
|
154
|
-
const ItemQty = styled.span<IItemQtyProps>`
|
|
155
|
-
position: relative;
|
|
156
|
-
top: 1.5rem;
|
|
157
|
-
left: ${props => props.left};
|
|
158
|
-
`;
|
|
1
|
+
import { IItem, IItemContainer, ItemSlotType } from '@rpg-engine/shared';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import atlasJSON from '../../../mocks/atlas/items/items.json';
|
|
5
|
+
import atlasIMG from '../../../mocks/atlas/items/items.png';
|
|
6
|
+
import { SpriteFromAtlas } from '../../shared/SpriteFromAtlas';
|
|
7
|
+
|
|
8
|
+
export enum SlotContainerType {
|
|
9
|
+
INVENTORY = 'Inventory',
|
|
10
|
+
EQUIPMENT_SET = 'EquipmentSet',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const EquipmentSlotSpriteByType: any = {
|
|
14
|
+
Neck: 'accessories/corruption-necklace.png',
|
|
15
|
+
LeftHand: 'swords/broad-sword.png',
|
|
16
|
+
Ring: 'rings/iron-ring.png',
|
|
17
|
+
Head: 'helmets/viking-helmet.png',
|
|
18
|
+
Torso: 'armors/iron-armor.png',
|
|
19
|
+
Legs: 'legs/studded-legs.png',
|
|
20
|
+
Feet: 'boots/iron-boots.png',
|
|
21
|
+
Inventory: 'containers/bag.png',
|
|
22
|
+
RightHand: 'shields/plate-shield.png',
|
|
23
|
+
Accessory: 'gloves/plate-gloves.png',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
interface IProps {
|
|
27
|
+
slotIndex: number;
|
|
28
|
+
item: IItem | null;
|
|
29
|
+
itemContainer?: IItemContainer | null;
|
|
30
|
+
slotContainerType: SlotContainerType | null;
|
|
31
|
+
slotSpriteMask?: ItemSlotType | null;
|
|
32
|
+
onMouseOver: (
|
|
33
|
+
event: any,
|
|
34
|
+
slotIndex: number,
|
|
35
|
+
item: IItem | null,
|
|
36
|
+
x: number,
|
|
37
|
+
y: number
|
|
38
|
+
) => void;
|
|
39
|
+
onMouseOut: () => void;
|
|
40
|
+
onClick: (
|
|
41
|
+
item: IItem,
|
|
42
|
+
posX: number,
|
|
43
|
+
posY: number,
|
|
44
|
+
slotContainerType: SlotContainerType | null
|
|
45
|
+
) => void;
|
|
46
|
+
onCancelContextMenu: () => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const ItemSlot: React.FC<IProps> = ({
|
|
50
|
+
slotIndex,
|
|
51
|
+
item,
|
|
52
|
+
slotContainerType,
|
|
53
|
+
slotSpriteMask,
|
|
54
|
+
onMouseOver,
|
|
55
|
+
onMouseOut,
|
|
56
|
+
onClick,
|
|
57
|
+
onCancelContextMenu,
|
|
58
|
+
}) => {
|
|
59
|
+
const getLeftPositionValue = (quantity: number) => {
|
|
60
|
+
if (quantity > 0 && quantity < 10) return '2.5rem';
|
|
61
|
+
else if (quantity > 9 && quantity < 100) return '2.0rem';
|
|
62
|
+
else if (quantity > 99) return '1rem';
|
|
63
|
+
return '2.5rem';
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const renderItem = (itemToRender: IItem | null) => {
|
|
67
|
+
const element = [];
|
|
68
|
+
if (itemToRender?.texturePath) {
|
|
69
|
+
element.push(
|
|
70
|
+
<SpriteFromAtlas
|
|
71
|
+
atlasIMG={atlasIMG}
|
|
72
|
+
atlasJSON={atlasJSON}
|
|
73
|
+
spriteKey={itemToRender.texturePath}
|
|
74
|
+
imgScale={3}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (itemToRender?.isStackable && itemToRender?.stackQty) {
|
|
79
|
+
element.push(
|
|
80
|
+
<ItemQty left={getLeftPositionValue(itemToRender.stackQty)}>
|
|
81
|
+
{' '}
|
|
82
|
+
{itemToRender.stackQty}{' '}
|
|
83
|
+
</ItemQty>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return element;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const renderEquipment = (itemToRender: IItem | null) => {
|
|
90
|
+
if (
|
|
91
|
+
itemToRender?.texturePath &&
|
|
92
|
+
itemToRender.allowedEquipSlotType?.includes(slotSpriteMask!)
|
|
93
|
+
) {
|
|
94
|
+
return (
|
|
95
|
+
<SpriteFromAtlas
|
|
96
|
+
atlasIMG={atlasIMG}
|
|
97
|
+
atlasJSON={atlasJSON}
|
|
98
|
+
spriteKey={itemToRender.texturePath}
|
|
99
|
+
imgScale={3}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
} else {
|
|
103
|
+
return (
|
|
104
|
+
<SpriteFromAtlas
|
|
105
|
+
atlasIMG={atlasIMG}
|
|
106
|
+
atlasJSON={atlasJSON}
|
|
107
|
+
spriteKey={EquipmentSlotSpriteByType[slotSpriteMask!]}
|
|
108
|
+
imgScale={3}
|
|
109
|
+
grayScale={true}
|
|
110
|
+
opacity={0.4}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const onRenderSlot = (itemToRender: IItem | null) => {
|
|
117
|
+
if (slotContainerType === SlotContainerType.EQUIPMENT_SET)
|
|
118
|
+
return renderEquipment(itemToRender);
|
|
119
|
+
return renderItem(itemToRender);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<Container
|
|
124
|
+
className="rpgui-icon empty-slot"
|
|
125
|
+
onMouseOver={event =>
|
|
126
|
+
onMouseOver(event, slotIndex, item, event.clientX, event.clientY)
|
|
127
|
+
}
|
|
128
|
+
onMouseOut={() => onMouseOut()}
|
|
129
|
+
onClick={e => {
|
|
130
|
+
if (item) {
|
|
131
|
+
onClick(item, e.clientX, e.clientY, slotContainerType);
|
|
132
|
+
} else {
|
|
133
|
+
onCancelContextMenu();
|
|
134
|
+
}
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
{onRenderSlot(item)}
|
|
138
|
+
</Container>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const Container = styled.div`
|
|
143
|
+
margin: 0.1rem;
|
|
144
|
+
.sprite-from-atlas-img {
|
|
145
|
+
position: relative;
|
|
146
|
+
top: 1.5rem;
|
|
147
|
+
left: 1.5rem;
|
|
148
|
+
}
|
|
149
|
+
`;
|
|
150
|
+
|
|
151
|
+
interface IItemQtyProps {
|
|
152
|
+
left: string;
|
|
153
|
+
}
|
|
154
|
+
const ItemQty = styled.span<IItemQtyProps>`
|
|
155
|
+
position: relative;
|
|
156
|
+
top: 1.5rem;
|
|
157
|
+
left: ${props => props.left};
|
|
158
|
+
`;
|