Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.69 KB | None | 0 0
  1. #==============================================================================
  2. # Vampyr HUD
  3. #==============================================================================
  4. # Switch ID that show or hide the HUD
  5. OnOff_Switch = 2
  6.  
  7. # Show HP, MP and EXP Bars?
  8. Show_Status = true
  9.  
  10. # Text displayed on skills window
  11. Show_Skills = true
  12. Skills_Text = "Skills"
  13.  
  14. # Text displayed on items window
  15. Show_Items = true
  16. Items_Text = "Items"
  17.  
  18. # Text displayed on ammunitions window
  19. Show_Ammos = true
  20. Ammo_Text = "Munition"
  21.  
  22. # The name of the font
  23. Font_Name = Font.default_name
  24.  
  25. # The size of the font
  26. Font_Size = 16
  27.  
  28. #------------------------------------------------------------------------------
  29. if Vampyr_Kernel.enabled?("Vampyr SBABS")
  30. #------------------------------------------------------------------------------
  31. Vampyr_Kernel.register("Vampyr HUD", 1.1, "12/06/2009")
  32. #------------------------------------------------------------------------------
  33. class Vampyr_HUD1 < Sprite
  34.  
  35.   def initialize(viewport)
  36.     super(viewport)
  37.     self.x, self.y = 1, 1
  38.     @base   = Cache.system("Actor Base")
  39.     @hpbar  = Cache.system("Actor HP Bar")
  40.     @mpbar  = Cache.system("Actor MP Bar")
  41.     @expbar = Cache.system("Actor Exp Bar")
  42.     self.bitmap = Bitmap.new(156, 100)
  43.     self.bitmap.font.name = Font_Name
  44.     self.bitmap.font.size = Font_Size
  45.     refresh
  46.   end
  47.  
  48.   def update
  49.     super
  50.     self.visible = (OnOff_Switch <= 0 or $game_switches[OnOff_Switch])
  51.     update_opacity
  52.     refresh if something_changed?
  53.   end
  54.  
  55.   def refresh
  56.     @actor = $game_party.members[0]
  57.     return if @actor == nil
  58.     @old_hp  = @actor.hp
  59.     @old_mp  = @actor.mp
  60.     @old_exp = @actor.exp
  61.     self.bitmap.clear
  62.     draw_hpbar(@actor, 0, 0)
  63.     draw_mpbar(@actor, 0, 20)
  64.     draw_expbar(@actor, 0, 40) if @actor.next_exp > 0
  65.   end
  66.  
  67.   def draw_hpbar(actor, x, y)
  68.     self.bitmap.draw_outlined_text(x, y, 24, Font_Size, Vocab::hp_a)
  69.     rect = Rect.new(0, 0, @hpbar.width*actor.hp/actor.maxhp, @hpbar.height)
  70.     self.bitmap.blt(x+24, y, @base, @base.rect)
  71.     self.bitmap.blt(x+24, y, @hpbar, rect)
  72.     self.bitmap.draw_text(x+24,y,@hpbar.width/2-10,Font_Size,"#{actor.hp}",2)
  73.     self.bitmap.draw_text(x+24+@hpbar.width/2-10,y,20,Font_Size,"/",1)
  74.     self.bitmap.draw_text(x+24+@hpbar.width/2+10,y,@hpbar.width/2-10,Font_Size,"#{actor.maxhp}",0)
  75.   end
  76.  
  77.   def draw_mpbar(actor, x, y)
  78.     self.bitmap.draw_outlined_text(x, y, 24, Font_Size, Vocab::mp_a)
  79.     rect = Rect.new(0, 0, @mpbar.width*actor.mp/actor.maxmp, @mpbar.height)
  80.     self.bitmap.blt(x+24, y, @base, @base.rect)
  81.     self.bitmap.blt(x+24, y, @mpbar, rect)
  82.     self.bitmap.draw_text(x+24,y,@hpbar.width/2-10,Font_Size,"#{actor.mp}",2)
  83.     self.bitmap.draw_text(x+24+@hpbar.width/2-10,y,20,Font_Size,"/",1)
  84.     self.bitmap.draw_text(x+24+@hpbar.width/2+10,y,@hpbar.width/2-10,Font_Size,"#{actor.maxmp}",0)
  85.   end
  86.  
  87.   def draw_expbar(actor, x, y)
  88.     self.bitmap.draw_outlined_text(x, y, 24, Font_Size, "Exp")
  89.     rect = Rect.new(0, 0, @expbar.width*actor.current_exp/actor.next_exp, @expbar.height)
  90.     self.bitmap.blt(x+24, y, @base, @base.rect)
  91.     self.bitmap.blt(x+24, y, @expbar, rect)
  92.     exp = actor.next_exp > 0 ? actor.current_exp/(actor.next_exp/100) : 100
  93.     self.bitmap.draw_text(x+24,y, @expbar.width - 48, Font_Size, "#{exp} %",1)
  94.     self.bitmap.draw_text(x,y+Font_Size,@expbar.width - 48,Font_Size,"Level #{}",0)
  95.   end
  96.  
  97.   def something_changed?
  98.     return true if $game_party.members.size > 0 && @actor == nil
  99.     return false if $game_party.members.size <= 0
  100.     return true if @old_hp  != @actor.hp
  101.     return true if @old_mp  != @actor.mp
  102.     return true if @old_exp != @actor.exp
  103.     return true if @actor   != $game_party.members[0]
  104.     return false
  105.   end
  106.  
  107.   def update_opacity
  108.     if $game_player.screen_x <= (self.bitmap.width+16) and $game_player.screen_y <= (self.bitmap.height+16)
  109.       self.opacity -= 10
  110.     elsif self.opacity < 255
  111.       self.opacity += 10
  112.     end
  113.   end
  114.  
  115.   def dispose
  116.     self.bitmap.dispose
  117.     super
  118.   end
  119.  
  120. end
  121.  
  122. #------------------------------------------------------------------------------
  123. class Vampyr_HUD2 < Sprite
  124.  
  125.   def initialize(viewport)
  126.     super(viewport)
  127.     @bg = Cache.system("Ammos Base")
  128.     self.y = Graphics.height-@bg.height-(Font_Size/2)-1
  129.     self.bitmap = Bitmap.new(@bg.width, @bg.height+(Font_Size/2))
  130.     self.bitmap.font.name = Font_Name
  131.     self.bitmap.font.size = Font_Size
  132.     refresh
  133.   end
  134.  
  135.   def update
  136.     super
  137.     self.visible = (OnOff_Switch <= 0 or $game_switches[OnOff_Switch])
  138.     update_opacity
  139.     refresh if something_changed?
  140.   end
  141.  
  142.   def refresh
  143.     @actor = $game_party.members[0]
  144.     return if @actor == nil
  145.     @weapon1 = @actor.weapons[0]
  146.     @weapon2 = @actor.weapons[1]
  147.     @count1 = $game_party.item_number(@actor.ammos[@weapon1.id])
  148.     @count2 = $game_party.item_number(@actor.ammos[@weapon2.id])
  149.     self.bitmap.clear
  150.     self.bitmap.blt(0, 10, @bg, @bg.rect)
  151.     draw_ammos
  152.   end
  153.  
  154.   def draw_ammos
  155.     if @actor.weapons[0] != nil and @actor.ammos[@actor.weapons[0].id] != nil
  156.       draw_icon(@actor.ammos[@actor.weapons[0].id].icon_index, 4, 14)
  157.       self.bitmap.draw_outlined_text(0, self.bitmap.height-Font_Size, 32, Font_Size, @count1.to_s, 1)
  158.     end
  159.     if @actor.weapons[1] != nil and @actor.ammos[@actor.weapons[1].id] != nil
  160.       draw_icon(@actor.ammos[@actor.weapons[1].id].icon_index, 36, 14)
  161.     end
  162.     self.bitmap.draw_outlined_text(0, 0, self.bitmap.width, Font_Size, Ammo_Text, 1)
  163.   end
  164.  
  165.   def something_changed?
  166.     return true if $game_party.members.size > 0 && @actor == nil
  167.     return false if $game_party.members.size <= 0
  168.     return true if @weapon1 != @actor.weapons[0]
  169.     return true if @weapon2 != @actor.weapons[1]
  170.     return true if @actor   != $game_party.members[0]
  171.     return true if @count1  != $game_party.item_number(@actor.ammos[@weapon1.id])
  172.     return true if @count2  != $game_party.item_number(@actor.ammos[@weapon2.id])
  173.     return false
  174.   end
  175.  
  176.   def update_opacity
  177.     if $game_player.screen_x <= (self.bitmap.width+16) and $game_player.screen_y >= (Graphics.height-self.bitmap.height-16)
  178.       self.opacity -= 10
  179.     elsif self.opacity < 255
  180.       self.opacity += 10
  181.     end
  182.   end
  183.  
  184.   def dispose
  185.     self.bitmap.dispose
  186.     super
  187.   end
  188.  
  189. end
  190.  
  191. #------------------------------------------------------------------------------
  192. class Vampyr_HUD3 < Sprite
  193.  
  194.   def initialize(viewport)
  195.     super(viewport)
  196.     @bg = Cache.system("Skills Base")
  197.     self.x = Graphics.width-@bg.width
  198.     self.y = Graphics.height-@bg.height-(Font_Size/2)-1
  199.     self.bitmap = Bitmap.new(@bg.width, @bg.height+(Font_Size/2))
  200.     self.bitmap.font.name = Font_Name
  201.     self.bitmap.font.size = Font_Size
  202.     refresh
  203.   end
  204.  
  205.   def update
  206.     super
  207.     self.visible = (OnOff_Switch <= 0 or $game_switches[OnOff_Switch])
  208.     update_opacity
  209.     refresh if something_changed?
  210.   end
  211.  
  212.   def refresh
  213.     @actor = $game_party.members[0]
  214.     return if @actor == nil
  215.     @hotkeys = {}
  216.     @actor.skill_hotkeys.each { |k, v| @hotkeys[k] = v }
  217.     self.bitmap.clear
  218.     self.bitmap.blt(0, 10, @bg, @bg.rect)
  219.     draw_skills
  220.   end
  221.  
  222.   def draw_skills
  223.     count = 0
  224.     @actor.skill_hotkeys.sort.each { |key, value|
  225.      next if value.nil?
  226.      skill = $data_skills[value]
  227.      next if skill.nil?
  228.      draw_icon(skill.icon_index, 32*count+4, 14)
  229.      self.bitmap.draw_outlined_text(32*count, self.bitmap.height-Font_Size, 32, Font_Size, Keys.name(key), 1)
  230.      count += 1
  231.     }
  232.     self.bitmap.draw_outlined_text(0, 0, self.bitmap.width, Font_Size, Skills_Text, 1)
  233.   end
  234.  
  235.   def something_changed?
  236.     return true if $game_party.members.size > 0 && @actor == nil
  237.     return false if $game_party.members.size <= 0
  238.     return true if @actor != $game_party.members[0]
  239.     return true if @hotkeys != @actor.skill_hotkeys
  240.     return false
  241.   end
  242.  
  243.   def update_opacity
  244.     if $game_player.screen_x >= (Graphics.width-self.bitmap.width-16) and $game_player.screen_y >= (Graphics.height-self.bitmap.height-16)
  245.       self.opacity -= 10
  246.     elsif self.opacity < 255
  247.       self.opacity += 10
  248.     end
  249.   end
  250.  
  251.   def dispose
  252.     self.bitmap.dispose
  253.     super
  254.   end
  255.  
  256. end
  257.  
  258. #------------------------------------------------------------------------------
  259. class Vampyr_HUD4 < Sprite
  260.  
  261.   def initialize(viewport)
  262.     super(viewport)
  263.     @bg = Cache.system("Items Base")
  264.     self.x, self.y = Graphics.width-@bg.width, 1
  265.     self.bitmap = Bitmap.new(@bg.width, @bg.height+(Font_Size/2))
  266.     self.bitmap.font.name = Font_Name
  267.     self.bitmap.font.size = Font_Size
  268.     refresh
  269.   end
  270.  
  271.   def update
  272.     super
  273.     self.visible = (OnOff_Switch <= 0 or $game_switches[OnOff_Switch])
  274.     update_opacity
  275.     refresh if something_changed?
  276.   end
  277.  
  278.   def refresh
  279.     @actor = $game_party.members[0]
  280.     return if @actor == nil
  281.     @hotkeys = {}
  282.     @actor.item_hotkeys.each { |k, v| @hotkeys[k] = v }
  283.     self.bitmap.clear
  284.     self.bitmap.blt(0, 10, @bg, @bg.rect)
  285.     draw_items
  286.   end
  287.  
  288.   def draw_items
  289.     count = 0
  290.     @actor.item_hotkeys.sort.each { |key, value|
  291.      next if value.nil?
  292.      item = $data_items[value]
  293.      next if item.nil?
  294.      draw_icon(item.icon_index, 32*count+4, 14)
  295.      self.bitmap.draw_outlined_text(32*count, self.bitmap.height-Font_Size, 32, Font_Size, Keys.name(key), 1)
  296.      count += 1
  297.     }
  298.     self.bitmap.draw_outlined_text(0, 0, self.bitmap.width, Font_Size, Items_Text, 1)
  299.   end
  300.  
  301.   def something_changed?
  302.     return true if $game_party.members.size > 0 && @actor == nil
  303.     return false if $game_party.members.size <= 0
  304.     return true if @actor != $game_party.members[0]
  305.     return true if @hotkeys.to_s != @actor.item_hotkeys.to_s
  306.     return false
  307.   end
  308.  
  309.   def update_opacity
  310.     if $game_player.screen_x >= (Graphics.width-self.bitmap.width-16) and $game_player.screen_y <= (self.bitmap.height+16)
  311.       self.opacity -= 10
  312.     elsif self.opacity < 255
  313.       self.opacity += 10
  314.     end
  315.   end
  316.  
  317.   def dispose
  318.     self.bitmap.dispose
  319.     super
  320.   end
  321.  
  322. end
  323.  
  324. #------------------------------------------------------------------------------
  325. class Spriteset_Map
  326.  
  327.   alias vampyr_hud_initialize initialize
  328.   alias vampyr_hud_update update
  329.   alias vampyr_hud_dispose dispose
  330.  
  331.   def initialize
  332.     $vampyr_hud1 = Vampyr_HUD1.new(@viewport3) if Show_Status
  333.     $vampyr_hud2 = Vampyr_HUD2.new(@viewport3) if Show_Ammos
  334.     $vampyr_hud3 = Vampyr_HUD3.new(@viewport3) if Show_Skills
  335.     $vampyr_hud4 = Vampyr_HUD4.new(@viewport3) if Show_Items
  336.     vampyr_hud_initialize
  337.   end
  338.  
  339.   def update
  340.     vampyr_hud_update
  341.     $vampyr_hud1.update if Show_Status
  342.     $vampyr_hud2.update if Show_Ammos
  343.     $vampyr_hud3.update if Show_Skills
  344.     $vampyr_hud4.update if Show_Items
  345.   end
  346.  
  347.   def dispose
  348.     vampyr_hud_dispose
  349.     $vampyr_hud1.dispose if Show_Status
  350.     $vampyr_hud2.dispose if Show_Ammos
  351.     $vampyr_hud3.dispose if Show_Skills
  352.     $vampyr_hud4.dispose if Show_Items
  353.   end
  354.  
  355. end
  356.  
  357. #------------------------------------------------------------------------------
  358. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement