Advertisement
Rafael_Sol_Maker

RSM's Balloon Upgrade MV PLUS v1.0 [EN]

May 24th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // RSM_BalloonUpgradePlus.js
  3. // Rafael_Sol_Maker's Balloon Upgrade MV (PLUS edition) v1.0
  4. // This work is licensed under a Creative Commons Attribution 4.0 International License.
  5. //=============================================================================
  6.  
  7. // Some guys say that it's a good practice...
  8. var Imported = Imported || {};
  9. Imported.RSM_BalloonUpgrade = true;
  10.  
  11. var RSMTweaks = RSMTweaks || {};
  12. RSMTweaks.BalloonUpgrade = RSMTweaks.BalloonUpgrade || {};
  13. RSMTweaks.BalloonUpgrade.version = 1.0;
  14.  
  15. /*:
  16.  * @plugindesc RSM's Balloon Upgrade MV PLUS v1.0.
  17.  * Expression balloon upgrade. Requires RPG Maker 1.5 or newer.
  18.  * @author Rafael_Sol_Maker (www.condadobraveheart.com/forum)
  19.  * @help This plugin allows some deep customization of the expression balloons and
  20.  * adds some new functionalities as well.
  21.  * ---------------------------------------------------------------
  22.  * IMPORTANT: THIS PLUGIN WILL REPLACE THE STANDARD BALLOONS,
  23.  * AND WILL REQUIRE PREVIOUS CONFIGURATION TO BE USED!
  24.  * ---------------------------------------------------------------
  25.  *
  26.  * The index in the list of this plugin parameters corresponds to the
  27.  * ones that will be displayed in the selection list via event commands.
  28.  *
  29.  * You will not be able to use a balloon beyond what was previously set up.
  30.  * e.g.: If you have set up only 3 balloons, attempting to use the 4th of
  31.  * the list will result in ERROR.
  32.  *
  33.  * If you have any questions, criticisms or suggestions, please let me know.
  34.  * Best regards,
  35.  *                                                          ~RAFAEL_SOL_MAKER
  36.  *
  37.  * @param balloon_list
  38.  * @text Balloon Configurations
  39.  * @desc Set up here each balloon property individually.
  40.  * @type struct<Balloon>[]
  41.  */
  42.  
  43. /*~struct~Balloon:
  44.  * @param animation
  45.  * @text Animation
  46.  * @desc Category to deal with the details of the animations
  47.  * @default ===================================
  48.  *
  49.  * @param filename
  50.  * @parent animation
  51.  * @text File Name
  52.  * @desc Name of the file from which the animation will be extracted.
  53.  * @type file
  54.  * @dir img/system
  55.  * @default Balloon
  56.  *
  57.  * @param animation_id
  58.  * @parent animation
  59.  * @text Animation ID
  60.  * @desc Determination of the index of the animation extracted from the file.
  61.  * @type number
  62.  * @min 1
  63.  * @default 1
  64.  *
  65.  * @param total_frames
  66.  * @parent animation
  67.  * @text Total of Frames
  68.  * @desc Total of frames to complete the animation.
  69.  * @type number
  70.  * @min 1
  71.  * @default 8
  72.  *
  73.  * @param speed
  74.  * @parent animation
  75.  * @text Speed
  76.  * @desc Exposure time for each frame of the animation, in frames (1/60 second).
  77.  * @type number
  78.  * @min 1
  79.  * @default 8
  80.  *
  81.  * @param wait_time
  82.  * @parent animation
  83.  * @text Final Wait Time
  84.  * @desc Standby time of the last frame of the animation, in frames (1/60 second).
  85.  * @type number
  86.  * @min 1
  87.  * @default 12
  88.  *
  89.  * @param frame
  90.  * @text Animation Frame
  91.  * @desc Animation frame category. Yeah, that's it. Go check it out.
  92.  * @default ===================================
  93.  *
  94.  * @param offset
  95.  * @parent frame
  96.  * @text Position (Offset)
  97.  * @desc Offset of the expression balloon relative to the center of the target character. Value in tiles.
  98.  * @type struct<Point>
  99.  * @default {"X":"0.250","Y":"0.500"}
  100.  *
  101.  * @param scale
  102.  * @parent frame
  103.  * @text Scaling Factor
  104.  * @desc Scaling factor, for width and height. Use between 0 and 1 to shrink and greater than 1 to enlarge.
  105.  * @type struct<Point>
  106.  * @default {"X":"1.000","Y":"1.000"}
  107.  *
  108.  * @param rotation
  109.  * @parent frame
  110.  * @text Rotation
  111.  * @desc Rotation of the balloon, in radians. Use values from 0 to 2*PI.
  112.  * @type number
  113.  * @decimals 4
  114.  * @default 0.0000
  115.  *
  116.  * @param frame_size
  117.  * @parent frame
  118.  * @text Frame Size
  119.  * @desc Balloon animation frame size (width and height).
  120.  * @type struct<Size>
  121.  * @default {"W":"48","H":"48"}
  122.  *
  123.  * @param z_order
  124.  * @parent frame
  125.  * @text Priority
  126.  * @desc Display priority. The higher the value, the higher above the other objects it will be shown.
  127.  * @type number
  128.  * @default 7
  129.  *
  130.  * @param sfx
  131.  * @text Sound Effect
  132.  * @desc Category where we place the sound effect playback settings.
  133.  * @default ===================================
  134.  *
  135.  * @param sfx_filename
  136.  * @parent sfx
  137.  * @text File Name
  138.  * @desc The name of the sound file to be played.
  139.  * @type file
  140.  * @dir audio/se
  141.  * @default Cancel2
  142.  *
  143.  * @param sfx_volume
  144.  * @parent sfx
  145.  * @text Volume
  146.  * @desc Volume that the sound will be played (0 to 100).
  147.  * @type number
  148.  * @min 0
  149.  * @max 100
  150.  * @default 90
  151.  *
  152.  * @param sfx_pitch
  153.  * @parent sfx
  154.  * @text Pitch
  155.  * @desc Pitch (bass or treble) in which the sound will be played. Default is 100 (normal pitch)
  156.  * @type number
  157.  * @min 50
  158.  * @max 150
  159.  * @default 100
  160.  *
  161.  * @param sfx_pan
  162.  * @parent sfx
  163.  * @text Pan
  164.  * @desc Stereo balance(left-to-right)of the sound. Use values from -100 to 100.
  165.  * @type number
  166.  * @min -100
  167.  * @max 100
  168.  * @default 0
  169.  *
  170.  * @param sfx_wait
  171.  * @parent sfx
  172.  * @text Waiting Delay
  173.  * @desc Wait, in frames (1/60 seconds), before playing the sound.
  174.  * Won't play if the animation is already finished.
  175.  * @type number
  176.  * @default 0
  177.  *
  178.  * @param blend
  179.  * @text Opacity and Blend
  180.  * @desc Category that deals with transparencies and suchlike.
  181.  * @default ===================================
  182.  *
  183.  * @param opacity
  184.  * @parent blend
  185.  * @text Opacity
  186.  * @desc Degree of transparency of the image. Use values from 0 to 255.
  187.  * @type number
  188.  * @min 0
  189.  * @max 255
  190.  * @default 255
  191.  *
  192.  * @param blend_mode
  193.  * @parent blend
  194.  * @text Blend Mode
  195.  * @desc Blend mode (operation overlay) that the image will be mixed with others.
  196.  * @type select
  197.  * @option Graphics.BLEND_NORMAL
  198.  * @option Graphics.BLEND_ADD
  199.  * @option Graphics.BLEND_MULTIPLY
  200.  * @option Graphics.BLEND_SCREEN
  201.  * @default Graphics.BLEND_NORMAL
  202.  *
  203.  * @param blend_color
  204.  * @parent blend
  205.  * @text Blend Color
  206.  * @desc RGB color under which the mixture of the blend mode will be performed.
  207.  * @type struct<Color>
  208.  * @default {"R":"0","G":"0","B":"0","A":"0"}
  209.  *
  210.  * @param color_tone
  211.  * @parent blend
  212.  * @text Color Tone
  213.  * @desc Tone of the image in RGB range (-255 to 255) and in Gray (0 to 255).
  214.  * @type struct<Tone>
  215.  * @default {"R":"0","G":"0","B":"0","Gray":"0"}
  216.  *
  217. */
  218.  
  219. /////////////////////////////////////////////////////////////////////////////
  220.  
  221. /*~struct~Size:
  222.  * @param W @type number @text Width @min 0
  223.  * @param H @type number @text Height @min 0
  224. */
  225.  
  226. /*~struct~Point:
  227.  * @param X @type number @text X-coordinate @decimals 3
  228.  * @param Y @type number @text Y-coordinate @decimals 3
  229. */
  230.  
  231. /*~struct~Color:
  232.  * @param R @type number @text Red @min 0 @max 255
  233.  * @param G @type number @text Green @min 0 @max 255
  234.  * @param B @type number @text Blue @min 0 @max 255
  235.  * @param A @type number @text Alpha @min 0 @max 255
  236. */
  237.  
  238. /*~struct~Tone:
  239.  * @param R @type number @text Red @min -255 @max 255
  240.  * @param G @type number @text Green @min -255 @max 255
  241.  * @param B @type number @text Blue @min -255 @max 255
  242.  * @param Gray @type number @text Gray @min 0 @max 255
  243. */
  244.  
  245. ///////////////////////////////////////////////////////////////////////////////
  246.  
  247. (function() {
  248.  
  249.   // Reading the parameters...
  250.   var params = PluginManager.parameters('RSM_BalloonUpgradePlus');
  251.   var list = JSON.parse(params['balloon_list']);
  252.   var items = []
  253.   for (n = 0; n < list.length; n++) {
  254.     items[n] = JSON.parse(list[n]);
  255.     items[n].offset = JSON.parse(items[n].offset);
  256.     items[n].scale = JSON.parse(items[n].scale);
  257.     items[n].blend_color = JSON.parse(items[n].blend_color);
  258.     items[n].color_tone = JSON.parse(items[n].color_tone);
  259.     items[n].frame_size = JSON.parse(items[n].frame_size);
  260.   };
  261.  
  262.   /////////////////////////////////////////////////////////////////////////////
  263.  
  264.   // Passing value as soon as it starts
  265.   Sprite_Character.prototype.startBalloon = function() {
  266.       if (this._character.balloonId() > list.length) {
  267.         throw new Error("Error: The index of the balloon chosen is not configured. Please set up this balloon in the Plugin Manager!");
  268.         return;
  269.       };
  270.       if (!this._balloonSprite) {
  271.         this._balloonSprite = new Sprite_Balloon(this._character.balloonId());
  272.       };
  273.       this.parent.addChild(this._balloonSprite);
  274.   };
  275.  
  276.   /////////////////////////////////////////////////////////////////////////////
  277.  
  278.   // Essential to pass balloonId to initMembers
  279.   Sprite_Balloon.prototype.initialize = function(balloonId) {
  280.     Sprite_Base.prototype.initialize.call(this);
  281.     this.initMembers(balloonId);
  282.     this.loadBitmap();
  283.   };
  284.  
  285.     // Changing our initial properties
  286.   Sprite_Balloon.prototype.initMembers = function(balloonId) {
  287.  
  288.     // Essential data
  289.     this._balloonId = balloonId;
  290.     var i = items[balloonId - 1];
  291.  
  292.     // Positioning
  293.     this.anchor.x = Number(i.offset.X);
  294.     this.anchor.y = Number(i.offset.Y);
  295.     this.scale.x = Number(i.scale.X);
  296.     this.scale.y = Number(i.scale.Y);
  297.     this.rotation = Number(i.rotation);
  298.     this.fw = Number(i.frame_size.W);
  299.     this.fh = Number(i.frame_size.H);
  300.     this.z = Number(i.z_order);
  301.  
  302.     // Blend Properties
  303.     this.opacity = Number(i.opacity);
  304.     this.blendMode = eval(i.blend_mode);
  305.     var b = i.blend_color;
  306.     var c = i.color_tone;
  307.     this.setBlendColor([b['R'], b['G'], b['B'], b['A']]);
  308.     this.setColorTone([c['R'], c['G'], c['B'], c['Gray']]);
  309.  
  310.     // Animation Details
  311.     this.count = 0;
  312.     this.sfx_wait = Number(i.sfx_wait);
  313.     this.animation_id = Number(i.animation_id);
  314.     this.speed = Number(i.speed);
  315.     this.wait_time = Number(i.wait_time);
  316.     this._duration = Number(i.total_frames) * Number(i.speed) + Number(i.wait_time);
  317.     };
  318.  
  319.   // Loading the file we want
  320.   Sprite_Balloon.prototype.loadBitmap = function() {
  321.     this.bitmap = ImageManager.loadSystem(items[this._balloonId - 1].filename);
  322.     this.setFrame(0, 0, 0, 0);
  323.   };
  324.  
  325.   // Sprite update time!
  326.   var _Sprite_Balloon_update = Sprite_Balloon.prototype.update;
  327.   Sprite_Balloon.prototype.update = function() {
  328.     _Sprite_Balloon_update.call(this);
  329.     var a = items[this._balloonId - 1];
  330.     if (this.sfx_wait == this.count){
  331.       AudioManager.playSe({name: a.sfx_filename, pan: a.sfx_pan, pitch: a.sfx_pitch, volume: a.sfx_volume});
  332.     };
  333.     this.count++;
  334.   };
  335.  
  336.   // Animation frame update
  337.   Sprite_Balloon.prototype.updateFrame = function() {
  338.     var sx = this.frameIndex() * this.fw;
  339.     var sy = (this.animation_id - 1) * this.fh;
  340.     this.setFrame(sx, sy, this.fw, this.fh);
  341.   };
  342.  
  343.     // Animation speed
  344.     Sprite_Balloon.prototype.speed = function() {
  345.         return Number(items[this._balloonId - 1].speed);
  346.     };
  347.  
  348.     // Additional waiting for the final frame
  349.     Sprite_Balloon.prototype.waitTime = function() {
  350.         return Number(items[this._balloonId - 1].wait_time);
  351.     };
  352.  
  353.   // It has to stay here for some reason that I don't know...
  354.   Sprite_Balloon.prototype.frameIndex = function() {
  355.     var index = (this._duration - this.wait_time) / this.speed;
  356.     return items[this._balloonId - 1].total_frames - Math.max(Math.floor(index), 0);
  357.   };
  358.  
  359. })(); // Do not delete!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement