Holy87

HUD grezzo

Mar 3rd, 2015
257
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module HUDConfig
  2.   AUTO_HIDE = false #vuoi che l'HUD si nasconda automaticamente dopo un po'?
  3.   # ATTENZIONE: NECESSITA DELLO SCRITP SMOOTH MOVE
  4.   HIDE_TIME = 5 #dopo quanti secondi vuoi che si nasconda?
  5.   SPEED = 3 #velocità di scomparsa dell'HUD
  6. end
  7.  
  8. class Window_H87Hud1 < Window_Base
  9.   def initialize(x, y)
  10.     super(x, y, Graphics.width, 96 + 16 + line_height*2)
  11.     self.opacity = 0
  12.     refresh
  13.   end
  14.  
  15.   def refresh
  16.     self.contents.clear
  17.     @actor = $game_party.members[0]
  18.     return if @actor.nil?
  19.     draw_actor_face(actor, 0, 0)
  20.     draw_actor_status
  21.     draw_actor_equip
  22.     draw_actor_exp
  23.   end
  24.  
  25.   def actor
  26.     return @actor
  27.   end
  28.  
  29.   def draw_actor_status
  30.     draw_hp(95, 0)
  31.     draw_mp(95, line_height)
  32.     draw_states(95, line_height*2)
  33.     draw_name(0,0,95)
  34.   end
  35.  
  36.   def draw_hp(x, y)
  37.     mwidth = [actor.mhp/10,contents.width-x].min
  38.     contents.fill_rect(x+2, y+2, mwidth+2, line_height - 4, Color.new(0,0,0))
  39.     contents.fill_rect(x+3, y+3, mwidth, line_height - 6, gauge_back_color)
  40.     hpwidth = actor.hp.to_f*mwidth/actor.mhp
  41.     contents.gradient_fill_rect(x+3, y+3, hpwidth, line_height-6,hp_gauge_color1, hp_gauge_color2)
  42.     change_color(system_color)
  43.     #draw_text(x, y, 30, line_height, Vocab::hp_a)
  44.     #draw_current_and_max_values(x, y, mwidth, actor.hp, actor.mhp,
  45.     #  hp_color(actor), normal_color)
  46.   end
  47.  
  48.   def draw_mp(x, y)
  49.     mwidth = [actor.mmp/2,contents.width-x].min
  50.     contents.fill_rect(x+2, y+2, mwidth+2, line_height - 4, Color.new(0,0,0))
  51.     contents.fill_rect(x+3, y+3, mwidth, line_height - 6, gauge_back_color)
  52.     mpwidth = actor.mp.to_f*mwidth/actor.mmp
  53.     contents.gradient_fill_rect(x+3, y+3, mwidth, line_height-6,mp_gauge_color1, mp_gauge_color2)
  54.     change_color(system_color)
  55.     #draw_text(x, y, 30, line_height, Vocab::mp_a)
  56.     #draw_current_and_max_values(x+30, y, mwidth, actor.mp, actor.mhp,
  57.     #  mp_color(actor), normal_color)
  58.     end
  59.    
  60.   def draw_states(x, y)
  61.     draw_actor_icons(actor, x, y)
  62.   end
  63.    
  64.   def draw_name(x, y, width)
  65.     change_color(normal_color)
  66.     old_size = contents.font.size
  67.     contents.font.size = 15
  68.     height = contents.text_size(actor.name).height
  69.     #contents.fill_rect(x, y, width, height, Color.new(0,0,0,128))
  70.     draw_text(x, y, width, height, actor.name)
  71.     contents.font.size = old_size
  72.   end
  73.    
  74.   def draw_actor_equip
  75.     return if actor.weapons.size == 0
  76.     for i in 0..actor.weapons.size-1
  77.       weapon = actor.weapons[i]
  78.       draw_icon(weapon.icon_index, 0, 95 + (line_height * i))
  79.       draw_text(x+24, 95 + (line_height * i), contents.width, line_height, weapon.name)
  80.     end
  81.   end
  82.    
  83.   def draw_actor_exp
  84.     unless actor.max_level?
  85.       zero = actor.current_level_exp
  86.       nlev = actor.next_level_exp - zero
  87.       exp = actor.exp - zero
  88.       contents.fill_rect(0, 94, 95, 2, gauge_back_color)
  89.       width = exp*95/nlev
  90.       contents.fill_rect(0,94,width, 2, power_up_color)
  91.     end
  92.     draw_actor_level(actor, 0, 96 - line_height)
  93. #~     exp = actor.
  94. #~     contents.fill_rect(0, 91,
  95.   end
  96.  
  97.   def draw_exp_info(x, y)
  98.     s1 = @actor.max_level? ? "-------" : @actor.exp
  99.     s2 = @actor.max_level? ? "-------" : @actor.next_level_exp - @actor.exp
  100.     s_next = sprintf(Vocab::ExpNext, Vocab::level)
  101.     change_color(system_color)
  102.     draw_text(x, y + line_height * 0, 180, line_height, Vocab::ExpTotal)
  103.     draw_text(x, y + line_height * 2, 180, line_height, s_next)
  104.     change_color(normal_color)
  105.     draw_text(x, y + line_height * 1, 180, line_height, s1, 2)
  106.     draw_text(x, y + line_height * 3, 180, line_height, s2, 2)
  107.   end
  108. end
  109.  
  110. class Spriteset_Map
  111.   alias h87hud1_create_pictures create_pictures unless $@
  112.   def create_pictures
  113.     h87hud1_create_pictures
  114.     create_hud
  115.   end
  116.    
  117.   def create_hud
  118.     y = $game_system.hud_active ? 0 : - 160
  119.     @actor_hud = Window_H87Hud1.new(0, y)
  120.     @actor_hud.viewport = @viewport3
  121.   end
  122.    
  123.   alias h87hud1_update update unless $@
  124.   def update
  125.     h87hud1_update
  126.     @actor_hud.update
  127.   end
  128.    
  129.   alias h87hud1_dispose dispose unless $@
  130.   def dispose
  131.     h87hud1_dispose
  132.     @actor_hud.dispose
  133.   end
  134.    
  135.   def refresh_hud
  136.     @actor_hud.refresh
  137.   end
  138.  
  139.   def hide_hud
  140.     @actor_hud.smooth_move(0,0-@actor_hud.height, HUDConfig::SPEED)
  141.   end
  142.  
  143.   def show_hud
  144.     @actor_hud.smooth_move(0,0, HUDConfig::SPEED)
  145.   end
  146. end
  147.  
  148. class Scene_Map < Scene_Base
  149.   alias h87hud_update update unless $@
  150.   def update
  151.     h87hud_update
  152.     update_hud_autohide
  153.   end
  154.  
  155.   def update_hud_autohide
  156.     return unless HUDConfig::AUTO_HIDE
  157.     if $game_system.hud_time > 0
  158.       $game_system.hud_time -= 1
  159.       hide_hud if $game_system.hud_time <= 0
  160.     end
  161.   end
  162.  
  163.   def refresh_hud
  164.     @spriteset.refresh_hud
  165.     if HUDConfig::AUTO_HIDE
  166.       show_hud
  167.     end
  168.   end
  169.  
  170.   def hide_hud
  171.     $game_system.hud_active = false
  172.     @spriteset.hide_hud
  173.   end
  174.  
  175.   def show_hud
  176.     $game_system.hud_active = true
  177.     @spriteset.show_hud
  178.     $game_system.reset_hud_time
  179.   end
  180.  
  181.   alias h87_hud1_update_scene update_scene unless $@
  182.   def update_scene
  183.     h87_hud1_update_scene
  184.     update_hide_hud unless scene_changing?
  185.   end
  186.  
  187.   def update_hide_hud
  188.     if Input.trigger?(:X)
  189.       Sound.play_cursor
  190.       $game_system.hud_active ? hide_hud : show_hud
  191.     end
  192.   end
  193. end
  194.  
  195. class Game_BattlerBase
  196.   alias h87hud1_refresh refresh unless $@
  197.   def refresh
  198.     h87hud1_refresh
  199.     refresh_hud
  200.   end
  201.  
  202.   def refresh_hud
  203.     return unless actor?
  204.     SceneManager.scene.refresh_hud if SceneManager.scene_is?(Scene_Map)
  205.   end
  206. end
  207.  
  208. class Game_System
  209.   def hud_active
  210.     @hud_active = true if @hud_active.nil?
  211.     return @hud_active
  212.   end
  213.  
  214.   def hud_active=(value)
  215.     @hud_active = value
  216.   end
  217.  
  218.   def hud_time
  219.     reset_hud_time if @hud_time.nil?
  220.     return @hud_time
  221.   end
  222.  
  223.   def hud_time=(value)
  224.     @hud_time = 0 if @hud_time.nil?
  225.     @hud_time = value
  226.   end
  227.  
  228.   def reset_hud_time
  229.     @hud_time = HUDConfig::HIDE_TIME*Graphics.frame_rate
  230.   end
  231. end
  232.  
  233. class Game_Interpreter
  234.   def hide_hud
  235.     $game_system.hud_active = false
  236.     SceneManager.scene.hide_hud if SceneManager.scene_is?(Scene_Map)
  237.   end
  238.  
  239.   def show_hud
  240.     $game_system.hud_active = true
  241.     SceneManager.scene.show_hud if SceneManager.scene_is?(Scene_Map)
  242.   end  
  243. end
RAW Paste Data