85 lines
2.8 KiB
JavaScript
85 lines
2.8 KiB
JavaScript
/*:
|
||
* @target MZ
|
||
* @plugindesc [MZ] 変数48の値に応じてピクチャの透明度を操作(会話開始時に即255化/特定スイッチ状態で無効)
|
||
* @author you
|
||
*
|
||
* @help
|
||
* ・変数48が1のとき:
|
||
* 上下左右キーを押している間はピクチャ21〜30を半透明(128)、
|
||
* それ以外は不透明(255)にします。
|
||
*
|
||
* ・変数48が2のとき:
|
||
* 上下左右キーを押している間は0.5秒(30フレーム)かけてフェードアウト、
|
||
* 離したときは1秒(60フレーム)かけてフェードインします。
|
||
*
|
||
* ・以下の状況では動作しません:
|
||
* ├ 会話中(メッセージウィンドウが開いている間)
|
||
* ├ スイッチ11がONのとき
|
||
* └ スイッチ31がOFFのとき
|
||
*
|
||
* ・会話が始まった瞬間に、ピクチャ21〜30を即座に不透明(255)に戻します。
|
||
*
|
||
* この処理はフレームごとに監視されます(並列処理不要)。
|
||
*/
|
||
|
||
(() => {
|
||
const pictureIds = [...Array(10)].map((_, i) => i + 21); // ピクチャ21〜30
|
||
let wasMessageBusy = false; // 前フレームの会話状態を記録
|
||
|
||
const _Scene_Map_update = Scene_Map.prototype.update;
|
||
Scene_Map.prototype.update = function() {
|
||
_Scene_Map_update.call(this);
|
||
|
||
const isMessageBusy = $gameMessage.isBusy();
|
||
|
||
// 会話が始まった瞬間(前はfalse → 今true)
|
||
if (!wasMessageBusy && isMessageBusy) {
|
||
resetPictureOpacity();
|
||
}
|
||
|
||
wasMessageBusy = isMessageBusy;
|
||
|
||
// 会話中、スイッチ11がON、またはスイッチ31がOFFなら処理を無効化
|
||
if (isMessageBusy || $gameSwitches.value(11) || !$gameSwitches.value(31)) return;
|
||
|
||
updatePictureOpacity();
|
||
};
|
||
|
||
// 会話開始時にピクチャを即座に255に戻す
|
||
function resetPictureOpacity() {
|
||
for (const id of pictureIds) {
|
||
const p = $gameScreen.picture(id);
|
||
if (p) p.setOpacity(255);
|
||
}
|
||
}
|
||
|
||
function updatePictureOpacity() {
|
||
const mode = $gameVariables.value(48);
|
||
const pressed =
|
||
Input.isPressed('up') ||
|
||
Input.isPressed('down') ||
|
||
Input.isPressed('left') ||
|
||
Input.isPressed('right');
|
||
|
||
if (mode === 1) {
|
||
// 半透明/不透明切替
|
||
for (const id of pictureIds) {
|
||
const p = $gameScreen.picture(id);
|
||
if (p) p.setOpacity(pressed ? 128 : 255);
|
||
}
|
||
} else if (mode === 2) {
|
||
// フェード処理
|
||
for (const id of pictureIds) {
|
||
const p = $gameScreen.picture(id);
|
||
if (!p) continue;
|
||
if (pressed) {
|
||
const next = Math.max(0, p.opacity() - 255 / 30);
|
||
p.setOpacity(next);
|
||
} else {
|
||
const next = Math.min(255, p.opacity() + 255 / 60);
|
||
p.setOpacity(next);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
})();
|