Advertisement
thiago_d_d

Custom HUD

Jan 16th, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.69 KB | None | 0 0
  1. #==============================================================
  2. # http://thiagodd.blogspot.com.br
  3. #
  4. # [TSDA] Custom HUD
  5. #   --> Version 1.0
  6. # ----Credits
  7. #     thiago_d_d
  8. #     Blizzard - for the mouse system
  9. #
  10. #--------------------------------------------------------------
  11. # * Features
  12. #--------------------------------------------------------------
  13. # + A custom HUD that shows value when mouse is above.
  14. #
  15. #--------------------------------------------------------------
  16. # * Install
  17. #--------------------------------------------------------------
  18. # Put this script above Main.
  19. #
  20. #--------------------------------------------------------------
  21. # * Configuration
  22. #--------------------------------------------------------------
  23. # Configure text color below.
  24. #==============================================================
  25. module TSDA
  26.   COR_R=0
  27.   COR_G=0
  28.   COR_B=0
  29. end
  30. #--------------------------------------------------------------
  31. class Scene_Map
  32.   alias old_main main
  33.   alias old_update update
  34.   def main
  35.     @window_digimon = Window_Digimon_Hud.new
  36.     @window_text = Window_MouseOver.new
  37.     old_main
  38.     @window_digimon.dispose
  39.     @window_text.dispose
  40.   end
  41.   #------------------------------------------------------------
  42.   def update
  43.     @window_digimon.update
  44.     @window_text.update
  45.     old_update
  46.     @window_digimon.refresh
  47.     x = $mouse.x
  48.     y = $mouse.y
  49.     if x >= 328 && x <= 629 && y >= 465 && y <= 476
  50.       actor = $game_party.actors[0]
  51.       st = "#{actor.exp_now}/#{actor.exp_next}"
  52.       @window_text.refresh(st)
  53.       @window_text.visible = true
  54.     elsif x >= 532 && x <= 630
  55.       if y >= 429 && y <= 440
  56.         actor = $game_party.actors[0]
  57.         st = "#{actor.hp}/#{actor.maxhp}"
  58.         @window_text.refresh(st)
  59.         @window_text.visible = true
  60.       elsif y >= 448 && y <= 459
  61.         actor = $game_party.actors[0]
  62.         st = "#{actor.sp}/#{actor.maxsp}"
  63.         @window_text.refresh(st)
  64.         @window_text.visible = true
  65.       end
  66.     else
  67.       @window_text.visible = false
  68.     end
  69.   end
  70. end
  71. #----------------------------------------------
  72. class Game_Actor
  73.   def exp_now
  74.     return @exp_list[@level+1] > 0 ? self.exp_next -
  75.     (@exp_list[@level+1] - @exp) : 0
  76.   end
  77.   #------------------------------------------------------------
  78.   def exp_next
  79.     @exp_list[@level+1] > 0 ? @exp_list[@level+1] -
  80.     @exp_list[@level] : 0
  81.   end
  82. end
  83. #--------------------------------------------------------------
  84. class Window_Digimon_Hud < Window_Base
  85.   def initialize
  86.     super(262,383,394,113)
  87.     self.contents = Bitmap.new(width - 32,height - 32)
  88.     self.contents.font.size = 16
  89.     self.opacity = 0
  90.     self.back_opacity = 0
  91.     self.contents_opacity = 210
  92.     refresh
  93.   end
  94.   #------------------------------------------------------------
  95.   def refresh
  96.     self.contents.clear
  97.     actor = $game_party.actors[0]
  98.     self.contents.font.color = Color.new(TSDA::COR_R,
  99.     TSDA::COR_G,TSDA::COR_B)
  100.     bitmap = RPG::Cache.picture("HUD1")
  101.     bitmap2 = RPG::Cache.picture("HUD2")
  102.     bitmap3 = RPG::Cache.picture("HUD3")
  103.     bitmap4 = RPG::Cache.picture("HUD4")
  104.     src_rect = Rect.new(0, 0, 362, 81)
  105.     src_rect2 = Rect.new(0, 0,
  106.     actor.exp_now * 302 / actor.exp_next, 12)
  107.     src_rect3 = Rect.new(0, 0, actor.hp * 99 / actor.maxhp, 12)
  108.     src_rect4 = Rect.new(0, 0, actor.sp * 99 / actor.maxsp, 12)
  109.     self.contents.blt(0, 0, bitmap, src_rect)
  110.     self.contents.blt(50, 66, bitmap2, src_rect2)
  111.     self.contents.blt(254, 30, bitmap3, src_rect3)
  112.     self.contents.blt(254, 49, bitmap4, src_rect4)
  113.     self.contents.draw_text(231,8,39,16,actor.level.to_s)
  114.   end
  115. end
  116. #--------------------------------------------------------------
  117. class Window_MouseOver < Window_Base
  118.   def initialize
  119.     super(0, 0, 160, 64)
  120.     self.contents = Bitmap.new(width - 32,height - 32)
  121.     self.contents.font.name = $fontface
  122.     self.contents.font.size = $fontsize
  123.     self.opacity = 210
  124.     self.back_opacity = 210
  125.     self.z = 9999
  126.     self.visible = false
  127.   end
  128.   #------------------------------------------------------------
  129.   def refresh(text)
  130.     self.width = self.contents.text_size(text).width + 32
  131.     self.contents.dispose
  132.     self.contents = Bitmap.new(width - 32,height - 32)
  133.     self.contents.font.color = Color.new(TSDA::COR_R,
  134.     TSDA::COR_G,TSDA::COR_B)
  135.     self.x = $mouse.x - 64
  136.     self.y = $mouse.y - 64
  137.     self.contents.draw_text(0,0,128,32,text)
  138.   end
  139. end
  140. #--------------------------------------------------------------
  141. class Mouse
  142.   MOUSE_ICON = 'cursor'
  143.   AUTO_CONFIGURE = true
  144.   SCREEN_TO_CLIENT = Win32API.new('user32',
  145.   'ScreenToClient', %w(l p), 'i')
  146.   CLIENT_RECT = Win32API.new('user32',
  147.   'GetClientRect', %w(l p), 'i')
  148.   READ_INI = Win32API.new('kernel32',
  149.   'GetPrivateProfileStringA', %w(p p p p l p), 'l')
  150.   FIND_WINDOW = Win32API.new('user32',
  151.   'FindWindowA', %w(p p), 'l')
  152.   CURSOR_POSITION = Win32API.new('user32',
  153.   'GetCursorPos', 'p', 'i')
  154.   #------------------------------------------------------------
  155.   def initialize
  156.     @cursor = Sprite.new
  157.     @cursor.z = 1000000
  158.     update
  159.   end
  160.   #------------------------------------------------------------
  161.   def update
  162.     @cursor.x, @cursor.y = self.position
  163.   end
  164.   #------------------------------------------------------------
  165.   def x
  166.     return @cursor.x
  167.   end
  168.   #------------------------------------------------------------
  169.   def y
  170.     return @cursor.y
  171.   end
  172.   #------------------------------------------------------------
  173.   def global_position
  174.     pos = [0, 0].pack('ll')
  175.     return (CURSOR_POSITION.call(pos) != 0 ?
  176.     pos.unpack('ll') : nil)
  177.   end
  178.   #------------------------------------------------------------
  179.   def position
  180.     width, height = self.client_size
  181.     x, y = self.screen_to_client(*self.global_position)
  182.     return x, y
  183.   end
  184.   #------------------------------------------------------------
  185.   def screen_to_client(x, y)
  186.     return nil if x == nil || y == nil
  187.     pos = [x, y].pack('ll')
  188.     return (SCREEN_TO_CLIENT.call(WINDOW, pos) != 0 ?
  189.     pos.unpack('ll') : nil)
  190.   end
  191.   #------------------------------------------------------------
  192.   def client_size
  193.     rect = [0, 0, 0, 0].pack('l4')
  194.     CLIENT_RECT.call(WINDOW, rect)
  195.     right, bottom = rect.unpack('l4')[2, 2]
  196.     return right, bottom
  197.   end
  198.   #------------------------------------------------------------
  199.   def self.find_window
  200.     game_name = "\0" * 256
  201.     READ_INI.call('Game', 'Title', '', game_name, 255,
  202.     '.\\Game.ini')
  203.     game_name.delete!("\0")
  204.     return FIND_WINDOW.call('RGSS Player', game_name)
  205.   end
  206.   #------------------------------------------------------------
  207.   WINDOW = self.find_window
  208. end
  209. $mouse = Mouse.new
  210. #--------------------------------------------------------------
  211. module Input
  212.   class << Input
  213.     alias update_mousecontroller_later update
  214.   end
  215.   #------------------------------------------------------------
  216.   def self.update
  217.     $mouse.update
  218.     update_mousecontroller_later
  219.   end
  220.   #------------------------------------------------------------
  221.   if Mouse::AUTO_CONFIGURE
  222.     if $BlizzABS
  223.       C.push(Input::Key['Mouse Left']) if
  224.       !C.include?(Input::Key['Mouse Left'])
  225.       if !Attack.include?(Input::Key['Mouse Right'])
  226.         Attack.push(Input::Key['Mouse Right'])
  227.       end
  228.     elsif $tons_version != nil && $tons_version >= 6.4 &&
  229.         TONS_OF_ADDONS::CUSTOM_CONTROLS || defined?(RMXOS)
  230.       C.push(Input::Key['Mouse Left']) if !C.include?(
  231.       Input::Key['Mouse Left'])
  232.     end
  233.   end
  234. end
  235. #--------------------------------------------------------------
  236. class Rect
  237.   def covers?(x, y)
  238.     return !(x < self.x || x >= self.x + self.width ||
  239.         y < self.y || y >= self.y + self.height)
  240.   end
  241. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement