Advertisement
roninator2

Kid Friendly Basic Quest - Actor Hud

Dec 13th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 21.16 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: KFBQ Actor HUD on screen     ║  Version: 1.01     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║   FFMQ Style Actor HUD              ║    09 Mar 2023     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║                                                          ║
  12. # ║  Set the Level to have the additional HP split.          ║
  13. # ║  At 23 the HP meter will show 23 HP bars before          ║
  14. # ║  changing to allow a second row.                         ║
  15. # ║                                                          ║
  16. # ║  Set the file name of the base image used                ║
  17. # ║     Base_File =                                          ║
  18. # ║  This is the image that is shown when the player MHP     ║
  19. # ║   goes up.                                               ║
  20. # ║                                                          ║
  21. # ║  Set the file name for the active HP file name           ║
  22. # ║     HP_File =                                            ║
  23. # ║  This is the image that is shown when the player HP      ║
  24. # ║  is higher than the main HP bar.                         ║
  25. # ║                                                          ║
  26. # ║  ====================================================    ║
  27. # ║                                                          ║
  28. # ║  Setting window colours:                                 ║
  29. # ║                                                          ║
  30. # ║  Below is the constants used to configure the window     ║
  31. # ║  colour settings. with this addition you can now         ║
  32. # ║  specify what colour the window will be when the actor   ║
  33. # ║  is making an action in battle and when done.            ║
  34. # ║                                                          ║
  35. # ║  USE_SYSTEM_COLOURS = true                               ║
  36. # ║    will use the first two constants not the second       ║
  37. # ║                                                          ║
  38. # ║  WINDOW_LIGHT = [76,100] & WINDOW_DARK = [124,108]       ║
  39. # ║    these corrospond to the windowskin graphic file       ║
  40. # ║    starting at 64,96 is the top left corner of the       ║
  41. # ║    colour palet.                                         ║
  42. # ║                                                          ║
  43. # ║  WINDOW_RGBLIGHT = [100,200,100] and                     ║
  44. # ║  WINDOW_RGBDARK = [100,0,100]                            ║
  45. # ║    these corrospond to RGB colours Red, Green, Blue      ║
  46. # ║                                                          ║
  47. # ╚══════════════════════════════════════════════════════════╝
  48. # ╔══════════════════════════════════════════════════════════╗
  49. # ║ Terms of use:                                            ║
  50. # ║ Free for all uses in RPG Maker - Except nudity           ║
  51. # ╚══════════════════════════════════════════════════════════╝
  52.  
  53. #==============================================================================
  54. # ** Module Actor HUD
  55. #==============================================================================
  56. module R2_Hud_Data
  57.   Level = 23  # amount of levels the player can be before the health bar doubles
  58.   Base_File = "HP-Base-extra" # Health block base
  59.   HP_File = "HP-Active-extra" # Health block active
  60.   HP_BAR_COLOUR_1 = 2
  61.   HP_BAR_COLOUR_2 = 21
  62.   # highlighting windows with system colours or RGB colours
  63.   USE_SYSTEM_COLOURS = false
  64.   WINDOW_LIGHT = [76,100] # windowskin pixel
  65.   WINDOW_DARK = [124,108] # windowskin pixel
  66.   # RGB colours
  67.   WINDOW_RGBLIGHT = [100,200,100] # RGB colours
  68.   WINDOW_RGBDARK = [100,0,100] # RGB colours
  69. end
  70.  
  71. #==============================================================================
  72. # ** Game Actor
  73. #==============================================================================
  74. class Game_Actor < Game_Battler
  75.   #--------------------------------------------------------------------------
  76.   # * Level = to set level value
  77.   #--------------------------------------------------------------------------
  78.   def level=(value)
  79.     @level = value
  80.   end
  81. end
  82.  
  83. #==============================================================================
  84. # ** Actor Hud Window
  85. #==============================================================================
  86. class Actor_Hud_Window < Window_Base
  87.   #--------------------------------------------------------------------------
  88.   # * Initialize
  89.   #--------------------------------------------------------------------------
  90.   def initialize(id)
  91.     @actor = $game_actors[id]
  92.     @actcln = @actor.clone
  93.     @actcln.level = 1
  94.     @barhp = @actcln.mhp
  95.     x = @actor == $game_party.members[0] ? 0 : Graphics.width / 2
  96.     y = Graphics.height - 100
  97.     w = Graphics.width / 2
  98.     h = Graphics.height - y
  99.     super(x,y,w,h)
  100.     self.tone.set(self.windowskin.get_pixel(R2_Hud_Data::WINDOW_DARK[0],R2_Hud_Data::WINDOW_DARK[1]))
  101.     @tone = self.tone
  102.     self.z = 2
  103.     self.opacity = 255
  104.     self.back_opacity = 0
  105.     self.contents_opacity = 255
  106.     refresh if @actor
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # * Change tone when active
  110.   #--------------------------------------------------------------------------
  111.   def change_tone
  112.     self.back_opacity = 255
  113.     if R2_Hud_Data::USE_SYSTEM_COLOURS
  114.       self.tone.set(self.windowskin.get_pixel(R2_Hud_Data::WINDOW_LIGHT[0],R2_Hud_Data::WINDOW_LIGHT[1]))
  115.     else
  116.       self.tone.set(Color.new(R2_Hud_Data::WINDOW_RGBLIGHT[0],R2_Hud_Data::WINDOW_RGBLIGHT[1],R2_Hud_Data::WINDOW_RGBLIGHT[2]))
  117.     end
  118.     @tone = self.tone
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # * Clear tone
  122.   #--------------------------------------------------------------------------
  123.   def clear_tone
  124.     self.back_opacity = 0
  125.     if R2_Hud_Data::USE_SYSTEM_COLOURS
  126.       self.tone.set(self.windowskin.get_pixel(R2_Hud_Data::WINDOW_DARK[0],R2_Hud_Data::WINDOW_DARK[1]))
  127.     else
  128.       self.tone.set(Color.new(R2_Hud_Data::WINDOW_RGBDARK[0],R2_Hud_Data::WINDOW_RGBDARK[1],R2_Hud_Data::WINDOW_RGBDARK[2]))
  129.     end
  130.     @tone = self.tone
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # * Update Tone
  134.   #--------------------------------------------------------------------------
  135.   def update_tone
  136.     @tone.nil? ? self.tone.set($game_system.window_tone) : @tone
  137.     # self.tone.set(Tone.new(-255,-255,-255))
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # * Get Actor
  141.   #--------------------------------------------------------------------------
  142.   def actor?
  143.     return @actor
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # * Draw Actor HUD HP
  147.   #--------------------------------------------------------------------------
  148.   def draw_actor_hud_hp(actor, x, y, width = 130)
  149.     if $game_system.life_indicator?
  150.       draw_text(0, y + 5, contents.width/2, line_height, "LIFE", 0)
  151.       draw_text(x + 10, y + 25, 62, line_height, @actor.hp, 2)
  152.       draw_text(x + 80, y + 25, 12, line_height, "/", 2)
  153.       draw_text(x + 90, y + 25, 62, line_height, @actor.mhp, 2)
  154.     else
  155.       draw_gauge(x, y, width, hp_rate, text_color(R2_Hud_Data::HP_BAR_COLOUR_1), text_color(R2_Hud_Data::HP_BAR_COLOUR_2))
  156.     end
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # * Get HP Rate
  160.   #--------------------------------------------------------------------------
  161.   def hp_rate
  162.     if @actor.mhp > @barhp
  163.       a = (@actor.hp / @barhp).to_i
  164.       b = a * @barhp
  165.       c = @actor.hp - b
  166.       d = c == 0 ? @barhp : c
  167.       d.to_f / @barhp
  168.     else
  169.       @actor.hp.to_f / @actor.mhp
  170.     end
  171.   end
  172.   #--------------------------------------------------------------------------
  173.   # * Draw HP Gauges
  174.   #--------------------------------------------------------------------------
  175.   def draw_gauge(x, y, width, rate, color1, color2)
  176.     fill_w = (width * rate).to_i
  177.     gauge_y = y + line_height - 8
  178.     height = 20
  179.     height = 10 if @actor.level > R2_Hud_Data::Level
  180.     contents.fill_rect(x, gauge_y, width, height, text_color(18))
  181.     contents.gradient_fill_rect(x, gauge_y, fill_w, height, color1, color2)
  182.     bitmap1 = Cache.system(R2_Hud_Data::Base_File)
  183.     bitmap2 = Cache.system(R2_Hud_Data::HP_File)
  184.     rect1 = Rect.new(0, 0, bitmap1.width, bitmap1.height)
  185.     rect2 = Rect.new(0, 0, bitmap2.width, bitmap2.height)
  186.     # find how many health bars to show
  187.     mhp_value = (@actor.mhp / @barhp).to_i - 1
  188.     a = (@actor.hp / @barhp).to_i
  189.     b = a * @barhp
  190.     c = @actor.hp - b
  191.     d = c > 0 ? 1 : 0
  192.     hp_value = d + a - 1
  193.     # Draw Base
  194.     if (@actor.level > 1) && (@actor.level < (R2_Hud_Data::Level + 1))
  195.       mhp_value.times do |i|
  196.         p = i*7
  197.         contents.blt(0+p, 50, bitmap1, rect1, 255)
  198.       end
  199.     elsif @actor.level > (R2_Hud_Data::Level)
  200.       row2 = mhp_value - (R2_Hud_Data::Level - 1)
  201.       row2 = (R2_Hud_Data::Level - 1) if (@actor.level > (R2_Hud_Data::Level * 2 - 1))
  202.       row1 = R2_Hud_Data::Level - 1
  203.       row1.times do |i|
  204.         p = i*7
  205.         contents.blt(0+p, 40, bitmap1, rect1, 255)
  206.       end
  207.       row2.times do |i|
  208.         p = i*7
  209.         contents.blt(0+p, 50, bitmap1, rect1, 255)
  210.       end
  211.     end
  212.     # Draw Health
  213.     if (@actor.level > 1) && (@actor.level < (R2_Hud_Data::Level + 1))
  214.       hp_value.times do |i|
  215.         p = i*7
  216.         contents.blt(0+p, 50, bitmap2, rect2, 255)
  217.       end
  218.     elsif @actor.level > (R2_Hud_Data::Level)
  219.       row4 = [0, hp_value - (R2_Hud_Data::Level - 1)].max
  220.       row4 = (R2_Hud_Data::Level - 1) if hp_value >= (R2_Hud_Data::Level * 2 - 1)
  221.       row3 = 0
  222.       row3 = [hp_value, (R2_Hud_Data::Level - 1)].min if hp_value >= 1
  223.       return if row3 == 0
  224.       row3.times do |i|
  225.         p = i*7
  226.         contents.blt(0+p, 40, bitmap2, rect2, 255)
  227.       end
  228.       row4.times do |i|
  229.         p = i*7
  230.         contents.blt(0+p, 50, bitmap2, rect2, 255)
  231.       end
  232.     end
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # * Refresh
  236.   #--------------------------------------------------------------------------
  237.   def refresh
  238.     contents.clear unless disposed?
  239.     return if disposed?
  240.     @actor_current_hp = @actor.hp
  241.     @previous_actor = @actor
  242.     @level = @actor.level
  243.     width = Graphics.width
  244.     draw_actor_hud_hp(@actor, 0, 10, 150)
  245.     draw_actor_weapon(@actor.equips[0].id) if !@actor.equips[0].nil?
  246.   end
  247.   #--------------------------------------------------------------------------
  248.   # * Draw Actor Weapon
  249.   #--------------------------------------------------------------------------
  250.   def draw_actor_weapon(id)
  251.     bitmap = Cache.system("Weapons\\Weapon" + id.to_s)
  252.     rect = Rect.new(0, 0, bitmap.width, bitmap.height)
  253.     contents.blt(180, 20, bitmap, rect, 255)
  254.     return if @actor == $game_party.members[0]
  255.     if $game_party.members[1].equips[0] == $data_weapons[16]
  256.       text = ($game_party.ninja_stars?).to_s
  257.       draw_text(175,15,50, 24, text)
  258.     end
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # * Check if HUD data Changed
  262.   #--------------------------------------------------------------------------
  263.   def hud_data_changed
  264.     return true if @actor_current_hp != @actor.hp
  265.     return true if @level != @actor.level
  266.     return false
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # * Update
  270.   #--------------------------------------------------------------------------
  271.   alias r2_hud_update    update
  272.   def update
  273.     refresh if hud_data_changed
  274.     r2_hud_update
  275.   end
  276. end
  277.  
  278. #==============================================================================
  279. # ** Actor Level Window
  280. #==============================================================================
  281. class Actor_Level_Window < Window_Base
  282.   #--------------------------------------------------------------------------
  283.   # * Initialize
  284.   #--------------------------------------------------------------------------
  285.   def initialize(id)
  286.     @actor = $game_actors[id]
  287.     x = @actor == $game_party.members[0] ? 5 : Graphics.width / 2 + 5
  288.     y = Graphics.height - 38
  289.     w = name_width
  290.     h = 45
  291.     super(x,y,w,h)
  292.     self.z = 1240
  293.     self.windowskin = Cache.system("Window_Border")
  294.     self.tone.set(Color.new(0,0,0))
  295.     self.opacity = 255
  296.     self.back_opacity = 0
  297.     self.contents_opacity = 255
  298.     @actor_alive = true
  299.     @level = @actor.level
  300.     refresh if @actor
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # * Set the Name Width for Window Width
  304.   #--------------------------------------------------------------------------
  305.   def name_width
  306.     name = @actor_alive ? " LEVEL " : " FATAL "    
  307.     wdth = name.size * 15
  308.     return wdth
  309.   end
  310.   #--------------------------------------------------------------------------
  311.   # * Remove Padding
  312.   #--------------------------------------------------------------------------
  313.   def standard_padding
  314.     return 0
  315.   end
  316.   #--------------------------------------------------------------------------
  317.   # * Refresh
  318.   #--------------------------------------------------------------------------
  319.   def refresh
  320.     contents.clear unless disposed?
  321.     return if disposed?
  322.     self.width = name_width
  323.     draw_level if @actor.hp != 0
  324.     draw_fatal if @actor.hp == 0
  325.   end
  326.   #--------------------------------------------------------------------------
  327.   # * Draw Level
  328.   #--------------------------------------------------------------------------
  329.   def draw_level
  330.     name = "LEVEL"
  331.     draw_text(5, 10, contents.width, line_height, name, 0)
  332.     draw_text(0, 10, contents.width, line_height, @actor.level, 2)
  333.     @level = @actor.level
  334.     @actor_alive = @actor.dead?
  335.   end
  336.   #--------------------------------------------------------------------------
  337.   # * Draw Fatal if dead
  338.   #--------------------------------------------------------------------------
  339.   def draw_fatal
  340.     name = "FATAL"
  341.     change_color(knockout_color)
  342.     draw_text(0, 0, contents.width, line_height, name, 0)
  343.     @actor_alive = @actor.dead?
  344.   end
  345.   #--------------------------------------------------------------------------
  346.   # * Update
  347.   #--------------------------------------------------------------------------
  348.   def update
  349.     refresh if @actor_alive != !@actor.dead?
  350.     refresh if @level != @actor.level
  351.   end
  352. end
  353.  
  354. #==============================================================================
  355. # ** Actor Control Window
  356. #==============================================================================
  357. class Actor_Control_Window < Window_Base
  358.   #--------------------------------------------------------------------------
  359.   # * Initialize
  360.   #--------------------------------------------------------------------------
  361.   def initialize(id)
  362.     @actor = $game_actors[id]
  363.     x = Graphics.width / 2 + 180
  364.     y = Graphics.height - 95
  365.     w = name_width
  366.     h = 20
  367.     super(x,y,w,h)
  368.     self.z = 140
  369.     self.windowskin = Cache.system("Window_Border")
  370.     self.tone.set(Color.new(0,0,0))
  371.     self.opacity = 255
  372.     self.arrows_visible = false
  373.     self.pause = false
  374.     self.back_opacity = 0
  375.     self.contents_opacity = 255
  376.     @control = $game_system.autobattle?
  377.     contents.font.size -= 8
  378.     refresh if @actor
  379.   end
  380.   #--------------------------------------------------------------------------
  381.   # * Set the Name Width for Window Width
  382.   #--------------------------------------------------------------------------
  383.   def name_width
  384.     name = $game_system.autobattle? ? " AUTO " : " MANUAL  "    
  385.     wdth = name.size * 10
  386.     return wdth
  387.   end
  388.   #--------------------------------------------------------------------------
  389.   # * Remove Padding
  390.   #--------------------------------------------------------------------------
  391.   def standard_padding
  392.     return 0
  393.   end
  394.   #--------------------------------------------------------------------------
  395.   # * Refresh
  396.   #--------------------------------------------------------------------------
  397.   def refresh
  398.     contents.clear unless disposed?
  399.     return if disposed?
  400.     self.width = name_width
  401.     draw_control
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # * Darw Control
  405.   #--------------------------------------------------------------------------
  406.   def draw_control
  407.     name = $game_system.autobattle? ? " AUTO " : " MANUAL "
  408.     draw_text(5, 0, 100, line_height, name, 0)
  409.     @control = $game_system.autobattle?
  410.   end
  411.   #--------------------------------------------------------------------------
  412.   # * Update
  413.   #--------------------------------------------------------------------------
  414.   def update
  415.     refresh if @control != $game_system.autobattle?
  416.   end
  417. end
  418.  
  419. #==============================================================================
  420. # ** Actor Name Window
  421. #==============================================================================
  422. class Actor_Name_Window < Window_Base
  423.   #--------------------------------------------------------------------------
  424.   # * Initialize
  425.   #--------------------------------------------------------------------------
  426.  def initialize(id)
  427.     @actor = $game_actors[id]
  428.     x = @actor == $game_party.members[0] ? 15 : Graphics.width / 2 + 15
  429.     y = Graphics.height - 95
  430.     w = name_width
  431.     h = 20
  432.     super(x,y,w,h)
  433.     self.z = 140
  434.     self.windowskin = Cache.system("Window_Border")
  435.     self.tone.set(Color.new(0,0,0))
  436.     self.opacity = 255
  437.     self.arrows_visible = false
  438.     self.pause = false
  439.     self.back_opacity = 0
  440.     self.contents_opacity = 255
  441.     refresh if @actor
  442.   end
  443.   #--------------------------------------------------------------------------
  444.   # * Set the Name Width for Window Width
  445.   #--------------------------------------------------------------------------
  446.   def name_width
  447.     text = @actor.name
  448.     total = text.size * 14
  449.     return total
  450.   end
  451.   #--------------------------------------------------------------------------
  452.   # * Remove Padding
  453.   #--------------------------------------------------------------------------
  454.   def standard_padding
  455.     return 0
  456.   end
  457.   #--------------------------------------------------------------------------
  458.   # * Refresh
  459.   #--------------------------------------------------------------------------
  460.   def refresh
  461.     contents.clear unless disposed?
  462.     return if disposed?
  463.     draw_actor_name
  464.   end
  465.   #--------------------------------------------------------------------------
  466.   # * Draw Control
  467.   #--------------------------------------------------------------------------
  468.   def draw_actor_name
  469.     name = @actor.name
  470.     draw_text(5, 0, 100, line_height, name, 0)
  471.   end
  472. end
  473.  
  474. #==============================================================================
  475. # ** Actor Hud Back
  476. #==============================================================================
  477. class Actor_Hud_Back < Window_Base
  478.   #--------------------------------------------------------------------------
  479.   # * Initialize
  480.   #--------------------------------------------------------------------------
  481.   def initialize
  482.     x = 0
  483.     y = Graphics.height - 100
  484.     w = Graphics.width
  485.     h = 100
  486.     super(x,y,w,h)
  487.     self.z = 1
  488.     self.windowskin = Cache.system("Window_Border")
  489.     self.tone.set(Color.new(0,0,0))
  490.     self.opacity = 255
  491.     self.arrows_visible = false
  492.     self.pause = false
  493.     self.back_opacity = 255
  494.     self.contents_opacity = 255
  495.   end
  496.   #--------------------------------------------------------------------------
  497.   # * Remove Padding
  498.   #--------------------------------------------------------------------------
  499.   def standard_padding
  500.     return 0
  501.   end
  502.   #--------------------------------------------------------------------------
  503.   # * Update
  504.   #--------------------------------------------------------------------------
  505.   def update
  506.     self.tone.set(Color.new(0,0,0))
  507.   end
  508. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement