code:
//=============================================================================
// Yanfly Engine Plugins - Message Core
// YEP_MessageCore.js
//=============================================================================

var Imported = Imported || {};
Imported.YEP_MessageCore = true;

var Yanfly = Yanfly || {};
Yanfly.Message = Yanfly.Message || {};
Yanfly.Message.version = 1.19;

//=============================================================================
/*:
 * @plugindesc v1.19 Adds more features to the Message Window to customized
 * the way your messages appear and functions.
 * @author Yanfly Engine Plugins
 *
 * @param ---General---
 * @default
 *
 * @param Default Rows
 * @parent ---General---
 * @type number
 * @min 0
 * @desc This is default amount of rows the message box will have.
 * Default: 4
 * @default 4
 *
 * @param Default Width
 * @parent ---General---
 * @desc This is default width for the message box in pixels.
 * Default: Graphics.boxWidth
 * @default Graphics.boxWidth
 *
 * @param Face Indent
 * @parent ---General---
 * @desc If using a face graphic, this is how much text indents by.
 * Default: Window_Base._faceWidth + 24
 * @default Window_Base._faceWidth + 24
 *
 * @param Fast Forward Key
 * @parent ---General---
 * @desc This is the key used for fast forwarding.
 * @default pagedown
 *
 * @param Enable Fast Forward
 * @parent ---General---
 * @type boolean
 * @on YES
 * @off NO
 * @desc Enable fast forward button for your messages by default?
 * NO - false     YES - true
 * @default true
 *
 * @param Word Wrapping
 * @parent ---General---
 * @type boolean
 * @on YES
 * @off NO
 * @desc Use this to enable or disable word wrapping by default.
 * OFF - false     ON - true
 * @default false
 *
 * @param Description Wrap
 * @parent ---General---
 * @type boolean
 * @on YES
 * @off NO
 * @desc Enable or disable word wrapping for descriptions.
 * OFF - false     ON - true
 * @default false
 *
 * @param Word Wrap Space
 * @parent ---General---
 * @type boolean
 * @on YES
 * @off NO
 * @desc Insert a space with manual line breaks?
 * NO - false     YES - true
 * @default false
 *
 * @param Tight Wrap
 * @parent ---General---
 * @type boolean
 * @on YES
 * @off NO
 * @desc If true and using a face for the message, the message will
 * wrap tighter. NO - false     YES - true
 * @default false
 *
 * @param ---Font---
 * @default
 *
 * @param Font Name
 * @parent ---Font---
 * @desc This is the default font used for the Message Window.
 * Default: GameFont
 * @default GameFont
 *
 * @param Font Name CH
 * @parent ---Font---
 * @desc This is the default font used for the Message Window for Chinese.
 * Default: SimHei, Heiti TC, sans-serif
 * @default SimHei, Heiti TC, sans-serif
 *
 * @param Font Name KR
 * @parent ---Font---
 * @desc This is the default font used for the Message Window for Korean.
 * Default: Dotum, AppleGothic, sans-serif
 * @default Dotum, AppleGothic, sans-serif
 *
 * @param Font Size
 * @parent ---Font---
 * @type number
 * @min 1
 * @desc This is the default font size used for the Message Window.
 * Default: 28
 * @default 28
 *
 * @param Font Size Change
 * @parent ---Font---
 * @type number
 * @min 1
 * @desc Whenever \{ and \} are used, they adjust by this value.
 * Default: 12
 * @default 12
 *
 * @param Font Changed Max
 * @parent ---Font---
 * @type number
 * @min 1
 * @desc This is the maximum size achieved by \{.
 * Default: 96
 * @default 96
 *
 * @param Font Changed Min
 * @parent ---Font---
 * @type number
 * @min 1
 * @desc This is the minimum size achieved by \{.
 * Default: 12
 * @default 12
 *
 * @param Font Outline
 * @parent ---Font---
 * @type number
 * @min 0
 * @desc This is the default font outline width for messages.
 * Default: 4
 * @default 4
 *
 * @param Maintain Font
 * @parent ---Font---
 * @type boolean
 * @on YES
 * @off NO
 * @desc When changing the font name or size, maintain for following
 * messages. NO - false     YES - true
 * @default false
 *
 * @param ---Name Box---
 * @default
 *
 * @param Name Box Buffer X
 * @parent ---Name Box---
 * @type number
 * @desc This is the buffer for the x location of the Name Box.
 * @default -28
 *
 * @param Name Box Buffer Y
 * @parent ---Name Box---
 * @type number
 * @desc This is the buffer for the y location of the Name Box.
 * @default 0
 *
 * @param Name Box Padding
 * @parent ---Name Box---
 * @desc This is the value for the padding of the Name Box.
 * @default this.standardPadding() * 4
 *
 * @param Name Box Color
 * @parent ---Name Box---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color used for the Name Box.
 * @default 0
 *
 * @param Name Box Clear
 * @parent ---Name Box---
 * @type boolean
 * @on YES
 * @off NO
 * @desc Do you wish for the Name Box window to be clear?
 * NO - false     YES - true
 * @default false
 *
 * @param Name Box Added Text
 * @parent ---Name Box---
 * @desc This text is always added whenever the name box is used.
 * This can be used to automatically set up colors.
 * @default \c[6]
 *
 * @param Name Box Auto Close
 * @parent ---Name Box---
 * @type boolean
 * @on YES
 * @off NO
 * @desc Close the message window each time the namebox displays a
 * different name? YES - true     NO - false
 * @default false
 *
 * @help
 * ============================================================================
 * Introduction
 * ============================================================================
 *
 * While RPG Maker MV Ace certainly improved the message system a whole lot, it
 * wouldn't hurt to add in a few more features, such as name windows,
 * converting textcodes to write out the icons and/or names of items, weapons,
 * armours, and* more in quicker fashion. This script also gives the developer
 * the ability to adjust the size of the message window during the game, give
 * it a separate font, and to give the player a text fast-forward feature.
 *
 * ============================================================================
 * Word Wrapping
 * ============================================================================
 *
 * Word wrapping is now possible through the message system. You can enable and
 * disable Word wrap using Plugin Commands. While using word wrap, if the word
 * is to extend past the message window's area, it will automatically go to the
 * following line. That said, word wrap will disable the editor's line breaks
 * and will require you to use the ones provided by the plugin:
 *
 *
 or <line break> is text code to apply a line break. Use this before or
 * after a part in which you wish to start a new line.
 *
 * Keep in mind word wrapping is mostly for message windows. However, in other
 * places that you'd like to see word wrapping, such as item descriptions,
 * insert <WordWrap> at the beginning of the text to enable it.
 *
 * ============================================================================
 * Text Codes
 * ============================================================================
 *
 * By using certain text codes in your messages, you can have the game replace
 * them with the following:
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 * Text Code   Function
 *   \V[n]       Replaced by the value of the nth variable.
 *   \N[n]       Replaced by the name of the nth actor.
 *   \P[n]       Replaced by the name of the nth party member.
 *   \G          Replaced by the currency unit.
 *   \C[n]       Draw the subsequent text in the nth color.
 *   \I[n]       Draw the nth icon.
 *   \{          Increases the text size by one step.
 *   \}          Decreases the text size by one step.
 *   \\          Replaced with the backslash character.
 *   \$          Opens the gold window.
 *   \.          Waits 1/4th seconds.
 *   \|          Waits 1 second.
 *   \!          Waits for button input.
 *   \>          Display remaining text on same line all at once.
 *   \<          Cancel the effect that displays text all at once.
 *   \^          Do not wait for input after displaying text.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 *  Wait:       Effect:
 *    \w[x]     - Waits x frames (60 frames = 1 second). Message window only.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 *  NameWindow: Effect:
 *    \n<x>     - Creates a name box with x string. Left side. *Note
 *    \nc<x>    - Creates a name box with x string. Centered. *Note
 *    \nr<x>    - Creates a name box with x string. Right side. *Note
 *
 *              *Note: Works for message window only.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 *  Line Break  Effect:
 *
      - If using word wrap mode, this will cause a line break.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 *  Position:   Effect:
 *    \px[x]    - Sets x position of text to x.
 *    \py[x]    - Sets y position of text to y.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 *  Outline:    Effect:
 *   \oc[x]    - Sets outline colour to x.
 *   \ow[x]    - Sets outline width to x.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 *  Font:       Effect:
 *    \fr       - Resets all font changes.
 *    \fs[x]    - Changes font size to x.
 *    \fn<x>    - Changes font name to x.
 *    \fb       - Toggles font boldness.
 *    \fi       - Toggles font italic.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 *  Actor:      Effect:
 *    \af[x]    - Shows face of actor x. *Note
 *    \ac[x]    - Writes out actor's class name.
 *    \an[x]    - Writes out actor's nickname.
 *
 *              *Note: Works for message window only.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 *  Party:      Effect:
 *    \pf[x]    - Shows face of party member x. *Note
 *    \pc[x]    - Writes out party member x's class name.
 *    \pn[x]    - Writes out party member x's nickname.
 *
 *              *Note: Works for message window only.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 *  Names:      Effect:
 *    \nc[x]    - Writes out class x's name.
 *    \ni[x]    - Writes out item x's name.
 *    \nw[x]    - Writes out weapon x's name.
 *    \na[x]    - Writes out armour x's name.
 *    \ns[x]    - Writes out skill x's name.
 *    \nt[x]    - Writes out state x's name.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 *  Icon Names: Effect:
 *    \ii[x]    - Writes out item x's name including icon.
 *    \iw[x]    - Writes out weapon x's name including icon.
 *    \ia[x]    - Writes out armour x's name including icon.
 *    \is[x]    - Writes out skill x's name including icon.
 *    \it[x]    - Writes out state x's name including icon.
 *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 *
 * And those are the text codes added with this script. Keep in mind that some
 * of these text codes only work for the Message Window. Otherwise, they'll
 * work for help descriptions, actor biographies, and others.
 *
 * ============================================================================
 * Plugin Commands
 * ============================================================================
 *
 * The following are some plugin commands you can use through the Event Editor
 * to change various aspects about the Message system.
 *
 * Plugin Comand
 *   MessageRows 6
 *   - Changes the Message Rows displayed to 6. If you are using continuous
 *   Show Text events, this will continue displaying the following lines's
 *   texts until it hits the row limit. Anything after that is cut off until
 *   the next message starts to avoid accidental overlap.
 *
 *   MessageWidth 400
 *   - Changes the Message Window Width to 400 pixels. This will cut off any
 *   words that are shown too far to the right so adjust accordingly!
 *
 *   EnableWordWrap
 *   - Enables wordwrapping. If a word extends past the window size, it will
 *   automatically move onto the next line. Keep in mind, you will need to use
 *   \br to perform line breaks.
 *
 *   DisableWordWrap
 *   - This disables wordwrapping. Line breaks will be automatic at points
 *   where a new line is started in the editor.
 *
 *   EnableFastForward
 *   - Enables Fast Forward key from working with messages.
 *
 *   DisableFastForward
 *   - Disables Fast Forward key from working with messages.
 *
 * ============================================================================
 * Changelog
 * ============================================================================
 *
 * Version 1.19:
 * - Updated for RPG Maker MV version 1.5.0.
 *
 * Version 1.18:
 * - Added new plugin parameters: 'Font Name CH' and 'Font Name KR'.
 *
 * Version 1.17:
 * - Compatibility update with Message Macros for 'Name Box Auto Close' option.
 *
 * Version 1.16:
 * - Added 'Tight Wrap' plugin parameter as a word wrap option to make the
 * word wrap tighter when using faces.
 *
 * Version 1.15:
 * - Added a failsafe where if the name box window would be off the screen, it
 * will automatically reposition itself to under the main message window.
 *
 * Version 1.14:
 * - Added 'Name Box Close' plugin parameter. If this is enabled, the message
 * window will check for the Name Window speaker each time a follow up message
 * occurs. If the name in the currently Name Window matches the name in the
 * following Name Window, the message window will remain open. If it doesn't,
 * the Name Window will close and reopen to indicate a new speaker.
 *
 * Version 1.13:
 * - Added 'Maintain Font' plugin parameter under the Font category. This will
 * allow you to use text codes \fn<x> and \fs[x] to permanently change the font
 * of your messages until you use it again. \fr will reset them to the plugin's
 * default parameter settings.
 *
 * Version 1.12:
 * - 'Word Wrap Space' parameter no longer leaves a space at the beginning of
 * each message.
 *
 * Version 1.11:
 * - Added 'Font Outline' parameter for the plugin parameters. This adjusts the
 * font outline width used by default for only message fonts.
 *
 * Version 1.10:
 * - Updated the Message Row system for Extended Message Pack 1's Autosizing
 * feature to work with extended heights.
 *
 * Version 1.09:
 * - Replaced 'Fast Forward' parameter with the 'Fast Forward Key' parameter
 * and 'Enable Fast Forward' parameter. Two new Plugin Commands are added. They
 * are 'EnableFastForward' and 'DisableFastForward' for control over when fast
 * forwarding is allowed as to not cause timed cutscenes to desynch.
 *
 * Version 1.08:
 * - Fixed a bug regarding Input Number positioning when the Message Window's
 * position was middle.
 *
 * Version 1.07:
 * - Added 'Word Wrap Space' for word wrap users. This parameter will leave a
 * space behind for those who want a space left behind.
 *
 * Version 1.06:
 * - Fixed a bug that would cause masking problems with mobile devices.
 *
 * Version 1.05:
 * - Fixed a bug that would cause the namebox window to appear distorted.
 *
 * Version 1.04:
 * - Fixed a bug that captured too many text codes with the namebox window.
 * - Timed Name Window's closing speed with main window's closing speed.
 *
 * Verison 1.03:
 * - Fixed a bug with textcodes that messed up wordwrapping.
 * - Fixed a bug with font reset, italic, and bold textcodes.
 *
 * Version 1.02:
 * - Namebox Window's overlap feature that's in every MV window is now disabled
 * to allow for overlapping with main message window.
 * - Updated window positioning for Branch Choices, Number Input, and Item
 * Selection windows.
 *
 * Version 1.01:
 * - Added 'Description Wrap' into the parameters to allow for all item
 * descriptions to be automatically processed with word wrapping.
 *
 * Version 1.00:
 * - Finished plugin!
 */
//=============================================================================

//=============================================================================
// Parameter Variables
//=============================================================================

Yanfly.Parameters = PluginManager.parameters("YEP_MessageCore");
Yanfly.Param = Yanfly.Param || {};

Yanfly.Param.MSGDefaultRows = String(Yanfly.Parameters["Default Rows"]);
Yanfly.Param.MSGDefaultWidth = String(Yanfly.Parameters["Default Width"]);
Yanfly.Param.MSGFaceIndent = String(Yanfly.Parameters["Face Indent"]);
Yanfly.Param.MSGFastForwardKey = String(Yanfly.Parameters["Fast Forward Key"]);
Yanfly.Param.MSGFFOn = eval(String(Yanfly.Parameters["Enable Fast Forward"]));
Yanfly.Param.MSGWordWrap = String(Yanfly.Parameters["Word Wrapping"]);
Yanfly.Param.MSGWordWrap = eval(Yanfly.Param.MSGWordWrap);
Yanfly.Param.MSGDescWrap = String(Yanfly.Parameters["Description Wrap"]);
Yanfly.Param.MSGWrapSpace = eval(String(Yanfly.Parameters["Word Wrap Space"]));
Yanfly.Param.MSGTightWrap = eval(String(Yanfly.Parameters["Tight Wrap"]));

Yanfly.Param.MSGFontName = String(Yanfly.Parameters["Font Name"]);
Yanfly.Param.MSGCNFontName = String(Yanfly.Parameters["Font Name CH"]);
Yanfly.Param.MSGKRFontName = String(Yanfly.Parameters["Font Name KR"]);
Yanfly.Param.MSGFontSize = Number(Yanfly.Parameters["Font Size"]);
Yanfly.Param.MSGFontSizeChange = String(Yanfly.Parameters["Font Size Change"]);
Yanfly.Param.MSGFontChangeMax = String(Yanfly.Parameters["Font Changed Max"]);
Yanfly.Param.MSGFontChangeMin = String(Yanfly.Parameters["Font Changed Min"]);
Yanfly.Param.MSGFontOutline = Number(Yanfly.Parameters["Font Outline"]) || 4;
Yanfly.Param.MSGFontMaintain = eval(String(Yanfly.Parameters["Maintain Font"]));

Yanfly.Param.MSGNameBoxBufferX = String(Yanfly.Parameters["Name Box Buffer X"]);
Yanfly.Param.MSGNameBoxBufferY = String(Yanfly.Parameters["Name Box Buffer Y"]);
Yanfly.Param.MSGNameBoxPadding = String(Yanfly.Parameters["Name Box Padding"]);
Yanfly.Param.MSGNameBoxColor = Number(Yanfly.Parameters["Name Box Color"]);
Yanfly.Param.MSGNameBoxClear = String(Yanfly.Parameters["Name Box Clear"]);
Yanfly.Param.MSGNameBoxText = String(Yanfly.Parameters["Name Box Added Text"]);
Yanfly.Param.MSGNameBoxClose = String(Yanfly.Parameters["Name Box Auto Close"]);
Yanfly.Param.MSGNameBoxClose = eval(Yanfly.Param.MSGNameBoxClose);

//=============================================================================
// Bitmap
//=============================================================================

Yanfly.Message.Bitmap_initialize = Bitmap.prototype.initialize;
Bitmap.prototype.initialize = function (width, height) {
  Yanfly.Message.Bitmap_initialize.call(this, width, height);
  this.fontBold = false;
};

Yanfly.Message.Bitmap_makeFontNameText = Bitmap.prototype._makeFontNameText;
Bitmap.prototype._makeFontNameText = function () {
  if (this.fontBold) return "Bold " + this.fontSize + "px " + this.fontFace;
  return Yanfly.Message.Bitmap_makeFontNameText.call(this);
};

//=============================================================================
// Game_System
//=============================================================================

Yanfly.Message.Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function () {
  Yanfly.Message.Game_System_initialize.call(this);
  this.initMessageSystem();
  this.initMessageFontSettings();
};

Game_System.prototype.initMessageSystem = function () {
  this._wordWrap = Yanfly.Param.MSGWordWrap;
  this._fastForward = Yanfly.Param.MSGFFOn;
};

Game_System.prototype.initMessageFontSettings = function () {
  if ($dataSystem.locale.match(/^zh/)) {
    this._msgFontName = Yanfly.Param.MSGCNFontName;
  } else if ($dataSystem.locale.match(/^ko/)) {
    this._msgFontName = Yanfly.Param.MSGKRFontName;
  } else {
    this._msgFontName = Yanfly.Param.MSGFontName;
  }
  this._msgFontSize = Yanfly.Param.MSGFontSize;
  this._msgFontOutline = Yanfly.Param.MSGFontOutline;
};

Game_System.prototype.messageRows = function () {
  var rows = eval(this._messageRows) || eval(Yanfly.Param.MSGDefaultRows);
  return Math.max(1, Number(rows));
};

Game_System.prototype.messageWidth = function () {
  return eval(this._messageWidth) || eval(Yanfly.Param.MSGDefaultWidth);
};

Game_System.prototype.wordWrap = function () {
  if (this._wordWrap === undefined) this.initMessageSystem();
  return this._wordWrap;
};

Game_System.prototype.setWordWrap = function (state) {
  if (this._wordWrap === undefined) this.initMessageSystem();
  this._wordWrap = state;
};

Game_System.prototype.isFastFowardEnabled = function () {
  if (this._fastForward === undefined) this.initMessageSystem();
  return this._fastForward;
};

Game_System.prototype.setFastFoward = function (state) {
  if (this._fastForward === undefined) this.initMessageSystem();
  this._fastForward = state;
};

Game_System.prototype.getMessageFontName = function () {
  if (this._msgFontName === undefined) this.initMessageFontSettings();
  return this._msgFontName;
};

Game_System.prototype.setMessageFontName = function (value) {
  if (this._msgFontName === undefined) this.initMessageFontSettings();
  this._msgFontName = value;
};

Game_System.prototype.getMessageFontSize = function () {
  if (this._msgFontSize === undefined) this.initMessageFontSettings();
  return this._msgFontSize;
};

Game_System.prototype.setMessageFontSize = function (value) {
  if (this._msgFontSize === undefined) this.initMessageFontSettings();
  this._msgFontSize = value;
};

Game_System.prototype.getMessageFontOutline = function () {
  if (this._msgFontOutline === undefined) this.initMessageFontSettings();
  return this._msgFontOutline;
};

Game_System.prototype.setMessageFontOutline = function (value) {
  if (this._msgFontOutline === undefined) this.initMessageFontSettings();
  this._msgFontOutline = value;
};

//=============================================================================
// Game_Message
//=============================================================================

Game_Message.prototype.addText = function (text) {
  if ($gameSystem.wordWrap()) text = "<WordWrap>" + text;
  this.add(text);
};

//=============================================================================
// Game_Interpreter
//=============================================================================

Yanfly.Message.Game_Interpreter_pluginCommand =
  Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
  Yanfly.Message.Game_Interpreter_pluginCommand.call(this, command, args);
  if (command === "MessageRows") $gameSystem._messageRows = args[0];
  if (command === "MessageWidth") $gameSystem._messageWidth = args[0];
  if (command === "EnableWordWrap") $gameSystem.setWordWrap(true);
  if (command === "DisableWordWrap") $gameSystem.setWordWrap(false);
  if (command === "EnableFastForward") $gameSystem.setFastFoward(true);
  if (command === "DisableFastForward") $gameSystem.setFastFoward(false);
};

Game_Interpreter.prototype.command101 = function () {
  if (!$gameMessage.isBusy()) {
    $gameMessage.setFaceImage(this._params[0], this._params[1]);
    $gameMessage.setBackground(this._params[2]);
    $gameMessage.setPositionType(this._params[3]);
    while (this.isContinueMessageString()) {
      this._index++;
      if (this._list[this._index].code === 401) {
        $gameMessage.addText(this.currentCommand().parameters[0]);
      }
      if ($gameMessage._texts.length >= $gameSystem.messageRows()) break;
    }
    switch (this.nextEventCode()) {
      case 102:
        this._index++;
        this.setupChoices(this.currentCommand().parameters);
        break;
      case 103:
        this._index++;
        this.setupNumInput(this.currentCommand().parameters);
        break;
      case 104:
        this._index++;
        this.setupItemChoice(this.currentCommand().parameters);
        break;
    }
    this._index++;
    this.setWaitMode("message");
  }
  return false;
};

Game_Interpreter.prototype.isContinueMessageString = function () {
  if (this.nextEventCode() === 101 && $gameSystem.messageRows() > 4) {
    return true;
  } else {
    return this.nextEventCode() === 401;
  }
};

//=============================================================================
// Window_Base
//=============================================================================

Yanfly.Message.Window_Base_resetFontSettings =
  Window_Base.prototype.resetFontSettings;
Window_Base.prototype.resetFontSettings = function () {
  Yanfly.Message.Window_Base_resetFontSettings.call(this);
  this.contents.fontBold = false;
  this.contents.fontItalic = false;
  this.contents.outlineColor = "rgba(0, 0, 0, 0.5)";
  this.contents.outlineWidth = $gameSystem.getMessageFontOutline();
};

Window_Base.prototype.textWidthEx = function (text) {
  return this.drawTextEx(text, 0, this.contents.height + this.lineHeight());
};

Yanfly.Message.Window_Base_convertEscapeCharacters =
  Window_Base.prototype.convertEscapeCharacters;
Window_Base.prototype.convertEscapeCharacters = function (text) {
  text = this.setWordWrap(text);
  text = Yanfly.Message.Window_Base_convertEscapeCharacters.call(this, text);
  text = this.convertExtraEscapeCharacters(text);
  return text;
};

Window_Base.prototype.setWordWrap = function (text) {
  this._wordWrap = false;
  if (text.match(/<(?:WordWrap)>/i)) {
    this._wordWrap = true;
    text = text.replace(/<(?:WordWrap)>/gi, "");
  }
  if (this._wordWrap) {
    var replace = Yanfly.Param.MSGWrapSpace ? " " : "";
    text = text.replace(/[\n\r]+/g, replace);
  }
  if (this._wordWrap) {
    text = text.replace(/<(?:BR|line break)>/gi, "\n");
  } else {
    text = text.replace(/<(?:BR|line break)>/gi, "");
  }
  return text;
};

Window_Base.prototype.convertExtraEscapeCharacters = function (text) {
  // Font Codes
  text = text.replace(/\x1bFR/gi, "\x1bMSGCORE[0]");
  text = text.replace(/\x1bFB/gi, "\x1bMSGCORE[1]");
  text = text.replace(/\x1bFI/gi, "\x1bMSGCORE[2]");
  // \AC[n]
  text = text.replace(
    /\x1bAC\[(\d+)\]/gi,
    function () {
      return this.actorClassName(parseInt(arguments[1]));
    }.bind(this)
  );
  // \AN[n]
  text = text.replace(
    /\x1bAN\[(\d+)\]/gi,
    function () {
      return this.actorNickname(parseInt(arguments[1]));
    }.bind(this)
  );
  // \PC[n]
  text = text.replace(
    /\x1bPC\[(\d+)\]/gi,
    function () {
      return this.partyClassName(parseInt(arguments[1]));
    }.bind(this)
  );
  // \PN[n]
  text = text.replace(
    /\x1bPN\[(\d+)\]/gi,
    function () {
      return this.partyNickname(parseInt(arguments[1]));
    }.bind(this)
  );
  // \NC[n]
  text = text.replace(
    /\x1bNC\[(\d+)\]/gi,
    function () {
      return $dataClasses[parseInt(arguments[1])].name;
    }.bind(this)
  );
  // \NI[n]
  text = text.replace(
    /\x1bNI\[(\d+)\]/gi,
    function () {
      return $dataItems[parseInt(arguments[1])].name;
    }.bind(this)
  );
  // \NW[n]
  text = text.replace(
    /\x1bNW\[(\d+)\]/gi,
    function () {
      return $dataWeapons[parseInt(arguments[1])].name;
    }.bind(this)
  );
  // \NA[n]
  text = text.replace(
    /\x1bNA\[(\d+)\]/gi,
    function () {
      return $dataArmors[parseInt(arguments[1])].name;
    }.bind(this)
  );
  // \NE[n]
  text = text.replace(
    /\x1bNE\[(\d+)\]/gi,
    function () {
      return $dataEnemies[parseInt(arguments[1])].name;
    }.bind(this)
  );
  // \NS[n]
  text = text.replace(
    /\x1bNS\[(\d+)\]/gi,
    function () {
      return $dataSkills[parseInt(arguments[1])].name;
    }.bind(this)
  );
  // \NT[n]
  text = text.replace(
    /\x1bNT\[(\d+)\]/gi,
    function () {
      return $dataStates[parseInt(arguments[1])].name;
    }.bind(this)
  );
  // \II[n]
  text = text.replace(
    /\x1bII\[(\d+)\]/gi,
    function () {
      return this.escapeIconItem(arguments[1], $dataItems);
    }.bind(this)
  );
  // \IW[n]
  text = text.replace(
    /\x1bIW\[(\d+)\]/gi,
    function () {
      return this.escapeIconItem(arguments[1], $dataWeapons);
    }.bind(this)
  );
  // \IA[n]
  text = text.replace(
    /\x1bIA\[(\d+)\]/gi,
    function () {
      return this.escapeIconItem(arguments[1], $dataArmors);
    }.bind(this)
  );
  // \IS[n]
  text = text.replace(
    /\x1bIS\[(\d+)\]/gi,
    function () {
      return this.escapeIconItem(arguments[1], $dataSkills);
    }.bind(this)
  );
  // \IT[n]
  text = text.replace(
    /\x1bIT\[(\d+)\]/gi,
    function () {
      return this.escapeIconItem(arguments[1], $dataStates);
    }.bind(this)
  );
  // Finish
  return text;
};

Window_Base.prototype.actorClassName = function (n) {
  var actor = n >= 1 ? $gameActors.actor(n) : null;
  return actor ? actor.currentClass().name : "";
};

Window_Base.prototype.actorNickname = function (n) {
  var actor = n >= 1 ? $gameActors.actor(n) : null;
  return actor ? actor.nickname() : "";
};

Window_Base.prototype.partyClassName = function (n) {
  var actor = n >= 1 ? $gameParty.members()[n - 1] : null;
  return actor ? actor.currentClass().name : "";
};

Window_Base.prototype.partyNickname = function (n) {
  var actor = n >= 1 ? $gameParty.members()[n - 1] : null;
  return actor ? actor.nickname() : "";
};

Window_Base.prototype.escapeIconItem = function (n, database) {
  return "\x1bI[" + database[n].iconIndex + "]" + database[n].name;
};

Window_Base.prototype.obtainEscapeString = function (textState) {
  var arr = /^\<(.*?)\>/.exec(textState.text.slice(textState.index));
  if (arr) {
    textState.index += arr[0].length;
    return String(arr[0].slice(1, arr[0].length - 1));
  } else {
    return "";
  }
};

Yanfly.Message.Window_Base_processEscapeCharacter =
  Window_Base.prototype.processEscapeCharacter;
Window_Base.prototype.processEscapeCharacter = function (code, textState) {
  switch (code) {
    case "MSGCORE":
      var id = this.obtainEscapeParam(textState);
      if (id === 0) {
        $gameSystem.initMessageFontSettings();
        this.resetFontSettings();
      }
      if (id === 1) this.contents.fontBold = !this.contents.fontBold;
      if (id === 2) this.contents.fontItalic = !this.contents.fontItalic;
      break;
    case "FS":
      var size = this.obtainEscapeParam(textState);
      this.contents.fontSize = size;
      if (Yanfly.Param.MSGFontMaintain) $gameSystem.setMessageFontSize(size);
      break;
    case "FN":
      var name = this.obtainEscapeString(textState);
      this.contents.fontFace = name;
      if (Yanfly.Param.MSGFontMaintain) $gameSystem.setMessageFontName(name);
      break;
    case "OC":
      var id = this.obtainEscapeParam(textState);
      this.contents.outlineColor = this.textColor(id);
      break;
    case "OW":
      this.contents.outlineWidth = this.obtainEscapeParam(textState);
      break;
    case "PX":
      textState.x = this.obtainEscapeParam(textState);
      break;
    case "PY":
      textState.y = this.obtainEscapeParam(textState);
      break;
    default:
      Yanfly.Message.Window_Base_processEscapeCharacter.call(
        this,
        code,
        textState
      );
      break;
  }
};

Window_Base.prototype.makeFontBigger = function () {
  var size = this.contents.fontSize + eval(Yanfly.Param.MSGFontSizeChange);
  this.contents.fontSize = Math.min(size, Yanfly.Param.MSGFontChangeMax);
};

Window_Base.prototype.makeFontSmaller = function () {
  var size = this.contents.fontSize - eval(Yanfly.Param.MSGFontSizeChange);
  this.contents.fontSize = Math.max(size, Yanfly.Param.MSGFontChangeMin);
};

Yanfly.Message.Window_Base_processNormalCharacter =
  Window_Base.prototype.processNormalCharacter;
Window_Base.prototype.processNormalCharacter = function (textState) {
  if (this.checkWordWrap(textState)) return this.processNewLine(textState);
  Yanfly.Message.Window_Base_processNormalCharacter.call(this, textState);
};

Window_Base.prototype.checkWordWrap = function (textState) {
  if (!textState) return false;
  if (!this._wordWrap) return false;
  if (textState.text[textState.index] === " ") {
    var nextSpace = textState.text.indexOf(" ", textState.index + 1);
    var nextBreak = textState.text.indexOf("\n", textState.index + 1);
    if (nextSpace < 0) nextSpace = textState.text.length + 1;
    if (nextBreak > 0) nextSpace = Math.min(nextSpace, nextBreak);
    var word = textState.text.substring(textState.index, nextSpace);
    var size = this.textWidthExCheck(word);
  }
  return size + textState.x > this.wordwrapWidth();
};

Window_Base.prototype.wordwrapWidth = function () {
  return this.contents.width;
};

Window_Base.prototype.saveCurrentWindowSettings = function () {
  this._saveFontFace = this.contents.fontFace;
  this._saveFontSize = this.contents.fontSize;
  this._savetextColor = this.contents.textColor;
  this._saveFontBold = this.contents.fontBold;
  this._saveFontItalic = this.contents.fontItalic;
  this._saveOutlineColor = this.contents.outlineColor;
  this._saveOutlineWidth = this.contents.outlineWidth;
};

Window_Base.prototype.restoreCurrentWindowSettings = function () {
  this.contents.fontFace = this._saveFontFace;
  this.contents.fontSize = this._saveFontSize;
  this.contents.textColor = this._savetextColor;
  this.contents.fontBold = this._saveFontBold;
  this.contents.fontItalic = this._saveFontItalic;
  this.contents.outlineColor = this._saveOutlineColor;
  this.contents.outlineWidth = this._saveOutlineWidth;
};

Window_Base.prototype.clearCurrentWindowSettings = function () {
  this._saveFontFace = undefined;
  this._saveFontSize = undefined;
  this._savetextColor = undefined;
  this._saveFontBold = undefined;
  this._saveFontItalic = undefined;
  this._saveOutlineColor = undefined;
  this._saveOutlineWidth = undefined;
};

Window_Base.prototype.textWidthExCheck = function (text) {
  var setting = this._wordWrap;
  this._wordWrap = false;
  this.saveCurrentWindowSettings();
  this._checkWordWrapMode = true;
  var value = this.drawTextEx(text, 0, this.contents.height);
  this._checkWordWrapMode = false;
  this.restoreCurrentWindowSettings();
  this.clearCurrentWindowSettings();
  this._wordWrap = setting;
  return value;
};

//=============================================================================
// Window_Help
//=============================================================================

Yanfly.Message.Window_Help_setItem = Window_Help.prototype.setItem;
Window_Help.prototype.setItem = function (item) {
  if (eval(Yanfly.Param.MSGDescWrap)) {
    this.setText(item ? "<WordWrap>" + item.description : "");
  } else {
    Yanfly.Message.Window_Help_setItem.call(this, item);
  }
};

//=============================================================================
// Window_ChoiceList
//=============================================================================

Window_ChoiceList.prototype.standardFontFace = function () {
  return $gameSystem.getMessageFontName();
};

Window_ChoiceList.prototype.standardFontSize = function () {
  return $gameSystem.getMessageFontSize();
};

Yanfly.Message.Window_ChoiceList_updatePlacement =
  Window_ChoiceList.prototype.updatePlacement;
Window_ChoiceList.prototype.updatePlacement = function () {
  Yanfly.Message.Window_ChoiceList_updatePlacement.call(this);
  var messagePosType = $gameMessage.positionType();
  if (messagePosType === 0) {
    this.y = this._messageWindow.height;
  } else if (messagePosType === 2) {
    this.y = Graphics.boxHeight - this._messageWindow.height - this.height;
  }
};

//=============================================================================
// Window_NumberInput
//=============================================================================

Yanfly.Message.Window_NumberInput_updatePlacement =
  Window_NumberInput.prototype.updatePlacement;
Window_NumberInput.prototype.updatePlacement = function () {
  Yanfly.Message.Window_NumberInput_updatePlacement.call(this);
  var messageY = this._messageWindow.y;
  var messagePosType = $gameMessage.positionType();
  if (messagePosType === 0) {
    this.y = this._messageWindow.height;
  } else if (messagePosType === 1) {
    if (messageY >= Graphics.boxHeight / 2) {
      this.y = messageY - this.height;
    } else {
      this.y = messageY + this._messageWindow.height;
    }
  } else if (messagePosType === 2) {
    this.y = Graphics.boxHeight - this._messageWindow.height - this.height;
  }
};

//=============================================================================
// Window_EventItem
//=============================================================================

Yanfly.Message.Window_EventItem_updatePlacement =
  Window_EventItem.prototype.updatePlacement;
Window_EventItem.prototype.updatePlacement = function () {
  Yanfly.Message.Window_EventItem_updatePlacement.call(this);
  var messagePosType = $gameMessage.positionType();
  if (messagePosType === 0) {
    this.y = Graphics.boxHeight - this.height;
  } else if (messagePosType === 2) {
    this.y = 0;
  }
};

//=============================================================================
// Window_ScrollText
//=============================================================================

Window_ScrollText.prototype.standardFontFace = function () {
  return $gameSystem.getMessageFontName();
};

Window_ScrollText.prototype.standardFontSize = function () {
  return $gameSystem.getMessageFontSize();
};

//=============================================================================
// Window_NameBox
//=============================================================================

Yanfly.DisableWebGLMask = false;

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

Window_NameBox.prototype = Object.create(Window_Base.prototype);
Window_NameBox.prototype.constructor = Window_NameBox;

Window_NameBox.prototype.initialize = function (parentWindow) {
  this._parentWindow = parentWindow;
  Window_Base.prototype.initialize.call(this, 0, 0, 240, this.windowHeight());
  this._text = "";
  this._lastNameText = "";
  this._openness = 0;
  this._closeCounter = 0;
  this.deactivate();
  if (eval(Yanfly.Param.MSGNameBoxClear)) {
    this.backOpacity = 0;
    this.opacity = 0;
  }
  this.hide();
};

Window_NameBox.prototype.windowWidth = function () {
  this.resetFontSettings();
  var dw = this.textWidthEx(this._text);
  dw += this.padding * 2;
  var width = dw + eval(Yanfly.Param.MSGNameBoxPadding);
  return Math.ceil(width);
};

Window_NameBox.prototype.textWidthEx = function (text) {
  return this.drawTextEx(text, 0, this.contents.height);
};

Window_NameBox.prototype.calcNormalCharacter = function (textState) {
  return this.textWidth(textState.text[textState.index++]);
};

Window_NameBox.prototype.windowHeight = function () {
  return this.fittingHeight(1);
};

Window_NameBox.prototype.standardFontFace = function () {
  return $gameSystem.getMessageFontName();
};

Window_NameBox.prototype.standardFontSize = function () {
  return $gameSystem.getMessageFontSize();
};

Window_NameBox.prototype.update = function () {
  Window_Base.prototype.update.call(this);
  if (this.active) return;
  if (this.isClosed()) return;
  if (this.isClosing()) return;
  if (this._closeCounter-- > 0) return;
  if (this._parentWindow.isClosing()) {
    this._openness = this._parentWindow.openness;
  }
  this.close();
};

Window_NameBox.prototype.refresh = function (text, position) {
  this.show();
  this._lastNameText = text;
  this._text = Yanfly.Param.MSGNameBoxText + text;
  this._position = position;
  this.width = this.windowWidth();
  this.createContents();
  this.contents.clear();
  this.resetFontSettings();
  this.changeTextColor(this.textColor(Yanfly.Param.MSGNameBoxColor));
  var padding = eval(Yanfly.Param.MSGNameBoxPadding) / 2;
  this.drawTextEx(this._text, padding, 0, this.contents.width);
  this._parentWindow.adjustWindowSettings();
  this._parentWindow.updatePlacement();
  this.adjustPositionX();
  this.adjustPositionY();
  this.open();
  this.activate();
  this._closeCounter = 4;
  return "";
};

Window_NameBox.prototype.adjustPositionX = function () {
  if (this._position === 1) {
    this.x = this._parentWindow.x;
    this.x += eval(Yanfly.Param.MSGNameBoxBufferX);
  } else if (this._position === 2) {
    this.x = this._parentWindow.x;
    this.x += (this._parentWindow.width * 3) / 10;
    this.x -= this.width / 2;
  } else if (this._position === 3) {
    this.x = this._parentWindow.x;
    this.x += this._parentWindow.width / 2;
    this.x -= this.width / 2;
  } else if (this._position === 4) {
    this.x = this._parentWindow.x;
    this.x += (this._parentWindow.width * 7) / 10;
    this.x -= this.width / 2;
  } else {
    this.x = this._parentWindow.x + this._parentWindow.width;
    this.x -= this.width;
    this.x -= eval(Yanfly.Param.MSGNameBoxBufferX);
  }
  this.x = this.x.clamp(0, Graphics.boxWidth - this.width);
};

Window_NameBox.prototype.adjustPositionY = function () {
  if ($gameMessage.positionType() === 0) {
    this.y = this._parentWindow.y + this._parentWindow.height;
    this.y -= eval(Yanfly.Param.MSGNameBoxBufferY);
  } else {
    this.y = this._parentWindow.y;
    this.y -= this.height;
    this.y += eval(Yanfly.Param.MSGNameBoxBufferY);
  }
  if (this.y < 0) {
    this.y = this._parentWindow.y + this._parentWindow.height;
    this.y -= eval(Yanfly.Param.MSGNameBoxBufferY);
  }
};

//=============================================================================
// Window_Message
//=============================================================================

Yanfly.Message.Window_Message_createSubWindows =
  Window_Message.prototype.createSubWindows;
Window_Message.prototype.createSubWindows = function () {
  Yanfly.Message.Window_Message_createSubWindows.call(this);
  this._nameWindow = new Window_NameBox(this);
  Yanfly.nameWindow = this._nameWindow;
  var scene = SceneManager._scene;
  scene.addChild(this._nameWindow);
};

Window_Message.prototype.numVisibleRows = function () {
  return $gameSystem.messageRows();
};

Window_Message.prototype.windowWidth = function () {
  return $gameSystem.messageWidth();
};

Window_Message.prototype.wordwrapWidth = function () {
  if (Yanfly.Param.MSGTightWrap && $gameMessage.faceName() !== "") {
    return this.contents.width - this.newLineX();
  }
  return Window_Base.prototype.wordwrapWidth.call(this);
};

Window_Message.prototype.adjustWindowSettings = function () {
  this.width = this.windowWidth();
  this.height = Math.min(this.windowHeight(), Graphics.boxHeight);
  if (Math.abs(Graphics.boxHeight - this.height) < this.lineHeight()) {
    this.height = Graphics.boxHeight;
  }
  this.createContents();
  this.x = (Graphics.boxWidth - this.width) / 2;
};

Yanfly.Message.Window_Message_startMessage =
  Window_Message.prototype.startMessage;
Window_Message.prototype.startMessage = function () {
  this._nameWindow.deactivate();
  Yanfly.Message.Window_Message_startMessage.call(this);
};

Yanfly.Message.Window_Message_terminateMessage =
  Window_Message.prototype.terminateMessage;
Window_Message.prototype.terminateMessage = function () {
  this._nameWindow.deactivate();
  Yanfly.Message.Window_Message_terminateMessage.call(this);
};

Yanfly.Message.Window_Message_newPage = Window_Message.prototype.newPage;
Window_Message.prototype.newPage = function (textState) {
  this.adjustWindowSettings();
  Yanfly.Message.Window_Message_newPage.call(this, textState);
};

Window_Message.prototype.standardFontFace = function () {
  return $gameSystem.getMessageFontName();
};

Window_Message.prototype.standardFontSize = function () {
  return $gameSystem.getMessageFontSize();
};

Window_Message.prototype.newLineX = function () {
  if ($gameMessage.faceName() === "") {
    return 0;
  } else {
    return eval(Yanfly.Param.MSGFaceIndent);
  }
};

Window_Message.prototype.isFastForward = function () {
  if (!$gameSystem.isFastFowardEnabled()) return false;
  return Input.isPressed(Yanfly.Param.MSGFastForwardKey);
};

Yanfly.Message.Window_Message_updateInput =
  Window_Message.prototype.updateInput;
Window_Message.prototype.updateInput = function () {
  if (this.pause && this.isFastForward()) {
    if (!this._textState) {
      this.pause = false;
      this.terminateMessage();
    }
  }
  return Yanfly.Message.Window_Message_updateInput.call(this);
};

Yanfly.Message.Window_Message_updateShowFast =
  Window_Message.prototype.updateShowFast;
Window_Message.prototype.updateShowFast = function () {
  if (this.isFastForward()) this._showFast = true;
  Yanfly.Message.Window_Message_updateShowFast.call(this);
};

Yanfly.Message.Window_Message_updateWait = Window_Message.prototype.updateWait;
Window_Message.prototype.updateWait = function () {
  if (this.isFastForward()) return false;
  return Yanfly.Message.Window_Message_updateWait.call(this);
};

Yanfly.Message.Window_Message_startWait = Window_Message.prototype.startWait;
Window_Message.prototype.startWait = function (count) {
  if (this._checkWordWrapMode) return;
  Yanfly.Message.Window_Message_startWait.call(this, count);
  if (this.isFastForward()) this._waitCount = 0;
};

Yanfly.Message.Window_Message_startPause = Window_Message.prototype.startPause;
Window_Message.prototype.startPause = function () {
  if (this._checkWordWrapMode) return;
  Yanfly.Message.Window_Message_startPause.call(this);
};

Window_Message.prototype.convertEscapeCharacters = function (text) {
  text = Window_Base.prototype.convertEscapeCharacters.call(this, text);
  text = this.convertNameBox(text);
  text = this.convertMessageCharacters(text);
  return text;
};

Window_Message.prototype.convertNameBox = function (text) {
  text = text.replace(
    /\x1bN\<(.*?)\>/gi,
    function () {
      return Yanfly.nameWindow.refresh(arguments[1], 1);
    },
    this
  );
  text = text.replace(
    /\x1bN1\<(.*?)\>/gi,
    function () {
      return Yanfly.nameWindow.refresh(arguments[1], 1);
    },
    this
  );
  text = text.replace(
    /\x1bN2\<(.*?)\>/gi,
    function () {
      return Yanfly.nameWindow.refresh(arguments[1], 2);
    },
    this
  );
  text = text.replace(
    /\x1bN3\<(.*?)\>/gi,
    function () {
      return Yanfly.nameWindow.refresh(arguments[1], 3);
    },
    this
  );
  text = text.replace(
    /\x1bNC\<(.*?)\>/gi,
    function () {
      return Yanfly.nameWindow.refresh(arguments[1], 3);
    },
    this
  );
  text = text.replace(
    /\x1bN4\<(.*?)\>/gi,
    function () {
      return Yanfly.nameWindow.refresh(arguments[1], 4);
    },
    this
  );
  text = text.replace(
    /\x1bN5\<(.*?)\>/gi,
    function () {
      return Yanfly.nameWindow.refresh(arguments[1], 5);
    },
    this
  );
  text = text.replace(
    /\x1bNR\<(.*?)\>/gi,
    function () {
      return Yanfly.nameWindow.refresh(arguments[1], 5);
    },
    this
  );
  return text;
};

Window_Message.prototype.convertMessageCharacters = function (text) {
  text = text.replace(
    /\x1bAF\[(\d+)\]/gi,
    function () {
      var i = parseInt(arguments[1]);
      return this.convertActorFace($gameActors.actor(i));
    }.bind(this)
  );
  text = text.replace(
    /\x1bPF\[(\d+)\]/gi,
    function () {
      var i = parseInt(arguments[1]);
      return this.convertActorFace($gameParty.members()[i - 1]);
    }.bind(this)
  );
  return text;
};

Window_Message.prototype.convertActorFace = function (actor) {
  $gameMessage.setFaceImage(actor.faceName(), actor.faceIndex());
  return "";
};

Yanfly.Message.Window_Message_processEscapeCharacter =
  Window_Message.prototype.processEscapeCharacter;
Window_Message.prototype.processEscapeCharacter = function (code, textState) {
  switch (code) {
    case "!":
      if (!this.isFastForward()) this.startPause();
      break;
    case "W":
      this.startWait(this.obtainEscapeParam(textState));
    default:
      Yanfly.Message.Window_Message_processEscapeCharacter.call(
        this,
        code,
        textState
      );
      break;
  }
};

if (Yanfly.Param.MSGNameBoxClose) {
  Yanfly.Message.Window_Message_doesContinue =
    Window_Message.prototype.doesContinue;
  Window_Message.prototype.doesContinue = function () {
    var value = Yanfly.Message.Window_Message_doesContinue.call(this);
    if (!value) return false;
    if (this.hasDifferentNameBoxText()) {
      return false;
    }
    return true;
  };

  Window_Message.prototype.hasDifferentNameBoxText = function () {
    var texts = $gameMessage._texts;
    var length = texts.length;
    var open = this._nameWindow.isOpen();
    for (var i = 0; i < length; ++i) {
      var text = texts[i];
      if (text.length <= 0) continue;
      if (Yanfly.MsgMacro) {
        text = this.convertMacroText(text);
        text = text.replace(/\x1b/gi, "\\");
      }
      if (text.match(/\\(?:N|N1|N2|N3|N4|N5|NC|NR)<(.*)>/i)) {
        var name = String(RegExp.$1);
      } else if (text.match(/\\(?:ND|ND1|ND2|ND3|ND4|ND5|NDC|NDR)<(.*)>/i)) {
        var name = String(RegExp.$1);
      } else if (text.match(/\\(?:NT|NT1|NT2|NT3|NT4|NT5|NTC|NTR)<(.*)>/i)) {
        var name = String(RegExp.$1);
      }
      if (name) {
        name = name.replace(
          /\\V\[(\d+)\]/gi,
          function () {
            return $gameVariables.value(parseInt(arguments[1]));
          }.bind(this)
        );
        name = name.replace(
          /\\V\[(\d+)\]/gi,
          function () {
            return $gameVariables.value(parseInt(arguments[1]));
          }.bind(this)
        );
        name = name.replace(
          /\\N\[(\d+)\]/gi,
          function () {
            return this.actorName(parseInt(arguments[1]));
          }.bind(this)
        );
        name = name.replace(
          /\\P\[(\d+)\]/gi,
          function () {
            return this.partyMemberName(parseInt(arguments[1]));
          }.bind(this)
        );
        name = name.replace(/\\/gi, "\x1b");
      }
      if (name && !open) return true;
      if (name && name !== this._nameWindow._lastNameText) {
        return true;
      }
    }
    if (open && !name) return true;
    return false;
  };
} // Yanfly.Param.MSGNameBoxClose

//=============================================================================
// End of File
//=============================================================================


code:
//=============================================================================
// Yanfly Engine Plugins - Status Menu Core
// YEP_StatusMenuCore.js
//=============================================================================

var Imported = Imported || {};
Imported.YEP_StatusMenuCore = true;

var Yanfly = Yanfly || {};
Yanfly.Status = Yanfly.Status || {};
Yanfly.Status.version = 1.04;

//=============================================================================
/*:
 * @plugindesc v1.04 Changes the Status menu for your characters into
 * a hub that displays more character information.
 * @author Yanfly Engine Plugins
 *
 * @param ---Settings---
 * @default
 *
 * @param Command Order
 * @parent ---Settings---
 * @desc This is the order in which the command menu will appear. Use
 * a space to separate the individual commands.
 * @default General Parameters Elements States Attributes Custom Cancel
 *
 * @param Command Window Width
 * @parent ---Settings---
 * @type number
 * @min 1
 * @desc This is the window width for the Command Window.
 * @default 240
 *
 * @param Command Window Rows
 * @parent ---Settings---
 * @type number
 * @min 1
 * @desc This is the number of rows for the Command Window.
 * @default 4
 *
 * @param Command Alignment
 * @parent ---Settings---
 * @type combo
 * @option left
 * @option center
 * @option right
 * @desc This is the text alignment for the Command Window.
 * left     center     right
 * @default center
 *
 * @param ---General---
 * @default
 *
 * @param General Command
 * @parent ---General---
 * @desc This is how the command for 'General' will appear.
 * @default General
 *
 * @param Parameters Text
 * @parent ---General---
 * @desc This is how the word 'Parameters' will appear.
 * @default Parameters
 *
 * @param Experience Text
 * @parent ---General---
 * @desc This is how the word 'Experience' will appear.
 * @default Experience
 *
 * @param Total Format
 * @parent ---General---
 * @desc This is the word total experience.
 * @default Total %1 for Next %2
 *
 * @param EXP Gauge Color 1
 * @parent ---General---
 * @type number
 * @min 0
 * @max 31
 * @desc The skin color used in EXP Gauge Color 1 shown in the
 * status window.
 * @default 30
 *
 * @param EXP Gauge Color 2
 * @parent ---General---
 * @type number
 * @min 0
 * @max 31
 * @desc The skin color used in EXP Gauge Color 2 shown in the
 * status window.
 * @default 31
 *
 * @param ---Parameters---
 * @default
 *
 * @param Parameters Command
 * @parent ---Parameters---
 * @desc This is how the command for 'Parameters' will appear.
 * @default Parameters
 *
 * @param Graph Text
 * @parent ---Parameters---
 * @desc This is how the words for 'Parameter Graph' appear.
 * @default Parameter Graph
 *
 * @param ATK Color
 * @parent ---Parameters---
 * @desc This is the gauge color for ATK.
 * #Color1 #Color2
 * @default #ed1c24 #f26c4f
 *
 * @param DEF Color
 * @parent ---Parameters---
 * @desc This is the gauge color for DEF.
 * #Color1 #Color2
 * @default #f7941d #fdc689
 *
 * @param MAT Color
 * @parent ---Parameters---
 * @desc This is the gauge color for MAT.
 * #Color1 #Color2
 * @default #605ca8 #bd8cbf
 *
 * @param MDF Color
 * @parent ---Parameters---
 * @desc This is the gauge color for MDF.
 * #Color1 #Color2
 * @default #448ccb #a6caf4
 *
 * @param AGI Color
 * @parent ---Parameters---
 * @desc This is the gauge color for AGI.
 * #Color1 #Color2
 * @default #39b54a #82ca9c
 *
 * @param LUK Color
 * @parent ---Parameters---
 * @desc This is the gauge color for LUK.
 * #Color1 #Color2
 * @default #fff568 #fffac3
 *
 * @param ---Resist Colors---
 * @default
 *
 * @param Above 300%
 * @parent ---Resist Colors---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color for rates over 300%.
 * @default 10
 *
 * @param 200% to 300%
 * @parent ---Resist Colors---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color for rates over 200%.
 * @default 20
 *
 * @param 150% to 200%
 * @parent ---Resist Colors---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color for rates over 150%.
 * @default 14
 *
 * @param 120% to 150%
 * @parent ---Resist Colors---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color for rates over 120%.
 * @default 6
 *
 * @param 100% to 120%
 * @parent ---Resist Colors---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color for rates over 100%.
 * @default 0
 *
 * @param 80% to 100%
 * @parent ---Resist Colors---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color for rates over 80%.
 * @default 24
 *
 * @param 50% to 80%
 * @parent ---Resist Colors---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color for rates over 50%.
 * @default 29
 *
 * @param 1% to 50%
 * @parent ---Resist Colors---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color for rates over 1%.
 * @default 23
 *
 * @param Exactly 0%
 * @parent ---Resist Colors---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color for rates exactly 0%.
 * @default 31
 *
 * @param Below 0%
 * @parent ---Resist Colors---
 * @type number
 * @min 0
 * @max 31
 * @desc This is the text color for rates below 0%.
 * @default 27
 *
 * @param ---Elements---
 * @default
 *
 * @param Elements Command
 * @parent ---Elements---
 * @desc This is how the command for 'Elements' will appear.
 * @default Elements
 *
 * @param Elements Decimal
 * @parent ---Elements---
 * @type number
 * @min 0
 * @desc How many decimal places to display for rates.
 * @default 2
 *
 * @param Element Column 1
 * @parent ---Elements---
 * @desc These are the element ID's drawn in column 1.
 * Separate these element ID's with a space.
 * @default 1
 *
 * @param Element Column 2
 * @parent ---Elements---
 * @desc These are the element ID's drawn in column 2.
 * Separate these element ID's with a space.
 * @default 2 3 4 5 6 7 8 9
 *
 * @param Element Column 3
 * @parent ---Elements---
 * @desc These are the element ID's drawn in column 3.
 * Separate these element ID's with a space.
 * @default
 *
 * @param Element Column 4
 * @parent ---Elements---
 * @desc These are the element ID's drawn in column 4.
 * Separate these element ID's with a space.
 * @default
 *
 * @param ---States---
 * @default
 *
 * @param States Command
 * @parent ---States---
 * @desc This is how the command for 'States' will appear.
 * @default States
 *
 * @param States Decimal
 * @parent ---States---
 * @type number
 * @min 0
 * @desc How many decimal places to display for rates.
 * @default 2
 *
 * @param States Column 1
 * @parent ---States---
 * @desc These are the state ID's drawn in column 1.
 * Separate these state ID's with a space.
 * @default 1 4 5 6
 *
 * @param States Column 2
 * @parent ---States---
 * @desc These are the state ID's drawn in column 2.
 * Separate these state ID's with a space.
 * @default 7 8 9 10
 *
 * @param States Column 3
 * @parent ---States---
 * @desc These are the state ID's drawn in column 3.
 * Separate these state ID's with a space.
 * @default
 *
 * @param States Column 4
 * @parent ---States---
 * @desc These are the state ID's drawn in column 4.
 * Separate these state ID's with a space.
 * @default
 *
 * @param ---Attributes---
 * @default
 *
 * @param Attributes Command
 * @parent ---Attributes---
 * @desc This is how the command for 'Attributes' will appear.
 * @default Attributes
 *
 * @param Attribute Font Size
 * @text Attributes Font Size
 * @parent ---Attributes---
 * @type number
 * @min 1
 * @desc The font size used to display attributes.
 * Default: 28
 * @default 20
 *
 * @param Attribute Decimal
 * @text Attributes Decimal
 * @parent ---Attributes---
 * @type number
 * @min 0
 * @desc How many decimal places to display for rates.
 * @default 0
 *
 * @param Attributes Column 1
 * @parent ---Attributes---
 * @desc These are the attributes drawn in column 1.
 * Separate these attributes with a space.
 * @default exr hit eva cri cev mev mrf cnt
 *
 * @param Attributes Column 2
 * @parent ---Attributes---
 * @desc These are the attributes drawn in column 2.
 * Separate these attributes with a space.
 * @default mcr tcr pdr mdr fdr grd rec pha
 *
 * @param Attributes Column 3
 * @parent ---Attributes---
 * @desc These are the attributes drawn in column 3.
 * Separate these attributes with a space.
 * @default hrg mrg trg tgr
 *
 * @param Attributes Column 4
 * @parent ---Attributes---
 * @desc These are the attributes drawn in column 4.
 * Separate these attributes with a space.
 * @default
 *
 * @param ---XParam Names---
 * @default
 *
 * @param hit Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Hit Rate
 *
 * @param eva Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Evasion Rate
 *
 * @param cri Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Critical Hit Rate
 *
 * @param cev Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Critical Evasion Rate
 *
 * @param mev Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Magic Evasion Rate
 *
 * @param mrf Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Magic Reflect Rate
 *
 * @param cnt Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Counter Rate
 *
 * @param hrg Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default HP Regen Rate
 *
 * @param mrg Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default MP Regen Rate
 *
 * @param trg Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default TP Regen Rate
 *
 * @param tgr Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Aggro Rate
 *
 * @param grd Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Guard Effect
 *
 * @param rec Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Recovery Effect
 *
 * @param pha Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Pharmacology Effect
 *
 * @param mcr Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default MP Cost Rate
 *
 * @param tcr Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default TP Charge Rate
 *
 * @param pdr Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Physical Damage Rate
 *
 * @param mdr Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Magical Damage Rate
 *
 * @param fdr Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Floor Damage Rate
 *
 * @param exr Name
 * @parent ---XParam Names---
 * @desc The text name used for this attribute.
 * @default Experience Rate
 *
 * @help
 * ============================================================================
 * Introduction
 * ============================================================================
 *
 * This plugin replaces the Status menu with a whole new layout. Including the
 * function to display more information regarding the actor. You can change the
 * order commands appear in game with the Command Order parameter.
 *
 * To add more commands, insert extension plugins under this plugin in the
 * Plugin Manager. Then, it will appear automatically in the Command Order
 * where you placed the 'Custom' string or elsewhere if you've placed the
 * extension plugin's keyword elsewhere.
 *
 * ============================================================================
 * Instructions
 * ============================================================================
 *
 * You can add and remove commands from the Command Window by changing the
 * 'Command Order' parameter. Here is a list of commands you may use:
 *
 *    General
 *    - Displays the current current stats and EXP for the actor.
 *
 *    Parameters
 *    - Displays a parameter gauge of the actor relative to other stats.
 *
 *    Elements
 *    - Displays the listed elements and their elemental rates.
 *
 *    States
 *    - Displays the listed states and their status infliction rates.
 *
 *    Attributes
 *    - Displays the listed attributes and their rates.
 *
 *    Custom
 *    - If you have any custom status window items to display, they will
 *    appear here.
 *
 *    Cancel
 *    - Adds a cancel command for leaving the Status Menu.
 *
 * ============================================================================
 * Adding Icons to Elements and Attributes
 * ============================================================================
 *
 * You can use icons for elements and attributes by using text codes.
 *
 * In the RPG Maker MV editor's database, types tab, for the elements, name
 * them as such:
 *
 * \i[64]Fire
 *
 * This will enable you to give the element an icon. You can also change the
 * text color and such using any of the available text codes.
 *
 * The same is applied for Attributes except you modify it within this plugin's
 * parameters. If you wish to display 'HP Regen Rate' with an icon, name it:
 *
 * \i[72]HP Regen Rate
 *
 * The icons will be drawn for the said attributes in addition to any other
 * text code modifications used.
 *
 * ============================================================================
 * Changelog
 * ============================================================================
 *
 * Version 1.04:
 * - Added a function to split the icon and text for Attribute names so that
 * icons will be centered properly if icons are used for the Attribute names.
 *
 * Version 1.03:
 * - Updated for RPG Maker MV version 1.5.0.
 *
 * Version 1.02:
 * - Compatibility update made for other plugins.
 *
 * Version 1.01a:
 * - Converted Window_StatusInfo to Window_Selectable for those who would like
 * to use it as such.
 *
 * Version 1.00:
 * - Finished Plugin!
 */
//=============================================================================

//=============================================================================
// Parameter Variables
//=============================================================================

Yanfly.Parameters = PluginManager.parameters("YEP_StatusMenuCore");
Yanfly.Param = Yanfly.Param || {};

Yanfly.Param.StatusCmdOrder = String(Yanfly.Parameters["Command Order"]);
Yanfly.Param.StatusCmdWidth = Number(Yanfly.Parameters["Command Window Width"]);
Yanfly.Param.StatusCmdRows = Number(Yanfly.Parameters["Command Window Rows"]);
Yanfly.Param.StatusCmdAlign = String(Yanfly.Parameters["Command Alignment"]);

Yanfly.Param.StatusGeneral = String(Yanfly.Parameters["General Command"]);
Yanfly.Param.StatusParamText = String(Yanfly.Parameters["Parameters Text"]);
Yanfly.Param.StatusExpText = String(Yanfly.Parameters["Experience Text"]);
Yanfly.Param.StatusTotalFmt = String(Yanfly.Parameters["Total Format"]);
Yanfly.Param.ColorExp1 = Number(Yanfly.Parameters["EXP Gauge Color 1"]);
Yanfly.Param.ColorExp2 = Number(Yanfly.Parameters["EXP Gauge Color 2"]);

Yanfly.Param.StatusParameters = String(Yanfly.Parameters["Parameters Command"]);
Yanfly.Param.StatusGraphText = String(Yanfly.Parameters["Graph Text"]);
Yanfly.Param.ColorParam2Gauge = String(Yanfly.Parameters["ATK Color"]);
Yanfly.Param.ColorParam3Gauge = String(Yanfly.Parameters["DEF Color"]);
Yanfly.Param.ColorParam4Gauge = String(Yanfly.Parameters["MAT Color"]);
Yanfly.Param.ColorParam5Gauge = String(Yanfly.Parameters["MDF Color"]);
Yanfly.Param.ColorParam6Gauge = String(Yanfly.Parameters["AGI Color"]);
Yanfly.Param.ColorParam7Gauge = String(Yanfly.Parameters["LUK Color"]);

Yanfly.Param.ColorResistS = Number(Yanfly.Parameters["Above 300%"]);
Yanfly.Param.ColorResistA = Number(Yanfly.Parameters["200% to 300%"]);
Yanfly.Param.ColorResistB = Number(Yanfly.Parameters["150% to 200%"]);
Yanfly.Param.ColorResistC1 = Number(Yanfly.Parameters["120% to 150%"]);
Yanfly.Param.ColorResistC2 = Number(Yanfly.Parameters["100% to 120%"]);
Yanfly.Param.ColorResistC3 = Number(Yanfly.Parameters["80% to 100%"]);
Yanfly.Param.ColorResistD = Number(Yanfly.Parameters["50% to 80%"]);
Yanfly.Param.ColorResistE = Number(Yanfly.Parameters["1% to 50%"]);
Yanfly.Param.ColorResistF = Number(Yanfly.Parameters["Exactly 0%"]);
Yanfly.Param.ColorResistG = Number(Yanfly.Parameters["Below 0%"]);

Yanfly.Param.StatusElements = String(Yanfly.Parameters["Elements Command"]);
Yanfly.Param.StatusEleDec = Number(Yanfly.Parameters["Elements Decimal"]);
Yanfly.Param.StatusEleCol1 = String(Yanfly.Parameters["Element Column 1"]);
Yanfly.Param.StatusEleCol1 = Yanfly.Param.StatusEleCol1.split(" ");
Yanfly.Param.StatusEleCol2 = String(Yanfly.Parameters["Element Column 2"]);
Yanfly.Param.StatusEleCol2 = Yanfly.Param.StatusEleCol2.split(" ");
Yanfly.Param.StatusEleCol3 = String(Yanfly.Parameters["Element Column 3"]);
Yanfly.Param.StatusEleCol3 = Yanfly.Param.StatusEleCol3.split(" ");
Yanfly.Param.StatusEleCol4 = String(Yanfly.Parameters["Element Column 4"]);
Yanfly.Param.StatusEleCol4 = Yanfly.Param.StatusEleCol4.split(" ");

Yanfly.Param.StatusStates = String(Yanfly.Parameters["States Command"]);
Yanfly.Param.StatusStatesDec = Number(Yanfly.Parameters["States Decimal"]);
Yanfly.Param.StatusStateCol1 = String(Yanfly.Parameters["States Column 1"]);
Yanfly.Param.StatusStateCol1 = Yanfly.Param.StatusStateCol1.split(" ");
Yanfly.Param.StatusStateCol2 = String(Yanfly.Parameters["States Column 2"]);
Yanfly.Param.StatusStateCol2 = Yanfly.Param.StatusStateCol2.split(" ");
Yanfly.Param.StatusStateCol3 = String(Yanfly.Parameters["States Column 3"]);
Yanfly.Param.StatusStateCol3 = Yanfly.Param.StatusStateCol3.split(" ");
Yanfly.Param.StatusStateCol4 = String(Yanfly.Parameters["States Column 4"]);
Yanfly.Param.StatusStateCol4 = Yanfly.Param.StatusStateCol4.split(" ");

Yanfly.Param.StatusAttributes = String(Yanfly.Parameters["Attributes Command"]);
Yanfly.Param.StatusAttriCol1 = String(Yanfly.Parameters["Attributes Column 1"]);
Yanfly.Param.StatusAttriCol1 = Yanfly.Param.StatusAttriCol1.split(" ");
Yanfly.Param.StatusAttriCol2 = String(Yanfly.Parameters["Attributes Column 2"]);
Yanfly.Param.StatusAttriCol2 = Yanfly.Param.StatusAttriCol2.split(" ");
Yanfly.Param.StatusAttriCol3 = String(Yanfly.Parameters["Attributes Column 3"]);
Yanfly.Param.StatusAttriCol3 = Yanfly.Param.StatusAttriCol3.split(" ");
Yanfly.Param.StatusAttriCol4 = String(Yanfly.Parameters["Attributes Column 4"]);
Yanfly.Param.StatusAttriCol4 = Yanfly.Param.StatusAttriCol4.split(" ");
Yanfly.Param.StatusAttrSize = Number(Yanfly.Parameters["Attribute Font Size"]);
Yanfly.Param.StatusAttrDec = Number(Yanfly.Parameters["Attribute Decimal"]);
Yanfly.Param.StatusAttr_hit = String(Yanfly.Parameters["hit Name"]);
Yanfly.Param.StatusAttr_eva = String(Yanfly.Parameters["eva Name"]);
Yanfly.Param.StatusAttr_cri = String(Yanfly.Parameters["cri Name"]);
Yanfly.Param.StatusAttr_cev = String(Yanfly.Parameters["cev Name"]);
Yanfly.Param.StatusAttr_mev = String(Yanfly.Parameters["mev Name"]);
Yanfly.Param.StatusAttr_mrf = String(Yanfly.Parameters["mrf Name"]);
Yanfly.Param.StatusAttr_cnt = String(Yanfly.Parameters["cnt Name"]);
Yanfly.Param.StatusAttr_hrg = String(Yanfly.Parameters["hrg Name"]);
Yanfly.Param.StatusAttr_mrg = String(Yanfly.Parameters["mrg Name"]);
Yanfly.Param.StatusAttr_trg = String(Yanfly.Parameters["trg Name"]);
Yanfly.Param.StatusAttr_tgr = String(Yanfly.Parameters["tgr Name"]);
Yanfly.Param.StatusAttr_grd = String(Yanfly.Parameters["grd Name"]);
Yanfly.Param.StatusAttr_rec = String(Yanfly.Parameters["rec Name"]);
Yanfly.Param.StatusAttr_pha = String(Yanfly.Parameters["pha Name"]);
Yanfly.Param.StatusAttr_mcr = String(Yanfly.Parameters["mcr Name"]);
Yanfly.Param.StatusAttr_tcr = String(Yanfly.Parameters["tcr Name"]);
Yanfly.Param.StatusAttr_pdr = String(Yanfly.Parameters["pdr Name"]);
Yanfly.Param.StatusAttr_mdr = String(Yanfly.Parameters["mdr Name"]);
Yanfly.Param.StatusAttr_fdr = String(Yanfly.Parameters["fdr Name"]);
Yanfly.Param.StatusAttr_exr = String(Yanfly.Parameters["exr Name"]);

//=============================================================================
// Window_StatusCommand
//=============================================================================

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

Window_StatusCommand.prototype = Object.create(Window_Command.prototype);
Window_StatusCommand.prototype.constructor = Window_StatusCommand;

Window_StatusCommand.prototype.initialize = function () {
  Window_Command.prototype.initialize.call(this, 0, 0);
  this._actor = null;
};

Window_StatusCommand.prototype.windowWidth = function () {
  return Yanfly.Param.StatusCmdWidth;
};

Window_StatusCommand.prototype.setActor = function (actor) {
  if (this._actor === actor) return;
  this._actor = actor;
  this.refresh();
  this.select(0);
};

Window_StatusCommand.prototype.numVisibleRows = function () {
  return Yanfly.Param.StatusCmdRows;
};

Window_StatusCommand.prototype.makeCommandList = function () {
  this._commandOrder = Yanfly.Param.StatusCmdOrder.split(" ");
  for (var i = 0; i < this._commandOrder.length; ++i) {
    var command = this._commandOrder[i];
    this.createCommand(command);
  }
};

Window_StatusCommand.prototype.createCommand = function (command) {
  command = command.toUpperCase();
  if (["GENERAL", "MAIN"].contains(command)) {
    var text = Yanfly.Param.StatusGeneral;
    this.addCommand(text, "general", true);
  } else if (["CANCEL", "FINISH"].contains(command)) {
    this.addCommand(TextManager.cancel, "cancel", true);
  } else if (["CUSTOM", "ORIGINAL"].contains(command)) {
    this.addCustomCommands();
  } else if (["PARAMETER", "PARAMETERS"].contains(command)) {
    var text = Yanfly.Param.StatusParameters;
    this.addCommand(text, "parameters", true);
  } else if (["ELEMENT", "ELEMENTS"].contains(command)) {
    var text = Yanfly.Param.StatusElements;
    this.addCommand(text, "elements", true);
  } else if (["STATE", "STATES"].contains(command)) {
    var text = Yanfly.Param.StatusStates;
    this.addCommand(text, "states", true);
  } else if (["ATTRIBUTE", "ATTRIBUTES"].contains(command)) {
    var text = Yanfly.Param.StatusAttributes;
    this.addCommand(text, "attributes", true);
  }
};

Window_StatusCommand.prototype.addCustomCommands = function () {};

Window_StatusCommand.prototype.setInfoWindow = function (infoWindow) {
  this._infoWindow = infoWindow;
};

Window_StatusCommand.prototype.update = function () {
  Window_Command.prototype.update.call(this);
  if (this._infoWindow) this._infoWindow.setSymbol(this.currentSymbol());
};

Window_StatusCommand.prototype.itemTextAlign = function () {
  return Yanfly.Param.StatusCmdAlign;
};

Window_StatusCommand.prototype.playOkSound = function () {
  if (this.isPlayOkSound()) SoundManager.playOk();
};

Window_StatusCommand.prototype.isPlayOkSound = function () {
  if (this.currentSymbol() === "cancel") return true;
  return false;
};

//=============================================================================
// Window_StatusInfo
//=============================================================================

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

Window_StatusInfo.prototype = Object.create(Window_Selectable.prototype);
Window_StatusInfo.prototype.constructor = Window_StatusInfo;

Window_StatusInfo.prototype.initialize = function (y, commandWindow) {
  var width = Graphics.boxWidth;
  var height = Graphics.boxHeight - y;
  this._commandWindow = commandWindow;
  Window_Selectable.prototype.initialize.call(this, 0, y, width, height);
  this.findParamLimits();
};

Window_StatusInfo.prototype.findParamLimits = function () {
  this._largestParam = 1;
  this._smallestParam = $gameActors.actor(1).paramMax(2);
  for (var i = 0; i < $gameParty.members().length; ++i) {
    var actor = $gameParty.members()[i];
    if (!actor) continue;
    for (var j = 2; j < 8; ++j) {
      this._largestParam = Math.max(this._largestParam, actor.param(j));
      this._smallestParam = Math.min(this._smallestParam, actor.param(j));
    }
  }
};

Window_StatusInfo.prototype.setActor = function (actor) {
  if (this._actor === actor) return;
  this._actor = actor;
  this.refresh();
};

Window_StatusInfo.prototype.setSymbol = function (symbol) {
  var needRefresh = this._symbol !== symbol;
  this._symbol = symbol;
  if (needRefresh) this.refresh();
};

Window_StatusInfo.prototype.resetFontSettings = function () {
  if (this._bypassResetText) return;
  Window_Base.prototype.resetFontSettings.call(this);
};

Window_StatusInfo.prototype.resetTextColor = function () {
  if (this._bypassResetTextColor) return;
  Window_Base.prototype.resetTextColor.call(this);
};

Window_StatusInfo.prototype.refresh = function () {
  this.contents.clear();
  this.drawInfoContents(this._symbol);
};

Window_StatusInfo.prototype.drawInfoContents = function (symbol) {
  this.resetFontSettings();
  if (!symbol) return;
  switch (symbol.toLowerCase()) {
    case "parameters":
      this.drawParameters();
      break;
    case "elements":
      this.drawElements();
      break;
    case "states":
      this.drawStates();
      break;
    case "attributes":
      this.drawAttributes();
      break;
    default:
      this.drawGeneral();
      break;
  }
};

Window_StatusInfo.prototype.drawDarkRect = function (dx, dy, dw, dh) {
  var color = this.gaugeBackColor();
  this.changePaintOpacity(false);
  this.contents.fillRect(dx + 1, dy + 1, dw - 2, dh - 2, color);
  this.changePaintOpacity(true);
};

Window_StatusInfo.prototype.drawGeneral = function () {
  var dx = this.standardPadding() / 2;
  var dy = this.lineHeight() / 2;
  var dw = (this.contents.width - this.standardPadding()) / 2;
  var dh = this.lineHeight();
  var text;
  this.changeTextColor(this.systemColor());
  this.drawText(Yanfly.Param.StatusParamText, dx, dy, dw, "center");
  dx += this.contents.width / 2;
  this.drawText(Yanfly.Param.StatusExpText, dx, dy, dw, "center");
  this.drawGeneralParam(dx, dy, dw, dh);
  this.drawGeneralExp(dx, dy, dw, dh);
};

Window_StatusInfo.prototype.drawGeneralParam = function () {
  var rect = new Rectangle();
  rect.width = (this.contents.width - this.standardPadding()) / 2;
  rect.y = this.lineHeight() * 2;
  rect.height = this.lineHeight();
  var dx = rect.x + this.textPadding();
  var dw = rect.width - this.textPadding() * 2;
  this.drawDarkRect(rect.x, rect.y, rect.width, rect.height);
  this.changeTextColor(this.systemColor());
  this.drawText(TextManager.level, dx, rect.y, dw, "left");
  this.changeTextColor(this.normalColor());
  text = Yanfly.Util.toGroup(this._actor.level);
  this.drawText(text, dx, rect.y, dw, "right");
  for (var i = 0; i < 8; ++i) {
    if (i < 2) {
      rect.y += this.lineHeight();
    } else if (i === 2) {
      rect.y += this.lineHeight();
      rect.width /= 2;
      dw = rect.width - this.textPadding() * 2;
    } else if (i % 2 === 0) {
      rect.x = 0;
      dx = rect.x + this.textPadding();
      rect.y += this.lineHeight();
    } else {
      rect.x += rect.width;
      dx += rect.width;
    }
    this.drawDarkRect(rect.x, rect.y, rect.width, rect.height);
    this.changeTextColor(this.systemColor());
    this.drawText(TextManager.param(i), dx, rect.y, dw, "left");
    this.changeTextColor(this.normalColor());
    text = Yanfly.Util.toGroup(this._actor.param(i));
    this.drawText(text, dx, rect.y, dw, "right");
  }
};

Window_StatusInfo.prototype.actorCurrentExpRate = function (actor) {
  var actorLv = actor.level;
  if (actorLv === actor.maxLevel()) return 1.0;
  var nowExp = actor.currentExp() - actor.expForLevel(actorLv);
  var nextExp = actor.expForLevel(actorLv + 1) - actor.expForLevel(actorLv);
  return ((1.0 * nowExp) / nextExp).clamp(0.0, 1.0);
};

Window_StatusInfo.prototype.actorExpRate = function (actor) {
  var actorLv = actor.level;
  if (actorLv === actor.maxLevel()) return 1.0;
  var nowExp = actor.currentExp();
  var nextExp = actor.expForLevel(actorLv + 1);
  return ((1.0 * nowExp) / nextExp).clamp(0.0, 1.0);
};

Window_StatusInfo.prototype.drawExpGauge = function (actor, rate, rect) {
  var color1 = this.textColor(Yanfly.Param.ColorExp1);
  var color2 = this.textColor(Yanfly.Param.ColorExp2);
  var wy = rect.y;
  this.drawGauge(rect.x, wy, rect.width, rate, color1, color2);
};

Window_StatusInfo.prototype.drawGeneralExp = function (dx, dy, dw, dh) {
  dy = this.lineHeight() * 2;
  dw = (this.contents.width - this.textPadding()) / 2;
  dx = this.textPadding() + dw;
  // Current Exp
  this.changeTextColor(this.systemColor());
  text = TextManager.expTotal.format(TextManager.exp);
  this.drawText(text, dx, dy, dw, "left");
  dy += this.lineHeight();
  this.changeTextColor(this.normalColor());
  text = Yanfly.Util.toGroup(this._actor.currentExp());
  this.drawText(text, dx, dy, dw, "right");
  // To Next Level
  dy += this.lineHeight();
  this.changeTextColor(this.systemColor());
  text = TextManager.expNext.format(TextManager.level);
  this.drawText(text, dx, dy, dw, "left");
  dy += this.lineHeight();
  var rect = new Rectangle();
  rect.x = dx;
  rect.y = dy;
  rect.width = dw;
  var rate = this.actorCurrentExpRate(this._actor);
  this.drawExpGauge(this._actor, rate, rect);
  this.changeTextColor(this.normalColor());
  text = Yanfly.Util.toGroup(this._actor.nextRequiredExp());
  if (this._actor.isMaxLevel()) text = "-------";
  this.drawText(text, dx, dy, dw, "right");
  // Total EXP for Next Level
  dy += this.lineHeight();
  this.changeTextColor(this.systemColor());
  text = Yanfly.Param.StatusTotalFmt.format(TextManager.exp, TextManager.level);
  this.drawText(text, dx, dy, dw, "left");
  dy += this.lineHeight();
  var rect = new Rectangle();
  rect.x = dx;
  rect.y = dy;
  rect.width = dw;
  var rate = this.actorExpRate(this._actor);
  this.drawExpGauge(this._actor, rate, rect);
  this.changeTextColor(this.normalColor());
  text = Yanfly.Util.toGroup(this._actor.nextLevelExp());
  if (this._actor.isMaxLevel()) text = "-------";
  this.drawText(text, dx, dy, dw, "right");
};

Window_StatusInfo.prototype.drawParameters = function () {
  var dx = 0;
  var dy = this.lineHeight() / 2;
  var dw = this.contents.width;
  var dh = this.lineHeight();
  var dw2;
  var text;
  this.changeTextColor(this.systemColor());
  this.drawText(Yanfly.Param.StatusGraphText, dx, dy, dw, "center");
  dy = this.lineHeight();
  dx = this.standardPadding();
  dw -= this.standardPadding() * 2;
  for (var i = 2; i < 8; ++i) {
    dy += this.lineHeight();
    var rate = this.drawParamGauge(dx, dy, dw, i);
    this.changeTextColor(this.systemColor());
    this.drawText(TextManager.param(i), dx + 4, dy, dw - 4);
    text = Yanfly.Util.toGroup(this._actor.param(i));
    this.changeTextColor(this.normalColor());
    dw2 = dw * rate;
    this.drawText(text, dx, dy, dw2 - 4, "right");
  }
};

Window_StatusInfo.prototype.drawParamGauge = function (dx, dy, dw, paramId) {
  var rate = this.calcParamRate(paramId);
  var array = eval("Yanfly.Param.ColorParam" + paramId + "Gauge").split(" ");
  this.drawGauge(dx, dy, dw, rate, array[0], array[1]);
  return rate;
};

Window_StatusInfo.prototype.calcParamRate = function (paramId) {
  if (this._largestParam === this._smallestParam) return 1.0;
  var rate =
    parseFloat(this._actor.param(paramId) - this._smallestParam) /
    parseFloat(this._largestParam - this._smallestParam);
  rate *= 0.7;
  rate += 0.3;
  return rate;
};

Window_StatusInfo.prototype.getMaxArrayCols = function (array) {
  var maxCols = 0;
  for (var i = 0; i < array.length; ++i) {
    var arr = array[i];
    if (arr[0] !== "") ++maxCols;
  }
  return maxCols;
};

Window_StatusInfo.prototype.getMaxArrayRows = function (array) {
  var maxRows = 0;
  for (var i = 0; i < array.length; ++i) {
    var arr = array[i];
    maxRows = Math.max(maxRows, arr.length);
  }
  return maxRows;
};

Window_StatusInfo.prototype.getArrayX = function () {
  return this.standardPadding() * 1.5;
};

Window_StatusInfo.prototype.getArrayY = function () {
  return 0;
};

Window_StatusInfo.prototype.getArrayDW = function (maxCols) {
  var dw = this.contents.width - this.standardPadding() * 3;
  dw /= maxCols;
  dw += this.standardPadding() / maxCols;
  dw -= this.standardPadding();
  return dw;
};

Window_StatusInfo.prototype.setRateColor = function (rate) {
  var colorId = 0;
  if (rate >= 3.0) {
    colorId = Yanfly.Param.ColorResistS;
  } else if (rate >= 2.0) {
    colorId = Yanfly.Param.ColorResistA;
  } else if (rate >= 1.5) {
    colorId = Yanfly.Param.ColorResistB;
  } else if (rate >= 1.2) {
    colorId = Yanfly.Param.ColorResistC1;
  } else if (rate >= 1.0) {
    colorId = Yanfly.Param.ColorResistC2;
  } else if (rate >= 0.8) {
    colorId = Yanfly.Param.ColorResistC3;
  } else if (rate >= 0.5) {
    colorId = Yanfly.Param.ColorResistD;
  } else if (rate > 0) {
    colorId = Yanfly.Param.ColorResistE;
  } else if (rate === 0) {
    colorId = Yanfly.Param.ColorResistF;
  } else {
    colorId = Yanfly.Param.ColorResistG;
  }
  this.changeTextColor(this.textColor(colorId));
};

Window_StatusInfo.prototype.drawSplitIcon = function (name, dx, dy) {
  if (name.match(/\\I\[(\d+)\]/i)) {
    var icon = parseInt(RegExp.$1) || 0;
    this.drawIcon(icon, dx, dy + 2);
    return true;
  } else {
    return false;
  }
};

Window_StatusInfo.prototype.drawElements = function () {
  this.drawElementColumnRects();
  this.drawElementInfo();
};

Window_StatusInfo.prototype.elementArray = function () {
  var array = [
    Yanfly.Param.StatusEleCol1,
    Yanfly.Param.StatusEleCol2,
    Yanfly.Param.StatusEleCol3,
    Yanfly.Param.StatusEleCol4,
  ];
  return array;
};

Window_StatusInfo.prototype.drawElementColumnRects = function () {
  var maxCols = this.getMaxArrayCols(this.elementArray());
  var maxRows = this.getMaxArrayRows(this.elementArray());
  if (maxCols <= 0) return;
  var dx = this.getArrayX();
  var dy = this.getArrayY();
  var dw = this.getArrayDW(maxCols);
  for (var i = 0; i < maxCols; ++i) {
    for (var j = 0; j < maxRows; ++j) {
      this.drawDarkRect(dx, dy, dw, this.lineHeight());
      dy += this.lineHeight();
    }
    dx += dw;
    dx += maxCols > 1 ? this.standardPadding() : 0;
    dy = 0;
  }
};

Window_StatusInfo.prototype.drawElementInfo = function () {
  var maxCols = this.getMaxArrayCols(this.elementArray());
  var maxRows = this.getMaxArrayRows(this.elementArray());
  if (maxCols <= 0) return;
  var infoArray = this.elementArray();
  var dx = this.getArrayX();
  var dy = this.getArrayY();
  var dw = this.getArrayDW(maxCols);
  for (var i = 0; i < maxCols; ++i) {
    for (var j = 0; j < infoArray[i].length; ++j) {
      var eleId = infoArray[i][j];
      this.drawElementData(eleId, dx, dy, dw);
      dy += this.lineHeight();
    }
    dx += dw;
    dx += maxCols > 1 ? this.standardPadding() : 0;
    dy = 0;
  }
};

Window_StatusInfo.prototype.drawElementData = function (eleId, dx, dy, dw) {
  eleId = parseInt(eleId);
  var eleName = $dataSystem.elements[eleId];
  var eleRate = this._actor.elementRate(eleId);
  dx += this.textPadding();
  dw -= this.textPadding() * 2;
  this._bypassResetTextColor = true;
  this.changeTextColor(this.systemColor());
  this.drawTextEx(eleName, dx, dy);
  this._bypassResetTextColor = false;
  this.setRateColor(eleRate);
  var text = (eleRate * 100).toFixed(Yanfly.Param.StatusEleDec) + "%";
  this.drawText(text, dx, dy, dw, "right");
};

Window_StatusInfo.prototype.drawStates = function () {
  this.drawStatesColumnRects();
  this.drawStatesInfo();
};

Window_StatusInfo.prototype.stateArray = function () {
  var array = [
    Yanfly.Param.StatusStateCol1,
    Yanfly.Param.StatusStateCol2,
    Yanfly.Param.StatusStateCol3,
    Yanfly.Param.StatusStateCol4,
  ];
  return array;
};

Window_StatusInfo.prototype.drawStatesColumnRects = function () {
  var maxCols = this.getMaxArrayCols(this.stateArray());
  var maxRows = this.getMaxArrayRows(this.stateArray());
  if (maxCols <= 0) return;
  var dx = this.getArrayX();
  var dy = this.getArrayY();
  var dw = this.getArrayDW(maxCols);
  for (var i = 0; i < maxCols; ++i) {
    for (var j = 0; j < maxRows; ++j) {
      this.drawDarkRect(dx, dy, dw, this.lineHeight());
      dy += this.lineHeight();
    }
    dx += dw;
    dx += maxCols > 1 ? this.standardPadding() : 0;
    dy = 0;
  }
};

Window_StatusInfo.prototype.drawStatesInfo = function () {
  var maxCols = this.getMaxArrayCols(this.stateArray());
  var maxRows = this.getMaxArrayRows(this.stateArray());
  if (maxCols <= 0) return;
  var infoArray = this.stateArray();
  var dx = this.getArrayX();
  var dy = this.getArrayY();
  var dw = this.getArrayDW(maxCols);
  for (var i = 0; i < maxCols; ++i) {
    for (var j = 0; j < infoArray[i].length; ++j) {
      var stateId = infoArray[i][j];
      this.drawStatesData(stateId, dx, dy, dw);
      dy += this.lineHeight();
    }
    dx += dw;
    dx += maxCols > 1 ? this.standardPadding() : 0;
    dy = 0;
  }
};

Window_StatusInfo.prototype.drawStatesData = function (stateId, dx, dy, dw) {
  stateId = parseInt(stateId);
  var stateRate = this._actor.stateRate(stateId);
  if (this._actor.isStateResist(stateId)) stateRate = 0;
  dx += this.textPadding();
  dw -= this.textPadding() * 2;
  this._bypassResetTextColor = true;
  this.changeTextColor(this.systemColor());
  this.drawItemName($dataStates[stateId], dx, dy, dw);
  this._bypassResetTextColor = false;
  this.setRateColor(stateRate);
  var text = (stateRate * 100).toFixed(Yanfly.Param.StatusStatesDec) + "%";
  this.drawText(text, dx, dy, dw, "right");
};

Window_StatusInfo.prototype.drawAttributes = function () {
  this.drawAttributesColumnRects();
  this.drawAttributesInfo();
};

Window_StatusInfo.prototype.attributesArray = function () {
  var array = [
    Yanfly.Param.StatusAttriCol1,
    Yanfly.Param.StatusAttriCol2,
    Yanfly.Param.StatusAttriCol3,
    Yanfly.Param.StatusAttriCol4,
  ];
  return array;
};

Window_StatusInfo.prototype.drawAttributesColumnRects = function () {
  var maxCols = this.getMaxArrayCols(this.attributesArray());
  var maxRows = this.getMaxArrayRows(this.attributesArray());
  if (maxCols <= 0) return;
  var dx = this.getArrayX();
  var dy = this.getArrayY();
  var dw = this.getArrayDW(maxCols);
  for (var i = 0; i < maxCols; ++i) {
    for (var j = 0; j < maxRows; ++j) {
      this.drawDarkRect(dx, dy, dw, this.lineHeight());
      dy += this.lineHeight();
    }
    dx += dw;
    dx += maxCols > 1 ? this.standardPadding() : 0;
    dy = 0;
  }
};

Window_StatusInfo.prototype.drawAttributesInfo = function () {
  var maxCols = this.getMaxArrayCols(this.attributesArray());
  var maxRows = this.getMaxArrayRows(this.attributesArray());
  if (maxCols <= 0) return;
  var infoArray = this.attributesArray();
  var dx = this.getArrayX();
  var dy = this.getArrayY();
  var dw = this.getArrayDW(maxCols);
  for (var i = 0; i < maxCols; ++i) {
    for (var j = 0; j < infoArray[i].length; ++j) {
      var attribute = infoArray[i][j].toLowerCase();
      this.drawAttributeData(attribute, dx, dy, dw);
      dy += this.lineHeight();
    }
    dx += dw;
    dx += maxCols > 1 ? this.standardPadding() : 0;
    dy = 0;
  }
};

Window_StatusInfo.prototype.drawAttributeData = function (attr, dx, dy, dw) {
  var actor = this._actor;
  this.contents.fontSize = Yanfly.Param.StatusAttrSize;
  switch (attr) {
    case "hit":
      this.drawAttributeName(Yanfly.Param.StatusAttr_hit, dx, dy, dw);
      this.drawAttributeRate(actor.hit, dx, dy, dw);
      break;
    case "eva":
      this.drawAttributeName(Yanfly.Param.StatusAttr_eva, dx, dy, dw);
      this.drawAttributeRate(actor.eva, dx, dy, dw);
      break;
    case "cri":
      this.drawAttributeName(Yanfly.Param.StatusAttr_cri, dx, dy, dw);
      this.drawAttributeRate(actor.cri, dx, dy, dw);
      break;
    case "cev":
      this.drawAttributeName(Yanfly.Param.StatusAttr_cev, dx, dy, dw);
      this.drawAttributeRate(actor.cev, dx, dy, dw);
      break;
    case "mev":
      this.drawAttributeName(Yanfly.Param.StatusAttr_mev, dx, dy, dw);
      this.drawAttributeRate(actor.mev, dx, dy, dw);
      break;
    case "mrf":
      this.drawAttributeName(Yanfly.Param.StatusAttr_mrf, dx, dy, dw);
      this.drawAttributeRate(actor.mrf, dx, dy, dw);
      break;
    case "cnt":
      this.drawAttributeName(Yanfly.Param.StatusAttr_cnt, dx, dy, dw);
      this.drawAttributeRate(actor.cnt, dx, dy, dw);
      break;
    case "hrg":
      this.drawAttributeName(Yanfly.Param.StatusAttr_hrg, dx, dy, dw);
      this.drawAttributeRate(actor.hrg, dx, dy, dw);
      break;
    case "mrg":
      this.drawAttributeName(Yanfly.Param.StatusAttr_mrg, dx, dy, dw);
      this.drawAttributeRate(actor.mrg, dx, dy, dw);
      break;
    case "trg":
      this.drawAttributeName(Yanfly.Param.StatusAttr_trg, dx, dy, dw);
      this.drawAttributeRate(actor.trg, dx, dy, dw);
      break;
    case "tgr":
      this.drawAttributeName(Yanfly.Param.StatusAttr_tgr, dx, dy, dw);
      this.drawAttributeRate(actor.tgr, dx, dy, dw);
      break;
    case "grd":
      this.drawAttributeName(Yanfly.Param.StatusAttr_grd, dx, dy, dw);
      this.drawAttributeRate(actor.grd, dx, dy, dw);
      break;
    case "rec":
      this.drawAttributeName(Yanfly.Param.StatusAttr_rec, dx, dy, dw);
      this.drawAttributeRate(actor.rec, dx, dy, dw);
      break;
    case "pha":
      this.drawAttributeName(Yanfly.Param.StatusAttr_pha, dx, dy, dw);
      this.drawAttributeRate(actor.pha, dx, dy, dw);
      break;
    case "mcr":
      this.drawAttributeName(Yanfly.Param.StatusAttr_mcr, dx, dy, dw);
      this.drawAttributeRate(actor.mcr, dx, dy, dw);
      break;
    case "tcr":
      this.drawAttributeName(Yanfly.Param.StatusAttr_tcr, dx, dy, dw);
      this.drawAttributeRate(actor.tcr, dx, dy, dw);
      break;
    case "pdr":
      this.drawAttributeName(Yanfly.Param.StatusAttr_pdr, dx, dy, dw);
      this.drawAttributeRate(actor.pdr, dx, dy, dw);
      break;
    case "mdr":
      this.drawAttributeName(Yanfly.Param.StatusAttr_mdr, dx, dy, dw);
      this.drawAttributeRate(actor.mdr, dx, dy, dw);
      break;
    case "fdr":
      this.drawAttributeName(Yanfly.Param.StatusAttr_fdr, dx, dy, dw);
      this.drawAttributeRate(actor.fdr, dx, dy, dw);
      break;
    case "exr":
      this.drawAttributeName(Yanfly.Param.StatusAttr_exr, dx, dy, dw);
      this.drawAttributeRate(actor.exr, dx, dy, dw);
      break;
    default:
      break;
  }
};

Window_StatusInfo.prototype.drawAttributeName = function (name, dx, dy, dw) {
  this.changeTextColor(this.systemColor());
  dx += this.textPadding();
  dw -= this.textPadding() * 2;
  if (this.drawSplitIcon(name, dx, dy, dw)) {
    dx += Window_Base._iconWidth + 4;
    dw -= Window_Base._iconWidth + 4;
    name = name.replace(/\\I\[(\d+)\]/i, "");
  }
  dy += Math.floor((this.standardFontSize() - this.contents.fontSize) / 2);
  this._bypassResetText = true;
  this.changeTextColor(this.systemColor());
  this.drawTextEx(name, dx, dy, dw);
  this._bypassResetText = false;
};

Window_StatusInfo.prototype.drawAttributeRate = function (rate, dx, dy, dw) {
  var value = (rate * 100).toFixed(Yanfly.Param.StatusAttrDec) + "%";
  this.setRateColor(rate);
  this.drawAttributeValue(value, dx, dy, dw);
};

Window_StatusInfo.prototype.drawAttributeValue = function (value, dx, dy, dw) {
  dx += this.textPadding();
  dw -= this.textPadding() * 2;
  this.drawText(value, dx, dy, dw, "right");
};

Window_StatusInfo.prototype.maxPageItems = function () {
  return this.maxItems();
};

Window_Selectable.prototype.maxItems = function () {
  return 1;
};

Window_StatusInfo.prototype.drawItem = function (index) {
  this.clearItem(index);
};

Window_StatusInfo.prototype.drawAllItems = function () {
  var topIndex = this.topIndex();
  for (var i = 0; i < this.maxPageItems(); i++) {
    var index = topIndex + i;
    if (index < this.maxItems()) {
      this.drawItem(index);
    }
  }
};

//=============================================================================
// Scene_Status
//=============================================================================

Scene_Status.prototype.create = function () {
  Scene_MenuBase.prototype.create.call(this);
  this.createHelpWindow();
  this.createCommandWindow();
  this.createStatusWindow();
  this.createInfoWindow();
  this.refreshActor();
};

Scene_Status.prototype.refreshActor = function () {
  var actor = this.actor();
  this._statusWindow.setActor(actor);
  this._commandWindow.setActor(actor);
  this._helpWindow.setText(actor.profile());
  this._infoWindow.setActor(actor);
};

Scene_Status.prototype.onActorChange = function () {
  this.refreshActor();
  this._commandWindow.activate();
};

Scene_Status.prototype.createCommandWindow = function () {
  this._commandWindow = new Window_StatusCommand();
  this._commandWindow.x = 0;
  this._commandWindow.y = this._helpWindow.height;
  this.setCommandWindowHandlers();
  this.addWindow(this._commandWindow);
};

Scene_Status.prototype.setCommandWindowHandlers = function () {
  this._commandWindow.setHandler("cancel", this.popScene.bind(this));
  this._commandWindow.setHandler("pagedown", this.nextActor.bind(this));
  this._commandWindow.setHandler("pageup", this.previousActor.bind(this));
};

Scene_Status.prototype.createStatusWindow = function () {
  var wx = this._commandWindow.width;
  var wy = this._helpWindow.height;
  var ww = Graphics.boxWidth - wx;
  var wh = this._commandWindow.height;
  this._statusWindow = new Window_SkillStatus(wx, wy, ww, wh);
  this.addWindow(this._statusWindow);
};

Scene_Status.prototype.createInfoWindow = function () {
  var wy = this._helpWindow.height + this._commandWindow.height;
  this._infoWindow = new Window_StatusInfo(wy, this._commandWindow);
  this._commandWindow.setInfoWindow(this._infoWindow);
  this.addWindow(this._infoWindow);
  this._infoWindow.setHandler("cancel", this.onInfoCancel.bind(this));
};

Scene_Status.prototype.onInfoCancel = function () {
  this._commandWindow.activate();
  this._infoWindow.deselect();
};

//=============================================================================
// Utilities
//=============================================================================

Yanfly.Util = Yanfly.Util || {};

if (!Yanfly.Util.toGroup) {
  Yanfly.Util.toGroup = function (inVal) {
    return inVal;
  };
}

//=============================================================================
// End of File
//=============================================================================

repo_name: dazed/translations

license: unknown