DrDhoom

Living Live HUD

Jan 8th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.78 KB | None | 0 0
  1. module Dhoom
  2.   module LivingLiveHUD    
  3.     WWIDTH          = 300
  4.     WHEIGHT         = 152
  5.     WX              = 0
  6.     WY              = Graphics.height - WHEIGHT
  7.    
  8.     VAR_STAMINA     = 1
  9.     VAR_MAX_STAMINA = 5
  10.     VAR_INT         = 6
  11.     VAR_INT_EXP     = 7
  12.     VAR_CHR         = 8
  13.     VAR_CHR_EXP     = 9
  14.     VAR_STR         = 10
  15.     VAR_STR_EXP     = 11
  16.    
  17.     STAMINA_COLOR1  = Color.new(0,128,0)
  18.     STAMINA_COLOR2  = Color.new(0,255,0)
  19.     INT_COLOR1      = Color.new(0,0,128)
  20.     INT_COLOR2      = Color.new(0,0,255)
  21.     CHR_COLOR1      = Color.new(128,128,128)
  22.     CHR_COLOR2      = Color.new(255,255,255)
  23.     STR_COLOR1      = Color.new(128,0,0)
  24.     STR_COLOR2      = Color.new(255,0,0)
  25.  
  26.     HUD_SWITCH      = 1
  27.   end
  28. end
  29.  
  30. class Window_HUD < Window_Base
  31.   include Dhoom::LivingLiveHUD
  32.   def initialize
  33.     super(WX,WY,WWIDTH,WHEIGHT)
  34.     self.opacity = 0
  35.     @actor = $game_party.members[0]
  36.     refresh
  37.   end
  38.  
  39.   def refresh
  40.     contents.clear
  41.     draw_face(@actor.face_name, @actor.face_index, 0, 0)
  42.     contents.font.size = 24
  43.     draw_currency_value($game_party.gold, Vocab::currency_unit, 0, 100, 96)
  44.     contents.font.color = normal_color
  45.     draw_actor_name    
  46.     draw_stamina
  47.     draw_int
  48.     draw_int_exp
  49.     draw_chr
  50.     draw_chr_exp
  51.     draw_str
  52.     draw_str_exp    
  53.   end
  54.  
  55.   def draw_actor_name
  56.     contents.font.size = 28
  57.     draw_text(98, 0, contents.width-98, 28, @actor.name, 1)
  58.     contents.font.size = 24
  59.   end
  60.  
  61.   def draw_stamina
  62.     @stamina = $game_variables[VAR_STAMINA]
  63.     @stamina_max = $game_variables[VAR_MAX_STAMINA]
  64.     return if @stamina_max == 0
  65.     draw_gauge(98, 34, contents.width-98, line_height-8, @stamina.to_f/@stamina_max, STAMINA_COLOR1, STAMINA_COLOR2)
  66.     contents.font.size = 18
  67.     draw_text(98, 30, contents.width-98, line_height, "Stamina: #{@stamina} / #{@stamina_max}", 1)
  68.     contents.font.size = 18
  69.   end
  70.  
  71.   def draw_int
  72.     @int = $game_variables[VAR_INT]
  73.     draw_text(98, 30+line_height, (contents.width-98)/2, line_height, "INT: #{@int}")
  74.   end
  75.  
  76.   def draw_int_exp
  77.     @int_exp = $game_variables[VAR_INT_EXP]
  78.     draw_gauge(98+(contents.width-98)/2, 34+line_height, (contents.width-98)/2, line_height-8, @int_exp/100.0, INT_COLOR1, INT_COLOR2)
  79.     contents.font.size = 18
  80.     draw_text(98+(contents.width-98)/2, 30+line_height, (contents.width-98)/2, line_height, "EXP: #{@int_exp} / 100", 1)
  81.   end
  82.  
  83.   def draw_chr
  84.     @chr = $game_variables[VAR_CHR]
  85.     draw_text(98, 30+line_height*2, (contents.width-98)/2, line_height, "CHR: #{@chr}")
  86.   end
  87.  
  88.   def draw_chr_exp
  89.     @chr_exp = $game_variables[VAR_CHR_EXP]
  90.     draw_gauge(98+(contents.width-98)/2, 34+line_height*2, (contents.width-98)/2, line_height-8, @chr_exp/100.0, CHR_COLOR1, CHR_COLOR2)
  91.     contents.font.size = 18
  92.     draw_text(98+(contents.width-98)/2, 30+line_height*2, (contents.width-98)/2, line_height, "EXP: #{@chr_exp} / 100", 1)
  93.   end
  94.  
  95.   def draw_str
  96.     @str = $game_variables[VAR_STR]
  97.     draw_text(98, 30+line_height*3, (contents.width-98)/2, line_height, "STR: #{@str}")
  98.   end
  99.  
  100.   def draw_str_exp
  101.     @str_exp = $game_variables[VAR_STR_EXP]
  102.     draw_gauge(98+(contents.width-98)/2, 34+line_height*3, (contents.width-98)/2, line_height-8, @str_exp/100.0, STR_COLOR1, STR_COLOR2)
  103.     contents.font.size = 18
  104.     draw_text(98+(contents.width-98)/2, 30+line_height*3, (contents.width-98)/2, line_height, "EXP: #{@str_exp} / 100", 1)
  105.   end  
  106.  
  107.   def draw_gauge(x, y, width, height, rate, color1, color2)
  108.     fill_w = (width * rate).to_i
  109.     contents.fill_rect(x, y, width, height, gauge_back_color)
  110.     contents.gradient_fill_rect(x, y, fill_w, height, color1, color2)
  111.   end
  112.  
  113.   def update
  114.     super
  115.     refresh if something_changed?
  116.   end
  117.  
  118.   def something_changed?
  119.     return true if @stamina != $game_variables[VAR_STAMINA]
  120.     return true if @stamina_max != $game_variables[VAR_MAX_STAMINA]
  121.     return true if @int != $game_variables[VAR_INT]
  122.     return true if @chr != $game_variables[VAR_CHR]
  123.     return true if @str != $game_variables[VAR_STR]
  124.     return true if @int_exp != $game_variables[VAR_INT_EXP]
  125.     return true if @chr_exp != $game_variables[VAR_CHR_EXP]
  126.     return true if @str_exp != $game_variables[VAR_STR_EXP]
  127.     return false
  128.   end
  129. end
  130.  
  131. class Scene_Map < Scene_Base
  132.   include Dhoom::LivingLiveHUD
  133.  
  134.   alias dhoom_hudlivliv_scmap_create_all_windows create_all_windows
  135.   def create_all_windows
  136.     dhoom_hudlivliv_scmap_create_all_windows
  137.     @hud_window = Window_HUD.new
  138.     @hud_window.z = 9999
  139.     @hud_window.openness = 0 unless $game_switches[HUD_SWITCH]
  140.   end
  141.  
  142.   alias dhoom_hudlivliv_scmap_update update
  143.   def update
  144.     dhoom_hudlivliv_scmap_update
  145.     if $game_switches[HUD_SWITCH]
  146.       @hud_window.open
  147.     else
  148.       @hud_window.close
  149.     end
  150.   end
  151. end
Add Comment
Please, Sign In to add comment