Jragyn

[MV] J_RecordWindow

Dec 6th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* -------------------------------------------------------------------------- */
  2. // J_HUD
  3. // V: 1.0
  4.  
  5. /*:@plugindesc Stemmed from Mr. Wriggles' SimpleHUD, but added more things.
  6. @author J (+ mr wiggles)
  7.  
  8. @param HUD_width
  9. @desc width of HUD
  10. @default 420
  11.  
  12. @param HUD_height
  13. @desc height of HUD
  14. @default 128
  15.  
  16. @param HUD_opacity
  17. @desc The visibility (0 being invis, 255 being solid) of the HUD.
  18. @default 255
  19.  
  20. @help This is a generic HUD plugin. It accomplishes the goal of displaying
  21.       things like HP/MP/TP while on the map.
  22.     The following plugin commands are available:
  23.      'show' = show HUD; Example 'HUD hide'
  24.      'hide' = hide HUD; Example 'HUD show'
  25. */
  26. /* -------------------------------------------------------------------------- */
  27. var Imported = Imported || {};
  28. Imported.J_HUD = true;
  29.  
  30. var J = J || {};
  31. J.HUD = J.HUD || {};
  32. J.HUD.Parameters = PluginManager.parameters('J_HUD');
  33. J.HUD.width = Number(J.HUD.Parameters['HUD_width']);
  34. J.HUD.height = Number(J.HUD.Parameters['HUD_height']);
  35. J.HUD.HUDopacity = Number(J.HUD.Parameters['HUD_opacity']);
  36.  
  37. (function() { // start plugin.
  38. /* -------------------------------------------------------------------------- */
  39. //  Game_Interpreter Modifications
  40. //    deals with the extra pluginCommand stuff for manually doing things
  41. //    within the game (using the pluginCommand event command).
  42. /* -------------------------------------------------------------------------- */
  43.   var _Game_Interpreter_jHUD_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  44.   Game_Interpreter.prototype.pluginCommand = function(command, args) {
  45.     _Game_Interpreter_jHUD_pluginCommand.call(this, command, args);
  46.     if (command === 'HUD') {
  47.       switch (args[0]) {
  48.         case 'hide': SoundManager.playOk(); break;
  49.         case 'show': SoundManager.playOk(); break;
  50.       }
  51.     }
  52.   };
  53. /* -------------------------------------------------------------------------- */
  54. //  Scene_Map Modifications
  55. //    Handles the update process of the HUD.
  56. //    If not created creates. If created, updates.
  57. /* -------------------------------------------------------------------------- */
  58.  
  59.   // hooks into Scene_Map.update and gets the ball rolling.
  60.   var _Scene_Map_jHUD_update = Scene_Map.prototype.update;
  61.   Scene_Map.prototype.update = function() {
  62.     this.handleHUD();
  63.     _Scene_Map_jHUD_update.call(this);
  64.   };
  65.  
  66.   // if the window on the map doesn't exist, make it.
  67.   // if it does exist, update it.
  68.   // if there is stuff going on, hide window.
  69.   Scene_Map.prototype.handleHUD = function() {
  70.     if (this._HUDWindow) {
  71.       this._HUDWindow.update;
  72.     } else {
  73.       this._HUDWindow = new Window_HUD(0,0);
  74.       this.addWindow(this._HUDWindow);
  75.       this._HUDWindow.opacity = J.HUD.HUDopacity;
  76.     };
  77.     if (this.hideExtras()) {
  78.       this._HUDWindow.close();
  79.     }
  80.     else {
  81.         this._HUDWindow.open();
  82.     }
  83.   };
  84. /* -------------------------------------------------------------------------- */
  85. //  Window_HUD [NEW]
  86. //    Creates the main window that houses all the visual data.
  87. /* -------------------------------------------------------------------------- */
  88.   function Window_HUD() { this.initialize.apply(this, arguments); }
  89.   Window_HUD.prototype = Object.create(Window_Base.prototype);
  90.   Window_HUD.prototype.constructor = Window_HUD;
  91.  
  92.   // the initialization of the window.
  93.   // effectively, what happens when first called.
  94.   Window_HUD.prototype.initialize = function(x, y) {
  95.     Window_Base.prototype.initialize.call(this, x, Graphics.height - J.HUD.height,
  96.       J.HUD.width, J.HUD.height);
  97.       this._updateWait = 0;
  98.       this.z = 0;
  99.       this.refresh();
  100.       this.activate();
  101.     };
  102.  
  103.     // handles the "when i should refresh" functionality.
  104.     Window_HUD.prototype.update = function() {
  105.       Window_Base.prototype.update.call(this);
  106.       if (this._updateWait <= 0) {
  107.         this.refresh();
  108.         this._updateWait = 3;
  109.       } else {
  110.         this._updateWait--;
  111.       }
  112.     };
  113.  
  114.     // the updating of contents within the window.
  115.     // handled by the .update method.
  116.     Window_HUD.prototype.refresh = function() {
  117.       if (this.contents) {
  118.         if ($gameParty != null) {
  119.           var actor = $gameParty.leader();
  120.         }
  121.         var lineHeight = this.lineHeight();
  122.         this.contents.clear();
  123.         if (actor) {
  124.           this.drawHUDstatus(actor, 0, 0, 300);
  125.         }
  126.       }
  127.     };
  128.  
  129.     // does all the heavy lifting.
  130.     // all things drawn here.
  131.     Window_Base.prototype.drawHUDstatus = function(actor, x, y, width) {
  132.       this.contents.fontSize = 18;
  133.       var lh = 18;
  134.       var x2 = x + 120; var x3 = 264;
  135.       var barWidth = 200;
  136.  
  137.       // colors for bars.
  138.       var hpc1 = this.hpGaugeColor1(); var hpc2 = this.hpGaugeColor2();
  139.       var mpc1 = this.mpGaugeColor1(); var mpc2 = this.mpGaugeColor2();
  140.       var tpc1 = this.tpGaugeColor1(); var tpc2 = this.tpGaugeColor2();
  141.  
  142.       // draws name and face
  143.       this.drawFace(actor.faceName(), actor.faceIndex(), x, y, 100, 64);
  144.       this.drawActorName(actor, x2, y);
  145.  
  146.       // draws hp and gauge
  147.       this.drawGaugeMod(x2, y + 6 +  lh * 1, barWidth, 8, actor.hpRate(), hpc1, hpc2);
  148.       this.drawText(actor.hp.toFixed(0), x3, y + lh * 1, 100, 'left');
  149.  
  150.       // draws mp and gauge
  151.       this.drawGaugeMod(x2, y + 6 + lh * 2, barWidth, 8, actor.mpRate(), mpc1, mpc2);
  152.       this.drawText(actor.mp.toFixed(0), x3, y + lh * 2, 100, 'left');
  153.  
  154.       // draws tp and gauge
  155.       this.drawGaugeMod(x2, y + 10 + lh * 3, barWidth, 4, actor.tpRate(), tpc1, tpc2);
  156.       this.drawText(actor.tp.toFixed(0), x3, y + lh * 3, 100, 'left');
  157.  
  158.       // draws exp and gauge
  159.       this.drawEXPgauge(actor, x, y + 10 + lh * 3, barWidth);
  160.       this.drawText(actor.nextRequiredExp(), x, y + 10 + lh * 3, 44);
  161.       this.drawActorLevel(actor, x2 + 128, y);
  162.  
  163.       // draws icons for status buff/debuffs
  164.       this.drawActorIcons(actor, x + 256, y);
  165.     };
  166.  
  167.     // custom method for drawing a gauge for the leader's EXP.
  168.     Window_Base.prototype.drawEXPgauge = function(actor, x, y, width) {
  169.       width = width || 186;
  170.       var color1 = this.textColor(24);
  171.       var color2 = this.textColor(25);
  172.       var xp4next = actor.nextLevelExp() - actor.currentLevelExp();
  173.       var cExp = actor.currentExp() - actor.currentLevelExp();
  174.       var expRate = cExp / xp4next;
  175.       this.drawGaugeMod(x, y+10, width, 12, expRate, color1, color2);
  176.     };
  177.  
  178.     // a custom variant of the drawGauge function.
  179.     // allows for also drawing the height of the gauge.
  180.     Window_Base.prototype.drawGaugeMod = function(x, y, width, height, rate, color1, color2) {
  181.       var fillW = Math.floor(width * rate);
  182.       var gaugeY = y + height;
  183.       this.contents.fillRect(x, gaugeY, width, height, this.gaugeBackColor());
  184.       this.contents.gradientFillRect(x, gaugeY, fillW, height, color1, color2);
  185.     };
  186. /* -------------------------------------------------------------------------- */
  187. })(); // end plugin.
Add Comment
Please, Sign In to add comment