设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3041|回复: 0
打印 上一主题 下一主题

[RMVX发布] 鼠标输入模块 修复press判定的bug

[复制链接]

Lv2.观梦者 (管理员)

八云紫的式神

梦石
0
星屑
609
在线时间
1243 小时
注册时间
2008-1-1
帖子
4282

烫烫烫

跳转到指定楼层
1
发表于 2010-6-30 16:15:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
原鼠标输入模块中press判定有bug,以下为修复后的:
  1. #==============================================================================
  2. # ** 鼠标输入模块
  3. #------------------------------------------------------------------------------
  4. #   微调 by zh99998
  5. #   版本 1.2a
  6. #   06-30-2010
  7. #   修复press判定
  8. #   基于沉影的鼠标系统修改版alpha
  9. #------------------------------------------------------------------------------
  10. #   by DerVVulfman
  11. #   版本 1.2
  12. #   08-18-2007
  13. #------------------------------------------------------------------------------
  14. #   建立在鼠标输入模块...
  15. #
  16. #   by Near Fantastica
  17. #------------------------------------------------------------------------------
  18. #   Set_Pos feature by
  19. #   Freakboy
  20. #------------------------------------------------------------------------------
  21. #
  22. #   CALLS:
  23. #
  24. #   Mouse.click?
  25. #   判断鼠标是否真的按下(Ture/False).
  26. #   这个值控制您按下的是左/右键,还是中键

  27. #
  28. #   Mouse.press?
  29. #   判断鼠标是否真的按下/保持按下状态
  30. #   这个值控制您按下的是左/右键,还是中键
  31. #   Mouse.pixels
  32. #   Mouse.pixels
  33. #   这个值返回鼠标所在的坐标(640*480大小),如果鼠标超出游戏画面,这个值为空
  34. #
  35. #   Mouse.tiles
  36. #   This returns  the mouse's screen  coordinates  in map tiles.   Based on the
  37. #   system's 20x15 tile size,  this returns it in index values  (a 0-19 width &
  38. #   a 0-14 height).  This functions the same manner as Mouse.pixels.
  39. #
  40. #   Mouse.set_pos
  41. #   This allows you  to forcefully position the mouse at an x/y position within
  42. #   the game screen by pixel coordinates.  Given the game's normal screen width
  43. #   of 640x480, adding:  Mouse.set_pos(320,240)  should position the mouse dead
  44. #   center of the gaming window.
  45. #
  46. #   Mouse.update
  47. #   Add this routine  into your update routines  to update  the mouse position.
  48. #   It must be called otherwise you won't get valid mouse coordinates.
  49. #
  50. #==============================================================================

  51. module Mouse
  52.   #--------------------------------------------------------------------------
  53.   # ## 常量
  54.   #--------------------------------------------------------------------------
  55.   GetAsyncKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
  56.   GetKeyState = Win32API.new("user32","GetKeyState",['i'],'i')
  57.   
  58.   ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
  59.   
  60.   GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  61.   GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
  62.   
  63.   #--------------------------------------------------------------------------
  64.   # * Mouse Click
  65.   #     button      : button
  66.   #--------------------------------------------------------------------------
  67.   def Mouse.click?(button)
  68.     return false if button == 1 and !$click_abled
  69.     return true if @keys.include?(button)
  70.     return false
  71.   end  
  72.   #--------------------------------------------------------------------------
  73.   # * Mouse Pressed
  74.   #     button      : button
  75.   #--------------------------------------------------------------------------
  76.   def Mouse.press?(button)
  77.     return true if @press.include?(button)
  78.     return false
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # * Mouse Pressed
  82.   #     button      : button
  83.   #--------------------------------------------------------------------------
  84.   def Mouse.area?(x, y, width=32, height=32)
  85.     return false if @pos == nil
  86.     return true if @pos[0] >= x and @pos[0] <= (x+width) and @pos[1] >= y and @pos[1] <= (y+height)
  87.     return false
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # * Mouse Pixel Position
  91.   #--------------------------------------------------------------------------
  92.   def Mouse.pixels
  93.     return @pos == nil ? [0, 0] : @pos
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # * Mouse Tile Position
  97.   #--------------------------------------------------------------------------
  98.   def Mouse.tiles
  99.     return nil if @pos == nil
  100.     x = @pos[0] / 32
  101.     y = @pos[1] / 32
  102.     return [x, y]
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # * Set Mouse Position
  106.   #--------------------------------------------------------------------------
  107.   def Mouse.set_pos(x_pos=0, y_pos=0)
  108.     width, height = Mouse.client_size
  109.     if (x_pos.between?(0, width) && y_pos.between?(0, height))
  110.       x = Mouse.client_pos[0] + x_pos; y = Mouse.client_pos[1] + y_pos
  111.       Win32API.new('user32', 'SetCursorPos', 'NN', 'N').call(x, y)
  112.     end
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # * Mouse Update
  116.   #--------------------------------------------------------------------------
  117.   def Mouse.update
  118.     @pos            = Mouse.pos
  119.     @keys, @press   = [], []
  120.     @keys.push(1)   if GetAsyncKeyState.call(1) & 0X01 == 1
  121.     @keys.push(2)   if GetAsyncKeyState.call(2) & 0X01 == 1
  122.     @keys.push(3)   if GetAsyncKeyState.call(4) & 0X01 == 1
  123.     @press.push(1)  if GetKeyState.call(1) > 1
  124.     @press.push(2)  if GetKeyState.call(2) > 1
  125.     @press.push(3)  if GetKeyState.call(4) > 1
  126.     ## 鼠标双击
  127.     @wait ||= 0
  128.     @wait += 1 if @key != nil
  129.     (@key = nil; @wait = 0) if @wait > 30 # 双击时间
  130.   end  
  131.   #--------------------------------------------------------------------------
  132.   # * Automatic functions below
  133.   #--------------------------------------------------------------------------
  134.   #
  135.   #--------------------------------------------------------------------------
  136.   # * Obtain Mouse position in screen
  137.   #--------------------------------------------------------------------------
  138.   def Mouse.global_pos
  139.     pos = [0, 0].pack('ll')
  140.     if GetCursorPos.call(pos) != 0
  141.       return pos.unpack('ll')
  142.     else
  143.       return nil
  144.     end
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # * Return Screen mouse position within game window
  148.   #--------------------------------------------------------------------------
  149.   def Mouse.pos
  150.     x, y = Mouse.screen_to_client(*Mouse.global_pos)
  151.     width, height = Mouse.client_size
  152.     begin
  153.       if (x >= 0 and y >= 0 and x < width and y < height)
  154.         return x, y
  155.       else
  156.         return nil
  157.       end
  158.     rescue
  159.       return nil
  160.     end
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   #  * Pass Screen to Game System
  164.   #--------------------------------------------------------------------------
  165.   def Mouse.screen_to_client(x, y)
  166.     return nil unless x and y
  167.     pos = [x, y].pack('ll')
  168.     if ScreenToClient.call(HWND, pos) != 0
  169.       return pos.unpack('ll')
  170.     else
  171.       return nil
  172.     end
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # * Get Game Window Size
  176.   #--------------------------------------------------------------------------
  177.   def Mouse.client_size
  178.     rect = [0, 0, 0, 0].pack('l4')
  179.     GetClientRect.call(HWND, rect)
  180.     right, bottom = rect.unpack('l4')[2..3]
  181.     return right, bottom
  182.   end
  183.   #--------------------------------------------------------------------------
  184.   # * Get Window Position
  185.   #--------------------------------------------------------------------------
  186.   def Mouse.client_pos
  187.     rect = [0, 0, 0, 0].pack('l4')
  188.     ## 用户区
  189.     GetClientRect.call(HWND, rect)
  190.     left, upper = rect.unpack('l4')[0..1]
  191.     return left, upper
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # ## 句柄
  195.   #--------------------------------------------------------------------------
  196.   def Mouse.get_hwnd
  197.     game_name = "\0" * 256
  198.     Win32API.new('kernel32', 'GetPrivateProfileStringA', 'pppplp', 'l').call('Game','Title','',game_name,255,".\\Game.ini")
  199.     game_name.delete!("\0")
  200.     return Win32API.new('user32', 'FindWindowA', 'pp', 'l').call('RGSS Player',game_name)
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # ## 双击
  204.   #--------------------------------------------------------------------------
  205.   def self.double_click?(key)
  206.     if @keys.include?(key)
  207.       @key !=key ? (@key = key; return false) : (@key = nil; return true)
  208.     end
  209.   end
  210.   ## 句柄常量
  211.   HWND = Mouse.get_hwnd
  212.   
  213.   ###############
  214.   GetMessage = Win32API.new('user32','GetMessage','plll','l')
  215.   
  216.   Point = Struct.new(:x, :y)
  217.   Message = Struct.new(:message, :wparam, :lparam, :pt)
  218.   Param = Struct.new(:x, :y, :scroll)
  219.   
  220.   def self.scroll
  221.     msg = "\0"*32
  222.     GetMessage.call(msg,0,0,0)
  223.     r = wmcallback(unpack_msg(msg))
  224.     return r unless r.nil?
  225.   end
  226.   
  227.   def wmcallback(msg)
  228.     return unless msg.message == Scroll
  229.     param = Param.new
  230.     param.x = word2signed_short(loword(msg.lparam))
  231.     param.y = word2signed_short(hiword(msg.lparam))
  232.     param.scroll = word2signed_short(hiword(msg.wparam))
  233.     return [param.x,param.y,param.scroll]
  234.   end
  235.   
  236.   def hiword(dword)
  237.     ###return ((dword&0xffff0000)>>16)&0x0000ffff
  238.     return (dword & 0xffff0000) / 0x10000
  239.   end
  240.   
  241.   def loword(dword)
  242.     return dword&0x0000ffff
  243.   end
  244. end

复制代码
改动在于Mouse.update中@press.push部分
  1.     @press.push(1)  if GetKeyState.call(1) > 1
  2.     @press.push(2)  if GetKeyState.call(2) > 1
  3.     @press.push(3)  if GetKeyState.call(4) > 1
复制代码
脚本基于沉影的鼠标系统修改alpha
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-21 19:30

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表