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

Project1

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

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
2429
在线时间
407 小时
注册时间
2016-2-3
帖子
755
跳转到指定楼层
1
发表于 2020-10-31 20:35:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
100星屑
JS 代码复制下载
  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. /*:
  27. * @plugindesc 動的文字列ピクチャ生成プラグイン
  28. * @author トリアコンタン
  29. *
  30. * @help 指定した文字列でピクチャを動的に生成するコマンドを提供します。
  31. * 以下の手順で表示します。
  32. *  1 : プラグインコマンド[D_TEXT]で描画したい文字列と引数を指定(下記の例参照)
  33. *  2 : プラグインコマンド[D_TEXT_SETTING]で背景色や揃えを指定(任意)
  34. *  3 : イベントコマンド「ピクチャの表示」で「画像」を未選択に指定。
  35. * ※ 1の時点ではピクチャは表示されないので必ずセットで呼び出してください。
  36. * ※ ピクチャ表示前にD_TEXTを複数回実行すると、複数行表示できます。
  37. *
  38. * プラグインコマンド詳細
  39. *   イベントコマンド「プラグインコマンド」から実行。
  40. *   (引数の間は半角スペースで区切る)
  41. *
  42. *  D_TEXT [描画文字列] [文字サイズ] : 動的文字列ピクチャ生成の準備
  43. *  例:D_TEXT テスト文字列 32
  44. *
  45. * 表示後は通常のピクチャと同様に移動や回転、消去ができます。
  46. * また、変数やアクターの表示など制御文字にも対応しています。
  47. *
  48. *  D_TEXT_SETTING ALIGN [揃え] : 揃え(左揃え、中央揃え、右揃え)の設定
  49. *  0:左揃え 1:中央揃え 2:右揃え
  50. *
  51. *  例:D_TEXT_SETTING ALIGN 0
  52. *      D_TEXT_SETTING ALIGN CENTER
  53. *
  54. *  D_TEXT_SETTING BG_COLOR [背景色] : 背景色の設定(CSSの色指定と同様の書式)
  55. *
  56. *  例:D_TEXT_SETTING BG_COLOR black
  57. *      D_TEXT_SETTING BG_COLOR #336699
  58. *      D_TEXT_SETTING BG_COLOR rgba(255,255,255,0.5)
  59. *
  60. * これらの設定はD_TEXTと同様、ピクチャを表示する前に行ってください。
  61. *
  62. * 対応制御文字一覧(イベントコマンド「文章の表示」と同一です)
  63. * \V[n]
  64. * \N[n]
  65. * \P[n]
  66. * \G
  67. * \C[n]
  68. * \I[n]
  69. * \{
  70. * \}
  71. *
  72. * 専用制御文字
  73. * \V[n,m](m桁分のゼロ埋めした変数の値)
  74. * \item[n]   n 番のアイテム情報(アイコン+名称)
  75. * \weapon[n] n 番の武器情報(アイコン+名称)
  76. * \armor[n]  n 番の防具情報(アイコン+名称)
  77. * \skill[n]  n 番のスキル情報(アイコン+名称)
  78. * \state[n]  n 番のステート情報(アイコン+名称)
  79. *
  80. * 利用規約:
  81. *  作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
  82. *  についても制限はありません。
  83. *  このプラグインはもうあなたのものです。
  84. */
  85. (function () {
  86.  
  87.     var getCommandName = function (command) {
  88.         return (command || '').toUpperCase();
  89.     };
  90.  
  91.     var getArgNumber = function (arg, min, max) {
  92.         if (arguments.length < 2) min = -Infinity;
  93.         if (arguments.length < 3) max = Infinity;
  94.         return (parseInt(convertEscapeCharacters(arg.toString()), 10) || 0).clamp(min, max);
  95.     };
  96.  
  97.     var getArgString = function (arg, upperFlg) {
  98.         arg = convertEscapeCharacters(arg);
  99.         return upperFlg ? arg.toUpperCase() : arg;
  100.     };
  101.  
  102.     var connectArgs = function (args, startIndex, endIndex) {
  103.         if (arguments.length < 2) startIndex = 0;
  104.         if (arguments.length < 3) endIndex = args.length;
  105.         var text = '';
  106.         for (var i = startIndex; i < endIndex; i++) {
  107.             text += args[i];
  108.             if (i < endIndex - 1) text += ' ';
  109.         }
  110.         return text;
  111.     };
  112.  
  113.     var convertEscapeCharacters = function(text) {
  114.         if (text == null) text = '';
  115.         var window = SceneManager.getHiddenWindow();
  116.         return window ? window.convertEscapeCharacters(text) : text;
  117.     };
  118.  
  119.     SceneManager.getHiddenWindow = function() {
  120.         return this._scene._hiddenWindow;
  121.     };
  122.  
  123.  
  124.     //=============================================================================
  125.     // Game_Interpreter
  126.     //  プラグインコマンド[D_TEXT]を追加定義します。
  127.     //=============================================================================
  128.     var _Game_Interpreter_pluginCommand      = Game_Interpreter.prototype.pluginCommand;
  129.     Game_Interpreter.prototype.pluginCommand = function (command, args) {
  130.         _Game_Interpreter_pluginCommand.apply(this, arguments);
  131.         try {
  132.             this.pluginCommandDTextPicture(command, args);
  133.         } catch (e) {
  134.             if ($gameTemp.isPlaytest() && Utils.isNwjs()) {
  135.                 var window = require('nw.gui').Window.get();
  136.                 if (!window.isDevToolsOpen()) {
  137.                     var devTool = window.showDevTools();
  138.                     devTool.moveTo(0, 0);
  139.                     devTool.resizeTo(Graphics.width, Graphics.height);
  140.                     window.focus();
  141.                 }
  142.             }
  143.             console.log('プラグインコマンドの実行中にエラーが発生しました。');
  144.             console.log('- コマンド名  : ' + command);
  145.             console.log('- コマンド引数 : ' + args);
  146.             console.log('- エラー原因   : ' + e.toString());
  147.         }
  148.     };
  149.  
  150.     Game_Interpreter.textAlignMapper = {
  151.         LEFT:0, CENTER:1, RIGHT:2, 左:0, 中央:1, 右:2
  152.     };
  153.  
  154.     Game_Interpreter.prototype.pluginCommandDTextPicture = function(command, args) {
  155.         switch (getCommandName(command)) {
  156.             case 'D_TEXT' :
  157.                 if (isNaN(args[args.length - 1])) args.push($gameScreen.dTextSize || 28);
  158.                 var fontSize = getArgNumber(args.pop());
  159.                 $gameScreen.setDTextPicture(getArgString(connectArgs(args), false), fontSize);
  160.                 break;
  161.  
  162.  
  163.             case 'D_TEXT_SETTING':
  164.                 switch (getCommandName(args[0])) {
  165.                     case 'ALIGN' :
  166.                         $gameScreen.dTextAlign = isNaN(args[1]) ?
  167.                             Game_Interpreter.textAlignMapper[getArgString(args[1], true)] : getArgNumber(args[1], 0, 2);
  168.                         break;
  169.                     case 'BG_COLOR' :
  170.                         $gameScreen.dTextBackColor = getArgString(connectArgs(args, 1));
  171.                         break;
  172.                     case 'FONT':
  173.                         $gameScreen.setFont(getArgString(args[1]));
  174.                         break;
  175.                 }
  176.                 break;
  177.         }
  178.     };
  179.  
  180.     //=============================================================================
  181.     // Game_Screen
  182.     //  動的ピクチャ用のプロパティを追加定義します。
  183.     //=============================================================================
  184.     var _Game_Screen_clear = Game_Screen.prototype.clear;
  185.     Game_Screen.prototype.clear = function() {
  186.         _Game_Screen_clear.call(this);
  187.         this.clearDTextPicture();
  188.     };
  189.  
  190.     Game_Screen.prototype.clearDTextPicture = function() {
  191.         this.dTextValue = null;
  192.         this.dTextSize  = 0;
  193.         this.dTextAlign = 0;
  194.         this.dTextBackColor = null;
  195.         this.dTextFont = null;
  196.     };
  197.  
  198.     Game_Screen.prototype.setDTextPicture = function(value, size) {
  199.         if (!this.dTextValue) this.dTextValue = [];
  200.         this.dTextValue.push(value);
  201.         this.dTextSize = size;
  202.     };
  203.  
  204.     Game_Screen.prototype.getDTextPictureInfo = function() {
  205.         return {value:this.dTextValue, size:this.dTextSize, align:this.dTextAlign,
  206.             color:this.dTextBackColor, font:this.dTextFont};
  207.     };
  208.  
  209.     Game_Screen.prototype.isSettingDText = function() {
  210.         return !!this.dTextValue;
  211.     };
  212.  
  213.     Game_Screen.prototype.setFont = function(name) {
  214.         if (Graphics.isFontLoaded(name)) {
  215.             this.dTextFont = name;
  216.         }
  217.     };
  218.  
  219.     //=============================================================================
  220.     // Game_Picture
  221.     //  動的ピクチャ用のプロパティを追加定義し、表示処理を動的ピクチャ対応に変更します。
  222.     //=============================================================================
  223.     var _Game_Picture_initBasic = Game_Picture.prototype.initBasic;
  224.     Game_Picture.prototype.initBasic = function() {
  225.         _Game_Picture_initBasic.call(this);
  226.         this.dTextValue = null;
  227.         this.dTextInfo = null;
  228.     };
  229.  
  230.     var _Game_Picture_show = Game_Picture.prototype.show;
  231.     Game_Picture.prototype.show = function(name, origin, x, y, scaleX,
  232.                                            scaleY, opacity, blendMode) {
  233.         if ($gameScreen.isSettingDText()) {
  234.             arguments[0] = Date.now().toString();
  235.             var textValue = "";
  236.             this.dTextInfo = $gameScreen.getDTextPictureInfo();
  237.             this.dTextInfo.value.forEach(function(text) {
  238.                 textValue +=  text + '\n';
  239.             }.bind(this));
  240.             this.dTextInfo.value = textValue;
  241.         } else {
  242.             this.dTextInfo = null;
  243.         }
  244.         $gameScreen.clearDTextPicture();
  245.         _Game_Picture_show.apply(this, arguments);
  246.     };
  247.  
  248.     var _Window_Base_convertEscapeCharacters = Window_Base.prototype.convertEscapeCharacters;
  249.     Window_Base.prototype.convertEscapeCharacters = function(text) {
  250.         text = _Window_Base_convertEscapeCharacters.call(this, text);
  251.         text = text.replace(/\x1bV\[(\d+)\,(\d+)\]/gi, function() {
  252.             return $gameVariables.value(parseInt(arguments[1])).padZero(arguments[2]);
  253.         }.bind(this));
  254.         text = text.replace(/\x1bITEM\[(\d+)\]/gi, function() {
  255.             var item = $dataItems[getArgNumber(arguments[1], 1, $dataItems.length)];
  256.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  257.         }.bind(this));
  258.         text = text.replace(/\x1bWEAPON\[(\d+)\]/gi, function() {
  259.             var item = $dataWeapons[getArgNumber(arguments[1], 1, $dataWeapons.length)];
  260.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  261.         }.bind(this));
  262.         text = text.replace(/\x1bARMOR\[(\d+)\]/gi, function() {
  263.             var item = $dataArmors[getArgNumber(arguments[1], 1, $dataArmors.length)];
  264.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  265.         }.bind(this));
  266.         text = text.replace(/\x1bSKILL\[(\d+)\]/gi, function() {
  267.             var item = $dataSkills[getArgNumber(arguments[1], 1, $dataSkills.length)];
  268.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  269.         }.bind(this));
  270.         text = text.replace(/\x1bSTATE\[(\d+)\]/gi, function() {
  271.             var item = $dataStates[getArgNumber(arguments[1], 1, $dataStates.length)];
  272.             return item ? '\x1bi[' + item.iconIndex + ']' + item.name : '';
  273.         }.bind(this));
  274.         return text;
  275.     };
  276.  
  277.     //=============================================================================
  278.     // Sprite_Picture
  279.     //  画像の動的生成を追加定義します。
  280.     //=============================================================================
  281.     var _Sprite_Picture_loadBitmap = Sprite_Picture.prototype.loadBitmap;
  282.     Sprite_Picture.prototype.loadBitmap = function() {
  283.         this.dTextInfo = this.picture().dTextInfo;
  284.         if (this.dTextInfo) {
  285.             this.makeDynamicBitmap();
  286.         } else {
  287.             _Sprite_Picture_loadBitmap.call(this);
  288.         }
  289.     };
  290.  
  291.     Sprite_Picture.prototype.makeDynamicBitmap = function() {
  292.         this.textWidths = [];
  293.         this.hiddenWindow = SceneManager.getHiddenWindow();
  294.         if (this.dTextInfo.font) this.hiddenWindow.contents.fontFace = this.dTextInfo.font;
  295.         if (this.dTextInfo.size > 0) this.hiddenWindow.contents.fontSize = this.dTextInfo.size;
  296.         var bitmapVirtual = new Bitmap_Virtual();
  297.         this._processText(bitmapVirtual);
  298.         this.bitmap = new Bitmap(bitmapVirtual.width, bitmapVirtual.height);
  299.         if (this.dTextInfo.font) this.bitmap.fontFace = this.dTextInfo.font;
  300.         if (this.dTextInfo.color) this.bitmap.fillAll(this.dTextInfo.color);
  301.         this._processText(this.bitmap);
  302.         this.hiddenWindow = null;
  303.     };
  304.  
  305.     Sprite_Picture.prototype._processText = function(bitmap) {
  306.         var textState = {index: 0, x: 0, y: 0, text: this.dTextInfo.value, left:0, line:-1, height:0};
  307.         this._processNewLine(textState, bitmap);
  308.         textState.height = this.hiddenWindow.calcTextHeight(textState, false);
  309.         textState.index  = 0;
  310.         while (textState.text[textState.index]) {
  311.             this._processCharacter(textState, bitmap);
  312.         }
  313.     };
  314.  
  315.     Sprite_Picture.prototype._processCharacter = function(textState, bitmap) {
  316.         if (textState.text[textState.index] === '\x1b') {
  317.             var code = this.hiddenWindow.obtainEscapeCode(textState);
  318.             switch (code) {
  319.                 case 'C':
  320.                     bitmap.textColor = this.hiddenWindow.textColor(this.hiddenWindow.obtainEscapeParam(textState));
  321.                     break;
  322.                 case 'I':
  323.                     this._processDrawIcon(this.hiddenWindow.obtainEscapeParam(textState), textState, bitmap);
  324.                     break;
  325.                 case '{':
  326.                     this.hiddenWindow.makeFontBigger();
  327.                     break;
  328.                 case '}':
  329.                     this.hiddenWindow.makeFontSmaller();
  330.                     break;
  331.                 case 'F':
  332.                     switch (this.hiddenWindow.obtainEscapeParam(textState)) {
  333.                         case 'I':
  334.                             bitmap.fontItalic = true;
  335.                             break;
  336.                         case '/':
  337.                         case 'N':
  338.                             bitmap.fontItalic = false;
  339.                             break;
  340.                     }
  341.                     break;
  342.             }
  343.         } else if (textState.text[textState.index] === '\n') {
  344.             this._processNewLine(textState, bitmap);
  345.         } else {
  346.             var c = textState.text[textState.index++];
  347.             var w = this.hiddenWindow.textWidth(c);
  348.             bitmap.fontSize = this.hiddenWindow.contents.fontSize;
  349.             bitmap.drawText(c, textState.x, textState.y, w * 2, textState.height, "left");
  350.             textState.x += w;
  351.         }
  352.     };
  353.  
  354.     Sprite_Picture.prototype._processNewLine = function(textState, bitmap) {
  355.         if (bitmap instanceof Bitmap_Virtual)
  356.             this.textWidths[textState.line] = textState.x;
  357.         this.hiddenWindow.processNewLine(textState);
  358.         textState.line++;
  359.         if (bitmap instanceof Bitmap)
  360.             textState.x = (bitmap.width - this.textWidths[textState.line]) / 2 * this.dTextInfo.align;
  361.     };
  362.  
  363.     Sprite_Picture.prototype._processDrawIcon = function(iconIndex, textState, bitmap) {
  364.         var iconBitmap = ImageManager.loadSystem('IconSet');
  365.         var pw = Window_Base._iconWidth;
  366.         var ph = Window_Base._iconHeight;
  367.         var sx = iconIndex % 16 * pw;
  368.         var sy = Math.floor(iconIndex / 16) * ph;
  369.         bitmap.blt(iconBitmap, sx, sy, pw, ph, textState.x + 2, textState.y + (textState.height - ph) / 2);
  370.         textState.x += Window_Base._iconWidth + 4;
  371.     };
  372.  
  373.     //=============================================================================
  374.     // Scene_Map
  375.     //  動的ピクチャ作成用の隠しウィンドウを追加定義します。
  376.     //=============================================================================
  377.     var _Scene_Map_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  378.     Scene_Map.prototype.createDisplayObjects = function() {
  379.         this._hiddenWindow = new Window_Base(1,1,1,1);
  380.         this._hiddenWindow.hide();
  381.         this._hiddenWindow.deactivate();
  382.         _Scene_Map_createDisplayObjects.call(this);
  383.         this.addChild(this._hiddenWindow);
  384.     };
  385.  
  386.     //=============================================================================
  387.     // Scene_Battle
  388.     //  動的ピクチャ作成用の隠しウィンドウを追加定義します。
  389.     //=============================================================================
  390.     var _Scene_Battle_createDisplayObjects = Scene_Battle.prototype.createDisplayObjects;
  391.     Scene_Battle.prototype.createDisplayObjects = function() {
  392.         this._hiddenWindow = new Window_Base(1,1,1,1);
  393.         this._hiddenWindow.hide();
  394.         this._hiddenWindow.deactivate();
  395.         _Scene_Battle_createDisplayObjects.call(this);
  396.         this.addChild(this._hiddenWindow);
  397.     };
  398.  
  399.     //=============================================================================
  400.     // Bitmap_Virtual
  401.     //  サイズを計算するための仮想ビットマップクラス
  402.     //=============================================================================
  403.     function Bitmap_Virtual() {
  404.         this.initialize.apply(this, arguments);
  405.     }
  406.  
  407.     Bitmap_Virtual.prototype.initialize = function() {
  408.         this.window = SceneManager.getHiddenWindow();
  409.         this.width = 0;
  410.         this.height = 0;
  411.     };
  412.  
  413.     Bitmap_Virtual.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) {
  414.         this.width  = Math.max(x + this.window.textWidth(text), this.width);
  415.         this.height = Math.max(y + this.window.contents.fontSize + 8, this.height);
  416.     };
  417.  
  418.     Bitmap_Virtual.prototype.blt = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
  419.         this.width  = Math.max(dx + (dw || sw), this.width);
  420.         this.height = Math.max(dy + (dy || sy), this.height);
  421.     };
  422. })();



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

new.zip

4.97 KB, 下载次数: 16

最佳答案

查看完整内容

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

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

!点击上面看*事件党*详情(内含200+收集插件)



Lv4.逐梦者

梦石
0
星屑
15507
在线时间
3950 小时
注册时间
2015-9-14
帖子
1333

开拓者

2
发表于 2020-10-31 20:35:07 | 只看该作者
本帖最后由 wabcmcc 于 2020-10-31 22:11 编辑

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

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

点评

原来已经有了诶!感谢  发表于 2020-11-1 10:23
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2655
在线时间
422 小时
注册时间
2020-8-13
帖子
124
3
发表于 2020-10-31 23:52:59 | 只看该作者
PluginCommonBase.js 的中文版

PluginCommonBase汉化版.zip

3.72 KB, 下载次数: 59

评分

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

查看全部评分

回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1390
在线时间
231 小时
注册时间
2017-10-24
帖子
209
4
发表于 2024-3-14 11:18:12 | 只看该作者
具体怎么用能给个范例吗大佬
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-20 21:45

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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