Advertisement
Guest User

Untitled

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