Advertisement
blackmorning

BM_ShopCore

Jun 3rd, 2016
1,328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Blackmorning Engine Plugins - Shop Core
  3. // BM_ShopCore.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.BM_ShopCore = true;
  8.  
  9. var BM = BM || {};
  10. //=============================================================================
  11.  /*:
  12.  * @plugindesc Shop Scene (v1.20)
  13.  * Shop layout setup
  14.  * @author Blackmorning
  15.  *
  16.  * @param ---General---
  17.  * @default
  18.  *
  19.  * @param CommandWindowAlign
  20.  * @parent ---General---
  21.  * @type combo
  22.  * @option left
  23.  * @option right
  24.  * @desc Location of the command window.
  25.  * left     right
  26.  * @default right
  27.  *
  28.  * @param CommandColumns
  29.  * @parent ---General---
  30.  * @type number
  31.  * @min 1
  32.  * @desc Number of columns in the command window.
  33.  * default for basic 3, yanfly 1
  34.  * @default 3
  35.  *
  36.  * @param CommandRows
  37.  * @parent ---General---
  38.  * @type number
  39.  * @min 1
  40.  * @desc Number of rows visible in the command window.
  41.  * default for basic 1, yanfly 4
  42.  * @default 1
  43.  *
  44.  * @param CommandWindowFull
  45.  * @parent ---General---
  46.  * @type boolean
  47.  * @on Enable
  48.  * @off Disable
  49.  * @desc Command window goes all the way across (best with 1 row)
  50.  * NO - false     YES - true
  51.  * @default false
  52.  *
  53.  * @param ---Status Window---
  54.  * @default
  55.  *
  56.  * @param StatusWindowWidth
  57.  * @parent ---Status Window---
  58.  * @type number
  59.  * @min 1
  60.  * @desc Width of the Shop Status window.
  61.  * default 400
  62.  * @default 400
  63.  *
  64.  * @param ParametersFontSize
  65.  * @parent ---Status Window---
  66.  * @type number
  67.  * @min 1
  68.  * @desc Font size of parameters.
  69.  * @default 20
  70.  *
  71.  * @param ---Status Actor Display---
  72.  * @default
  73.  *
  74.  * @param ShopActorParameters
  75.  * @parent ---Status Actor Display---
  76.  * @desc Parameters shown when comparing equipment.
  77.  * Separate parameters by a space. * see help *
  78.  * @default mhp mmp atk def mat mdf agi hit cri
  79.  *
  80.  * @param DisplayActors
  81.  * @parent ---Status Actor Display---
  82.  * @type number
  83.  * @min 0
  84.  * @desc Display a comparison for actors (# per page) or special
  85.  * # actors per page     0 - special display (single actor)
  86.  * @default 4
  87.  *
  88.  * @param CantEquipTxt
  89.  * @parent ---Status Actor Display---
  90.  * @desc Text for when actor can't equip item for special display
  91.  * @default Can't Equip
  92.  *
  93.  * @param EquippedTxt
  94.  * @parent ---Status Actor Display---
  95.  * @desc Text for number of equipment worn (
  96.  * if blank, number of equipment worn not shown
  97.  * @default Equipped
  98.  *
  99.  * @param ShowDifference
  100.  * @parent ---Status Actor Display---
  101.  * @type boolean
  102.  * @on Enable
  103.  * @off Disable
  104.  * @desc Show the change in parameters for special display?
  105.  * NO - false     YES - true
  106.  * @default true
  107.  *
  108.  * @param ComparePlusIcon
  109.  * @parent ---Status Actor Display---
  110.  * @desc Choose icon to show positive stat changes.
  111.  * default - leave blank to show none.
  112.  * @default
  113.  *
  114.  * @param CompareMinusIcon
  115.  * @parent ---Status Actor Display---
  116.  * @desc Choose icon to show negative stat changes.
  117.  * default - leave blank to show none.
  118.  * @default
  119.  *
  120.  * @param ---Number Window---
  121.  * @default
  122.  *
  123.  * @param ShowTouchButtons
  124.  * @parent ---Number Window---
  125.  * @type boolean
  126.  * @on Enable
  127.  * @off Disable
  128.  * @desc Always show touch buttons?
  129.  * NO - false     YES - true
  130.  * @default true
  131.  *
  132.  * @help
  133.  * ============================================================================
  134.  * Introduction
  135.  * ============================================================================
  136.  * Title: BM Shop Scene
  137.  * Author: Blackmorning
  138.  * Version: 1.21
  139.  * Website: http://bmscripts.weebly.com/mv-shop.html
  140.  
  141.  * - Decide what parameters to show/compare (using symbols in table below)
  142.  * - parameter percentage added directly to comparison
  143.  * - Customize layout of shop
  144.  * - added information on items, equipment
  145.  * - choose between special single actor or group comparison
  146.  *
  147.  * -- Compatiblity --
  148.  *
  149.  * - YEP Shop Core (Put YEP above this script)
  150.  * ============================================================================
  151.  * Instructions
  152.  * ============================================================================
  153.  * Table of built-in parameters:
  154.  * ============================
  155.  * | Symbol |      Name       |
  156.  * ============================
  157.  * | mhp    | Max HP          |
  158.  * | mmp    | Max MP          |
  159.  * | atk    | Attack          |
  160.  * | def    | Defense         |
  161.  * | mat    | M.Attack        |
  162.  * | mdf    | M.Defense       |
  163.  * | agi    | Agility         |
  164.  * | luk    | Luck            |
  165.  * =======================================
  166.  * | hit    | Hit Rate        | percent  |
  167.  * | eva    | Evasion         | percent  |
  168.  * | cri    | Critical Rate   | percent  |
  169.  * | cev    | Crit Evasion    | percent  |
  170.  * | mev    | Magic Evasion   | percent  |
  171.  * | mrf    | M. Reflection   | percent  |
  172.  * | cnt    | Counterattack   | percent  |
  173.  * | hrg    | HP Regen Rate   | percent  |
  174.  * | mrg    | MP Regen Rate   | percent  |
  175.  * | trg    | TP Regen Rate   | percent  |
  176.  * =======================================
  177.  * | tgr    | Target Rate     | percent  |
  178.  * | grd    | Guard Effect    | percent  |
  179.  * | rec    | Recovery Effect | percent  |
  180.  * | pha    | Pharmacology    | percent  |
  181.  * | mcr    | MP Cost Rate    | percent  |
  182.  * | tcr    | TP Cost Rate    | percent  |
  183.  * | pdr    | Phys Damage %   | percent  |
  184.  * | mdr    | Magic Damage %  | percent  |
  185.  * | fdr    | Floor Damage %  | percent  |
  186.  * | exr    | Exp Gain Rate   | percent  |
  187.  * =======================================
  188.  *
  189.  * ============================================================================
  190.  * Changelog
  191.  ============================================================================
  192.  * Version 1.21: 2018-Apr-01
  193.  * - fixed error with parameters
  194.  * Version 1.20: 2018-Mar-16
  195.  * - compatibility with EIS Shop System
  196.  * - updated for RPG Maker MV version 1.5.0
  197.  * Version 1.10: 2017-Feb-23
  198.  * - added info from YEP ShopCore
  199.  * Version 1.00: 2016-Jun-03
  200.  * - Finished plugin!
  201.  */
  202. //=============================================================================
  203. BM.Parameters = PluginManager.parameters('BM_ShopCore');
  204. BM.Shop = BM.Shop || {};
  205. BM.Icon = BM.Icon || {};
  206. BM.Vocab = BM.Vocab || {};
  207. BM.Shop.version = 1.21
  208.  
  209. BM.Shop.CommandWindowAlign = String(BM.Parameters['CommandWindowAlign']);
  210. BM.Shop.CommandColumns = Number(BM.Parameters['CommandColumns']);
  211. BM.Shop.CommandRows = Number(BM.Parameters['CommandRows']);
  212. BM.Shop.CommandWindowFull = eval(String(BM.Parameters['CommandWindowFull']));
  213. BM.Shop.StatusWidth = Number(BM.Parameters['StatusWindowWidth']);
  214. BM.Shop.ParamFontSize = Number(BM.Parameters['ParametersFontSize']);
  215.  
  216. BM.Shop.SDisplayActors = Number(BM.Parameters['DisplayActors']);
  217. BM.Shop.SShowDifference = eval(String(BM.Parameters['ShowDifference']));
  218. BM.Shop.CantEquipTxt = String(BM.Parameters['CantEquipTxt'])
  219. BM.Shop.EquippedTxt = String(BM.Parameters['EquippedTxt'] || '')
  220. BM.Shop.ShowTouchButtons = eval(String(BM.Parameters['ShowTouchButtons']));
  221.  
  222. BM.Icon.Plus = Number(BM.Parameters['ComparePlusIcon']);
  223. BM.Icon.Minus = Number(BM.Parameters['CompareMinusIcon']);
  224.  
  225. BM.Data = String(BM.Parameters['ShopActorParameters']);
  226. BM.Data = BM.Data.split(' ');
  227. BM.Shop.SActorParam = [];
  228. for (BM.i = 0; BM.i < BM.Data.length; ++BM.i) {
  229.   BM.Shop.SActorParam.push(BM.Data[BM.i]);
  230. };
  231. //=============================================================================
  232. if (!Imported.BM_EquipCore){
  233. TextManager.paramName = function(paramName) {
  234.     var name = ''
  235.     if(!name || name == '') {
  236.         switch(paramName){
  237.             case 'mhp':
  238.             return $dataSystem.terms.params[0] || '';
  239.             case 'mmp':
  240.             return $dataSystem.terms.params[1] || '';
  241.             case 'atk':
  242.             return $dataSystem.terms.params[2] || '';
  243.             case 'def':
  244.             return $dataSystem.terms.params[3] || '';
  245.             case 'mat':
  246.             return $dataSystem.terms.params[4] || '';
  247.             case 'mdf':
  248.             return $dataSystem.terms.params[5] || '';
  249.             case 'agi':
  250.             return $dataSystem.terms.params[6] || '';
  251.             case 'luk':
  252.             return $dataSystem.terms.params[7] || '';
  253.             case 'hit':
  254.             return $dataSystem.terms.params[8] || '';
  255.             case 'eva':
  256.             return $dataSystem.terms.params[9] || '';
  257.         }
  258.     }
  259.     if (!name || name == "undefined"){
  260.         name = capitalize_Words(paramName)
  261.     }  
  262.     return name
  263. };
  264. function capitalize_Words(str)
  265. {
  266.  return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
  267. }
  268. //=============================================================================
  269. Window_Base.prototype.checkParamPercent = function(paramName) {
  270.     percent = true;
  271.     switch(paramName){
  272.     case 'mhp':
  273.     case 'mmp':
  274.     case 'atk':
  275.     case 'def':
  276.     case 'mat':
  277.     case 'mdf':
  278.     case 'agi':
  279.     case 'luk':
  280.     percent = false;
  281.     break;
  282.     }
  283.     if (Imported.Quasi_ParamsPlus){
  284.         for (var i = 0; i < QuasiParams._custom.length; i++) {
  285.             if (paramName == QuasiParams._customAbr(i)){   
  286.                 percent = false;
  287.                 break;
  288.             }
  289.         }
  290.     }
  291.     return percent
  292. }
  293. Window_Base.prototype.textLineHeight = function() {
  294.     return (this.contents.fontSize + this.textPadding()*2)
  295. };
  296. Window_Base.prototype.drawDarkRect = function(dx, dy, dw, dh) {
  297.     var color = this.gaugeBackColor();    
  298.     this.changePaintOpacity(false);    
  299.     this.contents.fillRect(dx + 1, dy + 1, dw - 2, dh - 2, color);    
  300.     this.changePaintOpacity(true);
  301. };
  302. }
  303. Window_Base.prototype.calculateHeight = function(y, list, height) {
  304.     height = height || this.contents.height;
  305.     this._plist = 0
  306.     this._newPY = 0
  307.     var h = height - y;
  308.     var tf = h / this.textLineHeight();
  309.     var pf = Math.floor(Math.min(tf,list.length));
  310.     var dh = pf * this.textLineHeight();
  311.     var dy = Math.floor((h - dh)/2);
  312.     this._newPY = y + dy
  313.     this._plist = pf
  314. }
  315. //=============================================================================
  316. Game_Actor.prototype.forceChangeEquipById = function(etypeId, itemId) {
  317.     var slotId = etypeId - 1;
  318.     if (this.equipSlots()[slotId] === 1) {
  319.         this.forceChangeEquip(slotId, $dataWeapons[itemId]);
  320.     } else {
  321.         this.forceChangeEquip(slotId, $dataArmors[itemId]);
  322.     }
  323. };
  324. //=============================================================================
  325. Window_ShopCommand.prototype.windowWidth = function() {
  326.     if (BM.Shop.CommandWindowFull){
  327.         return Graphics.width
  328.     } else {
  329.         return Graphics.width - BM.Shop.StatusWidth;
  330.     }    
  331. };
  332. Window_ShopCommand.prototype.maxCols = function() {
  333.     return BM.Shop.CommandColumns;
  334. };
  335. Window_ShopCommand.prototype.numVisibleRows = function() {
  336.     return BM.Shop.CommandRows;
  337. };
  338. //=============================================================================
  339. Window_ShopBuy.prototype.windowWidth = function() {
  340.     return Graphics.width - BM.Shop.StatusWidth;
  341. };
  342. Window_ShopBuy.prototype.drawItem = function(index) {
  343.     var item = this._data[index];
  344.     var rect = this.itemRect(index);
  345.     var priceWidth = this.textWidth(this.price(item));
  346.     rect.width -= this.textPadding();
  347.     this.changePaintOpacity(this.isEnabled(item));
  348.     this.drawItemName(item, rect.x, rect.y, rect.width - priceWidth);
  349.     this.drawText(this.price(item), rect.x + rect.width - priceWidth,
  350.                   rect.y, priceWidth, 'right');
  351.     this.changePaintOpacity(true);
  352. };
  353. Window_ShopSell.prototype.maxCols = function() {
  354.     return 1;
  355. };
  356. Window_ShopSell.prototype.setStatusWindow = function(statusWindow) {
  357.     this._statusWindow = statusWindow;
  358.     this.callUpdateHelp();
  359. };
  360. Window_ShopSell.prototype.updateHelp = function() {
  361.     this.setHelpWindowItem(this.item());
  362.     if (this._statusWindow) {
  363.         this._statusWindow.setItem(this.item());
  364.     }
  365. };
  366. //=============================================================================
  367. var KR = KR || {};
  368. Window_ShopStatus.prototype.refresh = function() {
  369.     this.contents.clear();
  370.     if (this._item) {
  371.         var x = this.textPadding();
  372.         var y = 0
  373.         if (KR.ShopManager){
  374.             this.drawShopPossession(x, 0);
  375.             y = this.lineHeight();
  376.         }      
  377.         this.drawPossession(x, y);
  378.         this.contents.fontSize = BM.Shop.ParamFontSize
  379.         if (BM.Shop.EquippedTxt != ''){
  380.             dy = this.lineHeight()*5 + y
  381.         }else{
  382.             dy = this.lineHeight()*4 + y
  383.         }
  384.         var param = BM.Shop.SActorParam
  385.         this.calculateHeight(dy, param)
  386.         this.resetFontSettings();
  387.         if (this.isEquipItem()) {
  388.             this.drawEquipInfo(this._item);
  389.          } else {
  390.             this.drawItemInfo(this._item);
  391.         }      
  392.     }
  393. };
  394. Window_ShopStatus.prototype.drawPossession = function(x, y) {
  395.     var width = this.contents.width - this.textPadding() - x;
  396.     var possessionWidth = this.textWidth('0000');
  397.     this.changeTextColor(this.systemColor());
  398.     this.drawText(TextManager.currencyUnit, x, y, width - possessionWidth);
  399.     this.drawText(TextManager.possession, x, y + this.lineHeight(), width - possessionWidth);
  400.     this.resetTextColor();
  401.     this.drawText($gameParty.gold(), x, y, width, 'right');
  402.     this.drawText($gameParty.numItems(this._item), x, y + this.lineHeight(), width, 'right');
  403.     if ((this.isEquipItem()) && (BM.Shop.EquippedTxt != '')){
  404.         this._equipped = 0
  405.         var members = $gameParty.members()
  406.         for (var i = 0; i < members.length; i++) {
  407.             var item1 = this.currentEquippedItem(members[i], this._item.etypeId);
  408.             if (this._item == item1){
  409.                 this._equipped += 1
  410.             }
  411.         }
  412.         this.changeTextColor(this.systemColor());
  413.         this.drawText(BM.Shop.EquippedTxt, x, y + this.lineHeight()*2, width - this.textWidth('0000'));
  414.         this.resetTextColor();
  415.         this.drawText(this._equipped, x, y + this.lineHeight()*2, width, 'right');
  416.     }
  417. };
  418. Window_ShopStatus.prototype.pageSize = function() {
  419.     if (BM.Shop.SDisplayActors != 0){
  420.         return BM.Shop.SDisplayActors;
  421.     } else{
  422.         return 1;
  423.     }    
  424. };
  425. Window_ShopStatus.prototype.createWidths = function() {
  426.     this._paramNameWidth = 0;
  427.     this._paramValueWidth = 0;
  428.     this._columnSize = 0
  429.     this._arrowWidth = this.textWidth('\u2192' + ' ');
  430.     var buffer = this.textWidth(' ')
  431.     for (var i = 0; i < 8; ++i) {
  432.       var value1 = this.textWidth(TextManager.param(i));
  433.       var value2 = this.textWidth('9999');
  434.       this._paramNameWidth = Math.max(value1, this._paramNameWidth);
  435.       this._paramValueWidth = Math.max(value2, this._paramValueWidth);
  436.     }
  437.     this._bonusValueWidth = this._paramValueWidth;
  438.     this._bonusValueWidth += this.textWidth('(+)') + buffer;
  439.     this._paramNameWidth += buffer;
  440.     if (this._paramNameWidth + this._paramValueWidth * 2 + this._arrowWidth + this._bonusValueWidth > this.contents.width) {
  441.         this._bonusValueWidth = 0;
  442.     }
  443.     this._columnSize = (this.contents.width - this._paramNameWidth/1.5) / this.pageSize()
  444. };
  445. Window_ShopStatus.prototype.drawEquipInfo = function(item) {
  446.     this.createWidths()
  447.     var param = BM.Shop.SActorParam
  448.     var members = this.statusMembers();
  449.     var rect = new Rectangle();
  450.     rect.width = this.contents.width;
  451.     for (var i = 0; i < members.length; i++) {
  452.         var dw = this._columnSize
  453.         cx = this.contents.width - dw*this.pageSize() + (i * dw) - this.textPadding()
  454.         h = 0
  455.         if (KR.Plugins){h = this.lineHeight()}
  456.         this.drawEquipChar(members[i], cx + 32, this.lineHeight()*4 + h)
  457.     }
  458.     for (var i = 0; i < this._plist; ++i) {
  459.         this.contents.fontSize = BM.Shop.ParamFontSize
  460.         rect = this.getRectPosition(rect, i);
  461.         var dx = rect.x + this.textPadding();
  462.         var dw = rect.width - this.textPadding() * 2;  
  463.         this.drawDarkRect(rect.x, rect.y, rect.width, this.textLineHeight());
  464.         this.changeTextColor(this.systemColor());
  465.         this.drawParamName(rect.y, param[i])
  466.         for (var j = 0; j < members.length; j++) {
  467.             if (BM.Shop.SDisplayActors != 0){
  468.                 var dw = this._columnSize
  469.                 cx = this.contents.width - dw*this.pageSize() + (j * dw) - this.textPadding()
  470.                 this.drawActorEquipInfo(cx, rect.y, members[j], param[i]);
  471.             } else{
  472.                 this.drawSoloEquipInfo(this._paramNameWidth, rect.y, members[j], param[i]);
  473.             }
  474.         }
  475.     }
  476.     this.resetFontSettings();
  477. };
  478. Window_ShopStatus.prototype.drawActorEquipInfo = function(x, y, actor, param) {
  479.     var enabled = actor.canEquip(this._item);
  480.     this.resetTextColor();
  481.     this.contents.fontSize = BM.Shop.ParamFontSize
  482.     var item1 = this.currentEquippedItem(actor, this._item.etypeId);
  483.     if (enabled) {
  484.         this.setTempActor(actor, item1);       
  485.         this.drawActorParamChange(x, y, actor, item1, param);
  486.     }
  487.     this.resetFontSettings();
  488. };
  489. Window_ShopStatus.prototype.drawSoloEquipInfo = function(x, y, actor, param) {
  490.     var enabled = actor.canEquip(this._item);
  491.     this.resetTextColor();
  492.     this.contents.fontSize = BM.Shop.ParamFontSize
  493.     var item1 = this.currentEquippedItem(actor, this._item.etypeId);
  494.     if (enabled) {     
  495.         this.setTempActor(actor, item1);       
  496.         this.drawSoloParamChange(x, y, param);
  497.     }
  498.     this.resetFontSettings();
  499. };
  500. Window_ShopStatus.prototype.drawEquipChar = function(actor, x, y) {
  501.     var enabled = actor.canEquip(this._item);
  502.     this.changePaintOpacity(enabled);
  503.     var item1 = this.currentEquippedItem(actor, this._item.etypeId);
  504.     if (BM.Shop.SDisplayActors != 0){          
  505.         this.drawActorCharacter(actor, x + 16, y)
  506.         this.drawIcon((item1 ? item1.iconIndex : 0), x, y)
  507.     }else{
  508.         this.drawActorCharacter(actor, 25, y)
  509.         this.drawText(actor.name(), 50, y - this.lineHeight(), this.contents.height - x);
  510.         this.drawDarkRect(Window_Base._iconWidth, y, this.contents.width-this.padding-Window_Base._iconWidth/2, Window_Base._iconHeight+this.textPadding());
  511.         if (enabled) {
  512.             this.drawItemName(item1, Window_Base._iconWidth, y);       
  513.         } else{
  514.             this.changePaintOpacity(enabled);
  515.             this.drawText(BM.Shop.CantEquipTxt, Window_Base._iconWidth + this.textPadding(), y, this.contents.width-this.padding-Window_Base._iconWidth/2);
  516.         };
  517.     };
  518.     this.changePaintOpacity(true);
  519. }
  520. Window_ShopStatus.prototype.getRectPosition = function(rect, i) {  
  521.     rect.x = 0
  522.     rect.y = this._newPY + this.textLineHeight()*i;
  523.     return rect;
  524. };
  525. Window_ShopStatus.prototype.drawActorParamChange = function(x, y, actor, item1, paramName) {
  526.     var percent = this.checkParamPercent(paramName)
  527.     var width = this._columnSize;
  528.     var oldValue = eval("this._actor." + paramName, this);
  529.     var newValue = eval("this._tempActor." + paramName, this);
  530.     var diffvalue = newValue - oldValue;
  531.     var change = diffvalue
  532.     if (diffvalue > 0 && BM.Icon.Plus && BM.Icon.Plus != 0){
  533.         this.drawIcon(BM.Icon.Plus, x, y)
  534.     }
  535.     if (diffvalue < 0 && BM.Icon.Minus && BM.Icon.Minus != 0){
  536.         this.drawIcon(BM.Icon.Minus, x, y)
  537.     }
  538.     if (percent == true) {
  539.         change = Math.round(diffvalue * 100) + "%";
  540.     }
  541.     this.changeTextColor(this.paramchangeTextColor(change));
  542.     this.drawText((diffvalue > 0 ? '+' : '') + change, x, y, width, 'right');
  543. };
  544. Window_ShopStatus.prototype.drawItemInfo = function(item) {
  545.     //for plugin
  546. };
  547. Window_ShopStatus.prototype.setTempActor = function(actor, item1) {
  548.     this._actor = actor
  549.     this._tempActor = JsonEx.makeDeepCopy(actor)
  550.     if (item1 === null){
  551.         this._tempActor.forceChangeEquip(this._item.etypeId-1, this._item);
  552.     } else {
  553.         this._tempActor.forceChangeEquipById(item1.etypeId, this._item.id);
  554.     }
  555. }
  556. BM.Shop.Window_ShopStatus_drawItemName = Window_ShopStatus.prototype.drawItemName;
  557. Window_ShopStatus.prototype.drawItemName = function(item, x, y, width) {
  558.     width = width || this.contents.width;
  559.     BM.Shop.Window_ShopStatus_drawItemName.call(this, item, x, y, width - x - this.textPadding());    
  560. };
  561. Window_ShopStatus.prototype.drawParamName = function(y, paramName) {
  562.     var x = this.textPadding()
  563.     this.changeTextColor(this.systemColor());
  564.     var name = TextManager.paramName(paramName);
  565.     this.drawText(name, x, y, this._paramNameWidth);
  566. };
  567. Window_ShopStatus.prototype.drawSoloParamChange = function(x, y, paramName) {
  568.     var width = this._columnSize;
  569.     this.drawRightArrow(y);
  570.     this.drawCurrentParam(y, paramName)
  571.     this.drawNewParam(y, paramName)
  572.     if (BM.Shop.SShowDifference) this.drawParamDifference(y, paramName);
  573. };
  574. Window_ShopStatus.prototype.drawRightArrow = function(y) {
  575.     var x = this.contents.width - this.textPadding();
  576.     x -= this._paramValueWidth * 2 + this._arrowWidth;
  577.     var dw = this.textWidth('\u2192' + ' ');
  578.     this.changeTextColor(this.systemColor());
  579.     this.drawText('\u2192', x, y, dw, 'right');
  580. };
  581. Window_ShopStatus.prototype.drawCurrentParam = function(y, paramName) {
  582.     var percent = this.checkParamPercent(paramName)
  583.     var x = this.contents.width - this.padding;
  584.     x -= this._paramValueWidth * 3 + this._arrowWidth;
  585.     this.resetTextColor();
  586.     var value = eval("this._actor." + paramName, this);
  587.     if (percent == true) {         
  588.         value = Math.round(value * 100) + "%";
  589.     }
  590.     this.drawText(value, x, y, this._paramValueWidth, 'right');
  591. };
  592. Window_ShopStatus.prototype.drawNewParam = function(y, paramName) {
  593.     var percent = this.checkParamPercent(paramName)
  594.     var x = this.contents.width - this.padding;
  595.     x -= this._paramValueWidth;
  596.     var oldValue = eval("this._actor." + paramName, this);
  597.     var newValue = eval("this._tempActor." + paramName, this);
  598.     var diffvalue = newValue - oldValue;
  599.     this.changeTextColor(this.paramchangeTextColor(diffvalue));
  600.     if (diffvalue > 0 && BM.Icon.Plus && BM.Icon.Plus != 0){
  601.         this.drawIcon(BM.Icon.Plus, x, y)
  602.     }
  603.     if (diffvalue < 0 && BM.Icon.Minus && BM.Icon.Minus != 0){
  604.         this.drawIcon(BM.Icon.Minus, x, y)
  605.     }
  606.     if (percent == true) {         
  607.         newValue = Math.round(newValue * 100) + "%";
  608.     }
  609.     this.drawText(newValue, 0, y, this.contents.width, 'right');
  610. };
  611. Window_ShopStatus.prototype.drawParamDifference = function(y, paramName) {
  612.     var percent = this.checkParamPercent(paramName)
  613.     this.contents.fontSize = BM.Shop.ParamFontSize/1.5
  614.     var x = this.contents.width - this.textPadding();
  615.     x -= this._paramValueWidth * 2 + this._arrowWidth/2;
  616.     var oldValue = eval("this._actor." + paramName, this);
  617.     var newValue = eval("this._tempActor." + paramName, this);
  618.     var diffvalue = newValue - oldValue;
  619.     this.changeTextColor(this.paramchangeTextColor(diffvalue));
  620.     var text = diffvalue;
  621.     if (percent == true) {
  622.         text = Math.round(text * 100) + "%";
  623.     }
  624.     text = (diffvalue > 0 ? '+' : '') + text
  625.     text = (diffvalue != 0 ? '(' + text + ')' : '')
  626.     this.drawText(text, x, y - this.contents.fontSize/1.5, this._bonusValueWidth, 'left');
  627. };
  628. //=============================================================================
  629. Window_ShopNumber.prototype.windowWidth = function() {
  630.     return Graphics.width - BM.Shop.StatusWidth;
  631. };
  632. Window_ShopNumber.prototype.refresh = function() {
  633.     this.contents.clear();
  634.     this.drawDarkRect(0, 0, this.contents.width, this.textLineHeight());
  635.     this.drawItemName(this._item, 0, 0);
  636.     this.drawItemEntry();
  637.     this.drawInitialPrice()
  638.     this.drawMultiplicationSign();
  639.     this.drawNumber();
  640.     this.drawTotalPrice();
  641. };
  642.  
  643. Window_ShopNumber.prototype.drawItemEntry = function() {
  644.     if (!this._item) return;
  645.     var item = this._item;
  646.     if (DataManager.isItem(item)) this.drawItemInfo(item);
  647.     if (DataManager.isWeapon(item)) this.drawEquipInfo(item);
  648.     if (DataManager.isArmor(item)) this.drawEquipInfo(item);
  649. };
  650. Window_ShopNumber.prototype.drawItemInfo = function(item) {
  651.     //for plugin
  652. };
  653. Window_ShopNumber.prototype.drawEquipInfo = function(item) {
  654.     //for plugin
  655. };
  656. Window_ShopNumber.prototype.drawInitialPrice = function() {
  657.     var total = this._price;
  658.     var width = this.contentsWidth() - this.textPadding();
  659.     this.changeTextColor(this.systemColor());
  660.     this.drawText("Price", 0, this.itemY() - this.lineHeight(), width);
  661.     this.resetTextColor();
  662.     this.drawCurrencyValue(total, this._currencyUnit, 0, this.itemY() - this.lineHeight(), width);
  663. };
  664. Window_ShopNumber.prototype.drawNumber = function() {
  665.     var x = this.cursorX();
  666.     var y = this.itemY();
  667.     var width = this.cursorWidth() - this.textPadding();
  668.     this.changeTextColor(this.systemColor());
  669.     this.drawText("Number", 0, y, this.contentsWidth() - this.textPadding());
  670.     this.resetTextColor();
  671.     this.drawText(this._number, x, y, width, 'right');
  672. };
  673. Window_ShopNumber.prototype.drawTotalPrice = function() {
  674.     var total = this._price * this._number;
  675.     var width = this.contentsWidth() - this.textPadding();
  676.     this.changeTextColor(this.systemColor());
  677.     this.drawText("Total", 0, this.priceY(), width);
  678.     this.resetTextColor();
  679.     this.drawCurrencyValue(total, this._currencyUnit, 0, this.priceY(), width);
  680. };
  681. Window_ShopNumber.prototype.priceY = function() {
  682.     return Math.round(this.contentsHeight() - this.lineHeight());
  683. };
  684. Window_ShopNumber.prototype.itemY = function() {
  685.     this.visibleButtons()
  686.     if (this._buttonsVisible) {
  687.         return Math.round(this.contentsHeight() - this.lineHeight()*4.5);
  688.     }else{
  689.         return Math.round(this.contentsHeight() - this.lineHeight()*2);
  690.     }
  691. };
  692. Window_ShopNumber.prototype.buttonY = function() {
  693.     return Math.round(this.contentsHeight() - this.lineHeight() * 2.5);
  694. };
  695. Window_ShopNumber.prototype.visibleButtons = function(){
  696.     if (BM.Shop.ShowTouchButtons || (TouchInput.date > Input.date)){
  697.         this._buttonsVisible = true
  698.     }else{
  699.         this._buttonsVisible = false
  700.     }
  701. }
  702. Window_ShopNumber.prototype.updateButtonsVisiblity = function() {
  703.     this.visibleButtons()
  704.     if (this._buttonsVisible) {
  705.         this.showButtons();
  706.     } else {
  707.         this.hideButtons();
  708.     }
  709. };
  710. //=============================================================================
  711. function Window_Item2Category() {
  712.     this.initialize.apply(this, arguments);
  713. }
  714.  
  715. Window_Item2Category.prototype = Object.create(Window_HorzCommand.prototype);
  716. Window_Item2Category.prototype.constructor = Window_Item2Category;
  717.  
  718. Window_Item2Category.prototype.initialize = function() {
  719.     Window_HorzCommand.prototype.initialize.call(this, 0, 0);
  720. };
  721.  
  722. Window_Item2Category.prototype.windowWidth = function() {
  723.     return Graphics.width - BM.Shop.StatusWidth;
  724. };
  725.  
  726. Window_Item2Category.prototype.maxCols = function() {
  727.     return 4;
  728. };
  729.  
  730. Window_Item2Category.prototype.update = function() {
  731.     Window_HorzCommand.prototype.update.call(this);
  732.     if (this._itemWindow) {
  733.         this._itemWindow.setCategory(this.currentSymbol());
  734.     }
  735. };
  736.  
  737. Window_Item2Category.prototype.makeCommandList = function() {
  738.     this.addCommand(TextManager.item,    'item');
  739.     this.addCommand(TextManager.weapon,  'weapon');
  740.     this.addCommand(TextManager.armor,   'armor');
  741.     this.addCommand(TextManager.keyItem, 'keyItem');
  742. };
  743.  
  744. Window_Item2Category.prototype.setItemWindow = function(itemWindow) {
  745.     this._itemWindow = itemWindow;
  746.     this.update();
  747. };
  748. //=============================================================================
  749. BM.Shop.Scene_Shop_create = Scene_Shop.prototype.create;
  750. Scene_Shop.prototype.create = function() {
  751.     BM.Shop.Scene_Shop_create.call(this);
  752.     this.relocateWindows();
  753. }
  754. Scene_Shop.prototype.relocateWindows = function() {
  755.     if (BM.Shop.CommandWindowAlign == 'right') {
  756.         this._commandWindow.x  = this._statusWindow.width;
  757.         this._dummyWindow.x    = this._statusWindow.width;
  758.         this._buyWindow.x      = this._statusWindow.width;
  759.         this._sellWindow.x     = this._statusWindow.width;
  760.         this._categoryWindow.x = this._statusWindow.width;
  761.         this._numberWindow.x   = this._statusWindow.width;
  762.         this._statusWindow.x = 0;      
  763.     };
  764. }
  765. Scene_Shop.prototype.createGoldWindow = function() {
  766.     this._goldWindow = new Window_Gold(0, this._helpWindow.height);
  767.     this._goldWindow.x = Graphics.boxWidth - this._goldWindow.width;
  768.     this.addWindow(this._goldWindow);
  769.     this._goldWindow.hide();
  770. };
  771. Scene_Shop.prototype.createStatusWindow = function() {
  772.     var wx = this._numberWindow.width;
  773.     if (BM.Shop.CommandWindowFull){
  774.         var wy = this._commandWindow.y + this._commandWindow.height;
  775.     }else{
  776.         var wy = this._commandWindow.y;
  777.     }
  778.     var ww = Graphics.boxWidth - wx;
  779.     var wh = Graphics.boxHeight - wy;
  780.     this._statusWindow = new Window_ShopStatus(wx, wy, ww, wh);
  781.     this.addWindow(this._statusWindow);
  782. };
  783. BM.Shop.Scene_Shop_createDummyWindow = Scene_Shop.prototype.createDummyWindow;
  784. Scene_Shop.prototype.createDummyWindow = function() {
  785.     BM.Shop.Scene_Shop_createDummyWindow.call(this);
  786.     this._dummyWindow.width = Graphics.boxWidth - BM.Shop.StatusWidth;
  787. };
  788. Scene_Shop.prototype.createCategoryWindow = function() {
  789.     this._categoryWindow = new Window_Item2Category();
  790.     this._categoryWindow.setHelpWindow(this._helpWindow);
  791.     this._categoryWindow.y = this._dummyWindow.y;
  792.     this._categoryWindow.hide();
  793.     this._categoryWindow.deactivate();
  794.     this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
  795.     this._categoryWindow.setHandler('cancel', this.onCategoryCancel.bind(this));
  796.     this.addWindow(this._categoryWindow);
  797. };
  798. Scene_Shop.prototype.createSellWindow = function() {
  799.     var wy = this._categoryWindow.y + this._categoryWindow.height;
  800.     var ww = this._dummyWindow.width;
  801.     var wh = Graphics.boxHeight - wy;
  802.     this._sellWindow = new Window_ShopSell(0, wy, ww, wh);
  803.     this._sellWindow.setHelpWindow(this._helpWindow);
  804.     this._sellWindow.setStatusWindow(this._statusWindow);
  805.     this._sellWindow.hide();
  806.     this._sellWindow.setHandler('ok',     this.onSellOk.bind(this));
  807.     this._sellWindow.setHandler('cancel', this.onSellCancel.bind(this));
  808.     this._categoryWindow.setItemWindow(this._sellWindow);
  809.     this.addWindow(this._sellWindow);
  810. };
  811. BM.Shop.Scene_Shop_commandBuy = Scene_Shop.prototype.commandBuy;
  812. Scene_Shop.prototype.commandBuy = function() {
  813.     BM.Shop.Scene_Shop_commandBuy.call(this);
  814.     this._statusWindow.show();
  815. };
  816. BM.Shop.Scene_Shop_onBuyCancel = Scene_Shop.prototype.onBuyCancel;
  817. Scene_Shop.prototype.onBuyCancel = function() {
  818.     BM.Shop.Scene_Shop_onBuyCancel.call(this);
  819.     this._statusWindow.show();
  820. };
  821. BM.Shop.Scene_Shop_activateSellWindow = Scene_Shop.prototype.activateSellWindow;
  822. Scene_Shop.prototype.activateSellWindow = function() {
  823.     BM.Shop.Scene_Shop_activateSellWindow.call(this);
  824.     this._statusWindow.show();
  825. };
  826. //=============================================================================
  827. if (Imported.YEP_ShopMenuCore){
  828. //=============================================================================
  829. Window_ShopStatus.prototype.initialize = function(x, y, width, height) {
  830.     Yanfly.Shop.Window_ShopStatus_initialize.call(this, x, y, width, height);
  831. };
  832. Window_ShopStatus.prototype.update = function() {
  833.     Yanfly.Shop.Window_ShopStatus_update.call(this);
  834. };
  835. Window_ShopStatus.prototype.paramId = function() {
  836.     return Yanfly.Shop.Window_ShopStatus_paramId.call(this);
  837. };
  838. //=============================================================================
  839. BM.Shop.Scene_Shop_createStatusWindow = Scene_Shop.prototype.createStatusWindow;
  840. Scene_Shop.prototype.createStatusWindow = function() {
  841.     BM.Shop.Scene_Shop_createStatusWindow.call(this);
  842.     this._buyWindow.setStatusWindow(this._statusWindow);
  843.     this._sellWindow.setStatusWindow(this._statusWindow);
  844. };
  845.  
  846. Window_ShopStatus.prototype.drawItemInfo = function(item) {
  847.     this.contents.fontSize = BM.Shop.ParamFontSize
  848.     var rect = new Rectangle();
  849.     rect.width = this.contents.width;
  850.     for (var i = 0; i < 8; ++i) {
  851.       rect = this.getRectPosition(rect, i);
  852.       var dx = rect.x + this.textPadding();
  853.       var dw = rect.width - this.textPadding() * 2;  
  854.       this.drawDarkRect(rect.x, rect.y, rect.width, this.textLineHeight());
  855.       this.changeTextColor(this.systemColor());
  856.       var text = this.getItemInfoCategory(i);
  857.       this.drawText(text, dx, rect.y, dw);
  858.       this.drawItemData(i, dx, rect.y, dw);
  859.     }
  860.     this.resetFontSettings();
  861. };
  862. Window_ShopStatus.prototype.getRectPosition = function(rect, i) {  
  863.     rect.x = 0
  864.     rect.y = this._newPY + this.textLineHeight()*i;
  865.     return rect;
  866. };
  867. Window_Base.prototype.getItemInfoCategory = function(i) {
  868.     var fmt = Yanfly.Param.ItemRecoverFmt;
  869.     if (i === 0) return fmt.format(TextManager.param(0));
  870.     if (i === 1) return fmt.format(TextManager.hp);
  871.     if (i === 2) return fmt.format(TextManager.param(1));
  872.     if (i === 3) return fmt.format(TextManager.mp);
  873.     if (i === 4) return Yanfly.Param.ItemAddState;
  874.     if (i === 5) return Yanfly.Param.ItemRemoveState;
  875.     if (i === 6) return Yanfly.Param.ItemAddBuff;
  876.     if (i === 7) return Yanfly.Param.ItemRemoveBuff;
  877.     return '';
  878. };
  879. Window_Base.prototype.drawItemData = function(i, dx, dy, dw) {
  880.     if (!this._item) return;
  881.     var effect;
  882.     var value = '---';
  883.     var pre = '';
  884.     var text = '';
  885.     var icons = [];
  886.     if (i === 0) {
  887.       effect = this.getEffect(Game_Action.EFFECT_RECOVER_HP);
  888.       value = (effect) ? effect.value1 : '---';
  889.       if (value === 0) value = '---';
  890.       if (value !== '---' && value !== 0) value *= 100;
  891.     }
  892.     if (i === 1) {
  893.       effect = this.getEffect(Game_Action.EFFECT_RECOVER_HP);
  894.       value = (effect) ? effect.value2 : '---';
  895.       if (value === 0) value = '---';
  896.     }
  897.     if (i === 2) {
  898.       effect = this.getEffect(Game_Action.EFFECT_RECOVER_MP);
  899.       value = (effect) ? effect.value1 : '---';
  900.       if (value === 0) value = '---';
  901.       if (value !== '---' && value !== 0) value *= 100;
  902.     }
  903.     if (i === 3) {
  904.       effect = this.getEffect(Game_Action.EFFECT_RECOVER_MP);
  905.       value = (effect) ? effect.value2 : '---';
  906.       if (value === 0) value = '---';
  907.     }
  908.     if (i >= 4) {
  909.       icons = this.getItemIcons(i, icons);
  910.     }
  911.     this.changeTextColor(this.normalColor());
  912.     if (value === '---') {
  913.       this.changePaintOpacity(false);
  914.     } else if (i < 4) {
  915.       if (value > 0) pre = '+';
  916.       value = Yanfly.Util.toGroup(parseInt(value));
  917.       if ([0, 2].contains(i)) text = '%';
  918.     }
  919.     if (icons.length > 0) {
  920.       this.changePaintOpacity(true);
  921.       dx = dx + dw - icons.length * Window_Base._iconWidth;
  922.       dx += this.textPadding() - 2;
  923.       for (var j = 0; j < icons.length; ++j) {
  924.         var icon = icons[j];
  925.         this.drawIcon(icon, dx, dy + 2);
  926.         dx += Window_Base._iconWidth;
  927.       }
  928.     } else {
  929.       text = pre + value + text;
  930.       this.drawText(text, dx, dy, dw, 'right');
  931.       this.changePaintOpacity(true);
  932.     }
  933. };
  934. Window_Base.prototype.getEffect = function(code) {
  935.     var targetEffect;
  936.     this._item.effects.forEach(function(effect) {
  937.       if (effect.code === code) targetEffect = effect;
  938.     }, this);
  939.     return targetEffect;
  940. };
  941. Window_Base.prototype.getItemIcons = function(i, array) {
  942.     this._item.effects.forEach(function(effect) {
  943.       if (i === 4 && effect.code === Game_Action.EFFECT_ADD_STATE) {
  944.         var state = $dataStates[effect.dataId];
  945.         if (state && state.iconIndex !== 0) array.push(state.iconIndex);
  946.       }
  947.       if (i === 5 && effect.code === Game_Action.EFFECT_REMOVE_STATE) {
  948.         var state = $dataStates[effect.dataId];
  949.         if (state && state.iconIndex !== 0) array.push(state.iconIndex);
  950.       }
  951.       if (i === 6 && effect.code === Game_Action.EFFECT_ADD_BUFF) {
  952.         var icon = Game_BattlerBase.ICON_BUFF_START + effect.dataId;
  953.         array.push(icon);
  954.       }
  955.       if (i === 6 && effect.code === Game_Action.EFFECT_ADD_DEBUFF) {
  956.         var icon = Game_BattlerBase.ICON_DEBUFF_START + effect.dataId;
  957.         array.push(icon);
  958.       }
  959.       if (i === 7 && effect.code === Game_Action.EFFECT_REMOVE_BUFF) {
  960.         var icon = Game_BattlerBase.ICON_BUFF_START + effect.dataId;
  961.         array.push(icon);
  962.       }
  963.       if (i === 7 && effect.code === Game_Action.EFFECT_REMOVE_DEBUFF) {
  964.         var icon = Game_BattlerBase.ICON_DEBUFF_START + effect.dataId;
  965.         array.push(icon);
  966.       }
  967.     }, this);
  968.     array = array.slice(0, Yanfly.Param.ItemMaxIcons);
  969.     return array;
  970. }
  971. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement