@rpg-engine/long-bow 0.7.68 → 0.7.71
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/dist/components/Item/Inventory/ItemSlot.d.ts +2 -17
- package/dist/components/Item/Inventory/ItemSlotTooltips.d.ts +10 -7
- package/dist/components/Item/Inventory/context/DraggingContext.d.ts +2 -17
- package/dist/long-bow.cjs.development.js +334 -354
- 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 +335 -355
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Item/Inventory/ItemContainer.tsx +2 -2
- package/src/components/Item/Inventory/ItemSlot.tsx +441 -252
- package/src/components/Item/Inventory/ItemSlotTooltips.tsx +22 -18
- package/src/components/Item/Inventory/context/DraggingContext.tsx +5 -31
- package/src/mocks/skills.mocks.ts +0 -4
- package/src/stories/UI/containers/ItemContainer.stories.tsx +3 -30
- package/dist/components/Item/Inventory/hooks/useItemSlotDragAndDrop.d.ts +0 -43
- package/src/components/Item/Inventory/hooks/useItemSlotDragAndDrop.ts +0 -228
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
} from '@rpg-engine/shared';
|
|
10
10
|
|
|
11
11
|
import { observer } from 'mobx-react-lite';
|
|
12
|
-
import React, {
|
|
13
|
-
import Draggable from 'react-draggable';
|
|
12
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
13
|
+
import Draggable, { DraggableEventHandler } from 'react-draggable';
|
|
14
14
|
import styled from 'styled-components';
|
|
15
15
|
import { IPosition } from '../../../types/eventTypes';
|
|
16
16
|
import { rarityColor } from './ItemSlotRarity';
|
|
17
17
|
import { ItemSlotRenderer } from './ItemSlotRenderer';
|
|
18
18
|
import { ItemSlotToolTips } from './ItemSlotTooltips';
|
|
19
|
-
import {
|
|
19
|
+
import { useDragging } from './context/DraggingContext';
|
|
20
20
|
import { IContextMenuItem, generateContextMenu } from './itemContainerHelper';
|
|
21
21
|
|
|
22
22
|
export const EquipmentSlotSpriteByType: any = {
|
|
@@ -61,6 +61,7 @@ interface IProps {
|
|
|
61
61
|
onOutsideDrop?: (item: IItem, position: IPosition) => void;
|
|
62
62
|
dragScale?: number;
|
|
63
63
|
checkIfItemCanBeMoved?: () => boolean;
|
|
64
|
+
checkIfItemShouldDragEnd?: () => boolean;
|
|
64
65
|
openQuantitySelector?: (maxQuantity: number, callback: () => void) => void;
|
|
65
66
|
onPlaceDrop?: (
|
|
66
67
|
item: IItem | null,
|
|
@@ -76,264 +77,454 @@ interface IProps {
|
|
|
76
77
|
isDepotSystem?: boolean;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
export
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
export const ItemSlot: React.FC<IProps> = observer(
|
|
81
|
+
({
|
|
82
|
+
slotIndex,
|
|
83
|
+
item,
|
|
84
|
+
itemContainerType: containerType,
|
|
85
|
+
slotSpriteMask,
|
|
86
|
+
onMouseOver,
|
|
87
|
+
onMouseOut,
|
|
88
|
+
onPointerDown,
|
|
89
|
+
onSelected,
|
|
90
|
+
atlasJSON,
|
|
91
|
+
atlasIMG,
|
|
92
|
+
isContextMenuDisabled = false,
|
|
93
|
+
onDragEnd,
|
|
94
|
+
onDragStart,
|
|
95
|
+
onPlaceDrop,
|
|
96
|
+
onOutsideDrop: onDrop,
|
|
97
|
+
checkIfItemCanBeMoved,
|
|
98
|
+
openQuantitySelector,
|
|
99
|
+
checkIfItemShouldDragEnd,
|
|
100
|
+
dragScale,
|
|
101
|
+
isSelectingShortcut,
|
|
102
|
+
equipmentSet,
|
|
103
|
+
setItemShortcut,
|
|
104
|
+
isDepotSystem,
|
|
105
|
+
}) => {
|
|
106
|
+
// Centralized state using a single useState hook
|
|
107
|
+
const [state, setState] = useState({
|
|
108
|
+
isTooltipVisible: false,
|
|
109
|
+
isTooltipMobileVisible: false,
|
|
110
|
+
isContextMenuVisible: false,
|
|
111
|
+
contextMenuPosition: { x: 0, y: 0 },
|
|
112
|
+
isFocused: false,
|
|
113
|
+
wasDragged: false,
|
|
114
|
+
dragPosition: { x: 0, y: 0 } as IPosition,
|
|
115
|
+
dropPosition: null as IPosition | null,
|
|
116
|
+
contextActions: [] as IContextMenuItem[],
|
|
117
|
+
draggingDistance: 0,
|
|
118
|
+
});
|
|
83
119
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
120
|
+
const {
|
|
121
|
+
isTooltipVisible,
|
|
122
|
+
isTooltipMobileVisible,
|
|
123
|
+
isContextMenuVisible,
|
|
124
|
+
contextMenuPosition,
|
|
125
|
+
isFocused,
|
|
126
|
+
wasDragged,
|
|
127
|
+
dragPosition,
|
|
128
|
+
dropPosition,
|
|
129
|
+
contextActions,
|
|
130
|
+
} = state;
|
|
88
131
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
132
|
+
const dragContainer = useRef<HTMLDivElement>(null);
|
|
133
|
+
const { item: draggingItem, setDraggingItem } = useDragging();
|
|
134
|
+
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
// Reset drag position and focus when item changes
|
|
137
|
+
setState(prevState => ({
|
|
138
|
+
...prevState,
|
|
139
|
+
dragPosition: { x: 0, y: 0 },
|
|
140
|
+
isFocused: false,
|
|
141
|
+
}));
|
|
142
|
+
|
|
143
|
+
// Update context actions when item or depot system changes
|
|
144
|
+
if (item && containerType) {
|
|
145
|
+
setState(prevState => ({
|
|
146
|
+
...prevState,
|
|
147
|
+
contextActions: generateContextMenu(
|
|
148
|
+
item,
|
|
149
|
+
containerType,
|
|
150
|
+
isDepotSystem
|
|
151
|
+
),
|
|
152
|
+
}));
|
|
153
|
+
} else {
|
|
154
|
+
setState(prevState => ({
|
|
155
|
+
...prevState,
|
|
156
|
+
contextActions: [],
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
}, [item, isDepotSystem]);
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
// Handle outside drop
|
|
163
|
+
if (onDrop && item && dropPosition) {
|
|
164
|
+
onDrop(item, dropPosition);
|
|
165
|
+
}
|
|
166
|
+
}, [dropPosition]);
|
|
167
|
+
|
|
168
|
+
const resetItem = () => {
|
|
169
|
+
setState(prevState => ({
|
|
170
|
+
...prevState,
|
|
171
|
+
isTooltipVisible: false,
|
|
172
|
+
wasDragged: false,
|
|
173
|
+
}));
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const onSuccessfulDrag = (quantity?: number) => {
|
|
177
|
+
resetItem();
|
|
178
|
+
|
|
179
|
+
if (quantity === -1) {
|
|
180
|
+
setState(prevState => ({
|
|
181
|
+
...prevState,
|
|
182
|
+
dragPosition: { x: 0, y: 0 },
|
|
183
|
+
isFocused: false,
|
|
184
|
+
}));
|
|
185
|
+
} else if (item) {
|
|
186
|
+
onDragEnd?.(quantity);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const onDraggableStop: DraggableEventHandler = (e, data) => {
|
|
191
|
+
console.log('>>> ON_DRAGGABLE_STOP');
|
|
192
|
+
// Stop the dragging state
|
|
193
|
+
|
|
194
|
+
console.log('setDraggingItem(null)');
|
|
195
|
+
setDraggingItem(null);
|
|
196
|
+
|
|
197
|
+
const target = e.target as HTMLElement;
|
|
198
|
+
|
|
199
|
+
console.log('handleShortcutSetter(target)');
|
|
200
|
+
handleShortcutSetter(target);
|
|
201
|
+
|
|
202
|
+
console.log('removeDraggingClass(target)');
|
|
203
|
+
removeDraggingClass(target);
|
|
204
|
+
|
|
205
|
+
console.log('shouldHandleDraggedItem()');
|
|
206
|
+
if (shouldHandleDraggedItem()) {
|
|
207
|
+
console.log('handleDraggedItem(e, data)');
|
|
208
|
+
handleDraggedItem(e, data);
|
|
209
|
+
} else if (item && !wasDragged) {
|
|
210
|
+
console.log('handleContextMenuOrTooltip(e)');
|
|
211
|
+
handleContextMenuOrTooltip(e);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Handles the shortcut setter logic if the target element is a shortcut setter.
|
|
217
|
+
*/
|
|
218
|
+
const handleShortcutSetter = (target: HTMLElement) => {
|
|
219
|
+
if (target?.id.includes('shortcutSetter') && setItemShortcut && item) {
|
|
220
|
+
const index = parseInt(target.id.split('_')[1], 10);
|
|
221
|
+
if (!isNaN(index)) {
|
|
222
|
+
setItemShortcut(item, index);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Removes the dragging CSS class from the target element.
|
|
229
|
+
*/
|
|
230
|
+
const removeDraggingClass = (target: HTMLElement) => {
|
|
231
|
+
target.classList.remove('react-draggable-dragging');
|
|
232
|
+
};
|
|
95
233
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
onPointerDown,
|
|
106
|
-
onSelected,
|
|
107
|
-
atlasJSON,
|
|
108
|
-
atlasIMG,
|
|
109
|
-
isContextMenuDisabled = false,
|
|
110
|
-
onDragEnd,
|
|
111
|
-
onDragStart,
|
|
112
|
-
onPlaceDrop,
|
|
113
|
-
onOutsideDrop: onDrop,
|
|
114
|
-
checkIfItemCanBeMoved,
|
|
115
|
-
openQuantitySelector,
|
|
116
|
-
dragScale,
|
|
117
|
-
isSelectingShortcut,
|
|
118
|
-
equipmentSet,
|
|
119
|
-
setItemShortcut,
|
|
120
|
-
isDepotSystem,
|
|
121
|
-
}: IProps): JSX.Element => {
|
|
122
|
-
const [tooltipState, setTooltipState] = useState<TooltipState>({
|
|
123
|
-
visible: false,
|
|
124
|
-
mobileVisible: false,
|
|
125
|
-
});
|
|
126
|
-
const [contextMenuState, setContextMenuState] = useState<
|
|
127
|
-
ContextMenuState
|
|
128
|
-
>({
|
|
129
|
-
visible: false,
|
|
130
|
-
position: { x: 0, y: 0 },
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const [contextActions, setContextActions] = useState<IContextMenuItem[]>(
|
|
134
|
-
[]
|
|
234
|
+
/**
|
|
235
|
+
* Determines whether the dragged item should be processed.
|
|
236
|
+
*/
|
|
237
|
+
const shouldHandleDraggedItem = (): boolean => {
|
|
238
|
+
console.log(
|
|
239
|
+
`Debug: shouldHandleDraggedItem()`,
|
|
240
|
+
`wasDragged: ${wasDragged}`,
|
|
241
|
+
`item: ${item}`,
|
|
242
|
+
`isSelectingShortcut: ${isSelectingShortcut}`
|
|
135
243
|
);
|
|
244
|
+
return !!(wasDragged && item && !isSelectingShortcut);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Handles the logic when an item has been dragged.
|
|
249
|
+
*/
|
|
250
|
+
const handleDraggedItem = (e: any, data: any) => {
|
|
251
|
+
const targetClasses = Array.from((e.target as HTMLElement).classList);
|
|
252
|
+
const isOutsideDrop =
|
|
253
|
+
targetClasses.some(elm => elm.includes('rpgui-content')) ||
|
|
254
|
+
targetClasses.length === 0;
|
|
255
|
+
|
|
256
|
+
if (isOutsideDrop) {
|
|
257
|
+
setState(prevState => ({
|
|
258
|
+
...prevState,
|
|
259
|
+
dropPosition: {
|
|
260
|
+
x: data.x,
|
|
261
|
+
y: data.y,
|
|
262
|
+
},
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
setState(prevState => ({
|
|
267
|
+
...prevState,
|
|
268
|
+
wasDragged: false,
|
|
269
|
+
}));
|
|
136
270
|
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
271
|
+
const targetElement = dragContainer.current;
|
|
272
|
+
if (!targetElement) return;
|
|
273
|
+
|
|
274
|
+
const { x, y } = getElementTransform(targetElement);
|
|
275
|
+
setState(prevState => ({
|
|
276
|
+
...prevState,
|
|
277
|
+
dragPosition: { x, y },
|
|
278
|
+
}));
|
|
279
|
+
|
|
280
|
+
// Delay to ensure state updates before proceeding
|
|
281
|
+
setTimeout(() => {
|
|
282
|
+
processDragEnd(item!);
|
|
283
|
+
}, 50);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Retrieves the current transform position of the dragged element.
|
|
288
|
+
*/
|
|
289
|
+
const getElementTransform = (
|
|
290
|
+
element: HTMLElement
|
|
291
|
+
): { x: number; y: number } => {
|
|
292
|
+
const style = window.getComputedStyle(element);
|
|
293
|
+
const matrix = new DOMMatrixReadOnly(style.transform);
|
|
294
|
+
return { x: matrix.m41, y: matrix.m42 };
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Processes the end of a drag event, handling quantity selection or resetting state.
|
|
299
|
+
*/
|
|
300
|
+
const processDragEnd = (item: IItem) => {
|
|
301
|
+
console.log(`Debug: processDragEnd(item)`, `item: ${item}`);
|
|
302
|
+
if (checkIfItemCanBeMoved?.()) {
|
|
303
|
+
console.log(
|
|
304
|
+
`Debug: checkIfItemCanBeMoved()`,
|
|
305
|
+
`result: ${checkIfItemCanBeMoved()}`
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
if (checkIfItemShouldDragEnd && !checkIfItemShouldDragEnd()) return;
|
|
309
|
+
|
|
310
|
+
console.log(
|
|
311
|
+
`Debug: checkIfItemShouldDragEnd()`,
|
|
312
|
+
`result: ${checkIfItemShouldDragEnd?.()}`
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) {
|
|
316
|
+
console.log(
|
|
317
|
+
`Debug: openQuantitySelector(item.stackQty, onSuccessfulDrag)`
|
|
168
318
|
);
|
|
319
|
+
openQuantitySelector(item.stackQty, onSuccessfulDrag);
|
|
320
|
+
} else {
|
|
321
|
+
console.log(`Debug: onSuccessfulDrag(item.stackQty)`);
|
|
322
|
+
onSuccessfulDrag(item.stackQty);
|
|
169
323
|
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (item && containerType) {
|
|
182
|
-
if (onPlaceDrop && draggingItem) {
|
|
183
|
-
onPlaceDrop(item, slotIndex, containerType);
|
|
184
|
-
}
|
|
185
|
-
if (
|
|
186
|
-
onPointerDown &&
|
|
187
|
-
onDragStart === undefined &&
|
|
188
|
-
onDragEnd === undefined
|
|
189
|
-
) {
|
|
190
|
-
onPointerDown(item.type, containerType, item);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
324
|
+
} else {
|
|
325
|
+
console.log(`Debug: resetItem()`);
|
|
326
|
+
resetItem();
|
|
327
|
+
setState(prevState => ({
|
|
328
|
+
...prevState,
|
|
329
|
+
isFocused: false,
|
|
330
|
+
dragPosition: { x: 0, y: 0 },
|
|
331
|
+
}));
|
|
332
|
+
}
|
|
333
|
+
};
|
|
193
334
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
containerType,
|
|
200
|
-
slotIndex,
|
|
201
|
-
onPlaceDrop,
|
|
202
|
-
onPointerDown,
|
|
203
|
-
onMouseOver,
|
|
204
|
-
onDragStart,
|
|
205
|
-
onDragEnd,
|
|
206
|
-
]
|
|
207
|
-
);
|
|
335
|
+
/**
|
|
336
|
+
* Handles the context menu or tooltip display after dragging stops without a drop.
|
|
337
|
+
*/
|
|
338
|
+
const handleContextMenuOrTooltip = (e: any) => {
|
|
339
|
+
let isTouchEvent = false;
|
|
208
340
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
341
|
+
if (
|
|
342
|
+
!isContextMenuDisabled &&
|
|
343
|
+
e.type === 'touchend' &&
|
|
344
|
+
!isSelectingShortcut
|
|
345
|
+
) {
|
|
346
|
+
isTouchEvent = true;
|
|
347
|
+
setState(prevState => ({
|
|
348
|
+
...prevState,
|
|
349
|
+
isTooltipMobileVisible: true,
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (!isContextMenuDisabled && !isSelectingShortcut && !isTouchEvent) {
|
|
354
|
+
setState(prevState => ({
|
|
355
|
+
...prevState,
|
|
356
|
+
isContextMenuVisible: !prevState.isContextMenuVisible,
|
|
357
|
+
contextMenuPosition: {
|
|
358
|
+
x: (e as MouseEvent).clientX - 10,
|
|
359
|
+
y: (e as MouseEvent).clientY - 5,
|
|
360
|
+
},
|
|
361
|
+
}));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (item) {
|
|
365
|
+
onPointerDown(item.type, containerType ?? null, item);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const onDraggableStart: DraggableEventHandler = () => {
|
|
370
|
+
if (!item || isSelectingShortcut) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (onDragStart && containerType) {
|
|
375
|
+
onDragStart(item, slotIndex, containerType);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const onDraggableProgress: DraggableEventHandler = (_e, _data) => {
|
|
380
|
+
// increment draggingDistance by 1
|
|
381
|
+
|
|
382
|
+
setState(prevState => ({
|
|
383
|
+
...prevState,
|
|
384
|
+
draggingDistance: prevState.draggingDistance + 1,
|
|
385
|
+
}));
|
|
386
|
+
|
|
387
|
+
if (state.draggingDistance > 10) {
|
|
388
|
+
setState(prevState => ({
|
|
389
|
+
...prevState,
|
|
390
|
+
wasDragged: true,
|
|
391
|
+
isFocused: true,
|
|
392
|
+
}));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (!draggingItem) {
|
|
396
|
+
setDraggingItem(item);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
231
399
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
400
|
+
return (
|
|
401
|
+
<Container
|
|
402
|
+
isDraggingItem={!!draggingItem}
|
|
403
|
+
item={item}
|
|
404
|
+
className="rpgui-icon empty-slot"
|
|
405
|
+
onMouseUp={() => {
|
|
406
|
+
const data = item ? item : null;
|
|
407
|
+
if (onPlaceDrop && containerType)
|
|
408
|
+
onPlaceDrop(data, slotIndex, containerType);
|
|
409
|
+
}}
|
|
410
|
+
onTouchEnd={e => {
|
|
411
|
+
const { clientX, clientY } = e.changedTouches[0];
|
|
412
|
+
const simulatedEvent = new MouseEvent('mouseup', {
|
|
413
|
+
clientX,
|
|
414
|
+
clientY,
|
|
415
|
+
bubbles: true,
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
document
|
|
419
|
+
.elementFromPoint(clientX, clientY)
|
|
420
|
+
?.dispatchEvent(simulatedEvent);
|
|
421
|
+
}}
|
|
422
|
+
onPointerDown={
|
|
423
|
+
onDragStart !== undefined && onDragEnd !== undefined
|
|
424
|
+
? undefined
|
|
425
|
+
: () => {
|
|
426
|
+
if (item) onPointerDown(item.type, containerType ?? null, item);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
isSelectingShortcut={
|
|
430
|
+
isSelectingShortcut &&
|
|
431
|
+
(item?.type === ItemType.Consumable ||
|
|
432
|
+
item?.type === ItemType.Tool ||
|
|
433
|
+
item?.subType === ItemSubType.Seed)
|
|
434
|
+
}
|
|
435
|
+
>
|
|
436
|
+
<Draggable
|
|
437
|
+
axis={isSelectingShortcut ? 'none' : 'both'}
|
|
438
|
+
defaultClassName={item ? 'draggable' : 'empty-slot'}
|
|
439
|
+
scale={dragScale}
|
|
440
|
+
disabled={onDragStart === undefined || onDragEnd === undefined}
|
|
441
|
+
onStop={onDraggableStop}
|
|
442
|
+
onStart={onDraggableStart}
|
|
443
|
+
onDrag={onDraggableProgress}
|
|
444
|
+
position={dragPosition}
|
|
445
|
+
cancel=".empty-slot"
|
|
446
|
+
bounds=".item-container-body, .equipment-container-body"
|
|
447
|
+
>
|
|
448
|
+
<ItemContainer
|
|
449
|
+
ref={dragContainer}
|
|
450
|
+
isFocused={isFocused}
|
|
451
|
+
onMouseOver={event => {
|
|
452
|
+
onMouseOver?.(
|
|
453
|
+
event,
|
|
454
|
+
slotIndex,
|
|
455
|
+
item,
|
|
456
|
+
event.clientX,
|
|
457
|
+
event.clientY
|
|
458
|
+
);
|
|
459
|
+
}}
|
|
460
|
+
onMouseOut={() => {
|
|
461
|
+
if (onMouseOut) onMouseOut();
|
|
462
|
+
}}
|
|
463
|
+
onMouseEnter={() => {
|
|
464
|
+
setState(prevState => ({
|
|
465
|
+
...prevState,
|
|
466
|
+
isTooltipVisible: true,
|
|
467
|
+
}));
|
|
468
|
+
}}
|
|
469
|
+
onMouseLeave={() => {
|
|
470
|
+
setState(prevState => ({
|
|
471
|
+
...prevState,
|
|
472
|
+
isTooltipVisible: false,
|
|
473
|
+
}));
|
|
474
|
+
}}
|
|
475
|
+
>
|
|
476
|
+
<ItemSlotRenderer
|
|
477
|
+
item={item}
|
|
478
|
+
slotSpriteMask={slotSpriteMask}
|
|
479
|
+
atlasIMG={atlasIMG}
|
|
480
|
+
atlasJSON={atlasJSON}
|
|
481
|
+
containerType={containerType}
|
|
482
|
+
/>
|
|
483
|
+
</ItemContainer>
|
|
484
|
+
</Draggable>
|
|
485
|
+
|
|
486
|
+
<ItemSlotToolTips
|
|
487
|
+
isTooltipVisible={isTooltipVisible}
|
|
488
|
+
isTooltipMobileVisible={isTooltipMobileVisible}
|
|
489
|
+
setIsTooltipMobileVisible={value =>
|
|
490
|
+
setState(prevState => ({
|
|
491
|
+
...prevState,
|
|
492
|
+
isTooltipMobileVisible: value,
|
|
493
|
+
}))
|
|
494
|
+
}
|
|
495
|
+
isFocused={isFocused}
|
|
496
|
+
isContextMenuVisible={isContextMenuVisible}
|
|
497
|
+
isContextMenuDisabled={isContextMenuDisabled}
|
|
235
498
|
item={item}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
499
|
+
contextActions={contextActions}
|
|
500
|
+
contextMenuPosition={contextMenuPosition}
|
|
501
|
+
dragScale={dragScale}
|
|
502
|
+
setIsContextMenuVisible={value =>
|
|
503
|
+
setState(prevState => ({
|
|
504
|
+
...prevState,
|
|
505
|
+
isContextMenuVisible: value,
|
|
506
|
+
}))
|
|
242
507
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (
|
|
249
|
-
onPlaceDrop(data, slotIndex, containerType);
|
|
250
|
-
}
|
|
251
|
-
}}
|
|
252
|
-
onTouchEnd={e => {
|
|
253
|
-
const { clientX, clientY } = e.changedTouches[0];
|
|
254
|
-
const simulatedEvent = new MouseEvent('mouseup', {
|
|
255
|
-
clientX,
|
|
256
|
-
clientY,
|
|
257
|
-
bubbles: true,
|
|
258
|
-
});
|
|
259
|
-
document
|
|
260
|
-
.elementFromPoint(clientX, clientY)
|
|
261
|
-
?.dispatchEvent(simulatedEvent);
|
|
508
|
+
onSelected={(optionId: string, item: IItem) => {
|
|
509
|
+
setState(prevState => ({
|
|
510
|
+
...prevState,
|
|
511
|
+
isContextMenuVisible: false,
|
|
512
|
+
}));
|
|
513
|
+
if (onSelected) onSelected(optionId, item);
|
|
262
514
|
}}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
515
|
+
atlasIMG={atlasIMG}
|
|
516
|
+
atlasJSON={atlasJSON}
|
|
517
|
+
equipmentSet={equipmentSet}
|
|
518
|
+
setIsTooltipVisible={value =>
|
|
519
|
+
setState(prevState => ({
|
|
520
|
+
...prevState,
|
|
521
|
+
isTooltipVisible: value,
|
|
522
|
+
}))
|
|
270
523
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
defaultClassName={item ? 'draggable' : 'empty-slot'}
|
|
276
|
-
scale={dragScale}
|
|
277
|
-
disabled={onDragStart === undefined || onDragEnd === undefined}
|
|
278
|
-
onStop={onDraggableStop}
|
|
279
|
-
onStart={onDraggableStart}
|
|
280
|
-
onDrag={onDraggableProgress}
|
|
281
|
-
position={dragState.position}
|
|
282
|
-
cancel=".empty-slot"
|
|
283
|
-
bounds={bounds}
|
|
284
|
-
>
|
|
285
|
-
<ItemContainer
|
|
286
|
-
ref={dragContainer}
|
|
287
|
-
isFocused={dragState.isFocused}
|
|
288
|
-
onMouseOver={event => {
|
|
289
|
-
onMouseOver?.(
|
|
290
|
-
event,
|
|
291
|
-
slotIndex,
|
|
292
|
-
item,
|
|
293
|
-
event.clientX,
|
|
294
|
-
event.clientY
|
|
295
|
-
);
|
|
296
|
-
}}
|
|
297
|
-
onMouseOut={onMouseOut}
|
|
298
|
-
onMouseEnter={() => {
|
|
299
|
-
setTooltipState(prev => ({ ...prev, visible: true }));
|
|
300
|
-
}}
|
|
301
|
-
onMouseLeave={() => {
|
|
302
|
-
setTooltipState(prev => ({ ...prev, visible: false }));
|
|
303
|
-
}}
|
|
304
|
-
>
|
|
305
|
-
<ItemSlotRenderer
|
|
306
|
-
item={item}
|
|
307
|
-
slotSpriteMask={slotSpriteMask}
|
|
308
|
-
atlasIMG={atlasIMG}
|
|
309
|
-
atlasJSON={atlasJSON}
|
|
310
|
-
containerType={containerType}
|
|
311
|
-
/>
|
|
312
|
-
</ItemContainer>
|
|
313
|
-
</Draggable>
|
|
314
|
-
|
|
315
|
-
<ItemSlotToolTips
|
|
316
|
-
tooltipState={tooltipState}
|
|
317
|
-
setTooltipState={setTooltipState}
|
|
318
|
-
contextMenuState={contextMenuState}
|
|
319
|
-
setContextMenuState={setContextMenuState}
|
|
320
|
-
isFocused={dragState.isFocused}
|
|
321
|
-
isContextMenuDisabled={isContextMenuDisabled}
|
|
322
|
-
item={item}
|
|
323
|
-
contextActions={contextActions}
|
|
324
|
-
dragScale={dragScale}
|
|
325
|
-
onSelected={(optionId: string, item: IItem) => {
|
|
326
|
-
setContextMenuState(prev => ({ ...prev, visible: false }));
|
|
327
|
-
if (onSelected) onSelected(optionId, item);
|
|
328
|
-
}}
|
|
329
|
-
atlasIMG={atlasIMG}
|
|
330
|
-
atlasJSON={atlasJSON}
|
|
331
|
-
equipmentSet={equipmentSet}
|
|
332
|
-
/>
|
|
333
|
-
</Container>
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
)
|
|
524
|
+
/>
|
|
525
|
+
</Container>
|
|
526
|
+
);
|
|
527
|
+
}
|
|
337
528
|
);
|
|
338
529
|
|
|
339
530
|
interface ContainerTypes {
|
|
@@ -347,7 +538,7 @@ const Container = styled.div<ContainerTypes>`
|
|
|
347
538
|
margin: 0.1rem;
|
|
348
539
|
|
|
349
540
|
.react-draggable-dragging {
|
|
350
|
-
//
|
|
541
|
+
// If dragging item, set opacity to 0
|
|
351
542
|
opacity: ${({ isDraggingItem }) => (isDraggingItem ? 0 : 1)};
|
|
352
543
|
}
|
|
353
544
|
|
|
@@ -358,10 +549,8 @@ const Container = styled.div<ContainerTypes>`
|
|
|
358
549
|
top: 1.5rem;
|
|
359
550
|
left: 1.5rem;
|
|
360
551
|
border-color: ${({ item }) => rarityColor(item)};
|
|
361
|
-
box-shadow: ${({ item }) => `0 0 5px 2px ${rarityColor(item)}`} inset,
|
|
362
|
-
|
|
363
|
-
}) => `0 0 4px 3px ${rarityColor(item)}`};
|
|
364
|
-
//background-color: ${({ item }) => rarityColor(item)};
|
|
552
|
+
box-shadow: ${({ item }) => `0 0 5px 2px ${rarityColor(item)}`} inset,
|
|
553
|
+
${({ item }) => `0 0 4px 3px ${rarityColor(item)}`};
|
|
365
554
|
}
|
|
366
555
|
|
|
367
556
|
&::before {
|