/
DTextPicture.js
862 lines (789 loc) · 37.7 KB
/
DTextPicture.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
//=============================================================================
// DTextPicture.js
// ----------------------------------------------------------------------------
// (C) 2015 Triacontane
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
// ----------------------------------------------------------------------------
// Version
// 1.15.0 2019/10/21 カーソルのアクティブ状態を変更できるコマンドを追加
// アイテム表示の制御文字でアイコン表示可否を変更できる設定を追加
// 1.14.0 2019/01/13 背景ウィンドウにカーソル表示できる機能を追加
// 1.13.0 2018/11/25 背景色のグラデーションを設定できる機能を追加
// 1.12.0 2018/11/08 背景ウィンドウの透明度と文字列ピクチャの透明度を連動させるよう仕様変更
// 1.11.1 2018/10/20 プラグイン等でGame_Variables.prototype.setValueを呼んだとき、変数の添え字に文字列型の数値を渡した場合も変数のリアルタイム表示が効くよう修正
// 1.11.0 2018/10/13 公式プラグイン「TextDecoration.js」の設定を動的文字列に適用できる機能を追加
// 1.10.1 2018/05/30 アウトラインカラー取得で0およびその他の文字列を指定したときに正しく色が設定されない問題を修正(by奏ねこまさん)
// 1.10.0 2017/02/12 アウトラインカラーをウィンドウカラー番号から指定できる機能を追加
// 1.9.0 2017/08/20 ウィンドウつきピクチャが重なったときにウィンドウがピクチャの下に表示される問題を修正
// 1.8.6 2017/06/28 フォント変更機能のヘルプが抜けていたので追加
// 1.8.5 2017/06/12 変数がマイナス値のときのゼロ埋め表示が正しく表示されない問題を修正
// 1.8.4 2017/05/10 プラグインを未適用のデータを読み込んだとき、最初の一回のみ動的文字列ピクチャが作成されない問題を修正
// 1.8.3 2017/04/19 自動翻訳プラグインに一部対応
// 1.8.2 2017/04/05 ピクチャの消去時にエラーが発生していた問題を修正
// 1.8.1 2017/03/30 拡大率と原点に対応していなかった問題を修正
// 1.8.0 2017/03/30 背景にウィンドウを表示できる機能を追加
// 1.7.1 2017/03/20 1.7.0で末尾がイタリック体の場合に、傾き部分が見切れてしまう問題を修正
// 1.7.0 2017/03/20 動的文字列を太字とイタリックにできる機能を追加
// 複数行表示かつ制御文字でアイコンを指定した場合に高さが余分に計算されてしまう問題の修正
// 1.6.2 2016/12/13 動的ピクチャに対して、ピクチャの表示とピクチャの色調変更を同フレームで行うと画像が消える問題の修正
// 1.6.1 2016/11/03 一通りの競合対策
// 1.6.0 2016/11/03 インストールされているフォントをピクチャのフォントとして利用できる機能を追加
// 1.5.1 2016/10/27 1.5.0でアウトラインカラーを指定するとエラーになっていた現象を修正
// 1.5.0 2016/10/23 制御文字で表示した変数の内容をリアルタイム更新できる機能を追加
// 1.4.2 2016/07/02 スクリプトからダイレクトで実行した場合も制御文字が反映されるよう修正(ただし余分にエスケープする必要あり)
// 1.4.1 2016/06/29 制御文字「\{」で文字サイズを大きくした際、元のサイズに戻さないと正しいサイズで表示されない問題を修正
// 1.4.0 2016/06/28 D_TEXT実行後に画像を指定してピクチャを表示した場合は画像を優先表示するよう仕様変更
// 1.3.1 2016/06/07 描画文字が半角英数字のみかつフォントを未指定の場合に文字が描画されない不具合を修正
// 1.3.0 2016/06/03 制御文字\oc[c] \ow[n]に対応
// 1.2.2 2016/03/28 データベース情報を簡単に出力する制御文字を追加
// 1.2.1 2016/01/29 コマンド「D_TEXT_SETTING」の実装が「D_TEST_SETTING」になっていたので修正(笑)
// 1.2.0 2016/01/27 複数行表示に対応
// 文字列の揃えと背景色を設定する機能を追加
// 変数をゼロ埋めして表示する機能を追加
// 1.1.3 2015/12/10 戦闘画面でもピクチャを使用できるよう修正
// 描画後にデバッグ画面等を開いて変数を修正した場合、再描画で変更が反映されてしまう問題を修正
// 1.1.2 2015/11/07 描画文字列に半角スペースが含まれていた場合も問題なく実行できるよう修正
// 1.1.0 2015/11/07 制御文字\C[n] \I[n] \{ \} に対応(\$と表示スピード制御系以外全部)
// 1.0.1 2015/11/07 RPGツクールMV(日本語版)に合わせてコメントの表記を変更
// 1.0.0 2015/11/06 初版
// ----------------------------------------------------------------------------
// [Blog] : https://triacontane.blogspot.jp/
// [Twitter]: https://twitter.com/triacontane/
// [GitHub] : https://github.com/triacontane/
//=============================================================================
/*:
* @plugindesc [ ver.1.15.0 ]產生動態文字圖片
* @author トリアコンタン( 翻譯 : ReIris )
*
* @param itemIconSwitchId
* @text 道具圖標開關 ID
* @desc 當指定開關 ID 為 ON 時,將顯示帶有 \ITEM[n] 的圖標。
* 沒有指定的情況將常時顯示。
* @default 0
* @type switch
*
* @help 提供動態生成具有指定文字圖片的命令。
* 各種控制字元(\v[n]等)也可用於文字,並且當控制字元顯示的變數發生變化時,
* 您可以實時更新圖像的內容。
*
* 按以下步驟顯示動態文字圖片。
* 1 : 插件命令 [D_TEXT] 指定要繪製的文字和參數(參照下方範例)。
* 2 : 插件命令 [D_TEXT_SETTING] 指定背景顏色和對齊方式(任意)
* 3 : 事件命令「顯示圖片」,並且「圖片」未選擇圖片檔案。
* ※ 進行步驟 1 時不會直接顯示文字圖片,所以最後需要用「顯示圖片」的命令呼叫。
* ※ 在顯示圖片之前,通過多次執行 D_TEXT ,可以顯示多行文字。
*
* ※ 從ver1.4.0開始,如果在執行[D_TEXT]後在「顯示圖片」中指定「圖片」,
* 則暫停動態文字圖片生成並像往常一樣顯示「圖片」。
*
* 插件命令詳細
* 使用事件命令中的「插件命令」執行。
* (用空格分隔參數)
*
* D_TEXT [描繪文字內容] [文字大小] : 動態文字圖片生成準備
* 範例:D_TEXT 測試文字 32
*
* 顯示後,您可以像普通圖片一樣移動,旋轉和擦除。
* 文字顯示還支持控制字元,如變數和角色名稱的顯示。
*
* D_TEXT_SETTING ALIGN [對齊] : 對齊設定(左對齊、中間對齊、右對齊)
* 0 : 左對齊 / 1 : 中間對齊 / 2 : 右對齊
*
* 範例:D_TEXT_SETTING ALIGN 0
* D_TEXT_SETTING ALIGN CENTER
*
* D_TEXT_SETTING BG_COLOR [背景色] : 背景顏色設置(與 CSS 顏色規格相同的格式)
*
* 範例:D_TEXT_SETTING BG_COLOR black
* D_TEXT_SETTING BG_COLOR #336699
* D_TEXT_SETTING BG_COLOR rgba(255,255,255,0.5)
*
* 您可以指定背景色漸變(以像素為單位)。
* D_TEXT_SETTING BG_GRADATION_RIGHT [像素(px)]
* D_TEXT_SETTING BG_GRADATION_LEFT [像素(px)]
*
* 範例:D_TEXT_SETTING BG_GRADATION_RIGHT 50
* D_TEXT_SETTING BG_GRADATION_LEFT 50
*
* D_TEXT_SETTING REAL_TIME ON : 使用控制字元顯示變數的實時顯示
*
* 範例:D_TEXT_SETTING REAL_TIME ON
*
* 啟用實時顯示後,當顯示圖像後變數發生變化時,圖像內容也會自動更新。
*
* D_TEXT_SETTING WINDOW ON : 顯示窗口背景
* 範例:D_TEXT_SETTING WINDOW ON
*
* D_TEXT_SETTING FONT [字體名稱] : 更改描繪字體
* 範例:D_TEXT_SETTING FONT MS P明朝
*
* 與 D_TEXT 一樣,這些設置應在顯示圖片之前完成。
*
* 對應的控制字元一覽(與事件命令的「文章表示」一樣)
* \V[n]
* \N[n]
* \P[n]
* \G
* \C[n]
* \I[n]
* \{
* \}
*
* 専用控制字元
* \V[n,m]( m 為該變數的位數 )
* \item[n] n 個物品的訊息(圖標 + 名稱)
* \weapon[n] n 個武器的訊息(圖標 + 名稱)
* \armor[n] n 個防具的訊息(圖標 + 名稱)
* \skill[n] n 個技能的訊息(圖標 + 名稱)
* \state[n] n 個狀態的訊息(圖標 + 名稱)
* \oc[c] 將文字邊框顏色設置為「c」(※1)
* \ow[n] 將文字邊框寬度設置為「n」(例如\ ow [5])
* \f[b] 粗體字體
* \f[i] 斜體字體
* \f[n] 返回普通字體
*
* ※1 如何指定文字邊框顏色
* \oc[red] 由顏色名稱指定
* \oc[rgb(0,255,0)] 由顏色代碼指定
* \oc[2] 與文字代碼顏色編號 \c[n] 相同
*
* 當背景是以窗口顯示的時候,顯示光標。
* 在顯示動態文字圖片生成後執行這個命令。
* D_TEXT_WINDOW_CURSOR 1 ON # 在圖片 [1] 上顯示窗口光標。
* D_TEXT_WINDOW_CURSOR 2 OFF # 在圖片 [2] 上刪除窗口光標。
*
* 光標的狀態啟用變更命令可以透過以下內容。
* D_TEXT_WINDOW_CURSOR_ACTIVE 2 ON # 啟用圖片 [2] 的光標。
* D_TEXT_WINDOW_CURSOR_ACTIVE 1 OFF # 停止圖片 [1] 的光標。
*
* 要指定光標矩形的座標可以透過以下內容。
* D_TEXT_WINDOW_CURSOR 1 ON 0 0 100 100 # 在圖片 [1] 上顯示,
* # 大小為 [0,0,100,100] 的窗口光標。
*
* 利用規約:
* 不需要作者許可,可以進行修改和二次發布。
* 使用形式(商業用途,18禁使用等)沒有限制。
*/
(function() {
'use strict';
var getCommandName = function(command) {
return (command || '').toUpperCase();
};
var getArgNumber = function(arg, min, max) {
if (arguments.length < 2) min = -Infinity;
if (arguments.length < 3) max = Infinity;
return (parseInt(convertEscapeCharacters(arg.toString())) || 0).clamp(min, max);
};
var getArgString = function(arg, upperFlg) {
arg = convertEscapeCharacters(arg);
return upperFlg ? arg.toUpperCase() : arg;
};
var getArgBoolean = function(arg) {
return (arg || '').toUpperCase() === 'ON';
};
var connectArgs = function(args, startIndex, endIndex) {
if (arguments.length < 2) startIndex = 0;
if (arguments.length < 3) endIndex = args.length;
var text = '';
for (var i = startIndex; i < endIndex; i++) {
text += args[i];
if (i < endIndex - 1) text += ' ';
}
return text;
};
var convertEscapeCharacters = function(text) {
if (text === undefined || text === null) text = '';
var window = SceneManager.getHiddenWindow();
return window ? window.convertEscapeCharacters(text) : text;
};
var getUsingVariables = function(text) {
var usingVariables = [];
text = text.replace(/\\/g, '\x1b');
text = text.replace(/\x1b\x1b/g, '\\');
text = text.replace(/\x1bV\[(\d+),\s*(\d+)]/gi, function() {
var number = parseInt(arguments[1], 10);
usingVariables.push(number);
return $gameVariables.value(number);
}.bind(this));
text = text.replace(/\x1bV\[(\d+)]/gi, function() {
var number = parseInt(arguments[1], 10);
usingVariables.push(number);
return $gameVariables.value(number);
}.bind(this));
text = text.replace(/\x1bV\[(\d+)]/gi, function() {
var number = parseInt(arguments[1], 10);
usingVariables.push(number);
return $gameVariables.value(number);
}.bind(this));
return usingVariables;
};
/**
* Create plugin parameter. param[paramName] ex. param.commandPrefix
* @param pluginName plugin name(EncounterSwitchConditions)
* @returns {Object} Created parameter
*/
var createPluginParameter = function(pluginName) {
var paramReplacer = function(key, value) {
if (value === 'null') {
return value;
}
if (value[0] === '"' && value[value.length - 1] === '"') {
return value;
}
try {
return JSON.parse(value);
} catch (e) {
return value;
}
};
var parameter = JSON.parse(JSON.stringify(PluginManager.parameters(pluginName), paramReplacer));
PluginManager.setParameters(pluginName, parameter);
return parameter;
};
var textDecParam = createPluginParameter('TextDecoration');
var param = createPluginParameter('DTextPicture');
//=============================================================================
// Game_Interpreter
// プラグインコマンド[D_TEXT]を追加定義します。
//=============================================================================
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.apply(this, arguments);
this.pluginCommandDTextPicture(command, args);
};
Game_Interpreter.textAlignMapper = {
LEFT: 0, CENTER: 1, RIGHT: 2, 左: 0, 中央: 1, 右: 2
};
Game_Interpreter.prototype.pluginCommandDTextPicture = function(command, args) {
switch (getCommandName(command)) {
case 'D_TEXT' :
if (isNaN(args[args.length - 1]) || args.length === 1) args.push($gameScreen.dTextSize || 28);
var fontSize = getArgNumber(args.pop());
$gameScreen.setDTextPicture(connectArgs(args), fontSize);
break;
case 'D_TEXT_SETTING':
switch (getCommandName(args[0])) {
case 'ALIGN' :
$gameScreen.dTextAlign = isNaN(args[1]) ?
Game_Interpreter.textAlignMapper[getArgString(args[1], true)] : getArgNumber(args[1], 0, 2);
break;
case 'BG_COLOR' :
$gameScreen.dTextBackColor = getArgString(connectArgs(args, 1));
break;
case 'BG_GRADATION_LEFT' :
$gameScreen.dTextGradationLeft = getArgNumber(args[1], 0);
break;
case 'BG_GRADATION_RIGHT' :
$gameScreen.dTextGradationRight = getArgNumber(args[1], 0);
break;
case 'FONT':
args.shift();
$gameScreen.setDtextFont(getArgString(connectArgs(args)));
break;
case 'REAL_TIME' :
$gameScreen.dTextRealTime = getArgBoolean(args[1]);
break;
case 'WINDOW':
$gameScreen.dWindowFrame = getArgBoolean(args[1]);
break;
}
break;
case 'D_TEXT_WINDOW_CURSOR' :
var windowRect = null;
if (getArgBoolean(args[1])) {
windowRect = {
x : getArgNumber(args[3] || '', 0),
y : getArgNumber(args[4] || '', 0),
width : getArgNumber(args[5] || '', 0),
height: getArgNumber(args[6] || '', 0)
};
}
$gameScreen.setDTextWindowCursor(getArgNumber(args[0], 0), windowRect);
break;
case 'D_TEXT_WINDOW_CURSOR_ACTIVE' :
$gameScreen.setDTextWindowCursorActive(getArgNumber(args[0], 0), getArgBoolean(args[1]));
break;
}
};
//=============================================================================
// Game_Variables
// 値を変更した変数の履歴を取得します。
//=============================================================================
var _Game_Variables_setValue = Game_Variables.prototype.setValue;
Game_Variables.prototype.setValue = function(variableId, value) {
variableId = parseInt(variableId);
if (this.value(variableId) !== value) {
this._changedVariables = this.getChangedVariables();
if (!this._changedVariables.contains(variableId)) {
this._changedVariables.push(variableId);
}
}
_Game_Variables_setValue.apply(this, arguments);
};
Game_Variables.prototype.getChangedVariables = function() {
return this._changedVariables || [];
};
Game_Variables.prototype.clearChangedVariables = function() {
return this._changedVariables = [];
};
//=============================================================================
// Game_Screen
// 動的ピクチャ用のプロパティを追加定義します。
//=============================================================================
var _Game_Screen_clear = Game_Screen.prototype.clear;
Game_Screen.prototype.clear = function() {
_Game_Screen_clear.call(this);
this.clearDTextPicture();
};
Game_Screen.prototype.clearDTextPicture = function() {
this.dTextValue = null;
this.dTextOriginal = null;
this.dTextRealTime = null;
this.dTextSize = 0;
this.dTextAlign = 0;
this.dTextBackColor = null;
this.dTextFont = null;
this.dUsingVariables = null;
this.dWindowFrame = null;
this.dTextGradationRight = 0;
this.dTextGradationLeft = 0;
};
Game_Screen.prototype.setDTextPicture = function(value, size) {
if (typeof TranslationManager !== 'undefined') {
TranslationManager.translateIfNeed(value, function(translatedText) {
value = translatedText;
});
}
this.dUsingVariables = (this.dUsingVariables || []).concat(getUsingVariables(value));
this.dTextValue = (this.dTextValue || '') + getArgString(value, false) + '\n';
this.dTextOriginal = (this.dTextOriginal || '') + value + '\n';
this.dTextSize = size;
};
Game_Screen.prototype.setDTextWindowCursor = function(pictureId, rect) {
var picture = this.picture(pictureId);
if (picture) {
picture.setWindowCursor(rect);
picture.setWindowCursorActive(true);
}
};
Game_Screen.prototype.setDTextWindowCursorActive = function(pictureId, value) {
var picture = this.picture(pictureId);
if (picture) {
picture.setWindowCursorActive(value);
}
};
Game_Screen.prototype.getDTextPictureInfo = function() {
return {
value : this.dTextValue,
size : this.dTextSize || 0,
align : this.dTextAlign || 0,
color : this.dTextBackColor,
font : this.dTextFont,
usingVariables: this.dUsingVariables,
realTime : this.dTextRealTime,
originalValue : this.dTextOriginal,
windowFrame : this.dWindowFrame,
gradationLeft : this.dTextGradationLeft,
gradationRight: this.dTextGradationRight,
};
};
Game_Screen.prototype.isSettingDText = function() {
return !!this.dTextValue;
};
Game_Screen.prototype.setDtextFont = function(name) {
this.dTextFont = name;
};
var _Game_Screen_updatePictures = Game_Screen.prototype.updatePictures;
Game_Screen.prototype.updatePictures = function() {
_Game_Screen_updatePictures.apply(this, arguments);
$gameVariables.clearChangedVariables();
};
//=============================================================================
// Game_Picture
// 動的ピクチャ用のプロパティを追加定義し、表示処理を動的ピクチャ対応に変更します。
//=============================================================================
var _Game_Picture_initBasic = Game_Picture.prototype.initBasic;
Game_Picture.prototype.initBasic = function() {
_Game_Picture_initBasic.call(this);
this.dTextValue = null;
this.dTextInfo = null;
};
var _Game_Picture_show = Game_Picture.prototype.show;
Game_Picture.prototype.show = function(name, origin, x, y, scaleX,
scaleY, opacity, blendMode) {
if ($gameScreen.isSettingDText() && !name) {
arguments[0] = Date.now().toString();
this.dTextInfo = $gameScreen.getDTextPictureInfo();
$gameScreen.clearDTextPicture();
} else {
this.dTextInfo = null;
}
_Game_Picture_show.apply(this, arguments);
};
var _Game_Picture_update = Game_Picture.prototype.update;
Game_Picture.prototype.update = function() {
_Game_Picture_update.apply(this, arguments);
if (this.dTextInfo && this.dTextInfo.realTime) {
this.updateDTextVariable();
}
};
Game_Picture.prototype.updateDTextVariable = function() {
$gameVariables.getChangedVariables().forEach(function(variableId) {
if (this.dTextInfo.usingVariables.contains(variableId)) {
this._name = Date.now().toString();
this.dTextInfo.value = getArgString(this.dTextInfo.originalValue, false);
}
}, this);
};
Game_Picture.prototype.setWindowCursor = function(rect) {
this._windowCursor = rect;
};
Game_Picture.prototype.getWindowCursor = function() {
return this._windowCursor;
};
Game_Picture.prototype.setWindowCursorActive = function(value) {
this._windowCursorActive = value;
};
Game_Picture.prototype.getWindowCursorActive = function() {
return this._windowCursorActive;
};
//=============================================================================
// SceneManager
// 文字描画用の隠しウィンドウを取得します。
//=============================================================================
SceneManager.getHiddenWindow = function() {
if (!this._hiddenWindow) {
this._hiddenWindow = new Window_Hidden(1, 1, 1, 1);
}
return this._hiddenWindow;
};
SceneManager.getSpriteset = function() {
return this._scene._spriteset;
};
//=============================================================================
// Window_Base
// 文字列変換処理に追加制御文字を設定します。
//=============================================================================
var _Window_Base_convertEscapeCharacters = Window_Base.prototype.convertEscapeCharacters;
Window_Base.prototype.convertEscapeCharacters = function(text) {
text = _Window_Base_convertEscapeCharacters.call(this, text);
text = text.replace(/\x1bV\[(\d+),\s*(\d+)]/gi, function() {
return this.getVariablePadZero($gameVariables.value(parseInt(arguments[1], 10)), arguments[2]);
}.bind(this));
text = text.replace(/\x1bITEM\[(\d+)]/gi, function() {
var item = $dataItems[getArgNumber(arguments[1], 1, $dataItems.length)];
return this.getItemInfoText(item);
}.bind(this));
text = text.replace(/\x1bWEAPON\[(\d+)]/gi, function() {
var item = $dataWeapons[getArgNumber(arguments[1], 1, $dataWeapons.length)];
return this.getItemInfoText(item);
}.bind(this));
text = text.replace(/\x1bARMOR\[(\d+)]/gi, function() {
var item = $dataArmors[getArgNumber(arguments[1], 1, $dataArmors.length)];
return this.getItemInfoText(item);
}.bind(this));
text = text.replace(/\x1bSKILL\[(\d+)]/gi, function() {
var item = $dataSkills[getArgNumber(arguments[1], 1, $dataSkills.length)];
return this.getItemInfoText(item);
}.bind(this));
text = text.replace(/\x1bSTATE\[(\d+)]/gi, function() {
var item = $dataStates[getArgNumber(arguments[1], 1, $dataStates.length)];
return this.getItemInfoText(item);
}.bind(this));
return text;
};
Window_Base.prototype.getItemInfoText = function(item) {
if (!item) {
return '';
}
return (this.isValidDTextIconSwitch() ? '\x1bi[' + item.iconIndex + ']' : '') + item.name;
};
Window_Base.prototype.isValidDTextIconSwitch = function() {
return !param.itemIconSwitchId || $gameSwitches.value(param.itemIconSwitchId);
};
Window_Base.prototype.getVariablePadZero = function(value, digit) {
return (value < 0 ? '-' : '') + Math.abs(value).padZero(digit);
};
//=============================================================================
// Sprite_Picture
// 画像の動的生成を追加定義します。
//=============================================================================
var _Sprite_Picture_update = Sprite_Picture.prototype.update;
Sprite_Picture.prototype.update = function() {
_Sprite_Picture_update.apply(this, arguments);
if (this._frameWindow) {
this.updateFrameWindow();
}
};
Sprite_Picture.prototype.updateFrameWindow = function() {
var padding = this._frameWindow.standardPadding();
this._frameWindow.x = this.x - (this.anchor.x * this.width * this.scale.x) - padding;
this._frameWindow.y = this.y - (this.anchor.y * this.height * this.scale.y) - padding;
this._frameWindow.opacity = this.opacity;
if (!this.visible) {
this.removeFrameWindow();
return;
}
if (!this._addFrameWindow) {
this.addFrameWindow();
}
if (Graphics.frameCount % 2 === 0) {
this.adjustScaleFrameWindow();
}
this.updateFrameWindowCursor();
};
Sprite_Picture.prototype.updateFrameWindowCursor = function() {
var picture = this.picture();
if (!picture) {
return;
}
var rect = picture.getWindowCursor();
if (rect) {
var width = rect.width || this._frameWindow.contentsWidth();
var height = rect.width || this._frameWindow.contentsHeight();
this._frameWindow.setCursorRect(0, 0, width, height);
this._frameWindow.active = picture.getWindowCursorActive();
} else {
this._frameWindow.setCursorRect(0, 0, 0, 0);
}
};
Sprite_Picture.prototype.adjustScaleFrameWindow = function() {
var padding = this._frameWindow.standardPadding();
var newFrameWidth = Math.floor(this.width * this.scale.x + padding * 2);
var newFrameHeight = Math.floor(this.height * this.scale.x + padding * 2);
if (this._frameWindow.width !== newFrameWidth || this._frameWindow.height !== newFrameHeight) {
this._frameWindow.move(this._frameWindow.x, this._frameWindow.y, newFrameWidth, newFrameHeight);
}
};
Sprite_Picture.prototype.addFrameWindow = function() {
var parent = this.parent;
if (parent) {
var index = parent.getChildIndex(this);
parent.addChildAt(this._frameWindow, index);
this._addFrameWindow = true;
}
};
Sprite_Picture.prototype.removeFrameWindow = function() {
var parent = this.parent;
if (parent) {
parent.removeChild(this._frameWindow);
this._frameWindow = null;
this._addFrameWindow = false;
}
};
var _Sprite_Picture_loadBitmap = Sprite_Picture.prototype.loadBitmap;
Sprite_Picture.prototype.loadBitmap = function() {
this.dTextInfo = this.picture().dTextInfo;
if (this.dTextInfo) {
this.makeDynamicBitmap();
} else {
_Sprite_Picture_loadBitmap.apply(this, arguments);
}
};
Sprite_Picture.prototype.makeDynamicBitmap = function() {
this.textWidths = [];
this.hiddenWindow = SceneManager.getHiddenWindow();
this.hiddenWindow.resetFontSettings(this.dTextInfo);
var bitmapVirtual = new Bitmap_Virtual();
this._processText(bitmapVirtual);
this.hiddenWindow.resetFontSettings(this.dTextInfo);
this.bitmap = new Bitmap(bitmapVirtual.width, bitmapVirtual.height);
this.applyTextDecoration();
this.bitmap.fontFace = this.hiddenWindow.contents.fontFace;
if (this.dTextInfo.color) {
this.bitmap.fillAll(this.dTextInfo.color);
var h = this.bitmap.height;
var w = this.bitmap.width;
var gradationLeft = this.dTextInfo.gradationLeft;
if (gradationLeft > 0) {
this.bitmap.clearRect(0, 0, gradationLeft, h);
this.bitmap.gradientFillRect(0, 0, gradationLeft, h, 'rgba(0, 0, 0, 0)', this.dTextInfo.color, false);
}
var gradationRight = this.dTextInfo.gradationRight;
if (gradationRight > 0) {
this.bitmap.clearRect(w - gradationRight, 0, gradationRight, h);
this.bitmap.gradientFillRect(w - gradationRight, 0, gradationRight, h, this.dTextInfo.color, 'rgba(0, 0, 0, 0)', false);
}
}
this._processText(this.bitmap);
this._colorTone = [0, 0, 0, 0];
if (this._frameWindow) {
this.removeFrameWindow();
}
if (this.dTextInfo.windowFrame) {
var scaleX = this.picture().scaleX() / 100;
var scaleY = this.picture().scaleY() / 100;
this.makeFrameWindow(bitmapVirtual.width * scaleX, bitmapVirtual.height * scaleY);
}
this.hiddenWindow = null;
};
Sprite_Picture.prototype.applyTextDecoration = function() {
if (textDecParam.Mode >= 0) {
this.bitmap.outlineColor =
'rgba(%1,%2,%3,%4)'.format(textDecParam.Red, textDecParam.Green, textDecParam.Blue, textDecParam.Alpha / 255);
this.bitmap.decorationMode = textDecParam.Mode;
}
};
Sprite_Picture.prototype.makeFrameWindow = function(width, height) {
var padding = this.hiddenWindow.standardPadding();
this._frameWindow = new Window_Base(0, 0, width + padding * 2, height + padding * 2);
};
Sprite_Picture.prototype._processText = function(bitmap) {
var textState = {index: 0, x: 0, y: 0, text: this.dTextInfo.value, left: 0, line: -1, height: 0};
this._processNewLine(textState, bitmap);
textState.height = this.hiddenWindow.calcTextHeight(textState, false);
textState.index = 0;
while (textState.text[textState.index]) {
this._processCharacter(textState, bitmap);
}
};
Sprite_Picture.prototype._processCharacter = function(textState, bitmap) {
if (textState.text[textState.index] === '\x1b') {
var code = this.hiddenWindow.obtainEscapeCode(textState);
switch (code) {
case 'C':
bitmap.textColor = this.hiddenWindow.textColor(this.hiddenWindow.obtainEscapeParam(textState));
break;
case 'I':
this._processDrawIcon(this.hiddenWindow.obtainEscapeParam(textState), textState, bitmap);
break;
case '{':
this.hiddenWindow.makeFontBigger();
break;
case '}':
this.hiddenWindow.makeFontSmaller();
break;
case 'F':
switch (this.hiddenWindow.obtainEscapeParamString(textState).toUpperCase()) {
case 'I':
bitmap.fontItalic = true;
break;
case 'B':
bitmap.fontBoldFotDtext = true;
break;
case '/':
case 'N':
bitmap.fontItalic = false;
bitmap.fontBoldFotDtext = false;
break;
}
break;
case 'OC':
var colorCode = this.hiddenWindow.obtainEscapeParamString(textState);
var colorIndex = Number(colorCode);
if (!isNaN(colorIndex)) {
bitmap.outlineColor = this.hiddenWindow.textColor(colorIndex);
} else {
bitmap.outlineColor = colorCode;
}
break;
case 'OW':
bitmap.outlineWidth = this.hiddenWindow.obtainEscapeParam(textState);
break;
}
} else if (textState.text[textState.index] === '\n') {
this._processNewLine(textState, bitmap);
} else {
var c = textState.text[textState.index++];
var w = this.hiddenWindow.textWidth(c);
bitmap.fontSize = this.hiddenWindow.contents.fontSize;
bitmap.drawText(c, textState.x, textState.y, w * 2, textState.height, 'left');
textState.x += w;
}
};
Sprite_Picture.prototype._processNewLine = function(textState, bitmap) {
if (bitmap instanceof Bitmap_Virtual)
this.textWidths[textState.line] = textState.x;
this.hiddenWindow.processNewLine(textState);
textState.line++;
if (bitmap instanceof Bitmap)
textState.x = (bitmap.width - this.textWidths[textState.line]) / 2 * this.dTextInfo.align;
};
Sprite_Picture.prototype._processDrawIcon = function(iconIndex, textState, bitmap) {
var iconBitmap = ImageManager.loadSystem('IconSet');
var pw = Window_Base._iconWidth;
var ph = Window_Base._iconHeight;
var sx = iconIndex % 16 * pw;
var sy = Math.floor(iconIndex / 16) * ph;
bitmap.blt(iconBitmap, sx, sy, pw, ph, textState.x + 2, textState.y + (textState.height - ph) / 2);
textState.x += Window_Base._iconWidth + 4;
};
//=============================================================================
// Bitmap_Virtual
// サイズを計算するための仮想ビットマップクラス
//=============================================================================
function Bitmap_Virtual() {
this.initialize.apply(this, arguments);
}
Bitmap_Virtual.prototype.initialize = function() {
this.window = SceneManager.getHiddenWindow();
this.width = 0;
this.height = 0;
};
Bitmap_Virtual.prototype.drawText = function(text, x, y) {
var baseWidth = this.window.textWidth(text);
var fontSize = this.window.contents.fontSize;
if (this.fontItalic) {
baseWidth += Math.floor(fontSize / 6);
}
if (this.fontBoldFotDtext) {
baseWidth += 2;
}
this.width = Math.max(x + baseWidth, this.width);
this.height = Math.max(y + fontSize + 8, this.height);
};
Bitmap_Virtual.prototype.blt = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
this.width = Math.max(dx + (dw || sw), this.width);
this.height = Math.max(dy + (dh || sh), this.height);
};
//=============================================================================
// Window_Hidden
// 文字描画用の隠しウィンドウ
//=============================================================================
function Window_Hidden() {
this.initialize.apply(this, arguments);
}
Window_Hidden.prototype.backOpacity = null;
Window_Hidden.prototype = Object.create(Window_Base.prototype);
Window_Hidden.prototype.constructor = Window_Hidden;
Window_Hidden.prototype._createAllParts = function() {
this._windowBackSprite = {};
this._windowSpriteContainer = {};
this._windowContentsSprite = new Sprite();
this.addChild(this._windowContentsSprite);
};
Window_Hidden.prototype._refreshAllParts = function() {};
Window_Hidden.prototype._refreshBack = function() {};
Window_Hidden.prototype._refreshFrame = function() {};
Window_Hidden.prototype._refreshCursor = function() {};
Window_Hidden.prototype._refreshArrows = function() {};
Window_Hidden.prototype._refreshPauseSign = function() {};
Window_Hidden.prototype.updateTransform = function() {};
Window_Hidden.prototype.resetFontSettings = function(dTextInfo) {
if (dTextInfo) {
var customFont = dTextInfo.font ? dTextInfo.font + ',' : '';
this.contents.fontFace = customFont + this.standardFontFace();
this.contents.fontSize = dTextInfo.size || this.standardFontSize();
} else {
Window_Base.prototype.resetFontSettings.apply(this, arguments);
}
};
Window_Hidden.prototype.obtainEscapeParamString = function(textState) {
var arr = /^\[.+?]/.exec(textState.text.slice(textState.index));
if (arr) {
textState.index += arr[0].length;
return arr[0].substring(1, arr[0].length - 1);
} else {
return '';
}
};
//=============================================================================
// Bitmap
// 太字対応
//=============================================================================
var _Bitmap__makeFontNameText = Bitmap.prototype._makeFontNameText;
Bitmap.prototype._makeFontNameText = function() {
return (this.fontBoldFotDtext ? 'bold ' : '') + _Bitmap__makeFontNameText.apply(this, arguments);
};
})();