Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // TheoAllen - Animated Message Portrait
- // Version: 1.0
- // TheoAllen_AnimatedMessagePortrait.js
- //=============================================================================
- var Imported = Imported || {};
- Imported.Theo_AnimPortrait = true;
- var Theo = Theo || {};
- Theo.AnimePortrait = Theo.AnimePortrait || {};
- /*:
- * @plugindesc
- * Animated Message Portrait.
- *
- * @author TheoAllen (Ported by Kadafi)
- *
- * @param Idle Interval
- * @desc Format [A, B]. Quick wait: A, Long wait: B + (0 ~ A)
- * (Default: [5, 120])
- * @default [5, 120]
- *
- * @param Dim Power
- * @desc Dimness value for inactive portraits. Set 0 if you don't
- * want to use dimness. (Default: 255)
- * @default 255
- *
- * @help
- * -----------------------------------------------------------------------------
- * *) Important
- * -----------------------------------------------------------------------------
- * This is a port of TheoAllen's Animated Message Portrait from VX Ace to MV.
- * Please remember to credit TheoAllen for the original script.
- *
- * -----------------------------------------------------------------------------
- * *) Introduction :
- * -----------------------------------------------------------------------------
- * This plugin is simply adds animated portrait in dialog scene
- *
- * -----------------------------------------------------------------------------
- * *) How to use :
- * -----------------------------------------------------------------------------
- * Prepare two images in any size. One will be used for idle animation. The
- * other will be used for talking animation. The image itself must consist
- * three grids to the side. Named those image like these
- *
- * imagename_idle.png << Image name for idle
- * imagename_talk.png << Image name for talks
- *
- * -----------------------------------------------------------------------------
- * *) Script call:
- * -----------------------------------------------------------------------------
- * To display animated portrait, use this script call
- *
- * - this.setPortrait(filename, pos, flip, active);
- * It's to set the portrait. Here are the explanations
- *
- * *) Filename >> is a image filename. Must be inside quotes ("").
- * You don't need to add _talk / _idle.
- * *) Pos >> For position. Choose between "A" (left), "B" (right),
- * and "C" (middle)
- * *) Flip >> Is the image flipped? Just put it true/false.
- * Can be ommited. The default is false
- * *) Active >> Is the image active? If true, when the message text is
- * being typed, the image will talks. (Default : true)
- *
- * - this.removePotrait(pos);
- * To remove one of the portraits. Replace pos with "A", "B", or "C"
- *
- * - this.activatePortrait(pos);
- * To switch active portrait. Replace pos with "A", "B", or "C"
- *
- * - this.clearPortrait();
- * Must be called when the conversation ends
- *
- * - this.locatePortrait(pos, x, y);
- * To move one of the portrait. Replace pos with "A", "B", or "C"
- *
- * Only change the screen x: this.locatePortrait(pos, x, null);
- * Only change the screen y: this.locatePortrait(pos, null, y);
- * Revert to original position: this.locatePortrait(pos, null, null);
- *
- * -----------------------------------------------------------------------------
- * *) Terms of use :
- * -----------------------------------------------------------------------------
- * TheoAllen:
- * Credit me, TheoAllen. You are free to edit this script by your own. As long
- * as you don't claim it yours. For commercial purpose, don't forget to give me
- * a free copy of the game.
- *
- * Kadafi:
- * Credit me, Kadafi. (Optional)
- */
- Theo.AnimePortrait.parameters = PluginManager.parameters('TheoAllen_AnimatedMessagePortrait');
- Theo.AnimePortrait.Idle_Interval = Theo.AnimePortrait.parameters['Idle Interval'];
- Theo.AnimePortrait.Idle_Interval = String(Theo.AnimePortrait.Idle_Interval).replace('[', '').replace(']', '').split(',');
- Theo.AnimePortrait.Dim_Power = Number(Theo.AnimePortrait.parameters['Dim Power']);
- //-----------------------------------------------------------------------------
- // Game_Interpreter
- //-----------------------------------------------------------------------------
- Game_Interpreter.prototype.setPortrait = function(filename, pos, flip, active) {
- $gameMessage._portraitData[pos] = [filename, flip || false, null, null];
- if (active || true) $gameMessage._activePortrait = pos;
- };
- Game_Interpreter.prototype.clearPortrait = function() {
- $gameMessage.resetPortrait();
- };
- Game_Interpreter.prototype.removePortrait = function(pos) {
- $gameMessage._portraitData[pos][0] = '';
- };
- Game_Interpreter.prototype.activatePortrait = function(pos) {
- $gameMessage._activePortrait = pos;
- };
- Game_Interpreter.prototype.locatePortrait = function(pos, x, y) {
- $gameMessage._portraitData[pos][2] = x;
- $gameMessage._portraitData[pos][3] = y;
- };
- //-----------------------------------------------------------------------------
- // Game_Message
- //-----------------------------------------------------------------------------
- var Game_Message_initialize = Game_Message.prototype.initialize;
- Game_Message.prototype.initialize = function() {
- Game_Message_initialize.call(this);
- this.resetPortrait();
- this._activePortrait = 'A';
- };
- Game_Message.prototype.resetPortrait = function() {
- this._portraitData = {
- A: ['', false, null, null],
- B: ['', false, null, null],
- C: ['', false, null, null]
- };
- };
- //-----------------------------------------------------------------------------
- // Window_Message
- //-----------------------------------------------------------------------------
- var Window_Message_initialize = Window_Message.prototype.initialize;
- Window_Message.prototype.initialize = function() {
- Window_Message_initialize.call(this);
- this._portraitWaitCount = 0;
- this._portraitTwiceBlink = 0;
- this.createAllPortraits();
- };
- Window_Message.prototype.activePortrait = function() {
- return this._portraits[['A', 'C', 'B'].indexOf($gameMessage._activePortrait)];
- };
- var Window_Message_update = Window_Message.prototype.update
- Window_Message.prototype.update = function() {
- Window_Message_update.call(this);
- this.updatePortraitWait();
- this.updateAllPortraits();
- };
- Window_Message.prototype.createAllPortraits = function() {
- this._portraits = [];
- for (var i = 0; i < 3; i++) {
- var portrait = new Sprite();
- portrait.filename = '';
- portrait.status = '_talk';
- portrait.visible = false;
- portrait.selfSwitch = false;
- portrait.idlePattern = 0;
- portrait.patternIndex = 0;
- this._portraits.push(portrait);
- this.addChild(this._portraits[i]);
- }
- };
- Window_Message.prototype.updateAllPortraits = function() {
- for (var i = 0; i < 3; i++) {
- if (this._portraits[i].bitmap && !this._portraits[i].bitmap.isReady()) return;
- if (this._portraits[i].bitmap) this.updatePortraitPositon(i);
- this.updatePortraitPattern(i);
- this.updatePortraitBitmap(i);
- this.updatePortraitColor(i);
- this.updatePortraitData(i);
- }
- };
- Window_Message.prototype.updatePortraitPositon = function(i) {
- var customX = $gameMessage._portraitData[['A', 'C', 'B'][i]][2];
- var customY = $gameMessage._portraitData[['A', 'C', 'B'][i]][3];
- switch (i) {
- case 0:
- this._portraits[i].x = 0;
- break;
- case 1:
- this._portraits[i].x = (Graphics.boxWidth - this._portraits[i].bitmap.width / 3) / 2;
- break;
- case 2:
- this._portraits[i].x = Graphics.boxWidth - this._portraits[i].bitmap.width / 3;
- break;
- }
- if (customX !== null) this._portraits[i].x = customX - this.x;
- if (customY !== null) {
- this._portraits[i].y = customY - this.y;
- } else {
- this._portraits[i].y = -this._portraits[i].bitmap.height;
- }
- if (this._positionType === 0) {
- this._portraits[i].y = Graphics.boxHeight - this._portraits[i].bitmap.height - this.y;
- }
- };
- Window_Message.prototype.updatePortraitPattern = function(i) {
- if (this.isOpen()) {
- if (['A', 'C', 'B'].indexOf($gameMessage._activePortrait) === i) {
- if (!this.updatePortraitWait()) {
- var pattern = [1, 2, 1, 0];
- var idlePattern = pattern[this.activePortrait().patternIndex];
- this.activePortrait().patternIndex++;
- this.activePortrait().idlePattern = idlePattern;
- if (this.activePortrait().patternIndex > 3) this.activePortrait().patternIndex = 0;
- this.updatePortraitFrame(i);
- if (this.activePortrait().idlePattern === 0) {
- if (!this.updateMessage()) {
- if (Math.random() > 0.75) {
- if (this._portraitTwiceBlink === 2) {
- this.startPortraitWait(Number(Theo.AnimePortrait.Idle_Interval[0]));
- this._portraitTwiceBlink = 0;
- }
- this._portraitTwiceBlink++;
- } else {
- this.startPortraitWait(Number(Theo.AnimePortrait.Idle_Interval[1]) + Number(Theo.AnimePortrait.Idle_Interval[0]));
- }
- }
- } else {
- this.startPortraitWait(Number(Theo.AnimePortrait.Idle_Interval[0]));
- }
- }
- }
- }
- };
- Window_Message.prototype.updatePortraitBitmap = function(i) {
- var filename = $gameMessage._portraitData[['A', 'C', 'B'][i]][0];
- if (filename === '') {
- this._portraits[i].filename = '';
- this._portraits[i].visible = false;
- } else {
- var status = this.updateMessage() ? '_talk' : '_idle';
- if (this._portraits[i].filename !== filename) {
- this.updatePortraitStatus(i, filename, status);
- } else if (this._portraits[i].status !== status) {
- this.updatePortraitStatus(i, filename, status);
- }
- this.updatePortraitFrame(i);
- }
- };
- Window_Message.prototype.updatePortraitStatus = function(i, filename, status) {
- ImageManager.loadSystem(filename + '_talk');
- ImageManager.loadSystem(filename + '_idle');
- this._portraits[i].bitmap = ImageManager.loadSystem(filename + status);
- this._portraits[i].filename = filename;
- this._portraits[i].status = status;
- this._portraits[i].visible = true;
- this.updatePortraitPositon(i)
- this.updatePortraitColor(i);
- this.updatePortraitData(i);
- };
- Window_Message.prototype.updatePortraitFrame = function(i) {
- if (this._portraits[i].bitmap) {
- this._portraits[i].setFrame(this._portraits[i].idlePattern * (this._portraits[i].bitmap.width / 3), 0,
- this._portraits[i].bitmap.width / 3, this._portraits[i].bitmap.height);
- }
- };
- Window_Message.prototype.updatePortraitColor = function(i) {
- if (['A', 'C', 'B'].indexOf($gameMessage._activePortrait) !== i) {
- this._portraits[i].setColorTone([0, 0, 0, Theo.AnimePortrait.Dim_Power]);
- } else {
- this._portraits[i].setColorTone([0, 0, 0, 0]);
- }
- };
- Window_Message.prototype.updatePortraitData = function(i) {
- if (['A', 'C', 'B'].indexOf($gameMessage._activePortrait) !== i) {
- this._portraits[i].idlePattern = 0;
- this._portraits[i].patternIndex = 0;
- }
- if ($gameMessage._portraitData[['A', 'C', 'B'][i]][1]) {
- this._portraits[i].scale.x = -1;
- this._portraits[i].anchor.x = 1;
- } else {
- this._portraits[i].scale.x = 1;
- this._portraits[i].anchor.x = 0;
- }
- this._portraits[i].opacity = this.openness;
- };
- Window_Message.prototype.updatePortraitWait = function() {
- if (this._portraitWaitCount > 0) {
- this._portraitWaitCount--;
- return true;
- } else {
- return false;
- }
- };
- Window_Message.prototype.startPortraitWait = function(count) {
- this._portraitWaitCount = count;
- };
- var Window_Message_updateShowFast = Window_Message.prototype.updateShowFast;
- Window_Message.prototype.updateShowFast = function() {
- Window_Message_updateShowFast.call(this);
- if (this.isTriggered()) {
- this.startPortraitWait(0);
- this.activePortrait().idlePattern = 0;
- this.activePortrait().patternIndex = 0;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement