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

Project1

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

[有事请教] 关于鼠标脚本的问题

[复制链接]

Lv1.梦旅人

梦石
0
星屑
73
在线时间
11 小时
注册时间
2021-4-1
帖子
3
跳转到指定楼层
1
发表于 2021-4-3 20:55:11 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
10星屑
当使用名称输入的处理出现问题。




RGSS2 脚本:
  1. $敵人選框擴大 = 20
  2. $角色選框擴大 = 30

  3. #==============================================================================
  4. # API調用
  5. #==============================================================================
  6. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  7. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  8. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  9. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  10. $Window_HWND = $GetActiveWindow.call
  11. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  12. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
  13. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)
  14. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)
  15. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')
  16. #$Window_HWND = $FindWindow.call(nil, 'mousetry')

  17. module Mouse  
  18.   LEFT = 0x01
  19.   RIGHT = 0x02

  20.   def self.init(sprite = nil)
  21. #   $HookStart.call($Window_HWND)
  22.     $ShowCursor.call(0)
  23.    
  24.     @show_cursor = false
  25.    
  26.     @mouse_sprite = Sprite.new
  27.     @mouse_sprite.z = 99999
  28.     @mouse_sprite.bitmap = Bitmap.new('Graphics/Mouse/1.png')
  29.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))

  30.     @left_press = false
  31.     @right_press = false
  32.     @left_trigger = false
  33.     @right_trigger = false
  34.     @left_repeat = false
  35.     @right_repeat = false
  36.     @click_lock = false
  37.    
  38.     update
  39.   end
  40.   def self.exit
  41.     @mouse_sprite.bitmap.dispose
  42.     @mouse_sprite.dispose
  43.     @show_cursor = true
  44. #    $HookEnd.call
  45.     $ShowCursor.call(1)
  46.   end
  47.   def self.mouse_debug
  48.     return @mouse_debug.bitmap
  49.   end
  50.   def self.update
  51.     left_down = $GetKeyState.call(0x01)
  52.     right_down = $GetKeyState.call(0x02)
  53.    
  54.     @click_lock = false
  55.     mouse_x, mouse_y = self.get_mouse_pos
  56.     if @mouse_sprite != nil
  57.       @mouse_sprite.x = mouse_x
  58.       @mouse_sprite.y = mouse_y
  59.     end
  60.     if left_down[7] == 1
  61.       @left_repeat = (not @left_repeat)
  62.       @left_trigger = (not @left_press)
  63.       @left_press = true
  64.     else
  65.       @left_press = false
  66.       @left_trigger = false
  67.       @left_repeat = false
  68.     end
  69.     if right_down[7] == 1
  70.       @right_repeat = (not @right_repeat)
  71.       @right_trigger = (not @right_press)
  72.       @right_press = true
  73.     else
  74.       @right_press = false
  75.       @right_trigger = false
  76.       @right_repeat = false
  77.     end
  78.   end
  79.   def self.get_mouse_pos
  80.     point_var = [0, 0].pack('ll')
  81.     if $GetCursorPos.call(point_var) != 0
  82.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  83.         x, y = point_var.unpack('ll')
  84.         if (x < 0) or (x > 10000) then x = 0 end
  85.         if (y < 0) or (y > 10000) then y = 0 end
  86.         if x > 640 then x = 640 end
  87.         if y > 480 then y = 480 end
  88.         return x, y
  89.       else
  90.         return 0, 0
  91.       end
  92.     else
  93.       return 0, 0
  94.     end
  95.   end
  96.   def self.press?(mouse_code)
  97.     if mouse_code == LEFT
  98.       if @click_lock
  99.         return false
  100.       else
  101.         return @left_press
  102.       end
  103.     elsif mouse_code == RIGHT
  104.       return @right_press
  105.     else
  106.       return false
  107.     end
  108.   end
  109.   def self.trigger?(mouse_code)
  110.     if mouse_code == LEFT
  111.       if @click_lock
  112.         return false
  113.       else
  114.         return @left_trigger
  115.       end
  116.     elsif mouse_code == RIGHT
  117.       return @right_trigger
  118.     else
  119.       return false
  120.     end
  121.   end
  122.   def self.repeat?(mouse_code)
  123.     if mouse_code == LEFT
  124.       if @click_lock
  125.         return false
  126.       else
  127.         return @left_repeat
  128.       end
  129.     elsif mouse_code == RIGHT
  130.       return @right_repeat
  131.     else
  132.       return false
  133.     end
  134.   end
  135.   def self.click_lock?
  136.     return @click_lock
  137.   end
  138.   def self.click_lock
  139.     @click_lock = true
  140.   end
  141.   def self.click_unlock
  142.     @click_lock = false
  143.   end
  144. end
  145. module Input
  146.   if @self_update == nil
  147.     @self_update = method('update')
  148.     @self_press = method('press?')
  149.     @self_trigger = method('trigger?')
  150.     @self_repeat = method('repeat?')
  151.   end
  152.   def self.update
  153.     @self_update.call
  154.     Mouse.update
  155.   end
  156.   def self.press?(key_code)
  157.     if @self_press.call(key_code)
  158.       return true
  159.     end
  160.     if key_code == C
  161.       return Mouse.press?(Mouse::LEFT)
  162.     elsif key_code == B
  163.       return Mouse.press?(Mouse::RIGHT)
  164.     else
  165.       return @self_press.call(key_code)
  166.     end
  167.   end
  168.   def self.trigger?(key_code)
  169.     if @self_trigger.call(key_code)
  170.       return true
  171.     end
  172.     if key_code == C
  173.       return Mouse.trigger?(Mouse::LEFT)
  174.     elsif key_code == B
  175.       return Mouse.trigger?(Mouse::RIGHT)
  176.     else
  177.       return @self_trigger.call(key_code)
  178.     end
  179.   end
  180.   def self.repeat?(key_code)
  181.     if @self_repeat.call(key_code)
  182.       return true
  183.     end
  184.     if key_code == C
  185.       return Mouse.repeat?(Mouse::LEFT)
  186.     elsif key_code == B
  187.       return Mouse.repeat?(Mouse::RIGHT)
  188.     else
  189.       return @self_repeat.call(key_code)
  190.     end
  191.   end
  192. end

  193. class Window_Selectable
  194.   if @self_alias == nil
  195.     alias self_update update
  196.     @self_alias = true
  197.   end
  198.   def update
  199.     #self.cursor_rect.empty
  200.     self_update
  201.     if self.active and @item_max > 0
  202.       index_var = @index
  203.       tp_index = @index
  204.       mouse_x, mouse_y = Mouse.get_mouse_pos
  205.       mouse_not_in_rect = true
  206.       for i in 0...@item_max
  207.         @index = i
  208.         update_cursor
  209.         top_x = self.cursor_rect.x + self.x + 16
  210.         top_y = self.cursor_rect.y + self.y + 16
  211.         bottom_x = top_x + self.cursor_rect.width
  212.         bottom_y = top_y + self.cursor_rect.height
  213.         
  214.           top_x += self.x_mod
  215.           top_y += self.y_mod
  216.           bottom_x += self.x_mod
  217.           bottom_y += self.y_mod
  218.         
  219.         if (mouse_x > top_x) and (mouse_y > top_y) and
  220.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  221.           mouse_not_in_rect = false
  222.           if tp_index != @index
  223.             tp_index = @index
  224.             $data_system.sounds[0].play
  225.           end
  226.           break
  227.         end
  228.       end
  229.     if Input.trigger?(Input::F9)
  230.     p top_x,top_y,Mouse.get_mouse_pos
  231.     end
  232.       if mouse_not_in_rect
  233.         @index = index_var
  234.         update_cursor
  235.         Mouse.click_lock
  236.       else
  237.         Mouse.click_unlock               
  238.       end
  239.     end
  240.   end
  241. end




  242. class Window_NameInput
  243.   if @self_alias == nil
  244.     alias self_update update
  245.     @self_alias = true
  246.   end
  247.   def update
  248.     #self.cursor_rect.empty
  249.     self_update
  250.     if self.active
  251.       index_var = @index
  252.       mouse_x, mouse_y = Mouse.get_mouse_pos
  253.       mouse_not_in_rect = true
  254.       for i in (0...HIRAGANA.size).to_a.push(180)
  255.         @index = i
  256.         update_cursor
  257.         top_x = self.cursor_rect.x + self.x + 16
  258.         top_y = self.cursor_rect.y + self.y + 16
  259.         bottom_x = top_x + self.cursor_rect.width
  260.         bottom_y = top_y + self.cursor_rect.height
  261.         #
  262.         if (mouse_x > top_x) and (mouse_y > top_y) and
  263.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  264.           mouse_not_in_rect = false
  265.           break
  266.         end
  267.       end
  268.       if mouse_not_in_rect
  269.         @index = index_var
  270.         update_cursor
  271.         Mouse.click_lock
  272.       else
  273.         Mouse.click_unlock
  274.       end
  275.     end
  276.   end
  277. end
  278. =begin

  279. class Window_InputNumber
  280.   if @self_alias == nil
  281.     alias self_update update
  282.     @self_alias = true
  283.   end
  284.   def update
  285.     #self.cursor_rect.empty
  286.     self_update
  287.     mouse_x, mouse_y = Mouse.get_mouse_pos
  288.     if self.active and @digits_max > 0
  289.       index_var = @index
  290.       mouse_not_in_rect = true
  291.       for i in 0...@digits_max
  292.         @index = i
  293.         #update_cursor
  294.         top_x = self.cursor_rect.x + self.x + 16
  295.         bottom_x = top_x + self.cursor_rect.width
  296.         #
  297.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  298.           mouse_not_in_rect = false
  299.           break
  300.         end
  301.       end
  302.       if mouse_not_in_rect
  303.         @index = index_var
  304.         #update_cursor
  305.         Mouse.click_lock
  306.       else
  307.         Mouse.click_unlock
  308.       end
  309.     end
  310.     if @last_mouse_y == nil
  311.       @last_mouse_y = mouse_y
  312.     end
  313.     check_pos = (@last_mouse_y - mouse_y).abs
  314.     if check_pos > 10
  315.       #$game_system.se_play($data_system.cursor_se)
  316.       place = 10 ** (@digits_max - 1 - @index)
  317.       n = @Number / place % 10
  318.       @number -= n * place
  319.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  320.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  321.       @number += n * place
  322.       refresh
  323.       @last_mouse_y = mouse_y
  324.     end
  325.   end
  326. end
  327. =end

  328. class Scene_File
  329.   if @self_alias == nil
  330.     alias self_update update
  331.     @self_alias = true
  332.   end
  333.   def update
  334.     mouse_x, mouse_y = Mouse.get_mouse_pos
  335.     Mouse.click_lock
  336.     idx = 0
  337.     for i in @savefile_windows
  338.       top_x = i.x + 16
  339.       top_y = i.y + 16
  340.       bottom_x = top_x + i.width
  341.       bottom_y = top_y + i.height
  342.       if (mouse_x > top_x) and (mouse_y > top_y) and
  343.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  344.         i.selected = true
  345.         if @file_index != idx
  346.           @file_index = idx
  347.           $data_system.sounds[0].play
  348.         end            
  349.         Mouse.click_unlock
  350.       else
  351.         i.selected = false
  352.       end
  353.       idx += 1
  354.     end
  355.     self_update
  356.   end
  357. end

  358. class Game_Player
  359.   if @self_alias == nil
  360.     alias self_update update
  361.     @self_alias = true
  362.   end
  363.   def update
  364.     mouse_x, mouse_y = Mouse.get_mouse_pos
  365.     if @last_move_x == nil
  366.       @last_move_x = false
  367.     end
  368.     if $game_switches[123]
  369.      if Mouse.press?(Mouse::LEFT)
  370.        for event in $game_map.events.values
  371.          if event.screen_x/32 == mouse_x/32 and event.screen_y/32-1 == mouse_y/32
  372.            event.start
  373.          end
  374.        end
  375.      end
  376.      self_update
  377.      return
  378.    end
  379.     if Mouse.press?(Mouse::LEFT)
  380.    #for event in $game_map.events.values
  381.    #if event.screen_x/32 == mouse_x/32 and event.screen_y/32-1 == mouse_y/32
  382.    #event.start
  383.    #end
  384.    #end
  385.       last_moving = moving?
  386.       last_direction = @direction
  387.     #  return unless movable?
  388.     #  return if $game_map.interpreter.running?
  389.       unless moving? or $game_map.interpreter.running?
  390.       last_x = @x
  391.         if @last_move_x
  392.           @last_move_x = false
  393.         elsif mouse_x > screen_x + 16
  394.           move_right
  395.         elsif mouse_x < screen_x - 16
  396.           move_left
  397.         end
  398.         last_y = @y
  399.         if last_x != @x
  400.           @last_move_x = true
  401.         elsif mouse_y > screen_y
  402.           move_down
  403.         elsif mouse_y < screen_y - 32
  404.           move_up
  405.         end
  406. =begin        
  407.         if last_y != @y
  408.           @last_move_x = false
  409.         elsif not @last_move_x
  410.           case last_direction
  411.           when 2
  412.             turn_down
  413.           when 4
  414.             turn_left
  415.           when 6
  416.             turn_right
  417.           when 8
  418.             turn_up
  419.           end        
  420.         end
  421. =end         
  422.       end
  423.     end
  424.     self_update
  425.   end
  426. end
  427. Mouse.init
  428. END { Mouse.exit }


  429. class Window_Base < Window
  430.   attr_accessor :x_mod
  431.   attr_accessor :y_mod
  432.   alias ka_initialize initialize
  433.   def initialize(x, y, width, height)
  434.     ka_initialize(x, y, width, height)
  435.     self.x_mod = 0
  436.     self.y_mod = 0
  437.   end
  438. end
  439. class Window_PartyCommand < Window_Command
  440.   alias ka1_initialize initialize
  441.   def initialize
  442.     ka1_initialize
  443.     self.y_mod = 288
  444.   end
  445. end
  446. class Window_ActorCommand < Window_Command
  447.   alias ka2_initialize initialize
  448.   def initialize
  449.     ka2_initialize
  450.     self.x_mod = -128
  451.     self.y_mod = 288
  452.   end
  453. end
复制代码

在本站找的
求解!!


其余很正常

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

本版积分规则

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

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

GMT+8, 2024-4-26 01:54

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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