Advertisement
mephistox

Meph's Mouse Selectable Windows

Jan 30th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.71 KB | None | 0 0
  1. #==============================================================================
  2. # ** Meph's Mouse System
  3. #    Plugin: Selectable Windows by Mouse
  4. #------------------------------------------------------------------------------
  5. # MephistoX
  6. # Version 1.0
  7. # 01-31-2015
  8. #------------------------------------------------------------------------------
  9. # * Version History :
  10. #
  11. #   Version 1 ---------------------------------------------------- (01-31-2015)
  12. #     - Log : First Version Released
  13. #------------------------------------------------------------------------------
  14. # * Requirements :
  15. #
  16. #   - LoadSo Ruby Extension Module
  17. #   - FyxInput v1.0
  18. #   - FyxInput ADDON - Mouse Sprite v1.0  
  19. #------------------------------------------------------------------------------
  20. # * Description :
  21. #
  22. #   Intented to be a plugin of my Mouse system, now as a Stand-Alone, this
  23. #   script allow you to use the mouse to control the windows.
  24. #   Work with horizontal and Vertical Selectable types of window and also
  25. #   with the arrows for vertical windows that need to display more content.
  26. #  
  27. #
  28. #   This Script uses the FenixFyreX Input System, just because at the moment
  29. #   is the best Input System out there, easy to control and because already
  30. #   included the cursor sprite by default.
  31. #------------------------------------------------------------------------------
  32. # * To Do
  33. #  
  34. #   The script doesn't work with the following scenes:
  35. #     - Scene Name Input
  36. #     - Scene Save and Load
  37. #     - Number Input
  38. #
  39. #   Of Course I'm Working in that, but by now, enjoy this!.
  40. #
  41. #------------------------------------------------------------------------------
  42. # * Instructions :
  43. #
  44. #   Place The Script Above Main as Usual
  45. #   Plug & Play
  46. #------------------------------------------------------------------------------
  47. # * Syntax :
  48. #------------------------------------------------------------------------------
  49. # * Terms & Conditions:
  50. #
  51. #   ** Made by MephistoX
  52. #==============================================================================
  53.  
  54. #==============================================================================
  55. # ** Window_Selectable
  56. #==============================================================================
  57.  
  58. class Window_Selectable
  59.   #--------------------------------------------------------------------------
  60.   # * Alias Listing
  61.   #--------------------------------------------------------------------------
  62.   alias_method :meph_mousesys_winselec_update, :update
  63.   alias_method :meph_mousesys_winselec_prhand, :process_handling
  64.   #--------------------------------------------------------------------------
  65.   # * Frame Update
  66.   #--------------------------------------------------------------------------
  67.   def update
  68.     # The Usual
  69.     meph_mousesys_winselec_update
  70.     # Update Mouse Selectable
  71.     update_mouse_cursor
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * Get Array of Shown Elements
  75.   #--------------------------------------------------------------------------
  76.   def shown_elements
  77.     ((top_row * col_max)...(page_item_max * (top_row + 1))).to_a
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * Visible Option? : Check if Item to check is visible (Based on Contents)
  81.   #--------------------------------------------------------------------------
  82.   def visible_option?(item)
  83.     shown_elements.include?(item)
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # * Relative Index : Get Relative Index
  87.   #--------------------------------------------------------------------------
  88.   def relative_index(check_index)
  89.     shown_elements[check_index]
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # * Get Rectangle for Drawing Items at Window Position
  93.   #--------------------------------------------------------------------------
  94.   def window_item_rect(index)
  95.     rect = item_rect(index)
  96.     rect.x += (x + 12) # Cursor offset adjustement
  97.     rect.y += (y + 12) # Cursor offset adjustement
  98.     rect
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # * Visible Rects : Get Visible Rects for Window (Based on window Size)
  102.   #--------------------------------------------------------------------------
  103.   def visible_rects
  104.     # If No Elements in selectable window Set Dummy Rect
  105.     return rects = [window_item_rect(0)] if item_max == 0
  106.     # Set Rects Array
  107.     rects = []
  108.     # Do Max Items per Page, add rect
  109.     [page_item_max, item_max].min.times do |rect|
  110.       rects << window_item_rect(rect)
  111.     end
  112.     # Return Rects
  113.     rects
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   # * Update Mouse Cursor
  117.   #--------------------------------------------------------------------------
  118.   def update_mouse_cursor
  119.     # Do Nothing if not open or not active
  120.     return unless cursor_movable?
  121.     # Set Last Index
  122.     last_index = @index
  123.     # If Mouse within Bottom Arrow Rectangle
  124.     if Mouse.within?(Rect.new(x + (width / 2) - 12, y + height - 12, 16, 16))
  125.       # If Left Click Cursor Down
  126.       cursor_down if Mouse.lclick?
  127.     end
  128.     # If Mouse within Bottom Arrow Rectangle
  129.     if Mouse.within?(Rect.new(x + (width / 2) - 12, y, 16, 16))
  130.       # If Left Click Cursor Down
  131.       cursor_up if Mouse.lclick?
  132.     end
  133.     # Pass Through Each Item Index
  134.     visible_rects.each_with_index do |rect, item_i|
  135.       # If Mouse is within Item Index Rect
  136.       if Mouse.within?(rect)
  137.         # Return if current index is same as relative index
  138.         return if @index == shown_elements[item_i]
  139.         # Return if last element (blank) is greater or equal to Item Max
  140.         return if shown_elements[item_i] >= item_max
  141.         # Select Relative Index
  142.         select(shown_elements[item_i])
  143.       end
  144.     end
  145.     # Play Cursor if Index was Changed
  146.     Sound.play_cursor if @index != last_index
  147.   end
  148.   #--------------------------------------------------------------------------
  149.   # * Handling Processing for OK and Cancel Etc.
  150.   #--------------------------------------------------------------------------
  151.   def process_handling
  152.     # Get to Mouse Process Handling
  153.     mouse_process_handling
  154.     # The Usual
  155.     meph_mousesys_winselec_prhand
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # * Handling Processing for OK and Cancel Etc.
  159.   #--------------------------------------------------------------------------
  160.   def mouse_process_handling
  161.     # Return if not open or not active
  162.     return unless open? && active
  163.     # If Ok Enabled & Mouse Left Click
  164.     if ok_enabled? && Mouse.lclick?
  165.       # If Mouse within Item Rects
  166.       if Mouse.within?(visible_rects[shown_elements.index(index)])
  167.         # OK Process
  168.         return process_ok
  169.       end
  170.     end
  171.     # If Cancel Enabled &  Right Click
  172.     if cancel_enabled? && Mouse.rclick?
  173.       # Cancel Process
  174.       return process_cancel
  175.     end
  176.   end
  177. end
  178.  
  179. #==============================================================================
  180. # ** Window_Message
  181. #==============================================================================
  182.  
  183. class Window_Message
  184.   #--------------------------------------------------------------------------
  185.   # * Input Pause Processing
  186.   #--------------------------------------------------------------------------
  187.   def input_pause
  188.     self.pause = true
  189.     wait(10)
  190.     # Check Until B, C, Left or Right Click Triggered
  191.     until (Input.trigger?(:B) || Input.trigger?(:C) || Mouse.lclick? ||
  192.       Mouse.rclick?)
  193.       # Pause
  194.       Fiber.yield
  195.     end
  196.     # Update Input
  197.     Input.update
  198.     # Pause OFF
  199.     self.pause = false
  200.   end
  201. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement