code:
//============================================================================
// MOG_TitlePictureCom.js
// Translate to Japanese : fungamemake.com
//============================================================================

/*:
 * @plugindesc (v1.6 *) Adiciona comandos em imagens no lugar da janela.
 * @author Moghunter
 *
 * @param -> Main <<<<<<<<<<<<<<<<<<<<<<<
 * @desc
 *
 * @param Animation Mode
 * @desc Definição do tipo de animação.
 * 0 - None     1 - Pulse    2 - Shake
 * @default 2
 * @type select
 * @option None
 * @value 0
 * @option Pulse Effect
 * @value 1
 * @option Shake Effect
 * @value 2
 * @parent -> Main <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Left & Right Input
 * @desc Ativar a seleção de comandos com as teclas Right/Left.
 * @default true
 * @type boolean
 * @parent -> Main <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Com Fade-In Duration
 * @text Fade-In Duration
 * @desc Faz os comandos aparecerem gradualmente.
 * @default 13
 * @type number
 * @parent -> Main <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Slide X-Axis
 * @desc Faz os comandos deslizarem na horizontal.
 * @default -100
 * @type number
 * @parent -> Main <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Slide Y-Axis
 * @desc Faz os comandos deslizarem na vertical.
 * @default 0
 * @type number
 * @parent -> Main <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param
 *
 * @param -> Smart Background  <<<<<<<<<<<<<<<<<<<<<<<
 * @desc
 *
 * @param Smart Background
 * @text Visible
 * @desc Ativar a imagem de fundo baseado na seleção de comando.
 * @default true
 * @type boolean
 * @parent -> Smart Background  <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Background X-Axis
 * @text X-Axis
 * @desc Definição X-Axis da imagem de fundo.
 * @default 0
 * @type number
 * @parent -> Smart Background  <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Background Y-Axis
 * @text Y-Axis
 * @desc Definição Y-Axis da imagem de fundo.
 * @default 0
 * @type number
 * @parent -> Smart Background  <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Background Fade-In Duration
 * @text Fade-In Duration
 * @desc Definição do tempo para apresentar a imagem.
 * @default 90
 * @type number
 * @parent -> Smart Background  <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param
 *
 * @param -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 * @desc
 *
 * @param Title Sprite
 * @text Visible
 * @desc Ativar o nome do título em sprite.
 * É necessário ter o arquivo Title.png na pasta img/titles2/
 * @default true
 * @type boolean
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Title Sprite X-Axis
 * @text X-Axis
 * @desc Definição X-axis.
 * @default 300
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Title Sprite Y-Axis
 * @text Y-Axis
 * @desc Definição Y-axis.
 * @default 150
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Fade-In Duration
 * @desc Define o tempo para fazer o título aparecer.
 * @default 40
 * @type number
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Zoom Effect
 * @desc Ativar o efeito de zoom.
 * @default true
 * @type boolean
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Zoom Speed
 * @desc Definição do tempo de zoom.
 * @default 40
 * @type number
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param
 *
 * @param -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 * @desc
 *
 * @param Cursor X-Axis
 * @text X-Axis
 * @desc Definição X-axis do cursor.
 * @default 0
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Cursor Y-Axis
 * @text Y-Axis
 * @desc Definição Y-axis do cursor.
 * @default 5
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Cursor Visible
 * @text Visible
 * @desc Ativar cursor.
 * @default true
 * @type boolean
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Cursor Wave Animation
 * @text Wave Animation
 * @desc Ativar animação de deslize.
 * @default true
 * @type boolean
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Cursor Rotation Animation
 * @text Rotation Animation
 * @desc Ativar animação de rotação.
 * @default true
 * @type boolean
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Cursor Rotation Speed
 * @text Rotation Speed
 * @desc Definição da velociade de rotação.
 * @default 0.05
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param
 *
 * @param -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 * @desc
 *
 * @param Command Pos 1
 * @desc Definição da posição do comando 1.
 * E.g -     32,32
 * @default 650,460
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 2
 * @desc Definição da posição do comando 2.
 * E.g -     32,32
 * @default 660,490
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 3
 * @desc Definição da posição do comando 3.
 * E.g -     32,32
 * @default 665,520
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 4
 * @desc Definição da posição do comando 4.
 * E.g -     32,32
 * @default 670,550
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 5
 * @desc Definição da posição do comando 5.
 * E.g -     32,32
 * @default 345,498
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 6
 * @desc Definição da posição do comando 6.
 * E.g -     32,32
 * @default 345,530
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 7
 * @desc Definição da posição do comando 7.
 * E.g -     32,32
 * @default 0,192
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 8
 * @desc Definição da posição do comando 8.
 * E.g -     32,32
 * @default 0,224
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 9
 * @desc Definição da posição do comando 9.
 * E.g -     32,32
 * @default 0,256
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 10
 * @desc Definição da posição do comando 10.
 * E.g -     32,32
 * @default 0,288
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @help
 * ===========================================================================
 * +++ MOG - Title Picture Commands (v1.6) +++
 * By Moghunter
 * https://atelierrgss.wordpress.com/
 * ===========================================================================
 * Adiciona comandos em imagens no lugar da janela.
 * É necessário ter os arquivos:
 *
 * Command_0.png, Command_1.png, Command_2.png , Command_3.png ...
 *
 * Grave as imagens na pasta:
 *
 * img/titles2/
 * ===========================================================================
 * Será necessário também uma imagem representando o cursor.
 *
 * Cursor.png
 *
 * ===========================================================================
 * - WHAT'S  NEW (version 1.6)
 * ===========================================================================
 * (BUG FIX) - Correção de alguns plugin parameters não funcionarem.
 *
 */
/*:ja
 * @plugindesc (v1.6 *) タイトルメニューのコマンドを画像で表示します
 * @author Moghunter
 *
 * @param -> Main <<<<<<<<<<<<<<<<<<<<<<<
 * @text -> コマンド全般 <<<<<<<<<<<<<<<<<<<<<<<
 * @desc
 *
 * @param Animation Mode
 * @text アニメーション設定
 * @desc アニメーション形式を選択
 * 0:なし / 1:波打ち / 2:振動
 * @default 2
 * @type select
 * @option なし
 * @value 0
 * @option 波打ち
 * @value 1
 * @option 振動
 * @value 2
 * @parent -> Main <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Left & Right Input
 * @text 右左キーコマンド選択
 * @desc 右/左キーでのコマンド選択の有効設定
 * @on 有効
 * @off 無効
 * @default true
 * @type boolean
 * @parent -> Main <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Com Fade-In Duration
 * @text コマンドのフェードイン時間
 * @desc コマンドがフェードイン完了するまでの時間
 * @default 13
 * @type number
 * @max 9007
 * @parent -> Main <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Slide X-Axis
 * @text X軸スライド
 * @desc コマンドを水平方向にスライドさせる量
 * @default -100
 * @type number
 * @min -9007
 * @max 9007
 * @parent -> Main <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Slide Y-Axis
 * @text Y軸スライド
 * @desc コマンドを垂直方向にスライドさせる量
 * @default 0
 * @type number
 * @min -9007
 * @max 9007
 * @parent -> Main <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param
 *
 * @param -> Smart Background  <<<<<<<<<<<<<<<<<<<<<<<
 * @text -> コマンド選択時イメージ  <<<<<<<<<<<<<<<<<<<<<<<
 * @desc
 *
 * @param Smart Background
 * @text 表示設定
 * @desc コマンド選択時のイメージ画像表示設定
 * @on 有効
 * @off 無効
 * @default true
 * @type boolean
 * @parent -> Smart Background  <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Background X-Axis
 * @text X軸設定
 * @desc X軸設定
 * @default 0
 * @type number
 * @min -9007
 * @max 9007
 * @parent -> Smart Background  <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Background Y-Axis
 * @text Y軸設定
 * @desc Y軸設定
 * @default 0
 * @type number
 * @min -9007
 * @max 9007
 * @parent -> Smart Background  <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Background Fade-In Duration
 * @text フェードイン時間
 * @desc フェードイン完了するまでの時間
 * @default 90
 * @type number
 * @max 9007
 * @parent -> Smart Background  <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param
 *
 * @param -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 * @text -> タイトル画像 <<<<<<<<<<<<<<<<<<<<<<<
 * @desc
 *
 * @param Title Sprite
 * @text タイトル画像表示設定
 * @desc タイトル画像表示の有効設定
 * @default true
 * @type boolean
 * @on 有効
 * @off 無効
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Title Sprite X-Axis
 * @text X軸設定
 * @desc X軸設定(原点:中央)
 * @default 300
 * @type number
 * @max 9007
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Title Sprite Y-Axis
 * @text Y軸設定
 * @desc Y軸設定(原点:中央)
 * @default 150
 * @type number
 * @max 9007
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Fade-In Duration
 * @text フェードイン時間
 * @desc フェードイン完了するまでの時間
 * @default 40
 * @type number
 * @max 9007
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Zoom Effect
 * @text ズーム効果
 * @desc ズーム効果の有効設定
 * @default true
 * @type boolean
 * @on 有効
 * @off 無効
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Zoom Speed
 * @text ズーム速度
 * @desc ズーム完了するまでの時間
 * @default 40
 * @type number
 * @max 9007
 * @parent -> Title Sprite <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param
 *
 * @param -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 * @text -> カーソル <<<<<<<<<<<<<<<<<<<<<<<
 * @desc
 *
 * @param Cursor Visible
 * @text カーソル有効化
 * @desc カーソルの有効設定
 * @default true
 * @type boolean
 * @on 有効
 * @off 無効
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Cursor Wave Animation
 * @text 波打ちアニメ有効化
 * @desc 波打ちアニメーションの有効設定
 * @default true
 * @type boolean
 * @on 有効
 * @off 無効
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Cursor Rotation Animation
 * @text 回転アニメ有効化
 * @desc 回転アニメーションを有効にします。
 * @default true
 * @type boolean
 * @on 有効
 * @off 無効
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Cursor Rotation Speed
 * @text 回転アニメ速度
 * @desc 正:時計回り / 負:反時計回り。絶対値が大きいほど高速。
 * @default 0.05
 * @type number
 * @min -9007
 * @max 9007
 * @decimals 2
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Cursor X-Axis
 * @text X軸設定
 * @desc カーソルのX軸設定
 * @default 0
 * @type number
 * @min -9007
 * @max 9007
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Cursor Y-Axis
 * @text Y軸設定
 * @desc カーソルのY軸設定
 * @default 5
 * @type number
 * @min -9007
 * @max 9007
 * @parent -> Cursor <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param
 *
 * @param -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 * @text コマンド位置
 * @desc
 *
 * @param Command Pos 1
 * @desc コマンド1の座標
 * 書式: 32,32
 * @default 650,460
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 2
 * @desc コマンド2の座標
 * 書式: 32,32
 * @default 660,490
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 3
 * @desc コマンド3の座標
 * 書式: 32,32
 * @default 665,520
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 4
 * @desc コマンド4の座標
 * 書式: 32,32
 * @default 670,550
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 5
 * @desc コマンド5の座標
 * 書式: 32,32
 * @default 345,498
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 6
 * @desc コマンド6の座標
 * 書式: 32,32
 * @default 345,530
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 7
 * @desc コマンド7の座標
 * 書式: 32,32
 * @default 0,192
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 8
 * @desc コマンド8の座標
 * 書式: 32,32
 * @default 0,224
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 9
 * @desc コマンド9の座標
 * 書式: 32,32
 * @default 0,256
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @param Command Pos 10
 * @desc コマンド10の座標
 * 書式: 32,32
 * @default 0,288
 * @parent -> Commands <<<<<<<<<<<<<<<<<<<<<<<
 *
 * @help
 * 翻訳:ムノクラ
 * https://fungamemake.com/
 * https://twitter.com/munokura/
 *
 * ===========================================================================
 * +++ MOG - Title Picture Commands (v1.6) +++
 * By Moghunter
 * https://atelierrgss.wordpress.com/
 * ===========================================================================
 * 必要な画像は下記のフォルダに保存してください。
 *
 * img/titles2/
 *
 * ---------------------------------------------------------------------------
 * タイトルウィンドウの代わりに画像でコマンドを表示します。
 * 下記のような画像ファイルがコマンドの数だけ必要です。
 *
 * Command_0.png, Command_1.png, Command_2.png , Command_3.png ...
 *
 * ---------------------------------------------------------------------------
 * "コマンド選択時イメージ"を有効にする場合、下記画像ファイルが必要です。
 * コマンドの数だけ必要です。
 *
 * Sub_0.png, Sub_1.png, Sub_2.png , Sub_3.png ...
 *
 * ---------------------------------------------------------------------------
 * "タイトル画像表示"を有効にする場合、下記画像ファイルが必要です。
 *
 * Title.png
 *
 * ---------------------------------------------------------------------------
 * "カーソル"を有効にする場合、下記画像ファイルが必要です。
 *
 * Cursor.png
 *
 * ===========================================================================
 * - WHAT'S  NEW (version 1.6)
 * ===========================================================================
 * (BUG FIX) - 一部のプラグインパラメータが機能しない問題を修正しました。
 *
 */

//============================================================================
// ** PLUGIN PARAMETERS
//============================================================================
var Imported = Imported || {};
Imported.MOG_Picture_Command = true;
var Moghunter = Moghunter || {};

Moghunter.parameters = PluginManager.parameters("MOG_TitlePictureCom");
Moghunter.title_sprite = Moghunter.parameters["Title Sprite"] || false;
Moghunter.title_x = Number(Moghunter.parameters["Title Sprite X-Axis"] || 300);
Moghunter.title_y = Number(Moghunter.parameters["Title Sprite Y-Axis"] || 150);
Moghunter.title_zoomEffect = String(
  Moghunter.parameters["Zoom Effect"] || "true"
);
Moghunter.title_zoomDuration = Number(Moghunter.parameters["Zoom Speed"] || 40);
Moghunter.title_FadeInDuration = Number(
  Moghunter.parameters["Fade-In Duration"] || 40
);
Moghunter.title_comMode = Number(Moghunter.parameters["Animation Mode"] || 2);
Moghunter.title_ComFadeInDuration = Number(
  Moghunter.parameters["Com Fade-In Duration"] || 13
);
Moghunter.title_sideInput = String(
  Moghunter.parameters["Left & Right Input"] || "true"
);
Moghunter.title_subPicture = String(
  Moghunter.parameters["Smart Background"] || "true"
);
Moghunter.title_slideXaxis = Number(
  Moghunter.parameters["Slide X-Axis"] || -100
);
Moghunter.title_slideYaxis = Number(Moghunter.parameters["Slide Y-Axis"] || 0);
Moghunter.title_subPictureX = Number(
  Moghunter.parameters["Background X-Axis"] || 0
);
Moghunter.title_subPictureY = Number(
  Moghunter.parameters["Background Y-Axis"] || 0
);
Moghunter.title_subFadeInDuration = Number(
  Moghunter.parameters["Background Fade-In Duration"] || 90
);
Moghunter.title_cursorVisible = String(
  Moghunter.parameters["Cursor Visible"] || "true"
);
Moghunter.title_cursorSlide = String(
  Moghunter.parameters["Cursor Wave Animation"] || "true"
);
Moghunter.title_cursorX = Number(Moghunter.parameters["Cursor X-Axis"] || 8);
Moghunter.title_cursorY = Number(Moghunter.parameters["Cursor Y-Axis"] || -10);
Moghunter.title_cursorRot = String(
  Moghunter.parameters["Cursor Rotation Animation"] || "true"
);
Moghunter.title_cursorRotSpeed = Number(
  Moghunter.parameters["Cursor Rotation Speed"] || 0.05
);
Moghunter.title_com_pos = [];
for (var i = 0; i < 10; i++) {
  Moghunter.title_com_pos[i] =
    Moghunter.parameters["Command Pos " + String(i + 1)] || null;
}

//============================================================================
// ** Window_TitleCommand
//============================================================================

//==============================
// * updatePlacement
//==============================
var _alias_mog_title_picture_commands_updatePlacement =
  Scene_Title.prototype.updatePlacement;
Window_TitleCommand.prototype.updatePlacement = function () {
  this.x = -Graphics.boxWidth;
  this.y = -Graphics.boxheight;
  this.visible = false;
};

//============================================================================
// ** Scene Base
//============================================================================

//==============================
// ** create Hud Field
//==============================
Scene_Base.prototype.createHudField = function () {
  this._hudField = new Sprite();
  this._hudField.z = 10;
  this.addChild(this._hudField);
};

//==============================
// ** sort MZ
//==============================
Scene_Base.prototype.sortMz = function () {
  this._hudField.children.sort(function (a, b) {
    return a.mz - b.mz;
  });
};

//============================================================================
// ** Scene Title
//============================================================================

//==============================
// * Create
//==============================
var _mog_title_picture_commands_create = Scene_Title.prototype.create;
Scene_Title.prototype.create = function () {
  _mog_title_picture_commands_create.call(this);
  if (!this._hudField) {
    this.createHudField();
  }
  this._sideInput = String(Moghunter.title_sideInput) == "true" ? true : false;
  this._comSave = this._commandWindow.isContinueEnabled();
  this._comInitVis = true;
  this.createComSprites();
  this.sortMz();
};

//==============================
// * set tcp
//==============================
Scene_Title.prototype.set_tcp = function (value) {
  if (!value) {
    return null;
  }
  var s = value.split(",");
  if (!s[0] || !s[1]) {
    return null;
  }
  return [Number(s[0]), Number(s[1])];
};

//==============================
// * create Com Sprites
//==============================
Scene_Title.prototype.createComSprites = function (value) {
  if (Moghunter.title_comMode == 1) {
    this._com_pulse = true;
    this._comshake = false;
  } else if (Moghunter.title_comMode == 2) {
    this._com_pulse = false;
    this._comshake = true;
  } else {
    this._com_pulse = false;
    this._comshake = false;
  }
  this.createPictureCommands();
  if (String(Moghunter.title_subPicture) == "true") {
    this.createSubPicture();
  }
  if (String(Moghunter.title_cursorVisible) == "true") {
    this.createCursorCommand();
  }
  if (String(Moghunter.title_sprite) == "true") {
    this.createTitleSprite();
  }
};

//==============================
// * Create Cursor Command
//==============================
Scene_Title.prototype.createCursorCommand = function () {
  this._cursorSlide = [0, 0, 0, false];
  if (String(Moghunter.title_cursorSlide) == "true") {
    this._cursorSlide[3] = true;
  }
  this._cursor = new Sprite(ImageManager.loadTitle2("Cursor"));
  this._cursor.anchor.x = 0.5;
  this._cursor.anchor.y = 0.5;
  this._cursor.org = [Moghunter.title_cursorX, Moghunter.title_cursorY];
  if (this._cursorSlide[3]) {
    this._cursor.org[0] -= 5;
  }
  this._cursor.opacity = 0;
  this._cursor.mz = 500;
  this._cursor.rot = [true, 0.05];
  this._cursor.rot[0] =
    String(Moghunter.title_cursorRot) == "true" ? true : false;
  this._cursor.rot[1] = Moghunter.title_cursorRotSpeed;
  this._hudField.addChild(this._cursor);
};

//==============================
// * Com Sprite
//==============================
Scene_Title.prototype.comSprite = function () {
  return this._com_sprites[this._commandWindow._index];
};

//==============================
// * update Cursor
//==============================
Scene_Title.prototype.updateCursor = function () {
  if (!this._comInitVis) {
    return;
  }
  if (this._cursorSlide[3]) {
    this.updateCursorSlide();
  }
  if (this._cursor.rot[0]) {
    this.updateCursorRotation();
  }
  this._cursor.opacity += 5;
  var nx =
    this.comSprite().x -
    this.comSprite().bitmap.width / 2 -
    this._cursor.width / 2 +
    this._cursorSlide[0] -
    this.comSprite().shake[0] +
    this._cursor.org[0]; //+ (this._cursor.width / 2)  + this._cursorSlide[0];
  var ny =
    this.comSprite().y -
    this.comSprite().bitmap.height / 2 +
    this._cursor.height / 2 +
    this._cursor.org[1];
  this._cursor.x = this.cursorMoveto(this._cursor.x, nx, 10);
  this._cursor.y = this.cursorMoveto(this._cursor.y, ny, 10);
};

//==============================
// * Uodate Cursor Rotation
//==============================
Scene_Title.prototype.updateCursorRotation = function () {
  this._cursor.rotation += this._cursor.rot[1];
};

//==============================
// * update Cursor Slide
//==============================
Scene_Title.prototype.updateCursorSlide = function () {
  this._cursorSlide[1]++;
  if (this._cursorSlide[1] < 3) {
    return;
  }
  this._cursorSlide[1] = 0;
  this._cursorSlide[2]++;
  if (this._cursorSlide[2] < 15) {
    this._cursorSlide[0]++;
  } else if (this._cursorSlide[2] < 30) {
    this._cursorSlide[0]--;
  } else {
    this._cursorSlide[0] = 0;
    this._cursorSlide[2] = 0;
  }
};

//==============================
// * Sprite Move To
//==============================
Scene_Title.prototype.cursorMoveto = function (value, real_value, speed) {
  if (value == real_value) {
    return value;
  }
  var dnspeed = 3 + Math.abs(value - real_value) / speed;
  if (value > real_value) {
    value -= dnspeed;
    if (value < real_value) {
      value = real_value;
    }
  } else if (value < real_value) {
    value += dnspeed;
    if (value > real_value) {
      value = real_value;
    }
  }
  return Math.floor(value);
};

//==============================
// * Create Picture Commands
//==============================
Scene_Title.prototype.createPictureCommands = function () {
  this._com_position = [];
  for (var i = 0; i < 10; i++) {
    this._com_position[i] = this.set_tcp(Moghunter.title_com_pos[i]);
  }
  var _com_index_old = -2;
  if (this._subPic) {
    this.createSubPicture();
  }
  this._csel = false;
  this._com_int = true;
  this._com_pictures = [];
  this._com_sprites = [];
  this._com_pictures_data = [];
  for (i = 0; i < this._commandWindow._list.length; i++) {
    this._com_pictures[i] = ImageManager.loadTitle2("Command_" + i);
    this._com_sprites[i] = new Sprite(this._com_pictures[i]);
    this._com_sprites[i].org = [0, 0];
    this._com_sprites[i].shake = [0, 0, 0];
    this._com_sprites[i].pulse = [0, 0, 0];
    this._com_sprites[i].mz = i + 200;
    this._com_sprites[i].wait = 0;
    this._com_sprites[i].enabled = true;
    this._com_sprites[i].anchor.x = 0.5;
    this._com_sprites[i].anchor.y = 0.5;
    this._com_sprites[i].size = [0, 0];
    this._hudField.addChild(this._com_sprites[i]);
  }
};

//==============================
// * Create Sub Picture
//==============================
Scene_Title.prototype.createSubPicture = function () {
  this._subPictures = [];
  for (i = 0; i < this._commandWindow._list.length; i++) {
    this._subPictures[i] = ImageManager.loadTitle2("Sub_" + i);
  }
  this._subPic = new Sprite();
  this._subPic.x = Moghunter.title_subPictureX;
  this._subPic.y = Moghunter.title_subPictureY;
  this._subPic.mz = 130;
  this._subPic.index = -1;
  this._subPic.opacity = 0;
  this._subPic.wait = Moghunter.title_subFadeInDuration;
  this._hudField.addChild(this._subPic);
};

//==============================
// * Refresh Com Sub Pic
//==============================
Scene_Title.prototype.refreshComSubPic = function () {
  this._subPic.index = this._commandWindow._index;
  this._subPic.opacity = 0;
  this._subPic.bitmap = this._subPictures[this._subPic.index];
};

//==============================
// * update ComSubPic
//==============================
Scene_Title.prototype.updateComSubPic = function () {
  if (this._subPic.index != this._commandWindow._index) {
    this.refreshComSubPic();
  }
  if (this._subPic.wait > 0) {
    this._subPic.wait--;
    return;
  }
  this._subPic.opacity += 2;
};

//==============================
// * Refresh Picture Command
//==============================
Scene_Title.prototype.refresh_picture_command = function () {
  this._com_index_old = this._commandWindow._index;
  for (i = 0; i < this._com_sprites.length; i++) {
    if (this._commandWindow._index != i) {
      var chr = this._com_pictures[i].height / 2;
      this._com_sprites[i].shake = [0, 0, 0];
    } else {
      var chr = 0;
      this._com_sprites[i].shake = [0, 10, 0];
    }
    this.cpsx = [this._com_position[i][0], this._com_position[i][1]];
    if (this._commandWindow._list[i].symbol == "continue" && !this._comSave) {
      this._com_sprites[i].enabled = false;
    }
    var cw = this._com_sprites[i].bitmap.width / 2;
    var ch = this._com_sprites[i].bitmap.height / 2;
    this._com_sprites[i].size = [cw, ch];
    this._com_sprites[i].setFrame(
      0,
      chr,
      this._com_pictures[i].width,
      this._com_pictures[i].height / 2
    );
    this._com_sprites[i].x = this.cpsx[0] + cw;
    this._com_sprites[i].y = this.cpsx[1] + ch;
    this._com_sprites[i].org = [this._com_sprites[i].x, this._com_sprites[i].y];
    this._com_pictures_data[i] = [];
    this._com_pictures_data[i][0] = this._com_sprites[i].x - cw;
    this._com_pictures_data[i][1] = this._com_sprites[i].x + cw;
    this._com_pictures_data[i][2] = this._com_sprites[i].y - ch / 2;
    this._com_pictures_data[i][3] = this._com_sprites[i].y + ch / 2;
    this._com_sprites[i].pulse = [0, 0, 0];
    if (!this._comshake) {
      this._com_sprites[i].shake[1] = 0;
    }
    if (this._com_int) {
      this._com_sprites[i].x += Moghunter.title_slideXaxis;
      this._com_sprites[i].y += Moghunter.title_slideYaxis;
      this._com_sprites[i].shake[1] = 0;
      this._com_sprites[i].wait = 10 + Moghunter.title_ComFadeInDuration * i;
      this._com_sprites[i].opacity = 0;
    }
  }
  this._com_int = false;
};

//==============================
// * Update Com Input
//==============================
Scene_Title.prototype.updateComInput = function () {
  if (TouchInput.isTriggered()) {
    for (i = 0; i < this._com_sprites.length; i++) {
      if (this.on_picture_com(i) && !this._csel) {
        this._commandWindow._index = i;
        this._commandWindow.processOk();
        if (this._commandWindow.isCommandEnabled(i)) {
          this._csel = true;
        }
      }
    }
  }
  if (this._sideInput) {
    this.updateComSideInput();
  }
};

//==============================
// * Update Com Side Inout
//==============================
Scene_Title.prototype.updateComSideInput = function () {
  if (Input.isRepeated("right")) {
    this.addTitleComIndex(1);
  } else if (Input.isRepeated("left")) {
    this.addTitleComIndex(-1);
  }
};

//==============================
// * add Title ComIndex
//==============================
Scene_Title.prototype.addTitleComIndex = function (value) {
  SoundManager.playCursor();
  var maxIndex = this._commandWindow._list.length - 1;
  this._commandWindow._index += value;
  if (this._commandWindow._index < 0) {
    this._commandWindow._index = maxIndex;
  } else if (this._commandWindow._index > maxIndex) {
    this._commandWindow._index = 0;
  }
};

//==============================
// * Update Com Shake
//==============================
Scene_Title.prototype.updateComShake = function (sprite) {
  sprite.shake[2]++;
  if (sprite.shake[2] < 2) {
    return;
  }
  sprite.shake[2] = 0;
  sprite.shake[1]--;
  sprite.shake[0] = -2 + Math.randomInt(4);
  if (sprite.shake[1] == 0) {
    sprite.shake[0] = 0;
  }
};

//==============================
// * Update Com Pulse
//==============================
Scene_Title.prototype.updateComPulse = function (sprite, enable) {
  if (enable) {
    if (sprite.pulse[0] == 0) {
      sprite.scale.x += 0.01;
      if (sprite.scale.x >= 1.25) {
        sprite.scale.x = 1.25;
        sprite.pulse[0] = 1;
      }
    } else {
      sprite.scale.x -= 0.01;
      if (sprite.scale.x <= 1.0) {
        sprite.scale.x = 1.0;
        sprite.pulse[0] = 0;
      }
    }
  } else {
    if (sprite.scale.x > 1.0) {
      sprite.scale.x -= 0.01;
    }
  }
  sprite.scale.y = sprite.scale.x;
};

//==============================
// * Update Picture Commands
//==============================
Scene_Title.prototype.updateCommandsPic = function (sprite, enable) {
  if (sprite.wait > 0) {
    sprite.wait--;
    return;
  }
  if (this._subPic) {
    this.updateComSubPic();
  }
  if (sprite.shake[1] > 0) {
    this.updateComShake(sprite);
  }
  if (this._com_pulse) {
    this.updateComPulse(sprite, enable);
  }
  var nx = sprite.org[0] + sprite.shake[0];
  var ny = sprite.org[1];
  sprite.x = this.cursorMoveto(sprite.x, nx, 60);
  sprite.y = this.cursorMoveto(sprite.y, ny, 60);
  sprite.opacity += 5;
  if (!sprite.enabled && sprite.opacity > 160) {
    sprite.opacity = 160;
  }
};

//==============================
// * On Picture Com
//==============================
Scene_Title.prototype.on_picture_com = function (index) {
  if (TouchInput.x < this._com_pictures_data[index][0]) {
    return false;
  }
  if (TouchInput.x > this._com_pictures_data[index][1]) {
    return false;
  }
  if (TouchInput.y < this._com_pictures_data[index][2]) {
    return false;
  }
  if (TouchInput.y > this._com_pictures_data[index][3]) {
    return false;
  }
  return true;
};

//==============================
// * Create Title Sprite
//==============================
Scene_Title.prototype.createTitleSprite = function () {
  if (this._gameTitleSprite) {
    this.removeChild(this._gameTitleSprite);
  }
  this._gameTitleSprite = new Sprite(ImageManager.loadTitle2("Title"));
  this._hudField.addChild(this._gameTitleSprite);
  this._gameTitleSprite.mz = 250;
  this._gameTitleSprite.x = Moghunter.title_x;
  this._gameTitleSprite.y = Moghunter.title_y;
  this._gameTitleSprite.anchor.x = 0.5;
  this._gameTitleSprite.anchor.y = 0.5;
  this._gameTitleSprite.wait = 30;
  this._gameTitleSprite.opacity = 0;
  this._gameTitleSprite.zoomEffect =
    Moghunter.title_zoomEffect == "true" ? true : false;
  this._gameTitleSprite.fadeInDuration = Moghunter.title_zoomDuration;
  this._gameTitleSprite.zoomSpd = 0.5 / this._gameTitleSprite.fadeInDuration;
  this._gameTitleSprite.opcSpd = 150 / this._gameTitleSprite.fadeInDuration;
  if (this._gameTitleSprite.zoomEffect) {
    this._gameTitleSprite.scale.x = 1.5;
    this._gameTitleSprite.scale.y = this._gameTitleSprite.scale.x;
  }
};

//==============================
// * update Title Sprite
//==============================
Scene_Title.prototype.updateTitleSprite = function () {
  if (this._gameTitleSprite.wait > 0) {
    this._gameTitleSprite.wait--;
    return;
  }
  this._gameTitleSprite.opacity += this._gameTitleSprite.opcSpd;
  if (this._gameTitleSprite.scale.x > 1.0) {
    this._gameTitleSprite.scale.x -= this._gameTitleSprite.zoomSpd;
    if (this._gameTitleSprite.scale.x <= 1.0) {
      this._gameTitleSprite.scale.x = 1.0;
    }
  }
  this._gameTitleSprite.scale.y = this._gameTitleSprite.scale.x;
};

//==============================
// * Update Picture Commands
//==============================
Scene_Title.prototype.updatePictureCommands = function () {
  this._comInitVis = true;
  for (i = 0; i < this._com_sprites.length; i++) {
    var sprite = this._com_sprites[i];
    var enable = i == this._commandWindow._index ? true : false;
    this.updateCommandsPic(sprite, enable);
  }
  if (!this._comInitVis) {
    return;
  }
  if (this._com_index_old != this._commandWindow._index) {
    this.refresh_picture_command();
  }
  this.updateComInput();
  this.updateTitleSprite();
  if (this._cursor) {
    this.updateCursor();
  }
};

//==============================
// * Update
//==============================
var _mog_title_picture_commands_update = Scene_Title.prototype.update;
Scene_Title.prototype.update = function () {
  _mog_title_picture_commands_update.call(this);
  this.updatePictureCommands();
};


code:
//===========================================================================
// MOG_TitleSplashScreen.js
// Translate to Japanese : fungamemake.com
//===========================================================================

/*:
 * @plugindesc (v1.1 *) Adiciona logos antes da tela de título.
 * @author Moghunter
 *
 * @param Number of Logos
 * @desc Quantidade de logos.
 * (Default = 1)
 * @default 1
 * @type number
 *
 * @param Slash Duration
 * @desc Duração do logo.
 * (Default = 60)
 * @default 60
 * @type number
 *
 * @param Splash Fade Duration
 * @desc Velocidade do fade.
 * (Default = 2)
 * @default 2
 * @type number
 *
 * @param Full Screen Mode
 * @desc Ativar o modo em tela cheia. (true  / false)
 * (Default = false)
 * @default false
 * @type boolean
 *
 * @help
 * ===========================================================================
 * +++ MOG - Title Splash Screen (v1.1) +++
 * By Moghunter
 * https://atelierrgss.wordpress.com/
 * ===========================================================================
 * Adiciona multiplos logos antes da tela de título.
 * Serâo necessários os arquivos.
 *
 * Splash_INDEX.png
 *
 * no lugar da INDEX coloque a numeração da imagem.
 *
 * Splash_0.png
 * Splash_1.png
 * Splash_2.png
 * ...
 *
 * Coloque as imagens na pasta:
 *
 * img/titles2/
 *
 * ===========================================================================
 * - WHAT'S  NEW (version 1.1)
 * ===========================================================================
 * - (NEW) - Plugins parameters compatíveis com RM1.5+
 */

/*:ja
 * @plugindesc (v1.1 *) タイトル画面の表示前に複数のロゴを表示します。
 * @author Moghunter
 *
 * @param Number of Logos
 * @text ロゴ数
 * @desc デフォルト:1
 * @default 1
 * @type number
 * @max 9007
 *
 * @param Slash Duration
 * @text ロゴの表示時間
 * @desc デフォルト:60
 * @default 60
 * @type number
 * @max 9007
 *
 * @param Splash Fade Duration
 * @text フェード速度
 * @desc デフォルト:2
 * @default 2
 * @type number
 * @max 9007
 *
 * @param Full Screen Mode
 * @text 起動時全画面表示の有効化
 * @desc デフォルト:無効
 * @type boolean
 * @on 有効
 * @off 無効
 * @default false
 *
 * @help
 * 翻訳:ムノクラ
 * https://fungamemake.com/
 * https://twitter.com/munokura/
 *
 * ===========================================================================
 * +++ MOG - Title Splash Screen (v1.1) +++
 * By Moghunter
 * https://atelierrgss.wordpress.com/
 * ===========================================================================
 * タイトル画面の表示前に複数のロゴを表示します。
 * 画像を下記フォルダに入れてください。
 *
 * img/titles2/
 *
 * 下記のファイルが必要になります。
 *
 * Splash_INDEX.png
 *
 * INDEXの代わりに表示順の番号を付けます。
 *
 * Splash_0.png
 * Splash_1.png
 * Splash_2.png
 * ...
 *
 * ===========================================================================
 * - 更新履歴 (version 1.1)
 * ===========================================================================
 * - (NEW) - RM1.5 +準拠パラメータプラグイン
 */

//===========================================================================
// ** PLUGIN PARAMETERS
//===========================================================================
var Imported = Imported || {};
Imported.MOG_TitleSplashScreen = true;
var Moghunter = Moghunter || {};

Moghunter.parameters = PluginManager.parameters("MOG_TitleSplashScreen");
Moghunter.title_splash_number = Number(
  Moghunter.parameters["Number of Logos"] || 1
);
Moghunter.title_splash_duration = Number(
  Moghunter.parameters["Slash Duration"] || 60
);
Moghunter.title_splash_fade_speed = Number(
  Moghunter.parameters["Splash Fade Duration"] || 2
);
Moghunter.title_full_screen_mode =
  Moghunter.parameters["Full Screen Mode"] || false;

//===========================================================================
// ** Scene Boot
//===========================================================================

//==============================
// * Start
//==============================
var _alias_mog_title_splash_screen_boot_start = Scene_Boot.prototype.start;
Scene_Boot.prototype.start = function () {
  if (Moghunter.title_full_screen_mode == "true") {
    Graphics._requestFullScreen();
  }
  if (!DataManager.isBattleTest() && !DataManager.isEventTest()) {
    SceneManager.goto(Scene_Splash_Screen);
    return;
  }
  _alias_mog_title_splash_screen_boot_start.call(this);
};

//===========================================================================
// ** Scene Splash Screen
//===========================================================================
function Scene_Splash_Screen() {
  this.initialize.apply(this, arguments);
}
Scene_Splash_Screen.prototype = Object.create(Scene_Base.prototype);
Scene_Splash_Screen.prototype.constructor = Scene_Splash_Screen;

//==============================
// * Initialize
//==============================
Scene_Splash_Screen.prototype.initialize = function () {
  Scene_Base.prototype.initialize.call(this);
};

//==============================
// * Create
//==============================
Scene_Splash_Screen.prototype.create = function () {
  Scene_Base.prototype.create.call(this);
  this._splash_data = [
    0,
    0,
    Math.max(Moghunter.title_splash_duration, 1),
    Math.max(Moghunter.title_splash_fade_speed, 1),
  ];
  this._splash_img = [];
  this._splash_sprite = new Sprite();
  this._splash_sprite.anchor.x = 0.5;
  this._splash_sprite.anchor.y = 0.5;
  this._splash_sprite.x = Graphics.boxWidth / 2;
  this._splash_sprite.y = Graphics.boxHeight / 2;
  this.addChild(this._splash_sprite);
  for (i = 0; i < Moghunter.title_splash_number; i++) {
    this._splash_img.push(ImageManager.loadTitle2("Splash_" + i));
  }
  this.refresh_splash_screen();
};

//==============================
// * Refresh Splash Screen
//==============================
Scene_Splash_Screen.prototype.refresh_splash_screen = function () {
  if (this._splash_data[0] >= this._splash_img.length) {
    AudioManager.stopMe();
    DataManager.setupNewGame();
    SceneManager.goto(Scene_Title);
    Window_TitleCommand.initCommandPosition();
    return;
  }
  this._splash_sprite.bitmap = this._splash_img[this._splash_data[0]];
  this._splash_sprite.opacity = 0;
  this._splash_data[0] += 1;
  this._splash_data[1] = this._splash_data[2];
};

//==============================
// * Start
//==============================
Scene_Splash_Screen.prototype.start = function () {
  Scene_Base.prototype.start.call(this);
  this.startFadeIn(this.fadeSpeed(), false);
};

//==============================
// * Update
//==============================
Scene_Splash_Screen.prototype.update = function () {
  Scene_Base.prototype.update.call(this);
  if (this._splash_data[1] <= 0) {
    this._splash_sprite.opacity -= this._splash_data[3];
    if (Input.isTriggered("ok") || TouchInput.isTriggered()) {
      this._splash_data[0] = this._splash_img.length;
    }
    if (this._splash_sprite.opacity <= 0) {
      this.refresh_splash_screen();
    }
  } else {
    this._splash_sprite.opacity += this._splash_data[3];
    if (
      (Input.isTriggered("ok") || TouchInput.isTriggered()) &&
      this._splash_sprite.opacity > 60
    ) {
      this._splash_data[1] = 0;
      this._splash_data[0] = this._splash_img.length;
    }
    if (this._splash_sprite.opacity >= 255) {
      this._splash_data[1] -= 1;
    }
  }
};

repo_name: dazed/translations

license: unknown


code:
//=============================================================================
// MPP_ChoiceEX.js
//=============================================================================
// Copyright (c) 2015 - 2022 Mokusei Penguin
// Released under the MIT license
// http://opensource.org/licenses/mit-license.php
//=============================================================================

/*:
 * @target MV MZ
 * @plugindesc Extend the functionality of your choices.
 * @author Mokusei Penguin
 * @url
 *
 * @help [version 4.3.3]
 * This plugin is for RPG Maker MV and MZ.
 *
 * ▼ Plugin command
 *  - In MV, the variable N is referred to by writing v[N] in the item for
 *    inputting a numerical value.
 *  - In MZ, in the item to enter a numerical value, select the text and
 *    write v[N] to refer to the variable N.
 *  - It is basically preferable to execute the plugin command before
 *    [Show Choices].
 *  - If you want to use the plug-in command while the message window is
 *    displayed, execute it before [Display text].
 *
 *  〇 MV / MZ
 *
 *  〇 ChoicePos x y row  / choicePos
 *       x   : X coordinate of choice window
 *       y   : Y coordinate of choice window
 *       row : The number of lines in the choice window. Show all if not set
 *   - Specify the position (x, y) and the number of rows of the next choice
 *     to display.
 *
 *  〇 ChoiceVariableId varId  / choiceVariableId
 *       varId : Variable number
 *   - Set the default position of the next choice to display to the value of
 *     the variable.
 *   - In addition, put the current cursor position in a variable.
 *   - The cursor position is 0 to 5 for the first option from the top,
 *     10 to 15 for the next option, and +10 for each option.
 *
 *  〇 ChoiceRect x y width height  / choiceRect
 *       x      : X coordinate
 *       y      : Y coordinate
 *       width  : width
 *       height : height
 *   - Specify the coordinates and size of the next choice to display.
 *   - For items that have not been set or for which -1 is specified,
 *     normal values will be applied.
 *
 *  〇 ChoiceInMessage  / ChoiceInMessage
 *   - The next choice to display is displayed in the message window.
 *   - This function will not work unless it is used in combination with
 *     [Display Text].
 *   - Please execute before [Display text].
 *
 * ▼ More choices
 *  - If you place the event command [Display Choices] in succession,
 *    they will be combined into one choice.
 *  - If you don't want to put them together, you can separate them as usual by
 *    inserting annotations in between.
 *  - For the "default" process, the one set other than none is applied.
 *  - For the "Cancel" process, the ones other than prohibited are applied.
 *  - In both cases, the setting of the option that follows takes precedence.
 *  - For "Background" and "Window position", the settings of the options that
 *    follow are applied.
 *
 * ▼ Setting conditions for displaying items
 *  - If you enter
 *      if(condition)
 *    in the text of the choice and the condition becomes false,
 *    the item will not be displayed.
 *  - The operation when the "Default" item is not displayed can be set in the
 *    [Disabled Index] of the plug-in parameter.
 *  - If the "Cancel" item is not displayed, the same processing as prohibition
 *    is performed.
 *  - Within the condition, you can refer to the switch with "s" and
 *    the variable with "v".
 *     Example: When set to if(s[1])
 *                => Switch No. 1 is ON for display and OFF for non-display.
 *              When set to if(!s[2])
 *                => Switch 2 is displayed when it is OFF,
 *                   and is hidden when it is ON.
 *              When set to if(v[5]>0)
 *                => Display if variable 5 is greater than 0,
 *                   hide if variable 5 is less than 0.
 *
 *     Inequalities that can be used in variables
 *       === : equal
 *       !== : Not equal
 *       <   : Smaller
 *       <=  : Less than or equal to
 *       >   : Greater
 *       >=  : Greater than or equal to
 *
 * ▼ Setting conditions for displaying items semi-transparently
 *  - Enter
 *      en(condition)
 *    in the text of the choice, and if the condition is false,
 *    the item will be displayed semi-transparently.
 *  - Items that are semi-transparent cannot be selected.
 *  - The conditions are the same as "Setting the conditions for displaying
 *    items" above.
 *  - If the "Cancel" item is semi-transparent, you cannot cancel it.
 *
 * ▼ Display help message
 *  - You can put
 *      ChoiceHelp
 *    in the [Comment] below each choice item to indicate the following text
 *    as a help message when you hover over it.
 *  - Help messages use the same functionality as View Text, so you can use
 *    control characters. (\! And \^ cannot be used)
 *  - The above command name can be changed with the plugin parameter.
 *
 * ================================
 * Mail : wood_penguin＠yahoo.co.jp (＠ is half-width)
 * Blog : http://woodpenguin.blog.fc2.com/
 * License : MIT license
 *
 *  @command choicePos
 *      @desc Specify the position and number of lines for the next choice to display.
 *      @arg x
 *          @desc -1: Default
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default 0
 *      @arg y
 *          @desc -1: Default
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default 0
 *      @arg row
 *          @desc 0: Show all
 *          @type number
 *              @min 0
 *              @max 99
 *          @default 0
 *
 *
 *  @command choiceVariableId
 *      @desc Set the default position of the next choice to display to the value of the variable. In addition, put the current cursor position in a variable.
 *      @arg varId
 *          @desc
 *          @type variable
 *          @default 0
 *
 *  @command choiceRect
 *      @desc Specify the coordinates and size of the next choice to display.
 * Normal values are applied to unset items.
 *      @arg x
 *          @desc -1: Default
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default
 *      @arg y
 *          @desc -1: Default
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default
 *      @arg width
 *          @desc -1: Default
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default
 *      @arg height
 *          @desc -1: Default
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default
 *
 *  @command choiceInMessage
 *      @desc The next choice to display is displayed in the message window.
 * It will not work unless it is used in combination with [Display text].
 *
 *
 *  @param Max Page Row
 *      @desc Maximum number of lines displayed on one page
 *      @type number
 *          @min 1
 *          @max 99
 *      @default 6
 *
 *  @param Disabled Position
 *      @desc Cursor position when the default choice is not displayed
 *      @type select
 *          @option none
 *          @option top
 *      @default none
 *
 *  @param Choice Help Commands
 *      @desc
 *      @type string[]
 *      @default ["ChoiceHelp","<ChoiceHelp>"]
 *
 */

/*:ja
 * @target MV MZ
 * @plugindesc 選択肢の機能を拡張します。
 * @author 木星ペンギン
 * @url
 *
 * @help [version 4.3.3]
 * このプラグインはRPGツクールMVおよびMZ用です。
 *
 * ▼ プラグインコマンド
 *  - MVでは数値を入力する項目で v[N] と記述することで変数N番を参照します。
 *  - MZでは数値を入力する項目で、テキストを選択して v[N] と記述することで
 *    変数N番を参照します。
 *  - プラグインコマンドは基本的に[選択肢の表示]の前に実行するのが好ましいです。
 *  - メッセージウィンドウを表示したままプラグインコマンドを使いたい場合、
 *    [文章の表示]の前に実行してください。
 *
 *  〇 MV / MZ
 *
 *  〇 ChoicePos x y row  / 選択肢位置設定
 *       x   : 選択肢ウィンドウのX座標
 *       y   : 選択肢ウィンドウのY座標
 *       row : 選択肢ウィンドウの行数。未設定の場合はすべて表示
 *   - 次に表示する選択肢の位置(x,y)と行数(row)指定します。
 *
 *  〇 ChoiceVariableId varId  / カーソル位置設定
 *       varId : 変数番号
 *   - 次に表示する選択肢のデフォルト位置を変数の値にします。
 *   - さらに現在のカーソル位置を変数に入れます。
 *   - カーソル位置は最初の選択肢が上から0～5、次の選択肢は10～15と、
 *     選択肢毎に+10されます。
 *
 *  〇 ChoiceRect x y width height  / 選択肢サイズ設定
 *       x      : X座標
 *       y      : Y座標
 *       width  : 幅
 *       height : 高さ
 *   - 次に表示する選択肢の座標とサイズを指定します。
 *   - 未設定もしくは-1を指定した項目は、通常の値が適用されます。
 *
 *  〇 ChoiceInMessage  / メッセージ内表示
 *   - 次に表示する選択肢をメッセージウィンドウ内に表示させます。
 *   - この機能は[文章の表示]と併用しなければ機能しません。
 *   - [文章の表示]の前に実行してください。
 *
 * ▼ 選択肢を増やす
 *  - イベントコマンド『選択肢の表示』を続けて配置すると
 *    一つの選択肢にまとめられます。
 *  - まとめたくない場合は、間に注釈などを入れることで
 *    通常通り分けることができます。
 *  - 『デフォルト』の処理は、なし以外を設定したものが適用されます。
 *  - 『キャンセル』の処理は、禁止以外を設定したものが適用されます。
 *  - どちらも後にある選択肢の設定が優先されます。
 *  - 『背景』と『ウィンドウ位置』は後にある選択肢の設定が適用されます。
 *
 * ▼ 項目が表示される条件の設定
 *  - 選択肢の文章中に
 *      if(条件)
 *    と入れ、その条件が偽になると項目が表示されなくなります。
 *  - 『デフォルト』の項目が表示されない場合の動作は、
 *    プラグインパラメータの[Disabled Index]にて設定できます。
 *  - 『キャンセル』の項目が表示されない場合、禁止と同じ処理をします。
 *  - 条件内では s でスイッチ、v で変数を参照できます。
 *     例：if(s[1]) とした場合
 *          => スイッチ１番がONで表示、OFFで非表示。
 *        if(!s[2]) とした場合
 *          => スイッチ２番がOFFで表示、ONで非表示。
 *        if(v[5]>0) とした場合
 *          => 変数５番が0より大きければ表示、0以下で非表示。
 *
 *     変数で使える不等号
 *       === : 等しい
 *       !== : 等しくない
 *       <   : より小さい
 *       <=  : より小さいまたは等しい
 *       >   : より大きい
 *       >=  : より大きいまたは等しい
 *
 * ▼ 項目を半透明で表示する条件の設定
 *  - 選択肢の文章中に
 *      en(条件)
 *    と入れ、その条件が偽になると項目が半透明で表示されます。
 *  - 半透明となった項目は選択できなくなります。
 *  - 条件は上の『項目が表示される条件の設定』と同じです。
 *  - 『キャンセル』の項目が半透明の場合、キャンセルできなくなります。
 *
 * ▼ ヘルプメッセージの表示
 *  - 各選択肢項目の下に[注釈]で
 *      選択肢ヘルプ
 *    と入れると、続きの文章をヘルプメッセージとしてカーソルを合わせたときに
 *    標示させることができます。
 *  - ヘルプメッセージは[文章の表示]と同じ機能を使っているため、
 *    制御文字が使用できます。(\!と\^は使用できません)
 *  - 上記のコマンド名はプラグインパラメータで変更できます。
 *
 * ================================
 * Mail : wood_penguin＠yahoo.co.jp (＠は半角)
 * Blog : http://woodpenguin.blog.fc2.com/
 * License : MIT license
 *
 *  @command choicePos
 *      @text 選択肢位置設定
 *      @desc 次に表示する選択肢の位置と行数を指定します。
 *      @arg x
 *          @desc -1: デフォルト
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default 0
 *      @arg y
 *          @desc -1: デフォルト
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default 0
 *       @arg row
 *          @text 行数
 *          @desc 0: 全て表示
 *          @type number
 *              @min 0
 *              @max 99
 *          @default 0
 *
 *  @command choiceVariableId
 *      @text カーソル位置設定
 *      @desc 次に表示する選択肢のデフォルト位置を変数の値にします。
 * さらに現在のカーソル位置を変数に入れます。
 *      @arg varId
 *          @text 変数
 *          @desc
 *          @type variable
 *          @default 0
 *
 *  @command choiceRect
 *      @text 選択肢サイズ設定
 *      @desc 次に表示する選択肢の座標とサイズを指定します。
 * 未設定の項目は通常の値が適用されます。
 *      @arg x
 *          @desc -1: デフォルト
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default
 *      @arg y
 *          @desc -1: デフォルト
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default
 *      @arg width
 *          @text 幅
 *          @desc -1: デフォルト
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default
 *      @arg height
 *          @text 高さ
 *          @desc -1: デフォルト
 *          @type number
 *              @min -1
 *              @max 9999
 *          @default
 *
 *  @command choiceInMessage
 *      @text メッセージ内表示
 *      @desc 次に表示する選択肢をメッセージウィンドウ内に表示させます。
 * [文章の表示]と併用しなければ機能しません。
 *
 *
 *  @param Max Page Row
 *      @text 最大表示行数
 *      @desc 1ページに表示される最大行数
 *      @type number
 *          @min 1
 *          @max 99
 *      @default 6
 *
 *  @param Disabled Position
 *      @text 無効時のカーソル位置
 *      @desc [デフォルト]となる選択肢が表示されない場合のカーソル位置
 *      @type select
 *          @option なし
 *              @value none
 *          @option 先頭
 *              @value top
 *      @default none
 *
 *  @param Choice Help Commands
 *      @text [選択肢ヘルプ]呼び出し名
 *      @desc
 *      @type string[]
 *      @default ["ChoiceHelp","<ChoiceHelp>","選択肢ヘルプ","<選択肢ヘルプ>"]
 *
 */

(() => {
  "use strict";

  const pluginName = "MPP_ChoiceEX";

  // Plugin Parameters
  const parameters = PluginManager.parameters(pluginName);
  const param_MaxPageRow = Number(parameters["Max Page Row"] || 6);
  const param_DisabledPosition = parameters["Disabled Position"] || "none";
  const param_ChoiceHelpCommands = JSON.parse(
    parameters["Choice Help Commands"] || "[]"
  );

  // Dealing with other plugins
  const __base = (obj, prop) => {
    if (obj.hasOwnProperty(prop)) {
      return obj[prop];
    } else {
      const proto = Object.getPrototypeOf(obj);
      return function () {
        return proto[prop].apply(this, arguments);
      };
    }
  };

  // JsExtensions 代替
  const MathExt = (() => {
    // Number.prototype.clamp と違い、下限優先
    const clamp = (x, min, max) => Math.max(Math.min(x, max), min);
    const mod = (x, n) => ((x % n) + n) % n;
    return { clamp, mod };
  })();

  //-------------------------------------------------------------------------
  // PluginManager

  if (!PluginManager.registerCommand) {
    PluginManager._commandsMV = PluginManager._commandsMV || {};

    PluginManager.registerCommandMV = function (pluginName, commandName, func) {
      const key = pluginName + ":" + commandName;
      this._commandsMV[key] = func;
    };

    PluginManager.callCommandMV = function (
      self,
      pluginName,
      commandName,
      args
    ) {
      const key = pluginName + ":" + commandName;
      const func = this._commandsMV[key];
      if (typeof func === "function") {
        func.bind(self)(args);
      }
    };
  }

  {
    const _registerCommand =
      PluginManager.registerCommand || PluginManager.registerCommandMV;

    _registerCommand.call(PluginManager, pluginName, "choicePos", (args) => {
      const x = PluginManager.mppValue(args.x);
      const y = PluginManager.mppValue(args.y);
      const row = PluginManager.mppValue(args.row) || 99;
      $gameMessage.setChoicePos(x, y, row);
    });

    _registerCommand.call(
      PluginManager,
      pluginName,
      "choiceVariableId",
      (args) => {
        const variableId = PluginManager.mppValue(args.varId);
        $gameMessage.setChoiceVariableId(variableId);
      }
    );

    _registerCommand.call(PluginManager, pluginName, "choiceRect", (args) => {
      const x = args.x ? PluginManager.mppValue(args.x) : -1;
      const y = args.y ? PluginManager.mppValue(args.y) : -1;
      const width = args.width ? PluginManager.mppValue(args.width) : -1;
      const height = args.height ? PluginManager.mppValue(args.height) : -1;
      $gameMessage.setChoiceRect(x, y, width, height);
    });

    _registerCommand.call(PluginManager, pluginName, "choiceInMessage", () => {
      $gameMessage.requestChoiceInMessage();
    });
  }

  PluginManager.mppValue = function (value) {
    const match = /^V\[(\d+)\]$/i.exec(value);
    return match ? $gameVariables.value(+match[1]) : +value;
  };

  //-------------------------------------------------------------------------
  // Game_Message

  Object.defineProperties(Game_Message.prototype, {
    choiceX: {
      get() {
        return this._choiceX;
      },
      configurable: true,
    },
    choiceY: {
      get() {
        return this._choiceY;
      },
      configurable: true,
    },
    choiceWidth: {
      get() {
        return this._choiceWidth;
      },
      configurable: true,
    },
    choiceHeight: {
      get() {
        return this._choiceHeight;
      },
      configurable: true,
    },
  });

  const _Game_Message_clear = Game_Message.prototype.clear;
  Game_Message.prototype.clear = function () {
    _Game_Message_clear.apply(this, arguments);
    this._choiceEnables = [];
    this._choiceResults = [];
    this._helpTexts = [];
    this._choiceX = -1;
    this._choiceY = -1;
    this._choiceWidth = -1;
    this._choiceHeight = -1;
    this._choiceMaxRow = param_MaxPageRow;
    this._choiceVariableId = 0;
    this._choiceInMessage = false;
  };

  Game_Message.prototype.choiceMaxRow = function () {
    return this._choiceMaxRow;
  };

  Game_Message.prototype.setTexts = function (texts) {
    this._texts = texts;
  };

  Game_Message.prototype.setChoiceEnables = function (enables) {
    this._choiceEnables = enables;
  };

  Game_Message.prototype.choiceEnables = function () {
    return this._choiceEnables;
  };

  Game_Message.prototype.setChoiceResults = function (results) {
    this._choiceResults = results;
  };

  Game_Message.prototype.choiceResults = function () {
    return this._choiceResults;
  };

  Game_Message.prototype.setChoiceHelpTexts = function (texts) {
    this._helpTexts = texts;
  };

  Game_Message.prototype.isChoiceHelp = function () {
    return !this._choiceInMessage && this._helpTexts.length > 0;
  };

  Game_Message.prototype.helpTexts = function () {
    return this._helpTexts;
  };

  Game_Message.prototype.setChoicePos = function (x, y, row) {
    this._choiceX = x;
    this._choiceY = y;
    this._choiceWidth = -1;
    this._choiceHeight = -1;
    this._choiceMaxRow = row;
  };

  Game_Message.prototype.setChoiceRect = function (x, y, width, height) {
    this._choiceX = x;
    this._choiceY = y;
    this._choiceWidth = width;
    this._choiceHeight = height;
  };

  Game_Message.prototype.setChoiceVariableId = function (id) {
    this._choiceVariableId = id;
  };

  Game_Message.prototype.lowerChoiceHeight = function (height) {
    this._choiceY += height;
    this._choiceHeight -= height;
  };

  Game_Message.prototype.requestChoiceInMessage = function () {
    this._choiceInMessage = true;
  };

  Game_Message.prototype.choiceVariableId = function () {
    return this._choiceVariableId;
  };

  Game_Message.prototype.isChoiceInMessage = function () {
    return this._choiceInMessage;
  };

  //-----------------------------------------------------------------------------
  // Game_Interpreter

  Game_Interpreter.prototype.setupChoices = function (params) {
    const data = {
      choices: [],
      enables: [],
      results: [],
      helpTexts: [],
      cancelType: -1,
      defaultType: -1,
      positionType: 0,
      background: 0,
    };
    this.addChoices(params, this._index, data, 0);
    if (data.choices.length > 0) {
      const helpTexts = this.choiceHelpTexts(data);
      const cancelType = this.choiceCancelType(data);
      const defaultType = this.choiceDefaultType(data);
      $gameMessage.setChoices(data.choices, defaultType, cancelType);
      $gameMessage.setChoiceEnables(data.enables);
      $gameMessage.setChoiceResults(data.results);
      $gameMessage.setChoiceHelpTexts(helpTexts);
      $gameMessage.setChoiceBackground(data.background);
      $gameMessage.setChoicePositionType(data.positionType);
      $gameMessage.setChoiceCallback((n) => {
        this._branch[this._indent] = n < 0 ? data.cancelType : data.results[n];
      });
    } else {
      this._branch[this._indent] = -1;
    }
  };

  Game_Interpreter.prototype.addChoices = function (params, index, data, d) {
    const choices = [...params[0]];
    const cancelType = params[1] < choices.length ? params[1] : -2;
    const defaultType = params[2] || 0;
    const nextCommand = this.nextCommandOfChoice(index + 1);
    this.checkChoiceConditions(choices, data, d);
    if (cancelType !== -1) data.cancelType = cancelType + d;
    if (defaultType >= 0) data.defaultType = defaultType + d;
    data.positionType = params.length > 3 ? params[3] : 2;
    data.background = params[4] || 0;
    this.setupHelpText(index + 1, data, d);
    if (nextCommand && nextCommand.code === 102) {
      const nextIndex = this._list.indexOf(nextCommand);
      this.addChoices(nextCommand.parameters, nextIndex, data, d + 10);
    }
  };

  Game_Interpreter.prototype.checkChoiceConditions = function (
    choices,
    data,
    d
  ) {
    const regIf = /\s?if\((.+?)\)/;
    const regEn = /\s?en\((.+?)\)/;
    for (const [i, text] of choices.entries()) {
      if (this.meetsChoiceConditions(text, regIf)) {
        const realText = text.replace(regIf, "").replace(regEn, "");
        data.choices.push(realText);
        data.enables.push(this.meetsChoiceConditions(text, regEn));
        data.results.push(i + d);
      }
    }
  };

  Game_Interpreter.prototype.meetsChoiceConditions = function (text, reg) {
    const match = reg.exec(text);
    return !match || this.evalChoice(match[1]);
  };

  Game_Interpreter.prototype.evalChoice = function (condition) {
    try {
      const s = $gameSwitches._data;
      const realCondition = condition.replace(/V\[(\d+)\]/gi, (_, n) =>
        $gameVariables.value(+n)
      );
      return !!eval(realCondition);
    } catch (e) {
      console.log("条件エラー \n " + condition);
      return true;
    }
  };

  Game_Interpreter.prototype.setupHelpText = function (index, data, d) {
    for (const [i, command] of this._list.slice(index).entries()) {
      if (command.indent === this._indent) {
        if (command.code === 402) {
          const type = command.parameters[0] + d;
          const helpTexts = this.extractHelpTexts(i + index + 1);
          if (helpTexts) data.helpTexts[type] = helpTexts;
        } else if (command.code === 404) {
          return;
        }
      }
    }
  };

  Game_Interpreter.prototype.extractHelpTexts = function (index) {
    const command = this._list[index];
    if (
      command.code === 108 &&
      param_ChoiceHelpCommands.includes(command.parameters[0])
    ) {
      return this.getCommentHelpTexts(index + 1);
    }
    return null;
  };

  Game_Interpreter.prototype.getCommentHelpTexts = function (index) {
    const result = [];
    for (const command of this._list.slice(index)) {
      if (command.code === 408) {
        result.push(command.parameters[0]);
      } else {
        break;
      }
    }
    return result;
  };

  Game_Interpreter.prototype.choiceHelpTexts = function (data) {
    const helpTexts = data.helpTexts;
    return helpTexts.length > 0 ? data.results.map((i) => helpTexts[i]) : [];
  };

  Game_Interpreter.prototype.choiceCancelType = function (data) {
    if (data.cancelType === -1) {
      return -1;
    } else if (MathExt.mod(data.cancelType, 10) === 8) {
      return -2;
    }
    return data.results.indexOf(data.cancelType);
  };

  Game_Interpreter.prototype.choiceDefaultType = function (data) {
    const vId = $gameMessage.choiceVariableId();
    const index = vId > 0 ? $gameVariables.value(vId) : data.defaultType;
    const defaultType = data.results.indexOf(index);
    if (index >= 0 && defaultType < 0 && param_DisabledPosition === "top") {
      return 0;
    }
    return defaultType;
  };

  Game_Interpreter.prototype.nextCommandOfChoice = function (index) {
    const i = this._list
      .slice(index)
      .findIndex(
        (command) => command.indent === this._indent && command.code === 404
      );
    return i >= 0 ? this._list[index + i + 1] : null;
  };

  // overwrite
  Game_Interpreter.prototype.command403 = function () {
    if (this._branch[this._indent] !== -2) {
      this.skipBranch();
    }
    return true;
  };

  Game_Interpreter.prototype.command404 = function () {
    if (this.nextEventCode() === 102) {
      this._branch[this._indent] -= 10;
      this._index++;
    }
    return true;
  };

  const _mzCommands = {
    ChoicePos: { name: "choicePos", keys: ["x", "y", "row"] },
    ChoiceVariableId: { name: "choiceVariableId", keys: ["varId"] },
    ChoiceRect: { name: "choiceRect", keys: ["x", "y", "width", "height"] },
    ChoiceInMessage: { name: "choiceInMessage", keys: [] },
  };
  Object.assign(_mzCommands, {
    選択肢位置設定: _mzCommands.ChoicePos,
    カーソル位置設定: _mzCommands.ChoiceVariableId,
    選択肢サイズ設定: _mzCommands.ChoiceRect,
    メッセージ内表示: _mzCommands.ChoiceInMessage,
  });

  const _Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
  Game_Interpreter.prototype.pluginCommand = function (command, args) {
    _Game_Interpreter_pluginCommand.apply(this, arguments);
    const mzCommand = _mzCommands[command];
    if (mzCommand) {
      const args2 = Object.assign(
        {},
        ...mzCommand.keys.map((key, i) => ({ [key]: args[i] }))
      );
      PluginManager.callCommandMV(this, pluginName, mzCommand.name, args2);
    }
  };

  //-----------------------------------------------------------------------------
  // Window_ChoiceList

  const _Window_ChoiceList_select = __base(
    Window_ChoiceList.prototype,
    "select"
  );
  Window_ChoiceList.prototype.select = function (index) {
    const variableId = $gameMessage.choiceVariableId();
    if (index !== this.index() && variableId > 0) {
      const results = $gameMessage.choiceResults();
      $gameVariables.setValue(variableId, results[index]);
    }
    _Window_ChoiceList_select.apply(this, arguments);
  };

  const _Window_ChoiceList_updatePlacement =
    Window_ChoiceList.prototype.updatePlacement;
  Window_ChoiceList.prototype.updatePlacement = function () {
    _Window_ChoiceList_updatePlacement.apply(this, arguments);
    const {
      choiceX: x,
      choiceY: y,
      choiceWidth: width,
      choiceHeight: height,
    } = $gameMessage;
    if (width >= 0) {
      this.width = MathExt.clamp(width, 1, Graphics.boxWidth);
    }
    if (height >= 0) {
      this.height = MathExt.clamp(height, 1, Graphics.boxHeight);
    }
    if (x >= 0) this.x = Math.min(x, Graphics.boxWidth - this.width);
    if (y >= 0) this.y = Math.min(y, Graphics.boxHeight - this.height);
    this._isWindow = !$gameMessage.isChoiceInMessage();
  };

  // overwrite
  Window_ChoiceList.prototype.numVisibleRows = function () {
    const choices = $gameMessage.choices();
    const maxLines = $gameMessage.choiceMaxRow();
    return Math.min(choices.length, maxLines);
  };

  // overwrite
  Window_ChoiceList.prototype.makeCommandList = function () {
    const enables = $gameMessage.choiceEnables();
    for (const [i, choice] of $gameMessage.choices().entries()) {
      this.addCommand(choice, "choice", enables[i]);
    }
  };

  const _Window_ChoiceList_drawItem = Window_ChoiceList.prototype.drawItem;
  Window_ChoiceList.prototype.drawItem = function (index) {
    this.changePaintOpacity(this.isCommandEnabled(index));
    _Window_ChoiceList_drawItem.apply(this, arguments);
  };

  const _Window_ChoiceList_callOkHandler =
    Window_ChoiceList.prototype.callOkHandler;
  Window_ChoiceList.prototype.callOkHandler = function () {
    _Window_ChoiceList_callOkHandler.apply(this, arguments);
    this._messageWindow.forceClear();
    this._helpIndex = null;
  };

  const _Window_ChoiceList_callCancelHandler =
    Window_ChoiceList.prototype.callCancelHandler;
  Window_ChoiceList.prototype.callCancelHandler = function () {
    _Window_ChoiceList_callCancelHandler.apply(this, arguments);
    this._messageWindow.forceClear();
    this._helpIndex = null;
  };

  const _Window_ChoiceList_processCancel = __base(
    Window_ChoiceList.prototype,
    "processCancel"
  );
  Window_ChoiceList.prototype.processCancel = function () {
    const cancelType = $gameMessage.choiceCancelType();
    if (
      cancelType >= 0 &&
      this.isCancelEnabled() &&
      !this.isCommandEnabled(cancelType)
    ) {
      this.playBuzzerSound();
      return;
    }
    _Window_ChoiceList_processCancel.apply(this, arguments);
  };

  Window_ChoiceList.prototype.callUpdateHelp = function () {
    if (
      this.active &&
      this._messageWindow &&
      $gameMessage.isChoiceHelp() &&
      this._helpIndex !== this.index()
    ) {
      this._helpIndex = this.index();
      this.updateHelp();
    }
  };

  Window_ChoiceList.prototype.updateHelp = function () {
    this._messageWindow.forceClear();
    const texts = $gameMessage.helpTexts()[this.index()];
    $gameMessage.setTexts(texts ? [...texts] : [""]);
    this._messageWindow.startMessage();
  };

  //-----------------------------------------------------------------------------
  // Window_Message

  const _Window_Message_initialize = Window_Message.prototype.initialize;
  Window_Message.prototype.initialize = function (rect) {
    _Window_Message_initialize.apply(this, arguments);
    this.updatePlacement();
  };

  const _Window_Message_updatePlacement =
    Window_Message.prototype.updatePlacement;
  Window_Message.prototype.updatePlacement = function () {
    _Window_Message_updatePlacement.apply(this, arguments);
    this.clearInChoice();
  };

  Window_Message.prototype.clearInChoice = function () {
    if ($gameMessage.isChoiceInMessage()) {
      const x = this.x + this.choiceStartX();
      const y = this.y + 4;
      const height = this.height;
      $gameMessage.setChoiceRect(x, y, -1, height);
    }
  };

  Window_Message.prototype.choiceStartX = function () {
    if ("left" in this._textState) {
      return this.standardPadding() + this._textState.left;
    } else {
      return $gameSystem.windowPadding() + this._textState.startX;
    }
  };

  const _Window_Message_processNewLine = __base(
    Window_Message.prototype,
    "processNewLine"
  );
  Window_Message.prototype.processNewLine = function (textState) {
    if ($gameMessage.isChoiceInMessage()) {
      $gameMessage.lowerChoiceHeight(textState.height);
    }
    _Window_Message_processNewLine.apply(this, arguments);
  };

  const _Window_Message_updateInput = Window_Message.prototype.updateInput;
  Window_Message.prototype.updateInput = function () {
    if ($gameMessage.isChoiceHelp() && this._textState) {
      return false;
    }
    return _Window_Message_updateInput.apply(this, arguments);
  };

  const _Window_Message_onEndOfText = Window_Message.prototype.onEndOfText;
  Window_Message.prototype.onEndOfText = function () {
    const choiceWindow = this._choiceWindow || this._choiceListWindow;
    if (!choiceWindow.active && $gameMessage.isChoiceHelp()) {
      this.startInput();
    } else {
      _Window_Message_onEndOfText.apply(this, arguments);
    }
  };

  const _Window_Message_startInput = Window_Message.prototype.startInput;
  Window_Message.prototype.startInput = function () {
    const choiceWindow = this._choiceWindow || this._choiceListWindow;
    if (choiceWindow.active) return true;
    if (this._textState && this.isLowerChoice()) {
      $gameMessage.lowerChoiceHeight(this._textState.height);
    }
    return _Window_Message_startInput.apply(this, arguments);
  };

  Window_Message.prototype.isLowerChoice = function () {
    const textState = this._textState;
    const startX = "left" in textState ? textState.left : textState.startX;
    return (
      $gameMessage.isChoice() &&
      $gameMessage.isChoiceInMessage() &&
      textState.x !== startX
    );
  };

  Window_Message.prototype.forceClear = function () {
    this._textState = null;
    this.close();
    this._goldWindow.close();
  };

  const _Window_Message_newPage = Window_Message.prototype.newPage;
  Window_Message.prototype.newPage = function (textState) {
    _Window_Message_newPage.apply(this, arguments);
    this.clearInChoice();
  };
})();


code:
//=============================================================================
// MPP_ChoiceEX_Op1.js
//=============================================================================
// Copyright (c) 2021 - 2022 Mokusei Penguin
// Released under the MIT license
// http://opensource.org/licenses/mit-license.php
//=============================================================================

/*:
 * @target MV MZ
 * @plugindesc Add the function to add choice and display it.
 * @author Mokusei Penguin
 * @url
 *
 * @base MPP_ChoiceEX
 * @orderAfter MPP_ChoiceEX
 *
 * @help [version 1.0.2]
 * This plugin is for RPG Maker MV and MZ.
 *
 * ▼ 概要
 *  - You can add the contents of the options one by one and display them all
 *    together.
 *  - Most of the functions of MPP_ChoiceEX.js can be used.
 *  - The added choices are saved in the save data.
 *
 * ▼ Plugin command
 *  - In MV, the variable N is referred to by writing v[N] in the item for
 *    inputting a numerical value.
 *  - In MZ, in the item to enter a numerical value, select the text and
 *    write v[N] to refer to the variable N.
 *  - If you use a variable, the value at the time of executing the command is
 *    applied.
 *
 *  〇 MV / MZ
 *
 *  〇 AddCustomChoice id text value  / addCustomChoice
 *       id    : ID of the array to add (integer greater than or equal to 0)
 *       text  : Choice text
 *       value : Return value
 *   - Add choices to the array.
 *   - Specify any numerical value for the array ID.
 *   - Some control characters and MPP_ChoiceEX.js functions if(condition)
 *     and en(condition) can be used for the choice text.
 *   - The return value is the number returned when this option is selected.
 *   - By design, MV does not allow spaces in the choice text.
 *   - If you want to use spaces in the text in the MV, edit the following
 *     code and execute it in the script.
 * ////////////////////////////////////////////////////////////////
 * const id = 0;
 * const choiceParams = {
 *     text: '',
 *     value: 0
 * };
 * $gameSystem.addCustomChoice(id, choiceParams);
 * ////////////////////////////////////////////////////////////////
 *
 *  〇 ShowCustomChoices id vId back pos def cancel  / showCustomChoices
 *       id     : ID of the array to display
 *       vId    : The number of the variable to put the return value
 *       back   : Background (0:Window, 1:Dim, 2:Transparent / unset:0)
 *       pos    : Window Position (0:Left, 1:Middle, 2:Right / unset:2)
 *       def    : Default (-1:None / unset:0)
 *       cancel : Cancel (-2:Branch, -1:Disallow / unset:-2)
 *   - Show your choices.
 *   - The return value of the selected choice is put into a variable.
 *   - The Background, Window Position, Default, and Cancel are the same as
 *     the normal [Show Choices].
 *   - If [Cancel:Branch] is selected, the return value is -2.
 *   - When executed after [Show Text], the same process as the default
 *     [Show Choices] is performed.
 *
 *  〇 DeleteCustomChoice id text  / deleteCustomChoice
 *       id    : Array ID
 *       text  : Choice text to delete
 *   - Removes all text-matched choices from the array.
 *
 *  〇 ClearCustomChoices id  / clearCustomChoices
 *       id    : ID of the array to be deleted
 *   - Delete the array.
 *
 * ================================
 * Mail : wood_penguin＠yahoo.co.jp (＠ is half-width)
 * Blog : http://woodpenguin.blog.fc2.com/
 * License : MIT license
 *
 *  @command addCustomChoice
 *      @desc
 *      @arg id
 *          @desc ID of the array to add
 *          It is used when displaying or deleting.
 *          @type number
 *              @min 0
 *              @max 99
 *          @default 0
 *      @arg choiceText
 *          @desc
 *          @default
 *      @arg returnValue
 *          @desc The value to put in the variable when this option is selected
 *          @type number
 *              @min -999999
 *              @max 999999
 *          @default 0
 *
 *  @command showCustomChoices
 *      @desc
 *      @arg id
 *          @desc ID of the option to display
 *          @type number
 *              @min 0
 *              @max 99
 *          @default 0
 *      @arg variableId
 *          @desc Variable to put the return value
 *          @type variable
 *          @default 0
 *      @arg background
 *          @desc
 *          @type select
 *              @option Window
 *              @value 0
 *              @option Dim
 *              @value 1
 *              @option Transparent
 *              @value 2
 *          @default 0
 *      @arg positionType
 *          @desc
 *          @type select
 *              @option Left
 *              @value 0
 *              @option Middle
 *              @value 1
 *              @option Right
 *              @value 2
 *          @default 2
 *      @arg defaultType
 *          @desc -1:None
 *          @type number
 *              @min -1
 *              @max 999
 *          @default 0
 *      @arg cancelType
 *          @desc -2:Branch, -1:Disallow
 *          @type number
 *              @min -2
 *              @max 999
 *          @default -2
 *
 *  @command deleteCustomChoice
 *      @desc Deletes the specified choice from the array.
 *      @arg id
 *          @desc ID of the array to delete
 *          @type number
 *              @min 0
 *              @max 99
 *          @default 0
 *      @arg choiceText
 *          @desc
 *          @default
 *
 *  @command clearCustomChoices
 *      @desc Delete the array of choices.
 *      @arg id
 *          @desc ID of the array to delete all
 *          @type number
 *              @min 0
 *              @max 99
 *          @default
 *
 */

/*:ja
 * @target MV MZ
 * @plugindesc 選択肢を追加していき、表示させる機能を追加します。
 * @author 木星ペンギン
 * @url
 *
 * @base MPP_ChoiceEX
 * @orderAfter MPP_ChoiceEX
 *
 * @help [version 1.0.2]
 * このプラグインはRPGツクールMVおよびMZ用です。
 *
 * ▼ 概要
 *  - 選択肢の内容を一つずつ追加していき、まとめて表示することができます。
 *  - MPP_ChoiceEX.jsの機能はおおむね使用できます。
 *  - 追加していった選択肢はセーブデータに保存されます。
 *
 * ▼ プラグインコマンド
 *  - MVでは数値を入力する項目で v[N] と記述することで変数N番を参照します。
 *  - MZでは数値を入力する項目で、テキストを選択して v[N] と記述することで
 *    変数N番を参照します。
 *  - 変数を使用する場合、そのコマンド実行時の値が適用されます。
 *
 *  〇 MV / MZ
 *
 *  〇 AddCustomChoice id text value  / 選択肢追加
 *       id    : 追加する配列のID(0以上の整数)
 *       text  : 選択肢テキスト
 *       value : 返り値
 *   - 配列に選択肢を追加します。
 *   - 配列のIDは任意の数値を指定してください。
 *   - 選択肢テキスト(text)には一部の制御文字や、MPP_ChoiceEX.jsの機能である
 *     if(条件) や en(条件) が使用できます。
 *   - 返り値はこの選択肢が選ばれたときに返す数値です。
 *   - MVでは仕様上、選択肢テキストにスペースを使用することはできません。
 *   - MVでテキストにスペースを使いたい場合は、以下のコード編集して
 *     スクリプトで実行してください。
 * ////////////////////////////////////////////////////////////////
 * const id = 0;
 * const choiceParams = {
 *     text: '',
 *     value: 0
 * };
 * $gameSystem.addCustomChoice(id, choiceParams);
 * ////////////////////////////////////////////////////////////////
 *
 *  〇 ShowCustomChoices id vId back pos def cancel  / 選択肢表示
 *       id     : 表示する配列のID
 *       vId    : 返り値を入れる変数の番号
 *       back   : 背景(0:ウィンドウ, 1:暗くする, 2:透明 / 未設定:0)
 *       pos    : ウィンドウ位置(0:左, 1:中, 2:右 / 未設定:2)
 *       def    : デフォルト(-1:なし / 未設定:0)
 *       cancel : キャンセル(-2:分岐, -1:禁止 / 未設定:-2)
 *   - 選択肢を表示します。
 *   - 選ばれた選択肢の返り値が変数に入れられます。
 *   - 背景・ウィンドウ位置・デフォルト・キャンセルは通常の[選択肢の表示]と
 *     同じです。
 *   - キャンセル:分岐が選ばれた場合の返り値は-2です。
 *   - [文章の表示]の後に実行した場合、デフォルトの[選択肢の表示]と
 *     同じ処理をします。
 *
 *  〇 DeleteCustomChoice id text  / 選択肢削除
 *       id    : 配列のID
 *       text  : 削除する選択肢テキスト
 *   - 配列からテキストが一致した選択肢を全て削除します。
 *
 *  〇 ClearCustomChoices id  / 選択肢クリア
 *       id    : 全削除する配列のID
 *   - 配列を削除します。
 *
 * ================================
 * Mail : wood_penguin＠yahoo.co.jp (＠は半角)
 * Blog : http://woodpenguin.blog.fc2.com/
 * License : MIT license
 *
 *  @command addCustomChoice
 *      @text 選択肢追加
 *      @desc
 *      @arg id
 *          @desc 追加する配列のID
 *          表示や削除を行う際に使用します。
 *          @type number
 *              @min 0
 *              @max 99
 *          @default 0
 *      @arg choiceText
 *          @text 選択肢テキスト
 *          @desc
 *          @default
 *      @arg returnValue
 *          @text 返り値
 *          @desc この選択肢が選ばれた際に変数に入れる値
 *          @type number
 *              @min -999999
 *              @max 999999
 *          @default 0
 *
 *  @command showCustomChoices
 *      @text 選択肢表示
 *      @desc
 *      @arg id
 *          @desc 表示する選択肢のID
 *          @type number
 *              @min 0
 *              @max 99
 *          @default 0
 *      @arg variableId
 *          @text 変数
 *          @desc 返り値を入れる変数
 *          @type variable
 *          @default 0
 *      @arg background
 *          @text 背景
 *          @desc
 *          @type select
 *              @option ウィンドウ
 *              @value 0
 *              @option 暗くする
 *              @value 1
 *              @option 透明
 *              @value 2
 *          @default 0
 *      @arg positionType
 *          @text ウィンドウ位置
 *          @desc
 *          @type select
 *              @option 左
 *              @value 0
 *              @option 中
 *              @value 1
 *              @option 右
 *              @value 2
 *          @default 2
 *      @arg defaultType
 *          @text デフォルト
 *          @desc -1:なし
 *          @type number
 *              @min -1
 *              @max 999
 *          @default 0
 *      @arg cancelType
 *          @text キャンセル
 *          @desc -2:分岐, -1:禁止
 *          @type number
 *              @min -2
 *              @max 999
 *          @default -2
 *
 *  @command deleteCustomChoice
 *      @text 選択肢削除
 *      @desc 配列から指定した選択肢を削除します。
 *      @arg id
 *          @desc 削除する配列のID
 *          @type number
 *              @min 0
 *              @max 99
 *          @default 0
 *      @arg choiceText
 *          @text 選択肢テキスト
 *          @desc
 *          @default
 *
 *  @command clearCustomChoices
 *      @text 選択肢クリア
 *      @desc 選択肢の配列を削除します。
 *      @arg id
 *          @desc 全て削除する配列のID
 *          @type number
 *              @min 0
 *              @max 99
 *          @default
 *
 */

(() => {
  "use strict";

  const pluginName = "MPP_ChoiceEX_Op1";

  //-----------------------------------------------------------------------------
  // Game_System

  const _Game_System_initialize = Game_System.prototype.initialize;
  Game_System.prototype.initialize = function () {
    _Game_System_initialize.apply(this, arguments);
    this._customChoices = [];
  };

  Game_System.prototype.addCustomChoice = function (id, params) {
    if (!this._customChoices[id]) {
      this._customChoices[id] = [];
    }
    this._customChoices[id].push(params);
  };

  Game_System.prototype.deleteCustomChoice = function (id, text) {
    const customChoices = this.getCustomChoices(id);
    if (customChoices) {
      this._customChoices[id] = customChoices.filter(
        (params) => params.text !== text
      );
      if (this._customChoices[id].length === 0) {
        this.clearCustomChoices(id);
      }
    }
  };

  Game_System.prototype.clearCustomChoices = function (id) {
    this._customChoices[id] = null;
  };

  Game_System.prototype.getCustomChoices = function (id) {
    return this._customChoices[id];
  };

  //-------------------------------------------------------------------------
  // Game_Message

  Game_Message.prototype.isTextOnly = function () {
    return (
      this.hasText() &&
      !this.isChoice() &&
      !this.isNumberInput() &&
      !this.isItemChoice()
    );
  };

  //-------------------------------------------------------------------------
  // Game_Interpreter

  const _Game_Interpreter_command101 = Game_Interpreter.prototype.command101;
  Game_Interpreter.prototype.command101 = function (params) {
    const result = _Game_Interpreter_command101.apply(this, arguments);
    if ($gameMessage.isTextOnly()) {
      if (Utils.RPGMAKER_NAME === "MV") {
        const command = this.currentCommand();
        if (command && command.code === 356) {
          const [comName, ...args] = command.parameters[0].split(" ");
          if (["ShowCustomChoices", "選択肢表示"].includes(comName)) {
            this._index++;
            this.pluginCommand(comName, args);
          }
        }
      } else {
        if (this.nextEventCode() === 357) {
          const nextParams = this._list[this._index + 1].parameters;
          if (
            nextParams[0] === pluginName &&
            nextParams[1] === "showCustomChoices"
          ) {
            this._index++;
            PluginManager.callCommand(
              this,
              nextParams[0],
              nextParams[1],
              nextParams[3]
            );
          }
        }
      }
    }
    return result;
  };

  const _mzCommands = {
    AddCustomChoice: {
      name: "addCustomChoice",
      keys: ["id", "choiceText", "returnValue"],
    },
    ShowCustomChoices: {
      name: "showCustomChoices",
      keys: [
        "id",
        "variableId",
        "background",
        "positionType",
        "defaultType",
        "cancelType",
      ],
    },
    DeleteCustomChoice: {
      name: "deleteCustomChoice",
      keys: ["id", "choiceText"],
    },
    ClearCustomChoices: { name: "clearCustomChoices", keys: ["id"] },
  };
  Object.assign(_mzCommands, {
    選択肢追加: _mzCommands.AddCustomChoice,
    選択肢表示: _mzCommands.ShowCustomChoices,
    選択肢削除: _mzCommands.DeleteCustomChoice,
    選択肢クリア: _mzCommands.ClearCustomChoices,
  });

  const _Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
  Game_Interpreter.prototype.pluginCommand = function (command, args) {
    _Game_Interpreter_pluginCommand.apply(this, arguments);
    const mzCommand = _mzCommands[command];
    if (mzCommand) {
      const args2 = Object.assign(
        {},
        ...mzCommand.keys.map((k, i) => ({ [k]: args[i] }))
      );
      PluginManager.callCommandMV(this, pluginName, mzCommand.name, args2);
    }
  };

  //-------------------------------------------------------------------------
  // PluginManager

  if (!PluginManager.registerCommand && !PluginManager._commandsMV) {
    PluginManager._commandsMV = {};

    PluginManager.registerCommandMV = function (pluginName, commandName, func) {
      const key = pluginName + ":" + commandName;
      this._commandsMV[key] = func;
    };

    PluginManager.callCommandMV = function (
      self,
      pluginName,
      commandName,
      args
    ) {
      const key = pluginName + ":" + commandName;
      const func = this._commandsMV[key];
      if (typeof func === "function") {
        func.bind(self)(args);
      }
    };
  }

  const _registerCommandName = PluginManager.registerCommand
    ? "registerCommand"
    : "registerCommandMV";

  PluginManager[_registerCommandName](pluginName, "addCustomChoice", (args) => {
    const id = PluginManager.mppValue(args.id);
    const choiceParams = {
      text: args.choiceText,
      value: PluginManager.mppValue(args.returnValue),
    };
    $gameSystem.addCustomChoice(id, choiceParams);
  });

  PluginManager[_registerCommandName](
    pluginName,
    "showCustomChoices",
    function (args) {
      const id = PluginManager.mppValue(args.id);
      const customChoices = $gameSystem.getCustomChoices(id);
      if (customChoices) {
        const data = {
          choices: [],
          enables: [],
          results: [],
          cancelType: PluginManager.mppValue(args.cancelType || "-2"),
          defaultType: PluginManager.mppValue(args.defaultType || "0"),
        };
        const texts = customChoices.map((params) => params.text);
        this.checkChoiceConditions(texts, data, 0);
        const results = data.results.map((n) => customChoices[n].value);
        const cancelType = this.choiceCancelType(data);
        const defaultType = this.choiceDefaultType(data);
        const positionType = PluginManager.mppValue(args.positionType || "2");
        const background = PluginManager.mppValue(args.background || "0");
        const variableId = PluginManager.mppValue(args.variableId);
        $gameMessage.setChoices(data.choices, defaultType, cancelType);
        $gameMessage.setChoiceEnables(data.enables);
        $gameMessage.setChoiceResults(results);
        $gameMessage.setChoiceBackground(background);
        $gameMessage.setChoicePositionType(positionType);
        $gameMessage.setChoiceCallback((n) =>
          $gameVariables.setValue(variableId, n < 0 ? n : results[n])
        );
        this.setWaitMode("message");
      }
    }
  );

  PluginManager[_registerCommandName](
    pluginName,
    "deleteCustomChoice",
    (args) => {
      const id = PluginManager.mppValue(args.id);
      $gameSystem.deleteCustomChoice(id, args.choiceText);
    }
  );

  PluginManager[_registerCommandName](
    pluginName,
    "clearCustomChoices",
    (args) => {
      const id = PluginManager.mppValue(args.id);
      $gameSystem.clearCustomChoices(id);
    }
  );

  PluginManager.mppValue = function (value) {
    const match = /^V\[(\d+)\]$/i.exec(value);
    return match ? $gameVariables.value(+match[1]) : +value;
  };
})();


code:
/*:
 * NOTE: Images are stored in the img/system folder.
 *
 * @plugindesc Show a Splash Screen "Made with MV" and/or a Custom Splash Screen before going to main screen.
 * @author Dan "Liquidize" Deptula
 *
 * @help This plugin does not provide plugin commands.
 *
 * @param Show Made With MV
 * @desc Enabled/Disables showing the "Made with MV" splash screen.
 * OFF - false     ON - true
 * Default: ON
 * @default true
 *
 * @param Made with MV Image
 * @desc The image to use when showing "Made with MV"
 * Default: MadeWithMv
 * @default MadeWithMv
 * @require 1
 * @dir img/system/
 * @type file
 *
 * @param Show Custom Splash
 * @desc Enabled/Disables showing the "Made with MV" splash screen.
 * OFF - false     ON - true
 * Default: OFF
 * @default false
 *
 * @param Custom Image
 * @desc The image to use when showing "Made with MV"
 * Default:
 * @default
 * @require 1
 * @dir img/system/
 * @type file
 *
 * @param Fade Out Time
 * @desc The time it takes to fade out, in frames.
 * Default: 120
 * @default 120
 *
 * @param Fade In Time
 * @desc The time it takes to fade in, in frames.
 * Default: 120
 * @default 120
 *
 * @param Wait Time
 * @desc The time between fading in and out, in frames.
 * Default: 160
 * @default 160
 *
 */
/*:ja
 * メモ: イメージはimg／systemフォルダ内に保存されます。
 *
 * @plugindesc メイン画面へ進む前に、"Made with MV"のスプラッシュ画面もしくはカスタマイズされたスプラッシュ画面を表示します。
 * @author Dan "Liquidize" Deptula
 *
 * @help  このプラグインにはプラグインコマンドはありません。
 *
 * @param Show Made With MV
 * @desc "Made with MV"のスプラッシュ画面を表示できる/できないようにします。
 * OFF - false     ON - true
 * デフォルト: ON
 * @default true
 *
 * @param Made with MV Image
 * @desc "Made with MV"を表示する際に使用する画像
 * デフォルト: MadeWithMv
 * @default MadeWithMv
 * @require 1
 * @dir img/system/
 * @type file
 *
 * @param Show Custom Splash
 * @desc "Made with MV"のスプラッシュ画面を表示できる/できないようにします。
 * OFF - false     ON - true
 * デフォルト: OFF
 * @default false
 *
 * @param Custom Image
 * @desc "Made with MV"を表示する際に使用する画像
 * デフォルト:
 * @default
 * @require 1
 * @dir img/system/
 * @type file
 *
 * @param Fade Out Time
 * @desc フェードアウトに要する時間（フレーム数）
 * デフォルト: 120
 * @default 120
 *
 * @param Fade In Time
 * @desc フェードインに要する時間（フレーム数）
 * デフォルト: 120
 * @default 120
 *
 * @param Wait Time
 * @desc フェードインからフェードアウトまでに要する時間（フレーム数）
 * デフォルト: 160
 * @default 160
 *
 */
var Liquidize = Liquidize || {};
Liquidize.MadeWithMV = {};
Liquidize.MadeWithMV.Parameters = PluginManager.parameters("MadeWithMv");

Liquidize.MadeWithMV.ShowMV = JSON.parse(
  Liquidize.MadeWithMV.Parameters["Show Made With MV"]
);
Liquidize.MadeWithMV.MVImage = String(
  Liquidize.MadeWithMV.Parameters["Made with MV Image"]
);
Liquidize.MadeWithMV.ShowCustom = JSON.parse(
  Liquidize.MadeWithMV.Parameters["Show Custom Splash"]
);
Liquidize.MadeWithMV.CustomImage = String(
  Liquidize.MadeWithMV.Parameters["Custom Image"]
);
Liquidize.MadeWithMV.FadeOutTime =
  Number(Liquidize.MadeWithMV.Parameters["Fade Out Time"]) || 120;
Liquidize.MadeWithMV.FadeInTime =
  Number(Liquidize.MadeWithMV.Parameters["Fade In Time"]) || 120;
Liquidize.MadeWithMV.WaitTime =
  Number(Liquidize.MadeWithMV.Parameters["Wait Time"]) || 160;

//-----------------------------------------------------------------------------
// Scene_Splash
//
// This is a constructor, implementation is done in the inner scope.

function Scene_Splash() {
  this.initialize.apply(this, arguments);
}

(function () {
  //-----------------------------------------------------------------------------
  // Scene_Boot
  //
  // The scene class for dealing with the game boot.

  var _Scene_Boot_loadSystemImages = Scene_Boot.prototype.loadSystemImages;
  Scene_Boot.prototype.loadSystemImages = function () {
    _Scene_Boot_loadSystemImages.call(this);
    if (Liquidize.MadeWithMV.ShowMV) {
      ImageManager.loadSystem(Liquidize.MadeWithMV.MVImage);
    }
    if (Liquidize.MadeWithMV.ShowCustom) {
      ImageManager.loadSystem(Liquidize.MadeWithMV.CustomImage);
    }
  };

  var _Scene_Boot_start = Scene_Boot.prototype.start;
  Scene_Boot.prototype.start = function () {
    if (
      (Liquidize.MadeWithMV.ShowMV || Liquidize.MadeWithMV.ShowCustom) &&
      !DataManager.isBattleTest() &&
      !DataManager.isEventTest()
    ) {
      SceneManager.goto(Scene_Splash);
    } else {
      _Scene_Boot_start.call(this);
    }
  };

  //-----------------------------------------------------------------------------
  // Scene_Splash
  //
  // The scene class for dealing with the splash screens.

  Scene_Splash.prototype = Object.create(Scene_Base.prototype);
  Scene_Splash.prototype.constructor = Scene_Splash;

  Scene_Splash.prototype.initialize = function () {
    Scene_Base.prototype.initialize.call(this);
    this._mvSplash = null;
    this._customSplash = null;
    this._mvWaitTime = Liquidize.MadeWithMV.WaitTime;
    this._customWaitTime = Liquidize.MadeWithMV.WaitTime;
    this._mvFadeOut = false;
    this._mvFadeIn = false;
    this._customFadeOut = false;
    this._customFadeIn = false;
  };

  Scene_Splash.prototype.create = function () {
    Scene_Base.prototype.create.call(this);
    this.createSplashes();
  };

  Scene_Splash.prototype.start = function () {
    Scene_Base.prototype.start.call(this);
    SceneManager.clearStack();
    if (this._mvSplash != null) {
      this.centerSprite(this._mvSplash);
    }
    if (this._customSplash != null) {
      this.centerSprite(this._customSplash);
    }
  };

  Scene_Splash.prototype.update = function () {
    if (Liquidize.MadeWithMV.ShowMV) {
      if (!this._mvFadeIn) {
        this.startFadeIn(Liquidize.MadeWithMV.FadeInTime, false);
        this._mvFadeIn = true;
      } else {
        if (this._mvWaitTime > 0 && this._mvFadeOut == false) {
          this._mvWaitTime--;
        } else {
          if (this._mvFadeOut == false) {
            this._mvFadeOut = true;
            this.startFadeOut(Liquidize.MadeWithMV.FadeOutTime, false);
          }
        }
      }
    }

    if (Liquidize.MadeWithMV.ShowCustom) {
      if (Liquidize.MadeWithMV.ShowMV && this._mvFadeOut == true) {
        if (!this._customFadeIn && this._fadeDuration == 0) {
          this._customSplash.opacity = 255;
          this._customWaitTime = Liquidize.MadeWithMV.WaitTime;
          this.startFadeIn(Liquidize.MadeWithMV.FadeInTime, false);
          this._customFadeIn = true;
        } else {
          if (this._customWaitTime > 0 && this._customFadeOut == false) {
            this._customWaitTime--;
          } else {
            if (this._customFadeOut == false) {
              this._customFadeOut = true;
              this.startFadeOut(Liquidize.MadeWithMV.FadeOutTime, false);
            }
          }
        }
      } else if (!Liquidize.MadeWithMV.ShowMV) {
        if (!this._customFadeIn) {
          this._customSplash.opacity = 255;
          this.startFadeIn(Liquidize.MadeWithMV.FadeInTime, false);
          this._customFadeIn = true;
        } else {
          if (this._customWaitTime > 0 && this._customFadeOut == false) {
            this._customWaitTime--;
          } else {
            if (this._customFadeOut == false) {
              this._customFadeOut = true;
              this.startFadeOut(Liquidize.MadeWithMV.FadeOutTime, false);
            }
          }
        }
      }
    }

    if (Liquidize.MadeWithMV.ShowCustom) {
      if (
        Liquidize.MadeWithMV.ShowMV &&
        this._mvFadeOut == true &&
        this._customFadeOut == true
      ) {
        this.gotoTitleOrTest();
      } else if (!Liquidize.MadeWithMV.ShowMV && this._customFadeOut == true) {
        this.gotoTitleOrTest();
      }
    } else {
      if (this._mvFadeOut == true) {
        this.gotoTitleOrTest();
      }
    }

    Scene_Base.prototype.update.call(this);
  };

  Scene_Splash.prototype.createSplashes = function () {
    if (Liquidize.MadeWithMV.ShowMV) {
      this._mvSplash = new Sprite(
        ImageManager.loadSystem(Liquidize.MadeWithMV.MVImage)
      );
      this.addChild(this._mvSplash);
    }
    if (Liquidize.MadeWithMV.ShowCustom) {
      this._customSplash = new Sprite(
        ImageManager.loadSystem(Liquidize.MadeWithMV.CustomImage)
      );
      this._customSplash.opacity = 0;
      this.addChild(this._customSplash);
    }
  };

  Scene_Splash.prototype.centerSprite = function (sprite) {
    sprite.x = Graphics.width / 2;
    sprite.y = Graphics.height / 2;
    sprite.anchor.x = 0.5;
    sprite.anchor.y = 0.5;
  };

  Scene_Splash.prototype.gotoTitleOrTest = function () {
    Scene_Base.prototype.start.call(this);
    SoundManager.preloadImportantSounds();
    if (DataManager.isBattleTest()) {
      DataManager.setupBattleTest();
      SceneManager.goto(Scene_Battle);
    } else if (DataManager.isEventTest()) {
      DataManager.setupEventTest();
      SceneManager.goto(Scene_Map);
    } else {
      this.checkPlayerLocation();
      DataManager.setupNewGame();
      SceneManager.goto(Scene_Title);
      Window_TitleCommand.initCommandPosition();
    }
    this.updateDocumentTitle();
  };

  Scene_Splash.prototype.updateDocumentTitle = function () {
    document.title = $dataSystem.gameTitle;
  };

  Scene_Splash.prototype.checkPlayerLocation = function () {
    if ($dataSystem.startMapId === 0) {
      throw new Error("Player's starting position is not set");
    }
  };
})();