-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathRS_Inventory.js
1619 lines (1383 loc) · 48.5 KB
/
RS_Inventory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable no-unused-vars */
/* eslint-disable class-methods-use-this */
//================================================================
// RS_Inventory.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2015-2019 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @target MV
* @plugindesc This plugin allows you to use certain item and show gold using modern game inventory system. <RS_Inventory>
* @author biud436
*
* @param variableId
* @text variableId
*
* @param variableIdX
* @text variableIdX
* @parent variableId
* @type variable
* @desc Store x-position of inventory window to certain game variable.
* @default 9
*
* @param variableIdY
* @text y variable ID
* @parent variableId
* @type variable
* @desc Store y-position of inventory window to specific game variable.
* @default 10
*
* @param item-box
*
* @param item-width
* @parent item-box
* @type number
* @desc the width of item slot.
* @default 32
*
* @param item-height
* @parent item-box
* @type number
* @desc the height of item slot.
* @default 32
*
* @param divide-area-for-height
* @type number
* @desc the number of item slot in one row.
* @default 8
*
* @help
* This plugin implements inventory functionality.
* It mainly has the ability to use items, move them to different slots by dragging and display tooltips.
*
* However, this plugin is still under development, so it does not have a detailed documentation.
*
* == Known bugs ==
* 1. When an item is in a slot other than slot 0, picking up the same item will move it to slot 0.
*/
(() => {
'use strict';
let $gameInventory = {};
const { parameters } = $plugins.filter(function (i) {
return i.description.contains('<RS_Inventory>');
})[0];
/**
* @type {Record<'MOUSE_OVER' | 'MOUSE_OUT' | 'DRAGGING', any>}
*/
const MOUSE_STATE = {
MOUSE_OVER: 'MOUSE_OVER',
MOUSE_OUT: 'MOUSE_OUT',
DRAGGING: 'DRAGGING',
};
/**
* Params
* @enum {Object}
*/
const Params = {};
/**
* @type {Point}
*/
Params.id = new Point(
Number(parameters.variableIdX),
Number(parameters.variableIdY)
);
Params.itemBox = {
width: Number(parameters['item-width']),
height: Number(parameters['item-height']),
};
Params.maxRows = Number(parameters['divide-area-for-height']);
//==========================================================
// Game_Temp
//==========================================================
Object.defineProperty(Game_System, 'inventoryX', {
get() {
const variableId = Params.id.x;
return $gameVariables.value(variableId);
},
set(value) {
const variableId = Params.id.x;
$gameVariables.setValue(variableId, value);
},
configurable: true,
});
Object.defineProperty(Game_System, 'inventoryY', {
get() {
const variableId = Params.id.y;
return $gameVariables.value(variableId);
},
set(value) {
const variableId = Params.id.y;
$gameVariables.setValue(variableId, value);
},
configurable: true,
});
//==========================================================
// ItemCommand
//==========================================================
class ItemCommand {
/**
*
* @param {Game_BattlerBase|Game_Battler|Game_Actor|Game_Enemy} user
* @param {RPG.UsableItem} item
*/
constructor(user, item) {
this._user = user;
this._item = new Game_Item(item);
}
itemTargetActors() {
const action = new Game_Action($gameParty.leader());
action.setItemObject(this._item.object());
if (!action.isForFriend()) {
return [];
// eslint-disable-next-line no-else-return
} else if (action.isForAll()) {
return $gameParty.members();
} else {
return [$gameParty.members()[0]];
}
}
run() {
const item = this._item;
const numOfItem = $gameParty.numItems(item.object());
if (!item) {
return;
}
if (numOfItem <= 0) {
return;
}
const { _user: user } = this;
const action = new Game_Action(user);
if (item.isItem()) {
action.setItemObject(item.object());
this.itemTargetActors().forEach(target => {
for (let i = 0; i < action.numRepeats(); i++) {
action.apply(target);
}
});
action.applyGlobal();
$gameParty.gainItem(item.object(), -1);
SoundManager.playUseItem();
}
}
}
//==========================================================
// DraggingableSprite
//==========================================================
class DraggingableSprite extends Sprite {
constructor() {
super();
this.initMembers();
this.initComponents();
this.on('removed', this.dispose, this);
}
dispose() {
this.removeComponents();
}
initMembers() {
const { width: w, height: h } = Params.itemBox;
this._size = new Rectangle(0, 0, w, h);
this._divideAreaForHeight = Params.maxRows;
this._startX = this.x;
this._startY = this.y;
this._draggingTime = 0;
/**
* @type {'MOUSE_OVER'|'MOUSE_OUT'|'DRAGGING'|'CLICKED'|'NONE'}
*/
this._currentState = '';
}
/**
* 이벤트 리스너를 생성합니다.
* @method initComponents
*/
initComponents() {
this.on('onDragStart', this.onDragStart, this);
this.on('onDragEnd', this.onDragEnd, this);
this.on('onDragMove', this.onDragMove, this);
this.on('onButtonTriggered', this.onButtonTriggered, this);
this.on('onButtonReleased', this.onButtonReleased, this);
this.on('onButtonEnter', this.onButtonEnter, this);
this.on('onButtonExit', this.onButtonExit, this);
}
/**
* 이벤트 리스너를 제거합니다.
* @method removeComponents
*/
removeComponents() {
this.off('onDragStart', this.onDragStart, this);
this.off('onDragEnd', this.onDragEnd, this);
this.off('onDragMove', this.onDragMove, this);
this.off('onButtonTriggered', this.onButtonTriggered, this);
this.off('onButtonReleased', this.onButtonReleased, this);
this.off('onButtonEnter', this.onButtonEnter, this);
this.off('onButtonExit', this.onButtonExit, this);
}
/**
* 드래그 시작
* @param {MouseEvent} event
*/
emitOnDragStart(event) {
if (this.children != null) {
this.children.forEach(e => {
e.emit('onDragStart', event);
e.emit('onButtonTriggered', event);
});
}
}
/**
* 드래그 종료
* @param {MouseEvent} event
*/
emitOnDragEnd(event) {
if (this.children != null) {
this.children.forEach(e => {
e.emit('onDragEnd', event);
e.emit('onButtonReleased', event);
});
}
}
/**
* 드래그 중
* @param {MouseEvent} event
*/
emitOnDragMove(event) {
if (this.children != null) {
this.children.forEach(e => {
e.emit('onDragMove', event);
});
}
}
emitOnButtonEnter(event) {
if (this.children != null) {
this.children.forEach(e => {
e.emit('onButtonEnter', event);
});
}
}
emitOnButtonExit(event) {
if (this.children != null) {
this.children.forEach(e => {
e.emit('onButtonExit', event);
});
}
}
isInside(data) {
const px = this.parent.x || 0;
const py = this.parent.y || 0;
const x = px + this.x;
const y = py + this.y;
const mx = data.x;
const my = data.y;
const tw = x + this._size.width;
const th = y + this._size.height / this._divideAreaForHeight;
let inside = false;
if (mx > x && mx < tw) {
if (my > y && my < th) {
inside = true;
}
}
return inside;
}
/**
* @param {MouseEvent} event 마우스 이벤트
* @param {Boolean} skipEmit true이면 자식에게 이벤트가 전파되지 않습니다.
*/
onDragStart(event, skipEmit) {
this.data = new PIXI.Point(
Graphics.pageToCanvasX(event.pageX),
Graphics.pageToCanvasY(event.pageY)
);
const inside = this.isInside(this.data);
if (inside && event.button === 0) {
this.padding = new PIXI.Point(
this.data.x - this.x,
this.data.y - this.y
);
this.alpha = 0.5;
this.dragging = true;
this._draggingTime = 0;
}
if (!skipEmit) this.emitOnDragStart(event);
this.onButtonExit(event);
}
/**
* onDragEnd 이벤트 리스너
* @param {MouseEvent} event 마우스 이벤트
* @param {Boolean} skipEmit true이면 자식에게 이벤트가 전파되지 않습니다.
*/
onDragEnd(event, skipEmit) {
this.alpha = 1;
this.dragging = false;
this._draggingTime = 0;
this.data = null;
this.padding = null;
if (!skipEmit) this.emitOnDragEnd(event);
}
/**
* onDragMove 이벤트 리스너
* @param {MouseEvent} event 마우스 이벤트
* @param {Boolean} skipEmit true이면 자식에게 이벤트가 전파되지 않습니다.
*/
onDragMove(event, skipEmit) {
if (!this.dragging) {
const data = new PIXI.Point(
Graphics.pageToCanvasX(event.pageX),
Graphics.pageToCanvasY(event.pageY)
);
if (this.isInside(data)) {
if (this._currentState !== MOUSE_STATE.MOUSE_OVER) {
this._currentState = MOUSE_STATE.MOUSE_OVER;
}
this.onButtonEnter(event);
} else {
if (this._currentState === MOUSE_STATE.MOUSE_OVER) {
this.onButtonExit(event);
}
this._currentState = MOUSE_STATE.MOUSE_OUT;
}
}
if (this.dragging) {
this._currentState = MOUSE_STATE.DRAGGING;
this.data = new PIXI.Point(
Graphics.pageToCanvasX(event.pageX),
Graphics.pageToCanvasY(event.pageY)
);
const newPosition = this.data;
this.x = newPosition.x - this.padding.x;
this.y = newPosition.y - this.padding.y;
if (!this._draggingTime) this._draggingTime = 0;
this._draggingTime++;
}
if (!skipEmit) this.emitOnDragMove(event);
}
/**
* 부모에 대한 상대 좌표를 절대 좌표로 변경합니다.
* @param {Number} x
*/
canvasToLocalX(x) {
let node = this;
while (node) {
x -= node.x;
node = node.parent;
}
return x;
}
/**
* 부모에 대한 상대 좌표를 절대 좌표로 변경합니다.
* @param {Number} y
*/
canvasToLocalY(y) {
let node = this;
while (node) {
y -= node.y;
node = node.parent;
}
return y;
}
/**
* 버튼을 눌렀을 때
* @param {MouseEvent} event
* @param {Boolean} skipEmit true이면 자식에게 이벤트가 전파되지 않습니다.
*/
onButtonTriggered(event, skipEmit) {
console.log('event', event);
console.log('skipEmit', skipEmit);
}
/**
* 버튼을 똈을 때
* @param {MouseEvent} event
* @param {Boolean} skipEmit true이면 자식에게 이벤트가 전파되지 않습니다.
*/
onButtonReleased(event, skipEmit) {}
/**
* onButtonEnter
* @param {MouseEvent} event
* @param {Boolean} skipEmit true이면 자식에게 이벤트가 전파되지 않습니다.
*/
onButtonEnter(event, skipEmit) {}
/**
* onButtonExit
* @param {MouseEvent} event
* @param {Boolean} skipEmit true이면 자식에게 이벤트가 전파되지 않습니다.
*/
onButtonExit(event, skipEmit) {}
setAnchor(x, y) {
this.pivot.set(x, y);
}
}
//==========================================================
// InventoryItem
//==========================================================
const assignValues = Symbol('assignValues');
class InventoryItem extends DraggingableSprite {
/**
* @param {Number} index the index into an inventory.
* @param {Object} item the object contains the information for the item.
*/
constructor(index, slotIndex) {
super();
this._index = index;
this._slotIndex = slotIndex;
this.setAnchor(0.5, 0.5);
this._item = null;
this.initBitmaps();
}
initMembers() {
super.initComponents();
const { width: w, height: h } = Params.itemBox;
this._size = new PIXI.Rectangle(0, 0, w, h);
this._divideAreaForHeight = 1;
this._isOnTooltip = false;
this._startX = this.x;
this._startY = this.y;
this._lastButton = 0;
}
getItem() {
return this._item.item;
}
initBitmaps() {
this._item = $gameInventory._slots[this._slotIndex];
const { width: w, height: h } = this._size;
const bitmap = ImageManager.loadSystem('IconSet');
const { iconIndex } = this._item;
const pw = Window_Base._iconWidth;
const ph = Window_Base._iconHeight;
const sx = (iconIndex % 16) * pw;
const sy = Math.floor(iconIndex / 16) * ph;
const num = $gameParty.numItems(this._item.item);
this._background = new Sprite(new Bitmap(w, h));
this._background.bitmap.fontSize = 12;
this._background.bitmap.blt(bitmap, sx, sy, pw, ph, 0, 0);
this._background.bitmap.textColor = 'white';
this._background.bitmap.drawText(
num,
0,
(h - 2) / 6,
w - 2,
h,
'right'
);
this.addChild(this._background);
}
update() {
super.update();
}
[assignValues](func) {
const { width: w, height: h } = this._size;
const dw = w * Params.maxRows;
func(w, h, dw);
}
savePosition() {
this[assignValues]((w, h, dw) => {
this._startX = this.x.clamp(0, dw - w);
this._startY = this.y.clamp(h, dw - h);
this._startPX = this.x.clamp(0, dw - w);
this._startPY = this.y.clamp(h, dw - h);
});
}
updatePosition() {
this[assignValues]((w, h, dw) => {
this._startPX = this.x.clamp(0, dw - w);
this._startPY = this.y.clamp(h, dw - h);
});
}
checkRestorePosition() {
if (!this.parent) return;
const w = this._size.width;
const h = this._size.height;
const pw = this.parent._size.width;
const ph = this.parent._size.height;
const startY = this._startY;
const { x, y } = this;
if (x < 0 || x > pw - w) {
this.x = this._startPX;
}
if (y < h || startY > ph - h) {
this.y = this._startPY;
}
}
setGrid() {
const { parent } = this;
if (!parent) return;
const { width: w, height: h } = this._size;
const { maxRows } = Params;
// 그리드 좌표를 구함 (32등분)
const gridX = Math.floor(this.x / w).clamp(0, maxRows - 1);
const gridY = Math.floor(this.y / h).clamp(0, maxRows - 1);
// 그리드에서의 인덱스를 찾는다 (0 ~ 63)
const index = maxRows * gridY + gridX - maxRows;
// 해당 슬롯에 아이템이 있는지 확인
if (!$gameInventory.isExist(index)) {
this.x = gridX * w;
this.y = gridY * h;
const prevIndex = this._index;
this._index = index;
$gameInventory.moveTo(prevIndex, index);
} else {
// 아이템이 있는 위치에는 옮길 수 없다.
// 나중에 교환 처리로 바꾸자.
this.x = this._startX;
this.y = this._startY;
}
}
onDragStart(event) {
this._isDragEnd = false;
this.savePosition();
super.onDragStart(event, true);
}
onDragEnd(event) {
super.onDragEnd(event, true);
// 그리드에 정렬합니다.
if (
!this._isDragEnd &&
event.button === 0 &&
this._lastButton !== 2
) {
this.setGrid();
}
// 이 플래그가 없으면 그리드 함수가 6번 연속으로 실행되면서 버그를 일으킨다.
this._isDragEnd = true;
this._lastButton = event.button;
}
onDragMove(event) {
this.updatePosition();
super.onDragMove(event, true);
if (this.dragging && event.button === 0) {
// 밖으로 드래그 못하게 합니다.
this.checkRestorePosition();
}
}
/**
* @param {MouseEvent} event
*/
onButtonTriggered(event, skipEmit) {
if (this.dragging) {
this.scale.x = 0.8;
this.scale.y = 0.8;
this._fire = true;
}
}
onButtonEnter(event, skipEmit) {
super.onButtonEnter(event, skipEmit);
console.log('onButtonEnter');
if (this.parent) {
this.parent.openTooltip(this);
}
}
onButtonExit(event, skipEmit) {
super.onButtonExit(event, skipEmit);
console.log('onButtonExit');
if (this.parent) {
this.parent.closeTooltip();
}
}
/**
* 드래깅 중인지 판단합니다.
* @return {Boolean} ret 드래깅 중이면 true, 아니면 false
*/
isValidDragging() {
const x = this._startX;
const px = this._startPX;
const y = this._startY;
const py = this._startPY;
if (
Math.abs(px - x) > this._size.width * 0.3 ||
Math.abs(py - y) > this._size.height * 0.3
) {
SoundManager.playEquip();
return true;
}
return false;
}
/**
* @param {MouseEvent} event
*/
onButtonReleased(event, skipEmit) {
if (this._fire) {
this.scale.x = 1.0;
this.scale.y = 1.0;
this._fire = false;
// 드래깅 중이라면 아이템 사용 처리를 하지 않는다.
if (this.isValidDragging()) {
return;
}
const itemCommand = new ItemCommand(
$gameParty.leader(),
this._item.item
);
itemCommand.run();
}
}
}
//==========================================================
// ToolTip
//==========================================================
Params.Tooltip = {
fontFace: '나눔고딕',
fontSize: 18,
textColor: 'white',
outlineWidth: 1,
outlineColor: 'blue',
};
class Tooltip extends Sprite {
constructor(bitmap) {
super(bitmap);
this.initMembers();
this.createTextLayer();
}
initMembers() {
this._size = new PIXI.Rectangle(0, 0, 128, 256);
}
/**
* Init with text layer.
*
* @returns {void}
*/
createTextLayer() {
this._textLayer = new Sprite();
this.addChild(this._textLayer);
}
/**
* @param {number} width
* @param {number} fontSize
* @returns {PIXI.TextStyle}
*/
makeNormalColor(width, fontSize = 16) {
const wordWrapWidth = width || this._size.width;
const style = new PIXI.TextStyle({
breakWords: true,
fillGradientStops: [0],
fill: 'white',
fontSize,
stroke: 'black',
strokeThickness: 2,
wordWrap: true,
wordWrapWidth,
});
return style;
}
/**
* @param {number} width
* @param {number} fontSize
* @returns {PIXI.TextStyle}
*/
makeRedColor(width, fontSize = 16) {
const wordWrapWidth = width || this._size.width;
const style = new PIXI.TextStyle({
breakWords: true,
dropShadow: true,
dropShadowBlur: 1,
dropShadowColor: '#262626',
dropShadowDistance: 0,
fill: '#f20000',
fontSize,
strokeThickness: 1,
wordWrap: true,
wordWrapWidth,
});
return style;
}
/**
* @param {number} width
* @param {number} fontSize
* @returns {PIXI.TextStyle}
*/
makeYellowColor(width, fontSize = 16) {
const wordWrapWidth = width || this._size.width;
const style = new PIXI.TextStyle({
breakWords: true,
dropShadow: true,
dropShadowBlur: 1,
dropShadowColor: '#262626',
dropShadowDistance: 0,
fill: ['#eff2b7', '#e3e97e'],
fillGradientStops: [0],
fontSize,
strokeThickness: 1,
wordWrap: true,
wordWrapWidth,
});
return style;
}
/**
* @param {number} width
* @param {number} fontSize
* @returns {PIXI.TextStyle}
*/
makeBlueGlowColor(width, fontSize = 16) {
const wordWrapWidth = width || this._size.width;
const style = new PIXI.TextStyle({
breakWords: true,
dropShadow: true,
dropShadowBlur: 6,
dropShadowColor: '#71f4ca',
dropShadowDistance: 0,
fillGradientStops: [0],
fontSize,
fontWeight: 600,
stroke: 'white',
strokeThickness: 2,
wordWrap: true,
wordWrapWidth,
});
return style;
}
/**
*
* @param {string} color
* @param {number} fontSize
* @param {number} width
* @returns {PIXI.TextStyle}
*/
makeColor(color, fontSize = 16, width = 0) {
width = width || this._size.width;
switch (color) {
// eslint-disable-next-line default-case-last
default:
case 'normal':
return this.makeNormalColor(width, fontSize);
case 'red':
return this.makeRedColor(width, fontSize);
case 'yellow':
return this.makeYellowColor(width, fontSize);
case 'blue':
return this.makeBlueGlowColor(width, fontSize);
}
}
/**
* @param {PIXI.Text} textObject
* @returns {void}
*/
addDescription(textObject) {
if (!this._textLayer) {
this.createTextLayer();
}
if (!(textObject instanceof PIXI.Text)) return;
this._textLayer.addChild(textObject);
}
/**
*
* @param {number} x
* @param {number} y
* @param {string} text
* @param {string} color
*
* @return {PIXI.Text}
*/
makeText(x, y, text, color) {
const textObj = new PIXI.Text(text, this.makeColor(color));
textObj.x = x;
textObj.y = y;
return textObj;
}
/**
* @returns {void}
*/
clear() {
this.removeChildren();
this.createTextLayer();
if (!this.bitmap) {
this.bitmap = new Bitmap(128, 256);
}
this.bitmap.clear();
this.bitmap.fillAll('rgba(0, 0, 0, 0.6)');
}
/**
* @param {RPG.BaseItem} item
*
* @returns {boolean}
*/
isValid(item) {
return (
DataManager.isItem(item) ||
DataManager.isWeapon(item) ||
DataManager.isArmor(item)
);
}
/**
* @param {RPG.BaseItem} item
*
* @returns {void}
*/
refresh(item) {
if (!this.isValid(item)) {
return;
}
this.clear();
// 누적 변수를 선언합니다.
let lineHeight = 0;
const pad = 2;
// 아이템 이름 (빨강)
const itemName = this.makeText(0, 0, item.name, 'red');
lineHeight += itemName.height;
lineHeight += pad;
this.addDescription(itemName);
// 아이템 설명 (노랑)
const itemDesc = this.makeText(
0,
lineHeight,
item.description,
'yellow'
);
lineHeight += itemDesc.height;
lineHeight += pad;
this.addDescription(itemDesc);
}
}
//==========================================================
// InventoryView
//==========================================================
class InventoryView extends DraggingableSprite {
constructor() {
super();
this.initBitmaps();
this.initBackground();
this.initSlots();
this.drawAllItems();
this.initTooltip();
}
initComponents() {
document.addEventListener('mousedown', this.onDragStart.bind(this));
document.addEventListener('mouseup', this.onDragEnd.bind(this));
document.addEventListener('mousemove', this.onDragMove.bind(this));
}
removeComponents() {
document.removeEventListener(
'mousedown',
this.onDragStart.bind(this)
);
document.removeEventListener('mouseup', this.onDragEnd.bind(this));
document.removeEventListener(
'mousemove',
this.onDragMove.bind(this)
);
}
initMembers() {
super.initMembers();
const size = Params.itemBox.width * 8;
const itemHeight = Params.itemBox.height;
this._divideAreaForHeight = Params.maxRows;
this._size = new PIXI.Rectangle(0, 0, 256, 256);
this._backgroundBitmap = new Bitmap(
this._size.width,
this._size.height + itemHeight
);
this._background = new Sprite();
this._data = $gameInventory.slots();
this._itemLayer = [];
this._itemIndex = 0;