Advertisement
DaxSoft

[MV] Steampunk HUD

Oct 17th, 2015
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Steampunk Hud
  3. // By Kvothe
  4. // steampunk_hud.js
  5. // Version: 0.1
  6. // Free for commercial and non commercial use.
  7. //=============================================================================
  8. var Imported = Imported || {};
  9. var SteampunkHud = SteampunkHud || {};
  10. 'use strict';
  11. //=============================================================================
  12. // Game_System:initialize
  13. //=============================================================================
  14. var __oldGameSystem_initialize = Game_System.prototype.initialize;
  15. Game_System.prototype.initialize = function() {
  16.   __oldGameSystem_initialize.call(this);
  17.   this._steamHud = true;
  18. }
  19. //=============================================================================
  20. // Game_System::steamHud
  21. //=============================================================================
  22. Object.defineProperty(Game_System.prototype, 'steamHud', {
  23.   get: function() {
  24.     return this._steamHud || false;
  25.   }, set : function(value) {
  26.     if ( typeof value == 'boolean' ) {
  27.       this._steamHud = value;
  28.     }
  29.   }
  30. })
  31. //=============================================================================
  32. // [Extended]Number:to_p
  33. //=============================================================================
  34. Number.prototype.to_p = function(actual, max) {
  35.   return (this * actual / max);
  36. }
  37. //=============================================================================
  38. // function:OpacityEffect
  39. //=============================================================================
  40. function numberEffectUpDown(num, low, max) {
  41.   var _num = num
  42.       _low = low
  43.       _max = max
  44.       _chg = true;
  45.   if ( _chg == true ) {
  46.     _num = _num > _max ? _num + 1 : _max;
  47.     if ( _num > _max ) { _chg = false };
  48.   } else {
  49.     _num = _num < _low ? _num - 1 : _low;
  50.     if ( _num < _low ) { _chg = true };
  51.   }
  52.   return _now
  53. }
  54. //=============================================================================
  55. // Sprite:SteampunkHud
  56. //=============================================================================
  57. function SpriteSteampunkHud() { this.initialize.apply(this, arguments) }
  58. SpriteSteampunkHud.prototype.constructor = SpriteSteampunkHud;
  59. //=============================================================================
  60. // steampunk_hud:
  61. //=============================================================================
  62. (function($){
  63.   //---------------------------------------------------------------------------
  64.   // Carregar parameters.
  65.   //---------------------------------------------------------------------------
  66.   $.Parameters = PluginManager.parameters['SteampunkHud'];
  67.   $.Param = $.Param || {};
  68.   //---------------------------------------------------------------------------
  69.   // Configuração.
  70.   //---------------------------------------------------------------------------
  71.   $.Param.layout0 = "Layout 0 - Back HUD"; // Primeiro layout da HUD.
  72.   $.Param.layout1 = "Layout 1 - Icon HUD"; // Segundo layout da HUD.
  73.   $.Param.layoutEffect = "Efeito HUD";     // Layout de efeito da HUD.
  74.   $.Param.hp_meter = "Hp Meter HUD";       // Barra de HP da HUD.
  75.   $.Param.mp_meter = "Mp Meter HUD";       // Barra de MP da HUD.
  76.   $.Param.speed = 4;                       // Velocidade para esconder/ativar
  77.   $.Param.actor_id = 1;                    // A HUD é destinada a qual actor?
  78.   $.Param.addonX = 0;                      // Modificar a posição X.
  79.   $.Param.addonY = 0;                      // Modificar a posição Y.
  80.   $.Param.switchID = 1;                    // ID para ativar/desativar a HUD.
  81.   //---------------------------------------------------------------------------
  82.   // Inicialização.
  83.   //---------------------------------------------------------------------------
  84.   SpriteSteampunkHud.prototype.initialize = function() {
  85.     var actor = $gameActor.actor($.Param.actor_id);
  86.     var layout0 = new Sprite(null);
  87.     layout0.bitmap = ImageManager.loadSystem($.Param.layout0);
  88.     layout0.move(30 + $.Param.addonX.toNumber, 16 + $.Param.addonY.toNumber);
  89.     var layout1 = new Sprite(null);
  90.     layout1.bitmap = ImageManager.loadSystem($.Param.layout1);
  91.     layout1.move(19 + $.Param.addonX.toNumber, 10 + $.Param.addonY.toNumber);
  92.     var hpBitmap = ImageManager.loadSystem($.Param.hp_meter);
  93.     var mpBitmap = ImageManager.loadSystem($.Param.mp_meter);
  94.     var sHp = new Sprite(null);
  95.     sHp.bitmap = new Bitmap(hpBitmap.width, mpBitmap.width);
  96.     sHp.move(42 + $.Param.addonX.toNumber, 22 + $.Param.addonY.toNumber);
  97.     var sMp = new Sprite(null);
  98.     sMp.bitmap = new Bitmap(mpBitmap.width, mpBitmap.height);
  99.     sMp.move(44 + $.Param.addonX.toNumber, 43 + $.Param.addonY.toNumber);
  100.     sHp.bitmap.blt(hpBitmap, 0, 0, hpBitmap.width.to_p(actor.hp, actor.mhp), hpBitmap.height, 0, 0, sHp.width, sHp.height);
  101.     sMp.bitmap.blt(mpBitmap, 0, 0, mpBitmap.width.to_p(actor.mp, actor.mmp), mpBitmap.height, 0, 0, sHp.width, sHp.height);
  102.     var effect = new Sprite(null);
  103.     effect.bitmap = ImageManager.loadSystem($.Param.layoutEffect);
  104.     effect.opacity.set(128);
  105.     var effectOpacity = 128;
  106.     var opacityGeral = 0;
  107.   }
  108.   //---------------------------------------------------------------------------
  109.   // Renovar
  110.   //---------------------------------------------------------------------------
  111.   SpriteSteampunkHud.prototype.dispose = function() {
  112.     layout0.clear;
  113.     layout1.clear;
  114.     sHp.clear;
  115.     sMp.clear;
  116.     effect.clear;
  117.   }
  118.   //---------------------------------------------------------------------------
  119.   // Atualizar
  120.   //---------------------------------------------------------------------------
  121.   SpriteSteampunkHud.prototype.update = function() {
  122.     sHp._refresh;
  123.     sMp._refresh;
  124.     sHp.bitmap.blt(hpBitmap, 0, 0, hpBitmap.width.to_p(actor.hp, actor.mhp), hpBitmap.height, 0, 0, sHp.width, sHp.height);
  125.     sMp.bitmap.blt(mpBitmap, 0, 0, mpBitmap.width.to_p(actor.mp, actor.mmp), mpBitmap.height, 0, 0, sHp.width, sHp.height);
  126.     if ( $.Param.switchID !== undefined && $.Param.switchID > 0 ) {
  127.       $gameSystem.steamHud.set($gameSwitches.value($.Param.switchID))
  128.     }
  129.     if ( $gameSystem.steamHud.get == true ) {
  130.       effectOpacity = numberEffectUpDown.call(effectOpacity, 62, 122);
  131.       effect.opacity.set(effectOpacity);
  132.       if ( layout0.opacity.get !== 255 || layout1.opacity.get !== 255 || sHp.opacity.get !== 255 || sHp.opacity !== 255 ) {
  133.         opacityGeral = Math.clamp(opacityGeral + 1, 0, 255)
  134.         layout0.opacity.set(opacityGeral);
  135.         layout1.opacity.set(opacityGeral);
  136.         sHp.opacity.set(opacityGeral);
  137.         sMp.opacity.set(opacityGeral);
  138.       }
  139.     } else {
  140.       if ( effect.opacity.get !== 0 || layout0.opacity.get !== 0 || layout1.opacity.get !== 0 || sHp.opacity.get !== 0 || sHp.opacity !== 0 ) {
  141.         opacityGeral = Math.clamp(opacityGeral - 1, 0, 255)
  142.         effect.opacity.set(opacityGeral);
  143.         layout0.opacity.set(opacityGeral);
  144.         layout1.opacity.set(opacityGeral);
  145.         sHp.opacity.set(opacityGeral);
  146.         sMp.opacity.set(opacityGeral);
  147.       }
  148.     }
  149.   }
  150.   //---------------------------------------------------------------------------
  151.   // Scene_Map:start
  152.   //---------------------------------------------------------------------------
  153.   var oldSceneMapSteampunkHud_start = Scene_Map.prototype.start;
  154.   Scene_Map.prototype.start = function() {
  155.     oldSceneMapSteampunkHud_start.call(this);
  156.     this.createSteampunkHud();
  157.   }
  158.   //---------------------------------------------------------------------------
  159.   // Scene_Map:createSteampunkHud
  160.   //---------------------------------------------------------------------------
  161.   Scene_Map.prototype.createSteampunkHud = function () {
  162.     this._steampunkHud = new SpriteSteampunkHud();
  163.     this.addChild(this._steampunkHud);
  164.   };
  165.   //---------------------------------------------------------------------------
  166.   // Scene_Map:terminate
  167.   //---------------------------------------------------------------------------
  168.   var oldSceneMapSteampunkHud_terminate = Scene_Map.prototype.terminate;
  169.   Scene_Map.prototype.terminate = function () {
  170.     oldSceneMapSteampunkHud_terminate.call(this);
  171.     this._steampunkHud.dispose();
  172.   };
  173.   //---------------------------------------------------------------------------
  174.   // Scene_Map:update
  175.   //---------------------------------------------------------------------------
  176.   var oldSceneMapSteampunkHud_update = Scene_Map.prototype.update;
  177.   Scene_Map.prototype.update = function () {
  178.     oldSceneMapSteampunkHud_update.call(this);
  179.     this._steampunkHud.update();
  180.   };
  181. })(SteampunkHud)
  182. //=============================================================================
  183. // PluginManager:register
  184. //=============================================================================
  185. PluginManager.register("SteampunkHud", "0.1.0.0", "HUD estilo steampunk.", {
  186.   email: "dax-soft@live.com",
  187.   name: "Kvothe",
  188.   website: "http://www.dax-soft.weebly.com"
  189. }, "2015-10-17");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement