Advertisement
dricc1

Untitled

Oct 11th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // TinyGetInfoWnd.js
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @plugindesc Display tiny window of gaining/losing items information on map
  7.  * @author Sasuke KANNAZUKI
  8.  *
  9.  * @param EventCommandSwitch
  10.  * @desc If the switch on, display window when change an item number by an
  11.  *  event command (only map scene, not on battle).
  12.  * @default 22
  13.  *
  14.  * @param Ypositiontype
  15.  * @desc Windows' position. 0:top 1:bottom
  16.  * @default 1
  17.  *
  18.  * @param textGainItem
  19.  * @desc title text display on the window when gain item(s).
  20.  * %1 is replaced to the item's kind(weapon/armor/item).
  21.  * @default You got %1
  22.  *
  23.  * @param textLoseItem
  24.  * @desc title text display on the window when lose item(s).
  25.  * %1 is replaced to the item's kind(weapon/armor/item).
  26.  * @default You lost %1
  27.  *
  28.  * @param SEfilename
  29.  * @desc the filename of the SE that plays when you gain item(s).
  30.  * note: It doesn't play when you lose item(s).
  31.  * @default Chime2
  32.  *
  33.  * @param SEvolume
  34.  * @desc the volume of the SE that plays when you gain item(s).
  35.  * @default 90
  36.  *
  37.  * @param SEpitch
  38.  * @desc the pitch of the SE that plays when you gain item(s).
  39.  * @default 100
  40.  *
  41.  * @param GoldItemId
  42.  * @desc The ID of the fictive item representing gold
  43.  * @default 3
  44.  *
  45.  * @help
  46.  * Plugin Commands:
  47.  * TinyGetInfoWnd arg0 arg1 arg2 arg3
  48.  * arg0 must be 'item', 'weapon', 'gold' or 'armor'.
  49.  * arg1 must be the ID of the item(or equipment),
  50.  *  or 'V' + number(ex. 'V20') where the number is the variable ID for item ID.
  51.  * arg2 must be 'gain' or 'lose'. (default value is 'gain').
  52.  * arg3 must be the number of gain/lose. (defalut value is 1).
  53.  *  (arg3 also accepts the same notation as the arg1 like 'V15')
  54.  * ex.
  55.  * TinyGetInfoWnd weapon 14 gain 2  # gain 2 weapons whose id is 14.
  56.  * TinyGetInfoWnd armor 20 lose 1   # lose an armor whose id is 20.
  57.  *   (if you equip the armor, it will not be lost.)
  58.  * TinyGetInfoWnd item 7    # gain an item whose id is 7.
  59.  *   (default value, arg2='gain' and arg3='1' is applied.)
  60.  * TinyGetInfoWnd item V10 gain 3   # gain 3 items whose ID is variable #10.
  61.  * TinyGetInfoWnd gold gain 10 # gain 10
  62.  * TinyGetInfoWnd gold gain V10 # gain the value of the variable 10
  63.  *
  64.  * note description:
  65.  * <info:the_explanation> : the_explanation is displayed when gain or lose
  66.  *  the item. If it isn't written down, the first line of the item's
  67.  *  description is displayed.
  68.  *
  69.  * Item lost is not more than the party has.
  70.  * When you have only 3 and execute 'lose 5' for the item,
  71.  * it will display 'lost 3'.
  72.  * When you have the item none, even if execute 'lose', do not display window.
  73.  */
  74.  
  75. (function() {
  76.   //
  77.   // process parameters
  78.   //
  79.   var parameters = PluginManager.parameters('TinyGetInfoWnd');
  80.   var dispSwitchID = Number(parameters['EventCommandSwitch'] || 22);
  81.   var yPosType = Number(parameters['Ypositiontype'] || 1);
  82.   var textGainItem = parameters['textGainItem'] || 'Vous obtenez %1';
  83.   var textLoseItem = parameters['textLoseItem'] || 'Vous perdez %1';
  84.   var seFilename = parameters['SEfilename'] || 'Shop1';
  85.   var seVolume = Number(parameters['SEvolume'] || 90);
  86.   var sePitch = Number(parameters['SEpitch'] || 100);
  87.   var goldItemId = Number(parameters['GoldItemId'] || 2);
  88.  
  89.   //
  90.   // process plugin commands
  91.   //
  92.   var _Game_Interpreter_pluginCommand =
  93.    Game_Interpreter.prototype.pluginCommand;
  94.   Game_Interpreter.prototype.pluginCommand = function(command, args) {
  95.     _Game_Interpreter_pluginCommand.call(this, command, args);
  96.     if (command === 'TinyGetInfoWnd') {
  97.       // find args[1]
  98.       var itemId = 0;
  99.       var reg = (/^V([0-9]+)/i).exec(args[1]);
  100.       if(reg){
  101.         itemId = $gameVariables.value(Number(reg[1])) || 0;
  102.       } else {
  103.         itemId = Number(args[1]) || 0;
  104.       }
  105.       // find args[3]
  106.       var itemNumber = 0;
  107.       reg = (/^V([0-9]+)/i).exec(args[3]);
  108.       if(reg){
  109.         itemNumber = $gameVariables.value(Number(reg[1])) || 1;
  110.       } else {
  111.         itemNumber = Number(args[3]) || 1;
  112.       }
  113.       // get current spriteset
  114.       var spriteSet = null;
  115.       if(!$gameParty.inBattle()){
  116.         spriteSet = SceneManager._scene._spriteset;
  117.       }
  118.       // parse parameters
  119.       switch(args[0]) {
  120.       case 'item':
  121.         if(!!$dataItems[itemId] && !!spriteSet) {
  122.           switch(args[2]) {
  123.           case 'gain':
  124.           case undefined:
  125.             // gain item process
  126.             var text = textGainItem.format(TextManager.item);
  127.             spriteSet.addGetInfoWindow(itemId, 0, text, itemNumber);
  128.             break;
  129.           case 'lose':
  130.             // lose item process
  131.             var text = textLoseItem.format(TextManager.item);
  132.             spriteSet.addGetInfoWindow(itemId, 0, text, -itemNumber);
  133.             break;
  134.           }
  135.         }
  136.         break;
  137.       case 'weapon':
  138.         if(!!$dataWeapons[itemId] && !!spriteSet) {
  139.           switch(args[2]) {
  140.           case 'gain':
  141.           case undefined:
  142.             // gain weapon process
  143.             var text = textGainItem.format(TextManager.weapon);
  144.             spriteSet.addGetInfoWindow(itemId, 1, text, itemNumber);
  145.             break;
  146.           case 'lose':
  147.             // lose weapon process
  148.             var text = textLoseItem.format(TextManager.weapon);
  149.             spriteSet.addGetInfoWindow(itemId, 1, text, -itemNumber);
  150.             break;
  151.           }
  152.         }
  153.         break;
  154.       case 'gold':
  155.         if(1 === 1) {
  156.           reg = (/^V([0-9]+)/i).exec(args[2]);
  157.           if(reg){
  158.             itemNumber = $gameVariables.value(Number(reg[1])) || 1;
  159.           } else {
  160.             itemNumber = Number(args[2]) || 1;
  161.           }
  162.           switch(args[1]) {
  163.           case 'gain':
  164.           case undefined:
  165.             // gain gold process
  166.             var text = textGainItem.format(TextManager.currencyUnit);
  167.             spriteSet.addGetInfoWindow(0, 3, text, itemNumber);
  168.             break;
  169.           case 'lose':
  170.             // lose gold process
  171.             var text = textLoseItem.format(TextManager.currencyUnit);
  172.             spriteSet.addGetInfoWindow(0, 3, text, -itemNumber);
  173.             break;
  174.           }
  175.         }
  176.         break;
  177.       case 'armor':
  178.         if(!!$dataArmors[itemId] && !!spriteSet) {
  179.           switch(args[2]) {
  180.           case 'gain':
  181.           case undefined:
  182.             // gain armor process
  183.             var text = textGainItem.format(TextManager.armor);
  184.             spriteSet.addGetInfoWindow(itemId, 2, text, itemNumber);
  185.             break;
  186.           case 'lose':
  187.             // lose armor process
  188.             var text = textLoseItem.format(TextManager.armor);
  189.             spriteSet.addGetInfoWindow(itemId, 2, text, -itemNumber);
  190.             break;
  191.           }
  192.         }
  193.         break;
  194.       }
  195.     }
  196.   };
  197.  
  198.   //
  199.   // variable initialization
  200.   //
  201.   var _Game_Temp_initialize = Game_Temp.prototype.initialize;
  202.   Game_Temp.prototype.initialize = function() {
  203.     _Game_Temp_initialize.call(this);
  204.     this.strEffect = [];
  205.     this.getInfoOccupied = [];
  206.   };
  207.  
  208.   //
  209.   // process spriteset
  210.   //
  211.   var _Scene_Map_onMapLoaded = Scene_Map.prototype.onMapLoaded;
  212.   Scene_Map.prototype.onMapLoaded = function() {
  213.     $gameTemp.strEffect = [];
  214.     $gameTemp.getInfoOccupied = [];
  215.     _Scene_Map_onMapLoaded.call(this);
  216.   };
  217.  
  218.   Spriteset_Map.prototype.addGetInfoWindow = function(id, type, text, value) {
  219.     var w = new Window_GetInfo(id, type, text, value);
  220.     $gameTemp.strEffect.push(w);
  221.     this._baseSprite.addChild(w);
  222.   };
  223.  
  224.   var _Spriteset_Map_update = Spriteset_Map.prototype.update;
  225.   Spriteset_Map.prototype.update = function() {
  226.     _Spriteset_Map_update.call(this);
  227.     for(var i = 0; i < $gameTemp.strEffect.length; i++) {
  228.       if($gameTemp.strEffect[i].disposed) {
  229.         $gameTemp.strEffect[i] = null;
  230.         continue;
  231.       }
  232.       $gameTemp.strEffect[i].update();
  233.     }
  234.     $gameTemp.strEffect =
  235.      $gameTemp.strEffect.filter(function(window){return window != null;});
  236.   };
  237.  
  238.   var _Scene_Map_terminate = Scene_Map.prototype.terminate;
  239.   Scene_Map.prototype.terminate = function() {
  240.     $gameTemp.strEffect = [];
  241.     $gameTemp.getInfoOccupied = [];
  242.     _Scene_Map_terminate.call(this);
  243.   };
  244.  
  245.   // -------------------------------------------------------------------------
  246.   // Window_GetInfo
  247.   //
  248.   // The tiny window to display item gain/lose situation on map.
  249.  
  250.   function Window_GetInfo(){
  251.     this.initialize.apply(this, arguments);
  252.   }
  253.  
  254.   Window_GetInfo.prototype = Object.create(Window_Base.prototype);
  255.   Window_GetInfo.prototype.constructor = Window_GetInfo;
  256.  
  257.   Window_GetInfo.prototype.initialize = function(id, type, text, value) {
  258.     Window_Base.prototype.initialize.call(this, -24, 0, 864, 105);
  259.     this.disposed = false;
  260.     // set opacities
  261.     this.opacity = 0;
  262.     this.backOpacity = 0;
  263.     this.contentsOpacity = 0;
  264.     // set count
  265.     this.count = 0;
  266.     // make room for new index
  267.     this.index = $gameTemp.getInfoOccupied.indexOf(null);
  268.     if(this.index === -1) {
  269.       this.index = $gameTemp.getInfoOccupied.length;
  270.     }
  271.     $gameTemp.getInfoOccupied[this.index] = true;
  272.     // set Y position
  273.     if(yPosType == 0){
  274.       this.y = this.index * 60;
  275.     } else {
  276.       this.y = 520 - (this.index * 60);
  277.     }
  278.     // draw and get item
  279.     this.setup(id, type, text, value);
  280.     // play SE
  281.     switch(type) {
  282.     case 0: // item
  283.     case 1: // weapon
  284.     case 3: // gold
  285.     case 2: // armor
  286.       if(value >= 1) {   // play when gain, not play when lose.
  287.         if(seFilename){
  288.           var audio = {};
  289.           audio.name = seFilename;
  290.           audio.volume = seVolume;
  291.           audio.pitch = sePitch;
  292.           AudioManager.playSe(audio);
  293.         }
  294.       }
  295.       break;
  296.     default: // not supported
  297.       break;
  298.     }
  299.   };
  300.  
  301.   Window_GetInfo.prototype.setup = function(id, type, text, value) {
  302.     // determine item data
  303.     var data = '';
  304.     switch(type) {
  305.     case 0:
  306.       data = $dataItems[id];
  307.       break;
  308.     case 1:
  309.       data = $dataWeapons[id];
  310.       break;
  311.     case 2:
  312.       data = $dataArmors[id];
  313.       break;
  314.     case 3:
  315.       data = $dataItems[goldItemId];
  316.       break;
  317.     }
  318.     // check number (whether the party has the number of item to lose)
  319.     if(type >= 0 && type <= 2) {
  320.       if(value < 0){
  321.         if(-value > $gameParty.numItems(data)){
  322.           value = -$gameParty.numItems(data);
  323.         }
  324.       }
  325.       if(value == 0) {
  326.         return;
  327.       }
  328.     }
  329.     // fill background
  330.     this.contents.paintOpacity = 160;
  331.     this.contents.fillRect(0, 21, 816, 36, '#000000');
  332.     // draw item name, number, description
  333.     if(type >= 0 && type <= 3) {
  334.       this.contents.paintOpacity = 255;
  335.       this.changeTextColor(this.normalColor());      
  336.       if(value < 0){
  337.         this.contents.paintOpacity = 160;
  338.       }
  339.       this.drawItemName(data, 6, 21, 300);
  340.       this.drawText('\xd7', 306, 21, 24, 'center');
  341.       this.drawText(String(Math.abs(value)), 330, 21, 32, 'right');
  342.       this.drawText(this.description(data), 384, 21, 432, 'left');
  343.     }
  344.     // draw guide string
  345.     this.contents.paintOpacity = 160;
  346.     this.contents.fontSize = 20;
  347.     this.contents.fillRect(0, 0, this.textWidth(text) + 6, 22, '#000000');
  348.     this.contents.paintOpacity = 255;
  349.     this.changeTextColor(this.normalColor());
  350.     this.drawText(text, 6, -8, 510, 'left');
  351.     // gain item
  352.     if(type >= 0 && type <= 2) {
  353.       $gameParty.gainItem(data, value);
  354.     }
  355.     if(type === 3) {
  356.       $gameParty.gainGold(value);
  357.     }
  358.   };
  359.  
  360.   Window_GetInfo.prototype.description = function(data) {
  361.     if(data.meta.info) {
  362.       return data.meta.info;
  363.     }
  364.     return data.description.replace(/[\r\n]+.*/m, "");
  365.   };
  366.  
  367.   Window_GetInfo.prototype.update = function() {
  368.     Window_Base.prototype.update.call(this);
  369.     if(++this.count < 180) {
  370.       this.contentsOpacity += 32;
  371.     } else {
  372.       if(yPosType == 0){
  373.         this.y -= 2;
  374.       } else {
  375.         this.y += 2;
  376.       }
  377.       this.contentsOpacity -= 32;
  378.       if(this.contentsOpacity == 0){
  379.         this.remove();
  380.       }
  381.     }
  382.   };
  383.  
  384.   Window_GetInfo.prototype.remove = function() {
  385.     $gameTemp.getInfoOccupied[this.index] = null;
  386.     this.parent.removeChild(this);
  387.     this.disposed = true;
  388.   };
  389.  
  390.   //
  391.   // interpreter commands
  392.   // *** note *** : To prevent multiple exection of operateValue,
  393.   // not to alias but overwriting functions.
  394.  
  395.   // Change Items
  396.   Game_Interpreter.prototype.command126 = function() {
  397.     var value = this.operateValue(this._params[1], this._params[2],
  398.      this._params[3]);
  399.     if($gameSwitches.value(dispSwitchID) && !$gameParty.inBattle() &&
  400.      value != 0) {
  401.       var text = '';
  402.       var spriteSet = SceneManager._scene._spriteset;
  403.       if(value > 0){
  404.         text = textGainItem.format(TextManager.item);
  405.       } else {
  406.         text = textLoseItem.format(TextManager.item);
  407.       }
  408.       spriteSet.addGetInfoWindow(this._params[0], 0, text, value);
  409.     } else {
  410.       $gameParty.gainItem($dataItems[this._params[0]], value);
  411.     }
  412.     return true;
  413.   };
  414.  
  415.   // Change Weapons
  416.   Game_Interpreter.prototype.command127 = function() {
  417.     var value = this.operateValue(this._params[1], this._params[2],
  418.      this._params[3]);
  419.     if($gameSwitches.value(dispSwitchID) && !$gameParty.inBattle() &&
  420.      value != 0) {
  421.       var text = '';
  422.       var spriteSet = SceneManager._scene._spriteset;
  423.       if(value > 0){
  424.         text = textGainItem.format(TextManager.weapon);
  425.       } else {
  426.         text = textLoseItem.format(TextManager.weapon);
  427.       }
  428.       spriteSet.addGetInfoWindow(this._params[0], 1, text, value);
  429.     } else {
  430.       $gameParty.gainItem($dataWeapons[this._params[0]], value,
  431.        this._params[4]);
  432.     }
  433.     return true;
  434.   };
  435.  
  436.   // Change Armors
  437.   Game_Interpreter.prototype.command128 = function() {
  438.     var value = this.operateValue(this._params[1], this._params[2],
  439.      this._params[3]);
  440.     if($gameSwitches.value(dispSwitchID) && !$gameParty.inBattle() &&
  441.      value != 0) {
  442.       var text = '';
  443.       var spriteSet = SceneManager._scene._spriteset;
  444.       if(value > 0){
  445.         text = textGainItem.format(TextManager.armor);
  446.       } else {
  447.         text = textLoseItem.format(TextManager.armor);
  448.       }
  449.       spriteSet.addGetInfoWindow(this._params[0], 2, text, value);
  450.     } else {
  451.       $gameParty.gainItem($dataArmors[this._params[0]], value,
  452.        this._params[4]);
  453.     }
  454.     return true;
  455.   };
  456.  
  457. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement