ForeverZer0

{RMXP] Item Weight Addon - HUD

Apr 16th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.61 KB | None | 0 0
  1. #===============================================================================
  2. # * WeightHUD
  3. #===============================================================================
  4.  
  5. class WeightHUD < Window_Base
  6.  
  7.   # Set true/false if windowskin should be used or not. If not, text will simply
  8.   # be displayed on the screen.
  9.   WINDOWED = true
  10.  
  11.   # Set the location of the HUD. [X, Y, WIDTH, HEIGHT]
  12.   # I recommend a small X and Y offset if WINDOWED is set to false to have
  13.   # the text placed properly and not to far off the edge of the screen.
  14.   LOCATION = [0, 0, 144, 64]
  15.  
  16.   # Set the font used for the HUD. [FONT_NAME, FONT_SIZE]
  17.   # A value of nil for either setting will have it simply use the default font
  18.   FONT = ['Calibri', 20]
  19.  
  20.   # Script Calls:
  21.   #   hide_weightHUD(true/false) - Sets the hidden state of the weight HUD
  22.  
  23.   #-----------------------------------------------------------------------------
  24.   # * initialize
  25.   #     Creates a new instance of the HUD
  26.   #-----------------------------------------------------------------------------
  27.   def initialize
  28.     super(*LOCATION)
  29.     self.windowskin = nil unless WINDOWED
  30.     self.contents = Bitmap.new(width - 32, height - 32)
  31.     self.contents.font.name = FONT[0] == nil ? Font.default_name : FONT[0]
  32.     self.contents.font.size = FONT[1] == nil ? Font.default_size : FONT[1]
  33.     refresh
  34.   end
  35.   #-----------------------------------------------------------------------------
  36.   # * refresh
  37.   #   Clears and redraws the HUD
  38.   #-----------------------------------------------------------------------------
  39.   def refresh
  40.     self.contents.clear
  41.     self.contents.font.color = system_color
  42.     self.contents.draw_text(0, 0, 32, 32, 'WT')
  43.     weight, capacity = $game_party.total_weight, $game_party.weight_capacity
  44.     color = weight > capacity ? crisis_color : normal_color
  45.     self.contents.font.color = color
  46.     self.contents.draw_text(32, 0, 42, 32, weight.to_s, 2)
  47.     self.contents.font.color = normal_color
  48.     self.contents.draw_text(74, 0, 8, 32, '/', 1)
  49.     self.contents.draw_text(82, 0, 42, 32, capacity.to_s)
  50.   end
  51. end
  52.  
  53. #===============================================================================
  54. # * Game_Party
  55. #===============================================================================
  56.  
  57. class Game_Party
  58.   #-----------------------------------------------------------------------------
  59.   # * refresh_weight
  60.   #     Tells Scene_Map that the HUD needs refresh when the values change
  61.   #-----------------------------------------------------------------------------
  62.   alias weight_hud_refresh_weight refresh_weight
  63.   def refresh_weight
  64.     weight_hud_refresh_weight
  65.     if $scene.is_a?(Scene_Map)
  66.       $scene.refresh_weightHUD
  67.     end
  68.   end
  69. end
  70.  
  71. #===============================================================================
  72. # * Scene_Map
  73. #===============================================================================
  74.  
  75. class Scene_Map
  76.   #-----------------------------------------------------------------------------
  77.   # * main
  78.   #     Creates the HUD and disposes it when the scene ends
  79.   #-----------------------------------------------------------------------------
  80.   alias item_weight_main main
  81.   def main
  82.     @weight_hud = WeightHUD.new
  83.     item_weight_main
  84.     @weight_hud.dispose
  85.   end
  86.   #-----------------------------------------------------------------------------
  87.   # * hide_weightHUD
  88.   #     Hides/Shows the weight HUD if it is present and not disposed
  89.   #-----------------------------------------------------------------------------
  90.   def hide_weightHUD(bool)
  91.     if @weight_hud != nil && !@weight_hud.disposed?
  92.       @weight_hud.visible = bool
  93.     end
  94.   end
  95.   #-----------------------------------------------------------------------------
  96.   # * refresh_weightHUD
  97.   #     Refreshes the weight HUD if it is present and not disposed
  98.   #-----------------------------------------------------------------------------
  99.   def refresh_weightHUD
  100.     if @weight_hud != nil && !@weight_hud.disposed?
  101.       @weight_hud.refresh
  102.     end
  103.   end
  104. end
  105.  
  106. #===============================================================================
  107. # * Interpreter
  108. #===============================================================================
  109.  
  110. class Interpreter
  111.   #-----------------------------------------------------------------------------
  112.   # * hide_weightHUD
  113.   #     Hides/Shows the weight HUD if it is present and not disposed
  114.   #-----------------------------------------------------------------------------
  115.   def hide_weightHUD(value = true)
  116.     if $scene.is_a?(Scene_Map)
  117.       $scene.hide_weightHUD(value)
  118.     end
  119.   end
  120. end
Add Comment
Please, Sign In to add comment