Gabriel_Nascimento

** Esteem - HUD Sprite

May 5th, 2018
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. #  ** Esteem - HUD Sprite
  3. #==============================================================================
  4. # ► Script por: Revali / Skyloftian
  5. #------------------------------------------------------------------------------
  6. # ► Atualizações: 05/05/18 - v1.0 - Código finalizado e revisado
  7. #==============================================================================
  8. # ► Descrição: Cria uma HUD básica. Script feito a pedido do membro Saggi.
  9. #==============================================================================
  10. # ► Comandos: Existem dois comandos para a utilização da HUD. Estes são:
  11. #
  12. #             esteem_hudsprite_enable     - Ativa a HUD
  13. #             esteem_hudsprite_disable    - Desativa a HUD
  14. #
  15. # * OBSERVAÇÃO: Estes comandos devem ser usados através do comando de evento
  16. #               Chamar Script / Script Call.
  17. #==============================================================================
  18. # * Para configurar vide a área configurável abaixo.
  19. #==============================================================================
  20. module Esteem
  21.   module HUD_Sprite
  22. #==============================================================================
  23. # ► Configurações
  24. #==============================================================================
  25.  
  26.    #===========================================================================
  27.    # ► Cores das Barras
  28.    #===========================================================================
  29.    # * Configure as duas cores de cada barra(HP, MP e TP) utilizando-se do
  30.    #   esquema RGB(Red, Green, Blue) / VVA (Vermelho, Verde, Azul). As duas
  31.    #   cores formarão um gradiente.
  32.    #---------------------------------------------------------------------------
  33.    # NÃO_MUDE  = [RED, GREEN, BLUE]
  34.    #===========================================================================
  35.      HP_COLOR1 = [115,   4,   4] # Primeira cor HP
  36.      HP_COLOR2 = [210,  12,  12] # Segunda cor HP
  37.    
  38.      MP_COLOR1 = [  0, 144, 255] # Primeira cor MP
  39.      MP_COLOR2 = [171, 218, 255] # Segunda cor MP
  40.    
  41.      TP_COLOR1 = [ 30, 252, 157] # Primeira cor TP
  42.      TP_COLOR2 = [147, 255, 209] # Segunda cor TP
  43.    
  44.      B_COLOR   = [109, 109, 109] # Cor do fundo das barras
  45.      
  46.      TX_COLOR  = [  0,   0, 255] # Cor do texto indicativo dos parâmetros
  47. #==============================================================================
  48. # ► Fim das Configurações | Não mude mais nada caso não entenda
  49. #==============================================================================    
  50.   end # HUD_Sprite
  51. end # Esteem
  52. class Scene_Map < Scene_Base
  53.  
  54.   def hud_manager
  55.     if !@hud
  56.       @hud = EHS_Hud.new
  57.     else
  58.       @hud.update
  59.     end
  60.   end
  61.  
  62.   alias :ehs_update :update
  63.   def update
  64.     ehs_update
  65.     hud_manager if $game_system.ehs_switch
  66.     @hud.dispose if !$game_system.ehs_switch && @hud
  67.   end
  68.  
  69.   alias :ehs_terminate :terminate
  70.   def terminate
  71.     @hud.dispose if @hud
  72.   end
  73.  
  74. end # Scene_Map
  75. class EHS_Hud
  76.   include Esteem::HUD_Sprite
  77.  
  78.   def initialize
  79.     super
  80.     draw_contents
  81.   end
  82.  
  83.   def draw_contents
  84.     @sprites = []
  85.     actor = $game_party.members[0]
  86.     all_width = (Graphics.width - 20) / 3
  87.     draw_actor_gauges(actor, all_width)
  88.     draw_actor_values(actor, all_width)
  89.     draw_actor_icons(actor, all_width * 2)
  90.   end
  91.  
  92.   def draw_actor_gauges(actor, gauge_width)
  93.     draw_gauge(actor.hp_rate, 5 , 19, gauge_width, HP_COLOR1, HP_COLOR2)
  94.     draw_gauge(actor.mp_rate, 10 + gauge_width, 19 , gauge_width, MP_COLOR1, MP_COLOR2)
  95.     draw_gauge(actor.tp_rate, 15 + gauge_width * 2, 19 , gauge_width, TP_COLOR1, TP_COLOR2)
  96.   end
  97.  
  98.   def draw_actor_values(actor, text_width)
  99.     draw_cam_values(actor.hp, actor.mhp, Vocab::hp_a, 5, 2, text_width, true)
  100.     draw_cam_values(actor.mp, actor.mmp, Vocab::mp_a, 10 + text_width, 2, text_width, true)
  101.     draw_cam_values(actor.tp, 100, Vocab::tp_a, 15 + text_width * 2, 2, text_width, false)
  102.   end
  103.  
  104.   def draw_actor_icons(actor, icons_width)
  105.     icons = (actor.state_icons + actor.buff_icons)[0, icons_width / 24]
  106.     icons.each_with_index {|n, i| draw_icon(n, 5 + 24 * i, 28) }
  107.   end
  108.  
  109.   def draw_gauge(rate, x, y, width, colora, colorb, colorc = B_COLOR)
  110.     color1 = Color.new(colora[0], colora[1], colora[2])
  111.     color2 = Color.new(colorb[0], colorb[1], colorb[2])
  112.     colorb = Color.new(colorc[0], colorc[1], colorc[2])
  113.     fill_w = (width * rate).to_i
  114.     gauge_back = Sprite.new
  115.     gauge_back.x = x ; gauge_back.y = y
  116.     gauge_back.bitmap = Bitmap.new(width, 6)
  117.     gauge_back.bitmap.fill_rect(0, 0, width, 6, colorb)
  118.     gauge = Sprite.new
  119.     gauge.x = x ; gauge.y = y
  120.     gauge.bitmap = Bitmap.new(width, 6)
  121.     gauge.bitmap.gradient_fill_rect(0, 0, fill_w, 6, color1, color2)
  122.     @sprites.push(gauge_back, gauge)
  123.   end
  124.  
  125.   def draw_cam_values(current, max, vocab, x, y, width, change)
  126.     color1 = Color.new(TX_COLOR[0], TX_COLOR[1], TX_COLOR[2])
  127.     current < max / 4 && change ? color2 = Color.new(255, 255, 0, 255) : color2 = Color.new(255, 255, 255, 255)
  128.     text = Sprite.new ; values = Sprite.new
  129.     text.x = x ; values.x = x
  130.     text.y = y ; values.y = y
  131.     text.z = 1 ; values.z = 1
  132.     text.bitmap = Bitmap.new(width, 25) ; values.bitmap = text.bitmap
  133.     text.bitmap.font.color = color1
  134.     text.bitmap.draw_text(0, 0, width, 25, vocab, 0)
  135.     values.bitmap.font.color = color2
  136.     values.bitmap.draw_text(0, 0, width, 25, current.to_s + "/" + max.to_s, 2)
  137.     @sprites.push(text, values)
  138.   end
  139.  
  140.   def draw_icon(icon_index, x, y, enabled = true)
  141.     icon = Sprite.new
  142.     icon.x = x ; icon.y = y
  143.     icon.bitmap = Cache.system("Iconset")
  144.     icon.src_rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  145.     @sprites.push(icon)
  146.   end
  147.  
  148.   def update
  149.     refresh
  150.   end
  151.  
  152.   def refresh
  153.     dispose
  154.     draw_contents
  155.   end
  156.  
  157.   def dispose
  158.     @sprites.each {|sprite| sprite.dispose}
  159.   end
  160.  
  161. end # EHS_Hud
  162. class Game_System
  163.  
  164.   attr_accessor :ehs_switch
  165.  
  166.   alias :ehs_initialize :initialize
  167.   def initialize
  168.     ehs_initialize
  169.     @ehs_switch = false
  170.   end
  171.  
  172. end # Game_System
  173. class Game_Interpreter
  174.  
  175.   def esteem_hudsprite_enable
  176.     $game_system.ehs_switch = true
  177.   end
  178.  
  179.   def esteem_hudsprite_disable
  180.     $game_system.ehs_switch = false
  181.   end
  182.  
  183. end # Game_Interpreter
RAW Paste Data