sakura-gozen/js/plugins/iii/iiiMessageEvent.js
2025-01-14 14:06:54 -06:00

220 lines
7.2 KiB
JavaScript

/*:ja
* @target MZ
* @plugindesc 特定シーンで特殊メッセージウィンドウ
* @author ズワイKANI
*
* @help iiiMessageEvent.js
*
* @param WindowSkins
* @text ウィンドウ画像
* @desc ウィンドウ画像を指定します。ここに登録した順番でウインドウ番号1~として扱います
* @dir img/system
* @type file[]
*
* @command ChangeMsgWinSkinNo
* @text ウインドウ画像切り替え
* @desc Window_Messageに利用するウインドウ画像を指定の番号のものに差し替えて表示します。
* 0以下を指定するとデフォルト表示に戻ります
* @arg windowSkinNo
* @type number
*
*/
var Imported = Imported || {};
Imported["iiiMessageEvent"] = 1.0;
(function () {
"use strict";
var _windowSkinNo = 0;
/**
* PluginCommand
*/
const script = document.currentScript;
const param = PluginManagerEx.createParameter(script);
PluginManagerEx.registerCommand(
script,
"ChangeMsgWinSkinNo",
function (args) {
_windowSkinNo = args.windowSkinNo;
}
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
const _Window_Message_prototype_loadWindowskin =
Window_Message.prototype.loadWindowskin;
Window_Message.prototype.loadWindowskin = function () {
_Window_Message_prototype_loadWindowskin.call(this);
this._windowSkins = [];
this._windowSkins[0] = null;
param.WindowSkins.forEach((path, index) => {
this._windowSkins[index + 1] = ImageManager.loadSystem(path);
}, this);
};
const _Window_Message_prototype__createFrameSprite =
Window_Message.prototype._createFrameSprite;
Window_Message.prototype._createFrameSprite = function () {
_Window_Message_prototype__createFrameSprite.call(this);
this._customWindowSprite = new Sprite();
this._customWindowSprite.visible = false;
this.addChild(this._customWindowSprite);
};
const _Window_Message_prototype__refreshAllParts =
Window_Message.prototype._refreshAllParts;
Window_Message.prototype._refreshAllParts = function () {
let isCustomSkinVisible = _windowSkinNo > 0;
this._backSprite.visible = !isCustomSkinVisible;
this._frameSprite.visible = !isCustomSkinVisible;
this._contentsBackSprite.visible = !isCustomSkinVisible;
this._customWindowSprite.visible = isCustomSkinVisible;
this._customWindowSprite.x = -(Graphics.width - Graphics.boxWidth) / 2;
if (_windowSkinNo <= 0) {
_Window_Message_prototype__refreshAllParts.call(this);
} else {
this._refreshCustomWindowSkin();
this._refreshCursor();
this._refreshArrows();
this._refreshPauseSign();
}
};
Window_Message.prototype._refreshCustomWindowSkin = function () {
if (!this._windowSkins) {
return;
}
if (_windowSkinNo < this._windowSkins.length) {
this._customWindowSprite.bitmap = this._windowSkins[_windowSkinNo];
}
};
Window_Message.prototype.isCustomSkinUse = function () {
let isCustomSkinVisible = _windowSkinNo > 0;
if (isCustomSkinVisible) {
return true;
}
return false;
};
const _Window_Message_prototype_updateBackgroundDimmer =
Window_Message.prototype.updateBackgroundDimmer;
Window_Message.prototype.updateBackgroundDimmer = function () {
_Window_Message_prototype_updateBackgroundDimmer.call(this);
if (this.isCustomSkinUse() && this._dimmerSprite) {
this._dimmerSprite.visible = false;
}
};
const _Window_Message_prototype_drawMessageFace =
Window_Message.prototype.drawMessageFace;
Window_Message.prototype.drawMessageFace = function () {
//_Window_Message_prototype_drawMessageFace.call(this);
const faceName = $gameMessage.faceName();
const faceIndex = $gameMessage.faceIndex();
const rtl = $gameMessage.isRTL();
const width = ImageManager.faceWidth;
const height = this.innerHeight;
const x = rtl ? this.innerWidth - width - 4 : 4;
if (!this.isCustomSkinUse()) {
this.drawFace(faceName, faceIndex, x, 0, width, height);
}
//this.drawFace2(faceName, faceIndex, x, 10, width, height, 0, 0);
};
const _Window_Message_prototype_newPage = Window_Message.prototype.newPage;
Window_Message.prototype.newPage = function (textState) {
_Window_Message_prototype_newPage.call(this, textState);
const skin = _windowSkinNo;
if (this.isCustomSkinUse()) {
switch (skin) {
case 1:
textState.y = 24;
break;
case 2:
textState.y = 74;
break;
default:
textState.y = 24;
break;
}
}
};
/*
//追加部分
const _Window_Base_prototype_createTextState = Window_Base.prototype.createTextState;
Window_Base.prototype.createTextState = function(text, x, y, width)
{
_Window_Base_prototype_createTextState.call(this, text, x, y, width);
};
//追加部分
*/
Window_Base.prototype.drawFace2 = function (
faceName,
faceIndex,
x,
y,
width,
height,
sclx,
scly
) {
width = width || ImageManager.faceWidth;
height = height || ImageManager.faceHeight;
const bitmap = ImageManager.loadFace(faceName);
const pw = ImageManager.faceWidth;
const ph = ImageManager.faceHeight;
const sw = Math.min(width, pw);
const sh = Math.min(height, ph);
const dx = Math.floor(x + Math.max(width - pw, 0) / 2);
const dy = Math.floor(y + Math.max(height - ph, 0) / 2);
const sx = Math.floor((faceIndex % 4) * pw + (pw - sw) / 2);
const sy = Math.floor(Math.floor(faceIndex / 4) * ph + (ph - sh) / 2);
this.contents.blt(bitmap, sx, sy, sw, sh, dx, dy, sw * sclx, sh * scly);
};
const _Window_NameBox_prototype_updatePlacement =
Window_NameBox.prototype.updatePlacement;
Window_NameBox.prototype.updatePlacement = function () {
const messageWindow = this._messageWindow;
if (messageWindow._windowSkinNo < 1) {
_Window_NameBox_prototype_updatePlacement.call(this);
} else {
this.width = this.windowWidth();
this.height = this.windowHeight();
this.x = messageWindow.x + 130;
const skin = _windowSkinNo;
switch (skin) {
case 1:
this.y = messageWindow.y - this.height * 0.3;
break;
case 2:
this.y = messageWindow.y + this.height * 0.5;
break;
default:
this.y = messageWindow.y - this.height * 0.3;
break;
}
this._isWindow = false; //ウィンドウが重なった際、背景を投下させるためにフラグをfalseに
}
};
const _Window_NameBox_prototype_updateBackground =
Window_NameBox.prototype.updateBackground;
Window_NameBox.prototype.updateBackground = function () {
const messageWindow = this._messageWindow;
if (messageWindow._windowSkinNo < 1) {
_Window_NameBox_prototype_updateBackground.call(this);
} else {
this.setBackgroundType(2);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
})();