查看: 3754|回复: 4

[有事请教] DTextPicture.js

[复制链接]
梦石
0
星屑
1593
在线时间
252 小时
注册时间
2017-10-24
回帖
158
发表于 2017-11-15 14:00:31 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
请问这个插件谁有,可以分享一下吗?
梦石
0
星屑
16296
在线时间
4017 小时
注册时间
2015-9-14
回帖
1322

开拓者

发表于 2017-11-17 10:34:26 | 显示全部楼层
https://triacontane.blogspot.com/2015/12/rpgmv-rpgmv-dtext-1-rpgmv-dtext-dtext.html作者トリアコンタン:

  1. //=============================================================================
  2. // DTextPicture.js
  3. // ----------------------------------------------------------------------------
  4. // Copyright (c) 2015-2017 Triacontane
  5. // This software is released under the MIT License.
  6. // [url]http://opensource.org/licenses/mit-license.php[/url]
  7. // ----------------------------------------------------------------------------
  8. // Version
  9. // 1.9.0 2017/08/20 ウィンドウつきピクチャが重なったときにウィンドウがピクチャの下に表示される問題を修正
  10. // 1.8.6 2017/06/28 フォント変更機能のヘルプが抜けていたので追加
  11. // 1.8.5 2017/06/12 変数がマイナス値のときのゼロ埋め表示が正しく表示されない問題を修正
  12. // 1.8.4 2017/05/10 プラグインを未適用のデータを読み込んだとき、最初の一回のみ動的文字列ピクチャが作成されない問題を修正
  13. // 1.8.3 2017/04/19 自動翻訳プラグインに一部対応
  14. // 1.8.2 2017/04/05 ピクチャの消去時にエラーが発生していた問題を修正
  15. // 1.8.1 2017/03/30 拡大率と原点に対応していなかった問題を修正
  16. // 1.8.0 2017/03/30 背景にウィンドウを表示できる機能を追加
  17. // 1.7.1 2017/03/20 1.7.0で末尾がイタリック体の場合に、傾き部分が見切れてしまう問題を修正
  18. // 1.7.0 2017/03/20 動的文字列を太字とイタリックにできる機能を追加
  19. //                  複数行表示かつ制御文字でアイコンを指定した場合に高さが余分に計算されてしまう問題の修正
  20. // 1.6.2 2016/12/13 動的ピクチャに対して、ピクチャの表示とピクチャの色調変更を同フレームで行うと画像が消える問題の修正
  21. // 1.6.1 2016/11/03 一通りの競合対策
  22. // 1.6.0 2016/11/03 インストールされているフォントをピクチャのフォントとして利用できる機能を追加
  23. // 1.5.1 2016/10/27 1.5.0でアウトラインカラーを指定するとエラーになっていた現象を修正
  24. // 1.5.0 2016/10/23 制御文字で表示した変数の内容をリアルタイム更新できる機能を追加
  25. // 1.4.2 2016/07/02 スクリプトからダイレクトで実行した場合も制御文字が反映されるよう修正(ただし余分にエスケープする必要あり)
  26. // 1.4.1 2016/06/29 制御文字「\{」で文字サイズを大きくした際、元のサイズに戻さないと正しいサイズで表示されない問題を修正
  27. // 1.4.0 2016/06/28 D_TEXT実行後に画像を指定してピクチャを表示した場合は画像を優先表示するよう仕様変更
  28. // 1.3.1 2016/06/07 描画文字が半角英数字のみかつフォントを未指定の場合に文字が描画されない不具合を修正
  29. // 1.3.0 2016/06/03 制御文字\oc[c] \ow[n]に対応
  30. // 1.2.2 2016/03/28 データベース情報を簡単に出力する制御文字を追加
  31. // 1.2.1 2016/01/29 コマンド「D_TEXT_SETTING」の実装が「D_TEST_SETTING」になっていたので修正(笑)
  32. // 1.2.0 2016/01/27 複数行表示に対応
  33. //                  文字列の揃えと背景色を設定する機能を追加
  34. //                  変数をゼロ埋めして表示する機能を追加
  35. // 1.1.3 2015/12/10 戦闘画面でもピクチャを使用できるよう修正
  36. //                  描画後にデバッグ画面等を開いて変数を修正した場合、再描画で変更が反映されてしまう問題を修正
  37. // 1.1.2 2015/11/07 描画文字列に半角スペースが含まれていた場合も問題なく実行できるよう修正
  38. // 1.1.0 2015/11/07 制御文字\C[n] \I[n] \{ \} に対応(\$と表示スピード制御系以外全部)
  39. // 1.0.1 2015/11/07 RPGツクールMV(日本語版)に合わせてコメントの表記を変更
  40. // 1.0.0 2015/11/06 初版
  41. // ----------------------------------------------------------------------------
  42. // [Blog]   : [url]https://triacontane.blogspot.jp/[/url]
  43. // [Twitter]: [url]https://twitter.com/triacontane/[/url]
  44. // [GitHub] : [url]https://github.com/triacontane/[/url]
  45. //=============================================================================

  46. /*:
  47. * @plugindesc 動的文字列ピクチャ生成プラグイン
  48. * @author トリアコンタン
  49. *
  50. * @help 指定した文字列でピクチャを動的に生成するコマンドを提供します。
  51. * 文字列には各種制御文字(\v[n]等)も使用可能で、制御文字で表示した変数の値が
  52. * 変更されたときにリアルタイムでピクチャの内容を更新できます。
  53. *
  54. * 以下の手順で表示します。
  55. *  1 : プラグインコマンド[D_TEXT]で描画したい文字列と引数を指定(下記の例参照)
  56. *  2 : プラグインコマンド[D_TEXT_SETTING]で背景色や揃えを指定(任意)
  57. *  3 : イベントコマンド「ピクチャの表示」で「画像」を未選択に指定。
  58. * ※ 1の時点ではピクチャは表示されないので必ずセットで呼び出してください。
  59. * ※ ピクチャ表示前にD_TEXTを複数回実行すると、複数行表示できます。
  60. *
  61. * ※ ver1.4.0より、[D_TEXT]実行後に「ピクチャの表示」で「画像」を指定した場合は
  62. *    動的文字列ピクチャ生成を保留として通常通り「画像」ピクチャが表示される
  63. *    ように挙動が変更になりました。
  64. *
  65. * プラグインコマンド詳細
  66. *   イベントコマンド「プラグインコマンド」から実行。
  67. *   (引数の間は半角スペースで区切る)
  68. *
  69. *  D_TEXT [描画文字列] [文字サイズ] : 動的文字列ピクチャ生成の準備
  70. *  例:D_TEXT テスト文字列 32
  71. *
  72. * 表示後は通常のピクチャと同様に移動や回転、消去ができます。
  73. * また、変数やアクターの表示など制御文字にも対応しています。
  74. *
  75. *  D_TEXT_SETTING ALIGN [揃え] : 揃え(左揃え、中央揃え、右揃え)の設定
  76. *  0:左揃え 1:中央揃え 2:右揃え
  77. *
  78. *  例:D_TEXT_SETTING ALIGN 0
  79. *      D_TEXT_SETTING ALIGN CENTER
  80. *
  81. *  D_TEXT_SETTING BG_COLOR [背景色] : 背景色の設定(CSSの色指定と同様の書式)
  82. *
  83. *  例:D_TEXT_SETTING BG_COLOR black
  84. *      D_TEXT_SETTING BG_COLOR #336699
  85. *      D_TEXT_SETTING BG_COLOR rgba(255,255,255,0.5)
  86. *
  87. *  D_TEXT_SETTING REAL_TIME ON : 制御文字で表示した変数のリアルタイム表示
  88. *
  89. *  例:D_TEXT_SETTING REAL_TIME ON
  90. *
  91. *  リアルタイム表示を有効にしておくと、ピクチャの表示後に変数の値が変化したとき
  92. *  自動でピクチャの内容も更新されます。
  93. *
  94. *  D_TEXT_SETTING WINDOW ON : 背景にウィンドウを表示する
  95. *  例:D_TEXT_SETTING WINDOW ON
  96. *
  97. *  D_TEXT_SETTING FONT [フォント名] : 描画で使用するフォントを指定した名称に変更
  98. *  例:D_TEXT_SETTING FONT MS P明朝
  99. *
  100. * これらの設定はD_TEXTと同様、ピクチャを表示する前に行ってください。
  101. *
  102. * 対応制御文字一覧(イベントコマンド「文章の表示」と同一です)
  103. * \V[n]
  104. * \N[n]
  105. * \P[n]
  106. * \G
  107. * \C[n]
  108. * \I[n]
  109. * \{
  110. * \}
  111. *
  112. * 専用制御文字
  113. * \V[n,m](m桁分のゼロ埋めした変数の値)
  114. * \item[n]   n 番のアイテム情報(アイコン+名称)
  115. * \weapon[n] n 番の武器情報(アイコン+名称)
  116. * \armor[n]  n 番の防具情報(アイコン+名称)
  117. * \skill[n]  n 番のスキル情報(アイコン+名称)
  118. * \state[n]  n 番のステート情報(アイコン+名称)
  119. * \oc[c] アウトラインカラーを「c」に設定(例:\oc[red])
  120. * \ow[n] アウトライン幅を「n」に設定(例:\ow[5])
  121. * \f[b] フォントの太字化
  122. * \f[i] フォントのイタリック化
  123. * \f[n] フォントの太字とイタリックを通常に戻す
  124. *
  125. * 利用規約:
  126. *  作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
  127. *  についても制限はありません。
  128. *  このプラグインはもうあなたのものです。
  129. */
  130. (function() {
  131.     'use strict';

  132.     var getCommandName = function(command) {
  133.         return (command || '').toUpperCase();
  134.     };

  135.     var getArgNumber = function(arg, min, max) {
  136.         if (arguments.length < 2) min = -Infinity;
  137.         if (arguments.length < 3) max = Infinity;
  138.         return (parseInt(convertEscapeCharacters(arg.toString())) || 0).clamp(min, max);
  139.     };

  140.     var getArgString = function(arg, upperFlg) {
  141.         arg = convertEscapeCharacters(arg);
  142.         return upperFlg ? arg.toUpperCase() : arg;
  143.     };

  144.     var getArgBoolean = function(arg) {
  145.         return (arg || '').toUpperCase() === 'ON';
  146.     };

  147.     var connectArgs = function(args, startIndex, endIndex) {
  148.         if (arguments.length < 2) startIndex = 0;
  149.         if (arguments.length < 3) endIndex = args.length;
  150.         var text = '';
  151.         for (var i = startIndex; i < endIndex; i++) {
  152.             text += args[i];
  153.             if (i < endIndex - 1) text += ' ';
  154.         }
  155.         return text;
  156.     };

  157.     var convertEscapeCharacters = function(text) {
  158.         if (text === undefined || text === null) text = '';
  159.         var window = SceneManager.getHiddenWindow();
  160.         return window ? window.convertEscapeCharacters(text) : text;
  161.     };

  162.     var getUsingVariables = function(text) {
  163.         var usingVariables = [];

  164.         text = text.replace(/\\/g, '\x1b');
  165.         text = text.replace(/\x1b\x1b/g, '\\');
  166.         text = text.replace(/\x1bV\[(\d+)\,\s*(\d+)\]/gi, function() {
  167.             var number = parseInt(arguments[1], 10);
  168.             usingVariables.push(number);
  169.             return $gameVariables.value(number);
  170.         }.bind(this));
  171.         text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
  172.             var number = parseInt(arguments[1], 10);
  173.             usingVariables.push(number);
  174.             return $gameVariables.value(number);
  175.         }.bind(this));
  176.         text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
  177.             var number = parseInt(arguments[1], 10);
  178.             usingVariables.push(number);
  179.             return $gameVariables.value(number);
  180.         }.bind(this));
  181.         return usingVariables;
  182.     };

  183.     //=============================================================================
  184.     // Game_Interpreter
  185.     //  プラグインコマンド[D_TEXT]を追加定義します。
  186.     //=============================================================================
  187.     var _Game_Interpreter_pluginCommand      = Game_Interpreter.prototype.pluginCommand;
  188.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  189.         _Game_Interpreter_pluginCommand.apply(this, arguments);
  190.         this.pluginCommandDTextPicture(command, args);
  191.     };

  192.     Game_Interpreter.textAlignMapper = {
  193.         LEFT: 0, CENTER: 1, RIGHT: 2, 左: 0, 中央: 1, 右: 2
  194.     };

  195.     Game_Interpreter.prototype.pluginCommandDTextPicture = function(command, args) {
  196.         switch (getCommandName(command)) {
  197.             case 'D_TEXT' :
  198.                 if (isNaN(args[args.length - 1]) || args.length === 1) args.push($gameScreen.dTextSize || 28);
  199.                 var fontSize = getArgNumber(args.pop());
  200.                 $gameScreen.setDTextPicture(connectArgs(args), fontSize);
  201.                 break;
  202.             case 'D_TEXT_SETTING':
  203.                 switch (getCommandName(args[0])) {
  204.                     case 'ALIGN' :
  205.                         $gameScreen.dTextAlign = isNaN(args[1]) ?
  206.                             Game_Interpreter.textAlignMapper[getArgString(args[1], true)] : getArgNumber(args[1], 0, 2);
  207.                         break;
  208.                     case 'BG_COLOR' :
  209.                         $gameScreen.dTextBackColor = getArgString(connectArgs(args, 1));
  210.                         break;
  211.                     case 'FONT':
  212.                         args.shift();
  213.                         $gameScreen.setDtextFont(getArgString(connectArgs(args)));
  214.                         break;
  215.                     case 'REAL_TIME' :
  216.                         $gameScreen.dTextRealTime = getArgBoolean(args[1]);
  217.                         break;
  218.                     case 'WINDOW':
  219.                         $gameScreen.dWindowFrame = getArgBoolean(args[1]);
  220.                         break;
  221.                 }
  222.                 break;
  223.         }
  224.     };

  225.     //=============================================================================
  226.     // Game_Variables
  227.     //  値を変更した変数の履歴を取得します。
  228.     //=============================================================================
  229.     var _Game_Variables_setValue      = Game_Variables.prototype.setValue;
  230.     Game_Variables.prototype.setValue = function(variableId, value) {
  231.         if (this.value(variableId) !== value) {
  232.             this._changedVariables = this.getChangedVariables();
  233.             if (!this._changedVariables.contains(variableId)) {
  234.                 this._changedVariables.push(variableId);
  235.             }
  236.         }
  237.         _Game_Variables_setValue.apply(this, arguments);
  238.     };

  239.     Game_Variables.prototype.getChangedVariables = function() {
  240.         return this._changedVariables || [];
  241.     };

  242.     Game_Variables.prototype.clearChangedVariables = function() {
  243.         return this._changedVariables = [];
  244.     };

  245.     //=============================================================================
  246.     // Game_Screen
  247.     //  動的ピクチャ用のプロパティを追加定義します。
  248.     //=============================================================================
  249.     var _Game_Screen_clear      = Game_Screen.prototype.clear;
  250.     Game_Screen.prototype.clear = function() {
  251.         _Game_Screen_clear.call(this);
  252.         this.clearDTextPicture();
  253.     };

  254.     Game_Screen.prototype.clearDTextPicture = function() {
  255.         this.dTextValue      = null;
  256.         this.dTextOriginal   = null;
  257.         this.dTextRealTime   = null;
  258.         this.dTextSize       = 0;
  259.         this.dTextAlign      = 0;
  260.         this.dTextBackColor  = null;
  261.         this.dTextFont       = null;
  262.         this.dUsingVariables = null;
  263.         this.dWindowFrame    = null;
  264.     };

  265.     Game_Screen.prototype.setDTextPicture = function(value, size) {
  266.         if (typeof TranslationManager !== 'undefined') {
  267.             TranslationManager.translateIfNeed(value, function(translatedText) {
  268.                 value = translatedText;
  269.             });
  270.         }
  271.         this.dUsingVariables = (this.dUsingVariables || []).concat(getUsingVariables(value));
  272.         this.dTextValue      = (this.dTextValue || '') + getArgString(value, false) + '\n';
  273.         this.dTextOriginal   = (this.dTextOriginal || '') + value + '\n';
  274.         this.dTextSize       = size;
  275.     };

  276.     Game_Screen.prototype.getDTextPictureInfo = function() {
  277.         return {
  278.             value         : this.dTextValue,
  279.             size          : this.dTextSize || 0,
  280.             align         : this.dTextAlign || 0,
  281.             color         : this.dTextBackColor,
  282.             font          : this.dTextFont,
  283.             usingVariables: this.dUsingVariables,
  284.             realTime      : this.dTextRealTime,
  285.             originalValue : this.dTextOriginal,
  286.             windowFrame   : this.dWindowFrame
  287.         };
  288.     };

  289.     Game_Screen.prototype.isSettingDText = function() {
  290.         return !!this.dTextValue;
  291.     };

  292.     Game_Screen.prototype.setDtextFont = function(name) {
  293.         this.dTextFont = name;
  294.     };

  295.     var _Game_Screen_updatePictures      = Game_Screen.prototype.updatePictures;
  296.     Game_Screen.prototype.updatePictures = function() {
  297.         _Game_Screen_updatePictures.apply(this, arguments);
  298.         $gameVariables.clearChangedVariables();
  299.     };

  300.     //=============================================================================
  301.     // Game_Picture
  302.     //  動的ピクチャ用のプロパティを追加定義し、表示処理を動的ピクチャ対応に変更します。
  303.     //=============================================================================
  304.     var _Game_Picture_initBasic      = Game_Picture.prototype.initBasic;
  305.     Game_Picture.prototype.initBasic = function() {
  306.         _Game_Picture_initBasic.call(this);
  307.         this.dTextValue = null;
  308.         this.dTextInfo  = null;
  309.     };

  310.     var _Game_Picture_show      = Game_Picture.prototype.show;
  311.     Game_Picture.prototype.show = function(name, origin, x, y, scaleX,
  312.                                            scaleY, opacity, blendMode) {
  313.         if ($gameScreen.isSettingDText() && !name) {
  314.             arguments[0]   = Date.now().toString();
  315.             this.dTextInfo = $gameScreen.getDTextPictureInfo();
  316.             $gameScreen.clearDTextPicture();
  317.         } else {
  318.             this.dTextInfo = null;
  319.         }
  320.         _Game_Picture_show.apply(this, arguments);
  321.     };

  322.     var _Game_Picture_update      = Game_Picture.prototype.update;
  323.     Game_Picture.prototype.update = function() {
  324.         _Game_Picture_update.apply(this, arguments);
  325.         if (this.dTextInfo && this.dTextInfo.realTime) {
  326.             this.updateDTextVariable();
  327.         }
  328.     };

  329.     Game_Picture.prototype.updateDTextVariable = function() {
  330.         $gameVariables.getChangedVariables().forEach(function(variableId) {
  331.             if (this.dTextInfo.usingVariables.contains(variableId)) {
  332.                 this._name           = Date.now().toString();
  333.                 this.dTextInfo.value = getArgString(this.dTextInfo.originalValue, false);
  334.             }
  335.         }, this);
  336.     };

  337.     //=============================================================================
  338.     // SceneManager
  339.     //  文字描画用の隠しウィンドウを取得します。
  340.     //=============================================================================
  341.     SceneManager.getHiddenWindow = function() {
  342.         if (!this._hiddenWindow) {
  343.             this._hiddenWindow = new Window_Hidden(1, 1, 1, 1);
  344.         }
  345.         return this._hiddenWindow;
  346.     };

  347.     SceneManager.getSpriteset = function() {
  348.         return this._scene._spriteset;
  349.     };

  350.     //=============================================================================
  351.     // Window_Base
  352.     //  文字列変換処理に追加制御文字を設定します。
  353.     //=============================================================================
  354.     var _Window_Base_convertEscapeCharacters      = Window_Base.prototype.convertEscapeCharacters;
  355.     Window_Base.prototype.convertEscapeCharacters = function(text) {
  356.         text = _Window_Base_convertEscapeCharacters.call(this, text);
  357.         text = text.replace(/\x1bV\[(\d+)\,\s*(\d+)\]/gi, function() {
  358.             return this.getVariablePadZero($gameVariables.value(parseInt(arguments[1], 10)), arguments[2]);
  359.         }.bind(this));
  360.         text = text.replace(/\x1bITEM\[(\d+)\]/gi, function() {
  361.             var item = $dataItems[getArgNumber(arguments[1], 1, $dataItems.length)];
  362.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  363.         }.bind(this));
  364.         text = text.replace(/\x1bWEAPON\[(\d+)\]/gi, function() {
  365.             var item = $dataWeapons[getArgNumber(arguments[1], 1, $dataWeapons.length)];
  366.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  367.         }.bind(this));
  368.         text = text.replace(/\x1bARMOR\[(\d+)\]/gi, function() {
  369.             var item = $dataArmors[getArgNumber(arguments[1], 1, $dataArmors.length)];
  370.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  371.         }.bind(this));
  372.         text = text.replace(/\x1bSKILL\[(\d+)\]/gi, function() {
  373.             var item = $dataSkills[getArgNumber(arguments[1], 1, $dataSkills.length)];
  374.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  375.         }.bind(this));
  376.         text = text.replace(/\x1bSTATE\[(\d+)\]/gi, function() {
  377.             var item = $dataStates[getArgNumber(arguments[1], 1, $dataStates.length)];
  378.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  379.         }.bind(this));
  380.         return text;
  381.     };

  382.     Window_Base.prototype.getVariablePadZero = function(value, digit) {
  383.         return (value < 0 ? '-' : '') + Math.abs(value).padZero(digit);
  384.     };

  385.     //=============================================================================
  386.     // Sprite_Picture
  387.     //  画像の動的生成を追加定義します。
  388.     //=============================================================================
  389.     var _Sprite_Picture_update      = Sprite_Picture.prototype.update;
  390.     Sprite_Picture.prototype.update = function() {
  391.         _Sprite_Picture_update.apply(this, arguments);
  392.         if (this._frameWindow) {
  393.             this.updateFrameWindow();
  394.         }
  395.     };

  396.     Sprite_Picture.prototype.updateFrameWindow = function() {
  397.         var padding = this._frameWindow.standardPadding();
  398.         this._frameWindow.x = this.x - (this.anchor.x * this.width * this.scale.x) - padding;
  399.         this._frameWindow.y = this.y - (this.anchor.y * this.height * this.scale.y) - padding;
  400.         if (!this.visible) {
  401.             this.removeFrameWindow();
  402.             return;
  403.         }
  404.         if (!this._addFrameWindow) {
  405.             this.addFrameWindow();
  406.         }
  407.         if (Graphics.frameCount % 2 === 0) {
  408.             this.adjustScaleFrameWindow();
  409.         }
  410.     };

  411.     Sprite_Picture.prototype.adjustScaleFrameWindow = function() {
  412.         var padding = this._frameWindow.standardPadding();
  413.         var newFrameWidth = Math.floor(this.width * this.scale.x + padding * 2);
  414.         var newFrameHeight = Math.floor(this.height * this.scale.x + padding * 2);
  415.         if (this._frameWindow.width !== newFrameWidth || this._frameWindow.height !== newFrameHeight) {
  416.             this._frameWindow.move(this._frameWindow.x, this._frameWindow.y, newFrameWidth, newFrameHeight);
  417.         }
  418.     };

  419.     Sprite_Picture.prototype.addFrameWindow = function() {
  420.         var parent = this.parent;
  421.         if (parent) {
  422.             var index = parent.getChildIndex(this);
  423.             parent.addChildAt(this._frameWindow, index);
  424.             this._addFrameWindow = true;
  425.         }
  426.     };

  427.     Sprite_Picture.prototype.removeFrameWindow = function() {
  428.         var parent = this.parent;
  429.         if (parent) {
  430.             parent.removeChild(this._frameWindow);
  431.             this._frameWindow    = null;
  432.             this._addFrameWindow = false;
  433.         }
  434.     };

  435.     var _Sprite_Picture_loadBitmap      = Sprite_Picture.prototype.loadBitmap;
  436.     Sprite_Picture.prototype.loadBitmap = function() {
  437.         this.dTextInfo = this.picture().dTextInfo;
  438.         if (this.dTextInfo) {
  439.             this.makeDynamicBitmap();
  440.         } else {
  441.             _Sprite_Picture_loadBitmap.apply(this, arguments);
  442.         }
  443.     };

  444.     Sprite_Picture.prototype.makeDynamicBitmap = function() {
  445.         this.textWidths   = [];
  446.         this.hiddenWindow = SceneManager.getHiddenWindow();
  447.         this.hiddenWindow.resetFontSettings(this.dTextInfo);
  448.         var bitmapVirtual = new Bitmap_Virtual();
  449.         this._processText(bitmapVirtual);
  450.         this.hiddenWindow.resetFontSettings(this.dTextInfo);
  451.         this.bitmap          = new Bitmap(bitmapVirtual.width, bitmapVirtual.height);
  452.         this.bitmap.fontFace = this.hiddenWindow.contents.fontFace;
  453.         if (this.dTextInfo.color) {
  454.             this.bitmap.fillAll(this.dTextInfo.color);
  455.         }
  456.         this._processText(this.bitmap);
  457.         this._colorTone = [0, 0, 0, 0];
  458.         if (this._frameWindow) {
  459.             this.removeFrameWindow();
  460.         }
  461.         if (this.dTextInfo.windowFrame) {
  462.             var scaleX = this.picture().scaleX() / 100;
  463.             var scaleY = this.picture().scaleY() / 100;
  464.             this.makeFrameWindow(bitmapVirtual.width * scaleX, bitmapVirtual.height * scaleY);
  465.         }
  466.         this.hiddenWindow = null;
  467.     };

  468.     Sprite_Picture.prototype.makeFrameWindow = function(width, height) {
  469.         var padding             = this.hiddenWindow.standardPadding();
  470.         this._frameWindow       = new Window_Base(0, 0, width + padding * 2, height + padding * 2);
  471.     };

  472.     Sprite_Picture.prototype._processText = function(bitmap) {
  473.         var textState = {index: 0, x: 0, y: 0, text: this.dTextInfo.value, left: 0, line: -1, height: 0};
  474.         this._processNewLine(textState, bitmap);
  475.         textState.height = this.hiddenWindow.calcTextHeight(textState, false);
  476.         textState.index  = 0;
  477.         while (textState.text[textState.index]) {
  478.             this._processCharacter(textState, bitmap);
  479.         }
  480.     };

  481.     Sprite_Picture.prototype._processCharacter = function(textState, bitmap) {
  482.         if (textState.text[textState.index] === '\x1b') {
  483.             var code = this.hiddenWindow.obtainEscapeCode(textState);
  484.             switch (code) {
  485.                 case 'C':
  486.                     bitmap.textColor = this.hiddenWindow.textColor(this.hiddenWindow.obtainEscapeParam(textState));
  487.                     break;
  488.                 case 'I':
  489.                     this._processDrawIcon(this.hiddenWindow.obtainEscapeParam(textState), textState, bitmap);
  490.                     break;
  491.                 case '{':
  492.                     this.hiddenWindow.makeFontBigger();
  493.                     break;
  494.                 case '}':
  495.                     this.hiddenWindow.makeFontSmaller();
  496.                     break;
  497.                 case 'F':
  498.                     switch (this.hiddenWindow.obtainEscapeParamString(textState).toUpperCase()) {
  499.                         case 'I':
  500.                             bitmap.fontItalic = true;
  501.                             break;
  502.                         case 'B':
  503.                             bitmap.fontBoldFotDtext = true;
  504.                             break;
  505.                         case '/':
  506.                         case 'N':
  507.                             bitmap.fontItalic       = false;
  508.                             bitmap.fontBoldFotDtext = false;
  509.                             break;
  510.                     }
  511.                     break;
  512.                 case 'OC':
  513.                     bitmap.outlineColor = this.hiddenWindow.obtainEscapeParamString(textState);
  514.                     break;
  515.                 case 'OW':
  516.                     bitmap.outlineWidth = this.hiddenWindow.obtainEscapeParam(textState);
  517.                     break;
  518.             }
  519.         } else if (textState.text[textState.index] === '\n') {
  520.             this._processNewLine(textState, bitmap);
  521.         } else {
  522.             var c = textState.text[textState.index++];
  523.             var w = this.hiddenWindow.textWidth(c);

  524.             bitmap.fontSize = this.hiddenWindow.contents.fontSize;
  525.             bitmap.drawText(c, textState.x, textState.y, w * 2, textState.height, 'left');
  526.             textState.x += w;
  527.         }
  528.     };

  529.     Sprite_Picture.prototype._processNewLine = function(textState, bitmap) {
  530.         if (bitmap instanceof Bitmap_Virtual)
  531.             this.textWidths[textState.line] = textState.x;
  532.         this.hiddenWindow.processNewLine(textState);
  533.         textState.line++;
  534.         if (bitmap instanceof Bitmap)
  535.             textState.x = (bitmap.width - this.textWidths[textState.line]) / 2 * this.dTextInfo.align;
  536.     };

  537.     Sprite_Picture.prototype._processDrawIcon = function(iconIndex, textState, bitmap) {
  538.         var iconBitmap = ImageManager.loadSystem('IconSet');
  539.         var pw         = Window_Base._iconWidth;
  540.         var ph         = Window_Base._iconHeight;
  541.         var sx         = iconIndex % 16 * pw;
  542.         var sy         = Math.floor(iconIndex / 16) * ph;
  543.         bitmap.blt(iconBitmap, sx, sy, pw, ph, textState.x + 2, textState.y + (textState.height - ph) / 2);
  544.         textState.x += Window_Base._iconWidth + 4;
  545.     };

  546.     //=============================================================================
  547.     // Bitmap_Virtual
  548.     //  サイズを計算するための仮想ビットマップクラス
  549.     //=============================================================================
  550.     function Bitmap_Virtual() {
  551.         this.initialize.apply(this, arguments);
  552.     }

  553.     Bitmap_Virtual.prototype.initialize = function() {
  554.         this.window = SceneManager.getHiddenWindow();
  555.         this.width  = 0;
  556.         this.height = 0;
  557.     };

  558.     Bitmap_Virtual.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) {
  559.         var baseWidth = this.window.textWidth(text);
  560.         var fontSize  = this.window.contents.fontSize;
  561.         if (this.fontItalic) {
  562.             baseWidth += Math.floor(fontSize / 6);
  563.         }
  564.         if (this.fontBoldFotDtext) {
  565.             baseWidth += 2;
  566.         }
  567.         this.width  = Math.max(x + baseWidth, this.width);
  568.         this.height = Math.max(y + fontSize + 8, this.height);
  569.     };

  570.     Bitmap_Virtual.prototype.blt = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
  571.         this.width  = Math.max(dx + (dw || sw), this.width);
  572.         this.height = Math.max(dy + (dh || sh), this.height);
  573.     };

  574.     //=============================================================================
  575.     // Window_Hidden
  576.     //  文字描画用の隠しウィンドウ
  577.     //=============================================================================
  578.     function Window_Hidden() {
  579.         this.initialize.apply(this, arguments);
  580.     }

  581.     Window_Hidden.prototype.backOpacity = null;

  582.     Window_Hidden.prototype             = Object.create(Window_Base.prototype);
  583.     Window_Hidden.prototype.constructor = Window_Hidden;

  584.     Window_Hidden.prototype._createAllParts = function() {
  585.         this._windowBackSprite      = {};
  586.         this._windowSpriteContainer = {};
  587.         this._windowContentsSprite  = new Sprite();
  588.         this.addChild(this._windowContentsSprite);
  589.     };

  590.     Window_Hidden.prototype._refreshAllParts = function() {};

  591.     Window_Hidden.prototype._refreshBack = function() {};

  592.     Window_Hidden.prototype._refreshFrame = function() {};

  593.     Window_Hidden.prototype._refreshCursor = function() {};

  594.     Window_Hidden.prototype._refreshArrows = function() {};

  595.     Window_Hidden.prototype._refreshPauseSign = function() {};

  596.     Window_Hidden.prototype.updateTransform = function() {};

  597.     Window_Hidden.prototype.resetFontSettings = function(dTextInfo) {
  598.         if (dTextInfo) {
  599.             var customFont         = dTextInfo.font ? dTextInfo.font + ',' : '';
  600.             this.contents.fontFace = customFont + this.standardFontFace();
  601.             this.contents.fontSize = dTextInfo.size || this.standardFontSize();
  602.         } else {
  603.             Window_Base.prototype.resetFontSettings.apply(this, arguments);
  604.         }

  605.     };

  606.     Window_Hidden.prototype.obtainEscapeParamString = function(textState) {
  607.         var arr = /^\[.+?\]/.exec(textState.text.slice(textState.index));
  608.         if (arr) {
  609.             textState.index += arr[0].length;
  610.             return arr[0].substring(1, arr[0].length - 1);
  611.         } else {
  612.             return '';
  613.         }
  614.     };

  615.     //=============================================================================
  616.     // Bitmap
  617.     //  太字対応
  618.     //=============================================================================
  619.     var _Bitmap__makeFontNameText      = Bitmap.prototype._makeFontNameText;
  620.     Bitmap.prototype._makeFontNameText = function() {
  621.         return (this.fontBoldFotDtext ? 'bold ' : '') + _Bitmap__makeFontNameText.apply(this, arguments);
  622.     };
  623. })();
复制代码

https://rpg.blue/data/attachment/album/202003/28/021323lltgrsvfytfwuya5.gif
回复

使用道具 举报

梦石
0
星屑
1593
在线时间
252 小时
注册时间
2017-10-24
回帖
158
 楼主| 发表于 2017-11-17 13:44:05 | 显示全部楼层
wabcmcc 发表于 2017-11-17 10:34
https://triacontane.blogspot.com/2015/12/rpgmv-rpgmv-dtext-1-rpgmv-dtext-dtext.html作者トリアコンタ ...

感谢大神,拿去研究一下
回复

使用道具 举报

梦石
0
星屑
1593
在线时间
252 小时
注册时间
2017-10-24
回帖
158
 楼主| 发表于 2017-11-17 22:21:16 | 显示全部楼层
wabcmcc 发表于 2017-11-17 10:34
https://triacontane.blogspot.com/2015/12/rpgmv-rpgmv-dtext-1-rpgmv-dtext-dtext.html作者トリアコンタ ...

大神 我用了插件命令:D_TEXT テスト文字列 32, 但是什么反应也没有啊?求教
回复

使用道具 举报

梦石
0
星屑
16296
在线时间
4017 小时
注册时间
2015-9-14
回帖
1322

开拓者

发表于 2017-11-18 01:29:21 | 显示全部楼层
本帖最后由 wabcmcc 于 2017-11-18 13:02 编辑

我也是一樣,轉用其他插件.
如下圖,變量窗口
TMSimpleWindow.js

33.png
https://rpg.blue/data/attachment/album/202003/28/021323lltgrsvfytfwuya5.gif
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部