Project1
标题:
再次请教关于鼠标脚本
[打印本页]
作者:
白鬼
时间:
2009-7-26 22:24
标题:
再次请教关于鼠标脚本
本帖最后由 白鬼 于 2009-7-27 01:08 编辑
我用了鼠标脚本,
如何判断 按钮Mouse::LBUTTON 被按下?
我还是想应用到条件分歧里面
但是试了几个都不好使。
如果条件分歧里面无法应用,可否用事件脚本来判断,当Mouse::LBUTTON被按下,返还Input::C 键被按下,然后再条件分歧C键被按下怎样怎样~~
鼠标脚本核心部分
unless defined? Mouse
#==============================================================================
# ■ Mouse
#------------------------------------------------------------------------------
# 鼠标核心模块。 v1.0 by 灼眼的夏娜
#==============================================================================
module Mouse
#--------------------------------------------------------------------------
# ● DLL名
#--------------------------------------------------------------------------
DLL = "DLL/mouse"
#--------------------------------------------------------------------------
# ● 按键常量
#--------------------------------------------------------------------------
LBUTTON = 0x01
RBUTTON = 0x02
MBUTTON = 0x04
#--------------------------------------------------------------------------
# ● API函数声明
#--------------------------------------------------------------------------
MOUSE_INIT = Win32API.new(DLL,"_mouse_init","v","i")
MOUSE_EXIT = Win32API.new(DLL,"_mouse_exit","v","v")
MOUES_GET_POS = Win32API.new(DLL,"_mouse_get_pos","p","v")
MOUSE_SET_POS = Win32API.new(DLL,"_mouse_set_pos","ll","v")
MOUSE_GET_WHEEL = Win32API.new(DLL,"_mouse_get_wheel","v","i")
MOUSE_IS_OVER = Win32API.new(DLL,"_mouse_is_over","v","i")
GET_KEY_STATE = Win32API.new(DLL,"_get_key_state","i","i")
KEY_DOWN = Win32API.new(DLL,"_key_down","i","i")
KEY_UP = Win32API.new(DLL,"_key_up","i","i")
MOUSE_UPDATE = Win32API.new(DLL,"_mouse_update","v","v")
CLEAR_QUEUE = Win32API.new(DLL,"_clear_queue","v","v")
#--------------------------------------------------------------------------
# ● 鼠标系统启动
#--------------------------------------------------------------------------
def self.start
finish
@spr_cursor = Sprite.new
@spr_cursor.visible = false
@spr_cursor.bitmap = RPG::Cache.icon("cursor.png")
@spr_cursor.z = 99999
@mx = 0
@my = 0
@l_last_pressed = @l_pressed = false
@r_last_pressed = @r_pressed = false
@wheel = 0
raise "Init Mouse System Error..." if MOUSE_INIT.call != 0
end
#--------------------------------------------------------------------------
# ● 返回鼠标位置
#--------------------------------------------------------------------------
def self.pos
return @mx,@my
end
#--------------------------------------------------------------------------
# ● 鼠标系统结束
#--------------------------------------------------------------------------
def self.finish
if @spr_cursor != nil
@spr_cursor.bitmap.dispose
@spr_cursor.dispose
@spr_cursor = nil
@mx = 0
@my = 0
@l_last_pressed = @l_pressed = false
@r_last_pressed = @r_pressed = false
@wheel = 0
MOUSE_EXIT.call
end
end
#--------------------------------------------------------------------------
# ● 键按下?
#--------------------------------------------------------------------------
def self.key_down(key)
return KEY_DOWN.call(key) != 0
end
#--------------------------------------------------------------------------
# ● 键弹起?
#--------------------------------------------------------------------------
def self.key_up(key)
return KEY_UP.call(key) != 0
end
#--------------------------------------------------------------------------
# ● 连续按键?
#--------------------------------------------------------------------------
def self.press?(key)
case key
when LBUTTON
return @l_pressed
when RBUTTON
return @r_pressed
else
return false
end
end
#--------------------------------------------------------------------------
# ● 等同于:key_down
#--------------------------------------------------------------------------
def self.trigger?(key)
return key_down(key)
end
#--------------------------------------------------------------------------
# ● 滚动中?
#--------------------------------------------------------------------------
def self.scroll?
return @wheel != 0
end
#--------------------------------------------------------------------------
# ● 向上滚动?
#--------------------------------------------------------------------------
def self.scroll_up?
return @wheel > 0
end
#--------------------------------------------------------------------------
# ● 向下滚动?
#--------------------------------------------------------------------------
def self.scroll_down?
return @wheel < 0
end
#--------------------------------------------------------------------------
# ● 滚轮计数
#--------------------------------------------------------------------------
def self.scroll
return @wheel
end
#--------------------------------------------------------------------------
# ● 更新
#--------------------------------------------------------------------------
def self.update
MOUSE_UPDATE.call
pt = [0,0].pack("ll")
MOUES_GET_POS.call(pt)
@mx,@my = pt.unpack("ll")
@l_last_pressed = @l_pressed
@l_pressed = GET_KEY_STATE.call(LBUTTON) != 0
@r_last_pressed = @r_pressed
@r_pressed = GET_KEY_STATE.call(RBUTTON) != 0
@wheel = MOUSE_GET_WHEEL.call
@spr_cursor.x = @mx
@spr_cursor.y = @my
@spr_cursor.visible = MOUSE_IS_OVER.call != 0
end
#--------------------------------------------------------------------------
# ● 清空队列
#--------------------------------------------------------------------------
def self.clear_queue
CLEAR_QUEUE.call
end
end
#==============================================================================
# ■ Graphics
#------------------------------------------------------------------------------
# 图象模块,添加鼠标支持。
#==============================================================================
class << Graphics
alias origin_update update
def update
Mouse.clear_queue
origin_update
Mouse.update
end
end
#==============================================================================
# ■ Input
#------------------------------------------------------------------------------
# 按键输入模块,添加鼠标支持。
#==============================================================================
class << Input
alias origin_trigger? trigger?
def trigger?(key)
if origin_trigger?(key)
return true
end
case key
when Input::C
return Mouse.key_down(Mouse::LBUTTON)
when Input::B
return Mouse.key_down(Mouse::RBUTTON)
else
return false
end
end
end
end
Mouse.start
复制代码
鼠标脚本实现部分
class Window_Selectable
if @self_alias == nil
alias self_update update
@self_alias = true
end
def update
#self.cursor_rect.empty
self_update
if self.active and @item_max > 0
index_var = @index
tp_index = @index
mouse_x, mouse_y = Mouse.pos
mouse_not_in_rect = true
for i in 0...@item_max
@index = i
update_cursor_rect
top_x = self.cursor_rect.x + self.x + 16
top_y = self.cursor_rect.y + self.y + 16
bottom_x = top_x + self.cursor_rect.width
bottom_y = top_y + self.cursor_rect.height
if (mouse_x > top_x) and (mouse_y > top_y) and
(mouse_x < bottom_x) and (mouse_y < bottom_y)
mouse_not_in_rect = false
if tp_index != @index
tp_index = @index
$game_system.se_play($data_system.cursor_se)
end
break
end
end
if mouse_not_in_rect
@index = index_var
if Mouse.scroll_up?
# 光标向上移动
$game_system.se_play($data_system.cursor_se)
@index = (@index - @column_max + @item_max) % @item_max
end
if Mouse.scroll_down?
# 光标向上移动
$game_system.se_play($data_system.cursor_se)
@index = (@index + @column_max) % @item_max
end
update_cursor_rect
#Mouse.click_lock
else
#Mouse.click_unlock
end
end
end
end
复制代码
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1