211 lines
6.2 KiB
JavaScript
211 lines
6.2 KiB
JavaScript
//=============================================================================
|
|
// RPG Maker MZ - Conditional Choices
|
|
//
|
|
// Copyright 2024 Panzer-IV. All rights reserved.
|
|
// This source code or any portion thereof must not be
|
|
// reproduced or used without licensed in any manner whatsoever.
|
|
//=============================================================================
|
|
/*:
|
|
* @target MZ
|
|
* @plugindesc 条件付き選択肢
|
|
* @author 四号戦車
|
|
* @base PluginCommonBase
|
|
* @orderAfter PluginCommonBase
|
|
*
|
|
* @help SceneLewdStatus.js
|
|
*
|
|
* Version: 0.0.2
|
|
*
|
|
* 条件付き選択肢
|
|
*
|
|
* 特定の選択肢を条件付きで入れたり消したりできます。
|
|
*
|
|
* @command showConditionalChoices
|
|
* @text 条件付き選択肢の表示
|
|
* @desc 選択肢の表示を条件付きで行えます
|
|
*
|
|
* @arg choices
|
|
* @text 選択肢
|
|
* @desc 条件付きの選択肢
|
|
* @type struct<ConditionalOption>[]
|
|
* @defult []
|
|
*
|
|
* @arg background
|
|
* @text 背景
|
|
* @desc 選択肢の背景
|
|
* @type select
|
|
* @default 0
|
|
* @option ウィンドウ
|
|
* @value 0
|
|
* @option 暗くする
|
|
* @value 1
|
|
* @option 透明
|
|
* @value 2
|
|
*
|
|
* @arg position
|
|
* @text ウィンドウ位置
|
|
* @desc ウィンドウの位置
|
|
* @type select
|
|
* @default 2
|
|
* @option 左
|
|
* @value 0
|
|
* @option 中
|
|
* @value 1
|
|
* @option 右
|
|
* @value 2
|
|
*
|
|
* @arg defaultOption
|
|
* @text デフォルト
|
|
* @desc デフォルトの選択肢
|
|
* @type select
|
|
* @default 0
|
|
* @option なし
|
|
* @value -1
|
|
* @option 選択肢#1
|
|
* @value 0
|
|
* @option 選択肢#2
|
|
* @value 1
|
|
* @option 選択肢#3
|
|
* @value 2
|
|
* @option 選択肢#4
|
|
* @value 3
|
|
* @option 選択肢#5
|
|
* @value 4
|
|
* @option 選択肢#6
|
|
* @value 5
|
|
*
|
|
* @arg cancelOption
|
|
* @text キャンセル
|
|
* @desc キャンセル時の処理
|
|
* @type select
|
|
* @default 1
|
|
* @option 指定イベント
|
|
* @value -2
|
|
* @option 禁止
|
|
* @value -1
|
|
* @option 選択肢#1
|
|
* @value 0
|
|
* @option 選択肢#2
|
|
* @value 1
|
|
* @option 選択肢#3
|
|
* @value 2
|
|
* @option 選択肢#4
|
|
* @value 3
|
|
* @option 選択肢#5
|
|
* @value 4
|
|
* @option 選択肢#6
|
|
* @value 5
|
|
*
|
|
* @arg cancelEvent
|
|
* @text キャンセル時のイベント
|
|
* @type common_event
|
|
* @default 0
|
|
*/
|
|
/*~struct~ConditionalOption:
|
|
*
|
|
* @param label
|
|
* @text 表示テキスト(ラベル)
|
|
* @desc 表示する文章のリソースラベル
|
|
* @type string
|
|
* @default
|
|
*
|
|
* @param text
|
|
* @text 表示テキスト
|
|
* @desc 表示する文章
|
|
* ラベルが指定されている場合無視されます
|
|
* @type string
|
|
* @default
|
|
*
|
|
* @param switchCondition
|
|
* @text 表示条件スイッチ
|
|
* @desc ONの時だけ条件になります
|
|
* @type switch
|
|
* @dedault 0
|
|
*
|
|
* @param event
|
|
* @text 選択時のイベント
|
|
* @type common_event
|
|
* @default 0
|
|
*
|
|
*/
|
|
(() => {
|
|
"use strict";
|
|
|
|
//========================================================================
|
|
// プラグイン定義
|
|
//========================================================================
|
|
const pluginName = "ConditionalChoices";
|
|
const script = document.currentScript;
|
|
const param = PluginManagerEx.createParameter(script);
|
|
|
|
//========================================================================
|
|
// 定数定義
|
|
//========================================================================
|
|
|
|
//========================================================================
|
|
// コアスクリプト変更部 (Game_Interpreter)
|
|
//========================================================================
|
|
Game_Interpreter.prototype.setupConditionalChoices = function(params) {
|
|
const choices = params.choices.filter(option => {
|
|
const switchId = option.switchCondition;
|
|
return PluginUtils.getSwitch(switchId, true);
|
|
}).map(option => {
|
|
if (!!option.label && label.length > 0) {
|
|
return TextResource.getText(label);
|
|
} else {
|
|
return option.text;
|
|
}
|
|
});
|
|
const defaultType = params.defaultOption;
|
|
const background = params.background;
|
|
const positionType = params.position;
|
|
const cancelType = params.cancelOption;
|
|
|
|
$gameMessage.setChoices(choices, defaultType, cancelType);
|
|
$gameMessage.setChoiceBackground(background);
|
|
$gameMessage.setChoicePositionType(positionType);
|
|
$gameMessage.setChoiceCallback(index => {
|
|
if (index === -2) {
|
|
// キャンセル時指定のイベント
|
|
PluginUtils.waitCommonEvent(params.cancelEvent);
|
|
} else if (index >= 0) {
|
|
PluginUtils.waitCommonEvent(params.choices[index]);
|
|
}
|
|
});
|
|
};
|
|
|
|
const _Game_Interpreter_prototype_command101 = Game_Interpreter.prototype.command101;
|
|
Game_Interpreter.prototype.command101 = function(params) {
|
|
if ($gameMessage.isBusy()) {
|
|
return false;
|
|
}
|
|
|
|
const result = _Game_Interpreter_prototype_command101.apply(this, arguments);
|
|
|
|
const nextCommand = this._list[this._index + 1];
|
|
if (nextCommand.code === 357) {
|
|
// 次がプラグインコマンド
|
|
const name = nextCommand.parameters[0];
|
|
const functionName = nextCommand.parameters[1];
|
|
|
|
if (name === pluginName && functionName === 'showConditionalChoices') {
|
|
// 次がこのプラグインの選択肢コマンド
|
|
const params = PluginManagerEx.createCommandArgs(nextCommand.parameters[3]);
|
|
this._index++;
|
|
this.setupConditionalChoices(params);
|
|
}
|
|
return true;
|
|
}
|
|
return result;
|
|
};
|
|
|
|
//========================================================================
|
|
// プラグインコマンド
|
|
//========================================================================
|
|
PluginManagerEx.registerCommand(script, 'showConditionalChoices', args => {
|
|
if (!!args.interpreter) {
|
|
args.interpreter.setupConditionalChoices(args);
|
|
args.interpreter.setWaitMode("message");
|
|
}
|
|
});
|
|
})();
|