khanhdu

Simple HUD

Sep 1st, 2017
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.35 KB | None | 0 0
  1. #╔═════════════════════════════════════════════════════════════════════════════╗
  2. #║ Simple HUD                                                                  ║
  3. #║  by DigiDeity                                                               ║
  4. #║  contact: [email protected]                                              ║
  5. #║  Want to use this for a commercial purpose? Contact me! :)                  ║
  6. #╠Description══════════════════════════════════════════════════════════════════╣
  7. #║ This Script allows the user to use a simple HUD which will display the HP,  ║
  8. #║ MP, Actor Charset and the name of every actor in the current party.         ║
  9. #╠Usage════════════════════════════════════════════════════════════════════════╣
  10. #║ Just setup the setting below this discription and you can start using it.   ║
  11. #╠Note═════════════════════════════════════════════════════════════════════════╣
  12. #║ Feel free to contact me if you want to report bugs or any ideas for updates.║
  13. #║ Also I'm trying to improve my English in genral if you find any big mistakes║
  14. #║ you would help me by letting me know. ;)                                    ║
  15. #╚═════════════════════════════════════════════════════════════════════════════╝
  16. module DoubleD
  17.   module Simple_HUD
  18. #╔Settings═════════════════════════════════════════════════════════════════════╗
  19. # Choose an ID fot the switch which determinates if the HUD is visible
  20.   VISIBLE_SWITCH_ID = 10
  21. # Choose the value (0-255) for the opacity of the HUD (Window)
  22.   WINDOW_ALPHA = 125
  23. # Choose the value (0-255) for the opacity of the HUD (Window) if the Player
  24. # collides with it.
  25.   WINDOW_COLLIDE_ALPHA = 50
  26. # Choose the position of the HUD
  27. # 1 => Top, 2 => Bot, 3 => Left, 4 => Right, 5 => Every Corner (works only with 4 members)
  28.   HUD_POSITION = 5
  29. #╚EndOfSetting═════════════════════════════════════════════════════════════════╝
  30.   end
  31. end
  32. include DoubleD::Simple_HUD
  33. #==============================================================================
  34. # ** Window_Base_HUD
  35. #------------------------------------------------------------------------------
  36. #  This is a super class of all windows within the game to show a simple HUD.
  37. #==============================================================================
  38. class Window_Base_HUD < Window_Base
  39.   #--------------------------------------------------------------------------
  40.   # * Object Initialization
  41.   #--------------------------------------------------------------------------
  42.   def initialize(x,y,actor_id)
  43.     @actor = $game_party.all_members[actor_id]
  44.     super(x,y,Graphics.width/4,fitting_height(3))
  45.     self.opacity = WINDOW_ALPHA
  46.     refresh
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # * Create Window Contents
  50.   #--------------------------------------------------------------------------
  51.   def refresh      
  52.     @actor_values = [@actor.mhp,@actor.hp,@actor.mmp,@actor.mp,@actor.character_name,@actor.character_index,@actor.name]
  53.     contents.clear
  54.     draw_character(@actor.character_name, @actor.character_index, 12, 32)
  55.     draw_actor_name(@actor, 32 , 0, self.contents.width-32)
  56.     draw_actor_hp(@actor, 0, self.contents.height/3,self.contents.width)
  57.     draw_actor_mp(@actor, 0, self.contents.height/3*2,self.contents.width)
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # * Frame Update
  61.   #--------------------------------------------------------------------------
  62.   def update
  63.     refresh if need_update? && $game_switches[VISIBLE_SWITCH_ID]
  64.     update_visibility
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # * Update the visibility and opacity
  68.   #--------------------------------------------------------------------------
  69.   def update_visibility
  70.     self.visible = $game_switches[VISIBLE_SWITCH_ID]
  71.     self.opacity = ($game_player.screen_x >= self.x && $game_player.screen_x <= self.x + self.width && $game_player.screen_y >= self.y && $game_player.screen_y <= self.y + self.height) ? WINDOW_COLLIDE_ALPHA : WINDOW_ALPHA
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * Determinates if the window have to be redrawn
  75.   #--------------------------------------------------------------------------
  76.   def need_update?
  77.     return @actor_values[0] != @actor.mhp || @actor_values[1] != @actor.hp || @actor_values[2] != @actor.mmp || @actor_values[3] != @actor.mp || @actor_values[4] != @actor.character_name || @actor_values[5] != @actor.character_index || @actor_values[6] != @actor.name
  78.   end
  79. end
  80. #==============================================================================
  81. # * Simple_HUD
  82. #------------------------------------------------------------------------------
  83. #  This is a super class of the simple HUD which will be displayed on the map
  84. #==============================================================================
  85. class Simple_HUD
  86.   #--------------------------------------------------------------------------
  87.   # * Object Initialization
  88.   #--------------------------------------------------------------------------
  89.   def initialize()
  90.     @hud_windows = []
  91.     for i in 0...$game_party.all_members.size
  92.       case HUD_POSITION
  93.       when 1 # Top
  94.         @hud_windows.push(Window_Base_HUD.new(Graphics.width/4*i,0,i))
  95.       when 2 # Bot
  96.         @hud_windows.push(Window_Base_HUD.new(Graphics.width/4*i,Graphics.height-(3*24+24),i))
  97.       when 3 # Left
  98.         @hud_windows.push(Window_Base_HUD.new(0,(3*24+24)*i,i))
  99.       when 4 # Right
  100.         @hud_windows.push(Window_Base_HUD.new(Graphics.width-Graphics.width/4,(3*24+24)*i,i))
  101.       when 5 # Corner
  102.         case i
  103.         when 0
  104.           @hud_windows.push(Window_Base_HUD.new(0,0,i))
  105.         when 1
  106.           @hud_windows.push(Window_Base_HUD.new(Graphics.width-Graphics.width/4,0,i))
  107.         when 2
  108.           @hud_windows.push(Window_Base_HUD.new(0,Graphics.height-(3*24+24),i))
  109.         when 3
  110.           @hud_windows.push(Window_Base_HUD.new(Graphics.width-Graphics.width/4,Graphics.height-(3*24+24),i))
  111.         end
  112.       end
  113.     end
  114.     @party_size = $game_party.all_members.size
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # * Frame Update
  118.   #--------------------------------------------------------------------------
  119.   def update
  120.     if @party_size != $game_party.all_members.size
  121.       terminate
  122.       initialize
  123.     end
  124.     for window in @hud_windows
  125.       window.update
  126.     end
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # * Terminate all windows
  130.   #--------------------------------------------------------------------------
  131.   def terminate
  132.     for window in @hud_windows
  133.       window.dispose
  134.     end
  135.   end
  136. end
  137. #==============================================================================
  138. # ** Spriteset_Map
  139. #------------------------------------------------------------------------------
  140. #  This class brings together map screen sprites, tilemaps, etc. It's used
  141. # within the Scene_Map class.
  142. #==============================================================================
  143. class Spriteset_Map
  144.   #--------------------------------------------------------------------------
  145.   # * Aliased methods
  146.   #--------------------------------------------------------------------------
  147.   alias doubleD_simple_hud_initialize initialize
  148.   alias doubleD_simple_hud_update update
  149.   alias doubleD_simple_hud_dispose dispose
  150.   #--------------------------------------------------------------------------
  151.   # * Object Initialization
  152.   #--------------------------------------------------------------------------
  153.   def initialize(*args)
  154.     doubleD_simple_hud_initialize(*args)
  155.     @doubleD_simple_hud = Simple_HUD.new()
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # * Frame Update
  159.   #--------------------------------------------------------------------------
  160.   def update(*args)
  161.     doubleD_simple_hud_update(*args)
  162.     @doubleD_simple_hud.update if !@doubleD_simple_hud.nil?
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # * Disposing all stuff
  166.   #--------------------------------------------------------------------------
  167.   def dispose(*args)
  168.     doubleD_simple_hud_dispose(*args)
  169.     @doubleD_simple_hud.terminate if !@doubleD_simple_hud.nil?
  170.   end
  171. end
Advertisement
Add Comment
Please, Sign In to add comment