简易鼠标模块VA移植版
原帖:(6R卡住,待填充)这次只是移植到VA了……
几乎没什么改动……
所以我闲得蛋疼把标识符全改成小写了……
使用方法:自己看脚本注释懒得再写了=-=
(关于FSL啥的我什么都不知道{:nm06:} )
#===============================================================================
# ■ 简易鼠标输入VA移植版
# EasyMouseInput
#-------------------------------------------------------------------------------
# click? :返回是否左键单击
# rightclick? :返回是否右键单击
# down? :返回是否左键单击
# rightdown? :返回是否左键单击
# getx :返回鼠标的画面X坐标
# gety :返回鼠标的画面Y坐标
# getdragrect :返回鼠标拖动形成的方框,格式为Rect
# 27~43行为设定,请根据游戏实际情况更改
#-------------------------------------------------------------------------------
# 更新作者: ⑨
# VA移植:satgo1546(其实根本没改多少)
# 许可协议: FSL
#===============================================================================
$fscript = {} if $fscript == nil
$fscript["EasyMouseInput"] = "1.0.0000"
#-------------------------------------------------------------------------------
# ▼ 通用配置模块
#-------------------------------------------------------------------------------
module FSL
module EasyMouseConfig
# 窗口大小,不用修改
WINDOW_X = Graphics.width
WINDOW_Y = Graphics.height
# 鼠标左键和右键点击的SE
CLICK_AUDIO_PATH = nil
R_CLICK_AUDIO_PATH = nil
# 鼠标是否限制在窗口中不能移动
MOUSE_IN_RECT = false
# 用图片代替鼠标指针
SHOW_MOUSE_IMAGE = true
# 鼠标图形路径
# 会读取这个路径下的MouseN、MouseL、MouseR图片,分别代表普通、左键/右键按下
MOUSE_IMAGE_PATH = "Graphics/System/"
end
end
# API =========================================================================
$show_cursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
$get_cursor_pos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
$screen_to_client = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
$get_active_window = Win32API.new("user32", "GetActiveWindow", nil, 'l')
$screen_to_client = Win32API.new("user32", "ScreenToClient", 'lp', 'l')
$clip_cursor = Win32API.new("user32", "ClipCursor", 'p', 'l')
$get_async_key_state = Win32API.new("user32", "GetAsyncKeyState", 'l', 'i')
$hwnd = $get_active_window.call()
#==============================================================================
# ■ Mouse
#------------------------------------------------------------------------------
#处理响应鼠标的模块
#==============================================================================
module Mouse
include (FSL::EasyMouseConfig)
attr_accessor :mousex
attr_accessor :mousey
attr_accessor :click
attr_accessor :rightclick
attr_accessor :downflag
attr_accessor :rightdownflag
attr_accessor :dragrect
attr_accessor :dragrect_x_1
attr_accessor :dragrect_x_2
attr_accessor :dragrect_y_1
attr_accessor :dragrect_y_2
$show_cursor.call(0) if SHOW_MOUSE_IMAGE
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def self.update
getmouselocation
setmouserect if FSL::EasyMouseConfig::MOUSE_IN_RECT
@click = mouseclickjudge
@rightClick = mouserightclickjudge
end
#--------------------------------------------------------------------------
# ● 判断鼠标左键点击
#--------------------------------------------------------------------------
def self.click?
return @click
end
#--------------------------------------------------------------------------
# ● 判断鼠标右键点击
#--------------------------------------------------------------------------
def self.rightclick?
return @rightclick
end
#--------------------------------------------------------------------------
# ● 判断鼠标左键正按下
#--------------------------------------------------------------------------
def self.down?
if @downflag == 1
return true
else
return false
end
end
#--------------------------------------------------------------------------
# ● 判断鼠标右键正按下
#--------------------------------------------------------------------------
def self.rightdown?
if @rightdownflag == 1
return true
else
return false
end
end
#--------------------------------------------------------------------------
# ● 获取鼠标X
#--------------------------------------------------------------------------
def self.getx
return @mousex
end
#--------------------------------------------------------------------------
# ● 获取鼠标Y
#--------------------------------------------------------------------------
def self.gety
return @mousey
end
#--------------------------------------------------------------------------
# ● 获取鼠标拖动矩形
#--------------------------------------------------------------------------
def self.getdragrect
return dragrect
end
#--------------------------------------------------------------------------
# ● 单击鼠标
#--------------------------------------------------------------------------
def self.mouseclickjudge
result = $get_async_key_state.call(0x01)
if @downflag == 0 && result != 0
@dragrect_x_1 = @mousex
@dragrect_y_1 = @mousey
@dragrect = Rect.new(0, 0, 0, 0)
end
if @downflag == 1 && result == 0
@dragrect_x_2 = @mousex
@dragrect_y_2 = @mousey
setdragrect
end
if @downflag == 1 && result != 0
return false
end
if result != 0
@downflag = 1
Audio.se_play(CLICK_AUDIO_PATH) if CLICK_AUDIO_PATH != nil
return true
else
@downflag = 0
return false
end
end
#--------------------------------------------------------------------------
# ● 右击鼠标
#--------------------------------------------------------------------------
def self.mouserightclickjudge
result = $get_async_key_state.call(0x02)
if @rightdownflag == 1 && result != 0
return false
end
if result != 0
@rightdownflag = 1
Audio.se_play(R_CLICK_AUDIO_PATH) if R_CLICK_AUDIO_PATH != nil
return true
else
@rightdownflag = 0
return false
end
end
#--------------------------------------------------------------------------
# ● 把鼠标限制在窗口中
#--------------------------------------------------------------------------
def self.setmouserect
w = .pack("ll")
$screen_to_client.call($hwnd, w)
w = w.unpack("ll")
x = w
y = w
$clip_cursor.call([-x, -y, -x+WINDOW_X, -y+WINDOW_Y].pack('llll'))
end
#--------------------------------------------------------------------------
# ● 获取鼠标在屏幕中的位置
#--------------------------------------------------------------------------
def self.getmouselocation
c =
c = c.pack("ll")
$get_cursor_pos.call(c)
c = c.unpack("ll")
w = .pack("ll")
$screen_to_client.call($hwnd, w)
w = w.unpack("ll")
@mousex = c + w
@mousey = c + w
end
#--------------------------------------------------------------------------
# ● 获取鼠标拖动的矩形
#--------------------------------------------------------------------------
def self.setdragrect
@dragrect = Rect.new(0, 0, 0, 0)
if @dragrect_x_1 >= @dragrect_x_2
@dragrect.x = @dragrect_x_2
@dragrect.width = @dragrect_x_1 - @dragrect_x_2
else
@dragrect.x = @dragrect_x_1
@dragrect.width = @dragrect_x_2 - @dragrect_x_1
end
if @dragrect_y_1 >= @dragrect_y_2
@dragrect.y = @dragrect_y_2
@dragrect.height = @dragrect_y_1 - @dragrect_y_2
else
@dragrect.y = @dragrect_y_1
@dragrect.height = @dragrect_y_2 - @dragrect_y_1
end
end
end
#==============================================================================
# ■ Scene_Base
#------------------------------------------------------------------------------
# 游戏中全部画面的超级类。
#==============================================================================
class Scene_Base
include (FSL::EasyMouseConfig)
alias start_easy_mouse_input start
def start
start_easy_mouse_input
if SHOW_MOUSE_IMAGE
@mouse_sprite = Sprite.new
@mouse_bitmap = []
@mouse_bitmap = Bitmap.new(MOUSE_IMAGE_PATH + "MouseN")
@mouse_bitmap = Bitmap.new(MOUSE_IMAGE_PATH + "MouseL")
@mouse_bitmap = Bitmap.new(MOUSE_IMAGE_PATH + "MouseR")
@mouse_sprite.bitmap = @mouse_bitmap_1
@mouse_sprite.ox = @mouse_sprite.oy = 4
@mousebitmapindex = 0
@mouse_sprite.z = 70000
end
end
alias termin_easy_mouse_input terminate
def terminate
termin_easy_mouse_input
if SHOW_MOUSE_IMAGE
@mouse_sprite.dispose
@mouse_sprite.bitmap.dispose
end
end
alias upd_easy_mouse_input update
def update
upd_easy_mouse_input
Mouse.update
if SHOW_MOUSE_IMAGE
@mouse_sprite.x = Mouse.getx
@mouse_sprite.y = Mouse.gety
if Mouse.down?
newindex = 2
elsif Mouse.rightdown?
newindex = 3
else
newindex = 1
end
if @mousebitmapindex != newindex
@mousebitmapindex = newindex
@mouse_sprite.bitmap = @mouse_bitmap[@mousebitmapindex]
end
end
end
end Win32api神马的最讨厌了 呵呵。
页:
[1]