设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2389|回复: 4
打印 上一主题 下一主题

[有事请教] DTextPicture.js

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1390
在线时间
231 小时
注册时间
2017-10-24
帖子
209
跳转到指定楼层
1
发表于 2017-11-15 14:00:31 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
请问这个插件谁有,可以分享一下吗?

Lv4.逐梦者

梦石
0
星屑
15539
在线时间
3954 小时
注册时间
2015-9-14
帖子
1334

开拓者

2
发表于 2017-11-17 10:34:26 | 只看该作者
https://triacontane.blogspot.com/2015/12/rpgmv-rpgmv-dtext-1-rpgmv-dtext-dtext.html作者トリアコンタン:

JAVASCRIPT 代码复制下载
  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. /*:
  48.  * @plugindesc 動的文字列ピクチャ生成プラグイン
  49.  * @author トリアコンタン
  50.  *
  51.  * @help 指定した文字列でピクチャを動的に生成するコマンドを提供します。
  52.  * 文字列には各種制御文字(\v[n]等)も使用可能で、制御文字で表示した変数の値が
  53.  * 変更されたときにリアルタイムでピクチャの内容を更新できます。
  54.  *
  55.  * 以下の手順で表示します。
  56.  *  1 : プラグインコマンド[D_TEXT]で描画したい文字列と引数を指定(下記の例参照)
  57.  *  2 : プラグインコマンド[D_TEXT_SETTING]で背景色や揃えを指定(任意)
  58.  *  3 : イベントコマンド「ピクチャの表示」で「画像」を未選択に指定。
  59.  * ※ 1の時点ではピクチャは表示されないので必ずセットで呼び出してください。
  60.  * ※ ピクチャ表示前にD_TEXTを複数回実行すると、複数行表示できます。
  61.  *
  62.  * ※ ver1.4.0より、[D_TEXT]実行後に「ピクチャの表示」で「画像」を指定した場合は
  63.  *    動的文字列ピクチャ生成を保留として通常通り「画像」ピクチャが表示される
  64.  *    ように挙動が変更になりました。
  65.  *
  66.  * プラグインコマンド詳細
  67.  *   イベントコマンド「プラグインコマンド」から実行。
  68.  *   (引数の間は半角スペースで区切る)
  69.  *
  70.  *  D_TEXT [描画文字列] [文字サイズ] : 動的文字列ピクチャ生成の準備
  71.  *  例:D_TEXT テスト文字列 32
  72.  *
  73.  * 表示後は通常のピクチャと同様に移動や回転、消去ができます。
  74.  * また、変数やアクターの表示など制御文字にも対応しています。
  75.  *
  76.  *  D_TEXT_SETTING ALIGN [揃え] : 揃え(左揃え、中央揃え、右揃え)の設定
  77.  *  0:左揃え 1:中央揃え 2:右揃え
  78.  *
  79.  *  例:D_TEXT_SETTING ALIGN 0
  80.  *      D_TEXT_SETTING ALIGN CENTER
  81.  *
  82.  *  D_TEXT_SETTING BG_COLOR [背景色] : 背景色の設定(CSSの色指定と同様の書式)
  83.  *
  84.  *  例:D_TEXT_SETTING BG_COLOR black
  85.  *      D_TEXT_SETTING BG_COLOR #336699
  86.  *      D_TEXT_SETTING BG_COLOR rgba(255,255,255,0.5)
  87.  *
  88.  *  D_TEXT_SETTING REAL_TIME ON : 制御文字で表示した変数のリアルタイム表示
  89.  *
  90.  *  例:D_TEXT_SETTING REAL_TIME ON
  91.  *
  92.  *  リアルタイム表示を有効にしておくと、ピクチャの表示後に変数の値が変化したとき
  93.  *  自動でピクチャの内容も更新されます。
  94.  *
  95.  *  D_TEXT_SETTING WINDOW ON : 背景にウィンドウを表示する
  96.  *  例:D_TEXT_SETTING WINDOW ON
  97.  *
  98.  *  D_TEXT_SETTING FONT [フォント名] : 描画で使用するフォントを指定した名称に変更
  99.  *  例:D_TEXT_SETTING FONT MS P明朝
  100.  *
  101.  * これらの設定はD_TEXTと同様、ピクチャを表示する前に行ってください。
  102.  *
  103.  * 対応制御文字一覧(イベントコマンド「文章の表示」と同一です)
  104.  * \V[n]
  105.  * \N[n]
  106.  * \P[n]
  107.  * \G
  108.  * \C[n]
  109.  * \I[n]
  110.  * \{
  111.  * \}
  112.  *
  113.  * 専用制御文字
  114.  * \V[n,m](m桁分のゼロ埋めした変数の値)
  115.  * \item[n]   n 番のアイテム情報(アイコン+名称)
  116.  * \weapon[n] n 番の武器情報(アイコン+名称)
  117.  * \armor[n]  n 番の防具情報(アイコン+名称)
  118.  * \skill[n]  n 番のスキル情報(アイコン+名称)
  119.  * \state[n]  n 番のステート情報(アイコン+名称)
  120.  * \oc[c] アウトラインカラーを「c」に設定(例:\oc[red])
  121.  * \ow[n] アウトライン幅を「n」に設定(例:\ow[5])
  122.  * \f[b] フォントの太字化
  123.  * \f[i] フォントのイタリック化
  124.  * \f[n] フォントの太字とイタリックを通常に戻す
  125.  *
  126.  * 利用規約:
  127.  *  作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
  128.  *  についても制限はありません。
  129.  *  このプラグインはもうあなたのものです。
  130.  */
  131. (function() {
  132.     'use strict';
  133.  
  134.     var getCommandName = function(command) {
  135.         return (command || '').toUpperCase();
  136.     };
  137.  
  138.     var getArgNumber = function(arg, min, max) {
  139.         if (arguments.length < 2) min = -Infinity;
  140.         if (arguments.length < 3) max = Infinity;
  141.         return (parseInt(convertEscapeCharacters(arg.toString())) || 0).clamp(min, max);
  142.     };
  143.  
  144.     var getArgString = function(arg, upperFlg) {
  145.         arg = convertEscapeCharacters(arg);
  146.         return upperFlg ? arg.toUpperCase() : arg;
  147.     };
  148.  
  149.     var getArgBoolean = function(arg) {
  150.         return (arg || '').toUpperCase() === 'ON';
  151.     };
  152.  
  153.     var connectArgs = function(args, startIndex, endIndex) {
  154.         if (arguments.length < 2) startIndex = 0;
  155.         if (arguments.length < 3) endIndex = args.length;
  156.         var text = '';
  157.         for (var i = startIndex; i < endIndex; i++) {
  158.             text += args[i];
  159.             if (i < endIndex - 1) text += ' ';
  160.         }
  161.         return text;
  162.     };
  163.  
  164.     var convertEscapeCharacters = function(text) {
  165.         if (text === undefined || text === null) text = '';
  166.         var window = SceneManager.getHiddenWindow();
  167.         return window ? window.convertEscapeCharacters(text) : text;
  168.     };
  169.  
  170.     var getUsingVariables = function(text) {
  171.         var usingVariables = [];
  172.  
  173.         text = text.replace(/\\/g, '\x1b');
  174.         text = text.replace(/\x1b\x1b/g, '\\');
  175.         text = text.replace(/\x1bV\[(\d+)\,\s*(\d+)\]/gi, function() {
  176.             var number = parseInt(arguments[1], 10);
  177.             usingVariables.push(number);
  178.             return $gameVariables.value(number);
  179.         }.bind(this));
  180.         text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
  181.             var number = parseInt(arguments[1], 10);
  182.             usingVariables.push(number);
  183.             return $gameVariables.value(number);
  184.         }.bind(this));
  185.         text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
  186.             var number = parseInt(arguments[1], 10);
  187.             usingVariables.push(number);
  188.             return $gameVariables.value(number);
  189.         }.bind(this));
  190.         return usingVariables;
  191.     };
  192.  
  193.     //=============================================================================
  194.     // Game_Interpreter
  195.     //  プラグインコマンド[D_TEXT]を追加定義します。
  196.     //=============================================================================
  197.     var _Game_Interpreter_pluginCommand      = Game_Interpreter.prototype.pluginCommand;
  198.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  199.         _Game_Interpreter_pluginCommand.apply(this, arguments);
  200.         this.pluginCommandDTextPicture(command, args);
  201.     };
  202.  
  203.     Game_Interpreter.textAlignMapper = {
  204.         LEFT: 0, CENTER: 1, RIGHT: 2, 左: 0, 中央: 1, 右: 2
  205.     };
  206.  
  207.     Game_Interpreter.prototype.pluginCommandDTextPicture = function(command, args) {
  208.         switch (getCommandName(command)) {
  209.             case 'D_TEXT' :
  210.                 if (isNaN(args[args.length - 1]) || args.length === 1) args.push($gameScreen.dTextSize || 28);
  211.                 var fontSize = getArgNumber(args.pop());
  212.                 $gameScreen.setDTextPicture(connectArgs(args), fontSize);
  213.                 break;
  214.             case 'D_TEXT_SETTING':
  215.                 switch (getCommandName(args[0])) {
  216.                     case 'ALIGN' :
  217.                         $gameScreen.dTextAlign = isNaN(args[1]) ?
  218.                             Game_Interpreter.textAlignMapper[getArgString(args[1], true)] : getArgNumber(args[1], 0, 2);
  219.                         break;
  220.                     case 'BG_COLOR' :
  221.                         $gameScreen.dTextBackColor = getArgString(connectArgs(args, 1));
  222.                         break;
  223.                     case 'FONT':
  224.                         args.shift();
  225.                         $gameScreen.setDtextFont(getArgString(connectArgs(args)));
  226.                         break;
  227.                     case 'REAL_TIME' :
  228.                         $gameScreen.dTextRealTime = getArgBoolean(args[1]);
  229.                         break;
  230.                     case 'WINDOW':
  231.                         $gameScreen.dWindowFrame = getArgBoolean(args[1]);
  232.                         break;
  233.                 }
  234.                 break;
  235.         }
  236.     };
  237.  
  238.     //=============================================================================
  239.     // Game_Variables
  240.     //  値を変更した変数の履歴を取得します。
  241.     //=============================================================================
  242.     var _Game_Variables_setValue      = Game_Variables.prototype.setValue;
  243.     Game_Variables.prototype.setValue = function(variableId, value) {
  244.         if (this.value(variableId) !== value) {
  245.             this._changedVariables = this.getChangedVariables();
  246.             if (!this._changedVariables.contains(variableId)) {
  247.                 this._changedVariables.push(variableId);
  248.             }
  249.         }
  250.         _Game_Variables_setValue.apply(this, arguments);
  251.     };
  252.  
  253.     Game_Variables.prototype.getChangedVariables = function() {
  254.         return this._changedVariables || [];
  255.     };
  256.  
  257.     Game_Variables.prototype.clearChangedVariables = function() {
  258.         return this._changedVariables = [];
  259.     };
  260.  
  261.     //=============================================================================
  262.     // Game_Screen
  263.     //  動的ピクチャ用のプロパティを追加定義します。
  264.     //=============================================================================
  265.     var _Game_Screen_clear      = Game_Screen.prototype.clear;
  266.     Game_Screen.prototype.clear = function() {
  267.         _Game_Screen_clear.call(this);
  268.         this.clearDTextPicture();
  269.     };
  270.  
  271.     Game_Screen.prototype.clearDTextPicture = function() {
  272.         this.dTextValue      = null;
  273.         this.dTextOriginal   = null;
  274.         this.dTextRealTime   = null;
  275.         this.dTextSize       = 0;
  276.         this.dTextAlign      = 0;
  277.         this.dTextBackColor  = null;
  278.         this.dTextFont       = null;
  279.         this.dUsingVariables = null;
  280.         this.dWindowFrame    = null;
  281.     };
  282.  
  283.     Game_Screen.prototype.setDTextPicture = function(value, size) {
  284.         if (typeof TranslationManager !== 'undefined') {
  285.             TranslationManager.translateIfNeed(value, function(translatedText) {
  286.                 value = translatedText;
  287.             });
  288.         }
  289.         this.dUsingVariables = (this.dUsingVariables || []).concat(getUsingVariables(value));
  290.         this.dTextValue      = (this.dTextValue || '') + getArgString(value, false) + '\n';
  291.         this.dTextOriginal   = (this.dTextOriginal || '') + value + '\n';
  292.         this.dTextSize       = size;
  293.     };
  294.  
  295.     Game_Screen.prototype.getDTextPictureInfo = function() {
  296.         return {
  297.             value         : this.dTextValue,
  298.             size          : this.dTextSize || 0,
  299.             align         : this.dTextAlign || 0,
  300.             color         : this.dTextBackColor,
  301.             font          : this.dTextFont,
  302.             usingVariables: this.dUsingVariables,
  303.             realTime      : this.dTextRealTime,
  304.             originalValue : this.dTextOriginal,
  305.             windowFrame   : this.dWindowFrame
  306.         };
  307.     };
  308.  
  309.     Game_Screen.prototype.isSettingDText = function() {
  310.         return !!this.dTextValue;
  311.     };
  312.  
  313.     Game_Screen.prototype.setDtextFont = function(name) {
  314.         this.dTextFont = name;
  315.     };
  316.  
  317.     var _Game_Screen_updatePictures      = Game_Screen.prototype.updatePictures;
  318.     Game_Screen.prototype.updatePictures = function() {
  319.         _Game_Screen_updatePictures.apply(this, arguments);
  320.         $gameVariables.clearChangedVariables();
  321.     };
  322.  
  323.     //=============================================================================
  324.     // Game_Picture
  325.     //  動的ピクチャ用のプロパティを追加定義し、表示処理を動的ピクチャ対応に変更します。
  326.     //=============================================================================
  327.     var _Game_Picture_initBasic      = Game_Picture.prototype.initBasic;
  328.     Game_Picture.prototype.initBasic = function() {
  329.         _Game_Picture_initBasic.call(this);
  330.         this.dTextValue = null;
  331.         this.dTextInfo  = null;
  332.     };
  333.  
  334.     var _Game_Picture_show      = Game_Picture.prototype.show;
  335.     Game_Picture.prototype.show = function(name, origin, x, y, scaleX,
  336.                                            scaleY, opacity, blendMode) {
  337.         if ($gameScreen.isSettingDText() && !name) {
  338.             arguments[0]   = Date.now().toString();
  339.             this.dTextInfo = $gameScreen.getDTextPictureInfo();
  340.             $gameScreen.clearDTextPicture();
  341.         } else {
  342.             this.dTextInfo = null;
  343.         }
  344.         _Game_Picture_show.apply(this, arguments);
  345.     };
  346.  
  347.     var _Game_Picture_update      = Game_Picture.prototype.update;
  348.     Game_Picture.prototype.update = function() {
  349.         _Game_Picture_update.apply(this, arguments);
  350.         if (this.dTextInfo && this.dTextInfo.realTime) {
  351.             this.updateDTextVariable();
  352.         }
  353.     };
  354.  
  355.     Game_Picture.prototype.updateDTextVariable = function() {
  356.         $gameVariables.getChangedVariables().forEach(function(variableId) {
  357.             if (this.dTextInfo.usingVariables.contains(variableId)) {
  358.                 this._name           = Date.now().toString();
  359.                 this.dTextInfo.value = getArgString(this.dTextInfo.originalValue, false);
  360.             }
  361.         }, this);
  362.     };
  363.  
  364.     //=============================================================================
  365.     // SceneManager
  366.     //  文字描画用の隠しウィンドウを取得します。
  367.     //=============================================================================
  368.     SceneManager.getHiddenWindow = function() {
  369.         if (!this._hiddenWindow) {
  370.             this._hiddenWindow = new Window_Hidden(1, 1, 1, 1);
  371.         }
  372.         return this._hiddenWindow;
  373.     };
  374.  
  375.     SceneManager.getSpriteset = function() {
  376.         return this._scene._spriteset;
  377.     };
  378.  
  379.     //=============================================================================
  380.     // Window_Base
  381.     //  文字列変換処理に追加制御文字を設定します。
  382.     //=============================================================================
  383.     var _Window_Base_convertEscapeCharacters      = Window_Base.prototype.convertEscapeCharacters;
  384.     Window_Base.prototype.convertEscapeCharacters = function(text) {
  385.         text = _Window_Base_convertEscapeCharacters.call(this, text);
  386.         text = text.replace(/\x1bV\[(\d+)\,\s*(\d+)\]/gi, function() {
  387.             return this.getVariablePadZero($gameVariables.value(parseInt(arguments[1], 10)), arguments[2]);
  388.         }.bind(this));
  389.         text = text.replace(/\x1bITEM\[(\d+)\]/gi, function() {
  390.             var item = $dataItems[getArgNumber(arguments[1], 1, $dataItems.length)];
  391.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  392.         }.bind(this));
  393.         text = text.replace(/\x1bWEAPON\[(\d+)\]/gi, function() {
  394.             var item = $dataWeapons[getArgNumber(arguments[1], 1, $dataWeapons.length)];
  395.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  396.         }.bind(this));
  397.         text = text.replace(/\x1bARMOR\[(\d+)\]/gi, function() {
  398.             var item = $dataArmors[getArgNumber(arguments[1], 1, $dataArmors.length)];
  399.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  400.         }.bind(this));
  401.         text = text.replace(/\x1bSKILL\[(\d+)\]/gi, function() {
  402.             var item = $dataSkills[getArgNumber(arguments[1], 1, $dataSkills.length)];
  403.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  404.         }.bind(this));
  405.         text = text.replace(/\x1bSTATE\[(\d+)\]/gi, function() {
  406.             var item = $dataStates[getArgNumber(arguments[1], 1, $dataStates.length)];
  407.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  408.         }.bind(this));
  409.         return text;
  410.     };
  411.  
  412.     Window_Base.prototype.getVariablePadZero = function(value, digit) {
  413.         return (value < 0 ? '-' : '') + Math.abs(value).padZero(digit);
  414.     };
  415.  
  416.     //=============================================================================
  417.     // Sprite_Picture
  418.     //  画像の動的生成を追加定義します。
  419.     //=============================================================================
  420.     var _Sprite_Picture_update      = Sprite_Picture.prototype.update;
  421.     Sprite_Picture.prototype.update = function() {
  422.         _Sprite_Picture_update.apply(this, arguments);
  423.         if (this._frameWindow) {
  424.             this.updateFrameWindow();
  425.         }
  426.     };
  427.  
  428.     Sprite_Picture.prototype.updateFrameWindow = function() {
  429.         var padding = this._frameWindow.standardPadding();
  430.         this._frameWindow.x = this.x - (this.anchor.x * this.width * this.scale.x) - padding;
  431.         this._frameWindow.y = this.y - (this.anchor.y * this.height * this.scale.y) - padding;
  432.         if (!this.visible) {
  433.             this.removeFrameWindow();
  434.             return;
  435.         }
  436.         if (!this._addFrameWindow) {
  437.             this.addFrameWindow();
  438.         }
  439.         if (Graphics.frameCount % 2 === 0) {
  440.             this.adjustScaleFrameWindow();
  441.         }
  442.     };
  443.  
  444.     Sprite_Picture.prototype.adjustScaleFrameWindow = function() {
  445.         var padding = this._frameWindow.standardPadding();
  446.         var newFrameWidth = Math.floor(this.width * this.scale.x + padding * 2);
  447.         var newFrameHeight = Math.floor(this.height * this.scale.x + padding * 2);
  448.         if (this._frameWindow.width !== newFrameWidth || this._frameWindow.height !== newFrameHeight) {
  449.             this._frameWindow.move(this._frameWindow.x, this._frameWindow.y, newFrameWidth, newFrameHeight);
  450.         }
  451.     };
  452.  
  453.     Sprite_Picture.prototype.addFrameWindow = function() {
  454.         var parent = this.parent;
  455.         if (parent) {
  456.             var index = parent.getChildIndex(this);
  457.             parent.addChildAt(this._frameWindow, index);
  458.             this._addFrameWindow = true;
  459.         }
  460.     };
  461.  
  462.     Sprite_Picture.prototype.removeFrameWindow = function() {
  463.         var parent = this.parent;
  464.         if (parent) {
  465.             parent.removeChild(this._frameWindow);
  466.             this._frameWindow    = null;
  467.             this._addFrameWindow = false;
  468.         }
  469.     };
  470.  
  471.     var _Sprite_Picture_loadBitmap      = Sprite_Picture.prototype.loadBitmap;
  472.     Sprite_Picture.prototype.loadBitmap = function() {
  473.         this.dTextInfo = this.picture().dTextInfo;
  474.         if (this.dTextInfo) {
  475.             this.makeDynamicBitmap();
  476.         } else {
  477.             _Sprite_Picture_loadBitmap.apply(this, arguments);
  478.         }
  479.     };
  480.  
  481.     Sprite_Picture.prototype.makeDynamicBitmap = function() {
  482.         this.textWidths   = [];
  483.         this.hiddenWindow = SceneManager.getHiddenWindow();
  484.         this.hiddenWindow.resetFontSettings(this.dTextInfo);
  485.         var bitmapVirtual = new Bitmap_Virtual();
  486.         this._processText(bitmapVirtual);
  487.         this.hiddenWindow.resetFontSettings(this.dTextInfo);
  488.         this.bitmap          = new Bitmap(bitmapVirtual.width, bitmapVirtual.height);
  489.         this.bitmap.fontFace = this.hiddenWindow.contents.fontFace;
  490.         if (this.dTextInfo.color) {
  491.             this.bitmap.fillAll(this.dTextInfo.color);
  492.         }
  493.         this._processText(this.bitmap);
  494.         this._colorTone = [0, 0, 0, 0];
  495.         if (this._frameWindow) {
  496.             this.removeFrameWindow();
  497.         }
  498.         if (this.dTextInfo.windowFrame) {
  499.             var scaleX = this.picture().scaleX() / 100;
  500.             var scaleY = this.picture().scaleY() / 100;
  501.             this.makeFrameWindow(bitmapVirtual.width * scaleX, bitmapVirtual.height * scaleY);
  502.         }
  503.         this.hiddenWindow = null;
  504.     };
  505.  
  506.     Sprite_Picture.prototype.makeFrameWindow = function(width, height) {
  507.         var padding             = this.hiddenWindow.standardPadding();
  508.         this._frameWindow       = new Window_Base(0, 0, width + padding * 2, height + padding * 2);
  509.     };
  510.  
  511.     Sprite_Picture.prototype._processText = function(bitmap) {
  512.         var textState = {index: 0, x: 0, y: 0, text: this.dTextInfo.value, left: 0, line: -1, height: 0};
  513.         this._processNewLine(textState, bitmap);
  514.         textState.height = this.hiddenWindow.calcTextHeight(textState, false);
  515.         textState.index  = 0;
  516.         while (textState.text[textState.index]) {
  517.             this._processCharacter(textState, bitmap);
  518.         }
  519.     };
  520.  
  521.     Sprite_Picture.prototype._processCharacter = function(textState, bitmap) {
  522.         if (textState.text[textState.index] === '\x1b') {
  523.             var code = this.hiddenWindow.obtainEscapeCode(textState);
  524.             switch (code) {
  525.                 case 'C':
  526.                     bitmap.textColor = this.hiddenWindow.textColor(this.hiddenWindow.obtainEscapeParam(textState));
  527.                     break;
  528.                 case 'I':
  529.                     this._processDrawIcon(this.hiddenWindow.obtainEscapeParam(textState), textState, bitmap);
  530.                     break;
  531.                 case '{':
  532.                     this.hiddenWindow.makeFontBigger();
  533.                     break;
  534.                 case '}':
  535.                     this.hiddenWindow.makeFontSmaller();
  536.                     break;
  537.                 case 'F':
  538.                     switch (this.hiddenWindow.obtainEscapeParamString(textState).toUpperCase()) {
  539.                         case 'I':
  540.                             bitmap.fontItalic = true;
  541.                             break;
  542.                         case 'B':
  543.                             bitmap.fontBoldFotDtext = true;
  544.                             break;
  545.                         case '/':
  546.                         case 'N':
  547.                             bitmap.fontItalic       = false;
  548.                             bitmap.fontBoldFotDtext = false;
  549.                             break;
  550.                     }
  551.                     break;
  552.                 case 'OC':
  553.                     bitmap.outlineColor = this.hiddenWindow.obtainEscapeParamString(textState);
  554.                     break;
  555.                 case 'OW':
  556.                     bitmap.outlineWidth = this.hiddenWindow.obtainEscapeParam(textState);
  557.                     break;
  558.             }
  559.         } else if (textState.text[textState.index] === '\n') {
  560.             this._processNewLine(textState, bitmap);
  561.         } else {
  562.             var c = textState.text[textState.index++];
  563.             var w = this.hiddenWindow.textWidth(c);
  564.  
  565.             bitmap.fontSize = this.hiddenWindow.contents.fontSize;
  566.             bitmap.drawText(c, textState.x, textState.y, w * 2, textState.height, 'left');
  567.             textState.x += w;
  568.         }
  569.     };
  570.  
  571.     Sprite_Picture.prototype._processNewLine = function(textState, bitmap) {
  572.         if (bitmap instanceof Bitmap_Virtual)
  573.             this.textWidths[textState.line] = textState.x;
  574.         this.hiddenWindow.processNewLine(textState);
  575.         textState.line++;
  576.         if (bitmap instanceof Bitmap)
  577.             textState.x = (bitmap.width - this.textWidths[textState.line]) / 2 * this.dTextInfo.align;
  578.     };
  579.  
  580.     Sprite_Picture.prototype._processDrawIcon = function(iconIndex, textState, bitmap) {
  581.         var iconBitmap = ImageManager.loadSystem('IconSet');
  582.         var pw         = Window_Base._iconWidth;
  583.         var ph         = Window_Base._iconHeight;
  584.         var sx         = iconIndex % 16 * pw;
  585.         var sy         = Math.floor(iconIndex / 16) * ph;
  586.         bitmap.blt(iconBitmap, sx, sy, pw, ph, textState.x + 2, textState.y + (textState.height - ph) / 2);
  587.         textState.x += Window_Base._iconWidth + 4;
  588.     };
  589.  
  590.     //=============================================================================
  591.     // Bitmap_Virtual
  592.     //  サイズを計算するための仮想ビットマップクラス
  593.     //=============================================================================
  594.     function Bitmap_Virtual() {
  595.         this.initialize.apply(this, arguments);
  596.     }
  597.  
  598.     Bitmap_Virtual.prototype.initialize = function() {
  599.         this.window = SceneManager.getHiddenWindow();
  600.         this.width  = 0;
  601.         this.height = 0;
  602.     };
  603.  
  604.     Bitmap_Virtual.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) {
  605.         var baseWidth = this.window.textWidth(text);
  606.         var fontSize  = this.window.contents.fontSize;
  607.         if (this.fontItalic) {
  608.             baseWidth += Math.floor(fontSize / 6);
  609.         }
  610.         if (this.fontBoldFotDtext) {
  611.             baseWidth += 2;
  612.         }
  613.         this.width  = Math.max(x + baseWidth, this.width);
  614.         this.height = Math.max(y + fontSize + 8, this.height);
  615.     };
  616.  
  617.     Bitmap_Virtual.prototype.blt = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
  618.         this.width  = Math.max(dx + (dw || sw), this.width);
  619.         this.height = Math.max(dy + (dh || sh), this.height);
  620.     };
  621.  
  622.     //=============================================================================
  623.     // Window_Hidden
  624.     //  文字描画用の隠しウィンドウ
  625.     //=============================================================================
  626.     function Window_Hidden() {
  627.         this.initialize.apply(this, arguments);
  628.     }
  629.  
  630.     Window_Hidden.prototype.backOpacity = null;
  631.  
  632.     Window_Hidden.prototype             = Object.create(Window_Base.prototype);
  633.     Window_Hidden.prototype.constructor = Window_Hidden;
  634.  
  635.     Window_Hidden.prototype._createAllParts = function() {
  636.         this._windowBackSprite      = {};
  637.         this._windowSpriteContainer = {};
  638.         this._windowContentsSprite  = new Sprite();
  639.         this.addChild(this._windowContentsSprite);
  640.     };
  641.  
  642.     Window_Hidden.prototype._refreshAllParts = function() {};
  643.  
  644.     Window_Hidden.prototype._refreshBack = function() {};
  645.  
  646.     Window_Hidden.prototype._refreshFrame = function() {};
  647.  
  648.     Window_Hidden.prototype._refreshCursor = function() {};
  649.  
  650.     Window_Hidden.prototype._refreshArrows = function() {};
  651.  
  652.     Window_Hidden.prototype._refreshPauseSign = function() {};
  653.  
  654.     Window_Hidden.prototype.updateTransform = function() {};
  655.  
  656.     Window_Hidden.prototype.resetFontSettings = function(dTextInfo) {
  657.         if (dTextInfo) {
  658.             var customFont         = dTextInfo.font ? dTextInfo.font + ',' : '';
  659.             this.contents.fontFace = customFont + this.standardFontFace();
  660.             this.contents.fontSize = dTextInfo.size || this.standardFontSize();
  661.         } else {
  662.             Window_Base.prototype.resetFontSettings.apply(this, arguments);
  663.         }
  664.  
  665.     };
  666.  
  667.     Window_Hidden.prototype.obtainEscapeParamString = function(textState) {
  668.         var arr = /^\[.+?\]/.exec(textState.text.slice(textState.index));
  669.         if (arr) {
  670.             textState.index += arr[0].length;
  671.             return arr[0].substring(1, arr[0].length - 1);
  672.         } else {
  673.             return '';
  674.         }
  675.     };
  676.  
  677.     //=============================================================================
  678.     // Bitmap
  679.     //  太字対応
  680.     //=============================================================================
  681.     var _Bitmap__makeFontNameText      = Bitmap.prototype._makeFontNameText;
  682.     Bitmap.prototype._makeFontNameText = function() {
  683.         return (this.fontBoldFotDtext ? 'bold ' : '') + _Bitmap__makeFontNameText.apply(this, arguments);
  684.     };
  685. })();

回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1390
在线时间
231 小时
注册时间
2017-10-24
帖子
209
3
 楼主| 发表于 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作者トリアコンタ ...

感谢大神,拿去研究一下
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1390
在线时间
231 小时
注册时间
2017-10-24
帖子
209
4
 楼主| 发表于 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, 但是什么反应也没有啊?求教
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
15539
在线时间
3954 小时
注册时间
2015-9-14
帖子
1334

开拓者

5
发表于 2017-11-18 01:29:21 | 只看该作者
本帖最后由 wabcmcc 于 2017-11-18 13:02 编辑

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


回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-2 16:01

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表