Project1
标题:
关于键盘位锁定的问题
[打印本页]
作者:
云海尘清
时间:
2016-5-17 22:25
标题:
关于键盘位锁定的问题
我想通过某个环节,暂时将方向键的某个键锁定起来,就是说暂时但某键无效。
例如锁定左键,除非解除锁定,不然在地图中按左键无反应。
希望能用事件脚本控制锁定与否,希望能同时锁定多键。
谢谢。
作者:
英顺的马甲
时间:
2016-5-18 00:23
Input.module_eval do
if !@orig_methods
@orig_methods = {}
@locks = []
Input.methods.each{|m|@orig_methods[m] = Input.method(m)}
["trigger?", "press?", "repeat?"].each do |m|
define_method(m) do |k|
@locks.include?(k) ? false : @orig_methods[m].call(k)
end
module_function m
public m
end
define_method('dir4') do
@locks.include?(k = @orig_methods['dir4'].call) ? 0 : k
end
define_method('dir8') do
k = @orig_methods['dir8'].call
return 0 if [2, 4, 6, 8].any?{|d|@locks.include?(d) and k == d}
case k
when 1
return 0 if @locks.include?(2) and @locks.include?(4)
return 4 if @locks.include?(2)
return 2 if @locks.include?(4)
when 3
return 0 if @locks.include?(2) and @locks.include?(6)
return 6 if @locks.include?(2)
return 2 if @locks.include?(6)
when 7
return 0 if @locks.include?(8) and @locks.include?(4)
return 4 if @locks.include?(8)
return 8 if @locks.include?(4)
when 9
return 0 if @locks.include?(6) and @locks.include?(8)
return 8 if @locks.include?(6)
return 6 if @locks.include?(8)
end
return k
end
define_method('lock') do |*args|
@locks |= args
@locks.sort!
end
define_method('unlock') do |*args|
args.each{|k|@locks.delete(k)}
end
module_function :dir4, :dir8, :lock, :unlock
public :dir4, :dir8, :lock, :unlock
end
end
复制代码
上面的插入main之前,下面的是例子,教程范例啥的懒得弄
# 禁用上和右
Input.lock Input::DOWN, Input::RIGHT
# 解禁
Input.unlock Input::DOWN, Input::RIGHT
复制代码
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1