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

Project1

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

[已经解决] 8v求类似于xp里的鼠标系统(翻页功能)和图片响应

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
977 小时
注册时间
2011-5-13
帖子
292
跳转到指定楼层
1
发表于 2012-9-2 16:44:15 手机端发表。 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
8星屑
本帖最后由 纳尔德 于 2012-9-2 18:05 编辑

如果有能力可以移植,xp-va,或者vx-va都行。鼠标系统要求简单,能达到点击效果,右键返回,结合图片响应。
当鼠标点到这个图片执行公共事件。
另外还有一个翻页功能,就是当物品数达到一页满鼠标可以翻页,详情参考以下。
http://rpg.blue/forum.php?mod=viewthread&tid=225935
http://rpg.blue/forum.php?mod=viewthread&tid=224428

至少达到以上两个帖子内的效果。当然能优化的可以适当优化。
求va大师帮帮忙。

最佳答案

查看完整内容

首先鼠标脚本基本上通用。。不过我用的是杨菲菲的鼠标。。如果是用其他的就不一定能用。。因为方法不一样。。首先是杨菲菲的脚本 $apicache = {} class String def apicall(*args) $apicache[self] = Win32API.new(*self.split("|")) unless $apicache.include? self $apicache[self].call(*args) end end class Symbol def method_missing(*args, &block) self.to_s.send(*args, &block) end en ...

Lv3.寻梦者

梦石
0
星屑
1314
在线时间
962 小时
注册时间
2012-4-30
帖子
1475

开拓者

2
发表于 2012-9-2 16:44:16 | 只看该作者
首先鼠标脚本基本上通用。。不过我用的是杨菲菲的鼠标。。如果是用其他的就不一定能用。。因为方法不一样。。首先是杨菲菲的脚本
RUBY 代码复制
  1. $apicache = {}
  2. class String
  3.    def apicall(*args)
  4.        $apicache[self] = Win32API.new(*self.split("|")) unless $apicache.include? self
  5.        $apicache[self].call(*args)
  6.    end
  7. end
  8.  
  9. class Symbol
  10.   def method_missing(*args, &block)
  11.         self.to_s.send(*args, &block)
  12.   end
  13. end
  14. class Win32API
  15.   WM_ACTIVATEAPP=0x1C
  16.   WM_MOUSEMOVE=0x200
  17.   WM_MOUSEWHEEL = 0x020A
  18.   WM_LBUTTONDOWN = 0x201
  19.   WM_RBUTTONDOWN = 0x204
  20.   WM_MOUSEDOWN = 0x210
  21.   WM_LBUTTONUP = 0x202
  22.   WM_RBUTTONUP = 0x205
  23.   WM_LBUTTONDBLCLK  = 0x203
  24.   WM_RBUTTONDBLCLK  = 0x204
  25. end
  26. module Roost   
  27.     module MainWindow
  28.         def self.getwndproc
  29.            @wndproc
  30.          end
  31.         def self.setwndproc(obj)
  32.            @wndproc=obj
  33.         end
  34.         def self.addwndproc(obj)
  35.           @@wndprocs.push(obj)
  36.         end
  37.         @@wndprocs=[]
  38.         @wndproc = lambda {|hwnd, msg, wp, lp|
  39.           @@handle=false
  40.           for i in @@wndprocs
  41.             i.call(hwnd, msg, wp, lp)
  42.           end
  43.           return Roost::MainWindow.use_rm_proc(hwnd, msg, wp, lp)
  44.         }
  45.         def self.use_rm_proc(hwnd,msg,wp,lp)
  46.           if (not @@handle)
  47.             @@handle=true
  48.             return :"user32|CallWindowProc|iiiii|i".apicall(@@oHandle,hwnd,msg,wp,lp)
  49.           end
  50.         end
  51.         def self.disable_rm_proc
  52.           @@handle=true
  53.         end
  54.         def self.enable
  55.               Roost::MainWindow.instance_eval do
  56.                 def self.enable
  57.                 end
  58.               end
  59.             Roost::MainWindow.instance_eval do
  60.               @msg = "\0"*24
  61.               @hwnd = 0
  62.               while @hwnd==0
  63.                :"user32|GetMessage|piii|v".apicall(@msg, 0, 0, 0)
  64.                @kmsg = @msg
  65.                :"user32|TranslateMessage|p|v".apicall(@kmsg)
  66.                :"user32|DispatchMessage|p|v".apicall(@kmsg)
  67.                @hwnd = @msg.unpack("i*")[0]
  68.              end
  69.             @hdc = :"user32|GetDC|i|i".apicall(@hwnd)
  70.             def self.hwnd
  71.                return @hwnd
  72.             end
  73.             def self.hdc
  74.               return @hdc
  75.             end
  76.  
  77.             def self.findProc(l, n)
  78.                    lib = :"kernel32|LoadLibrary|p|i".apicall(l);
  79.                    ret = :"kernel32|GetProcAddress|ip|l".apicall(lib, n);
  80.                    :"kernel32|FreeLibrary|l|v".apicall(lib)
  81.                    return ret
  82.             end
  83.                  def self.loadfindProc(l, n)
  84.                    lib = :"kernel32|LoadLibrary|p|i".apicall(l);
  85.                    ret = :"kernel32|GetProcAddress|ip|l".apicall(lib, n);
  86.                    return ret
  87.             end
  88.             def self.enableWndProc
  89.               Roost::MainWindow.instance_eval do
  90.                 def self.enableWndProc
  91.                 end
  92.               end
  93.               @malloc = :"msvcrt|malloc|i|i"
  94.               @memcpy = :"msvcrt|memcpy|ipi|v"
  95.  
  96.  
  97.              sprintf    = self.findProc("msvcrt",    "sprintf")
  98.              rgsseval   = self.findProc("RGSS300",  "RGSSGetInt")
  99.              old        = :"user32|GetWindowLong|ll|l".apicall(@hwnd, -4)
  100.              buf        = @malloc.apicall(1024)  
  101.              fmt        = @malloc.apicall(2048)
  102.              sprintfvar = @malloc.apicall(8)
  103.              rgssevalvar= @malloc.apicall(8)
  104.              oldvar     = @malloc.apicall(8)
  105.              fmtvar     = @malloc.apicall(8)
  106.              bufvar     = @malloc.apicall(8)
  107.              defvar     = @malloc.apicall(8)
  108.  
  109.              :"msvcrt|strcpy|pp|p".apicall(fmt, "Roost::MainWindow.getwndproc.call(%d,%d,%d,%d)")
  110.  
  111.              @memcpy.apicall(sprintfvar, [sprintf].pack("i"),  4)
  112.              @memcpy.apicall(rgssevalvar,[rgsseval].pack("i"), 4)
  113.              @memcpy.apicall(oldvar,     [old].pack("i"),      4)
  114.              @memcpy.apicall(fmtvar,     [fmt].pack("i"),      4)
  115.              @memcpy.apicall(bufvar,     [buf].pack("i"),      4)
  116.              @memcpy.apicall(defvar,     [self.findProc("user32", "DefWindowProcA")].pack("i"),      4)
  117.  
  118.              @code = [0x55,0x89,0xe5,0xff,0x75,0x14,
  119.                       0xff,0x75,0x10,0xff,0x75,0x0c,
  120.                       0xff,0x75,0x08,0xff,0x35].pack('C*')
  121.              @code << [fmtvar].pack('l') << [0xff, 0x35].pack('C*')
  122.              @code << [bufvar].pack('l') << [0xff, 0x15].pack('C*')
  123.              @code << [sprintfvar].pack("l")
  124.              @code << [0xff, 0x15].pack('C*')
  125.              @code << [rgssevalvar].pack("l")
  126. =begin
  127.              @code << [0x83,0xc4,0x18, 0xff, 0x75, 0x14,
  128.                        0xff,0x75, 0x10, 0xff, 0x75, 0x0c,
  129.                        0xff,0x75, 0x08, 0xff, 0x15].pack('C*')
  130.              @code << [oldvar].pack("l")
  131. =end
  132.              @code << [0x83,0xc4,0x18].pack('C*')
  133.              @code << [0xc9,0xc2,0x10,0x00].pack('C*')
  134.              #0xD1, 0xE8
  135.              @shellcode = @malloc.apicall(2048)  
  136.              @memcpy.apicall(@shellcode, @code, @code.size)
  137.              @@oHandle= :"user32|SetWindowLong|iii|i".apicall(@hwnd, -4, @shellcode)
  138.               #Returning Test : should be 5
  139.               #Roost::MainWindow.setwndproc (lambda{|hwnd, msg, wp, lp| 5})
  140.               #p :"user32|CallWindowProc|iiiii|i".apicall(@shellcode, 0, 0, 0, 0)
  141.             end
  142.           end
  143.  
  144.         end
  145.  
  146.   end
  147. end
  148.  
  149. Roost::MainWindow.enable
  150. Roost::MainWindow.enableWndProc
  151. module Mouse
  152.   module_function
  153.   LKEY,RKEY,MKEY   = 1,2,4
  154.   DBLCTIME         = (Win32API.new('user32','GetDoubleClickTime','','l').call * 60.0 / 1000).round
  155.   @count    = 0     ## 双击时间计数
  156.   @dblc     = []    ## 双击记录[key,wait,[mouse_x,mouse_y]]
  157.   @move_pos = []    ## 移动记录
  158.   @clicks   = []    ## 单击记录
  159.   def _init_
  160.     @press,@toggled=0,0
  161.  
  162.     @pos=[0,0]
  163.  
  164.     Roost::MainWindow.addwndproc (lambda {|hwnd, msg, wp, lp|
  165.       Mouse.onLMouseDown if msg==Win32API::WM_LBUTTONDOWN
  166.       Mouse.onRMouseDown if msg==Win32API::WM_RBUTTONDOWN
  167.       Mouse.onLMouseUp if msg==Win32API::WM_LBUTTONUP
  168.       Mouse.onRMouseUp if msg==Win32API::WM_RBUTTONUP
  169.       Mouse.onLMouseDD if msg==Win32API::WM_LBUTTONDBLCLK
  170.       Mouse.onRMouseDD if msg==Win32API::WM_RBUTTONDBLCLK
  171.       if msg==Win32API::WM_MOUSEMOVE
  172.         Mouse.setMouse([lp&0xffff,lp>>16])
  173.       end
  174.     })
  175.     @ldown=false
  176.     @ltd=false
  177.     @rdown=false
  178.     @rtd=false
  179.     @lup=false
  180.     @rup=false
  181.   end
  182.   def onLMouseDown
  183.     @ltd=true
  184.     @ltd=false if @ldown
  185.     @ldown=true
  186.   end
  187.   def onLMouseUp
  188.     @ldown=false
  189.     @ltd=false
  190.   end
  191.   def onLMouseDD
  192.  
  193.   end
  194.   def onRMouseDown
  195.     @rtd=true
  196.     @rtd=false if @rdown
  197.     @rdown=true
  198.  
  199.   end
  200.   def onRMouseUp
  201.     @rdown=false
  202.     @rtd=false
  203.   end
  204.   def onRMouseDD
  205.  
  206.   end
  207.   def setMouse(p)
  208.     @pos=p
  209.   end
  210.  
  211.   #--------------------------------------------------------------------------
  212.   # ## 触发?
  213.   #--------------------------------------------------------------------------
  214.   def self.toggled?(key)
  215.     return @toggled & key != 0
  216.   end
  217.   #--------------------------------------------------------------------------
  218.   # ## 按下?
  219.   #--------------------------------------------------------------------------
  220.   def Mouse.press?(key)
  221.     return @press & key != 0
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # ## 单击?
  225.   #--------------------------------------------------------------------------
  226.   def self.click?(key)
  227.     return false if key == LKEY and !$click_abled
  228.     return @clicks[0] & key == 0 && @clicks[1] & key != 0
  229.   end
  230.   #--------------------------------------------------------------------------
  231.   # ## 双击?
  232.   #--------------------------------------------------------------------------
  233.   def self.dbl_click?(key)
  234.     return false if @dblc.size < 2
  235.     ## 键值有效
  236.     if @dblc[1][0] & key != 0 and @dblc[0][0] & key != 0
  237.       ## 间隔有效
  238.       if @dblc[1][1] - @dblc[0][1] < DBLCTIME
  239.         ## 坐标有效
  240.         if @dblc[1][2] == @dblc[0][2]
  241.           return @clicks[0] & key == 0 && @clicks[1] & key != 0
  242.         end
  243.       end
  244.     end
  245.     return false
  246.   end
  247.   def pos
  248.     return @pos
  249.   end
  250.   def update
  251.     @press,@toggled=0,0
  252.     @press += LKEY   if @ldown
  253.     @press += RKEY   if @rdown
  254.     @toggled += LKEY if @ltd
  255.     @toggled += RKEY  if @rtd
  256.     @clicks.shift if @clicks.size >=2
  257.     @clicks.push @press
  258.     if @dblc.size >= 2
  259.       @dblc.clear
  260.       @count = 0
  261.     end
  262.     if @dblc.size == 1 and @count - @dblc[0][1] > DBLCTIME
  263.       @dblc.clear
  264.       @count = 0
  265.     end
  266.     if @clicks[0] == 0 and @clicks[1] != 0
  267.       if @dblc.size == 1 and @dblc[0][0] != @clicks[1]
  268.         @dblc.clear
  269.         @count = 0
  270.       end
  271.       @dblc.push [@press,@count,@pos]
  272.     end
  273.     @count += 1 unless @dblc.empty?
  274.     @move_pos.shift if @move_pos.size >= 2
  275.     @move_pos.push @pos
  276.     $click_abled=true
  277.   end
  278.   def down(p)
  279.     if (p==LEFT)
  280.       return @ldown
  281.     else
  282.       return @rdown
  283.     end
  284.   end
  285. end
  286.  
  287. Mouse._init_
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294. class << Mouse
  295.   Win32API.new('user32', 'ShowCursor', 'l', 'l').call(0)
  296.   $mousec = Sprite.new
  297.   $mousec.z = 10001
  298.   $mousec.x = $mousec.y = 1000
  299.   $mouse_icon = 'Pointer'
  300.   $mousec.bitmap = Cache.system($mouse_icon)
  301.  
  302.   alias wor_mouse_upd_mouse update unless $@
  303.   def Mouse.update
  304.     wor_mouse_upd_mouse
  305.     if $mouse_old_icon.nil? or $mouse_old_icon != $mouse_icon
  306.       $mouse_old_icon = $mouse_icon
  307.       $mousec.bitmap = Cache.system($mouse_old_icon)
  308.     end
  309.     if @pos.nil?
  310.       $mousec.x = 1000 if $mousec.x != 1000
  311.       $mousec.y = 1000 if $mousec.y != 1000
  312.       Win32API.new('user32', 'ShowCursor', 'l', 'l').call(1)
  313.     else
  314.       $mousec.x = @pos[0] if $mousec.x != @pos[0]
  315.       $mousec.y = @pos[1] if $mousec.y != @pos[1]
  316.       Win32API.new('user32', 'ShowCursor', 'l', 'l').call(0)
  317.     end
  318.     ## 鼠标刷新
  319.     $mousec.update
  320.   end
  321.   #--------------------------------------------------------------------------
  322.   # ## 经过?
  323.   #     obj       : 对象实例
  324.   #                 **支持Sprite,Window,Viewport,Rect,Plane,可补充
  325.   #--------------------------------------------------------------------------
  326.   def Mouse.over?(obj)
  327.     case obj
  328.     when Sprite
  329.       x = obj.x-obj.ox; y = obj.y-obj.oy
  330.       unless obj.viewport.nil?
  331.         x += obj.viewport.rect.x
  332.         y += obj.viewport.rect.y
  333.       end
  334.       return Mouse.area?(x, y, obj.width, obj.height)
  335.     when Window
  336.       x = obj.x;y = obj.y
  337.       unless obj.viewport.nil?
  338.         x += obj.viewport.rect.x
  339.         y += obj.viewport.rect.y
  340.       end
  341.       return Mouse.area?(x, y, obj.width, obj.height)
  342.     when Viewport
  343.       return Mouse.area?(obj.rect.x, obj.rect.y, obj.rect.width, obj.rect.height)
  344.     when Rect
  345.       return Mouse.area?(obj.x, obj.y, obj.width, obj.height)
  346.     when Plane
  347.       x = obj.x;y = obj.y
  348.       unless obj.viewport.nil?
  349.         x += obj.viewport.rect.x
  350.         y += obj.viewport.rect.y
  351.       end
  352.       return Mouse.area?(x, y, obj.width, obj.height)
  353.     end
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # * Mouse in_area
  357.   #--------------------------------------------------------------------------
  358.   def Mouse.area?(x, y, width=32, height=32)
  359.     return false if @pos == nil
  360.     return true if @pos[0] >= x and @pos[0] <= (x+width) and @pos[1] >= y and @pos[1] <= (y+height)
  361.     return false
  362.   end
  363.  
  364. end
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372. #==============================================================================
  373. # ## Window_Selectable
  374. #==============================================================================
  375. class Window_Selectable < Window_Base
  376.   alias wor_winsel_ini_mouse initialize
  377.   alias wor_winsel_upd_mouse update
  378.   def initialize(*args)
  379.     wor_winsel_ini_mouse(*args)
  380.     @scroll_wait = 0
  381.     @cursor_wait = 0
  382.   end
  383.  
  384.   def update
  385.     wor_winsel_upd_mouse
  386.     if self.active and self.visible
  387.       update_mouse
  388.     end
  389.   end
  390.  
  391.   def update_mouse
  392.     @cursor_wait -= 1 if @cursor_wait > 0
  393.     (0...item_max).each do |i|
  394.       irect = mouse_rect(i)
  395.       irx = self.x + 16 + irect.x - self.ox
  396.       iry = self.y + 16 + irect.y - self.oy
  397.       result = Mouse.area?(irx, iry, irect.width, irect.height)
  398.       move_cursor(i) if result
  399.       ## 控制单击条件
  400.       $click_abled = false if i == @index and !result
  401.     end
  402.  
  403.   end
  404.  
  405.   ## 鼠标区域
  406.   def mouse_rect(i)
  407.     rect = item_rect(i)
  408.     return rect if rect.width <= 32
  409.     rect.x += 4
  410.     rect.y += 4
  411.     rect.width -= 8
  412.     rect.height -= 8
  413.     return rect
  414.   end
  415.   def column_max
  416.     return row_max
  417.   end
  418.   def move_cursor(index)
  419.     ## 不响应
  420.     return if @cursor_wait > 0
  421.     return if self.index == index
  422.     @scroll_wait -= 1 if @scroll_wait > 0
  423.     row1 = self.index / column_max
  424.     row2 = index / column_max
  425.     bottom = self.top_row + (self.page_row_max - 1)
  426.     if row1 == self.top_row and row2 < self.top_row
  427.       return if @scroll_wait > 0
  428.       self.index = [self.index - column_max, 0].max
  429.       @scroll_wait = 4
  430.     elsif row1 == bottom and row2 > bottom
  431.       return if @scroll_wait > 0
  432.       self.index = [self.index + column_max, item_max - 1].min
  433.       @scroll_wait = 4
  434.     else
  435.       self.index = index
  436.     end
  437.     return if @cursor_wait > 0
  438.     Sound.play_cursor
  439.     @cursor_wait += 2
  440.   end
  441. end
  442.  
  443. #==============================================================================
  444. # ** Input
  445. #==============================================================================
  446. class << Input
  447.   alias wor_input_upd_mouse update unless $@
  448.   alias wor_input_trig_mouse trigger? unless $@
  449.   alias wor_input_rep_mouse repeat? unless $@
  450.   def Input.update
  451.     wor_input_upd_mouse
  452.     Mouse.update
  453.   end
  454.   def Input.trigger?(input)
  455.  
  456.     return wor_input_trig_mouse(input) if Mouse.pos.nil?
  457.     case input
  458.     when Input::B
  459.       return (wor_input_trig_mouse(input) or Mouse.click?(Mouse::RKEY))
  460.     when Input::C
  461.       if SceneManager.scene.is_a?(Scene_Map) and !$game_message.visible
  462.         return wor_input_trig_mouse(input)
  463.       else
  464.         return (wor_input_trig_mouse(input) or Mouse.click?(Mouse::LKEY))
  465.       end
  466.     else
  467.       return wor_input_trig_mouse(input)
  468.     end
  469.   end
  470.  
  471.   def Input.repeat?(input)
  472.  
  473.     if input == Input::B
  474.       return (wor_input_rep_mouse(input) or Mouse.click?(Mouse::RKEY))
  475.     else
  476.       return wor_input_rep_mouse(input)
  477.     end
  478.   end
  479. end


然后是鼠标响应图片。。命名规则就是cmd+公共事件ID  鼠标移动到上面显示cmd+公共事件ID+"_2"的形式
RUBY 代码复制
  1. class Game_Picture
  2. def name=(str)
  3.    @name = str
  4. end
  5. end
  6. class Sprite_Picture
  7. alias update_old update
  8. def update
  9.    update_old
  10.    return if @picture.name == "" or @picture.name[/cmd/].nil?
  11.    picx = self.x
  12.    picy = self.y
  13.    picw = self.bitmap.width
  14.    pich = self.bitmap.height
  15.  
  16.    if Mouse.area?(picx, picy, picw, pich)
  17.  
  18.      if @picture.name.split(/_/)[1].nil?
  19.        @picture.name = @picture.name + "_2"
  20.       #self.tone.set(199, 255, 255)#如果不用显示cmd+公共事件ID+"_2"的形式的话把上面的那句注释掉把这句的#删掉 则只是把图片色调变了
  21.      end
  22.  
  23.  
  24.      if Mouse.click?(Mouse::LKEY) && @picture.name.split(/_/)[0] != nil
  25.        @picture.name.split(/_/)[0].sub(/cmd([0-9]+)/,"")
  26.        $game_temp.reserve_common_event($1.to_i)
  27.      end
  28.  
  29.    else
  30.  
  31.      @picture.name = @picture.name.split(/_/)[0]
  32.  
  33.    end
  34. end
  35. end


这个就是自动翻页的脚本。。。突然觉得很简单。。。(´Д`)
RUBY 代码复制
  1. class Window_Selectable
  2.   def update
  3.     if self.active and item_max > 0
  4.       mouse_x, mouse_y = Mouse.pos
  5.       rect_last = item_rect(item_max)
  6.       rect_last_x = rect_last.x + rect_last.width
  7.       rect_last_y = rect_last.y + rect_last.height
  8.  
  9.       rect_first = item_rect(top_row)
  10.       rect_first_x = rect_first.x + rect_first.width
  11.       rect_first_y = rect_first.y + rect_first.height
  12.       if mouse_y > rect_last_y
  13.         cursor_down
  14.       end
  15.       if mouse_y < rect_first_y
  16.         cursor_up
  17.       end
  18.     end
  19.   end
  20. end

评分

参与人数 1星屑 +200 收起 理由
千葉玖濑 + 200 谢谢前辈。

查看全部评分

回复

使用道具 举报

Lv3.寻梦者

Assassin-K

梦石
0
星屑
3463
在线时间
2281 小时
注册时间
2012-5-23
帖子
4065

贵宾

3
发表于 2012-9-2 20:48:39 | 只看该作者
帮你找人过来,看他接不接活
@铅笔描绘的思念

点评

正在翻脚本的样子。。  发表于 2012-9-2 20:53

◆ROZONE◆
>洛子又要去流浪地球了……
>如果你看到我在线,又没动静,那只能说明我在挂机……
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
116 小时
注册时间
2012-8-12
帖子
61
4
发表于 2012-9-2 23:13:43 | 只看该作者
好像外站有一个比较完整的鼠标脚本!鼠标系统  by  Jet
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-4-26 03:29

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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