08-30-2023, 07:19 PM (This post was last modified: 08-30-2023, 07:21 PM by DerVVulfman.)
MKXP COMPATIBLE MOUSE ADD-on
<not an RPGMaker XP script but close> Version: 1.0
Introduction
MKXP, a replacement engine for RPGMaker XP, has built-in content to support mouse input. But it does not attach mouse input to the input class, generate a mouse cursor, nor deal with highlighting of menu options by way of the mouse. This script is a skeleton for users of MKXP or latter additions of HiddenChest (at least tested with 64bit Windows).
Features
Allows a new Graphics\Mouse folder for cashing the cursor
Creates a new Sprite_Mouse class for generating the mouse cursor
Tracks the mouse within the Window_Selectable class for simple menu use
Adds Left-Click for Input::C (Decision)
Adds Right-Click for Input::B (Cancel)
Adds Middle-Click for Input::A (um... up to you)
Shows simple means to add mouse control to any Scene_ code instances
Screenshots
A screenshot? It would show just a mouse cursor IN the game window.
Script
"script"
Code:
#==============================================================================
# ** MKXP Compatible Mouse Add-on
#------------------------------------------------------------------------------
# by DerVVulfman
# Version 1.0 (2023/08/30) YYYY/MM/DD
# MKXP / HiddenChest 1.1.49 Windows 64bit compatible
#==============================================================================
#==============================================================================
# ** Input
#------------------------------------------------------------------------------
# A module that handles input data from a gamepad or keyboard. This update
# adds mouse input by using class commands to attach its functionality.
#==============================================================================
class << Input
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias old_trigger? trigger? unless $@
#--------------------------------------------------------------------------
# * Trigger command
# num : Button ID number being tested
#--------------------------------------------------------------------------
def trigger?(num)
case num
when Input::A ; # Tertiary option
return (old_trigger?(num) or old_trigger?(Input::MOUSEMIDDLE))
when Input::B ; # Traditional cancel option
return (old_trigger?(num) or old_trigger?(Input::MOUSERIGHT))
when Input::C ; # Traditional decision option
return (old_trigger?(num) or old_trigger?(Input::MOUSELEFT))
end
end
end
#==============================================================================
# ** RPG::Cache
#------------------------------------------------------------------------------
# Data class that handles the creation and retention of bitmaps within the
# RPG module.
#==============================================================================
module RPG::Cache
#--------------------------------------------------------------------------
# * Load Cached Resource (mouse)
# filename : filename
#--------------------------------------------------------------------------
def self.mouse(filename)
self.load_bitmap("Graphics/Mouse/", filename)
end
end
#==============================================================================
# ** Sprite_Mouse
#------------------------------------------------------------------------------
# This sprite is used to display the mouse.
#==============================================================================
class Sprite_Mouse < RPG::Sprite
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
#--------------------------------------------------------------------------
def initialize
super
update_icon_bitmap("Arrow")
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
if self.bitmap != nil
self.bitmap.dispose
end
super
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
self.x = Input.mouse_x
self.y = Input.mouse_y
self.z = 200
update_icon
end
#--------------------------------------------------------------------------
# * Frame Update (When detecting if mouse over map event)
#--------------------------------------------------------------------------
def update_icon
return unless $scene.is_a?(Scene_Map)
return if $game_map.scrolling? or $game_player.moving?
update_icon_bitmap("Arrow")
end
#--------------------------------------------------------------------------
# * Frame Update (When changing mouse cursor)
#--------------------------------------------------------------------------
def update_icon_bitmap(mouse_cursor)
cursor = mouse_cursor
return if @old_cursor == cursor
@old_cursor = cursor
self.bitmap = RPG::Cache.mouse(cursor)
end
end
# Just add the mouse globally
$mouse_sprite = Sprite_Mouse.new
#==============================================================================
# ** Window_Selectable
#------------------------------------------------------------------------------
# This window class contains cursor movement and scroll functions.
#==============================================================================
class Window_Selectable < Window_Base
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias mkxp_mouse_selectable_initialize initialize
alias mkxp_mouse_selectable_update_cursor_rect update_cursor_rect
#--------------------------------------------------------------------------
# * Object Initialization
# x : window x-coordinate
# y : window y-coordinate
# width : window width
# height : window height
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
# Perform the original method with all window dimensions
mkxp_mouse_selectable_initialize(x, y, width, height)
# Add a minor scroll-wait value
@scroll_wait = 0
end
#--------------------------------------------------------------------------
# * Update Cursor Rectangle
#--------------------------------------------------------------------------
def update_cursor_rect
# Perform the original method
mkxp_mouse_selectable_update_cursor_rect
# Include mouse tracking operations
mouse_operation
end
#--------------------------------------------------------------------------
# * Perform mouse operations
#--------------------------------------------------------------------------
def mouse_operation
# Update the mouse
$mouse_sprite.update
# Acquire the mouse position in relation to menu position and 16px border
mx = Input.mouse_x - (self.x - self.ox + 16)
my = Input.mouse_y - (self.y - self.oy + 16)
# Define width and height
width = self.width / @column_max - 32
height = self.cursor_rect.height
# Cycle through items until mouse position detected
for index in 0...@item_max
x = index % @column_max * (width + 32)
y = index / @column_max * height
# Define mouse placement and exit when mouse position detected
if mx > x and mx < x + width and my > y and my < y + height
mouse_cursor(index)
break
end
end
end
#--------------------------------------------------------------------------
# * Track the position of the mouse cursor
#--------------------------------------------------------------------------
def mouse_cursor(index)
# Ignore if repeat
return if @index == index
@scroll_wait -= 1 if @scroll_wait > 0
row1 = @index / @column_max
row2 = index / @column_max
bottom = self.top_row + (self.page_row_max - 1)
if row1 == self.top_row and row2 < self.top_row
return if @scroll_wait > 0
@index = [@index - @column_max, 0].max
@scroll_wait = 4
elsif row1 == bottom and row2 > bottom
return if @scroll_wait > 0
@index = [@index + @column_max, @item_max - 1].min
@scroll_wait = 4
else
@index = index
end
$game_system.se_play($data_system.cursor_se)
end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs title screen processing.
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias mkxp_mouse_scene_update update
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Include mouse tracking operations
$mouse_sprite.update
# Perform the original method
mkxp_mouse_scene_update
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias mkxp_mouse_scene_update update
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Include mouse tracking operations
$mouse_sprite.update
# Perform the original method
mkxp_mouse_scene_update
end
end
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
# This class performs menu screen processing.
#==============================================================================
class Scene_Menu
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias mkxp_mouse_scene_update update
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Include mouse tracking operations
$mouse_sprite.update
# Perform the original method
mkxp_mouse_scene_update
end
end
Instructions
Generally, place this below Scene_Debug and above Main for this to work if you are using a generic RPGMaker XP set of scripts.
REQUIRES: You include a .png file named "Arrow" within a new Graphics\Mouse folder
FAQ
This is stripped down from other work that I have, made primarily to test different MKXP-based engines.
Compatibility
Not for RPGMaker XP, but compatible MKXP based engines. Earlier HiddenChest engines such as HiddenChest Hires has issues.
Credits and Thanks
Ancurio for MKXP, Kyonides for HiddenChest, and Melana for retaining HiddenChest Hires edition.
Terms and Conditions
Free for use.... PERIOD!
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
OK, this sounds like a good idea for making it easy to treat mouse clicks like your typical OK and Cancel buttons in RPG Maker. I just find it unfair. Nope, it's not jealousy speaking here. Actually, it's all about accessibility. The people which for any given reason need to use their left hand the way most of us use our right hand, could end up feeling slightly discriminated here. It doesn't offer a way to adapt it to their circumstances.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.