//============================================================================= // RPG Maker MZ - Event Display Name //============================================================================= /*: * @target MZ * @plugindesc Show name above the event. * @author gabacho(Ichiro Meiken) * @url https://star-write-dream.com/ * @help GABA_EventDisplayName.js(ver1.0.0) * * Show name above the event. * * -------------------------- * Copyright (c) 2020 Gabacho(Ichiro Meiken) * Released under the MIT license * https://opensource.org/licenses/mit-license.php * -------------------------- * * @param nameFontSize * @text Name font size * @type number * @desc Enter the font size of the name.(Default:16) * @default 16 * * @param nameFontColor * @text Name font color * @type number * @desc Enter the font color of the name. (Default:0) The same as the method for specifying the message font color. * @default 0 * * @param nameOutlineColor * @text Name outline color * @type number * @desc Enter the outline color of the name. (Default:19) The same as the method for specifying the message font color. * @default 19 * * @param nameDisplayWidth * @text Name display width * @type number * @desc Enter the display width of the name. (Default:80) If it does not fit, the font is reduced. * @default 80 * * @param par * @text Background setting * * @param paddingX * @parent par * @text Padding of background (left and right) * @type number * @desc Enter the left and right padding of the background in pixels. (Default: 4) * @default 4 * * @param paddingY * @parent par * @text Padding of background (top and bottom) * @type number * @desc Enter the top and bottom padding of the background in pixels. (Default: 4) * @default 4 * * @param baseColor * @parent par * @text Bace color * @type struct * @desc Background base color * @default {"red":"0","green":"0","blue":"255", "opacity":"0.8"} * * @param gradationColor * @parent par * @text Gradient color * @type struct * @desc Background gradient color * @default {"red":"0","green":"0","blue":"0", "opacity":"0.8"} * * @param verticalMode * @parent par * @text Gradation in the vertical direction * @type boolean * @desc ON:Vertical OFF:Horizontal * @on ON * @off OFF * @default true * */ /*:ja * @target MZ * @plugindesc イベントの上部にテキストを表示します。 * @author ガバチョ(溟犬一六) * @url https://star-write-dream.com/ * * @help GABA_EventDisplayName.js(ver1.0.0) * * イベントの上方に任意のテキストを表示します。 * イベントのメモ欄にと入力してください。 * * イベントの画像が(なし)だと表示されません。 * 移動イベントなど画像不要で名前を表示したい場合は、 * 透明の画像を選択してください。 * * プラグインコマンドはありません。 * * -------------------------- * Copyright (c) 2020 Gabacho(Ichiro Meiken) * Released under the MIT license * https://opensource.org/licenses/mit-license.php * -------------------------- * * @param nameFontSize * @text フォントサイズ * @type number * @desc フォントサイズを指定します。(初期値:16) * @default 16 * * @param nameFontColor * @text フォントカラー * @type number * @desc フォントカラーを指定します。(初期値:0)メッセージのフォントカラーの指定方法と同じです。 * @default 0 * * @param nameOutlineColor * @text アウトラインカラー * @type number * @desc アウトラインカラーを指定します。(初期値:19)メッセージのフォントカラーの指定方法と同じです。 * @default 19 * * @param nameDisplayWidth * @text 表示幅 * @type number * @desc 表示幅を指定します。(初期値:80)収まらない場合はフォントが小さくなります。 * @default 80 * * @param par * @text 背景の設定 * * @param paddingX * @parent par * @text 背景の内側余白(左右) * @type number * @desc 背景の左右内側余白をピクセル数で指定します。(初期値:4) * @default 4 * * @param paddingY * @parent par * @text 背景の内側余白(上下) * @type number * @desc 背景の上下内側余白をピクセル数で指定します。(初期値:4) * @default 4 * * @param baseColor * @parent par * @text ベースカラー * @type struct * @desc 背景の色 * @default {"red":"0","green":"0","blue":"255", "opacity":"0.8"} * * @param gradationColor * @parent par * @text グラデーションカラー * @type struct * @desc 背景のグラデーション用の色 * @default {"red":"255","green":"255","blue":"255", "opacity":"0.8"} * * @param verticalMode * @parent par * @text 縦方向にグラデーションする * @type boolean * @desc ON:縦にグラデーションします。 OFF:横にグラデーションします。 * @on ON * @off OFF * @default true * * */ /*~struct~Color: * * @param red * @type number * @max 255 * @desc 赤(R)。0~255で指定してください。 * @default 0 * @decimals 0 * * @param green * @type number * @max 255 * @desc 緑(G)。0~255で指定してください。 * @default 0 * @decimals 0 * * @param blue * @type number * @max 255 * @desc 青(B)。0~255で指定してください。 * @default 0 * @decimals 0 * * @param opacity * @type number * @max 1 * @desc 不透明度を0~1で指定してください。0で透明です。 * @default 1 * @decimals 1 * */ (() => { "use strict"; const pluginName = "GABA_EventDisplayName"; let eventDisplayName = ""; let oldName = ""; const convertArrayParam = function (param) { if (!param) { return; } if (param !== undefined) { try { const array = JSON.parse(param); for (let i = 0; i < array.length; i++) { array[i] = JSON.parse(array[i]); } return array; } catch (e) { console.group(); console.error( "%cParameter is invalid ! GABA_EventDisplayNameのパラメータ準備に失敗しました。", "background-color: #5174FF" ); console.error("Parameter:" + eval(param)); console.error("Error message :" + e); console.groupEnd(); } } }; const parameters = PluginManager.parameters(pluginName); const nameFontSize = parseInt(parameters["nameFontSize"]) || 0; const nameFontColor = parseInt(parameters["nameFontColor"]) || 0; const nameOutlineColor = parseInt(parameters["nameOutlineColor"]) || 15; const nameDisplayWidth = parseInt(parameters["nameDisplayWidth"]) || 80; const paddingX = parseInt(parameters["paddingX"]) || 0; const paddingY = parseInt(parameters["paddingY"]) || 0; const isVerticalMode = Boolean( parameters["verticalMode"] === "true" || false ); let param = {}; param.color1 = String(parameters["baseColor"]); param.color1 = convertArrayParam(param.color1); param.color2 = String(parameters["gradationColor"]); param.color2 = convertArrayParam(param.color2); const c1 = "rgba(" + param.color1.red + "," + param.color1.green + "," + param.color1.blue + "," + param.color1.opacity + ")"; const c2 = "rgba(" + param.color2.red + "," + param.color2.green + "," + param.color2.blue + "," + param.color2.opacity + ")"; function createEventDisplayNameBitmap(dispName) { const tempWindow = new Window_Base(new Rectangle()); tempWindow.padding = 0; tempWindow.move( paddingX, 0, nameDisplayWidth + paddingX * 2, nameFontSize + paddingY * 2 ); tempWindow.createContents(); tempWindow.contents.textColor = ColorManager.textColor(nameFontColor); tempWindow.contents.outlineColor = ColorManager.textColor(nameOutlineColor); tempWindow.contents.fontSize = nameFontSize; tempWindow.contents.gradientFillRect( 0, 0, nameDisplayWidth, nameFontSize + paddingY * 2, c1, c2, isVerticalMode ); const wNameDisplayWidth = nameDisplayWidth - paddingX * 2; tempWindow.contents.drawText( dispName, paddingX, paddingY, wNameDisplayWidth, nameFontSize, "center" ); const bitmap = tempWindow.contents; bitmap.gaba_isEventDisplayName = true; tempWindow.contents = null; tempWindow.destroy(); return bitmap; } // Sprite_EventDisplayNameの定義 // Sprite_Balloonをベースにします function Sprite_EventDisplayName() { this.initialize(...arguments); } Sprite_EventDisplayName.prototype = Object.create(Sprite_Balloon.prototype); Sprite_EventDisplayName.prototype.constructor = Sprite_EventDisplayName; Sprite_EventDisplayName.prototype.initialize = function () { Sprite.prototype.initialize.call(this); this.initMembers(); }; Sprite_EventDisplayName.prototype.initMembers = function () { this._target = null; this._balloonId = 0; this._duration = 0; this.anchor.x = 0.45; this.anchor.y = 1; this.z = 9; }; Sprite_EventDisplayName.prototype.setup = function (targetSprite, balloonId) { this._target = targetSprite; this._balloonId = balloonId; this._duration = 1; }; Sprite_EventDisplayName.prototype.update = function () { Sprite.prototype.update.call(this); if (this._duration > 0) { this.updateDisplay(); this.updatePosition(); } }; Sprite_EventDisplayName.prototype.updatePosition = function () { this.x = this._target.x; this.y = this._target.y - this._target.height; }; Sprite_EventDisplayName.prototype.updateDisplay = function () { if (this._target._character._characterName === "") { this.bitmap.clear(); return; } if (this.characterName === this._target._character._characterName) { return; } else { this.characterName = this._target._character._characterName; } const dispName = this._target._character.event().meta.dn; this.bitmap = createEventDisplayNameBitmap(dispName); }; // Spriteset_Map const _Spriteset_Map_initialize = Spriteset_Map.prototype.initialize; Spriteset_Map.prototype.initialize = function () { _Spriteset_Map_initialize.apply(this, arguments); this._eventDisplayNameSprites = []; this.processEventDisplayNameRequests(); }; const _Spriteset_Map_destroy = Spriteset_Map.prototype.destroy; Spriteset_Map.prototype.destroy = function (options) { this.removeAllEventDisplayName(); _Spriteset_Map_destroy.apply(this, arguments); }; Spriteset_Map.prototype.processEventDisplayNameRequests = function () { for (let ev of $gameMap._events) { if (ev != null) { if (ev.event().meta.dn != null) { this.createEventDisplayName(ev); } } } }; Spriteset_Map.prototype.createEventDisplayName = function (request) { const targetSprite = this.findTargetSprite(request); if (targetSprite) { const dispName = request.event().meta.dn; let eventDisplayNameSprite = new Sprite_EventDisplayName(); eventDisplayNameSprite.bitmap = createEventDisplayNameBitmap(dispName.replace(/_/g, ' ')); eventDisplayNameSprite.targetObject = request; eventDisplayNameSprite.setup(targetSprite, 0); eventDisplayNameSprite.characterName = request._characterName; this._effectsContainer.addChild(eventDisplayNameSprite); this._eventDisplayNameSprites.push(eventDisplayNameSprite); } }; Spriteset_Map.prototype.removeAllEventDisplayName = function () { for (const sprite of this._eventDisplayNameSprites) { this.removeEventDisplayName(sprite); } }; Spriteset_Map.prototype.removeEventDisplayName = function (sprite) { this._eventDisplayNameSprites.remove(sprite); this._effectsContainer.removeChild(sprite); sprite.destroy(); }; })();