eugene222

Mouse Hud

Jul 24th, 2014
260
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. # ** Mouse Hud **
  3. #
  4. # Author:   Evgenij
  5. # Version:  1.0
  6. # Date:     24.07.2014
  7. #
  8. # Required: SUPER SIMPLE MOUSE SCRIPT V. 1.10 by Shaz
  9. #           http://forums.rpgmakerweb.com/index.php?/topic/17829-amaranths-super-simple-mouse-system-for-ace/
  10. #
  11. # Thanks To: Shaz for the Script
  12. #            kevin25081998 for requesting this script
  13. #
  14. # My Terms of Use: http://evgenij-scripts.org/?page_id=34
  15. #===============================================================================
  16. #
  17. # Description:
  18. #
  19. #  With this script you can make map icon commands which will call an common
  20. #  event if you press it.
  21. #  Look below at the examples to understand how it works.
  22. #
  23. #===============================================================================
  24. module EVG
  25.   module MouseHud
  26.     #--------------------------------------------------------------------------
  27.     Huds = { # Dont touch this line
  28.     #--------------------------------------------------------------------------
  29.    
  30.       #------------------------------------------------------------------------
  31.       :test1 => {
  32.      
  33.         pos_x:        Graphics.width - 2,
  34.         pos_y:        Graphics.height - 26,
  35.         icon:         22,
  36.         hower_text:   "Common Event 2",
  37.        
  38.        
  39.         # take the right corner as reference for the x placing.
  40.         # set this true if you want to place commands at the right site
  41.         invert_x:     true,
  42.        
  43.         # Position of the hower text
  44.         # :right or :left
  45.         hower_pos:    :left,
  46.        
  47.         # Common Event which will be started when you press this Command
  48.         ce_on_click:  2,
  49.       },
  50.      
  51.       #------------------------------------------------------------------------
  52.       :test2 => {
  53.      
  54.         pos_x:        Graphics.width - 2,
  55.         pos_y:        Graphics.height - 52,
  56.         icon:         23,
  57.         hower_text:   "Common Event 1",
  58.        
  59.        
  60.         # take the right corner as reference for the x placing.
  61.         # set this true if you want to place commands at the right site
  62.         invert_x:     true,
  63.        
  64.         # Position of the hower text
  65.         # :right or :left
  66.         hower_pos:    :left,
  67.        
  68.         # Common Event which will be started when you press this Command
  69.         ce_on_click:  1,
  70.       },
  71.       #------------------------------------------------------------------------
  72.      
  73.     #--------------------------------------------------------------------------
  74.     } # Dont touch this line !
  75.     #--------------------------------------------------------------------------
  76.   end
  77. end
  78. #===============================================================================
  79. class Spriteset_Map
  80.   #--------------------------------------------------------------------------
  81.   alias :evg_sm_cp_mhuds        :create_pictures
  82.   #--------------------------------------------------------------------------
  83.   def create_pictures
  84.     evg_sm_cp_mhuds
  85.     @mouse_huds = {}
  86.     EVG::MouseHud::Huds.each do |sym, properties|
  87.       @mouse_huds[sym] = HudSpriteMouse.new(properties, @viewport3)
  88.     end
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   alias :evg_sm_up_mhuds        :update_pictures
  92.   #--------------------------------------------------------------------------
  93.   def update_pictures
  94.     evg_sm_up_mhuds
  95.     @mouse_huds.values.compact.each(&:update) if @mouse_huds
  96.   end
  97.   #--------------------------------------------------------------------------
  98. end
  99. #===============================================================================
  100. class HudSpriteMouse < Sprite
  101.   #--------------------------------------------------------------------------
  102.   def initialize(command, viewport = nil)
  103.     super(viewport)
  104.     self.x = command[:pos_x]
  105.     self.y = command[:pos_y]
  106.     @icon_index = command[:icon]
  107.     @hower_text = command[:hower_text]
  108.     @common_event_id = command[:ce_on_click]
  109.     @pos    = command[:hower_pos]
  110.     @need_clean = true
  111.     create_bitmap
  112.     adjust_position if command[:invert_x]
  113.     refresh
  114.   end
  115.   def adjust_position
  116.     self.x -= self.bitmap.width
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   def create_bitmap
  120.     self.bitmap = Bitmap.new(24, 24)
  121.     width_plus = self.bitmap.text_size(@hower_text).width
  122.     self.bitmap.dispose
  123.     self.bitmap = Bitmap.new(24 + width_plus + 4, 24)
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   def refresh
  127.     self.bitmap.clear
  128.     draw_icon(@icon_index, icon_x, 0)
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   def update
  132.     if mouse_hower?
  133.       proccess_common_event if Mouse.trigger?(0)
  134.       return if @need_clean
  135.       $mouse.ignored = true
  136.       refresh
  137.       self.bitmap.draw_text(text_x, 0, self.bitmap.width - 26, 24, @hower_text)
  138.       @need_clean = true
  139.     elsif @need_clean
  140.       $mouse.ignored = false
  141.       refresh
  142.       @need_clean = false
  143.     end
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   def icon_x
  147.     @pos == :right ? 0 : self.bitmap.width - 24
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   def text_x
  151.     @pos == :right ? 26 : 0
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   def proccess_common_event
  155.     $game_temp.reserve_common_event(@common_event_id)
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   def mouse_hower?
  159.     return false if $game_message.visible
  160.     (hower_x..(hower_x + 24)).include?(Mouse.pos[0]) &&
  161.     (self.y..(self.y + 24)).include?(Mouse.pos[1])
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   def hower_x
  165.     @pos == :right ? self.x : self.x + self.bitmap.width - 24
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   def draw_icon(icon_index, x, y)
  169.     bitmap = Cache.system("Iconset")
  170.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  171.     self.bitmap.blt(x, y, bitmap, rect)
  172.   end
  173.   #--------------------------------------------------------------------------
  174. end
  175. #===============================================================================
  176. # SCRIPT END
  177. #===============================================================================
RAW Paste Data