Advertisement
Guest User

Tinys Pop Up Icon MV

a guest
Feb 13th, 2016
1,500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  *=============================================================================
  3.  * Tinys Pop Up Icon MV Version
  4.  *  By TinyMine / Philipp Brede
  5.  *  Tiny_PopUpIcon.js
  6.  *  Version: 1.1
  7.  *  Free for commercial and non commercial use.
  8.  *=============================================================================
  9.  */
  10. /*:
  11.  * @help
  12.  *=============================================================================
  13.  *  Bugs, Ideas, Requests?...
  14.  *  ...contact TinyMine in rpgmakerweb.com
  15.  *=============================================================================
  16.  *                                   Plugin Commands
  17.  *=============================================================================
  18.  *
  19.  *     █ PopUp Icon characterId iconIndex text amount [waitForEnd]
  20.  *
  21.  *          Help:
  22.  *                  characterId  = eventID to occur on (0 for event where it was
  23.  *                                 called, -1 for player)
  24.  *                  iconIndex    = icon number you want to show
  25.  *                  text         = the name you wanna pass to be displayed as text
  26.  *                  amount       = if you put 0 it will not be shown. But it will
  27.  *                                 be displayed when going above 0.
  28.  *                  waitForEnd   = either 0 or 1, where 1 is wait for end before
  29.  *                                 continuing with further event code [optional]
  30.  *          Example:
  31.  *              PopUp Icon 0 12 Potion 2 1
  32.  *                  Icon 12 will be shown above the event where it was called with
  33.  *                  the text Potion and the amount x2. Furthermore event will wait
  34.  *                  until popup has finished.
  35.  *
  36.  *=============================================================================
  37.  * @plugindesc This lets you pop up icons like you can do with balloons and such.
  38.  *
  39.  * @author TinyMine / Philipp Brede
  40.  *
  41.  * @param General Settings
  42.  * @desc No Use; Following Paramates regard general settings.
  43.  * @default
  44.  *
  45.  * @param Auto PopUp
  46.  * @desc Everytime the player receives an item / gold it will be shown as a pop up. On or Off
  47.  * @default On
  48.  *
  49.  * @param Time
  50.  * @desc Defines the time the icon will be shown in frames. 0-999
  51.  * @default 45
  52.  *
  53.  * @param IconSet Name
  54.  * @desc The graphic name this plugin should use in your system folder.
  55.  * @default IconSet
  56.  *
  57.  * @param Gold Icon Index
  58.  * @desc The index of the icon used for gold popup, on the icon set.
  59.  * @default 208
  60.  *
  61.  * @param Sound Settings
  62.  * @desc Activate Sound when displaying icons? On or Off
  63.  * @default On
  64.  *
  65.  * @param Item Sound
  66.  * @desc The sound that plays whenever you pop up an item icon.
  67.  * @default Item1
  68.  *
  69.  * @param Item Volume
  70.  * @desc The volume of the sound that will play. 0-100
  71.  * @default 100
  72.  *
  73.  * @param Item Pitch
  74.  * @desc The pitch of the sound that will play. 50-150
  75.  * @default 100
  76.  *
  77.  * @param Gold Sound
  78.  * @desc The sound that plays whenever you pop up an item icon.
  79.  * @default Coin
  80.  *
  81.  * @param Gold Volume
  82.  * @desc The volume of the sound that will play. 0-100
  83.  * @default 100
  84.  *
  85.  * @param Gold Pitch
  86.  * @desc The pitch of the sound that will play. 50-150
  87.  * @default 100
  88.  *
  89.  * @param Advanced Settings
  90.  * @desc No Use; Following Paramates regard advanced settings.
  91.  * @default
  92.  *
  93.  * @param Icon Collums
  94.  * @desc How many collums your IconSet has?
  95.  * @default 16
  96.  *
  97.  * @param Icon Width
  98.  * @desc Which width each icon has in your iconset in pixels.
  99.  * @default 32
  100.  *
  101.  * @param Icon Height
  102.  * @desc Which height each icon has in your iconset in pixels.
  103.  * @default 32
  104.  *
  105.  * @param Icon Offset Y
  106.  * @desc Define the offset y position of the icon that will popup;
  107.  * @default -16
  108.  *
  109.  * @param Text Offset Y
  110.  * @desc Define the offset y position of the text that will popup;
  111.  * @default -8
  112.  *
  113.  * @param Text Size
  114.  * @desc Define fontsize of the text that will popup;
  115.  * @default 14
  116.  *
  117.  *=============================================================================
  118.  */
  119. (function () {
  120.     var _usedParams = {}
  121.     //Initializing variables to parameter values
  122.     var parameters = PluginManager.parameters('Tiny_PopUpIcon');
  123.     _usedParams['auto_pop'] = String(parameters['Auto PopUp']);
  124.     _usedParams['time'] = Number(parameters['Time'] || 45);
  125.     _usedParams['icon_png'] = String(parameters['IconSet Name'] || 'IconSet');
  126.     _usedParams['gold_index'] = String(parameters['Gold Icon Index'] || 208);
  127.     _usedParams['sound_on'] = String(parameters['Sound Settings']);
  128.     _usedParams['itemSound'] = String(parameters['Item Sound'] || 'Item1');
  129.     _usedParams['itemVolume'] = Number(parameters['Item Volume'] || 100);
  130.     _usedParams['itemPitch'] = Number(parameters['Item Pitch'] || 100);
  131.     _usedParams['goldSound'] = String(parameters['Gold Sound'] || 'Coin1');
  132.     _usedParams['goldVolume'] = Number(parameters['Gold Volume'] || 100);
  133.     _usedParams['goldPitch'] = Number(parameters['Gold Pitch'] || 100);
  134.     _usedParams['collums'] = Number(parameters['Icon Collums'] || 16);
  135.     _usedParams['icon_width'] = Number(parameters['Icon Width'] || 32);
  136.     _usedParams['icon_height'] = Number(parameters['Icon Height'] || 32);
  137.     _usedParams['icon_y'] = Number(parameters['Icon Offset Y'] || -16);
  138.     _usedParams['text_y'] = Number(parameters['Text Offset Y'] || -8);
  139.     _usedParams['text_size'] = Number(parameters['Text Size'] || 14);
  140.     //-------------------------------------------------------------------------
  141.     // OLD Game_Interpreter
  142.     //  Modified:
  143.     //      - pluginCommand
  144.     //      - updateWaitMode
  145.     var oldGI_pluginCommand_Tiny_PUI = Game_Interpreter.prototype.pluginCommand;
  146.     Game_Interpreter.prototype.pluginCommand = function (command, args) {
  147.         oldGI_pluginCommand_Tiny_PUI.call(this, command, args);
  148.         if (command === 'PopUp') {
  149.             if (args[0] === 'Icon') {
  150.                 this._character = this.character(args[1]);
  151.                 if (this._character) {
  152.                     var itemScheme = {};
  153.                     itemScheme.iconIndex = args[2];
  154.                     itemScheme.name = args[3];
  155.                     this._character.requestPopUp(itemScheme, args[4]);
  156.                     if (args[3] === '1') {
  157.                         this.setWaitMode('popicon');
  158.                     }
  159.                 }
  160.                 return true;
  161.             }
  162.         }
  163.     };
  164.     var oldGI_updateWaitMode_Tiny_PUI = Game_Interpreter.prototype.updateWaitMode;
  165.     Game_Interpreter.prototype.updateWaitMode = function () {
  166.         var waiting = false;
  167.         if (this._waitMode === 'popicon') {
  168.             waiting = this._character.isPopUpPlaying();
  169.         }
  170.         if (waiting) {
  171.             return waiting;
  172.         }
  173.         else {
  174.             return oldGI_updateWaitMode_Tiny_PUI.call(this);
  175.         }
  176.     };
  177.     //-------------------------------------------------------------------------
  178.     // OLD Game_Party
  179.     //  Modified:
  180.     //      - gainItem
  181.     var oldGP_gainItem_Tiny_PUI = Game_Party.prototype.gainItem;
  182.     Game_Party.prototype.gainItem = function (item, amount, includeEquip) {
  183.         if (_usedParams['auto_pop'] === 'On' && amount > 0) {
  184.             var container = this.itemContainer(item);
  185.             if (container) {
  186.                 $gamePlayer.requestPopUp(item, amount);
  187.             }
  188.         }
  189.         oldGP_gainItem_Tiny_PUI.call(this, item, amount, includeEquip);
  190.     };
  191.     //-------------------------------------------------------------------------
  192.     // OLD Game_Party
  193.     //  Modified:
  194.     //      - gainGold
  195.     var oldGP_GainGold__Tiny_PUI = Game_Party.prototype.gainGold;
  196.     Game_Party.prototype.gainGold = function(amount) {
  197.         if (_usedParams['auto_pop'] === 'On') {
  198.             var item = {
  199.               name: 'Gold',
  200.               iconIndex: _usedParams['gold_index']
  201.             };
  202.             $gamePlayer.requestPopUp(item, amount);
  203.         }
  204.         oldGP_GainGold__Tiny_PUI.call(this, amount);
  205.     };
  206.     //-------------------------------------------------------------------------
  207.     // OLD Game_CharacterBase
  208.     //  Modified:
  209.     //      - initMembers
  210.     //  Added:
  211.     //      - startPopUp
  212.     //      - isPopUpPlaying
  213.     //      - endPopUp
  214.     //      - requestPopUp
  215.     var oldGCB_initMembers_Tiny_PUI = Game_CharacterBase.prototype.initMembers;
  216.     Game_CharacterBase.prototype.initMembers = function () {
  217.         oldGCB_initMembers_Tiny_PUI.call(this);
  218.         this._requestedPopUps = []
  219.         this._popUpPlaying = false;
  220.     };
  221.     Game_CharacterBase.prototype.startPopUp = function () {
  222.         this._requestedPopUps.pop();
  223.         this._popUpPlaying = true;
  224.     };
  225.     Game_CharacterBase.prototype.isPopUpPlaying = function () {
  226.         return this._requestedPopUps.length > 0 || this._popUpPlaying;
  227.     };
  228.     Game_CharacterBase.prototype.endPopUp = function () {
  229.         this._popUpPlaying = false;
  230.     };
  231.     Game_CharacterBase.prototype.requestPopUp = function (item, amount) {
  232.         var popUp = {};
  233.         popUp.item = item;
  234.         popUp.amount = amount;
  235.         this._requestedPopUps.push(popUp);
  236.     };
  237.     Game_CharacterBase.prototype.popUpIndex = function () {
  238.         if (this._requestedPopUps.length > 0) {
  239.             return this.popUpItem().iconIndex;
  240.         }
  241.         return 0;
  242.     };
  243.     Game_CharacterBase.prototype.popUpItem = function () {
  244.         if (this._requestedPopUps.length > 0) {
  245.             var last = this._requestedPopUps.length - 1;
  246.             return this._requestedPopUps[last].item;
  247.         }
  248.         return null;
  249.     };
  250.     Game_CharacterBase.prototype.popUpAmount = function () {
  251.         if (this._requestedPopUps.length > 0) {
  252.             var last = this._requestedPopUps.length - 1;
  253.             return this._requestedPopUps[last].amount;
  254.         }
  255.         return 0;
  256.     };
  257.     //-------------------------------------------------------------------------
  258.     // OLD Sprite_Character
  259.     //  Modified:
  260.     //      - updateAnimation
  261.     //  Added:
  262.     //      - setupPopUp
  263.     //      - startPopUp
  264.     //      - updatePopUp
  265.     //      - endPopUp
  266.     //      - isPopUpPlaying
  267.     var oldSC_updateAnimation_Tiny_PUI = Sprite_Character.prototype.updateAnimation;
  268.     Sprite_Character.prototype.updateAnimation = function () {
  269.         oldSC_updateAnimation_Tiny_PUI.call(this);
  270.         if (!this.isPopUpPlaying()) {
  271.             this._character.endPopUp();
  272.         }
  273.     };
  274.     Sprite_Character.prototype.setupPopUp = function () {
  275.         if (this._character.popUpIndex() > 0 && !this.isPopUpPlaying()) {
  276.             this.startPopUp();
  277.             this._character.startPopUp();
  278.         }
  279.     };
  280.     Sprite_Character.prototype.startPopUp = function () {
  281.         if (!this._popUpSprite) {
  282.             this._popUpSprite = new Sprite_PopUpIcon();
  283.             this._popUpWindow = new Sprite_PopUpText();
  284.         }
  285.         this._popUpSprite.setup(this._character.popUpItem(), this._character.popUpAmount());
  286.         this._popUpWindow.setup(this._character.popUpItem(), this._character.popUpAmount());
  287.         this.parent.addChild(this._popUpSprite);
  288.         this.parent.addChild(this._popUpWindow);
  289.         if (_usedParams['sound_on'] === 'On') {
  290.             var type = this._character.popUpItem().name === 'Gold' ? 'gold' : 'item';
  291.             var sePlay = {};
  292.             sePlay.name = _usedParams[type + 'Sound'];
  293.             sePlay.pitch = _usedParams[type + 'Pitch'];
  294.             sePlay.volume = _usedParams[type + 'Volume'];
  295.             sePlay.pan = 0;
  296.             AudioManager.playSe(sePlay);
  297.         }
  298.     };
  299.     Sprite_Character.prototype.updatePopUp = function () {
  300.         this.setupPopUp();
  301.         if (this._popUpSprite) {
  302.             this._popUpSprite.x = this.x;
  303.             this._popUpSprite.y = this.y - this.height + _usedParams['icon_y'];
  304.             this._popUpWindow.x = this.x;
  305.             this._popUpWindow.y = this.y - this.height + _usedParams['text_y'];
  306.             if (!this._popUpSprite.isPlaying()) {
  307.                 this.endPopUp();
  308.             }
  309.         }
  310.     };
  311.     Sprite_Character.prototype.endPopUp = function () {
  312.         if (this._popUpSprite) {
  313.             this.parent.removeChild(this._popUpSprite);
  314.             this.parent.removeChild(this._popUpWindow);
  315.             this._popUpSprite = null;
  316.             this._popUpWindow = null;
  317.         }
  318.     };
  319.     Sprite_Character.prototype.isPopUpPlaying = function () {
  320.         return !!this._popUpSprite;
  321.     };
  322.     var oldSC_update_Tiny_PUI = Sprite_Character.prototype.update;
  323.     Sprite_Character.prototype.update = function () {
  324.         oldSC_update_Tiny_PUI.call(this);
  325.         this.updatePopUp();
  326.     };
  327.     //-------------------------------------------------------------------------
  328.     // NEW Sprite_PopUpText
  329.     //
  330.     // The sprite for displaying popping up text.
  331.     function Sprite_PopUpText() {
  332.         this.initialize.apply(this, arguments);
  333.     }
  334.     //
  335.     Sprite_PopUpText.prototype = Object.create(Sprite.prototype);
  336.     Sprite_PopUpText.prototype.constructor = Sprite_PopUpText;
  337.     //
  338.     Sprite_PopUpText.prototype.initialize = function () {
  339.         Sprite.prototype.initialize.call(this);
  340.         this.initMembers();
  341.         this.loadBitmap();
  342.     };
  343.     Sprite_PopUpText.prototype.initMembers = function () {
  344.         this._duration = 0;
  345.         this.anchor.x = 0.5;
  346.         this.anchor.y = 0.5;
  347.         this.z = 7;
  348.     };
  349.     Sprite_PopUpText.prototype.loadBitmap = function () {
  350.         this.bitmap = new Bitmap(200, 200);
  351.         this.bitmap.fontSize = _usedParams['text_size'];
  352.         this.setFrame(0, 0, 200, 200);
  353.     };
  354.     Sprite_PopUpText.prototype.setup = function (popUpItem, amount) {
  355.         this._duration = this.waitTime();
  356.         this.scale.set(0, 0);
  357.         var amountText = "";
  358.         if (amount > 0) amountText = " x" + amount;
  359.         this.bitmap.drawText(popUpItem.name + amountText, 0, 0, 200, 200, 'center');
  360.     };
  361.     Sprite_PopUpText.prototype.update = function () {
  362.         Sprite.prototype.update.call(this);
  363.         if (this._duration > 0) {
  364.             this._duration--;
  365.             if (this._duration > 0) {
  366.                 this.updateMovement();
  367.             }
  368.         }
  369.     };
  370.     Sprite_PopUpText.prototype.waitTime = function () {
  371.         return _usedParams['time'];
  372.     };
  373.     Sprite_PopUpText.prototype.updateMovement = function () {
  374.         var g = 1.0 / (this.waitTime() / 2) + this.scale.x;
  375.         var n = Math.min(g, 1.0);
  376.         this.scale.set(n, n);
  377.     };
  378.     //-------------------------------------------------------------------------
  379.     // NEW Sprite_PopUpIcon
  380.     //
  381.     // The sprite for displaying popping up icons.
  382.     function Sprite_PopUpIcon() {
  383.         this.initialize.apply(this, arguments);
  384.     }
  385.     //
  386.     Sprite_PopUpIcon.prototype = Object.create(Sprite_Base.prototype);
  387.     Sprite_PopUpIcon.prototype.constructor = Sprite_PopUpIcon;
  388.     //
  389.     Sprite_PopUpIcon.prototype.initialize = function () {
  390.         Sprite_Base.prototype.initialize.call(this);
  391.         this.initMembers();
  392.         this.loadBitmap();
  393.     };
  394.     Sprite_PopUpIcon.prototype.initMembers = function () {
  395.         this._popUpIndex = 0;
  396.         this._duration = 0;
  397.         this.anchor.x = 0.5;
  398.         this.anchor.y = 1;
  399.         this.z = 7;
  400.     };
  401.     Sprite_PopUpIcon.prototype.loadBitmap = function () {
  402.         this.bitmap = ImageManager.loadSystem(_usedParams['icon_png']);
  403.         this.setFrame(0, 0, 0, 0);
  404.     };
  405.     Sprite_PopUpIcon.prototype.setup = function (popUpItem, amount) {
  406.         this._popUpIndex = popUpItem.iconIndex;
  407.         this._duration = this.waitTime();
  408.         this.scale.set(0, 0);
  409.         this.updateFrame();
  410.     };
  411.     Sprite_PopUpIcon.prototype.update = function () {
  412.         Sprite_Base.prototype.update.call(this);
  413.         if (this._duration > 0) {
  414.             this._duration--;
  415.             if (this._duration > 0) {
  416.                 this.updateMovement();
  417.             }
  418.         }
  419.     };
  420.     Sprite_PopUpIcon.prototype.updateMovement = function () {
  421.         var g = 1.0 / (this.waitTime() / 2) + this.scale.x;
  422.         var n = Math.min(g, 1.0);
  423.         this.scale.set(n, n);
  424.     };
  425.     Sprite_PopUpIcon.prototype.updateFrame = function () {
  426.         var pw = _usedParams['icon_width'];
  427.         var ph = _usedParams['icon_height'];
  428.         var sx = this._popUpIndex % _usedParams['collums'] * pw;
  429.         var sy = Math.floor(this._popUpIndex / _usedParams['collums']) * ph;
  430.         this.setFrame(sx, sy, pw, ph);
  431.     };
  432.     Sprite_PopUpIcon.prototype.waitTime = function () {
  433.         return _usedParams['time'];
  434.     };
  435.     Sprite_PopUpIcon.prototype.isPlaying = function () {
  436.         return this._duration > 0;
  437.     };
  438. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement