Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Meph's Mouse System
- # Plugin: Selectable Windows by Mouse
- #------------------------------------------------------------------------------
- # MephistoX
- # Version 1.0
- # 01-31-2015
- #------------------------------------------------------------------------------
- # * Version History :
- #
- # Version 1 ---------------------------------------------------- (01-31-2015)
- # - Log : First Version Released
- #------------------------------------------------------------------------------
- # * Requirements :
- #
- # - LoadSo Ruby Extension Module
- # - FyxInput v1.0
- # - FyxInput ADDON - Mouse Sprite v1.0
- #------------------------------------------------------------------------------
- # * Description :
- #
- # Intented to be a plugin of my Mouse system, now as a Stand-Alone, this
- # script allow you to use the mouse to control the windows.
- # Work with horizontal and Vertical Selectable types of window and also
- # with the arrows for vertical windows that need to display more content.
- #
- #
- # This Script uses the FenixFyreX Input System, just because at the moment
- # is the best Input System out there, easy to control and because already
- # included the cursor sprite by default.
- #------------------------------------------------------------------------------
- # * To Do
- #
- # The script doesn't work with the following scenes:
- # - Scene Name Input
- # - Scene Save and Load
- # - Number Input
- #
- # Of Course I'm Working in that, but by now, enjoy this!.
- #
- #------------------------------------------------------------------------------
- # * Instructions :
- #
- # Place The Script Above Main as Usual
- # Plug & Play
- #------------------------------------------------------------------------------
- # * Syntax :
- #------------------------------------------------------------------------------
- # * Terms & Conditions:
- #
- # ** Made by MephistoX
- #==============================================================================
- #==============================================================================
- # ** Window_Selectable
- #==============================================================================
- class Window_Selectable
- #--------------------------------------------------------------------------
- # * Alias Listing
- #--------------------------------------------------------------------------
- alias_method :meph_mousesys_winselec_update, :update
- alias_method :meph_mousesys_winselec_prhand, :process_handling
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # The Usual
- meph_mousesys_winselec_update
- # Update Mouse Selectable
- update_mouse_cursor
- end
- #--------------------------------------------------------------------------
- # * Get Array of Shown Elements
- #--------------------------------------------------------------------------
- def shown_elements
- ((top_row * col_max)...(page_item_max * (top_row + 1))).to_a
- end
- #--------------------------------------------------------------------------
- # * Visible Option? : Check if Item to check is visible (Based on Contents)
- #--------------------------------------------------------------------------
- def visible_option?(item)
- shown_elements.include?(item)
- end
- #--------------------------------------------------------------------------
- # * Relative Index : Get Relative Index
- #--------------------------------------------------------------------------
- def relative_index(check_index)
- shown_elements[check_index]
- end
- #--------------------------------------------------------------------------
- # * Get Rectangle for Drawing Items at Window Position
- #--------------------------------------------------------------------------
- def window_item_rect(index)
- rect = item_rect(index)
- rect.x += (x + 12) # Cursor offset adjustement
- rect.y += (y + 12) # Cursor offset adjustement
- rect
- end
- #--------------------------------------------------------------------------
- # * Visible Rects : Get Visible Rects for Window (Based on window Size)
- #--------------------------------------------------------------------------
- def visible_rects
- # If No Elements in selectable window Set Dummy Rect
- return rects = [window_item_rect(0)] if item_max == 0
- # Set Rects Array
- rects = []
- # Do Max Items per Page, add rect
- [page_item_max, item_max].min.times do |rect|
- rects << window_item_rect(rect)
- end
- # Return Rects
- rects
- end
- #--------------------------------------------------------------------------
- # * Update Mouse Cursor
- #--------------------------------------------------------------------------
- def update_mouse_cursor
- # Do Nothing if not open or not active
- return unless cursor_movable?
- # Set Last Index
- last_index = @index
- # If Mouse within Bottom Arrow Rectangle
- if Mouse.within?(Rect.new(x + (width / 2) - 12, y + height - 12, 16, 16))
- # If Left Click Cursor Down
- cursor_down if Mouse.lclick?
- end
- # If Mouse within Bottom Arrow Rectangle
- if Mouse.within?(Rect.new(x + (width / 2) - 12, y, 16, 16))
- # If Left Click Cursor Down
- cursor_up if Mouse.lclick?
- end
- # Pass Through Each Item Index
- visible_rects.each_with_index do |rect, item_i|
- # If Mouse is within Item Index Rect
- if Mouse.within?(rect)
- # Return if current index is same as relative index
- return if @index == shown_elements[item_i]
- # Return if last element (blank) is greater or equal to Item Max
- return if shown_elements[item_i] >= item_max
- # Select Relative Index
- select(shown_elements[item_i])
- end
- end
- # Play Cursor if Index was Changed
- Sound.play_cursor if @index != last_index
- end
- #--------------------------------------------------------------------------
- # * Handling Processing for OK and Cancel Etc.
- #--------------------------------------------------------------------------
- def process_handling
- # Get to Mouse Process Handling
- mouse_process_handling
- # The Usual
- meph_mousesys_winselec_prhand
- end
- #--------------------------------------------------------------------------
- # * Handling Processing for OK and Cancel Etc.
- #--------------------------------------------------------------------------
- def mouse_process_handling
- # Return if not open or not active
- return unless open? && active
- # If Ok Enabled & Mouse Left Click
- if ok_enabled? && Mouse.lclick?
- # If Mouse within Item Rects
- if Mouse.within?(visible_rects[shown_elements.index(index)])
- # OK Process
- return process_ok
- end
- end
- # If Cancel Enabled & Right Click
- if cancel_enabled? && Mouse.rclick?
- # Cancel Process
- return process_cancel
- end
- end
- end
- #==============================================================================
- # ** Window_Message
- #==============================================================================
- class Window_Message
- #--------------------------------------------------------------------------
- # * Input Pause Processing
- #--------------------------------------------------------------------------
- def input_pause
- self.pause = true
- wait(10)
- # Check Until B, C, Left or Right Click Triggered
- until (Input.trigger?(:B) || Input.trigger?(:C) || Mouse.lclick? ||
- Mouse.rclick?)
- # Pause
- Fiber.yield
- end
- # Update Input
- Input.update
- # Pause OFF
- self.pause = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement