@rpg-engine/long-bow 0.8.15 → 0.8.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.8.15",
3
+ "version": "0.8.17",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -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 TooltipContainer = styled.div<{ x: number; y: number }>`
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 x={x} y={y}>
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{' '}
@@ -1,20 +1,25 @@
1
1
  import React from 'react';
2
2
  import { ColorSelector } from './ItemPropertyColorSelector';
3
3
 
4
- interface Props {
4
+ interface IItemPropertySimpleHandlerProps {
5
5
  isOpen: boolean;
6
6
  selectedColor: string;
7
7
  onClose: () => void;
8
8
  onConfirm: (color: string) => void;
9
9
  onChange: (color: string) => void;
10
+ costWarning?: {
11
+ cost: number;
12
+ currency?: string;
13
+ };
10
14
  }
11
15
 
12
- export const ItemPropertySimpleHandler: React.FC<Props> = ({
16
+ export const ItemPropertySimpleHandler: React.FC<IItemPropertySimpleHandlerProps> = ({
13
17
  isOpen,
14
18
  selectedColor,
15
19
  onClose,
16
20
  onConfirm,
17
21
  onChange,
22
+ costWarning,
18
23
  }) => (
19
24
  <ColorSelector
20
25
  selectedColor={selectedColor}
@@ -22,5 +27,6 @@ export const ItemPropertySimpleHandler: React.FC<Props> = ({
22
27
  onClose={onClose}
23
28
  onConfirm={onConfirm}
24
29
  onChange={onChange}
30
+ costWarning={costWarning}
25
31
  />
26
32
  );