查看: 2926|回复: 4

[有事请教] 【求移植】MV的显示文字插件

[复制链接]
梦石
0
星屑
2632
在线时间
420 小时
注册时间
2016-2-3
回帖
679
发表于 2020-10-31 20:35:06 | 显示全部楼层 |阅读模式
悬赏100星屑已解决
  1. //=============================================================================
  2. // DTextPicture.js
  3. // ----------------------------------------------------------------------------
  4. // Copyright (c) 2015 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.2.2 2016/03/28 データベース情報を簡単に出力する制御文字を追加
  10. // 1.2.1 2016/01/29 コマンド「D_TEXT_SETTING」の実装が「D_TEST_SETTING」になっていたので修正(笑)
  11. // 1.2.0 2016/01/27 複数行表示に対応
  12. //                  文字列の揃えと背景色を設定する機能を追加
  13. //                  変数をゼロ埋めして表示する機能を追加
  14. // 1.1.3 2015/12/10 戦闘画面でもピクチャを使用できるよう修正
  15. //                  描画後にデバッグ画面等を開いて変数を修正した場合、再描画で変更が反映されてしまう問題を修正
  16. // 1.1.2 2015/11/07 描画文字列に半角スペースが含まれていた場合も問題なく実行できるよう修正
  17. // 1.1.0 2015/11/07 制御文字\C[n] \I[n] \{ \} に対応(\$と表示スピード制御系以外全部)
  18. // 1.0.1 2015/11/07 RPGツクールMV(日本語版)に合わせてコメントの表記を変更
  19. // 1.0.0 2015/11/06 初版
  20. // ----------------------------------------------------------------------------
  21. // [Blog]   : [url]http://triacontane.blogspot.jp/[/url]
  22. // [Twitter]: [url]https://twitter.com/triacontane/[/url]
  23. // [GitHub] : [url]https://github.com/triacontane/[/url]
  24. //=============================================================================

  25. /*:
  26. * @plugindesc 動的文字列ピクチャ生成プラグイン
  27. * @author トリアコンタン
  28. *
  29. * @help 指定した文字列でピクチャを動的に生成するコマンドを提供します。
  30. * 以下の手順で表示します。
  31. *  1 : プラグインコマンド[D_TEXT]で描画したい文字列と引数を指定(下記の例参照)
  32. *  2 : プラグインコマンド[D_TEXT_SETTING]で背景色や揃えを指定(任意)
  33. *  3 : イベントコマンド「ピクチャの表示」で「画像」を未選択に指定。
  34. * ※ 1の時点ではピクチャは表示されないので必ずセットで呼び出してください。
  35. * ※ ピクチャ表示前にD_TEXTを複数回実行すると、複数行表示できます。
  36. *
  37. * プラグインコマンド詳細
  38. *   イベントコマンド「プラグインコマンド」から実行。
  39. *   (引数の間は半角スペースで区切る)
  40. *
  41. *  D_TEXT [描画文字列] [文字サイズ] : 動的文字列ピクチャ生成の準備
  42. *  例:D_TEXT テスト文字列 32
  43. *
  44. * 表示後は通常のピクチャと同様に移動や回転、消去ができます。
  45. * また、変数やアクターの表示など制御文字にも対応しています。
  46. *
  47. *  D_TEXT_SETTING ALIGN [揃え] : 揃え(左揃え、中央揃え、右揃え)の設定
  48. *  0:左揃え 1:中央揃え 2:右揃え
  49. *
  50. *  例:D_TEXT_SETTING ALIGN 0
  51. *      D_TEXT_SETTING ALIGN CENTER
  52. *
  53. *  D_TEXT_SETTING BG_COLOR [背景色] : 背景色の設定(CSSの色指定と同様の書式)
  54. *
  55. *  例:D_TEXT_SETTING BG_COLOR black
  56. *      D_TEXT_SETTING BG_COLOR #336699
  57. *      D_TEXT_SETTING BG_COLOR rgba(255,255,255,0.5)
  58. *
  59. * これらの設定はD_TEXTと同様、ピクチャを表示する前に行ってください。
  60. *
  61. * 対応制御文字一覧(イベントコマンド「文章の表示」と同一です)
  62. * \V[n]
  63. * \N[n]
  64. * \P[n]
  65. * \G
  66. * \C[n]
  67. * \I[n]
  68. * \{
  69. * \}
  70. *
  71. * 専用制御文字
  72. * \V[n,m](m桁分のゼロ埋めした変数の値)
  73. * \item[n]   n 番のアイテム情報(アイコン+名称)
  74. * \weapon[n] n 番の武器情報(アイコン+名称)
  75. * \armor[n]  n 番の防具情報(アイコン+名称)
  76. * \skill[n]  n 番のスキル情報(アイコン+名称)
  77. * \state[n]  n 番のステート情報(アイコン+名称)
  78. *
  79. * 利用規約:
  80. *  作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
  81. *  についても制限はありません。
  82. *  このプラグインはもうあなたのものです。
  83. */
  84. (function () {

  85.     var getCommandName = function (command) {
  86.         return (command || '').toUpperCase();
  87.     };

  88.     var getArgNumber = function (arg, min, max) {
  89.         if (arguments.length < 2) min = -Infinity;
  90.         if (arguments.length < 3) max = Infinity;
  91.         return (parseInt(convertEscapeCharacters(arg.toString()), 10) || 0).clamp(min, max);
  92.     };

  93.     var getArgString = function (arg, upperFlg) {
  94.         arg = convertEscapeCharacters(arg);
  95.         return upperFlg ? arg.toUpperCase() : arg;
  96.     };

  97.     var connectArgs = function (args, startIndex, endIndex) {
  98.         if (arguments.length < 2) startIndex = 0;
  99.         if (arguments.length < 3) endIndex = args.length;
  100.         var text = '';
  101.         for (var i = startIndex; i < endIndex; i++) {
  102.             text += args[i];
  103.             if (i < endIndex - 1) text += ' ';
  104.         }
  105.         return text;
  106.     };

  107.     var convertEscapeCharacters = function(text) {
  108.         if (text == null) text = '';
  109.         var window = SceneManager.getHiddenWindow();
  110.         return window ? window.convertEscapeCharacters(text) : text;
  111.     };

  112.     SceneManager.getHiddenWindow = function() {
  113.         return this._scene._hiddenWindow;
  114.     };


  115.     //=============================================================================
  116.     // Game_Interpreter
  117.     //  プラグインコマンド[D_TEXT]を追加定義します。
  118.     //=============================================================================
  119.     var _Game_Interpreter_pluginCommand      = Game_Interpreter.prototype.pluginCommand;
  120.     Game_Interpreter.prototype.pluginCommand = function (command, args) {
  121.         _Game_Interpreter_pluginCommand.apply(this, arguments);
  122.         try {
  123.             this.pluginCommandDTextPicture(command, args);
  124.         } catch (e) {
  125.             if ($gameTemp.isPlaytest() && Utils.isNwjs()) {
  126.                 var window = require('nw.gui').Window.get();
  127.                 if (!window.isDevToolsOpen()) {
  128.                     var devTool = window.showDevTools();
  129.                     devTool.moveTo(0, 0);
  130.                     devTool.resizeTo(Graphics.width, Graphics.height);
  131.                     window.focus();
  132.                 }
  133.             }
  134.             console.log('プラグインコマンドの実行中にエラーが発生しました。');
  135.             console.log('- コマンド名  : ' + command);
  136.             console.log('- コマンド引数 : ' + args);
  137.             console.log('- エラー原因   : ' + e.toString());
  138.         }
  139.     };

  140.     Game_Interpreter.textAlignMapper = {
  141.         LEFT:0, CENTER:1, RIGHT:2, 左:0, 中央:1, 右:2
  142.     };

  143.     Game_Interpreter.prototype.pluginCommandDTextPicture = function(command, args) {
  144.         switch (getCommandName(command)) {
  145.             case 'D_TEXT' :
  146.                 if (isNaN(args[args.length - 1])) args.push($gameScreen.dTextSize || 28);
  147.                 var fontSize = getArgNumber(args.pop());
  148.                 $gameScreen.setDTextPicture(getArgString(connectArgs(args), false), fontSize);
  149.                 break;
  150.                                
  151.                                
  152.             case 'D_TEXT_SETTING':
  153.                 switch (getCommandName(args[0])) {
  154.                     case 'ALIGN' :
  155.                         $gameScreen.dTextAlign = isNaN(args[1]) ?
  156.                             Game_Interpreter.textAlignMapper[getArgString(args[1], true)] : getArgNumber(args[1], 0, 2);
  157.                         break;
  158.                     case 'BG_COLOR' :
  159.                         $gameScreen.dTextBackColor = getArgString(connectArgs(args, 1));
  160.                         break;
  161.                     case 'FONT':
  162.                         $gameScreen.setFont(getArgString(args[1]));
  163.                         break;
  164.                 }
  165.                 break;
  166.         }
  167.     };

  168.     //=============================================================================
  169.     // Game_Screen
  170.     //  動的ピクチャ用のプロパティを追加定義します。
  171.     //=============================================================================
  172.     var _Game_Screen_clear = Game_Screen.prototype.clear;
  173.     Game_Screen.prototype.clear = function() {
  174.         _Game_Screen_clear.call(this);
  175.         this.clearDTextPicture();
  176.     };

  177.     Game_Screen.prototype.clearDTextPicture = function() {
  178.         this.dTextValue = null;
  179.         this.dTextSize  = 0;
  180.         this.dTextAlign = 0;
  181.         this.dTextBackColor = null;
  182.         this.dTextFont = null;
  183.     };

  184.     Game_Screen.prototype.setDTextPicture = function(value, size) {
  185.         if (!this.dTextValue) this.dTextValue = [];
  186.         this.dTextValue.push(value);
  187.         this.dTextSize = size;
  188.     };

  189.     Game_Screen.prototype.getDTextPictureInfo = function() {
  190.         return {value:this.dTextValue, size:this.dTextSize, align:this.dTextAlign,
  191.             color:this.dTextBackColor, font:this.dTextFont};
  192.     };

  193.     Game_Screen.prototype.isSettingDText = function() {
  194.         return !!this.dTextValue;
  195.     };

  196.     Game_Screen.prototype.setFont = function(name) {
  197.         if (Graphics.isFontLoaded(name)) {
  198.             this.dTextFont = name;
  199.         }
  200.     };

  201.     //=============================================================================
  202.     // Game_Picture
  203.     //  動的ピクチャ用のプロパティを追加定義し、表示処理を動的ピクチャ対応に変更します。
  204.     //=============================================================================
  205.     var _Game_Picture_initBasic = Game_Picture.prototype.initBasic;
  206.     Game_Picture.prototype.initBasic = function() {
  207.         _Game_Picture_initBasic.call(this);
  208.         this.dTextValue = null;
  209.         this.dTextInfo = null;
  210.     };

  211.     var _Game_Picture_show = Game_Picture.prototype.show;
  212.     Game_Picture.prototype.show = function(name, origin, x, y, scaleX,
  213.                                            scaleY, opacity, blendMode) {
  214.         if ($gameScreen.isSettingDText()) {
  215.             arguments[0] = Date.now().toString();
  216.             var textValue = "";
  217.             this.dTextInfo = $gameScreen.getDTextPictureInfo();
  218.             this.dTextInfo.value.forEach(function(text) {
  219.                 textValue +=  text + '\n';
  220.             }.bind(this));
  221.             this.dTextInfo.value = textValue;
  222.         } else {
  223.             this.dTextInfo = null;
  224.         }
  225.         $gameScreen.clearDTextPicture();
  226.         _Game_Picture_show.apply(this, arguments);
  227.     };

  228.     var _Window_Base_convertEscapeCharacters = Window_Base.prototype.convertEscapeCharacters;
  229.     Window_Base.prototype.convertEscapeCharacters = function(text) {
  230.         text = _Window_Base_convertEscapeCharacters.call(this, text);
  231.         text = text.replace(/\x1bV\[(\d+)\,(\d+)\]/gi, function() {
  232.             return $gameVariables.value(parseInt(arguments[1])).padZero(arguments[2]);
  233.         }.bind(this));
  234.         text = text.replace(/\x1bITEM\[(\d+)\]/gi, function() {
  235.             var item = $dataItems[getArgNumber(arguments[1], 1, $dataItems.length)];
  236.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  237.         }.bind(this));
  238.         text = text.replace(/\x1bWEAPON\[(\d+)\]/gi, function() {
  239.             var item = $dataWeapons[getArgNumber(arguments[1], 1, $dataWeapons.length)];
  240.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  241.         }.bind(this));
  242.         text = text.replace(/\x1bARMOR\[(\d+)\]/gi, function() {
  243.             var item = $dataArmors[getArgNumber(arguments[1], 1, $dataArmors.length)];
  244.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  245.         }.bind(this));
  246.         text = text.replace(/\x1bSKILL\[(\d+)\]/gi, function() {
  247.             var item = $dataSkills[getArgNumber(arguments[1], 1, $dataSkills.length)];
  248.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  249.         }.bind(this));
  250.         text = text.replace(/\x1bSTATE\[(\d+)\]/gi, function() {
  251.             var item = $dataStates[getArgNumber(arguments[1], 1, $dataStates.length)];
  252.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  253.         }.bind(this));
  254.         return text;
  255.     };

  256.     //=============================================================================
  257.     // Sprite_Picture
  258.     //  画像の動的生成を追加定義します。
  259.     //=============================================================================
  260.     var _Sprite_Picture_loadBitmap = Sprite_Picture.prototype.loadBitmap;
  261.     Sprite_Picture.prototype.loadBitmap = function() {
  262.         this.dTextInfo = this.picture().dTextInfo;
  263.         if (this.dTextInfo) {
  264.             this.makeDynamicBitmap();
  265.         } else {
  266.             _Sprite_Picture_loadBitmap.call(this);
  267.         }
  268.     };

  269.     Sprite_Picture.prototype.makeDynamicBitmap = function() {
  270.         this.textWidths = [];
  271.         this.hiddenWindow = SceneManager.getHiddenWindow();
  272.         if (this.dTextInfo.font) this.hiddenWindow.contents.fontFace = this.dTextInfo.font;
  273.         if (this.dTextInfo.size > 0) this.hiddenWindow.contents.fontSize = this.dTextInfo.size;
  274.         var bitmapVirtual = new Bitmap_Virtual();
  275.         this._processText(bitmapVirtual);
  276.         this.bitmap = new Bitmap(bitmapVirtual.width, bitmapVirtual.height);
  277.         if (this.dTextInfo.font) this.bitmap.fontFace = this.dTextInfo.font;
  278.         if (this.dTextInfo.color) this.bitmap.fillAll(this.dTextInfo.color);
  279.         this._processText(this.bitmap);
  280.         this.hiddenWindow = null;
  281.     };

  282.     Sprite_Picture.prototype._processText = function(bitmap) {
  283.         var textState = {index: 0, x: 0, y: 0, text: this.dTextInfo.value, left:0, line:-1, height:0};
  284.         this._processNewLine(textState, bitmap);
  285.         textState.height = this.hiddenWindow.calcTextHeight(textState, false);
  286.         textState.index  = 0;
  287.         while (textState.text[textState.index]) {
  288.             this._processCharacter(textState, bitmap);
  289.         }
  290.     };

  291.     Sprite_Picture.prototype._processCharacter = function(textState, bitmap) {
  292.         if (textState.text[textState.index] === '\x1b') {
  293.             var code = this.hiddenWindow.obtainEscapeCode(textState);
  294.             switch (code) {
  295.                 case 'C':
  296.                     bitmap.textColor = this.hiddenWindow.textColor(this.hiddenWindow.obtainEscapeParam(textState));
  297.                     break;
  298.                 case 'I':
  299.                     this._processDrawIcon(this.hiddenWindow.obtainEscapeParam(textState), textState, bitmap);
  300.                     break;
  301.                 case '{':
  302.                     this.hiddenWindow.makeFontBigger();
  303.                     break;
  304.                 case '}':
  305.                     this.hiddenWindow.makeFontSmaller();
  306.                     break;
  307.                 case 'F':
  308.                     switch (this.hiddenWindow.obtainEscapeParam(textState)) {
  309.                         case 'I':
  310.                             bitmap.fontItalic = true;
  311.                             break;
  312.                         case '/':
  313.                         case 'N':
  314.                             bitmap.fontItalic = false;
  315.                             break;
  316.                     }
  317.                     break;
  318.             }
  319.         } else if (textState.text[textState.index] === '\n') {
  320.             this._processNewLine(textState, bitmap);
  321.         } else {
  322.             var c = textState.text[textState.index++];
  323.             var w = this.hiddenWindow.textWidth(c);
  324.             bitmap.fontSize = this.hiddenWindow.contents.fontSize;
  325.             bitmap.drawText(c, textState.x, textState.y, w * 2, textState.height, "left");
  326.             textState.x += w;
  327.         }
  328.     };

  329.     Sprite_Picture.prototype._processNewLine = function(textState, bitmap) {
  330.         if (bitmap instanceof Bitmap_Virtual)
  331.             this.textWidths[textState.line] = textState.x;
  332.         this.hiddenWindow.processNewLine(textState);
  333.         textState.line++;
  334.         if (bitmap instanceof Bitmap)
  335.             textState.x = (bitmap.width - this.textWidths[textState.line]) / 2 * this.dTextInfo.align;
  336.     };

  337.     Sprite_Picture.prototype._processDrawIcon = function(iconIndex, textState, bitmap) {
  338.         var iconBitmap = ImageManager.loadSystem('IconSet');
  339.         var pw = Window_Base._iconWidth;
  340.         var ph = Window_Base._iconHeight;
  341.         var sx = iconIndex % 16 * pw;
  342.         var sy = Math.floor(iconIndex / 16) * ph;
  343.         bitmap.blt(iconBitmap, sx, sy, pw, ph, textState.x + 2, textState.y + (textState.height - ph) / 2);
  344.         textState.x += Window_Base._iconWidth + 4;
  345.     };

  346.     //=============================================================================
  347.     // Scene_Map
  348.     //  動的ピクチャ作成用の隠しウィンドウを追加定義します。
  349.     //=============================================================================
  350.     var _Scene_Map_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  351.     Scene_Map.prototype.createDisplayObjects = function() {
  352.         this._hiddenWindow = new Window_Base(1,1,1,1);
  353.         this._hiddenWindow.hide();
  354.         this._hiddenWindow.deactivate();
  355.         _Scene_Map_createDisplayObjects.call(this);
  356.         this.addChild(this._hiddenWindow);
  357.     };

  358.     //=============================================================================
  359.     // Scene_Battle
  360.     //  動的ピクチャ作成用の隠しウィンドウを追加定義します。
  361.     //=============================================================================
  362.     var _Scene_Battle_createDisplayObjects = Scene_Battle.prototype.createDisplayObjects;
  363.     Scene_Battle.prototype.createDisplayObjects = function() {
  364.         this._hiddenWindow = new Window_Base(1,1,1,1);
  365.         this._hiddenWindow.hide();
  366.         this._hiddenWindow.deactivate();
  367.         _Scene_Battle_createDisplayObjects.call(this);
  368.         this.addChild(this._hiddenWindow);
  369.     };

  370.     //=============================================================================
  371.     // Bitmap_Virtual
  372.     //  サイズを計算するための仮想ビットマップクラス
  373.     //=============================================================================
  374.     function Bitmap_Virtual() {
  375.         this.initialize.apply(this, arguments);
  376.     }

  377.     Bitmap_Virtual.prototype.initialize = function() {
  378.         this.window = SceneManager.getHiddenWindow();
  379.         this.width = 0;
  380.         this.height = 0;
  381.     };

  382.     Bitmap_Virtual.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) {
  383.         this.width  = Math.max(x + this.window.textWidth(text), this.width);
  384.         this.height = Math.max(y + this.window.contents.fontSize + 8, this.height);
  385.     };

  386.     Bitmap_Virtual.prototype.blt = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
  387.         this.width  = Math.max(dx + (dw || sw), this.width);
  388.         this.height = Math.max(dy + (dy || sy), this.height);
  389.     };
  390. })();
复制代码



自己用好几年MV一直都在用的插件,可以把文字以图片形式显示UI,感觉也是一个MZ必备的插件
无奈自己太菜不会移植插件
求大佬移植!

new.zip

4.97 KB, 下载次数: 18

最佳答案

查看完整内容

MZ版DTextPicture.js 使用此插件需要基本插件“ PluginCommonBase.js”。 “ PluginCommonBase.js”位於RPG Tsukuru MZ的安裝文件夾下 存儲在以下。 dlc / BasicResources /plugins/official
MV/MZ Zeros魔塔样板

原创ARPG系统火爆出售中(论坛优惠价)(内含90+功能)
-------------------------------------------------------------------
*事件党*福利!本人两年的事件研究大集合

!点击上面看*事件党*详情(内含200+收集插件)
!
!
!
梦石
0
星屑
16296
在线时间
4017 小时
注册时间
2015-9-14
回帖
1322

开拓者

发表于 2020-10-31 20:35:07 | 显示全部楼层
本帖最后由 wabcmcc 于 2020-10-31 22:11 编辑

MZ版DTextPicture.js DTextPicture.rar (5.02 KB, 下载次数: 39)

使用此插件需要基本插件“ PluginCommonBase.js”。
“ PluginCommonBase.js”位於RPG Tsukuru MZ的安裝文件夾下
存儲在以下。
dlc / BasicResources /plugins/official

点评

原来已经有了诶!感谢  发表于 2020-11-1 10:23
https://rpg.blue/data/attachment/album/202003/28/021323lltgrsvfytfwuya5.gif
回复

使用道具 举报

梦石
0
星屑
2665
在线时间
423 小时
注册时间
2020-8-13
回帖
122
发表于 2020-10-31 23:52:59 | 显示全部楼层
PluginCommonBase.js 的中文版

PluginCommonBase汉化版.zip

3.72 KB, 下载次数: 67

评分

参与人数 1赞 +1 收起 理由
79160475 + 1 塞糖

查看全部评分

回复

使用道具 举报

梦石
0
星屑
1593
在线时间
252 小时
注册时间
2017-10-24
回帖
158
发表于 2024-3-14 11:18:12 | 显示全部楼层
具体怎么用能给个范例吗大佬
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部