Advertisement
TwentyFree

More Escape Codes

Jul 10th, 2021
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // More Escape Codes
  3. // by Shaz
  4. // Last Update: 2015.11.23
  5. //
  6. // Revisions
  7. // 2015.11.23 Added escape codes for busts
  8. //=============================================================================
  9.  
  10. /*:
  11.  * @plugindesc Extends the number of escape codes in the Show Text command
  12.  * @author Shaz
  13.  *
  14.  * @param Face ID Index
  15.  * @desc Escape code for ID of actor and index for face graphic
  16.  * @default f
  17.  *
  18.  * @param Bust ID Index
  19.  * @desc Escape code for ID of actor and index for bust graphic
  20.  * @default b
  21.  *
  22.  * @param Bust X
  23.  * @desc X position of bust image
  24.  * @default 0
  25.  *
  26.  * @param Bust Y
  27.  * @desc Y position of bust image
  28.  * @default 0
  29.  *
  30.  * @param Bust Width
  31.  * @desc Width of a single bust
  32.  * @default 180
  33.  *
  34.  * @param Bust Height
  35.  * @desc Height of a single bust
  36.  * @default 200
  37.  *
  38.  * @param Bust Text Position
  39.  * @desc X position of text when bust is displayed
  40.  * @default 200
  41.  *
  42.  * @param Nickname/Handle
  43.  * @desc Escape code for actor nickname/handle
  44.  * @default h
  45.  *
  46.  * @help This plugin has no plugin commands
  47.  *
  48.  * Escape Codes:
  49.  *
  50.  * Hover the mouse over the text input box of the Show Text command to see
  51.  * the default escape codes.  Do not use values that are already being used.
  52.  *
  53.  * ---Face Graphic---
  54.  * if the Face ID Index value is 'f', use \f[1,2] in a Show Text command
  55.  * to add the face at index 2 of Actor 1's face graphic.  Remember indexes
  56.  * start at 0.  This escape code can be used multiple times within a
  57.  * Show Text command to change expressions.
  58.  *
  59.  * ---Bust Graphic---
  60.  * if the Bust ID Index value is 'b', use \b[filename] in a Show Text command
  61.  * to add the bust graphic in the filename image.  This escape
  62.  * code can be used multiple times within a Show Text command to change
  63.  * expressions.
  64.  *
  65.  * ---Bust X---
  66.  * X position where bust will be displayed
  67.  *
  68.  * ---Bust Y---
  69.  * Y position where bust will be displayed
  70.  *
  71.  * ---Bust Width---
  72.  * Width of an individual bust (should be 1/4 of full image width)
  73.  *
  74.  * ---Bust Height---
  75.  * Height of an individual bust (should be 1/2 of full image height)
  76.  *
  77.  * ---Bust Text Position---
  78.  * X position of text when a bust image is displayed. For comparison, when
  79.  * a face image is displayed, the text position is 168.
  80.  *
  81.  * ---Nickname/Handle---
  82.  * if the Nickname/Handle value is 'h', use \h[1] to show Actor 1's nickname.
  83.  *
  84.  */
  85.  
  86. (function() {
  87.  
  88.   var parameters = PluginManager.parameters('MoreEscapeCodes');
  89.   var reFace = String(parameters['Face ID Index'] || '').toUpperCase();
  90.   var reBust = String(parameters['Bust ID Index'] || '').toUpperCase();
  91.   var bustX = parseInt(parameters['Bust X'] || 0);
  92.   var bustY = parseInt(parameters['Bust Y'] || 0);
  93.   var bustWidth = parseInt(parameters['Bust Width'] || 180);
  94.   var bustHeight = parseInt(parameters['Bust Height'] || 200);
  95.   var bustTextPosition = parseInt(parameters['Bust Text Position'] || 0);
  96.   var reHandle = String(parameters['Nickname/Handle'] || null);
  97.   var reHandlePattern = reHandle ? new RegExp('\\x1b' + reHandle + '\\[(\\d+)\\]', 'gi') : null;
  98.  
  99.   var _Game_Interpreter_command101 = Game_Interpreter.prototype.command101;
  100.   Game_Interpreter.prototype.command101 = function() {
  101.     if (!$gameMessage.isBusy()) {
  102.       $gameMessage.setBustImage('');
  103.     };
  104.     _Game_Interpreter_command101.call(this);
  105.   };
  106.  
  107.   Window_Base.prototype.obtainMultiEscapeParams = function(textState) {
  108.     var arr = /^\[(\d+,\d+)\]/.exec(textState.text.slice(textState.index));
  109.     if (arr) {
  110.       textState.index += arr[0].length;
  111.       return arr[1].split(',');
  112.     } else {
  113.       return '';
  114.     }
  115.   };
  116.  
  117.   var _Window_Base_convertEscapeCharacters = Window_Base.prototype.convertEscapeCharacters;
  118.   Window_Base.prototype.convertEscapeCharacters = function(text) {
  119.     text = _Window_Base_convertEscapeCharacters.call(this, text);
  120.     if (reHandle) {
  121.       text = text.replace(reHandlePattern, function() {
  122.         return this.actorNickname(parseInt(arguments[1]));
  123.       }.bind(this));
  124.     }
  125.     return text;
  126.   };
  127.  
  128.   Window_Base.prototype.actorNickname = function(n) {
  129.     var actor = n >= 1 ? $gameActors.actor(n) : null;
  130.     return actor ? actor.nickname() : '';
  131.   };
  132.  
  133.   var _Window_Message_initMembers = Window_Message.prototype.initMembers;
  134.   Window_Message.prototype.initMembers = function() {
  135.     _Window_Message_initMembers.call(this);
  136.     this._bustSprite = new Sprite();
  137.     this._bustSprite.x = bustX;
  138.     this._bustSprite.y = bustY;
  139.     this._bustSprite.bitmap = new Bitmap(bustWidth, bustHeight);
  140.     this.addChild(this._bustSprite);
  141.   };
  142.  
  143.   var _Window_Message_processEscapeCharacter = Window_Message.prototype.processEscapeCharacter;
  144.   Window_Message.prototype.processEscapeCharacter = function(code, textState) {
  145.     switch (code) {
  146.       case reFace:
  147.         this.changeFace(textState);
  148.         break;
  149.       case reBust:
  150.         this.changeBust(textState);
  151.         break;
  152.       default:
  153.         _Window_Message_processEscapeCharacter.call(this, code, textState);
  154.         break;
  155.     }
  156.   };
  157.  
  158.   Window_Message.prototype.changeFace = function(textState) {
  159.     newFace = this.obtainMultiEscapeParams(textState);
  160.     if (newFace) {
  161.       $gameMessage.setFaceImage($gameActors.actor(newFace[0]).faceName(), newFace[1]);
  162.       this.contents.clearRect(0, 0, Window_Base._faceWidth, Window_Base._faceHeight);
  163.       this.loadMessageFace();
  164.       this.drawMessageFace();
  165.     }
  166.   };
  167.  
  168.   Window_Message.prototype.changeBust = function(textState) {
  169.     newBust = this.obtainMultiEscapeParams(textState);
  170.     if (newBust) {
  171.       $gameMessage.setBustImage($gameActors.actor(newBust[0]).bustName(), newBust[1]);
  172.       this.loadMessageBust();
  173.       this.drawMessageBust();
  174.     }
  175.   };
  176.  
  177.   Window_Message.prototype.loadMessageBust = function() {
  178.     this._bustSprite = ImageManager.loadBust($gameMessage.bustName());
  179.   };
  180.  
  181.   Window_Message.prototype.drawMessageBust = function() {
  182.     var px = $gameMessage.bustIndex() % 4 * bustWidth;
  183.     var py = Math.floor($gameMessage.bustIndex() / 4) * bustHeight;
  184.     this._bustSprite.setFrame(px, py, bustWidth, bustHeight);
  185.   }
  186.  
  187.   var _Window_Message_newLineX = Window_Message.prototype.newLineX;
  188.   Window_Message.prototype.newLineX = function() {
  189.     var facePattern = new RegExp('\\\\' + reFace + '\\[(\\d+,\\d+)\\]', 'i');
  190.     var bustPattern = new RegExp('\\\\' + reBust + '\\[(\\d+,\\d+)\\]', 'i');
  191.     if ($gameMessage.allText().match(bustPattern)) {
  192.       return bustTextPosition;
  193.     } else if ($gameMessage.allText().match(facePattern)) {
  194.       return 168;
  195.     } else {
  196.       return _Window_Message_newLineX.call(this);
  197.     }
  198.   };
  199.  
  200.   Game_Message.prototype.setBustImage = function(bustName, bustIndex) {
  201.     this._bustName = bustName;
  202.     this._bustIndex = bustIndex;
  203.   };
  204.  
  205.   Game_Message.prototype.bustName = function() {
  206.     return this._bustName;
  207.   };
  208.  
  209.   Game_Message.prototype.bustIndex = function() {
  210.     return this._bustIndex;
  211.   };
  212.  
  213.   ImageManager.loadBust = function(filename, hue) {
  214.     return this.loadBitmap('img/busts/', filename, hue, true);
  215.   };
  216. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement