82 lines
2.7 KiB
JavaScript
82 lines
2.7 KiB
JavaScript
/*:
|
||
* @target MZ
|
||
* @plugindesc 通知メッセージをプラグインコマンドで呼び出す v1.2.0
|
||
* @author IvI
|
||
*
|
||
* 必須:
|
||
* - TorigoyaMZ_NotifyMessage.js
|
||
* - TorigoyaMZ_NotifyMessage_AddonVariableChangeCenter.js
|
||
*
|
||
* ▼ プラグインコマンド
|
||
* @command Show
|
||
* @text メッセージ表示
|
||
* @desc 任意の文字列を通知ウィンドウで表示します。
|
||
*
|
||
* @arg message
|
||
* @text メッセージ
|
||
* @type multiline_string
|
||
* @desc 表示するテキスト(制御文字使用可)
|
||
*
|
||
* @arg iconId
|
||
* @text アイコンID
|
||
* @type number
|
||
* @default 0
|
||
* @desc 左に並べるアイコン(0 で無し)
|
||
*/
|
||
|
||
(() => {
|
||
'use strict';
|
||
|
||
const PLUGIN_NAME = 'TorigoyaMZ_NotifyMessage_CommandMessage';
|
||
const Torigoya = window.Torigoya || {};
|
||
if (!Torigoya.NotifyMessage) {
|
||
console.error(`[${PLUGIN_NAME}] TorigoyaMZ_NotifyMessage が見つかりません。`);
|
||
return;
|
||
}
|
||
|
||
const Manager = Torigoya.NotifyMessage.Manager;
|
||
|
||
// 中央座標は AddonVariableChangeCenter のパラメータを再利用
|
||
const addonParams = PluginManager.parameters('TorigoyaMZ_NotifyMessage_AddonVariableChangeCenter');
|
||
const CENTER_Y = Number(addonParams.centerY || 360);
|
||
|
||
/**
|
||
* コマンド由来の通知をまとめて並べ替える
|
||
* 1フレーム遅延後に実行し、確定した高さを使う
|
||
*/
|
||
function refreshCommandStackPositions() {
|
||
setTimeout(() => {
|
||
const stacks = Manager._stacks.filter((s) => s.notifyItem?._fromCommand && s.window);
|
||
// Manager._stacks の並び順=生成順をそのまま使う
|
||
let y = CENTER_Y;
|
||
for (const stack of stacks) {
|
||
stack.y = y;
|
||
stack.window.y = y;
|
||
y += stack.window.height; // 高さぶんだけ下に積む
|
||
}
|
||
});
|
||
}
|
||
|
||
// -----------------------------------------------------------------------
|
||
// プラグインコマンド定義
|
||
// -----------------------------------------------------------------------
|
||
PluginManager.registerCommand(PLUGIN_NAME, 'Show', (args) => {
|
||
const message = String(args.message || '').trim();
|
||
if (!message) return;
|
||
|
||
const iconId = Number(args.iconId || 0);
|
||
|
||
const notifyItem = new Torigoya.NotifyMessage.NotifyItem({
|
||
message,
|
||
icon: iconId,
|
||
note: '<type:variableChange>', // 既存アドオンのロジックを流用
|
||
});
|
||
notifyItem._fromCommand = true; // コマンド生成フラグ
|
||
|
||
Manager.notify(notifyItem);
|
||
|
||
// 並び替えは 2 段構え(高さ確定まで 1〜2 フレーム必要)
|
||
refreshCommandStackPositions();
|
||
setTimeout(refreshCommandStackPositions, 2);
|
||
});
|
||
})();
|