Advertisement
F117Landers

(SSMS) Mouse 2

Jul 9th, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.39 KB | None | 0 0
  1. #==============================================================================
  2. # ** MouseCursor
  3. #==============================================================================
  4.  
  5. module MouseCursor    
  6.     Default_Cursor = 'Arrow'    
  7.     Event_Cursor   = 'Arrow3'    
  8.     Actor_Cursor   = 'Arrow'    
  9.     Enemy_Cursor   = 'Arrow4'    
  10.  
  11.     Item_Cursor    = true    
  12.     Skill_Cursor   = true    
  13.     Dummy = Bitmap.new(32, 32)
  14. end
  15.  
  16. #==============================================================================
  17. # ** Sprite_Mouse
  18. #==============================================================================
  19.  
  20. class Sprite_Mouse < Sprite  
  21.     #--------------------------------------------------------------------------  
  22.     # * Object Initialization  
  23.     #--------------------------------------------------------------------------  
  24.     def initialize    
  25.         super    
  26.         self.z = 10100    
  27.         self.ox = 4    
  28.         update  
  29.     end  
  30.     #--------------------------------------------------------------------------  
  31.     # ** Frame Update  
  32.     #--------------------------------------------------------------------------  
  33.     def update    
  34.         super        
  35.  
  36.         # Update Visibility    
  37.         self.visible = $scene != nil        
  38.        
  39.         # If Visible    
  40.         if self.visible            
  41.            
  42.             # If Non-nil Mouse Position      
  43.             if Mouse.position != nil                
  44.                
  45.                 # Gets Mouse Position        
  46.                 mx, my = *Mouse.position                
  47.                
  48.                 # Update POsition        
  49.                 self.x = mx unless mx.nil?        
  50.                 self.y = my unless my.nil?                    
  51.                
  52.             end            
  53.            
  54.             # If Scene changes or Mouse is Triggered      
  55.             if @scene != $scene.class || Mouse.trigger?                
  56.                
  57.                 # Update Scene Instance        
  58.                 @scene = $scene.class                
  59.                
  60.                 # Update Bitmap        
  61.                 set_bitmap(MouseCursor::Default_Cursor)      
  62.                
  63.             end          
  64.         end      
  65.     end  
  66.     #--------------------------------------------------------------------------  
  67.     # ** Set Bitmap  
  68.     #--------------------------------------------------------------------------  
  69.     def set_bitmap(cursor, xNPCname = nil)        
  70.        
  71.         # show fancy cursor only if custom mouse on    
  72.         if $game_mouse                  
  73.            
  74.             # If Cursor Info matches      
  75.             if (@_cursor == cursor) && (@_NPCname == xNPCname)        
  76.                 return      
  77.             end            
  78.            
  79.             # Reset Cursor Info      
  80.             @_cursor      = cursor      
  81.             @_NPCname     = xNPCname            
  82.            
  83.             # Gets Dummy      
  84.             dummy = MouseCursor::Dummy            
  85.            
  86.             # Gets Item Cursor Bitmap      
  87.             item_cursor = cursor.nil? ? MouseCursor::Default_Cursor : cursor            
  88.            
  89.             # Start Cursor Bitmap      
  90.             bitmap = RPG::Cache.icon(item_cursor) if item_cursor != ''      
  91.            
  92.             # Show NPC name      
  93.             if @_NPCname != nil        
  94.                 # Get name width        
  95.                 w = dummy.text_size(@_NPCname).width        
  96.                 h = dummy.font.size        
  97.                 b = RPG::Cache.icon(item_cursor)        
  98.                 # Create New Bitmap        
  99.                 bitmap = Bitmap.new((bitmap.nil? ? w : 40 + w), [b.height, h + 2].max)        
  100.                 bitmap.font.size = dummy.font.size        
  101.                 bitmap.blt(0, 0, b, b.rect)        
  102.                 # Draw NPC Name        
  103.                 x = item_cursor == '' ? 0 : 32        
  104.                 bitmap.font.color = Color.new(0, 0, 0, 255) # black        
  105.                 bitmap.draw_text(b.width + 9, 0, w, h, @_NPCname) # 0        
  106.                 bitmap.draw_text(b.width + 11, 0, w, h, @_NPCname) # 0        
  107.                 bitmap.draw_text(b.width + 10, -1, w, h, @_NPCname) # -1      
  108.                 bitmap.draw_text(b.width + 10, 1, w, h, @_NPCname) # 1        
  109.                 bitmap.font.color = Color.new(255, 255, 255, 255) # white        
  110.                 bitmap.draw_text(b.width + 10, 0, w, h, @_NPCname)      
  111.             end          
  112.            
  113.             # Set Bitmap      
  114.             self.bitmap = bitmap          
  115.            
  116.         elsif self.bitmap      
  117.             @_cursor = nil      
  118.             self.bitmap = nil          
  119.            
  120.         end      
  121.        
  122.     end  
  123.     #--------------------------------------------------------------------------  
  124.     # ** Frame Update : Update Event Cursors  
  125.     #--------------------------------------------------------------------------  
  126.     def update_event_cursors        
  127.        
  128.         # If Nil Grid Position    
  129.         if Mouse.grid.nil?      
  130.             # Set Default Cursor      
  131.             set_bitmap(MouseCursor::Default_Cursor)      
  132.             return    
  133.         end        
  134.        
  135.         # Gets Mouse Position    
  136.         x, y = *Mouse.grid        
  137.        
  138.         # Gets Mouse Position    
  139.         mx, my = *Mouse.position            
  140.        
  141.         # Gets Mouse Event    
  142.         event = $game_map.event_at(x, y)        
  143.        
  144.         # If Non-Nil Event or not over map HUD    
  145.         unless event.nil?      
  146.             # If Not Erased or Nil List      
  147.             if event.list != nil && event.erased == false && event.list[0].code == 108        
  148.                 # Get the cursor to show        
  149.                 icon = event.list[0].parameters        
  150.                 icon = icon.to_s        
  151.                 if !((icon == "Arrow2") ||            
  152.                     (icon == "Arrow3") ||            
  153.                     (icon == "Arrow4") ||            
  154.                     (icon == "Arrow5") ||            
  155.                     (icon == "Arrow6") ||          
  156.                     (icon == "Arrow7"))          
  157.                     icon = MouseCursor::Default_Cursor        
  158.                 end                
  159.                 xNPCname = nil        
  160.                 if event.list.size > 1 && event.list[1].code == 108          
  161.                     text = event.list[1].parameters.to_s          
  162.                     text.gsub!(/[Nn][Aa][Mm][Ee] (.*)/) do            
  163.                         xNPCname = $1.to_s          
  164.                     end        
  165.                 end        
  166.                 set_bitmap(icon, xNPCname)            
  167.                 return      
  168.             end      
  169.             return    
  170.         end        
  171.            
  172.     # Set Default Cursor    
  173.     set_bitmap(MouseCursor::Default_Cursor)      
  174.  
  175.     end
  176. end
  177.  
  178. #==============================================================================
  179. # ** Input
  180. #==============================================================================
  181. class << Input  
  182.     #------------------------------------------------------------------------  
  183.     # * Alias Listings  
  184.     #------------------------------------------------------------------------  
  185.     unless self.method_defined?(:sephlamchop_mousesys_input_update)    
  186.         alias_method :sephlamchop_mousesys_input_update,   :update  
  187.     end  
  188.     #------------------------------------------------------------------------  
  189.     # * Frame Update  
  190.     #--------------------------------------------------------------------------  
  191.     def update    
  192.         $mouse_sprite.update if $mouse_sprite.visible    
  193.         # Original Update    
  194.         sephlamchop_mousesys_input_update  
  195.     end
  196. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement