TheoAllen

Simple VarHUD v1.1

Aug 9th, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.96 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Simple Variable HUD
  3. # Version : 1.1b
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_VariableHUD] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2013.10.15 - Bugfix, crashed when using hide_variable script call
  12. # 2013.08.09 - Add mutiple variable HUD support
  13. # 2013.07.23 - Finished script
  14. # =============================================================================
  15. =begin
  16.  
  17.   Perkenalan :
  18.   Script ini berguna untuk menampilkan nilai dari sebuah variable
  19.  
  20.   Cara penggunaan :
  21.   Pasang dibawah material namun diatas main
  22.  
  23.   Gunakan script call
  24.   show_variable(id) >> nampilin nilai variable
  25.   show_variable(id,icon_id) >> variable + gambar icon
  26.   show_variable(id,icon_id,pos) >> variable + icon + posisi
  27.  
  28.   Untuk mutiple HUD, gunakan script call
  29.   show_variable([id,id,id],[icon,icon,icon],pos)
  30.  
  31.   hide_variable >> untuk sembunyiin variable HUD
  32.  
  33.   Terms of Use :
  34.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  35.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  36.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  37.  
  38.   Note :
  39.   Karena ini simple, jadi jangan harap ada banyak kustomisasi bebas
  40.  
  41. =end
  42. # =============================================================================
  43. # Sedikit Konfigurasi
  44. # =============================================================================
  45.   VarHUD_DefaultPos = 1 # Posisi default HUD
  46. # -----------------------------------------------------------------------------
  47. # 1 >> Kiri Atas
  48. # 2 >> Kanan Atas
  49. # 3 >> Kiri Bawah
  50. # 4 >> Kanan Bawah
  51. # -----------------------------------------------------------------------------
  52.   VarHUD_FontSize = 24 # Ukuran Font
  53. # -----------------------------------------------------------------------------
  54.   VarHUD_MaxVar = 3 # Maksimal variable yg dapat ditampilin
  55. # =============================================================================
  56. # Akhir dari konfig
  57. # =============================================================================
  58. class Game_Temp
  59.   attr_accessor :refresh_hud
  60.  
  61.   alias theo_varhud_init initialize
  62.   def initialize
  63.     theo_varhud_init
  64.     @refresh_hud = false
  65.   end
  66.  
  67. end
  68.  
  69. class Game_Variables
  70.   alias theo_varhud_on_change on_change
  71.   def on_change
  72.     theo_varhud_on_change
  73.     $game_temp.refresh_hud = true
  74.   end
  75. end
  76.  
  77. class Game_System
  78.   class VarHUD
  79.     attr_accessor :position
  80.     attr_accessor :icon
  81.     attr_accessor :id
  82.    
  83.     def initialize
  84.       @position = 0
  85.       @icon = 0
  86.       @id = 0
  87.     end
  88.   end
  89.   attr_accessor :varhud_visible
  90.   attr_accessor :varhud_position
  91.   attr_reader :varhud
  92.  
  93.   alias theo_varhud_init initialize
  94.   def initialize
  95.     theo_varhud_init
  96.     @varhud = Array.new(VarHUD_MaxVar) { VarHUD.new }
  97.   end
  98.  
  99.   def clear_varhud
  100.     @varhud.each do |hud|
  101.       hud.id = 0
  102.     end
  103.   end
  104.  
  105. end
  106.  
  107. class Game_Interpreter
  108.  
  109.   def show_variable(id = nil,icon = 0,position = VarHUD_DefaultPos)
  110.     $game_system.clear_varhud
  111.     if id.is_a?(Array)
  112.       icon = [icon] unless icon.is_a?(Array)
  113.       id.each_with_index do |i,index|
  114.         return if index-1 > VarHUD_MaxVar
  115.         hud = $game_system.varhud[index]
  116.         hud.id = i
  117.         hud.icon = icon[index]
  118.       end
  119.     elsif id.is_a?(Numeric)
  120.       hud = $game_system.varhud[0]
  121.       hud.icon = icon
  122.       hud.id = id
  123.     end
  124.     $game_system.varhud_position = position
  125.     $game_system.varhud_visible = true
  126.     $game_temp.refresh_hud = true
  127.   end
  128.  
  129.   def hide_variable
  130.     $game_system.varhud_visible = false
  131.   end
  132.  
  133. end
  134.  
  135. class Window_VarHUD < Window_Base
  136.  
  137.   def initialize
  138.     super(0,0,window_width,window_height)
  139.     contents.font.size = VarHUD_FontSize
  140.     update_hud_position
  141.     self.opacity = 0
  142.     refresh
  143.   end
  144.  
  145.   def window_width;Graphics.width;end;
  146.   def window_height;fitting_height(VarHUD_MaxVar);end;
  147.   def line_height;VarHUD_FontSize;end;
  148.    
  149.   def update
  150.     super
  151.     update_visibility
  152.     refresh if $game_temp.refresh_hud
  153.   end
  154.  
  155.   def update_visibility
  156.     self.visible = $game_system.varhud_visible
  157.   end
  158.  
  159.   def refresh
  160.     contents.clear
  161.     active_hud.each_with_index do |hud,i|
  162.       update_hud_contents(hud,i)
  163.     end
  164.     update_hud_position
  165.     $game_temp.refresh_hud = false
  166.   end
  167.  
  168.   def update_hud_position
  169.     pos = $game_system.varhud_position
  170.     if pos == 1 || pos == 2
  171.       self.y = 0
  172.     elsif
  173.       self.y = Graphics.height - self.height
  174.       size = active_hud.size - 1
  175.       return if size < 0
  176.       self.y += size * line_height
  177.     end
  178.   end
  179.  
  180.   def update_hud_contents(hud,i)
  181.     var_id = hud.id
  182.     icon = hud.icon.nil? ? 0 : hud.icon
  183.     return if var_id == 0
  184.     rect = Rect.new(0,0,contents.width,line_height)
  185.     rect.y = i * line_height
  186.     case $game_system.varhud_position
  187.     when 1,3
  188.       if icon != 0
  189.         rect.x += 27
  190.         draw_icon(icon,0,icon_y_pos + (i * line_height))
  191.       end
  192.       draw_text(rect,$game_variables[var_id])
  193.     else
  194.       if icon != 0
  195.         rect.x -= 27
  196.         draw_icon(icon,contents.width-24,icon_y_pos + (i * line_height))
  197.       end
  198.       draw_text(rect,$game_variables[var_id],2)
  199.     end
  200.   end
  201.  
  202.   def icon_y_pos
  203.     return 0 if line_height <= 24
  204.     return line_height/2 - 12
  205.   end
  206.  
  207.   def active_hud
  208.     $game_system.varhud.select {|hud| hud.id > 0}
  209.   end
  210.  
  211. end
  212.  
  213. class Scene_Map < Scene_Base
  214.  
  215.   alias theo_varhud_start start
  216.   def start
  217.     theo_varhud_start
  218.     create_var_hud
  219.   end
  220.  
  221.   def create_var_hud
  222.     @var_hud = Window_VarHUD.new
  223.     @var_hud.z -= 100
  224.   end
  225.  
  226. end
Advertisement
Add Comment
Please, Sign In to add comment