-
Notifications
You must be signed in to change notification settings - Fork 0
/
MULI_WindowTextField.js
1359 lines (1231 loc) · 41.7 KB
/
MULI_WindowTextField.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
//-----===================================================================-----
// MULI_WindowTextField.js
//-----===================================================================-----
/*:zh_TW
* @target MV MZ
* @plugindesc 仿原生文字框輸入,運用透明<input>
* @author moonyoulove
* @url https://github.com/moonyoulove/RPGMakerPlugins/blob/main/MULI_WindowTextField.js
*
* @help
* 插件命令:
* TextField input 5 1 true true // 參數依序為最大字數、變量ID、
* 允許空白和允許取消,變量的內容會做為預設文字。
*
* 名稱輸入處理指令,會判斷最近一次的輸入操作是鼠標鍵盤還是搖桿,
* 來啟用與禁用鍵盤輸入,原本的字符表也會隨之禁用或啟用。
*
* @command input
* @text 輸入文字
* @desc
*
* @arg maxLength
* @text 最大長度
* @desc
* @default -1
* @type number
* @min -1
*
* @arg variableId
* @text 變量ID
* @desc
* @default 0
* @type number
* @min 0
*
* @arg allowEmpty
* @text 允許留空
* @desc
* @default false
* @type boolean
*
* @arg allowCancel
* @text 允許取消
* @desc
* @default false
* @type boolean
*
* @param window
* @text -----視窗-----
*
* @param defaultWidth
* @parent window
* @text 預設寬度
* @desc 沒有設最大字數時的預設寬度
* @default 480
* @type number
*
* @param minWidth
* @parent window
* @text 最小寬度
* @desc 設有最大字數時自動適應的最小寬度,0=無限制
* @default 240
* @type number
* @min 0
*
* @param maxWidth
* @parent window
* @text 最大寬度
* @desc 設有最大字數時自動適應的最大寬度,0=遊戲寬度
* @default 0
* @type number
* @min 0
*
* @param windowHeight
* @parent window
* @text 視窗高度
* @desc 0=自動適應一個行高
* @default 0
* @type number
* @min 0
*
* @param textField
* @text -----文字框-----
*
* @param textFieldY
* @parent textField
* @text 文字框y座標
* @desc 視窗內文字框的位置,對齊為"none"時才有效
* @default 0
* @type number
*
* @param textFieldAlign
* @parent textField
* @text 文字框y座標對齊
* @desc
* @default center
* @type select
* @option 靠上
* @value top
* @option 置中
* @value center
* @option 靠下
* @value bottom
* @option 無
* @value none
*
* @param button
* @text -----按鈕-----
*
* @param buttonImage
* @parent button
* @text 按鈕圖片
* @desc MV可以使用TextFieldButton.png,MZ可以留空使用預設圖片
* @default TextFieldButton
* @type file
* @dir img/system
* @require 1
*
* @param buttonHeight
* @parent button
* @text 按鈕高度
* @desc
* @default 48
* @type number
* @min 1
*
* @param buttonAlign
* @parent button
* @text 按鈕水平對齊
* @desc 相對於視窗的位置
* @default center
* @type select
* @option 靠左
* @value left
* @option 置中
* @value center
* @option 靠右
* @value right
*
* @param buttonCancel
* @parent button
* @text -----取消按鈕-----
*
* @param buttonCancelX
* @parent buttonCancel
* @text 取消按鈕在圖片裡的X座標
* @desc
* @default 0
* @type number
*
* @param buttonCancelWidth
* @parent buttonCancel
* @text 取消按鈕的寬度
* @desc
* @default 96
* @type number
* @min 1
*
* @param buttonOk
* @parent button
* @text -----確認按鈕-----
*
* @param buttonOkX
* @parent buttonOk
* @text 確認按鈕在圖片裡的X座標
* @desc
* @default 96
* @type number
*
* @param buttonOkWidth
* @parent buttonOk
* @text 確認按鈕的寬度
* @desc
* @default 96
* @type number
* @min 1
*
* @param text
* @text -----文字-----
*
* @param selectionColor
* @parent text
* @text 反白顏色
* @desc 留空則自動檢測視窗指標的圖片顏色
* @default
* @type string
*
* @param textAlign
* @parent text
* @text 文字水平對齊
* @desc 文字框內文字水平對齊
* @default left
* @type select
* @option 靠左
* @value left
* @option 置中
* @value center
* @option 靠右
* @value right
*
* @param nameEdit
* @text -----更改名字-----
*
* @param hideTable
* @parent nameEdit
* @text 隱藏字符輸入表
* @desc 最後操作裝置非搖桿時,將字符表隱藏
* @default false
* @type boolean
*/
/*:zh_CN
* @target MV MZ
* @plugindesc 仿原生文字框输入,运用透明<input>
* @author moonyoulove
* @url https://github.com/moonyoulove/RPGMakerPlugins/blob/main/MULI_WindowTextField.js
*
* @help
* 插件命令:
* TextField input 5 1 true true // 参数依序为最大字数、变量ID、
* 允许空白和允许取消,变量的内容会做为预设文字。
*
* 名称输入处理指令,会判断最近一次的输入操作是鼠标键盘还是摇杆,
* 来启用与禁用键盘输入,原本的字符表也会随之禁用或启用。
*
* @command input
* @text 输入文字
* @desc
*
* @arg maxLength
* @text 最大长度
* @desc
* @default -1
* @type number
* @min -1
*
* @arg variableId
* @text 变量ID
* @desc
* @default 0
* @type number
* @min 0
*
* @arg allowEmpty
* @text 允许留空
* @desc
* @default false
* @type boolean
*
* @arg allowCancel
* @text 允许取消
* @desc
* @default false
* @type boolean
*
* @param window
* @text -----视窗-----
*
* @param defaultWidth
* @parent window
* @text 预设宽度
* @desc 没有设最大字数时的预设宽度
* @default 480
* @type number
*
* @param minWidth
* @parent window
* @text 最小宽度
* @desc 设有最大字数时自动适应的最小宽度,0=无限制
* @default 240
* @type number
* @min 0
*
* @param maxWidth
* @parent window
* @text 最大宽度
* @desc 设有最大字数时自动适应的最大宽度,0=游戏宽度
* @default 0
* @type number
* @min 0
*
* @param windowHeight
* @parent window
* @text 视窗高度
* @desc 0=自动适应一个行高
* @default 0
* @type number
* @min 0
*
* @param textField
* @text -----文字框-----
*
* @param textFieldY
* @parent textField
* @text 文字框y座标
* @desc 视窗内文字框的位置,对齐为"none"时才有效
* @default 0
* @type number
*
* @param textFieldAlign
* @parent textField
* @text 文字框y座标对齐
* @desc
* @default center
* @type select
* @option 靠上
* @value top
* @option 置中
* @value center
* @option 靠下
* @value bottom
* @option 无
* @value none
*
* @param button
* @text -----按钮-----
*
* @param buttonImage
* @parent button
* @text 按钮图片
* @desc MV可以使用TextFieldButton.png,MZ可以留空使用预设图片
* @default TextFieldButton
* @type file
* @dir img/system
* @require 1
*
* @param buttonHeight
* @parent button
* @text 按钮高度
* @desc
* @default 48
* @type number
* @min 1
*
* @param buttonAlign
* @parent button
* @text 按钮水平对齐
* @desc 相对于视窗的位置
* @default center
* @type select
* @option 靠左
* @value left
* @option 置中
* @value center
* @option 靠右
* @value right
*
* @param buttonCancel
* @parent button
* @text -----取消按钮-----
*
* @param buttonCancelX
* @parent buttonCancel
* @text 取消按钮在图片里的X座标
* @desc
* @default 0
* @type number
*
* @param buttonCancelWidth
* @parent buttonCancel
* @text 取消按钮的宽度
* @desc
* @default 96
* @type number
* @min 1
*
* @param buttonOk
* @parent button
* @text -----确认按钮-----
*
* @param buttonOkX
* @parent buttonOk
* @text 确认按钮在图片里的X座标
* @desc
* @default 96
* @type number
*
* @param buttonOkWidth
* @parent buttonOk
* @text 确认按钮的宽度
* @desc
* @default 96
* @type number
* @min 1
*
* @param text
* @text -----文字-----
*
* @param selectionColor
* @parent text
* @text 反白颜色
* @desc 留空则自动检测视窗指标的图片颜色
* @default
* @type string
*
* @param textAlign
* @parent text
* @text 文字水平对齐
* @desc 文字框内文字水平对齐
* @default left
* @type select
* @option 靠左
* @value left
* @option 置中
* @value center
* @option 靠右
* @value right
*
* @param nameEdit
* @text -----更改名字-----
*
* @param hideTable
* @parent nameEdit
* @text 隐藏字符输入表
* @desc 最后操作装置非摇杆时,将字符表隐藏
* @default false
* @type boolean
*/
var MULI = MULI || {};
MULI.TextField = class { };
MULI.TextField.pluginName = "MULI_WindowTextField";
MULI.TextField.parameters = PluginManager.parameters("MULI_WindowTextField");
MULI.TextField.commands = {
input(maxLength, variableId, allowEmpty, allowCancel) {
$gameMessage.setTextField(maxLength, variableId, allowEmpty, allowCancel);
this.setWaitMode("message");
}
};
MULI.TextField.defaultWidth = Number(MULI.TextField.parameters.defaultWidth);
MULI.TextField.minWidth = Number(MULI.TextField.parameters.minWidth);
MULI.TextField.maxWidth = Number(MULI.TextField.parameters.maxWidth);
MULI.TextField.windowHeight = Number(MULI.TextField.parameters.windowHeight);
MULI.TextField.textFieldY = Number(MULI.TextField.parameters.textFieldY);
MULI.TextField.textFieldAlign = MULI.TextField.parameters.textFieldAlign;
MULI.TextField.textAlign = MULI.TextField.parameters.textAlign;
MULI.TextField.selectionColor = MULI.TextField.parameters.selectionColor;
MULI.TextField.buttonImage = MULI.TextField.parameters.buttonImage;
MULI.TextField.buttonHeight = Number(MULI.TextField.parameters.buttonHeight);
MULI.TextField.buttonAlign = MULI.TextField.parameters.buttonAlign;
MULI.TextField.buttonCancelX = Number(MULI.TextField.parameters.buttonCancelX);
MULI.TextField.buttonCancelWidth = Number(MULI.TextField.parameters.buttonCancelWidth);
MULI.TextField.buttonOkX = Number(MULI.TextField.parameters.buttonOkX);
MULI.TextField.buttonOkWidth = Number(MULI.TextField.parameters.buttonOkWidth);
MULI.TextField.hideTable = MULI.TextField.parameters.hideTable === "true";
if (Utils.RPGMAKER_NAME === "MV") {
function Window_StatusBase() {
this.initialize.apply(this, arguments);
}
Window_StatusBase.prototype = Object.create(Window_Selectable.prototype);
Window_StatusBase.prototype.constructor = Window_StatusBase;
Window_StatusBase.prototype.initialize = function (x, y, width, height) {
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
};
}
function Window_TextField() {
this.initialize.apply(this, arguments);
}
Window_TextField.prototype = Object.create(Window_StatusBase.prototype);
Window_TextField.prototype.constructor = Window_TextField;
Window_TextField.prototype.initialize = function (messageWindow) {
this._messageWindow = messageWindow;
const args = Utils.RPGMAKER_NAME === "MV" ? [0, 0, 0, 0] : [new Rectangle()];
Window_StatusBase.prototype.initialize.apply(this, args);
this.openness = 0;
this.createTextField();
this.createButtons();
this.deactivate();
};
Window_TextField.prototype.start = function () {
this.setTextFieldMaxLength($gameMessage.textFieldMaxLength());
this.setTextFieldValue(String($gameVariables.value($gameMessage.textFieldVariableId()) || ""));
this.updatePlacement();
this.updateTextField();
this.placeButtons();
this.updateButtonsVisiblity();
this.createContents();
this.refresh();
this.open();
this.activate();
};
Window_TextField.prototype.refresh = function () {
Window_StatusBase.prototype.refresh.call(this);
if (this._textField) {
this.drawTextFieldValue();
this.drawTextFieldLength();
}
};
Window_TextField.prototype.windowWidth = function () {
const maxLength = this._textField.maxLength;
if (maxLength >= 0) {
const textWidth = this.textWidth("永") * maxLength;
const lengthWidth = this.textWidth("0") * (maxLength.toString().length * 2 + 1);
const totalWidth = textWidth + lengthWidth + this.padding * 2;
return totalWidth.clamp(MULI.TextField.minWidth, MULI.TextField.maxWidth || Graphics.boxWidth);
} else {
return MULI.TextField.defaultWidth;
}
};
Window_TextField.prototype.windowHeight = function () {
return MULI.TextField.windowHeight || this.fittingHeight(1);
};
Window_TextField.prototype.updatePlacement = function () {
const messageY = this._messageWindow.y;
const spacing = 8;
this.width = this.windowWidth();
this.height = this.windowHeight();
this.x = (Graphics.boxWidth - this.width) / 2;
if (messageY >= Graphics.boxHeight / 2) {
this.y = messageY - this.height - spacing;
} else {
this.y = messageY + this._messageWindow.height + spacing;
}
};
Window_TextField.prototype.buttonY = function () {
const spacing = 8;
if (this._messageWindow.y >= Graphics.boxHeight / 2) {
return 0 - this._buttons[0].height - spacing;
} else {
return this.height + spacing;
}
};
Window_TextField.prototype.updateButtonsVisiblity = function () {
if (Utils.RPGMAKER_NAME === "MV" ? TouchInput.date > Input.date : ConfigManager.touchUI) {
this.showButtons();
} else {
this.hideButtons();
}
};
Window_TextField.prototype.createButtons = function () {
const bitmap = MULI.TextField.buttonImage ? ImageManager.loadSystem(MULI.TextField.buttonImage) : null;
const buttonHeight = MULI.TextField.buttonHeight;
this._buttons = [];
for (let i = 0; i < 2; i++) {
// @rmmz
const button = new Sprite_Button(["cancel", "ok"][i]);
if (bitmap) {
const x = [MULI.TextField.buttonCancelX, MULI.TextField.buttonOkX][i];
const buttonWidth = [MULI.TextField.buttonCancelWidth, MULI.TextField.buttonOkWidth][i];
button.bitmap = bitmap;
button.setColdFrame(x, 0, buttonWidth, buttonHeight);
button.setHotFrame(x, buttonHeight, buttonWidth, buttonHeight);
}
button.visible = false;
this._buttons.push(button);
this.addChild(button);
}
this._buttons[0].setClickHandler(this.onTextFieldCancel.bind(this));
this._buttons[1].setClickHandler(this.onTextFieldOk.bind(this));
};
Window_TextField.prototype.placeButtons = function () {
const numButtons = this._buttons.length;
const spacing = 16;
let totalWidth = -spacing;
for (let i = 0; i < numButtons; i++) {
totalWidth += this._buttons[i].width + spacing;
}
let x = 0;
switch (MULI.TextField.buttonAlign) {
case "left":
x = 0;
break;
case "center":
x = (this.width - totalWidth) / 2;
break;
case "right":
x = this.width - totalWidth;
break;
}
for (let j = 0; j < numButtons; j++) {
const button = this._buttons[j];
button.x = x;
button.y = this.buttonY();
x += button.width + spacing;
}
};
Window_TextField.prototype.showButtons = function () {
for (let i = 0; i < this._buttons.length; i++) {
this._buttons[i].visible = true;
}
};
Window_TextField.prototype.hideButtons = function () {
for (let i = 0; i < this._buttons.length; i++) {
this._buttons[i].visible = false;
}
};
Window_TextField.prototype.isOkEnabled = function () {
return $gameMessage.textFieldAllowEmpty() ? true : this._textField.value.length > 0;
};
Window_TextField.prototype.isOkTriggered = function () {
return Input.isTriggered('ok');
};
Window_TextField.prototype.isCancelEnabled = function () {
return $gameMessage.textFieldAllowCancel();
};
Window_TextField.prototype.onTextFieldOk = function () {
if (this.isOkEnabled()) {
this.processOk();
} else {
this.playBuzzerSound();
}
};
Window_TextField.prototype.onTextFieldCancel = function () {
if (this.isCancelEnabled()) {
this.processCancel();
} else {
this.playBuzzerSound();
}
};
Window_TextField.prototype.processOk = function () {
Window_StatusBase.prototype.processOk.call(this);
$gameVariables.setValue($gameMessage.textFieldVariableId(), this._textField.value);
this.end();
};
Window_TextField.prototype.processCancel = function () {
Window_StatusBase.prototype.processCancel.call(this);
this.end();
};
Window_TextField.prototype.end = function () {
this.close();
this.hideButtons();
this._messageWindow.terminateMessage();
};
// @rmmz
Window_TextField.prototype.setMessageWindow = function (messageWindow) {
this._messageWindow = messageWindow;
};
function Window_NameTextField() {
this.initialize.apply(this, arguments);
}
Window_NameTextField.prototype = Object.create(Window_NameEdit.prototype);
Window_NameTextField.prototype.constructor = Window_NameTextField;
Window_NameTextField.prototype.initialize = function (...args) {
// @rmmz mv:[actor, maxLength] mz:[rect]
Window_NameEdit.prototype.initialize.apply(this, args);
this._isKeyboardInput = true;
this._inputWindow = null;
this.createTextField();
this.setTextFieldValue(this._name);
this.setTextFieldMaxLength(this._maxLength);
this.activate();
};
// @rmmz
Window_NameTextField.prototype.setup = function (actor, maxLength) {
Window_NameEdit.prototype.setup.call(this, actor, maxLength);
this.updateTextField();
this.setTextFieldValue(this._name);
this.setTextFieldMaxLength(this._maxLength);
};
Window_NameTextField.prototype.createTextField = function () {
Window_NameEdit.prototype.createTextField.call(this);
this._textField.style.textAlign = "center";
};
Window_NameTextField.prototype.setKeyboardInput = function (value) {
this._isKeyboardInput = value;
};
Window_NameTextField.prototype._onTextFieldKeyDown = function (event) {
if (!this._isKeyboardInput) {
event.preventDefault();
} else {
Window_NameEdit.prototype._onTextFieldKeyDown.call(this, event);
}
};
Window_NameTextField.prototype.setInputWindow = function (window) {
this._inputWindow = window;
};
Window_NameTextField.prototype.onTextFieldOk = function () {
this._inputWindow.onNameOk();
};
Window_NameTextField.prototype.textFieldRect = function () {
const rect = this.itemRect(0);
rect.x = this.faceWidth();
rect.width = this.innerWidth - rect.x;
return rect;
};
Window_NameTextField.prototype.drawUnderline = function (index) { };
Window_NameTextField.prototype.drawChar = function (index) { };
Window_NameTextField.prototype.refresh = function () {
Window_NameEdit.prototype.refresh.call(this);
this.setCursorRect(0, 0, 0, 0);
if (this._textField) {
this.drawTextFieldValue();
this.drawTextFieldLength();
}
};
Window_NameTextField.prototype._onTextFieldInput = function (event) {
Window_NameEdit.prototype._onTextFieldInput.call(this, event);
this._name = this._textField.value;
};
Window_NameTextField.prototype.restoreDefault = function () {
this.setTextFieldValue(this._defaultName);
Window_NameEdit.prototype.restoreDefault.call(this);
};
function Scene_NameKeyboard() {
this.initialize.apply(this, arguments);
}
Scene_NameKeyboard.prototype = Object.create(Scene_Name.prototype);
Scene_NameKeyboard.prototype.constructor = Scene_NameKeyboard;
Scene_NameKeyboard.prototype.initialize = function () {
Scene_Name.prototype.initialize.call(this);
};
Scene_NameKeyboard.prototype.createEditWindow = function () {
// 替換
Window_NameEdit = new Proxy(Window_NameEdit, {
construct(target, args, newTarget) {
Window_NameEdit = target;
return new Window_NameTextField(...args);
}
});
Scene_Name.prototype.createEditWindow.call(this);
};
Scene_NameKeyboard.prototype.createInputWindow = function () {
Scene_Name.prototype.createInputWindow.call(this);
this._editWindow.setInputWindow(this._inputWindow);
};
Scene_NameKeyboard.prototype.start = function () {
Scene_Name.prototype.start.call(this);
if (Input.gamepadDate > TouchInput.date && Input.gamepadDate >= Input.date) {
this._editWindow.setKeyboardInput(false);
} else {
this._inputWindow.deselect();
this._inputWindow.deactivate();
if (MULI.TextField.hideTable) {
this._inputWindow.hide();
this._editWindow.y = (Graphics.boxHeight - this._editWindow.height) / 2;
this._editWindow.updateTextFieldPosition();
}
}
};
(() => {
if (Utils.RPGMAKER_NAME === "MV") {
Object.defineProperty(Window.prototype, "innerWidth", {
get: function () {
return Math.max(0, this._width - this._padding * 2);
},
configurable: true
});
Object.defineProperty(Window.prototype, "innerHeight", {
get: function () {
return Math.max(0, this._height - this._padding * 2);
},
configurable: true
});
} else {
PluginManager.registerCommand(MULI.TextField.pluginName, "input", function (args) {
MULI.TextField.commands.input.call(this, Number(args.maxLength), Number(args.variableId), args.allowEmpty === "true", args.allowCancel === "true");
});
Window_Base.prototype.canvasToLocalX = function (x) {
var node = this;
while (node) {
x -= node.x;
node = node.parent;
}
return x;
};
Window_Base.prototype.canvasToLocalY = function (y) {
var node = this;
while (node) {
y -= node.y;
node = node.parent;
}
return y;
};
const _Scene_Message_createAllWindows = Scene_Message.prototype.createAllWindows;
Scene_Message.prototype.createAllWindows = function () {
this.createTextFieldWindow();
_Scene_Message_createAllWindows.call(this);
};
Scene_Message.prototype.createTextFieldWindow = function () {
this._textFieldWindow = new Window_TextField();
this.addWindow(this._textFieldWindow);
};
const _Scene_Message_associateWindows = Scene_Message.prototype.associateWindows;
Scene_Message.prototype.associateWindows = function () {
_Scene_Message_associateWindows.call(this);
const messageWindow = this._messageWindow;
messageWindow.setTextFieldWindow(this._textFieldWindow);
this._textFieldWindow.setMessageWindow(messageWindow);
};
}
const _Scene_Base_terminate = Scene_Base.prototype.terminate;
Scene_Base.prototype.terminate = function () {
_Scene_Base_terminate.call(this);
if (this._windowLayer) {
// @rmmz mz的windowlayer沒有removeChildren
this._windowLayer.destroy();
}
};
// 要使用文字框時必須
Window_Base.prototype.createTextField = function () {
this.on("added", this._onAdded, this);
this.on("removed", this._onRemoved, this);
this.createTextFieldElement();
this.updateTextField();
};
Window_Base.prototype.createTextFieldElement = function () {
this._textField = document.createElement("input");
this._textField.tabIndex = -1;
this._textField.className = "text-field";
this._textField.dataset.fontScale = "1";
this._textField.style.textAlign = MULI.TextField.textAlign;
this._textField.addEventListener("blur", this._onTextFieldLostFocus.bind(this));
this._textField.addEventListener("keydown", this._onTextFieldKeyDown.bind(this));
this._textField.addEventListener("input", this._onTextFieldInput.bind(this));
this._textField.addEventListener("contextmenu", this._onTextFieldRightClick.bind(this));
this._textField.addEventListener("compositionstart", this._onTextFieldCompositionStart.bind(this));
this._textField.addEventListener("compositionend", this._onTextFieldCompositionEnd.bind(this));
this._textField.addEventListener("keyup", this._onTextFieldKeyUp.bind(this));
};
Window_Base.prototype._onAdded = function () {
document.body.appendChild(this._textField);
Graphics.addTextFieldWindow(this);
if (this.active) {
this._textField.focus();
}
this.updateTextFieldPosition();
};
Window_Base.prototype._onRemoved = function () {
this._textField.disabled = true;
document.body.removeChild(this._textField);
Graphics.deleteTextFieldWindow(this);
};
Window_Base.prototype._onTextFieldLostFocus = function (event) {
this._textField.focus();
};
Window_Base.prototype._onTextFieldKeyDown = function (event) {
if (!event.code.match(/F\d+/)) {
event.stopPropagation();
}
if (event.repeat) {
this._textField.dataset.repeated = "true";
} else {
this._textField.dataset.composed = "false";
}
};
Window_Base.prototype._onTextFieldCompositionStart = function (event) {
// override
};
Window_Base.prototype._onTextFieldCompositionEnd = function (event) {
this._textField.dataset.composed = "true";
};
Window_Base.prototype._onTextFieldKeyUp = function (event) {
const dataset = this._textField.dataset;
if (this.active && dataset.repeated !== "true" && dataset.composed !== "true") {
switch (event.code) {
case "Enter":
this.onTextFieldOk();
break;
case "Escape":
this.onTextFieldCancel();
break;
}
}
dataset.repeated = "false";
};
Window_Base.prototype.onTextFieldOk = function () {
// override
};
Window_Base.prototype.onTextFieldCancel = function () {
// override
};
Window_Base.prototype._onTextFieldRightClick = function (event) {
event.preventDefault();
};
Window_Base.prototype.updateTextField = function () {
this.updateTextFieldPosition();
const rect = this.textFieldRect();
this._textField.style.width = Graphics.unit(rect.width);
this._textField.style.height = Graphics.unit(rect.height);
this._textField.style.caretColor = this.contents.textColor;
this._textField.style.fontFamily = this.contents.fontFace;
this.updateTextFieldFontSize();
const color = MULI.TextField.selectionColor || this.cursorColor();
this._textField.style.setProperty("--textField-selection-color", color);
};
Window_Base.prototype._onTextFieldInput = function (event) {
const width = this.textWidth(this._textField.value);
const maxWidth = this.textFieldRect().width;
this._textField.dataset.fontScale = String(width > maxWidth ? maxWidth / width : 1);
this.updateTextFieldFontSize();
this.refresh();
};
Window_Base.prototype.updateTextFieldFontSize = function () {
this._textField.style.fontSize = Graphics.unit(this.contents.fontSize * Number(this._textField.dataset.fontScale));
};
const _Window_Base_move = Window_Base.prototype.move;
Window_Base.prototype.move = function (x, y, width, height) {
width = width || this._width;
height = height || this._height;
let needsUpdate = false;
if (this.x !== x || this.y !== y && this._width === width && this._height === height) {
needsUpdate = true;
}
_Window_Base_move.call(this, x, y, width, height);
if (needsUpdate) {
this.updateTextFieldPosition();
}
};
const _Window_Base__refreshAllPart = Window_Base.prototype._refreshAllPart;
Window_Base.prototype._refreshAllPart = function () {
_Window_Base__refreshAllPart.call(this);
this.updateElement();
};
Window_Base.prototype.updateTextFieldPosition = function () {
if (this._textField) {
const rect = this.textFieldRect();
this._textField.style.left = Graphics.unit(this.padding + rect.x - this.canvasToLocalX(Graphics.pageToCanvasX(0)));
this._textField.style.top = Graphics.unit(this.padding + rect.y - this.canvasToLocalY(Graphics.pageToCanvasY(0)));
}
};
Window_Base.prototype.updateTextFieldVisibility = function () {
if (this._textField) {
this._textField.style.visibility = (this.visible && (this.isOpen() || this.isOpening()) && !this.isClosing()) ? "visible" : "hidden";
}
};
Window_Base.prototype.hideTextField = function () {
this._textField.style.visibility = "hidden";
};
const _Window_Base_open = Window_Base.prototype.open;
Window_Base.prototype.open = function () {
_Window_Base_open.call(this);
this.updateTextFieldVisibility();