@rpg-engine/long-bow 0.3.44 → 0.3.45
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/Abstractions/SlotsContainer.d.ts +1 -0
- package/dist/components/Button.d.ts +3 -2
- package/dist/components/Chat/Chat.d.ts +12 -2
- package/dist/components/Chatdeprecated/ChatDeprecated.d.ts +13 -0
- package/dist/components/CheckButton.d.ts +1 -2
- package/dist/components/CircularController/CircularController.d.ts +10 -0
- package/dist/components/CraftBook/CraftBook.d.ts +15 -0
- package/dist/components/CraftBook/MockItems.d.ts +2 -0
- package/dist/components/DraggableContainer.d.ts +1 -0
- package/dist/components/DropdownSelectorContainer.d.ts +13 -0
- package/dist/components/Equipment/EquipmentSet.d.ts +8 -0
- package/dist/components/Input.d.ts +1 -0
- package/dist/components/Item/Inventory/ItemContainer.d.ts +12 -0
- package/dist/components/Item/Inventory/ItemQuantitySelector.d.ts +7 -0
- package/dist/components/Item/Inventory/ItemSlot.d.ts +9 -0
- package/dist/components/NPCDialog/NPCDialogText.d.ts +4 -2
- package/dist/components/RadioInput/RadioButton.d.ts +8 -0
- package/dist/components/RadioInput/RadioInput.d.ts +13 -0
- package/dist/components/RadioInput/instruments.d.ts +4 -0
- package/dist/components/RangeSlider.d.ts +1 -0
- package/dist/components/Spellbook/QuickSpells.d.ts +10 -0
- package/dist/components/Spellbook/Spell.d.ts +11 -0
- package/dist/components/Spellbook/Spellbook.d.ts +15 -0
- package/dist/components/Spellbook/SpellbookShortcuts.d.ts +10 -0
- package/dist/components/Spellbook/constants.d.ts +3 -0
- package/dist/components/Spellbook/mockSpells.d.ts +2 -0
- package/dist/components/itemSelector/ItemSelector.d.ts +14 -0
- package/dist/constants/uiDevices.d.ts +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/long-bow.cjs.development.js +7464 -515
- 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 +7458 -518
- package/dist/long-bow.esm.js.map +1 -1
- package/dist/mocks/equipmentSet.mocks.d.ts +15 -2
- package/dist/mocks/skills.mocks.d.ts +2 -121
- package/dist/stories/ChatDeprecated.stories.d.ts +5 -0
- package/dist/stories/CircullarController.stories.d.ts +5 -0
- package/dist/stories/CraftBook.stories.d.ts +4 -0
- package/dist/stories/DropdownSelectorContainer.stories.d.ts +5 -0
- package/dist/stories/ItemQuantitySelector.stories.d.ts +5 -0
- package/dist/stories/ItemSelector.stories.d.ts +4 -0
- package/dist/stories/QuickSpells.stories.d.ts +5 -0
- package/dist/stories/RadioInput.stories.d.ts +5 -0
- package/dist/stories/Spellbook.stories.d.ts +5 -0
- package/package.json +4 -1
- package/src/components/Abstractions/SlotsContainer.tsx +3 -0
- package/src/components/Button.tsx +18 -8
- package/src/components/Chat/Chat.tsx +105 -105
- package/src/components/Chatdeprecated/ChatDeprecated.tsx +200 -0
- package/src/components/CheckButton.tsx +1 -1
- package/src/components/CircularController/CircularController.tsx +162 -0
- package/src/components/CraftBook/CraftBook.tsx +230 -0
- package/src/components/CraftBook/MockItems.ts +46 -0
- package/src/components/DraggableContainer.tsx +4 -1
- package/src/components/Dropdown.tsx +7 -1
- package/src/components/DropdownSelectorContainer.tsx +42 -0
- package/src/components/Equipment/EquipmentSet.tsx +46 -0
- package/src/components/Input.tsx +6 -2
- package/src/components/Item/Inventory/ItemContainer.tsx +104 -6
- package/src/components/Item/Inventory/ItemQuantitySelector.tsx +142 -0
- package/src/components/Item/Inventory/ItemSlot.tsx +234 -34
- package/src/components/NPCDialog/NPCDialog.tsx +4 -28
- package/src/components/NPCDialog/NPCDialogText.tsx +75 -15
- package/src/components/NPCDialog/img/press-button.gif +0 -0
- package/src/components/RadioInput/RadioButton.tsx +98 -0
- package/src/components/RadioInput/RadioInput.tsx +99 -0
- package/src/components/RadioInput/instruments.ts +16 -0
- package/src/components/RangeSlider.tsx +37 -14
- package/src/components/SkillsContainer.tsx +1 -1
- package/src/components/Spellbook/QuickSpells.tsx +120 -0
- package/src/components/Spellbook/Spell.tsx +201 -0
- package/src/components/Spellbook/Spellbook.tsx +144 -0
- package/src/components/Spellbook/SpellbookShortcuts.tsx +77 -0
- package/src/components/Spellbook/constants.ts +12 -0
- package/src/components/Spellbook/mockSpells.ts +60 -0
- package/src/components/TimeWidget/TimeWidget.tsx +1 -0
- package/src/components/TradingMenu/TradingItemRow.tsx +43 -6
- package/src/components/TradingMenu/TradingMenu.tsx +1 -1
- package/src/components/itemSelector/ItemSelector.tsx +136 -0
- package/src/components/shared/SpriteFromAtlas.tsx +4 -1
- package/src/constants/uiDevices.ts +5 -0
- package/src/hooks/useOutsideAlerter.ts +2 -2
- package/src/index.tsx +8 -0
- package/src/mocks/atlas/items/items.json +6086 -314
- package/src/mocks/atlas/items/items.png +0 -0
- package/src/mocks/equipmentSet.mocks.ts +49 -4
- package/src/mocks/itemContainer.mocks.ts +54 -6
- package/src/mocks/skills.mocks.ts +8 -2
- package/src/stories/Chat.stories.tsx +20 -3
- package/src/stories/ChatDeprecated.stories.tsx +170 -0
- package/src/stories/CircullarController.stories.tsx +33 -0
- package/src/stories/CraftBook.stories.tsx +40 -0
- package/src/stories/DropdownSelectorContainer.stories.tsx +41 -0
- package/src/stories/EquipmentSet.stories.tsx +10 -0
- package/src/stories/ItemContainer.stories.tsx +84 -15
- package/src/stories/ItemQuantitySelector.stories.tsx +26 -0
- package/src/stories/ItemSelector.stories.tsx +77 -0
- package/src/stories/QuickSpells.stories.tsx +38 -0
- package/src/stories/RadioInput.stories.tsx +35 -0
- package/src/stories/RangeSlider.stories.tsx +10 -9
- package/src/stories/Spellbook.stories.tsx +107 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { DraggableContainer } from '../DraggableContainer';
|
|
4
|
+
import { RPGUIContainerTypes } from '../RPGUIContainer';
|
|
5
|
+
import { Button, ButtonTypes } from '../Button';
|
|
6
|
+
import { RadioButton } from './RadioButton';
|
|
7
|
+
|
|
8
|
+
export interface IRadioItems {
|
|
9
|
+
title: string;
|
|
10
|
+
subtitle: string;
|
|
11
|
+
}
|
|
12
|
+
export interface IRadioInput {
|
|
13
|
+
title:string,
|
|
14
|
+
subtitle:string,
|
|
15
|
+
onSelect:(a:string)=>void,
|
|
16
|
+
onCancel:()=>void,
|
|
17
|
+
items:IRadioItems[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const RadioInput: React.FC<IRadioInput>=({title,subtitle,onSelect,onCancel,items})=>{
|
|
21
|
+
const [instrument, setInstrument] = useState('')
|
|
22
|
+
|
|
23
|
+
const confirHandler=()=>{
|
|
24
|
+
if(instrument){
|
|
25
|
+
onSelect(instrument)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<DraggableContainer
|
|
31
|
+
type={RPGUIContainerTypes.Framed}
|
|
32
|
+
onCloseButton={() => {
|
|
33
|
+
if (onCancel) onCancel();
|
|
34
|
+
}}
|
|
35
|
+
width="500px"
|
|
36
|
+
cancelDrag=".equipment-container-body .arrow-selector"
|
|
37
|
+
>
|
|
38
|
+
<>
|
|
39
|
+
<div style={{ width: '100%' }}>
|
|
40
|
+
<Title>{title}</Title>
|
|
41
|
+
<Subtitle>{subtitle}</Subtitle>
|
|
42
|
+
<hr className="golden" />
|
|
43
|
+
</div>
|
|
44
|
+
<RadioInputScroller>{
|
|
45
|
+
items.map((item,index)=>(
|
|
46
|
+
<RadioButton
|
|
47
|
+
key={`${item.title}_${index}`}
|
|
48
|
+
title={item.title}
|
|
49
|
+
subtitle={item.subtitle}
|
|
50
|
+
setInstrument={setInstrument}
|
|
51
|
+
instrument={instrument}
|
|
52
|
+
/>
|
|
53
|
+
))
|
|
54
|
+
}
|
|
55
|
+
</RadioInputScroller>
|
|
56
|
+
<ButtonWrapper>
|
|
57
|
+
<Button
|
|
58
|
+
buttonType={ButtonTypes.RPGUIButton}
|
|
59
|
+
onClick={() => onCancel()}
|
|
60
|
+
>
|
|
61
|
+
Cancel
|
|
62
|
+
</Button>
|
|
63
|
+
<Button
|
|
64
|
+
buttonType={ButtonTypes.RPGUIButton}
|
|
65
|
+
onClick={ confirHandler}
|
|
66
|
+
>
|
|
67
|
+
Select
|
|
68
|
+
</Button>
|
|
69
|
+
|
|
70
|
+
</ButtonWrapper>
|
|
71
|
+
|
|
72
|
+
</>
|
|
73
|
+
</DraggableContainer>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
const RadioInputScroller = styled.div`
|
|
77
|
+
overflow-y: scroll;
|
|
78
|
+
height: 390px;
|
|
79
|
+
width: 100%;
|
|
80
|
+
margin-top: 1rem;
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
const Title = styled.h1`
|
|
84
|
+
z-index: 22;
|
|
85
|
+
font-size: 0.6rem;
|
|
86
|
+
color: yellow !important;
|
|
87
|
+
`;
|
|
88
|
+
const Subtitle = styled.h1`
|
|
89
|
+
z-index: 22;
|
|
90
|
+
font-size: 0.4rem;
|
|
91
|
+
color: yellow !important;
|
|
92
|
+
`;
|
|
93
|
+
const ButtonWrapper = styled.div`
|
|
94
|
+
display: flex;
|
|
95
|
+
justify-content: flex-end;
|
|
96
|
+
padding-top: 20px;
|
|
97
|
+
width: 100%;
|
|
98
|
+
margin-top: 1rem;
|
|
99
|
+
`;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
export const Itools:{title:string,subtitle:string}[] = [
|
|
3
|
+
{
|
|
4
|
+
title : 'Ax',
|
|
5
|
+
subtitle:'Cut down trees',
|
|
6
|
+
}, {
|
|
7
|
+
title : 'Sawing',
|
|
8
|
+
subtitle:'cut the wood into small pieces',
|
|
9
|
+
}, {
|
|
10
|
+
title : 'Sickle',
|
|
11
|
+
subtitle:'harvesting cereal plants',
|
|
12
|
+
}, {
|
|
13
|
+
title : 'Bow',
|
|
14
|
+
subtitle:'Hunting monsters',
|
|
15
|
+
},
|
|
16
|
+
];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
-
import { _RPGUI } from './RPGUIRoot';
|
|
5
4
|
|
|
6
5
|
export enum RangeSliderType {
|
|
7
6
|
Slider = 'rpgui-slider',
|
|
@@ -14,6 +13,7 @@ export interface IRangeSliderProps {
|
|
|
14
13
|
valueMax: number;
|
|
15
14
|
width: string;
|
|
16
15
|
onChange: (value: number) => void;
|
|
16
|
+
value: number;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const RangeSlider: React.FC<IRangeSliderProps> = ({
|
|
@@ -22,29 +22,46 @@ export const RangeSlider: React.FC<IRangeSliderProps> = ({
|
|
|
22
22
|
valueMax,
|
|
23
23
|
width,
|
|
24
24
|
onChange,
|
|
25
|
+
value,
|
|
25
26
|
}) => {
|
|
26
27
|
const sliderId = uuidv4();
|
|
27
28
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const value = _RPGUI.get_value(rpguiSlider);
|
|
29
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
30
|
+
const [left, setLeft] = useState(0);
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const calculatedWidth = containerRef.current?.clientWidth || 0;
|
|
34
|
+
setLeft(
|
|
35
|
+
Math.max(
|
|
36
|
+
((value - valueMin) / (valueMax - valueMin)) * (calculatedWidth - 35) +
|
|
37
|
+
10
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
}, [value, valueMin, valueMax]);
|
|
41
|
+
|
|
42
|
+
const typeClass = type === RangeSliderType.GoldSlider ? 'golden' : '';
|
|
34
43
|
|
|
35
44
|
return (
|
|
36
|
-
<div
|
|
45
|
+
<div
|
|
46
|
+
style={{ width: width, position: 'relative' }}
|
|
47
|
+
className={`rpgui-slider-container ${typeClass}`}
|
|
48
|
+
id={`rpgui-slider-${sliderId}`}
|
|
49
|
+
ref={containerRef}
|
|
50
|
+
>
|
|
51
|
+
<div style={{ pointerEvents: 'none' }}>
|
|
52
|
+
<div className={`rpgui-slider-track ${typeClass}`} />
|
|
53
|
+
<div className={`rpgui-slider-left-edge ${typeClass}`} />
|
|
54
|
+
<div className={`rpgui-slider-right-edge ${typeClass}`} />
|
|
55
|
+
<div className={`rpgui-slider-thumb ${typeClass}`} style={{ left }} />
|
|
56
|
+
</div>
|
|
37
57
|
<Input
|
|
38
|
-
className={
|
|
39
|
-
type === RangeSliderType.Slider
|
|
40
|
-
? RangeSliderType.Slider
|
|
41
|
-
: RangeSliderType.GoldSlider
|
|
42
|
-
}
|
|
43
58
|
type="range"
|
|
44
59
|
style={{ width: width }}
|
|
45
60
|
min={valueMin}
|
|
46
61
|
max={valueMax}
|
|
47
|
-
|
|
62
|
+
onChange={e => onChange(Number(e.target.value))}
|
|
63
|
+
value={value}
|
|
64
|
+
className="rpgui-cursor-point"
|
|
48
65
|
/>
|
|
49
66
|
</div>
|
|
50
67
|
);
|
|
@@ -52,4 +69,10 @@ export const RangeSlider: React.FC<IRangeSliderProps> = ({
|
|
|
52
69
|
|
|
53
70
|
const Input = styled.input`
|
|
54
71
|
opacity: 0;
|
|
72
|
+
position: absolute;
|
|
73
|
+
width: 100%;
|
|
74
|
+
height: 100%;
|
|
75
|
+
top: 0;
|
|
76
|
+
left: 0;
|
|
77
|
+
margin-top: -5px;
|
|
55
78
|
`;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { IRawSpell } from '@rpg-engine/shared';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { uiColors } from '../../constants/uiColors';
|
|
5
|
+
|
|
6
|
+
export type QuickSpellsProps = {
|
|
7
|
+
quickSpells: IRawSpell[];
|
|
8
|
+
onSpellCast: (spellKey: string) => void;
|
|
9
|
+
mana: number;
|
|
10
|
+
isBlockedCastingByKeyboard?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const QuickSpells: React.FC<QuickSpellsProps> = ({
|
|
14
|
+
quickSpells,
|
|
15
|
+
onSpellCast,
|
|
16
|
+
mana,
|
|
17
|
+
isBlockedCastingByKeyboard = false,
|
|
18
|
+
}) => {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
21
|
+
if (isBlockedCastingByKeyboard) return;
|
|
22
|
+
|
|
23
|
+
const shortcutIndex = Number(e.key) - 1;
|
|
24
|
+
if (shortcutIndex >= 0 && shortcutIndex <= 3) {
|
|
25
|
+
const shortcut = quickSpells[shortcutIndex];
|
|
26
|
+
if (shortcut?.key && mana >= shortcut?.manaCost) {
|
|
27
|
+
onSpellCast(shortcut.key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
33
|
+
|
|
34
|
+
return () => {
|
|
35
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
36
|
+
};
|
|
37
|
+
}, [quickSpells, isBlockedCastingByKeyboard]);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<List>
|
|
41
|
+
{Array.from({ length: 4 }).map((_, i) => (
|
|
42
|
+
<SpellShortcut
|
|
43
|
+
key={i}
|
|
44
|
+
onClick={onSpellCast.bind(null, quickSpells[i]?.key)}
|
|
45
|
+
disabled={mana < quickSpells[i]?.manaCost}
|
|
46
|
+
>
|
|
47
|
+
<span className="mana">
|
|
48
|
+
{quickSpells[i]?.key && quickSpells[i]?.manaCost}
|
|
49
|
+
</span>
|
|
50
|
+
<span className="magicWords">
|
|
51
|
+
{quickSpells[i]?.magicWords.split(' ').map(word => word[0])}
|
|
52
|
+
</span>
|
|
53
|
+
<span className="keyboard">{i + 1}</span>
|
|
54
|
+
</SpellShortcut>
|
|
55
|
+
))}
|
|
56
|
+
</List>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const SpellShortcut = styled.button`
|
|
61
|
+
width: 3rem;
|
|
62
|
+
height: 3rem;
|
|
63
|
+
background-color: ${uiColors.lightGray};
|
|
64
|
+
border: 2px solid ${uiColors.darkGray};
|
|
65
|
+
border-radius: 50%;
|
|
66
|
+
text-transform: uppercase;
|
|
67
|
+
font-size: 0.7rem;
|
|
68
|
+
font-weight: bold;
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
justify-content: center;
|
|
72
|
+
position: relative;
|
|
73
|
+
|
|
74
|
+
span {
|
|
75
|
+
pointer-events: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.mana {
|
|
79
|
+
position: absolute;
|
|
80
|
+
top: -5px;
|
|
81
|
+
right: 0;
|
|
82
|
+
font-size: 0.65rem;
|
|
83
|
+
color: ${uiColors.blue};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.magicWords {
|
|
87
|
+
margin-top: 4px;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.keyboard {
|
|
91
|
+
position: absolute;
|
|
92
|
+
bottom: -5px;
|
|
93
|
+
left: 0;
|
|
94
|
+
font-size: 0.65rem;
|
|
95
|
+
color: ${uiColors.yellow};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
&:hover,
|
|
99
|
+
&:focus {
|
|
100
|
+
background-color: ${uiColors.darkGray};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
&:active {
|
|
104
|
+
background-color: ${uiColors.gray};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
&:disabled {
|
|
108
|
+
opacity: 0.5;
|
|
109
|
+
}
|
|
110
|
+
`;
|
|
111
|
+
|
|
112
|
+
const List = styled.p`
|
|
113
|
+
width: 100%;
|
|
114
|
+
display: flex;
|
|
115
|
+
align-items: center;
|
|
116
|
+
justify-content: center;
|
|
117
|
+
gap: 0.5rem;
|
|
118
|
+
box-sizing: border-box;
|
|
119
|
+
margin: 0 !important;
|
|
120
|
+
`;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { IRawSpell } from '@rpg-engine/shared';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { uiColors } from '../../constants/uiColors';
|
|
5
|
+
import { uiFonts } from '../../constants/uiFonts';
|
|
6
|
+
|
|
7
|
+
interface Props extends IRawSpell {
|
|
8
|
+
charMana: number;
|
|
9
|
+
charMagicLevel: number;
|
|
10
|
+
onClick?: (spellKey: string) => void;
|
|
11
|
+
isSettingShortcut?: boolean;
|
|
12
|
+
spellKey: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const Spell: React.FC<Props> = ({
|
|
16
|
+
spellKey,
|
|
17
|
+
name,
|
|
18
|
+
description,
|
|
19
|
+
magicWords,
|
|
20
|
+
manaCost,
|
|
21
|
+
charMana,
|
|
22
|
+
charMagicLevel,
|
|
23
|
+
onClick,
|
|
24
|
+
isSettingShortcut,
|
|
25
|
+
minMagicLevelRequired,
|
|
26
|
+
}) => {
|
|
27
|
+
const disabled = isSettingShortcut
|
|
28
|
+
? charMagicLevel < minMagicLevelRequired
|
|
29
|
+
: manaCost > charMana || charMagicLevel < minMagicLevelRequired;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Container
|
|
33
|
+
disabled={disabled}
|
|
34
|
+
onClick={onClick?.bind(null, spellKey)}
|
|
35
|
+
isSettingShortcut={isSettingShortcut && !disabled}
|
|
36
|
+
className="spell"
|
|
37
|
+
>
|
|
38
|
+
{disabled && (
|
|
39
|
+
<Overlay>
|
|
40
|
+
{charMagicLevel < minMagicLevelRequired
|
|
41
|
+
? 'Low magic level'
|
|
42
|
+
: manaCost > charMana && 'No mana'}
|
|
43
|
+
</Overlay>
|
|
44
|
+
)}
|
|
45
|
+
<SpellImage>{magicWords.split(' ').map(word => word[0])}</SpellImage>
|
|
46
|
+
<Info>
|
|
47
|
+
<Title>
|
|
48
|
+
<span>{name}</span>
|
|
49
|
+
<span className="spell">({magicWords})</span>
|
|
50
|
+
</Title>
|
|
51
|
+
<Description>{description}</Description>
|
|
52
|
+
</Info>
|
|
53
|
+
|
|
54
|
+
<Divider />
|
|
55
|
+
<Cost>
|
|
56
|
+
<span>Mana cost:</span>
|
|
57
|
+
<span className="mana">{manaCost}</span>
|
|
58
|
+
</Cost>
|
|
59
|
+
</Container>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const Container = styled.button<{ isSettingShortcut?: boolean }>`
|
|
64
|
+
display: block;
|
|
65
|
+
background: none;
|
|
66
|
+
border: 2px solid transparent;
|
|
67
|
+
border-radius: 1rem;
|
|
68
|
+
width: 100%;
|
|
69
|
+
display: flex;
|
|
70
|
+
height: 5rem;
|
|
71
|
+
gap: 1rem;
|
|
72
|
+
align-items: center;
|
|
73
|
+
padding: 0 1rem;
|
|
74
|
+
text-align: left;
|
|
75
|
+
position: relative;
|
|
76
|
+
|
|
77
|
+
animation: ${({ isSettingShortcut }) =>
|
|
78
|
+
isSettingShortcut ? 'border-color-change 1s infinite' : 'none'};
|
|
79
|
+
|
|
80
|
+
@keyframes border-color-change {
|
|
81
|
+
0% {
|
|
82
|
+
border-color: ${uiColors.yellow};
|
|
83
|
+
}
|
|
84
|
+
50% {
|
|
85
|
+
border-color: transparent;
|
|
86
|
+
}
|
|
87
|
+
100% {
|
|
88
|
+
border-color: ${uiColors.yellow};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
&:hover,
|
|
93
|
+
&:focus {
|
|
94
|
+
background-color: ${uiColors.darkGray};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&:active {
|
|
98
|
+
background: none;
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
const SpellImage = styled.div`
|
|
103
|
+
width: 4rem;
|
|
104
|
+
height: 4rem;
|
|
105
|
+
font-size: ${uiFonts.size.xLarge};
|
|
106
|
+
font-weight: bold;
|
|
107
|
+
background-color: ${uiColors.darkGray};
|
|
108
|
+
color: ${uiColors.lightGray};
|
|
109
|
+
display: flex;
|
|
110
|
+
justify-content: center;
|
|
111
|
+
align-items: center;
|
|
112
|
+
text-transform: uppercase;
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
const Info = styled.span`
|
|
116
|
+
width: 0;
|
|
117
|
+
flex: 1;
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
const Title = styled.p`
|
|
121
|
+
display: flex;
|
|
122
|
+
flex-wrap: wrap;
|
|
123
|
+
align-items: center;
|
|
124
|
+
margin-bottom: 5px;
|
|
125
|
+
margin: 0;
|
|
126
|
+
|
|
127
|
+
span {
|
|
128
|
+
font-size: ${uiFonts.size.medium} !important;
|
|
129
|
+
font-weight: bold !important;
|
|
130
|
+
color: ${uiColors.yellow} !important;
|
|
131
|
+
margin-right: 0.5rem;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.spell {
|
|
135
|
+
font-size: ${uiFonts.size.small} !important;
|
|
136
|
+
font-weight: normal !important;
|
|
137
|
+
color: ${uiColors.lightGray} !important;
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
140
|
+
|
|
141
|
+
const Description = styled.div`
|
|
142
|
+
font-size: ${uiFonts.size.small} !important;
|
|
143
|
+
line-height: 1.1 !important;
|
|
144
|
+
`;
|
|
145
|
+
|
|
146
|
+
const Divider = styled.div`
|
|
147
|
+
width: 1px;
|
|
148
|
+
height: 100%;
|
|
149
|
+
margin: 0 1rem;
|
|
150
|
+
background-color: ${uiColors.lightGray};
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
const Cost = styled.p`
|
|
154
|
+
display: flex;
|
|
155
|
+
align-items: center;
|
|
156
|
+
flex-direction: column;
|
|
157
|
+
gap: 0.5rem;
|
|
158
|
+
|
|
159
|
+
div {
|
|
160
|
+
z-index: 1;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.mana {
|
|
164
|
+
position: relative;
|
|
165
|
+
font-size: ${uiFonts.size.medium};
|
|
166
|
+
font-weight: bold;
|
|
167
|
+
z-index: 1;
|
|
168
|
+
|
|
169
|
+
&::after {
|
|
170
|
+
position: absolute;
|
|
171
|
+
content: '';
|
|
172
|
+
top: 0;
|
|
173
|
+
left: 0;
|
|
174
|
+
background-color: ${uiColors.blue};
|
|
175
|
+
width: 100%;
|
|
176
|
+
height: 100%;
|
|
177
|
+
border-radius: 50%;
|
|
178
|
+
transform: scale(1.8);
|
|
179
|
+
filter: blur(10px);
|
|
180
|
+
z-index: -1;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
`;
|
|
184
|
+
|
|
185
|
+
const Overlay = styled.p`
|
|
186
|
+
margin: 0 !important;
|
|
187
|
+
position: absolute;
|
|
188
|
+
top: 0;
|
|
189
|
+
left: 0;
|
|
190
|
+
width: 100%;
|
|
191
|
+
height: 100%;
|
|
192
|
+
border-radius: 1rem;
|
|
193
|
+
display: flex;
|
|
194
|
+
justify-content: center;
|
|
195
|
+
align-items: center;
|
|
196
|
+
color: ${uiColors.yellow};
|
|
197
|
+
font-size: ${uiFonts.size.large} !important;
|
|
198
|
+
font-weight: bold;
|
|
199
|
+
z-index: 10;
|
|
200
|
+
background-color: rgba(0 0 0 / 0.2);
|
|
201
|
+
`;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { IRawSpell } from '@rpg-engine/shared';
|
|
2
|
+
import React, { Fragment, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { uiFonts } from '../../constants/uiFonts';
|
|
5
|
+
import { DraggableContainer } from '../DraggableContainer';
|
|
6
|
+
import { Input } from '../Input';
|
|
7
|
+
import { RPGUIContainerTypes } from '../RPGUIContainer';
|
|
8
|
+
import { Spell } from './Spell';
|
|
9
|
+
import { SpellbookShortcuts } from './SpellbookShortcuts';
|
|
10
|
+
|
|
11
|
+
export interface ISpellbookProps {
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
onInputFocus?: () => void;
|
|
14
|
+
onInputBlur?: () => void;
|
|
15
|
+
spells: IRawSpell[];
|
|
16
|
+
magicLevel: number;
|
|
17
|
+
mana: number;
|
|
18
|
+
onSpellClick: (spellKey: string) => void;
|
|
19
|
+
setSpellShortcut: (key: string, index: number) => void;
|
|
20
|
+
spellShortcuts: IRawSpell[];
|
|
21
|
+
removeSpellShortcut: (index: number) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const Spellbook: React.FC<ISpellbookProps> = ({
|
|
25
|
+
onClose,
|
|
26
|
+
onInputFocus,
|
|
27
|
+
onInputBlur,
|
|
28
|
+
spells,
|
|
29
|
+
magicLevel,
|
|
30
|
+
mana,
|
|
31
|
+
onSpellClick,
|
|
32
|
+
setSpellShortcut,
|
|
33
|
+
spellShortcuts,
|
|
34
|
+
removeSpellShortcut,
|
|
35
|
+
}) => {
|
|
36
|
+
const [search, setSearch] = useState('');
|
|
37
|
+
const [settingShortcutIndex, setSettingShortcutIndex] = useState(-1);
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const handleEscapeClose = (e: KeyboardEvent) => {
|
|
41
|
+
if (e.key === 'Escape') {
|
|
42
|
+
onClose?.();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
document.addEventListener('keydown', handleEscapeClose);
|
|
47
|
+
|
|
48
|
+
return () => {
|
|
49
|
+
document.removeEventListener('keydown', handleEscapeClose);
|
|
50
|
+
};
|
|
51
|
+
}, [onClose]);
|
|
52
|
+
|
|
53
|
+
const spellsToDisplay = useMemo(() => {
|
|
54
|
+
return spells
|
|
55
|
+
.sort((a, b) => {
|
|
56
|
+
if (a.minMagicLevelRequired > b.minMagicLevelRequired) return 1;
|
|
57
|
+
if (a.minMagicLevelRequired < b.minMagicLevelRequired) return -1;
|
|
58
|
+
return 0;
|
|
59
|
+
})
|
|
60
|
+
.filter(
|
|
61
|
+
spell =>
|
|
62
|
+
spell.name.toLocaleLowerCase().includes(search.toLocaleLowerCase()) ||
|
|
63
|
+
spell.magicWords
|
|
64
|
+
.toLocaleLowerCase()
|
|
65
|
+
.includes(search.toLocaleLowerCase())
|
|
66
|
+
);
|
|
67
|
+
}, [search, spells]);
|
|
68
|
+
|
|
69
|
+
const setShortcut = (spellKey: string) => {
|
|
70
|
+
setSpellShortcut?.(spellKey, settingShortcutIndex);
|
|
71
|
+
setSettingShortcutIndex(-1);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<DraggableContainer
|
|
76
|
+
type={RPGUIContainerTypes.Framed}
|
|
77
|
+
onCloseButton={onClose}
|
|
78
|
+
width="inherit"
|
|
79
|
+
height="inherit"
|
|
80
|
+
cancelDrag="#spellbook-search, #shortcuts_list, .spell"
|
|
81
|
+
>
|
|
82
|
+
<Container>
|
|
83
|
+
<Title>Learned Spells</Title>
|
|
84
|
+
|
|
85
|
+
<SpellbookShortcuts
|
|
86
|
+
setSettingShortcutIndex={setSettingShortcutIndex}
|
|
87
|
+
settingShortcutIndex={settingShortcutIndex}
|
|
88
|
+
shortcuts={spellShortcuts}
|
|
89
|
+
removeShortcut={removeSpellShortcut}
|
|
90
|
+
/>
|
|
91
|
+
|
|
92
|
+
<Input
|
|
93
|
+
placeholder="Search for spell"
|
|
94
|
+
value={search}
|
|
95
|
+
onChange={e => setSearch(e.target.value)}
|
|
96
|
+
onFocus={onInputFocus}
|
|
97
|
+
onBlur={onInputBlur}
|
|
98
|
+
id="spellbook-search"
|
|
99
|
+
/>
|
|
100
|
+
|
|
101
|
+
<SpellList>
|
|
102
|
+
{spellsToDisplay.map(spell => (
|
|
103
|
+
<Fragment key={spell.key}>
|
|
104
|
+
<Spell
|
|
105
|
+
charMana={mana}
|
|
106
|
+
charMagicLevel={magicLevel}
|
|
107
|
+
onClick={
|
|
108
|
+
settingShortcutIndex !== -1 ? setShortcut : onSpellClick
|
|
109
|
+
}
|
|
110
|
+
spellKey={spell.key}
|
|
111
|
+
isSettingShortcut={settingShortcutIndex !== -1}
|
|
112
|
+
{...spell}
|
|
113
|
+
/>
|
|
114
|
+
</Fragment>
|
|
115
|
+
))}
|
|
116
|
+
</SpellList>
|
|
117
|
+
</Container>
|
|
118
|
+
</DraggableContainer>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const Title = styled.h1`
|
|
123
|
+
font-size: ${uiFonts.size.large} !important;
|
|
124
|
+
margin-bottom: 0 !important;
|
|
125
|
+
`;
|
|
126
|
+
|
|
127
|
+
const Container = styled.div`
|
|
128
|
+
width: 100%;
|
|
129
|
+
height: 100%;
|
|
130
|
+
color: white;
|
|
131
|
+
display: flex;
|
|
132
|
+
flex-direction: column;
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
const SpellList = styled.div`
|
|
136
|
+
width: 100%;
|
|
137
|
+
min-height: 0;
|
|
138
|
+
flex: 1;
|
|
139
|
+
overflow-y: auto;
|
|
140
|
+
display: flex;
|
|
141
|
+
flex-direction: column;
|
|
142
|
+
gap: 1.5rem;
|
|
143
|
+
margin-top: 1rem;
|
|
144
|
+
`;
|