Advertisement
GWibisono

SOUL_MV Rune Factory HUD.js

Aug 23rd, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ------------------------------------------------
  2. // SOUL_MV Rune Factory HUD.js
  3. // ------------------------------------------------
  4. /*:
  5. * @plugindesc Creates a HUD with the same style as Rune Factory.
  6. * @author Soulpour777 - soulxregalia.wordpress.com
  7. *
  8. * @help
  9.  
  10. Plugin Commands
  11.  
  12. change_actor x
  13.  
  14. where x is the number of the actor you want to be
  15. displayed instead of the default actor.
  16.  
  17. Place all images in the img / rf_hud folder.
  18.  
  19. * @param Default Actor
  20. * @desc The default actor that the hud will display its HP and MP. (Changable in Plugin Commands)
  21. * @default 1
  22. *
  23. * @param HUD_Switch
  24. * @desc The switch for the hud to show.
  25. * @default 1
  26. *
  27. * @param HUD Background
  28. * @desc The background image that holds both the HP and MP bars.
  29. * @default HUD_Background
  30. *
  31. * @param HUD Background X
  32. * @desc The x axis of the background image that holds both the HP and MP bars.
  33. * @default 40
  34. *
  35. * @param HUD Background Y
  36. * @desc The y axis of the background image that holds both the HP and MP bars.
  37. * @default 20
  38. *
  39. * @param HP Image
  40. * @desc The hp image that holds both the HP metre.
  41. * @default HP
  42. *
  43. * @param HP Image X
  44. * @desc The x axis of the hp image that holds both the HP metre.
  45. * @default 88
  46. *
  47. * @param HP Image Y
  48. * @desc The y axis of the hp image that holds both the HP metre.
  49. * @default 26
  50. *
  51. * @param MP Image
  52. * @desc The mp image that holds both the MP metre.
  53. * @default MP
  54. *
  55. * @param MP Image X
  56. * @desc The x axis of the mp image that holds both the HP metre.
  57. * @default 88
  58. *
  59. * @param MP Image Y
  60. * @desc The y axis of the mp image that holds both the HP metre.
  61. * @default 50
  62. *
  63. */
  64. var SOUL_MV = SOUL_MV || {};
  65. SOUL_MV.RuneFactory = {};
  66.  
  67. SOUL_MV.RuneFactory.pluginCommand = Game_Interpreter.prototype.pluginCommand;
  68. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  69.     SOUL_MV.RuneFactory.pluginCommand.call(this);
  70.     if (command === "change_actor") {
  71.         $gameSystem._defaultActor = args[0];
  72.     }
  73. };
  74.  
  75.  
  76. ImageManager.loadRune = function(filename, hue) {
  77.     return this.loadBitmap('img/rf_hud/', filename, hue, true);
  78. };
  79.  
  80.  
  81. SOUL_MV.RuneFactory.xinitialize = Game_System.prototype.initialize;
  82. Game_System.prototype.initialize = function() {
  83.     SOUL_MV.RuneFactory.xinitialize.call(this);
  84.     this._defaultActor = SOUL_MV.RuneFactory.DefaultActor;
  85. }
  86.  
  87. SOUL_MV.RuneFactory.DefaultActor = Number(PluginManager.parameters('SOUL_MV Rune Factory HUD')['Default Actor'] || 1);
  88. SOUL_MV.RuneFactory.HudSwitch = Number(PluginManager.parameters('SOUL_MV Rune Factory HUD')['HUD_Switch'] || 1);
  89.  
  90. SOUL_MV.RuneFactory.BackgroundSprite = PluginManager.parameters('SOUL_MV Rune Factory HUD')['HUD Background'] || "HUD_Background";
  91. SOUL_MV.RuneFactory.BackgroundX = Number(PluginManager.parameters('SOUL_MV Rune Factory HUD')['HUD Background X'] || 40);
  92. SOUL_MV.RuneFactory.BackgroundY = Number(PluginManager.parameters('SOUL_MV Rune Factory HUD')['HUD Background Y'] || 20);
  93. SOUL_MV.RuneFactory.HPSprite = PluginManager.parameters('SOUL_MV Rune Factory HUD')['HP Image'] || "HP";
  94. SOUL_MV.RuneFactory.MPSprite = PluginManager.parameters('SOUL_MV Rune Factory HUD')['MP Image'] || "MP";
  95.  
  96. SOUL_MV.RuneFactory.HPImageX = Number(PluginManager.parameters('SOUL_MV Rune Factory HUD')['HP Image X'] || 88);
  97. SOUL_MV.RuneFactory.HPImageY = Number(PluginManager.parameters('SOUL_MV Rune Factory HUD')['HP Image Y'] || 26);
  98.  
  99. SOUL_MV.RuneFactory.MPImageX = Number(PluginManager.parameters('SOUL_MV Rune Factory HUD')['MP Image X'] || 88);
  100. SOUL_MV.RuneFactory.MPImageY = Number(PluginManager.parameters('SOUL_MV Rune Factory HUD')['MP Image Y'] || 50);
  101. ////log_add( "start switch:"+SOUL_MV.RuneFactory.HudSwitch );
  102. ////log_add( "hp image:"+SOUL_MV.RuneFactory.HPSprite );
  103.    
  104. function Sprite_BarHud() {
  105.  this.initialize.apply(this, arguments);
  106. }
  107.  
  108. Sprite_BarHud.prototype = Object.create(Sprite.prototype);
  109. Sprite_BarHud.prototype.constructor = Sprite_BarHud;
  110.  
  111. Sprite_BarHud.prototype.initialize = function (bitmap) {
  112.     Sprite.prototype.initialize.apply(this, arguments);
  113.     this._backgroundSprite = new Sprite(ImageManager.loadRune(SOUL_MV.RuneFactory.BackgroundSprite));
  114.     this._barSprite = new Sprite(ImageManager.loadRune(SOUL_MV.RuneFactory.HPSprite));
  115.     this.addChild(this._backgroundSprite);
  116.     this.addChild(this._barSprite);
  117. }
  118.  
  119. Sprite_BarHud.prototype.update = function () {
  120.   Sprite.prototype.update.apply(this, arguments);
  121.   this.updateBackground();
  122.   this.updateBar();
  123. }
  124.  
  125. Sprite_BarHud.prototype.updateBackground = function () {
  126.   this._backgroundSprite.x = SOUL_MV.RuneFactory.BackgroundX;
  127.   this._backgroundSprite.y = SOUL_MV.RuneFactory.BackgroundY;
  128.   //log_add('back x:'+this._backgroundSprite.x+'|y:'+this._backgroundSprite.y);
  129.   this._backgroundSprite.opacity = this.opacity;
  130. }
  131.  
  132. Sprite_BarHud.prototype.updateBar= function () {
  133.   this._barSprite.x = this.x + SOUL_MV.RuneFactory.HPImageX;
  134.   this._barSprite.y = this.y + SOUL_MV.RuneFactory.HPImageY;
  135.   //log_add('hp x:'+this._barSprite.x+'|y:'+this._barSprite.y);
  136.   this._barSprite.opacity = this.opacity;
  137. }
  138.  
  139. Sprite_BarHud.prototype.setRate = function (rate) {
  140.   this._barSprite.setFrame(0, 0, this._barSprite.bitmap.width * rate, this._barSprite.bitmap.height);
  141. }
  142.  
  143. function Sprite_ActorHpBar() {
  144.   this.initialize.apply(this, arguments);
  145. }
  146.  
  147. Sprite_ActorHpBar.prototype = Object.create(Sprite_BarHud.prototype)
  148. Sprite_ActorHpBar.prototype.constructor = Sprite_ActorHpBar;
  149.  
  150. Sprite_ActorHpBar.prototype.initialize = function (bitmap) {
  151.   this._actor = null;
  152.   Sprite_BarHud.prototype.initialize.apply(this, arguments);
  153. }
  154.  
  155. Sprite_ActorHpBar.prototype.setActor = function (actor) {
  156.   this._actor = actor;
  157. }
  158.  
  159. Sprite_ActorHpBar.prototype.update = function () {
  160.   Sprite_BarHud.prototype.update .apply(this, arguments);
  161.   if (this._actor) {
  162.      this.setRate(this._actor.hpRate());
  163.   }
  164. }
  165.  
  166. function SOUL_MV_SpriteRFMPBar() {
  167.  this.initialize.apply(this, arguments);
  168. }
  169.  
  170. SOUL_MV_SpriteRFMPBar.prototype = Object.create(Sprite.prototype);
  171. SOUL_MV_SpriteRFMPBar.prototype.constructor = SOUL_MV_SpriteRFMPBar;
  172.  
  173. SOUL_MV_SpriteRFMPBar.prototype.initialize = function (bitmap) {
  174.     Sprite.prototype.initialize.apply(this, arguments);
  175.     this._mpBarSprite = new Sprite(ImageManager.loadRune(SOUL_MV.RuneFactory.MPSprite));
  176.     this.addChild(this._mpBarSprite);
  177. }
  178.  
  179. SOUL_MV_SpriteRFMPBar.prototype.update = function () {
  180.   Sprite.prototype.update.apply(this, arguments);
  181.   this.updateBar();
  182. }
  183.  
  184. SOUL_MV_SpriteRFMPBar.prototype.updateBar= function () {
  185.   this._mpBarSprite.x = this.x + SOUL_MV.RuneFactory.MPImageX;
  186.   this._mpBarSprite.y = this.y + SOUL_MV.RuneFactory.MPImageY;
  187.   this._mpBarSprite.opacity = this.opacity;
  188. }
  189.  
  190. SOUL_MV_SpriteRFMPBar.prototype.setRate = function (rate) {
  191.   this._mpBarSprite.setFrame(0, 0, this._mpBarSprite.bitmap.width * rate, this._mpBarSprite.bitmap.height);
  192. }
  193.  
  194. function Sprite_ActorMpBar() {
  195.   this.initialize.apply(this, arguments);
  196. }
  197.  
  198. Sprite_ActorMpBar.prototype = Object.create(SOUL_MV_SpriteRFMPBar.prototype)
  199. Sprite_ActorMpBar.prototype.constructor = Sprite_ActorMpBar;
  200.  
  201. Sprite_ActorMpBar.prototype.initialize = function (bitmap) {
  202.   this._actor = null;
  203.   SOUL_MV_SpriteRFMPBar.prototype.initialize.apply(this, arguments);
  204. }
  205.  
  206. Sprite_ActorMpBar.prototype.setActor = function (actor) {
  207.   this._actor = actor;
  208. }
  209.  
  210. Sprite_ActorMpBar.prototype.update = function () {
  211.   SOUL_MV_SpriteRFMPBar.prototype.update .apply(this, arguments);
  212.   if (this._actor) {
  213.      this.setRate(this._actor.mpRate());
  214.   }
  215. }
  216.  
  217. Spriteset_Map.prototype.createHud = function() {
  218.     this._sprite = new Sprite_ActorHpBar();
  219.     this._sprite.setActor($gameActors.actor($gameSystem._defaultActor));
  220.     this._mpBarsprite = new Sprite_ActorMpBar();
  221.     this._mpBarsprite.setActor($gameActors.actor($gameSystem._defaultActor));    
  222.     this._baseSprite.addChild(this._sprite, 1);
  223.     this._baseSprite.addChild(this._mpBarsprite, 2);
  224. }
  225.  
  226. Spriteset_Map.prototype.update = function() {
  227.     Spriteset_Base.prototype.update.call(this);
  228.     this.updateTileset();
  229.     this.updateParallax();
  230.     this.updateTilemap();
  231.     this.updateShadow();
  232.     this.updateWeather();
  233.     //log_add( "switch:"+SOUL_MV.RuneFactory.HudSwitch );
  234.     if($gameSwitches.value(SOUL_MV.RuneFactory.HudSwitch)) {
  235.     //log_add('show ');
  236.       if (!this._fin) {
  237.         this.createHud();
  238.         this._fin = true;
  239.       }
  240.       else{}
  241.     }
  242.     else{
  243.         //log_add('hide ');
  244.     }
  245. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement