@rpg-engine/long-bow 0.5.9 → 0.5.11

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.5.9",
3
+ "version": "0.5.11",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -13,6 +13,7 @@ import { ItemQuantitySelector } from './ItemQuantitySelector';
13
13
 
14
14
  import { IPosition } from '../../../types/eventTypes';
15
15
  import ModalPortal from '../../Abstractions/ModalPortal';
16
+ import SelectArrow from '../../Arrow/SelectArrow';
16
17
  import { ShortcutsSetter } from '../../Shortcuts/ShortcutsSetter';
17
18
  import { ItemSlot } from './ItemSlot';
18
19
 
@@ -81,12 +82,15 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
81
82
  onPositionChangeEnd,
82
83
  onPositionChangeStart,
83
84
  }) => {
85
+ const MAX_SLOTS_PER_PAGE = 20;
84
86
  const [quantitySelect, setQuantitySelect] = useState({
85
87
  isOpen: false,
86
88
  maxQuantity: 1,
87
- callback: (_quantity: number) => {},
89
+ callback: (_quantity: number) => { },
88
90
  });
89
91
  const [settingShortcutIndex, setSettingShortcutIndex] = useState(-1);
92
+ const [currentPage, setCurrentPage] = useState(1);
93
+ const totalPages = Math.ceil(itemContainer.slotQty / MAX_SLOTS_PER_PAGE);
90
94
 
91
95
  const handleSetShortcut = (item: IItem, index: number) => {
92
96
  if (item.type === ItemType.Consumable || item.type === ItemType.Tool) {
@@ -96,8 +100,10 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
96
100
 
97
101
  const onRenderSlots = () => {
98
102
  const slots = [];
103
+ const start = (currentPage - 1) * MAX_SLOTS_PER_PAGE;
104
+ const end = start + MAX_SLOTS_PER_PAGE;
99
105
 
100
- for (let i = 0; i < itemContainer.slotQty; i++) {
106
+ for (let i = start; i < end && i < itemContainer.slotQty; i++) {
101
107
  slots.push(
102
108
  <ItemSlot
103
109
  isContextMenuDisabled={disableContextMenu}
@@ -156,6 +162,14 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
156
162
  return slots;
157
163
  };
158
164
 
165
+ const goToNextPage = () => {
166
+ setCurrentPage(current => Math.min(current + 1, totalPages));
167
+ };
168
+
169
+ const goToPreviousPage = () => {
170
+ setCurrentPage(current => Math.max(current - 1, 1));
171
+ };
172
+
159
173
  return (
160
174
  <>
161
175
  <SlotsContainer
@@ -181,6 +195,32 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
181
195
  <ItemsContainer className="item-container-body">
182
196
  {onRenderSlots()}
183
197
  </ItemsContainer>
198
+ {totalPages > 1 && (
199
+ <ArrowContainer>
200
+ {currentPage > 1 && (
201
+ <SelectArrow
202
+ className='arrow .arrow-up'
203
+ direction="left"
204
+ onPointerDown={() => {
205
+ if (currentPage > 1) {
206
+ goToPreviousPage();
207
+ }
208
+ }}
209
+ />
210
+ )}
211
+ {currentPage < totalPages && (
212
+ <SelectArrow
213
+ className='arrow .arrow-down'
214
+ direction="right"
215
+ onPointerDown={() => {
216
+ if (currentPage < totalPages) {
217
+ goToNextPage();
218
+ }
219
+ }}
220
+ />
221
+ )}
222
+ </ArrowContainer>
223
+ )}
184
224
  </SlotsContainer>
185
225
  {quantitySelect.isOpen && (
186
226
  <ModalPortal>
@@ -192,7 +232,7 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
192
232
  setQuantitySelect({
193
233
  isOpen: false,
194
234
  maxQuantity: 1,
195
- callback: () => {},
235
+ callback: () => { },
196
236
  });
197
237
  }}
198
238
  onClose={() => {
@@ -200,7 +240,7 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
200
240
  setQuantitySelect({
201
241
  isOpen: false,
202
242
  maxQuantity: 1,
203
- callback: () => {},
243
+ callback: () => { },
204
244
  });
205
245
  }}
206
246
  />
@@ -229,3 +269,17 @@ const QuantitySelectorContainer = styled.div`
229
269
  align-items: center;
230
270
  background-color: rgba(0, 0, 0, 0.5);
231
271
  `;
272
+
273
+ const ArrowContainer = styled.div`
274
+ margin-top: 10px;
275
+ margin-bottom: 30px;
276
+ /* Aplica a margem ao primeiro span (seta para a esquerda) */
277
+ span:first-child {
278
+ margin-left: 20px;
279
+ }
280
+
281
+ /* Aplica a margem ao último span (seta para a direita) */
282
+ span:last-child {
283
+ margin-right: 20px;
284
+ }
285
+ `;
@@ -577,7 +577,7 @@ export const itemContainerMock: IItemContainer = {
577
577
  _id: '629ba0b6fe3f43002f58f23b',
578
578
  name: 'Item Container',
579
579
  owner: '629ba0b6fe3f43002f58f23b',
580
- slotQty: 20,
580
+ slotQty: 60,
581
581
  slots: {
582
582
  0: items[0],
583
583
  1: items[1],
@@ -595,6 +595,7 @@ export const itemContainerMock: IItemContainer = {
595
595
  13: items[13],
596
596
  14: items[14],
597
597
  15: items[15],
598
+ 21: items[15],
598
599
  //remaining slots are considered null by default
599
600
  },
600
601
  allowedItemTypes: [],