Project1

标题: MiniLab在事件顶部显示一个文字 [打印本页]

作者: q3226257    时间: 2020-8-26 16:04
标题: MiniLab在事件顶部显示一个文字
本帖最后由 q3226257 于 2020-9-7 14:42 编辑



MZ新出,写个超级简单的插件来蹭下热度~~~~
效果如图,在事件栏备注一下名字就可以了:
TEXT 代码复制
  1. <name:破坏神>


特别注意,改插件依赖于 MZ 自带的插件:PluginBaseFunction


修复了文字显示背景未清除的Bug!!!

JAVASCRIPT 代码复制下载
  1. /*:
  2.  *
  3.  *
  4.  * @plugindesc headName
  5.  * @author lh
  6.  * @date  14:42
  7.  * @target MZ
  8.  * @base PluginBaseFunction
  9.  *
  10.  * @param front
  11.  * @text 字体大小
  12.  * @desc 绘制顶部文字的大小
  13.  * @default 18
  14.  * @type number
  15.  *
  16.  * @param width
  17.  * @text 宽度
  18.  * @desc 当名字比较长显示不下可以调大该值
  19.  * @default 64
  20.  * @type number
  21.  *
  22.  * @param height
  23.  * @text 高度
  24.  * @desc 默认是居中的,所以会影响padding值
  25.  * @default 18
  26.  * @type number
  27.  *
  28.  * @param bgColor
  29.  * @text 背景颜色
  30.  * @desc 背景颜色
  31.  * @default rgba(0,0,0,0.5)
  32.  * @type color
  33.  *
  34.  * @help
  35.  * 事件栏备注:
  36.  *  <name:破坏神,2>
  37.  *
  38.  *
  39.  *
  40.  */
  41. const solve_HeadName = PluginManager.parameters('Solve_SimpleHeadName')
  42. solve_HeadName.width =parseInt(solve_HeadName.width)
  43. solve_HeadName.height =parseInt(solve_HeadName.height)
  44. function Sprite_HeadName() {
  45.     this.initialize(...arguments);
  46. }
  47.  
  48. Sprite_HeadName.prototype = Object.create(Sprite.prototype);
  49. Sprite_HeadName.prototype.constructor = Sprite_HeadName;
  50.  
  51. Sprite_HeadName.prototype.initialize = function (deploy) {
  52.     Sprite.prototype.initialize.call(this);
  53.     this._deploy = deploy;
  54.     this.bitmap = new Bitmap(solve_HeadName.width, solve_HeadName.height)
  55. };
  56.  
  57. Sprite_HeadName.prototype.update = function () {
  58.     Sprite.prototype.update.call(this);
  59.  
  60.     this.x = this._deploy.x - (solve_HeadName.width) / 2
  61.     this.y = this._deploy.y - solve_HeadName.height - this._deploy.height
  62.     this.z = this._deploy.z + 1
  63.  
  64.     this.opacity = this._deploy.opacity
  65.     this.blendMode = this._deploy.blendMode
  66.     this._bushDepth = this._deploy._bushDepth
  67.  
  68.     this.visible = this._deploy.visible;
  69.  
  70.     if (this.bitmap._headName === this.headName()) return
  71.     this.bitmap.outlineWidth = 0
  72.     this.bitmap.fontSize = solve_HeadName.front
  73.     this.bitmap.clear()
  74.     this.bitmap._headName = this.headName()
  75.     let [name,color] =this.bitmap._headName.split(',')
  76.     this.bitmap.textColor=ColorManager.textColor( parseInt(color)||0)
  77.     // this.bitmap.clearRect(0, 0, solve_HeadName.width, solve_HeadName.height);
  78.     this.bitmap.fillRoundRect(0,0, solve_HeadName.width, solve_HeadName.height,5,1,solve_HeadName.bgColor)
  79.     this.bitmap.drawText(name, 0, 0, solve_HeadName.width, solve_HeadName.height, 'center')
  80. }
  81.  
  82.  
  83. Sprite_HeadName.prototype.headName = function () {
  84.     let character = this._deploy._character;
  85.     if (character && character.findMeta) {
  86.         return character.findMeta("name") || ''
  87.     }
  88.     return '';
  89. }
  90.  
  91. solve_HeadName.Sprite_Character_initialize = Sprite_Character.prototype.initialize
  92. Sprite_Character.prototype.initialize = function (character) {
  93.     solve_HeadName.Sprite_Character_initialize.call(this, character);
  94.     if (character && character.findMeta && character.findMeta("name")) {
  95.         this._headSprite = new Sprite_HeadName(this)
  96.     }
  97. };
  98.  
  99. solve_HeadName.Sprite_Character_update = Sprite_Character.prototype.update
  100. Sprite_Character.prototype.update = function () {
  101.     solve_HeadName.Sprite_Character_update.call(this);
  102.     if (this._headSprite) {
  103.         this.parent.addChild(this._headSprite)
  104.         this._headSprite = undefined;
  105.     }
  106. };

Solve_SimpleHeadName.zip

1.1 KB, 下载次数: 59

售价: 1 星屑  [记录]


作者: migualmi    时间: 2020-8-29 23:52
非常感谢!很有用!
作者: q3226257    时间: 2020-9-7 14:42
加了个背景  加了颜色配置
作者: aaa627    时间: 2020-9-8 21:10
太感谢大佬啦!!




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1