TheoAllen

Theo - Simple Variable HUD

Jul 23rd, 2013
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.77 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Simple Variable HUD
  3. # Version : 1.0
  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.07.23 - Finished script
  12. # =============================================================================
  13. =begin
  14.  
  15.   Perkenalan :
  16.   Script ini berguna untuk menampilkan nilai dari sebuah variable
  17.  
  18.   Cara penggunaan :
  19.   Pasang dibawah material namun diatas main
  20.  
  21.   Gunakan script call
  22.   show_variable(id) >> nampilin nilai variable
  23.   show_variable(id,icon_id) >> variable + gambar icon
  24.   show_variable(id,icon_id,pos) >> variable + icon + posisi
  25.  
  26.   hide_variable >> untuk sembunyiin variable HUD
  27.  
  28.   Terms of Use :
  29.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  30.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  31.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  32.  
  33.   Note :
  34.   Karena ini simple, jadi jangan harap ada banyak kustomisasi bebas
  35.  
  36. =end
  37. # =============================================================================
  38. # Sedikit Konfigurasi
  39. # =============================================================================
  40.   VarHUD_DefaultPos = 1 # Posisi default HUD
  41. # -----------------------------------------------------------------------------
  42. # 1 >> Kiri Atas
  43. # 2 >> Kanan Atas
  44. # 3 >> Kiri Bawah
  45. # 4 >> Kanan Bawah
  46. # -----------------------------------------------------------------------------
  47.   VarHUD_FontSize = 34 # Ukuran Font
  48. # =============================================================================
  49. # Akhir dari konfig
  50. # =============================================================================
  51. class Game_Temp
  52.   attr_accessor :refresh_hud
  53.  
  54.   alias theo_varhud_init initialize
  55.   def initialize
  56.     theo_varhud_init
  57.     @refresh_hud = false
  58.   end
  59.  
  60. end
  61.  
  62. class Game_Variables
  63.   alias theo_varhud_on_change on_change
  64.   def on_change
  65.     theo_varhud_on_change
  66.     $game_temp.refresh_hud = true
  67.   end
  68. end
  69.  
  70. class Game_System
  71.   class VarHUD
  72.     attr_accessor :position
  73.     attr_accessor :visible
  74.     attr_accessor :icon
  75.     attr_accessor :id
  76.    
  77.     def initialize
  78.       @position = 0
  79.       @visible = false
  80.       @icon = 0
  81.       @id = 0
  82.     end
  83.   end
  84.   attr_reader :varhud
  85.  
  86.   alias theo_varhud_init initialize
  87.   def initialize
  88.     theo_varhud_init
  89.     @varhud = VarHUD.new
  90.   end
  91.  
  92. end
  93.  
  94. class Game_Interpreter
  95.  
  96.   def show_variable(id,icon = 0,position = VarHUD_DefaultPos)
  97.     hud = $game_system.varhud
  98.     hud.visible = true
  99.     hud.position = position
  100.     hud.icon = icon
  101.     hud.id = id
  102.     $game_temp.refresh_hud = true
  103.   end
  104.  
  105.   def hide_variable
  106.     $game_system.varhud.visible = false
  107.   end
  108.  
  109. end
  110.  
  111. class Window_VarHUD < Window_Base
  112.  
  113.   def initialize
  114.     super(0,0,window_width,window_height)
  115.     contents.font.size = VarHUD_FontSize
  116.     update_hud_position
  117.     self.opacity = 0
  118.     refresh
  119.   end
  120.  
  121.   def window_width;Graphics.width;end;
  122.   def window_height;fitting_height(1);end;
  123.   def line_height;VarHUD_FontSize;end;
  124.    
  125.   def update
  126.     super
  127.     update_visibility
  128.     refresh if $game_temp.refresh_hud
  129.   end
  130.  
  131.   def update_visibility
  132.     self.visible = $game_system.varhud.visible
  133.   end
  134.  
  135.   def refresh
  136.     contents.clear
  137.     update_hud_position
  138.     update_hud_contents
  139.     $game_temp.refresh_hud = false
  140.   end
  141.  
  142.   def update_hud_position
  143.     pos = $game_system.varhud.position
  144.     if pos == 1 || pos == 2
  145.       self.y = 0
  146.     else
  147.       self.y = Graphics.height - self.height
  148.     end
  149.   end
  150.  
  151.   def update_hud_contents
  152.     rect = contents.rect
  153.     icon = $game_system.varhud.icon
  154.     var_id = $game_system.varhud.id
  155.     case $game_system.varhud.position
  156.     when 1,3
  157.       if icon != 0
  158.         rect.x += 27
  159.         draw_icon(icon,0,icon_y_pos)
  160.       end
  161.       draw_text(rect,$game_variables[var_id])
  162.     else
  163.       if icon != 0
  164.         rect.x -= 27
  165.         draw_icon(icon,contents.width-24,icon_y_pos)
  166.       end
  167.       draw_text(rect,$game_variables[var_id],2)
  168.     end
  169.   end
  170.  
  171.   def icon_y_pos
  172.     return 0 if line_height <= 24
  173.     return contents.rect.height/2 - 12
  174.   end
  175.  
  176. end
  177.  
  178. class Scene_Map < Scene_Base
  179.  
  180.   alias theo_varhud_start start
  181.   def start
  182.     theo_varhud_start
  183.     create_var_hud
  184.   end
  185.  
  186.   def create_var_hud
  187.     @var_hud = Window_VarHUD.new
  188.     @var_hud.z -= 100
  189.   end
  190.  
  191. end
Advertisement
Add Comment
Please, Sign In to add comment