277 lines
8.4 KiB
JavaScript
277 lines
8.4 KiB
JavaScript
/*=============================================================================
|
|
iiiBackLogWindow.js
|
|
----------------------------------------------------------------------------
|
|
This software is released under the MIT License.
|
|
http://opensource.org/licenses/mit-license.php
|
|
----------------------------------------------------------------------------
|
|
Version
|
|
1.0.0
|
|
=============================================================================*/
|
|
/*:ja
|
|
* @target MZ
|
|
* @author iii
|
|
* @plugindesc バックログ表示機能を提供します。
|
|
* @help
|
|
* バックログ表示機能を提供します。バックログ内容を保存するような機能はありません。
|
|
*
|
|
* マップ画面、バトル画面などScene_Messageを継承している画面にいるとき、
|
|
* toggleKeyNameのボタンを押すことでバックログウインドウを表示します。
|
|
*
|
|
* バックログウインドウ表示中は台詞ウインドウの更新が停止します。
|
|
* イベントで設定された台詞を保存しているため戦闘ログの内容等は保存しません。
|
|
*
|
|
* また、プラグインコマンドによるログの追加、ログの削除や
|
|
* 選択肢内容のバックログ保存には対応していないので必要な場合は相談してください。
|
|
*
|
|
* @param toggleKeyName
|
|
* @text バックログウインドウ開閉に利用するキーコード
|
|
* @desc Input.keyMapperで定義されている値を指定してください
|
|
* @type string
|
|
* @default tab
|
|
* @option shift
|
|
* @option tab
|
|
* @option pageup
|
|
* @option pagedown
|
|
*
|
|
* @param maxLogNum
|
|
* @text バックログ保存最大件数
|
|
* @desc 0以下の値を指定すると無制限になります。
|
|
* @type number
|
|
* @default 100
|
|
*
|
|
* @param disableSwitchNo
|
|
* @text バックログ開閉を無効にするときのスイッチ番号
|
|
* @desc
|
|
* ここで指定していたスイッチが有効な時、バックログは開けなくします
|
|
* また、既にバックログウインドウが開かれていた場合は閉じます
|
|
* このスイッチが有効な場合でもログには保存されます
|
|
* @type switch
|
|
* @default 0
|
|
*
|
|
*/
|
|
(() => {
|
|
"use strict";
|
|
|
|
const script = document.currentScript;
|
|
const pluginParam = PluginManagerEx.createParameter(script);
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Scene_Message
|
|
// Scene_MapやScene_Battleはこのクラスを継承している
|
|
//
|
|
const _Scene_Message_prototype_createAllWindows =
|
|
Scene_Message.prototype.createAllWindows;
|
|
Scene_Message.prototype.createAllWindows = function () {
|
|
_Scene_Message_prototype_createAllWindows.call(this);
|
|
this.createBackLogWindow();
|
|
const messageWindow = this._messageWindow;
|
|
messageWindow.setBackLogWindow(this._backlogWindow);
|
|
};
|
|
|
|
Scene_Message.prototype.createBackLogWindow = function () {
|
|
const rect = new Rectangle(0, 0, Graphics.width, Graphics.height);
|
|
this._backlogWindow = new Window_Backlog(rect);
|
|
this.addWindow(this._backlogWindow);
|
|
};
|
|
|
|
const _Scene_Message_prototype_isActive = Scene_Message.prototype.isActive;
|
|
Scene_Message.prototype.isActive = function () {
|
|
const ret = _Scene_Message_prototype_isActive.call(this);
|
|
return ret && this._backlogWindow.active == false;
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Window_Message
|
|
//
|
|
const _Window_Message_prototype_initMembers =
|
|
Window_Message.prototype.initMembers;
|
|
Window_Message.prototype.initMembers = function () {
|
|
_Window_Message_prototype_initMembers.call(this);
|
|
this._backlogWindow = null;
|
|
};
|
|
|
|
Window_Message.prototype.setBackLogWindow = function (win) {
|
|
this._backlogWindow = win;
|
|
};
|
|
|
|
const _Window_Message_prototype_onEndOfText =
|
|
Window_Message.prototype.onEndOfText;
|
|
Window_Message.prototype.onEndOfText = function () {
|
|
if (this._backlogWindow) {
|
|
const message = this._textState.text;
|
|
const speakerName = $gameMessage.speakerName();
|
|
const faceName = $gameMessage.faceName();
|
|
const faceIndex = $gameMessage.faceIndex();
|
|
this._backlogWindow?.addLog(message, speakerName, faceName, faceIndex);
|
|
}
|
|
_Window_Message_prototype_onEndOfText.call(this);
|
|
};
|
|
|
|
const _Window_Message_prototype_update = Window_Message.prototype.update;
|
|
Window_Message.prototype.update = function () {
|
|
if (this._backlogWindow?.active == true) {
|
|
return; // バックログウインドウが有効なら台詞ウインドウの処理を停止
|
|
}
|
|
_Window_Message_prototype_update.call(this);
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Window_Backlog
|
|
//
|
|
//
|
|
class Window_Backlog extends Window_Selectable {
|
|
constructor(rect) {
|
|
super(rect);
|
|
this._isWindow = false;
|
|
this.visible = false;
|
|
}
|
|
|
|
#getLogArray() {
|
|
return $gameTemp._windowBackLogData ?? [];
|
|
}
|
|
|
|
addLog(message, speakerName, faceName, faceId) {
|
|
const logData = new Window_BackLog_LogData(
|
|
message,
|
|
speakerName,
|
|
faceName,
|
|
faceId
|
|
);
|
|
const logArr = this.#getLogArray();
|
|
const maxLogNum = pluginParam.maxLogNum;
|
|
logArr.push(logData);
|
|
if (maxLogNum > 0 && logArr.length > maxLogNum) {
|
|
logArr.splice(0, logArr.length - maxLogNum);
|
|
}
|
|
}
|
|
|
|
update() {
|
|
super.update();
|
|
const disableSwitchNo = pluginParam.disableSwitchNo;
|
|
if (
|
|
disableSwitchNo > 0 &&
|
|
$gameSwitches.value(disableSwitchNo) &&
|
|
(this.visible || this.activate)
|
|
) {
|
|
this.hide();
|
|
this.deactivate();
|
|
} else if (Input.isTriggered(pluginParam.toggleKeyName)) {
|
|
this.#toggleVisibleAndActivate();
|
|
}
|
|
}
|
|
|
|
#toggleVisibleAndActivate() {
|
|
if (this.visible) {
|
|
this.hide();
|
|
this.deactivate();
|
|
} else {
|
|
this.#selectLast();
|
|
this.show();
|
|
this.activate();
|
|
this.refresh();
|
|
}
|
|
}
|
|
|
|
#selectLast = function () {
|
|
const logArr = this.#getLogArray();
|
|
this.forceSelect(logArr.length > 0 ? logArr.length - 1 : 0);
|
|
};
|
|
|
|
// Window_Selectable override
|
|
|
|
// ログの表示
|
|
drawItem(index) {
|
|
const itemRect = this.itemRect(index);
|
|
const logData = $gameTemp._windowBackLogData[index];
|
|
const lineH = this.lineHeight();
|
|
const sx = itemRect.x;
|
|
const sy = itemRect.y;
|
|
const faceWidth = ImageManager.faceWidth;
|
|
const faceHeight = itemRect.height;
|
|
if (logData.faceName) {
|
|
this.drawFace(
|
|
logData.faceName,
|
|
logData.faceIndex,
|
|
sx,
|
|
sy,
|
|
faceWidth,
|
|
faceHeight
|
|
);
|
|
} else {
|
|
this.drawFace(
|
|
"ActorOther10_1",
|
|
logData.faceIndex,
|
|
sx,
|
|
sy,
|
|
faceWidth,
|
|
faceHeight
|
|
);
|
|
}
|
|
if (logData.speakerName) {
|
|
//this.drawText(logData.speakerName, sx + faceWidth, sy + lineH, itemRect.width);
|
|
}
|
|
this.drawTextEx(
|
|
"\\}" + logData.message,
|
|
sx + 10 + faceWidth,
|
|
sy,
|
|
itemRect.width
|
|
);
|
|
}
|
|
|
|
maxCols() {
|
|
return 1;
|
|
}
|
|
maxItems() {
|
|
return this.#getLogArray().length;
|
|
}
|
|
itemWidth() {
|
|
return super.itemWidth();
|
|
}
|
|
itemHeight() {
|
|
return this.lineHeight() * 4; /*super.itemHeight();*/
|
|
}
|
|
}
|
|
class Window_BackLog_LogData {
|
|
#message = "";
|
|
#speakerName = "";
|
|
#faceName = "";
|
|
#faceIndex = 0;
|
|
constructor(message, speakerName, faceName, faceIndex) {
|
|
this.#message = message;
|
|
this.#speakerName = speakerName;
|
|
this.#faceName = faceName;
|
|
this.#faceIndex = faceIndex;
|
|
}
|
|
get message() {
|
|
return this.#message;
|
|
}
|
|
get speakerName() {
|
|
return this.#speakerName;
|
|
}
|
|
get faceName() {
|
|
return this.#faceName;
|
|
}
|
|
get faceIndex() {
|
|
return this.#faceIndex;
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Game_Temp
|
|
//
|
|
const _Game_Temp_prototype_initialize = Game_Temp.prototype.initialize;
|
|
Game_Temp.prototype.initialize = function () {
|
|
_Game_Temp_prototype_initialize.call(this);
|
|
this._windowBackLogData = [];
|
|
};
|
|
|
|
// TMMMapHpGauge_Custom用に追加
|
|
Object.defineProperty(Game_Temp.prototype, "isBacklogActive", {
|
|
get: function () {
|
|
const scn = SceneManager._scene;
|
|
if (scn?._backlogWindow.active) return true;
|
|
return false;
|
|
},
|
|
configurable: true,
|
|
});
|
|
})();
|