Skip to content

Instantly share code, notes, and snippets.

@Mt3Zz
Last active April 17, 2021 05:58
Show Gist options
  • Select an option

  • Save Mt3Zz/094e48446c63cee8f7344f9a806530fb to your computer and use it in GitHub Desktop.

Select an option

Save Mt3Zz/094e48446c63cee8f7344f9a806530fb to your computer and use it in GitHub Desktop.
RPGMakerMZ plugins : Enable to use additional status in menu scene
//========================================================================
// RPG Maker MZ - Additional Status
// Copyright (c) 2021 9rvLU
// Released under the MIT license
// https://opensource.org/licenses/mit-license.php
//========================================================================
// [Update Histoty]
// 1.0.0 2021/01/20 初版
//
// [bug report]
/*:ja
* @target MZ
* @plugindesc 追加のステータス画面を作成します。
* @author 9rvLU
* @url
* @base PluginCommonBase
* @beforeThan PluginCommonBase
*
*
* @param command
* @text コマンドの名称
* @desc メニュー画面に表示されるコマンドの名称です。制御文字(\v[0]など)の使用が可能です。
* @default 追加ステータス
* @type string
*
*
* @param textList
* @text テキストリスト
* @desc 追加ステータス画面に表示するテキストのリストです。制御文字(\v[0]など)の使用が可能です。
* @default []
* @type struct<TextElement>[]
*
*
* @param pictureList
* @text ピクチャリスト
* @desc 追加ステータス画面に表示するピクチャのリストです。
* @default []
* @type struct<PictureElement>[]
* @dir img/pictures/
*
*
* @help AdditionalStatus.js
*
* 追加のステータス画面を作成するプラグインです。
*
* トリアコンタン様の PluginCommonBase.js をベースプラグインとしています。
* (トリアコンタン様ありがとうございます!)
* このプラグインより上に PluginCommonBase を登録してください。
*
*
* プラグインパラメータ説明
* - コマンドの名称
* メニュー画面に表示されるコマンドの名称です。
* - テキストリスト
* 追加ステータス画面に表示するテキストのリストです。
* - ピクチャリスト
* 追加ステータス画面に表示するピクチャのリストです。
*
*
* テキストには制御文字が使用可能です。
* テキストを装飾したい場合、制御文字を使用してください。
*
* 主な制御文字 : テキストに変数を使用
* - \V[n] : 変数n番の値を表示する。
*
* 主な制御文字 : テキストのサイズ変更
* - \{ : 文字サイズを一段階大きくする
* - \} : 文字サイズを一段階小さくする
*
* 主な制御文字 : テキスト装飾
* - \C[n] : 文字の色をn番に変更する
* - \I[n] : アイコンn番を表示する
*
*/
/*~struct~TextElement:ja
*
* @param Text
* @text テキスト
* @desc 追加ステータス画面に表示するテキストです。
* @default
* @type string
*
* @param TextSettings
* @text テキスト設定
* @desc 表示するテキストの設定です。
* @default
* @type struct<TextSettings>
*
*/
/*~struct~PictureElement:ja
*
* @param Picture
* @text ピクチャ
* @desc 追加ステータス画面に表示するピクチャです。
* @default
* @type file
* @dir img/pictures/
*
* @param PictureSettings
* @text ピクチャ設定
* @desc 表示するピクチャの設定です。
* @default {"x":"0","y":"0","scaleX":"100","scaleY":"100"}
* @type struct<PictureSettings>
*
*/
/*~struct~TextSettings:ja
*
* @param x
* @text 原点(横方向)
* @desc テキストの横方向の原点です。
* @default 0
* @type number
*
* @param y
* @text 原点(縦方向)
* @desc テキストの縦方向の原点です。
* @default 0
* @type number
*
*/
/*~struct~PictureSettings:ja
*
* @param x
* @text 原点のx座標
* @desc ピクチャ原点のx座標です。
* @default 0
* @type number
*
* @param y
* @text 原点のy座標
* @desc ピクチャ原点のy座標です。
* @default 0
* @type number
*
* @param scaleX
* @text 縮小率(横方向)
* @desc ピクチャの横方向の縮小率(-100~100%)です。負の数を指定することで左右反転することができます。
* @default 100
* @type number
* @min -100
* @max 100
*
* @param scaleY
* @text 縮小率(縦方向)
* @desc ピクチャの縦方向の縮小率(-100~100%)です。負の数を指定することで上下反転することができます。
* @default 100
* @type number
* @min -100
* @max 100
*/
(() => {
"use strict"
// @paramを使用可能にするためのおまじない
const pluginName = document.currentScript;
const params = PluginManagerEx.createParameter(pluginName);
// paramsの変数
const commandName = params['command'];
const textList = params['textList'];
const pictureList = params['pictureList'];
// ------- 追加するシーンの定義・初期化 -------
// 追加する用のシーンを定義
function Scene_AdditionalStatus() {
this.initialize(...arguments);
}
Scene_AdditionalStatus.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Status.prototype.constructor = Scene_Status;
// rmmz_scenes.js の Scene_Status の処理をコピーして改変
// 追加シーン初期化処理
Scene_AdditionalStatus.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_AdditionalStatus.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createStatusWindow();
// 追加処理
this.addPictures();
this.addText();
};
Scene_AdditionalStatus.prototype.createStatusWindow = function() {
const rect = this.statusWindowRect();
this._statusWindow = new Window_Status(rect);
this._statusWindow.setHandler("cancel", this.popScene.bind(this));
// PageUp PageDown の処理を無効化
// this._statusWindow.setHandler("pagedown", this.nextActor.bind(this));
// this._statusWindow.setHandler("pageup", this.previousActor.bind(this));
this.addWindow(this._statusWindow);
};
// ウィンドウの大きさを画面いっぱいに変更
Scene_AdditionalStatus.prototype.statusWindowRect = function() {
const wx = 0;
const wy = this.mainAreaTop();
const ww = Graphics.boxWidth;
const wh = Graphics.boxHeight - wy;
return new Rectangle(wx, wy, ww, wh);
};
// ------- 追加ステータス画面にテキスト、ピクチャを追加する処理 --------
// メンバ関数の追加
// 追加ステータス画面にピクチャを表示する処理
Scene_AdditionalStatus.prototype.addPictures = function(){
for (let element of pictureList){
const picture = element['Picture'];
const pictureSettings = element['PictureSettings'];
// ビットマップを作成し、スプライトを作成。
const bitmap = ImageManager.loadPicture(picture);
const sprite = new Sprite(bitmap);
console.log(element,picture,bitmap,pictureSettings);
sprite.x = pictureSettings['x'];
sprite.y = pictureSettings['y'];
sprite.scale.x = pictureSettings['scale'] / 100;
sprite.scale.y = pictureSettings['scale'] / 100;
this.addChild(sprite);
}
}
// 追加ステータス画面にテキストを表示する処理
Scene_AdditionalStatus.prototype.addText = function(){
const statusWindow = this._statusWindow;
for (let element of textList){
const text = element['Text'];
const textSettings = element['TextSettings'];
// 文字列表示
statusWindow.drawTextEx(
text,
textSettings['x'],
textSettings['y'],
Graphics.boxWidth
);
}
}
// ------- メニュー画面にコマンドを追加する処理 --------
// 既存クラスのメンバ関数追加・オーバーライド
// 正直なにやってるかいまいちわかってない
// Menuに作成した追加シーンをpush
Scene_Menu.prototype.additionalStatusCommand = function(){
SceneManager.push(Scene_AdditionalStatus);
};
// Time Out を検知する関数?
setTimeout(function(){
// オーバーライド
const _Scene_Menu_createCommandWindow = Scene_Menu.prototype.createCommandWindow;
Scene_Menu.prototype.createCommandWindow = function(){
_Scene_Menu_createCommandWindow.call(this);
// 新しいコマンドを表示?
this._commandWindow.setHandler('additionalStatus', this.additionalStatusCommand.bind(this));
};
},0);
// addOriginalCommand(空の関数。プラグイン制作用?)をオーバーライド
const _Window_MenuCommand_addOriginalCommands = Window_MenuCommand.prototype.addOriginalCommands;
Window_MenuCommand.prototype.addOriginalCommands = function(){
_Window_MenuCommand_addOriginalCommands.call(this);
// メニュー画面にコマンドを追加?
this.addCommand(commandName, 'additionalStatus', true);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment