Advertisement
Guest User

Untitled

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