IceDragon200

[ED][XS]Variable Hud

Apr 1st, 2012
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.33 KB | None | 0 0
  1. #==============================================================================
  2. #   XS - Variable Hud
  3. #   Author: Nicke
  4. #   Created: 02/04/2011
  5. #   Edited: 02/04/2012
  6. #   Version: 1.0
  7. #==============================================================================
  8. # Instructions
  9. # -----------------------------------------------------------------------------
  10. # To install this script, open up your script editor and copy/paste this script
  11. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  12. #
  13. # A small hud to display variables on the map.
  14. #
  15. # *** Only for RPG Maker VX Ace. ***
  16. #==============================================================================
  17. ($imported ||= {})["XAIL-SIMPLE-GOLD-HUD"] = true
  18.  
  19. module XAIL
  20.   module VAR_HUD
  21.   #--------------------------------------------------------------------------#
  22.   # * Settings
  23.   #--------------------------------------------------------------------------#
  24.     # FONT = [name, size, color, bold, shadow]
  25.     FONT = [["Verdana"], 14, Color.new(255,255,255), true, true]
  26.  
  27.     # HUD = [width, x, y, opacity, skin]
  28.     HUD =  [160, 405, -5,  200, 0, nil]
  29.    
  30.     # VAR_HUD_SWITCH = switch_id
  31.     VAR_HUD_SWITCH = 10
  32.    
  33.     # VAR_LIST = [variable_id, vocab (can be nil), icon_index, x, y]
  34.     VAR_LIST = [] # Don't remove!
  35.     VAR_LIST[0] = [1, "Herbs", 200]
  36.     VAR_LIST[1] = [2, "Gems", 358]
  37.     VAR_LIST[1] = [3, "Gold", 361]
  38.     VAR_LIST[2] = [4, nil, 359]
  39.     VAR_LIST[3] = [5, nil, 366]
  40.    
  41.     # The space beetween the variables.
  42.     # SPACING = number
  43.     SPACING = 24
  44.    
  45.   end
  46. end
  47. # *** Don't edit below unless you know what you are doing. ***
  48. #==============================================================================#
  49. # ** Window_Variables
  50. #------------------------------------------------------------------------------
  51. #  Class for drawing the variable hud.
  52. #==============================================================================#
  53. class Window_Variables < Window_Base
  54.  
  55.   def initialize
  56.     # // Method to initialize the gold window.
  57.     super(0, 0, window_width, fitting_height(XAIL::VAR_HUD::VAR_LIST.size))
  58.     refresh
  59.   end
  60.  
  61.   def window_width
  62.     # // Method to return the width.
  63.     return XAIL::VAR_HUD::HUD[0]
  64.   end
  65.  
  66.   def draw_var(var, unit, x, y, width)
  67.     # // Method to draw a variable with the content.
  68.     cx = text_size(unit).width
  69.     value = "#{$game_variables[var]}x"
  70.     contents.font = Font.new(XAIL::VAR_HUD::FONT[0], XAIL::VAR_HUD::FONT[1])
  71.     contents.font.color = XAIL::VAR_HUD::FONT[2]
  72.     contents.font.bold = XAIL::VAR_HUD::FONT[3]
  73.     contents.font.shadow = XAIL::VAR_HUD::FONT[4]
  74.     draw_text(x, y, width - cx - 10, line_height, value, 2)
  75.     draw_text(x, y, width - 18, line_height, unit, 2)
  76.     reset_font_settings
  77.   end
  78.  
  79.   def refresh
  80.     # // Method to refresh the gold.
  81.     contents.clear
  82.     draw_var_hud
  83.   end
  84.  
  85.   def draw_var_hud
  86.     # // Method to draw the var hud.
  87.     y = 0
  88.     @vars = {}
  89.     for i in XAIL::VAR_HUD::VAR_LIST
  90.       if i[1].nil?
  91.         draw_var(i[0], nil, -18, y, contents.width - 8)
  92.       else
  93.         draw_var(i[0], i[1], -10, y, contents.width - 8)
  94.       end
  95.       draw_icon(i[2], 100, y)
  96.       y += XAIL::VAR_HUD::SPACING
  97.       @vars[i[0]] = $game_variables[i[0]]
  98.     end
  99.   end
  100.  
  101.   def update
  102.     # // Method to update the gold.
  103.     super
  104.     for i in XAIL::VAR_HUD::VAR_LIST
  105.       refresh() if($game_variables[i[0]] != @vars[i[0]])
  106.     end
  107.   end
  108.  
  109. end
  110. #==============================================================================
  111. # ** Scene_Map
  112. #------------------------------------------------------------------------------
  113. #  Show variable hud on the map.
  114. #==============================================================================
  115. class Scene_Map < Scene_Base
  116.  
  117.   alias xail_var_hud_window_start start
  118.   def start(*args, &block)
  119.     # // Method to start the var hud window on the map.
  120.     xail_var_hud_window_start(*args, &block)
  121.     create_var_hud_window
  122.     @var_hud_window.visible = $game_switches[XAIL::VAR_HUD::VAR_HUD_SWITCH]
  123.   end
  124.  
  125.   alias xail_var_hud_window_terminate terminate
  126.   def terminate(*args, &block)
  127.     # // Method to terminate the var hud window on the map.
  128.     xail_var_hud_window_terminate(*args, &block)
  129.     dispose_var_hud_window
  130.   end
  131.  
  132.   def create_var_hud_window
  133.     # // Method to create the variable window.
  134.     @var_hud_window = Window_Variables.new
  135.     @var_hud_window.x = XAIL::VAR_HUD::HUD[1]
  136.     @var_hud_window.y = XAIL::VAR_HUD::HUD[2]
  137.     @var_hud_window.z = XAIL::VAR_HUD::HUD[3]
  138.     @var_hud_window.opacity = XAIL::VAR_HUD::HUD[4]
  139.     @var_hud_window.windowskin = Cache.system(XAIL::VAR_HUD::HUD[5]) unless XAIL::VAR_HUD::HUD[5].nil?
  140.   end
  141.  
  142.   def dispose_var_hud_window
  143.     # // Method to dispose the var hud window.
  144.     @var_hud_window.dispose unless @var_hud_window.nil?
  145.     @var_hud_window = nil
  146.   end
  147.  
  148.   alias xail_var_hud_window_update update
  149.   def update(*args, &block)
  150.     # // Method to update the gold window on the map.
  151.     xail_var_hud_window_update(*args, &block)
  152.     @var_hud_window.update
  153.     @var_hud_window.visible = $game_switches[XAIL::VAR_HUD::VAR_HUD_SWITCH]
  154.   end
  155.  
  156. end # END OF FILE
  157.  
  158. #=*==========================================================================*=#
  159. # ** END OF FILE
  160. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment