Advertisement
Zalerinian

ExtText

Oct 23rd, 2015
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  //=============================================================================
  2.  // Plugin: External Text
  3.  // Author: Zalerinian
  4.  // Version: 1.0.0
  5.  // License: http://creativecommons.org/licenses/by/4.0/
  6.  //=============================================================================
  7.  
  8.  /*:
  9.   * @plugindesc Use external files to load all the text in your game! Convenient for multi-language support!
  10.   * @author Zalerinian
  11.   *
  12.   * @param Text File
  13.   * @desc The default text file to load into the game.
  14.   * Default: text_en.json
  15.   * @default text_en.json
  16.   *
  17.   * @param Face File
  18.   * @desc The defaul file to load for predefined faces. This file should be in the text folder. Default: faces.json
  19.   * @default faces.json
  20.   *
  21.   * @param Text Folder
  22.   * @desc The folder to keep your text file(s). Make sure this folder exists! Default: data/text/
  23.   * @default data/text/
  24.   *
  25.   * @param Autofit Text
  26.   * @desc Automatically resize text to fit on the screen.
  27.   * @default true
  28.   *
  29.   * @param Remember Color
  30.   * @desc Remember the last text color used in a conversation, in case the line wrapping puts it on a new page.
  31.   * @default true
  32.   *
  33.   * @param Enable Name Window
  34.   * @desc Enable or disable the nameox from being created. Set this to false if you don't intend to use the namebox.
  35.   * @default true
  36.   *
  37.   * @param Name Window Margin
  38.   * @desc Code that returns the number of pixels there should be between the name window and side of the game screen.
  39.   * @default return Graphics.width / 5 - this.width / 2
  40.   *
  41.   * @help
  42.   * =============================================================================
  43.   *    Dependencies
  44.   * =============================================================================
  45.   *
  46.   * This plugin requires the MVCommons community core plugin, version 1.0.3 or
  47.   * above.
  48.   *
  49.   * =============================================================================
  50.   *    Introduction
  51.   * =============================================================================
  52.   *
  53.   * The external text script will allow you to take all the text outside of the
  54.   * game editor, and put it in a nicely-formatted JSON file. To learn more about
  55.   * the JSON format, online resources are available to show how to use it. For
  56.   * example, https://en.wikipedia.org/wiki/JSON#Samples
  57.   *
  58.   * This plugin is an MV edition of Enelvon's popular External Text script for
  59.   * RPG Maker VX Ace.
  60.   *
  61.   * =============================================================================
  62.   *    Using faces
  63.   * =============================================================================
  64.   *
  65.   * The External text plugin allows you to define a face to use with each bit of
  66.   * text. In text file, in the key you wish to set up, simply add a "face"
  67.   * section, with a set of curly braces( {} ) as the value. Inside these curly
  68.   * braces, you must define the type (actor, party, or predefined), the ID for
  69.   * the selected types (Actor and Party must be numbers, predefined depends on
  70.   * they key set in the faces file). The ID for Actor and Party starts at 1.
  71.   * Additionally, you must also supply an index used to determine which face in
  72.   * the faceset to use. Indexes range from 0-7.
  73.   *
  74.   * =============================================================================
  75.   *    Controlling the window
  76.   * =============================================================================
  77.   *
  78.   * In order to control the position and appearance of the text window, you need
  79.   * to add a "window" section. In this section, you can define values for the
  80.   * "background" and "position" fields. The values for these are the same as
  81.   * those you would set in the editor.
  82.   *
  83.   * For example, "background" can be set to "dim" or "transparent" for the black
  84.   * background, or no background respectively. Any other values will result in
  85.   * the window looking like a regular window. The values are case-insensitive.
  86.   *
  87.   * =============================================================================
  88.   *    Plugin Commands
  89.   * =============================================================================
  90.   *
  91.   * External Text provides the user with a few plugin commands to use. All
  92.   * commands must begin with ExternalText (case-insensitive), and may contain an
  93.   * underscore (_) or hyphen (-) between the words, if you wish. They are
  94.   * optional.
  95.   *
  96.   * External Text has 3 plugin commands, show, load text, and load face.
  97.   *
  98.   * "show" will display the text and apply all properties of the text key that
  99.   * follows it. Text keys CAN have spaces in them.
  100.   *
  101.   * "load text" is used to change the text file of the game in an event. The
  102.   * text file's name should come after "text", and may contain spaces. The
  103.   * .json file extension is optional.
  104.   *
  105.   * "load face" is used to change the face file of the game in an event. The
  106.   * face file's name should come after "face", and may contain spaces. The
  107.   * .json file extension is optional.
  108.   *
  109.   * =============================================================================
  110.   *    Additional Inputs
  111.   * =============================================================================
  112.   *
  113.   * Because the full effects of the External Text script, to control faces,
  114.   * position, and appearance, all come from a plugin command or call, the plugin
  115.   * also includes controls for choice input, number input, and item selection.
  116.   *
  117.   * =============================================================================
  118.   *    Setting up the choice window
  119.   * =============================================================================
  120.   *
  121.   * To use a choice window with a text key, the first step is to add a "choice"
  122.   * field to your text file. This will hold the settings for the choice window.
  123.   * The choice window supports the same values for "background" and "position"
  124.   * that the regular window has. In addition, the choice window requires at
  125.   * least "choice" and "variable" properties, with optional "default" and
  126.   * "cancel" properties to define which what the default selection is, and what
  127.   * happens if the user cancels the selection.
  128.   *
  129.   * The "variable" property for the message refers to a variable that will
  130.   * hold the index of the selected choice. Indexes start at 0, and range to
  131.   * <number of choices> - 1. Keep in mind that the first option is choice 0,
  132.   * indexes go up from there!
  133.   *
  134.   * Because the choice input is not set up directly in the editor, this variable
  135.   * must be used in conditional branches so that you can perform different
  136.   * actions based on the selected choice.
  137.   *
  138.   * The "choice" property should be an array of string values, holding the
  139.   * text for each choice. By default, RPG Maker MV only supports 6 choices in a
  140.   * choice selection. With External Text, however, there is no limit to the
  141.   * number of choices.
  142.   *
  143.   * The "default" property is the index (starting at 0) that will be highlighted
  144.   * by default.
  145.   *
  146.   * The "cancel" property is the index of the action to use when the selection is
  147.   * cancelled by the player. A value of -1 will disallow the player from
  148.   * cancelling the selection.
  149.   *
  150.   * If the "cancel" property is a valid value that allows the user to cancel the
  151.   * selection (any value from 0 to the <number of choices> - 1), and the user
  152.   * cancels the selection, this is the index that will be selected.
  153.   *
  154.   * =============================================================================
  155.   *    Setting up the number input window
  156.   * =============================================================================
  157.   *
  158.   * To set up a number input, the text key must have a "number" section with at
  159.   * least a "variable" and "digits" properties. There is an optional "dvar"
  160.   * property that may be used if the "digits" property is set to "variable"
  161.   *
  162.   * The "variable" property is the variable ID that will store the value of
  163.   * the number inputted.
  164.   *
  165.   * The "digits" field can be either a number, representing the number of digits
  166.   * that may be inputted, or the string "variable", indicating that the number
  167.   * of digits to be used can be found in a variable, with the ID stored in the
  168.   * "dvar" property.
  169.   *
  170.   * The "dvar" property is used when the "digits" property is set to "variable".
  171.   * "dvar" should be a variable ID that will hold the number of digits that may
  172.   * be inputted.
  173.   *
  174.   * =============================================================================
  175.   *    Setting up the item selection window
  176.   * =============================================================================
  177.   *
  178.   * Finally, the item input event command is also available. To use it, the text
  179.   * key must have a "number" section. There is are tw0 available option
  180.   * for the item selection command, "type", and "variable".
  181.   *
  182.   * The "variable" property is a variable ID that will hold the item ID, found
  183.   * in the database, after an item is picked, or 0 if the user cancels the
  184.   * selection.
  185.   *
  186.   * The "type" property is a string that may contain either "regular", "key",
  187.   * "hidden a", or "hidden b". These are all item types that are available in the
  188.   * engine by default. If you don't know what "hidden a" or "hidden b" are,
  189.   * please check the engine help file, as these are new.
  190.   *
  191.   */
  192.  
  193.  
  194.  
  195.   /**
  196.    * ==========================================================================
  197.    *
  198.    * Class.prototype.Function()
  199.    *
  200.    * @note
  201.    *
  202.    *
  203.    *
  204.    *
  205.    *
  206.    * ==========================================================================
  207.    */
  208.  
  209. var Imported = Imported || {};
  210.  
  211. var Zale = Zale || {};
  212. Zale.ExtText = Zale.ExtText || {};
  213.  
  214. (function(){
  215.   if(Imported["MVCommons"] && PluginManager.version("MVCommons", ">=", "1.0.3")) {
  216.     var author = [{
  217.       email: "support@razelon.com",
  218.       name: "Zalerinian",
  219.       website: "http://www.razelon.com"
  220.       }];
  221.     var v = PluginManager.register("ExternalText", "1.0.0", PluginManager.getBasicPlugin("ExternalText").description, author, "2015-10-23", ["MVCommons"], true);
  222.     if(v === undefined) {
  223.       throw new Error("Unable to load ExternalText due to mising dependencies!");
  224.     } else if (v === false){
  225.       PluginManager.printPlugin("ExternalText")
  226.       throw new Error("Unable to load ExternalText due to registration failure! Is there another version running?");
  227.     }
  228.   } else {
  229.     SceneManager.stop();
  230.     throw new Error("External Text requires some functionality of the MVCommons plugin!");
  231.   }
  232. })();
  233.  
  234. (function($){
  235.   "use strict";
  236.  
  237.   // ==========================================================================
  238.   //
  239.   // Parameter Setup
  240.   //  Sets up the parameters of the plugin and stores them in the ExtText
  241.   //  section of the Zale object.
  242.   //
  243.   // ==========================================================================
  244.   var params = PluginManager.parameters("ExtText");
  245.   Zale.ExtText.TEXTFILE    = params["Text File"];
  246.   Zale.ExtText.TEXTFOLDER  = params["Text Folder"];
  247.   Zale.ExtText.FACEFILE    = params["Face File"];
  248.   Zale.ExtText.AUTOFIT     = MVC.Boolean(params["Autofit Text"]);
  249.   Zale.ExtText.REMCOLOR    = MVC.Boolean(params["Remember Color"])
  250.   Zale.ExtText.NAMEENABLED = MVC.Boolean(params["Enabled Name Window"]);
  251.   Zale.ExtText.NAMEMARGIN  = Function(params["Name Window Margin"]);
  252.   Zale.ExtText.lastColor   = "#ffffff";
  253.  
  254.  
  255.   // ==========================================================================
  256.   //
  257.   // String.prototype.endsWith Polyfill
  258.   //  This block of code ensures that if the browser using this script doesn't
  259.   //  support the .endsWith function, that it will be made compatible by
  260.   //  adding out own implementation of the function.
  261.   //
  262.   // ==========================================================================
  263.   if (!String.prototype.endsWith) {
  264.    String.prototype.endsWith = function(searchString, position) {
  265.        var subjectString = this.toString();
  266.        if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
  267.          position = subjectString.length;
  268.        }
  269.        position -= searchString.length;
  270.        var lastIndex = subjectString.indexOf(searchString, position);
  271.        return lastIndex !== -1 && lastIndex === position;
  272.    };
  273.   }
  274.  
  275.   /**
  276.    * ==========================================================================
  277.    *
  278.    * Game_System.prototype.initialize()
  279.    *
  280.    * @note
  281.    *  Sets the default text and face files, and then loads them using
  282.    *  their respective methods.
  283.    *
  284.    * ==========================================================================
  285.    */
  286.   Zale.ExtText.GSYS_init_TEng2kfuj = Game_System.prototype.initialize;
  287.   Game_System.prototype.initialize = function() {
  288.     Zale.ExtText.GSYS_init_TEng2kfuj.call(this);
  289.     this._textFile = Zale.ExtText.TEXTFILE;
  290.     this._faceFile = Zale.ExtText.FACEFILE;
  291.   }
  292.  
  293.   /**
  294.     * ==========================================================================
  295.     *
  296.     * Game_System.prototype.textFile
  297.     *
  298.     * @note
  299.     *  Defines the getters and setters for the textFile property of Game_System.
  300.     *  This does not change the file loaded, and only the file to load when
  301.     *  loading a save. This is called internally by TextManager.loadTextFile.
  302.     *
  303.     * ==========================================================================
  304.     */
  305.   Object.defineProperty(Game_System.prototype, "textFile", {
  306.     get: function() {
  307.       return this._textFile;
  308.     },
  309.  
  310.     set: function(value) {
  311.       this._textFile = value;
  312.     },
  313.     configurable: true
  314.   });
  315.  
  316.   /**
  317.    * ==========================================================================
  318.    * Game_System.prototype.faceFile
  319.    *
  320.    * @note
  321.    *  Defines the getters and setters for the faceFile property of Game_System.
  322.    *  This doesn't change the faces loaded, only the file to load when loading
  323.    *  a save. The faces file outlines the predefined faces that may be used
  324.    *  with text keys, and can easily be switched to a different file for
  325.    *  dynamic character costumes. This is called internally by
  326.    *  TextManager.loadFaceFile.
  327.    *
  328.    * ==========================================================================
  329.    */
  330.   Object.defineProperty(Game_System.prototype, "faceFile", {
  331.     get: function() {
  332.       return this._faceFile;
  333.     },
  334.  
  335.     set: function(value) {
  336.       this._faceFile = value;
  337.     },
  338.     configurable: true
  339.   });
  340.  
  341.  
  342.   // ==========================================================================
  343.   //    DataManager
  344.   // ==========================================================================
  345.  
  346.   /**
  347.    * ==========================================================================
  348.    *
  349.    * DataManager.loadGameWithoutRescue()
  350.    *
  351.    * @note
  352.    *  Loads the sotred text and face files on load so that the data is ready
  353.    *  to go once a game is loaded!
  354.    *
  355.    * ==========================================================================
  356.    */
  357.   Zale.ExtText.DM_lgwr_RTVIOwnoSNC4b9 = DataManager.loadGameWithoutRescue;
  358.   DataManager.loadGameWithoutRescue = function(id) {
  359.     var r = Zale.ExtText.DM_lgwr_RTVIOwnoSNC4b9.call(this, id);
  360.     if(!r) {
  361.       return r;
  362.     }
  363.     console.trace("Loading the game!");
  364.     if(typeof $gameSystem.textFile !== 'string') {
  365.       $gameSystem.textFile = Zale.ExtText.TEXTFILE;
  366.     }
  367.     if(typeof $gameSystem.faceFile !== 'string') {
  368.       $gameSystem.faceFile = Zale.ExtText.FACEFILE;
  369.     }
  370.     TextManager.loadTextFile($gameSystem.textFile);
  371.     TextManager.loadFaceFile($gameSystem.faceFile);
  372.     return true;
  373.   }
  374.  
  375.   /**
  376.    * ==========================================================================
  377.    *
  378.    * DataManager.createGameObjects()
  379.    *
  380.    * @note
  381.    *  Aliases the createGameObjects function to also load in the default
  382.    *  text and face files into $gameSystem.
  383.    *
  384.    * ==========================================================================
  385.    */
  386.   Zale.ExtText.DM_cgo_vpioivnOIEUV5 = DataManager.createGameObjects;
  387.   DataManager.createGameObjects = function() {
  388.     Zale.ExtText.DM_cgo_vpioivnOIEUV5.call(this);
  389.     TextManager.loadTextFile($gameSystem.textFile);
  390.     TextManager.loadFaceFile($gameSystem.faceFile);
  391.   }
  392.  
  393.  
  394.   // ==========================================================================
  395.   //    Window Command
  396.   // ==========================================================================
  397.  
  398.   /**
  399.    * ==========================================================================
  400.    *
  401.    * Window_Command.prototype.commandName(number index)
  402.    *
  403.    * @param index The index of the command who's name is requested.
  404.    *
  405.    * @note
  406.    *  Aliases commandName to force the command name to do through the
  407.    *  convertEscapeCharacters function, to convert any text codes we ma have.
  408.    *
  409.    * ==========================================================================
  410.    */
  411.   Zale.ExtText.WCommand_cn_cnoSIcnr = Window_Command.prototype.commandName;
  412.   Window_Command.prototype.commandName = function(index) {
  413.     return this.convertEscapeCharacters(Zale.ExtText.WCommand_cn_cnoSIcnr.call(this, index));
  414.   }
  415.  
  416.   // ==========================================================================
  417.   //    Window Message
  418.   // ==========================================================================
  419.  
  420.   /**
  421.    * ==========================================================================
  422.    *
  423.    * Window_Base.prototype.convertEscapeCharacters(string text)
  424.    *
  425.    * @note
  426.    *  This aliased function is responsible for replacing the \t[key] text codes
  427.    *  with the text from the given key.
  428.    *
  429.    * ==========================================================================
  430.    */
  431.   Zale.ExtText.WBase_cec_VNOCxoiwrv1 = Window_Base.prototype.convertEscapeCharacters
  432.   Window_Base.prototype.convertEscapeCharacters = function(text) {
  433.     text = text.replace(/\\/g, '\x1b');
  434.     text = text.replace(/\x1b\x1b/g, '\\');
  435.     text = text.replace(/\x1bt\[(.+?)\]/g, function(){
  436.       return TextManager.text(arguments[1]);
  437.     });
  438.     return Zale.ExtText.WBase_cec_VNOCxoiwrv1.call(this, text);
  439.   }
  440.  
  441.   /**
  442.    * ==========================================================================
  443.    *
  444.    * Window_Message.prototype.createSubWindows()
  445.    *
  446.    * @note
  447.    *  Aliases the createSubWindows method to additionally call the
  448.    *  createNameWindow function if the name window is enabled.
  449.    *
  450.    * ==========================================================================
  451.    */
  452.   Zale.ExtText.WMessage_csw_OIcnblwkCn2rrc = Window_Message.prototype.createSubWindows;
  453.   Window_Message.prototype.createSubWindows = function() {
  454.     Zale.ExtText.WMessage_csw_OIcnblwkCn2rrc.call(this);
  455.     if(Zale.ExtText.NAMEENABLED){
  456.       this.createNameWindow();
  457.     }
  458.   }
  459.  
  460.   /**
  461.    * ==========================================================================
  462.    *
  463.    * Window_Message.prototype.updatePlacement()
  464.    *
  465.    * @note
  466.    *  Aliases the updatePlacement function to also call the name subwindow's
  467.    *  "proprietary" updatePlacement function, but only if the name window is
  468.    *  enabled.
  469.    *
  470.    * ==========================================================================
  471.    */
  472.   Zale.ExtText.WMessage_uplace_YGWfgcognvop42nc = Window_Message.prototype.updatePlacement;
  473.   Window_Message.prototype.updatePlacement = function() {
  474.     Zale.ExtText.WMessage_uplace_YGWfgcognvop42nc.call(this);
  475.     if(Zale.ExtText.NAMEENABLED) {
  476.       this._nameWindow.updatePlacement(this);
  477.     }
  478.   }
  479.  
  480.   /**
  481.    * ==========================================================================
  482.    *
  483.    * Window_Message.prototype.terminateMessage()
  484.    *
  485.    * @note
  486.    *  Aliases the terminateMessage function to also close the name subwindow,
  487.    *  if the name window is enabled.
  488.    *
  489.    * ==========================================================================
  490.    */
  491.   Zale.ExtText.WMessage_term_ZNGIOiwofnoizr222cn = Window_Message.prototype.terminateMessage;
  492.   Window_Message.prototype.terminateMessage = function() {
  493.     Zale.ExtText.WMessage_term_ZNGIOiwofnoizr222cn.call(this);
  494.     if(Zale.ExtText.NAMEENABLED){
  495.       this._nameWindow.close();
  496.     }
  497.   }
  498.  
  499.   /**
  500.    * ==========================================================================
  501.    *
  502.    * Window_Message.prototype.startMessage()
  503.    *
  504.    * @note
  505.    *  Aliases the startMessage function to check if Autofit Text should be
  506.    *  enabled. If Autofit is enabled, the text in the textState object is
  507.    *  set to the text returned by the TextManager.resizeText function.
  508.    *
  509.    * ==========================================================================
  510.    */
  511.   Zale.ExtText.WMessage_startm_NIOVnoind = Window_Message.prototype.startMessage;
  512.   Window_Message.prototype.startMessage = function() {
  513.     Zale.ExtText.WMessage_startm_NIOVnoind.call(this);
  514.     if(Zale.ExtText.AUTOFIT) {
  515.       var lines = TextManager.resizeText(this._textState.text, this.contentsWidth() - this._textState.left)
  516.       this._textState.text = lines.join("\n");
  517.     }
  518.   }
  519.  
  520.   /**
  521.    * ==========================================================================
  522.    * Window_Message.prototype.changeTextColor(string color)
  523.    *
  524.    * @note
  525.    *  Aliases the changeTextColor function in Window_Message. In addition to
  526.    *  its regular duties, if the Remember Color option was set to true in the
  527.    *  plugin's configuration, this will set the value Zale.ExtText.lastcolor
  528.    *  in order to retain the last color used in text pages.
  529.    *
  530.    * ==========================================================================
  531.    */
  532.   Zale.ExtText.WMessage_ctc_IONciowvn8hnanovi = Window_Message.prototype.changeTextColor;
  533.   Window_Message.prototype.changeTextColor = function(color) {
  534.     if(Zale.ExtText.REMCOLOR) {
  535.       Zale.ExtText.lastColor = this.contents.textColor;
  536.     }
  537.     Zale.ExtText.WMessage_ctc_IONciowvn8hnanovi.call(this, color);
  538.   }
  539.  
  540.   /**
  541.    * ==========================================================================
  542.    * Window_Message.prototype.resetFontSettings()
  543.    *
  544.    * @note
  545.    *  Aliases the resetFontSettings function. After resetting all the font
  546.    *  settings to their defaults, the alias will check if the last text color
  547.    *  was remembered. If it was, the window's text color will be set to the
  548.    *  last color that was stored in the settings.
  549.    *
  550.    * ==========================================================================
  551.    */
  552.   Zale.ExtText.WMessage_rfs_NOIsionwiocn240 = Window_Message.prototype.resetFontSettings;
  553.   Window_Message.prototype.resetFontSettings = function() {
  554.     Zale.ExtText.WMessage_rfs_NOIsionwiocn240.call(this);
  555.     if(Zale.ExtText.REMCOLOR) {
  556.       this.contents.textColor = Zale.ExtText.lastColor;
  557.     }
  558.   }
  559.  
  560.   /**
  561.    * ==========================================================================
  562.    * Window_Message.prototype.processEscapeCharacter(string code,
  563.    *    object textState)
  564.    *
  565.    * @note
  566.    *  Aliases the processEscapeCharacter function. This alias allows you to
  567.    *  set the name in the namebox in the text. This will only have an affect
  568.    *  if the namebox is enabled.
  569.    *
  570.    * ==========================================================================
  571.    */
  572.   Zale.ExtText.WMessage_pec_NOCionoi2rgnioo = Window_Message.prototype.processEscapeCharacter;
  573.   Window_Message.prototype.processEscapeCharacter = function(code, textState) {
  574.     if(Zale.ExtText.NAMEENABLED && code.toLowerCase() === 'n') {
  575.       var substr = textState.text.substring(textState.index);
  576.       if(/<([.\s\S]*?)>/m.test(substr)) {
  577.         var match = /<([.\s\S]*?)>/m.exec(substr);
  578.         textState.index += match[0].length;
  579.         this.setName(this.convertEscapeCharacters(match[1]));
  580.       }
  581.     }
  582.     Zale.ExtText.WMessage_pec_NOCionoi2rgnioo.call(this, code, textState);
  583.   }
  584.  
  585.   /**
  586.    * ==========================================================================
  587.    * Window_Message.prototype.newPage(object textState)
  588.    *
  589.    * @note
  590.    *  If the return value of Game_Message.prototype.characterName (defined
  591.    *  below) is not null, and the name window exists, then we set the name
  592.    *  for the name window here.
  593.    *
  594.    * ==========================================================================
  595.    */
  596.  
  597.   Zale.ExtText.WMessage_npage_NCOWOFNdoon = Window_Message.prototype.newPage;
  598.   Window_Message.prototype.newPage = function(textState) {
  599.     Zale.ExtText.WMessage_npage_NCOWOFNdoon.call(this, textState);
  600.     if(this._nameWindow && $gameMessage.characterName()) {
  601.       this.setName($gameMessage.characterName());
  602.     }
  603.   }
  604.  
  605.   /**
  606.    * ==========================================================================
  607.    * Window_Message.prototype.createNamewindow()
  608.    *
  609.    * @note
  610.    *  Creates the name window and sets its initial position based on the
  611.    *  message window's. The window is added as a separate child from the
  612.    *  window layer, because the name window overlaps the message window, and
  613.    *  this can cause issues with windowskins that have rounded corners, as the
  614.    *  transparent pixels on the corners would overwrite the windows drawn
  615.    *  before.
  616.    *  This is an issue directly with Pixi.js, and thus no easy solution is
  617.    *  available.
  618.    *
  619.    * ==========================================================================
  620.    */
  621.   Window_Message.prototype.createNameWindow = function() {
  622.     this._nameWindow = new Window_Help(1);
  623.     this._nameWindow.openness = 0;
  624.     this._nameWindow.updatePlacement = function(parent) {
  625.       this.x = Zale.ExtText.NAMEMARGIN.bind(this)();
  626.       if(parent.y > 0) {
  627.         this.y = parent.y - this.height / 1.5;
  628.       } else {
  629.         this.y = parent.height - this.height / 1.5;
  630.       }
  631.     }
  632.     SceneManager._scene.addChild(this._nameWindow);
  633.   }
  634.  
  635.   /**
  636.    * ==========================================================================
  637.    * Window_Message.prototype.closeName()
  638.    *
  639.    * @note
  640.    *  If the name window exists, it is closed using Window_Base's close
  641.    *  function. This provides us with the little closing animation.
  642.    *
  643.    * ==========================================================================
  644.    */
  645.   Window_Message.prototype.closeName = function() {
  646.     if(this._nameWindow){
  647.       this._nameWindow.close();
  648.     }
  649.   }
  650.  
  651.   /**
  652.    * ==========================================================================
  653.    * Window_Message.prototype.setName(string name)
  654.    *
  655.    * @note
  656.    *  If the messae window exists, this function sets its text to the given
  657.    *  string, and resizes and repositions the window to accomodate the text.
  658.    *
  659.    * ==========================================================================
  660.    */
  661.   Window_Message.prototype.setName = function(name) {
  662.     if(this._nameWindow){
  663.       this._nameWindow.width = this._nameWindow.textWidth(name) + 8 + this.padding * 2;
  664.       this._nameWindow.setText(name);
  665.       this._nameWindow.updatePlacement(this);
  666.       this._nameWindow.open();
  667.     }
  668.   }
  669.  
  670.  
  671.  
  672.  
  673.   // ==========================================================================
  674.   //    Game Message
  675.   // ==========================================================================
  676.  
  677.   /**
  678.    * ==========================================================================
  679.    *
  680.    * Game_Message.prototype.clear()
  681.    *
  682.    * @note
  683.    *  Aliases Game_Message's clear method. This sets the _characterName
  684.    *  property to null, signalling that there should be no name window
  685.    *  present with the current message.
  686.    *
  687.    * ==========================================================================
  688.    */
  689.   Zale.ExtText.GMessage_clr_Zoqbop429dncqnf = Game_Message.prototype.clear;
  690.   Game_Message.prototype.clear = function() {
  691.     Zale.ExtText.GMessage_clr_Zoqbop429dncqnf.call(this);
  692.     this._characterName = null;
  693.   }
  694.  
  695.   /**
  696.    * ==========================================================================
  697.    *
  698.    * Game_Message.prototype.setCharacterName(string name)
  699.    *
  700.    * @note
  701.    *  Sets the _characterName property to the given string, which will be
  702.    *  displayed in the name window, if it is enabled.
  703.    *
  704.    * ==========================================================================
  705.    */
  706.   Game_Message.prototype.setCharacterName = function(name) {
  707.     this._characterName = name;
  708.   }
  709.  
  710.   /**
  711.    * ==========================================================================
  712.    *
  713.    * Game_Message.prototype.characterName()
  714.    *
  715.    * @note
  716.    *  Returns the current calue of the _characterName property.
  717.    *
  718.    * @return A string containing the current name for the name window.
  719.    *
  720.    * ==========================================================================
  721.    */
  722.   Game_Message.prototype.characterName = function() {
  723.     return this._characterName;
  724.   }
  725.  
  726.  
  727.   // ==========================================================================
  728.   //    Game Interpeter
  729.   // ==========================================================================
  730.  
  731.   /**
  732.    * ==========================================================================
  733.    *
  734.    * Game_Inptereter.prototype.pluginCommand()
  735.    *
  736.    * @note
  737.    *  Allows the game developer to show text by using a plugin command
  738.    *  starting with ExternalText, with the first argument being the text key
  739.    *  to display.
  740.    *
  741.    * ==========================================================================
  742.    */
  743.   Zale.ExtText.GI_pcom_OISqs1cdkjz = Game_Interpreter.prototype.pluginCommand;
  744.   Game_Interpreter.prototype.pluginCommand = function(command, args) {
  745.     if(command.match(/External[_-]*Text/i)) {
  746.       if(args.length > 0){
  747.         if(args[0].toLowerCase() == "show") {
  748.           TextManager.displayMessage(args.slice(1).join(" "));
  749.           this.setWaitMode('message');
  750.         } else if(args[0].toLowerCase() == "load") {
  751.           if(args[1] == "text") {
  752.             TextManager.loadTextFile(args.slice(2).join(" "));
  753.           } else if(args[1] == "face") {
  754.             TextManager.loadFaceFile(args.slice(2).join(" "));
  755.           }
  756.         }
  757.       }
  758.     }
  759.   }
  760.  
  761.   /**
  762.    * ==========================================================================
  763.    *
  764.    * Game_Interpreter.prototype.showText()
  765.    *
  766.    * @note
  767.    *  A method to add to the Game_Interpretter class so as to give people who
  768.    *  prefer the old way of interacting with plugins a way to use the
  769.    *  External Text script.
  770.    *
  771.    *
  772.    * ==========================================================================
  773.    */
  774.   Game_Interpreter.prototype.showText = function(key) {
  775.     TextManager.displayMessage(key);
  776.     this.setWaitMode('message');
  777.   }
  778.  
  779.  
  780.   // ==========================================================================
  781.   //    TextManager
  782.   // ==========================================================================
  783.  
  784.   /**
  785.    * ==========================================================================
  786.    *
  787.    * TextManager.convertTextCode(string text)
  788.    *
  789.    * @params text The text to check for a text code to convert.
  790.    *
  791.    * @note
  792.    *  This will check teh given text for the text code, \t[key]. If the code
  793.    *  is found, the code is replaced with the text for that particular key.
  794.    *
  795.    * @return The text, with any text codes replaced.
  796.    *
  797.    * ==========================================================================
  798.    */
  799.   $.convertTextCode = function(text) {
  800.     text = text.replace(/\\/g, '\x1b');
  801.     text = text.replace(/\x1b\x1b/g, '\\');
  802.     text = text.replace(/\x1bt\[(.+?)\]/g, function(){
  803.       return TextManager.text(arguments[1]);
  804.     });
  805.     return text;
  806.   }
  807.  
  808.   /**
  809.    * ==========================================================================
  810.    *
  811.    * TextManager.getter(string method, mixed param)
  812.    *
  813.    * @param method A string indicating which function to call.
  814.    * @param param A value specific to each method to get the desired result.
  815.    *
  816.    * @note
  817.    *  This OVERWRITES the default TextManager.getter to force the text in the
  818.    *  messages section of the Systems tab in the database to be checked for
  819.    *  text codes.
  820.    *
  821.    * @return An object that is used in Object.defineProperty.
  822.    *
  823.    * ==========================================================================
  824.    */
  825.   $.getter = function(method, param) {
  826.     return {
  827.       get: function() {
  828.         return this.__hepWindow.convertTextCode(this[method](param));
  829.       },
  830.       configurable: true
  831.     };
  832.   };
  833.  
  834.  
  835.   /**
  836.    * ==========================================================================
  837.    *
  838.    * TextManager.resizeText(string text, int maxWidth, ?bitmap measure)
  839.    *
  840.    * @param text The text to resize
  841.    * @param maxWidth The max width that the text should fit in
  842.    * @param measure A bitmap with which to meaure text size. Optional.
  843.    *
  844.    * @note
  845.    *  Takes the given text and resizes it by splitting it by word, or letter
  846.    *  if absolutely needed, to fit within the given width. The result is
  847.    *  returned as an array.
  848.    *
  849.    * @return An array of strings.
  850.    *
  851.    * ==========================================================================
  852.    */
  853.   $.resizeText = function(text, maxWidth, measure) {
  854.     if(!maxWidth) {
  855.       throw new Error("No max width given!");
  856.     }
  857.     if(!(measure instanceof Bitmap)) {
  858.       measure = new Bitmap(1, 1);
  859.     }
  860.     var words = text.split(" ");
  861.     var lines = [];
  862.     var line = "";
  863.     var length = 0;
  864.     for(var i = 0; i < words.length; i++) {
  865.       var word = words[i];
  866.       if(measure.measureTextWidth(word) > maxWidth) {
  867.         for(var j = 0; j < word.length; j++) {
  868.           if(length + measure.measureTextWidth(word[j] + "-") > maxWidth) {
  869.             lines.push(line + "-");
  870.             line = word[j];
  871.             length = measure.measureTextWidth(line);
  872.           } else {
  873.             length += measure.measureTextWidth(word[j]);
  874.             line += word[j];
  875.           }
  876.         }
  877.       } else if(length + measure.measureTextWidth(word + " ") > maxWidth) {
  878.         lines.push(line.trim());
  879.         line = word + " ";
  880.         length = measure.measureTextWidth(line);
  881.       } else {
  882.         length += measure.measureTextWidth(word + " ");
  883.         line += word + " ";
  884.       }
  885.     }
  886.     lines.push(line);
  887.     return lines;
  888.   }
  889.  
  890.   /**
  891.    * ==========================================================================
  892.    *
  893.    * TextManager.loadTextFile(string file, ?function onLoad, ?function onError)
  894.    *
  895.    * @param file The text file to load.
  896.    * @param onLoad An optional function to be called after loading.
  897.    * @param onError An option function to be called on an error loading.
  898.    *
  899.    * @note
  900.    *  Loads the given filename from the predefined text folder and sets it as
  901.    *  the text.
  902.    *
  903.    * ==========================================================================
  904.    */
  905.   $.loadTextFile = function(file, onLoad, onError) {
  906.     if(!file.endsWith(".json")) {
  907.       file += ".json";
  908.     }
  909.     if($gameSystem) {
  910.       $gameSystem.textFile = file;
  911.     }
  912.     try {
  913.       this._text = JSON.parse(DataManager.ajaxLoadFile(Zale.ExtText.TEXTFOLDER + file));
  914.       if(typeof onLoad === 'function') {
  915.         onLoad.call(this);
  916.       }
  917.     } catch(e) {
  918.       console.error(e);
  919.       if(typeof onError === 'function') {
  920.         onError.call(this);
  921.       }
  922.     }
  923.   }
  924.  
  925.   /**
  926.    * ==========================================================================
  927.    *
  928.    * TextManager.loadFaceFile(string file, ?function onLoad, ?function onError)
  929.    *
  930.    * @param file The file to load for predefined faces, inside the text
  931.    *  folder.
  932.    * @param onLoad An optional function to be called on loading.
  933.    * @param onError An optional function to call if there was an error
  934.    *  loading.
  935.    *
  936.    * @note
  937.    *  Loads the specified file and sets it as the predefined faces file.
  938.    *
  939.    * ==========================================================================
  940.    */
  941.   $.loadFaceFile = function(file, onLoad, onError) {
  942.     if(!file.endsWith(".json")) {
  943.       file += ".json";
  944.     }
  945.     if($gameSystem) {
  946.       $gameSystem.faceFile = file;
  947.     }
  948.     try {
  949.       this._faces = JSON.parse(DataManager.ajaxLoadFile(Zale.ExtText.TEXTFOLDER + file));
  950.       if(typeof onLoad === 'function') {
  951.         onLoad.call(this);
  952.       }
  953.     } catch(e) {
  954.       console.error(e);
  955.       if(typeof onError === 'function') {
  956.         onError.call(this);
  957.       }
  958.     }
  959.   }
  960.  
  961.   /**
  962.    * ==========================================================================
  963.    *
  964.    * TextManager.text(string key)
  965.    *
  966.    * @param key The key name to get the text for.
  967.    *
  968.    * @note
  969.    *  Gets the text for the given key. If no key is found, an error message
  970.    *  is returned and printed to the console. If no file is loaded, an error
  971.    *  message is printed to the console, and undefined is returned.
  972.    *
  973.    * @return String on success, undefined on failure.
  974.    *
  975.    * ==========================================================================
  976.    */
  977.   $.text = function(key) {
  978.     if(!this._text) {
  979.       console.error("Attempt to get text before any text file is loaded!");
  980.       return undefined;
  981.     }
  982.     if(this._text[key]) {
  983.       return this._text[key].text;
  984.     } else {
  985.       return "No text found for '" + key + "'!";
  986.     }
  987.   }
  988.  
  989.   /**
  990.    * ==========================================================================
  991.    *
  992.    * TextManager.textObject(string key)
  993.    *
  994.    * @param key The key to load the text object of.
  995.    *
  996.    * @note
  997.    *  Loads the whle text object for the given key. Errors if there is no text
  998.    *  file loaded.
  999.    *
  1000.    * @return JS Object on success, undefine don failure.
  1001.    *
  1002.    * ==========================================================================
  1003.    */
  1004.   $.textObject = function(key) {
  1005.     if(!this._text) {
  1006.       console.error("Attempt to get text before any text file is loaded!");
  1007.       return undefined;
  1008.     }
  1009.     if(this._text[key]) {
  1010.       return this._text[key];
  1011.     } else {
  1012.       return {text: "No text found for '" + key + "'!"}
  1013.     }
  1014.   }
  1015.  
  1016.   /**
  1017.    * ==========================================================================
  1018.    *
  1019.    * TextManager.displayMessage(string key)
  1020.    *
  1021.    * @param key A string representing the key to load
  1022.    *
  1023.    * @note
  1024.    *  Dispays the tet from the given key, and also checks for and sets up the
  1025.    *  faces, item selection, number input, and choice selection. Each
  1026.    *  branch in the setup calls it's own methods to get the data that will be
  1027.    *  set, and then another to actually set the data. This allows other
  1028.    *  plugins to have plenty of opportunities to interact and change how
  1029.    *  External Text works.
  1030.    *
  1031.    * ==========================================================================
  1032.    */
  1033.   $.displayMessage = function(key) {
  1034.     var data = this.textObject(key);
  1035.     if(data) {
  1036.       if(data.face) {
  1037.         this.setFace(this._processFace(data.face));
  1038.       }
  1039.       if(data.window) {
  1040.         if(data.window.background) {
  1041.           this.setWindowBackground(this._processWindowBackground(data.window.background));
  1042.         }
  1043.         if(data.window.position) {
  1044.           this.setWindowPosition(this._processWindowPosition(data.window.position));
  1045.         }
  1046.       }
  1047.  
  1048.       if(data.choice) {
  1049.         if(data.choice.background) {
  1050.           this.setChoiceBackground(this._processWindowBackground(data.choice.background));
  1051.         }
  1052.         if(data.choice.position) {
  1053.           this.setChoicePosition(this._processWindowPosition(data.choice.position));
  1054.         }
  1055.         var def = data.choice.default;
  1056.         var can = data.choice.cancel;
  1057.         this.setChoiceList(data.choice.variable, data.choice.choices, def ? def : 0, can ? can : -1);
  1058.       }
  1059.  
  1060.       if(data.number) {
  1061.         var digits = 0;
  1062.         if(typeof data.number.digits === "string" && data.number.digits.toLowerCase() === "variable"){
  1063.           digits = $gameVariables.value(data.number.dvar);
  1064.         } else {
  1065.           digits = data.number.digits;
  1066.         }
  1067.         this.setNumberInput(data.number.variable, digits);
  1068.       }
  1069.  
  1070.       if(data.item) {
  1071.         this.setItemInput(data.item.variable, this._processItemInput(data));
  1072.       }
  1073.  
  1074.       if(data.name) {
  1075.         $gameMessage.setCharacterName(data.name);
  1076.       } else {
  1077.         $gameMessage.setCharacterName(null);
  1078.       }
  1079.  
  1080.       $gameMessage.add(data.text);
  1081.     } else {
  1082.       $gameMessage.add("No text data found for " + key);
  1083.       console.error("No text data found for " + key);
  1084.     }
  1085.   }
  1086.  
  1087.   /**
  1088.    * ==========================================================================
  1089.    *
  1090.    * TextManager._processFace(object data)
  1091.    *
  1092.    * @param data A JS object containing face data
  1093.    *
  1094.    * @note
  1095.    *  Checks the values of the object to determine what face to display.
  1096.    *
  1097.    * @return An array containing the face file and index to display.
  1098.    *
  1099.    * ==========================================================================
  1100.    */
  1101.   $._processFace = function(data) {
  1102.     var face = ['', 0];
  1103.     switch(data.type.toLowerCase()) {
  1104.       case "actor":
  1105.         face = this._getActorFace(data);
  1106.         break;
  1107.       case "party":
  1108.         face = this._getPartyFace(data);
  1109.         break;
  1110.       case "predefined":
  1111.         face = this._getPredefinedFace(data);
  1112.         break;
  1113.       default:
  1114.         break;
  1115.     }
  1116.     return face;
  1117.   }
  1118.  
  1119.   /**
  1120.    * ==========================================================================
  1121.    *
  1122.    * TextManager._processItemInput(object data)
  1123.    *
  1124.    * @param data A JS object containing item input data
  1125.    *
  1126.    * @note
  1127.    *  Checks the values of the object to determine what items to display.
  1128.    *  1 is regular items, 2 is key items, 3 is hidden a items, and 4 is
  1129.    *  hidden b items.
  1130.    *
  1131.    * @return A number indicating the type of item to display.
  1132.    *
  1133.    * ==========================================================================
  1134.    */
  1135.   $._processItemInput = function(data) {
  1136.     var type = 1;
  1137.     switch(data.item.type.toLowerCase()) {
  1138.       case "regular":
  1139.         type = 1;
  1140.         break;
  1141.       case "key":
  1142.         type = 2;
  1143.         break;
  1144.       case "hidden a":
  1145.         type = 3;
  1146.         break;
  1147.       case "hidden b":
  1148.         type = 4;
  1149.         break;
  1150.     }
  1151.     return type;
  1152.   }
  1153.  
  1154.   /**
  1155.    * ==========================================================================
  1156.    *
  1157.    * TextManager._processWindowBackground(object data)
  1158.    *
  1159.    * @param data A JS object that contains window background data
  1160.    *
  1161.    * @note
  1162.    *  Checks the value of the object to determind what the background should
  1163.    *  be set as.
  1164.    *
  1165.    * @return An integer representing background type.
  1166.    *
  1167.    * ==========================================================================
  1168.    */
  1169.   $._processWindowBackground = function(data) {
  1170.     var type = 0;
  1171.     switch(data.toLowerCase()) {
  1172.       case "transparent":
  1173.         type = 2;
  1174.         break;
  1175.       case "dim":
  1176.         type = 1;
  1177.         break;
  1178.       default:
  1179.         type = 0;
  1180.         break;
  1181.     }
  1182.     return type;
  1183.   }
  1184.  
  1185.   /**
  1186.    * ==========================================================================
  1187.    *
  1188.    * TextManager._processWindowPosition(string data)
  1189.    *
  1190.    * @param data A string representing the position for the window.
  1191.    *
  1192.    * @note
  1193.    *  Based on the given string, the windows position will be placed on the
  1194.    *  top, middle, or bottom (default) of the screen.
  1195.    *
  1196.    * @return An integer used to set the window position.
  1197.    *
  1198.    * ==========================================================================
  1199.    */
  1200.   $._processWindowPosition = function(data) {
  1201.     var position = 2;
  1202.     switch(data.toLowerCase()) {
  1203.       case "top":
  1204.         position = 0;
  1205.         break;
  1206.       case "middle":
  1207.         position = 1;
  1208.         break;
  1209.       default:
  1210.         break;
  1211.     }
  1212.     return position;
  1213.   }
  1214.  
  1215.   /**
  1216.    * ==========================================================================
  1217.    *
  1218.    * TextManager._getActorFace(object data)
  1219.    *
  1220.    * @param data A JS object that contains data for the face to display.
  1221.    *
  1222.    * @note
  1223.    *  This funciton will return the image filename and index for the face to
  1224.    *  for the current message. If the actor with the given ID doesn't exist,
  1225.    *  then the retun values will both be undefined.
  1226.    *
  1227.    * @return An array of the face filename and index..
  1228.    *
  1229.    * ==========================================================================
  1230.    */
  1231.   $._getActorFace = function(data) {
  1232.     var face, index;
  1233.     if($gameActors.actor(data.id)) {
  1234.       face = $gameActors.actor(data.id).faceName();
  1235.       if(data.index){
  1236.         index = data.index;
  1237.       } else {
  1238.         index = $gameActors.actor(data.id).faceIndex();
  1239.       }
  1240.     }
  1241.     return [face, index];
  1242.   }
  1243.  
  1244.   /**
  1245.    * ==========================================================================
  1246.    *
  1247.    * TextManager._getPartyFace(object data)
  1248.    *
  1249.    * @param data A JS object that contains data for getting a face from a
  1250.    *  party memeber.
  1251.    *
  1252.    * @note
  1253.    *  Returns the image filename based on a current party member. If an index
  1254.    *  is not specified, the index of the face setup in the editor is used.
  1255.    *
  1256.    * @return An array of the image filename and index.
  1257.    *
  1258.    * ==========================================================================
  1259.    */
  1260.   $._getPartyFace = function(data) {
  1261.     var face, index;
  1262.     if(data.id) {
  1263.       var member = $gameParty.members[id - 1];
  1264.       face = member.faceName();
  1265.       if(data.index) {
  1266.         index = member.faceIndex();
  1267.       } else {
  1268.         index = data.index;
  1269.       }
  1270.     }
  1271.     return [face, index];
  1272.   }
  1273.  
  1274.   /**
  1275.    * ==========================================================================
  1276.    *
  1277.    * TextManager._getPredefinedFace(object data)
  1278.    *
  1279.    * @param data A JS object containing data for face in the faces file.
  1280.    *
  1281.    * @note
  1282.    *  Checks the given data to see what face should be picked from the faces
  1283.    *  file.
  1284.    *
  1285.    * @return An array of the image filename and index.
  1286.    *
  1287.    * ==========================================================================
  1288.    */
  1289.   $._getPredefinedFace = function(data) {
  1290.     var face, index;
  1291.     if(data.id) {
  1292.       if(this._faces[data.id]) {
  1293.         face  = this._faces[data.id].file;
  1294.         index = this._faces[data.id].index;
  1295.       }
  1296.     }
  1297.     return [face, index];
  1298.   }
  1299.  
  1300.   /**
  1301.    * ==========================================================================
  1302.    *
  1303.    * TextManager._getNormalFace(object data)
  1304.    *
  1305.    * @param data A JS object that contains data about a face for the message.
  1306.    *
  1307.    * @note
  1308.    *  Returns an array with the filename and index as defined in the data.
  1309.    *
  1310.    * @return An array of the image filename and index.
  1311.    *
  1312.    *
  1313.    * ==========================================================================
  1314.    */
  1315.   $._getNormalFace = function(data) {
  1316.     var face, index;
  1317.     if(data.id) {
  1318.       face  = data.id;
  1319.       index = data.index || 0;
  1320.     }
  1321.     return [face, index];
  1322.   }
  1323.  
  1324.   /**
  1325.    * ==========================================================================
  1326.    *
  1327.    * TextManager._getChoiceCallback()
  1328.    *
  1329.    * @note
  1330.    *  This function returns an anonymous function that is called when a choice
  1331.    *  has been made in the choice selection. The function takes one argument,
  1332.    *  the index of the choice selected (starting at 0);
  1333.    *
  1334.    * @return Returns a function that wil be called on choice selection.
  1335.    *
  1336.    * ==========================================================================
  1337.    */
  1338.   $._getChoiceCallback = function(v) {
  1339.     return function(branch) {
  1340.         $gameVariables.setValue(v, branch);
  1341.       }
  1342.   }
  1343.  
  1344.   /**
  1345.    * ==========================================================================
  1346.    *
  1347.    * TextManager.setWindowBackground(number type)
  1348.    *
  1349.    * @param type A number to represent the background type
  1350.    *
  1351.    * @note
  1352.    *  0 is normal, 1 is dim, any other number is transparent.
  1353.    *
  1354.    * ==========================================================================
  1355.    */
  1356.   $.setWindowBackground = function(type) {
  1357.     $gameMessage.setBackground(type);
  1358.   }
  1359.  
  1360.   /**
  1361.    * ==========================================================================
  1362.    *
  1363.    * TextManager.setChoiceBackground(number type)
  1364.    *
  1365.    * @param type A number to represen the background type
  1366.    *
  1367.    * @note
  1368.    *  0 is normal, 1 is dim, any otehr number is transparent.
  1369.    *
  1370.    * ==========================================================================
  1371.    */
  1372.   $.setChoiceBackground = function(type) {
  1373.     $gameMessage.setChoiceBackground(type);
  1374.   }
  1375.  
  1376.   /**
  1377.    * ==========================================================================
  1378.    *
  1379.    * TextManager.setWindowPosition(number pos)
  1380.    *
  1381.    * @param pos A number representing the position for the message window.
  1382.    *
  1383.    * @note
  1384.    *  0 is top, 1 is middle, 2 is bottom. Floats are also acceptable to
  1385.    *  further change the position of the window.
  1386.    *
  1387.    * ==========================================================================
  1388.    */
  1389.   $.setWindowPosition = function(pos) {
  1390.     $gameMessage.setPositionType(pos);
  1391.   }
  1392.  
  1393.   /**
  1394.    * ==========================================================================
  1395.    *
  1396.    * TextManager.setChoicePosition(number pos)
  1397.    *
  1398.    * @param pos An integer indicating the position of the choice window.
  1399.    *
  1400.    * @note
  1401.    *  Sets the position of the choice window.
  1402.    *  0 is left, 1 is middle, 2 is right.
  1403.    *
  1404.    * ==========================================================================
  1405.    */
  1406.   $.setChoicePosition = function(pos) {
  1407.     $gameMessage.setChoicePositionType(pos);
  1408.   }
  1409.  
  1410.   /**
  1411.    * ==========================================================================
  1412.    *
  1413.    * TextManager.Function()
  1414.    *
  1415.    * @param pos A number representing the position for the choice window.
  1416.    *
  1417.    * @note
  1418.    *  0 is left, 1 is middle, 2 is right. Floats are also acceptable to
  1419.    *  further change the position of the choice window.
  1420.    *
  1421.    * ==========================================================================
  1422.    */
  1423.   $.setChoiceList = function(v, list, def, can) {
  1424.     $gameMessage.setChoices(list, def, can);
  1425.     $gameMessage.setChoiceCallback(this._getChoiceCallback(v));
  1426.   }
  1427.  
  1428.   /**
  1429.    * ==========================================================================
  1430.    *
  1431.    * TextManager.setFace(array face)
  1432.    *
  1433.    * @param face An array containing a face filename and index
  1434.    *
  1435.    * @note
  1436.    *  Sets the face for the message window to display with the current text.
  1437.    *  The filename is expected to be the first element in the array, with the
  1438.    *  face index being the second.
  1439.    *
  1440.    * ==========================================================================
  1441.    */
  1442.   $.setFace = function(face) {
  1443.     $gameMessage.setFaceImage(face[0], face[1]);
  1444.   }
  1445.  
  1446.   /**
  1447.    * ==========================================================================
  1448.    *
  1449.    * TextManager.setNumberInput(number v, number digits)
  1450.    *
  1451.    * @param v The variable number to store the result in
  1452.    * @params digits The number of digits to allow the input to be.
  1453.    *
  1454.    * @note
  1455.    *  Sets the values eneded for number input in $gameMessage. The
  1456.    *  Game_Message class handles what types of input to display with the text
  1457.    *  itself, depending on what values are set (Number input, Item selection,
  1458.    *  or the choice window).
  1459.    *
  1460.    * ==========================================================================
  1461.    */
  1462.   $.setNumberInput = function(v, digits) {
  1463.     $gameMessage.setNumberInput(v, digits);
  1464.   }
  1465.  
  1466.   /**
  1467.    * ==========================================================================
  1468.    *
  1469.    * TextManager.setItemInput(number v, number type)
  1470.    *
  1471.    * @param v The variable ID to store the selected item's ID in.
  1472.    * @param type A number to determine what type of item may be selected.
  1473.    *
  1474.    * @note
  1475.    *  MV has 4 item types to choose from, Regular, Key, Hidden A, and
  1476.    *  Hidden B. The Hidden A and B item tyes are not displayed in the item
  1477.    *  menu with the default system. They only show up when using an item
  1478.    *  selection. Additionally, the two groups are separate, allowing you to
  1479.    *  keep items separated into the two hidden groups as needed.
  1480.    *  Regular items are type 1.
  1481.    *  Key items are type 2.
  1482.    *  Hidden A items are type 3.
  1483.    *  Hdden B items are type 4.
  1484.    *
  1485.    * ==========================================================================
  1486.    */
  1487.   $.setItemInput = function(v, type) {
  1488.     $gameMessage.setItemChoice(v, type);
  1489.   }
  1490.  
  1491. })(TextManager);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement