@rpg-engine/long-bow 0.8.16 → 0.8.18
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/long-bow.cjs.development.js +44 -7
- 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 +44 -7
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/CraftBook/CraftBook.tsx +1 -1
- package/src/components/CraftBook/CraftingTooltip.tsx +45 -14
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ICraftableItem, IItemContainer, ISkill } from '@rpg-engine/shared';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useEffect, useRef } from 'react';
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
import { uiColors } from '../../constants/uiColors';
|
|
5
5
|
import { countItemFromInventory } from '../../libs/itemCounter';
|
|
@@ -16,7 +16,12 @@ interface ICraftingTooltipProps {
|
|
|
16
16
|
atlasJSON: any;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const OFFSET = 20;
|
|
20
|
+
|
|
21
|
+
const TooltipContainer = styled.div<{
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
}>`
|
|
20
25
|
position: fixed;
|
|
21
26
|
left: ${props => props.x}px;
|
|
22
27
|
top: ${props => props.y}px;
|
|
@@ -34,17 +39,6 @@ const TooltipContainer = styled.div<{ x: number; y: number }>`
|
|
|
34
39
|
border: 1px solid ${uiColors.darkGray};
|
|
35
40
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
|
36
41
|
line-height: 1.4;
|
|
37
|
-
|
|
38
|
-
/* Arrow */
|
|
39
|
-
&:before {
|
|
40
|
-
content: '';
|
|
41
|
-
position: absolute;
|
|
42
|
-
top: 12px;
|
|
43
|
-
left: -6px;
|
|
44
|
-
border-width: 6px 6px 6px 0;
|
|
45
|
-
border-style: solid;
|
|
46
|
-
border-color: transparent rgba(0, 0, 0, 0.95) transparent transparent;
|
|
47
|
-
}
|
|
48
42
|
`;
|
|
49
43
|
|
|
50
44
|
const MinCraftingRequirementsText = styled.div<{ levelIsOk: boolean }>`
|
|
@@ -96,6 +90,39 @@ export const CraftingTooltip: React.FC<ICraftingTooltipProps> = ({
|
|
|
96
90
|
atlasIMG,
|
|
97
91
|
atlasJSON,
|
|
98
92
|
}) => {
|
|
93
|
+
const tooltipRef = useRef<HTMLDivElement>(null);
|
|
94
|
+
const [adjustedPosition, setAdjustedPosition] = React.useState({ x, y });
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const tooltipElement = tooltipRef.current;
|
|
98
|
+
if (tooltipElement) {
|
|
99
|
+
const rect = tooltipElement.getBoundingClientRect();
|
|
100
|
+
const tooltipWidth = rect.width;
|
|
101
|
+
const tooltipHeight = rect.height;
|
|
102
|
+
|
|
103
|
+
let adjustedX = x;
|
|
104
|
+
let adjustedY = y;
|
|
105
|
+
|
|
106
|
+
// If tooltip would go off the right edge, show it on the left side of the cursor
|
|
107
|
+
if (x + tooltipWidth + OFFSET > window.innerWidth) {
|
|
108
|
+
adjustedX = x - tooltipWidth - OFFSET;
|
|
109
|
+
} else {
|
|
110
|
+
// Otherwise, show it on the right side of the cursor
|
|
111
|
+
adjustedX = x + OFFSET;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Vertical positioning
|
|
115
|
+
if (y + tooltipHeight > window.innerHeight) {
|
|
116
|
+
adjustedY = window.innerHeight - tooltipHeight - OFFSET;
|
|
117
|
+
}
|
|
118
|
+
if (y < OFFSET) {
|
|
119
|
+
adjustedY = OFFSET;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setAdjustedPosition({ x: adjustedX, y: adjustedY });
|
|
123
|
+
}
|
|
124
|
+
}, [x, y]);
|
|
125
|
+
|
|
99
126
|
const levelInSkill =
|
|
100
127
|
(skills?.[
|
|
101
128
|
(recipe?.minCraftingRequirements?.[0] ?? '') as keyof ISkill
|
|
@@ -104,7 +131,11 @@ export const CraftingTooltip: React.FC<ICraftingTooltipProps> = ({
|
|
|
104
131
|
const levelIsOk = recipe?.levelIsOk ?? false;
|
|
105
132
|
|
|
106
133
|
return (
|
|
107
|
-
<TooltipContainer
|
|
134
|
+
<TooltipContainer
|
|
135
|
+
ref={tooltipRef}
|
|
136
|
+
x={adjustedPosition.x}
|
|
137
|
+
y={adjustedPosition.y}
|
|
138
|
+
>
|
|
108
139
|
<TooltipTitle>Skill Requirements</TooltipTitle>
|
|
109
140
|
<MinCraftingRequirementsText levelIsOk={levelIsOk}>
|
|
110
141
|
{modifyString(`${recipe?.minCraftingRequirements?.[0] ?? ''}`)} lvl{' '}
|