Advertisement
Kakakadafi

TheoAllen_AnimatedMessagePortrait

Sep 5th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // TheoAllen - Animated Message Portrait
  3. // Version: 1.0
  4. // TheoAllen_AnimatedMessagePortrait.js
  5. //=============================================================================
  6.  
  7. var Imported = Imported || {};
  8. Imported.Theo_AnimPortrait = true;
  9.  
  10. var Theo = Theo || {};
  11. Theo.AnimePortrait = Theo.AnimePortrait || {};
  12.  
  13. /*:
  14.  * @plugindesc
  15.  * Animated Message Portrait.
  16.  *
  17.  * @author TheoAllen (Ported by Kadafi)
  18.  *
  19.  * @param Idle Interval
  20.  * @desc Format [A, B]. Quick wait: A, Long wait: B + (0 ~ A)
  21.  * (Default: [5, 120])
  22.  * @default [5, 120]
  23.  *
  24.  * @param Dim Power
  25.  * @desc Dimness value for inactive portraits. Set 0 if you don't
  26.  * want to use dimness. (Default: 255)
  27.  * @default 255
  28.  *
  29.  * @help
  30.  * -----------------------------------------------------------------------------
  31.  * *) Important
  32.  * -----------------------------------------------------------------------------
  33.  * This is a port of TheoAllen's Animated Message Portrait from VX Ace to MV.
  34.  * Please remember to credit TheoAllen for the original script.
  35.  *
  36.  * -----------------------------------------------------------------------------
  37.  * *) Introduction :
  38.  * -----------------------------------------------------------------------------
  39.  * This plugin is simply adds animated portrait in dialog scene
  40.  *
  41.  * -----------------------------------------------------------------------------
  42.  * *) How to use :
  43.  * -----------------------------------------------------------------------------
  44.  * Prepare two images in any size. One will be used for idle animation. The
  45.  * other will be used for talking animation. The image itself must consist
  46.  * three grids to the side. Named those image like these
  47.  *
  48.  * imagename_idle.png  << Image name for idle
  49.  * imagename_talk.png  << Image name for talks
  50.  *
  51.  * -----------------------------------------------------------------------------
  52.  * *) Script call:
  53.  * -----------------------------------------------------------------------------
  54.  * To display animated portrait, use this script call
  55.  *
  56.  * - this.setPortrait(filename, pos, flip, active);
  57.  *   It's to set the portrait. Here are the explanations
  58.  *
  59.  *   *) Filename >> is a image filename. Must be inside quotes ("").
  60.  *                  You don't need to add _talk / _idle.
  61.  *   *) Pos      >> For position. Choose between "A" (left), "B" (right),
  62.  *                  and "C" (middle)
  63.  *   *) Flip     >> Is the image flipped? Just put it true/false.
  64.  *                  Can be ommited. The default is false
  65.  *   *) Active   >> Is the image active? If true, when the message text is
  66.  *                  being typed, the image will talks. (Default : true)
  67.  *
  68.  * - this.removePotrait(pos);
  69.  *   To remove one of the portraits. Replace pos with "A", "B", or "C"
  70.  *
  71.  * - this.activatePortrait(pos);
  72.  *   To switch active portrait. Replace pos with "A", "B", or "C"
  73.  *
  74.  * - this.clearPortrait();
  75.  *   Must be called when the conversation ends
  76.  *
  77.  * - this.locatePortrait(pos, x, y);
  78.  *   To move one of the portrait. Replace pos with "A", "B", or "C"
  79.  *
  80.  *   Only change the screen x: this.locatePortrait(pos, x, null);
  81.  *   Only change the screen y: this.locatePortrait(pos, null, y);
  82.  *   Revert to original position: this.locatePortrait(pos, null, null);
  83.  *
  84.  * -----------------------------------------------------------------------------
  85.  * *) Terms of use :
  86.  * -----------------------------------------------------------------------------
  87.  * TheoAllen:
  88.  * Credit me, TheoAllen. You are free to edit this script by your own. As long
  89.  * as you don't claim it yours. For commercial purpose, don't forget to give me
  90.  * a free copy of the game.
  91.  *
  92.  * Kadafi:
  93.  * Credit me, Kadafi. (Optional)
  94.  */
  95.  
  96. Theo.AnimePortrait.parameters = PluginManager.parameters('TheoAllen_AnimatedMessagePortrait');
  97. Theo.AnimePortrait.Idle_Interval = Theo.AnimePortrait.parameters['Idle Interval'];
  98. Theo.AnimePortrait.Idle_Interval = String(Theo.AnimePortrait.Idle_Interval).replace('[', '').replace(']', '').split(',');
  99. Theo.AnimePortrait.Dim_Power = Number(Theo.AnimePortrait.parameters['Dim Power']);
  100.  
  101. //-----------------------------------------------------------------------------
  102. // Game_Interpreter
  103. //-----------------------------------------------------------------------------
  104.  
  105. Game_Interpreter.prototype.setPortrait = function(filename, pos, flip, active) {
  106.     $gameMessage._portraitData[pos] = [filename, flip || false, null, null];
  107.     if (active || true) $gameMessage._activePortrait = pos;
  108. };
  109.  
  110. Game_Interpreter.prototype.clearPortrait = function() {
  111.     $gameMessage.resetPortrait();
  112. };
  113.  
  114. Game_Interpreter.prototype.removePortrait = function(pos) {
  115.     $gameMessage._portraitData[pos][0] = '';
  116. };
  117.  
  118. Game_Interpreter.prototype.activatePortrait = function(pos) {
  119.     $gameMessage._activePortrait = pos;
  120. };
  121.  
  122. Game_Interpreter.prototype.locatePortrait = function(pos, x, y) {
  123.     $gameMessage._portraitData[pos][2] = x;
  124.     $gameMessage._portraitData[pos][3] = y;
  125. };
  126.  
  127. //-----------------------------------------------------------------------------
  128. // Game_Message
  129. //-----------------------------------------------------------------------------
  130.  
  131. var Game_Message_initialize = Game_Message.prototype.initialize;
  132. Game_Message.prototype.initialize = function() {
  133.     Game_Message_initialize.call(this);
  134.     this.resetPortrait();
  135.     this._activePortrait = 'A';
  136. };
  137.  
  138. Game_Message.prototype.resetPortrait = function() {
  139.     this._portraitData = {
  140.         A: ['', false, null, null],
  141.         B: ['', false, null, null],
  142.         C: ['', false, null, null]
  143.     };
  144. };
  145.  
  146. //-----------------------------------------------------------------------------
  147. // Window_Message
  148. //-----------------------------------------------------------------------------
  149.  
  150. var Window_Message_initialize = Window_Message.prototype.initialize;
  151. Window_Message.prototype.initialize = function() {
  152.     Window_Message_initialize.call(this);
  153.     this._portraitWaitCount = 0;
  154.     this._portraitTwiceBlink = 0;
  155.     this.createAllPortraits();
  156. };
  157.  
  158. Window_Message.prototype.activePortrait = function() {
  159.     return this._portraits[['A', 'C', 'B'].indexOf($gameMessage._activePortrait)];
  160. };
  161.  
  162. var Window_Message_update = Window_Message.prototype.update
  163. Window_Message.prototype.update = function() {
  164.     Window_Message_update.call(this);
  165.     this.updatePortraitWait();
  166.     this.updateAllPortraits();
  167. };
  168.  
  169. Window_Message.prototype.createAllPortraits = function() {
  170.     this._portraits = [];
  171.     for (var i = 0; i < 3; i++) {
  172.         var portrait = new Sprite();
  173.         portrait.filename = '';
  174.         portrait.status = '_talk';
  175.         portrait.visible = false;
  176.         portrait.selfSwitch = false;
  177.         portrait.idlePattern = 0;
  178.         portrait.patternIndex = 0;
  179.         this._portraits.push(portrait);
  180.         this.addChild(this._portraits[i]);
  181.     }
  182. };
  183.  
  184. Window_Message.prototype.updateAllPortraits = function() {
  185.     for (var i = 0; i < 3; i++) {
  186.         if (this._portraits[i].bitmap && !this._portraits[i].bitmap.isReady()) return;
  187.         if (this._portraits[i].bitmap) this.updatePortraitPositon(i);
  188.         this.updatePortraitPattern(i);
  189.         this.updatePortraitBitmap(i);
  190.         this.updatePortraitColor(i);
  191.         this.updatePortraitData(i);
  192.     }
  193. };
  194.  
  195. Window_Message.prototype.updatePortraitPositon = function(i) {
  196.     var customX = $gameMessage._portraitData[['A', 'C', 'B'][i]][2];
  197.     var customY = $gameMessage._portraitData[['A', 'C', 'B'][i]][3];
  198.     switch (i) {
  199.         case 0:
  200.             this._portraits[i].x = 0;
  201.         break;
  202.         case 1:
  203.             this._portraits[i].x = (Graphics.boxWidth - this._portraits[i].bitmap.width / 3) / 2;
  204.         break;
  205.         case 2:
  206.             this._portraits[i].x = Graphics.boxWidth - this._portraits[i].bitmap.width / 3;
  207.         break;
  208.     }
  209.     if (customX !== null) this._portraits[i].x = customX - this.x;
  210.     if (customY !== null) {
  211.         this._portraits[i].y = customY - this.y;
  212.     } else {
  213.         this._portraits[i].y = -this._portraits[i].bitmap.height;
  214.     }
  215.     if (this._positionType === 0) {
  216.         this._portraits[i].y = Graphics.boxHeight - this._portraits[i].bitmap.height - this.y;
  217.     }
  218. };
  219.  
  220. Window_Message.prototype.updatePortraitPattern = function(i) {
  221.     if (this.isOpen()) {
  222.         if (['A', 'C', 'B'].indexOf($gameMessage._activePortrait) === i) {
  223.             if (!this.updatePortraitWait()) {
  224.                 var pattern = [1, 2, 1, 0];
  225.                 var idlePattern = pattern[this.activePortrait().patternIndex];
  226.                 this.activePortrait().patternIndex++;
  227.                 this.activePortrait().idlePattern = idlePattern;
  228.                 if (this.activePortrait().patternIndex > 3) this.activePortrait().patternIndex = 0;
  229.                 this.updatePortraitFrame(i);
  230.                 if (this.activePortrait().idlePattern === 0) {
  231.                     if (!this.updateMessage()) {
  232.                         if (Math.random() > 0.75) {
  233.                             if (this._portraitTwiceBlink === 2) {
  234.                                 this.startPortraitWait(Number(Theo.AnimePortrait.Idle_Interval[0]));
  235.                                 this._portraitTwiceBlink = 0;
  236.                             }
  237.                             this._portraitTwiceBlink++;
  238.                         } else {
  239.                             this.startPortraitWait(Number(Theo.AnimePortrait.Idle_Interval[1]) + Number(Theo.AnimePortrait.Idle_Interval[0]));
  240.                         }
  241.                     }
  242.                 } else {
  243.                     this.startPortraitWait(Number(Theo.AnimePortrait.Idle_Interval[0]));
  244.                 }
  245.             }
  246.         }
  247.     }
  248. };
  249.  
  250.  
  251.  
  252. Window_Message.prototype.updatePortraitBitmap = function(i) {
  253.     var filename = $gameMessage._portraitData[['A', 'C', 'B'][i]][0];
  254.     if (filename === '') {
  255.         this._portraits[i].filename = '';
  256.         this._portraits[i].visible = false;
  257.     } else {
  258.         var status = this.updateMessage() ? '_talk' : '_idle';
  259.         if (this._portraits[i].filename !== filename) {
  260.             this.updatePortraitStatus(i, filename, status);
  261.         } else if (this._portraits[i].status !== status) {
  262.             this.updatePortraitStatus(i, filename, status);
  263.         }
  264.         this.updatePortraitFrame(i);
  265.     }
  266. };
  267.  
  268. Window_Message.prototype.updatePortraitStatus = function(i, filename, status) {
  269.     ImageManager.loadSystem(filename + '_talk');
  270.     ImageManager.loadSystem(filename + '_idle');
  271.     this._portraits[i].bitmap = ImageManager.loadSystem(filename + status);
  272.     this._portraits[i].filename = filename;
  273.     this._portraits[i].status = status;
  274.     this._portraits[i].visible = true;
  275.     this.updatePortraitPositon(i)
  276.     this.updatePortraitColor(i);
  277.     this.updatePortraitData(i);
  278. };
  279.  
  280. Window_Message.prototype.updatePortraitFrame = function(i) {
  281.     if (this._portraits[i].bitmap) {
  282.         this._portraits[i].setFrame(this._portraits[i].idlePattern * (this._portraits[i].bitmap.width / 3), 0,
  283.           this._portraits[i].bitmap.width / 3, this._portraits[i].bitmap.height);
  284.     }
  285. };
  286.  
  287. Window_Message.prototype.updatePortraitColor = function(i) {
  288.     if (['A', 'C', 'B'].indexOf($gameMessage._activePortrait) !== i) {
  289.         this._portraits[i].setColorTone([0, 0, 0, Theo.AnimePortrait.Dim_Power]);
  290.     } else {
  291.         this._portraits[i].setColorTone([0, 0, 0, 0]);
  292.     }
  293. };
  294.  
  295. Window_Message.prototype.updatePortraitData = function(i) {
  296.     if (['A', 'C', 'B'].indexOf($gameMessage._activePortrait) !== i) {
  297.         this._portraits[i].idlePattern = 0;
  298.         this._portraits[i].patternIndex = 0;
  299.     }
  300.     if ($gameMessage._portraitData[['A', 'C', 'B'][i]][1]) {
  301.         this._portraits[i].scale.x = -1;
  302.         this._portraits[i].anchor.x = 1;
  303.     } else {
  304.         this._portraits[i].scale.x = 1;
  305.         this._portraits[i].anchor.x = 0;
  306.     }
  307.     this._portraits[i].opacity = this.openness;
  308. };
  309.  
  310. Window_Message.prototype.updatePortraitWait = function() {
  311.     if (this._portraitWaitCount > 0) {
  312.         this._portraitWaitCount--;
  313.         return true;
  314.     } else {
  315.         return false;
  316.     }
  317. };
  318.  
  319. Window_Message.prototype.startPortraitWait = function(count) {
  320.     this._portraitWaitCount = count;
  321. };
  322.  
  323. var Window_Message_updateShowFast = Window_Message.prototype.updateShowFast;
  324. Window_Message.prototype.updateShowFast = function() {
  325.     Window_Message_updateShowFast.call(this);
  326.     if (this.isTriggered()) {
  327.         this.startPortraitWait(0);
  328.         this.activePortrait().idlePattern = 0;
  329.         this.activePortrait().patternIndex = 0;
  330.     }
  331. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement