84 lines
2.8 KiB
JavaScript
84 lines
2.8 KiB
JavaScript
/*:
|
||
* @target MZ
|
||
* @plugindesc [MZ] 条件で選択肢を「押下不可」+1段目のみ\C[26]表示対応版
|
||
* @author you
|
||
* @help
|
||
* 使い方([選択肢の表示] 直前にスクリプト):
|
||
* DisableChoices.clear();
|
||
* // 例: 変数38が60未満なら1番目(0)を無効化
|
||
* DisableChoices.disableIf(0, $gameVariables.value(38) < 60);
|
||
*
|
||
* 備考:
|
||
* - インデックスは0始まり(1番目=0)。
|
||
* - 無効時は半透明の薄いグレー、選択可能時の1段目は\C[26]で描画されます。
|
||
*/
|
||
|
||
(() => {
|
||
// ===== 公開API =====
|
||
window.DisableChoices = {
|
||
clear() { $gameTemp._disabledChoices = []; },
|
||
disable(index) {
|
||
if (index == null) return;
|
||
$gameTemp._disabledChoices ||= [];
|
||
$gameTemp._disabledChoices[index] = true;
|
||
},
|
||
disableIf(index, cond) { if (cond) this.disable(index); }
|
||
};
|
||
const flags = () => $gameTemp._disabledChoices || [];
|
||
|
||
// ===== 選択肢作成時に「押下不可」フラグを設定 =====
|
||
const _makeCommandList = Window_ChoiceList.prototype.makeCommandList;
|
||
Window_ChoiceList.prototype.makeCommandList = function() {
|
||
_makeCommandList.call(this);
|
||
const f = flags();
|
||
for (let i = 0; i < this._list.length; i++) {
|
||
if (f[i] && this._list[i]) {
|
||
this._list[i].enabled = false; // 押下不可に設定
|
||
}
|
||
}
|
||
};
|
||
|
||
// ===== 描画時に1段目のみ\C[26]を付与 =====
|
||
const _drawItem = Window_ChoiceList.prototype.drawItem;
|
||
Window_ChoiceList.prototype.drawItem = function(index) {
|
||
const rect = this.itemLineRect(index);
|
||
let text = this.commandName(index);
|
||
const enabled = this.isCommandEnabled(index);
|
||
|
||
// 1段目かつ選択可能なら\C[26]を付ける
|
||
if (index === 0 && enabled) {
|
||
text = "\\C[26]" + text;
|
||
}
|
||
|
||
this.changePaintOpacity(enabled);
|
||
this.drawTextEx(text, rect.x, rect.y);
|
||
this.changePaintOpacity(true);
|
||
};
|
||
|
||
// ===== 判定の保険(押下ブロック) =====
|
||
const _isCommandEnabled = Window_ChoiceList.prototype.isCommandEnabled;
|
||
Window_ChoiceList.prototype.isCommandEnabled = function(index) {
|
||
if (flags()[index]) return false;
|
||
return _isCommandEnabled.call(this, index);
|
||
};
|
||
|
||
// ===== 押下時の最終バズ音 =====
|
||
const _processOk = Window_Command.prototype.processOk;
|
||
Window_Command.prototype.processOk = function() {
|
||
if (this instanceof Window_ChoiceList) {
|
||
const i = this.index();
|
||
if (flags()[i]) {
|
||
this.playBuzzerSound();
|
||
return;
|
||
}
|
||
}
|
||
_processOk.call(this);
|
||
};
|
||
|
||
// ===== メッセージ終了時にクリア =====
|
||
const _terminateMessage = Scene_Message.prototype.terminateMessage;
|
||
Scene_Message.prototype.terminateMessage = function() {
|
||
_terminateMessage.call(this);
|
||
$gameTemp._disabledChoices = [];
|
||
};
|
||
})();
|