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

Project1

 找回密码
 注册会员
搜索
查看: 3100|回复: 4

[已经解决] 请问鼠标脚本如何用开关更换鼠标样式?

[复制链接]

Lv3.寻梦者

梦石
1
星屑
985
在线时间
231 小时
注册时间
2006-2-3
帖子
82
发表于 2019-9-30 18:41:32 | 显示全部楼层 |阅读模式

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

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

x
脚本如下
  1. #==============================================================================

  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息

  3. #==============================================================================



  4. #=================以下两个用来调整战斗时的手感问题,可以自己试试。

  5. $敌人选框扩大 = 20

  6. $角色选框扩大 = 30





  7. #==============================================================================

  8. # API调用

  9. #==============================================================================

  10. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')

  11. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')

  12. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')

  13. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')

  14. $Window_HWND = $GetActiveWindow.call

  15. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')

  16. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')

  17. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)

  18. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)

  19. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')

  20. #$Window_HWND = $FindWindow.call(nil, 'mousetry')



  21. module Mouse  

  22.   LEFT = 0x01

  23.   RIGHT = 0x02



  24.   def self.init(sprite = nil)

  25. #   $HookStart.call($Window_HWND)

  26.     $ShowCursor.call(0)

  27.    

  28.     @show_cursor = false

  29.    

  30.     @mouse_sprite = Sprite.new

  31.     @mouse_sprite.z = 99999
  32.    
  33.     @mouse_sprite.bitmap = Bitmap.new('Graphics/Pictures/mouse1.png')
  34.    
  35.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))



  36.     @left_press = false

  37.     @right_press = false

  38.     @left_trigger = false

  39.     @right_trigger = false

  40.     @left_repeat = false

  41.     @right_repeat = false

  42.     @click_lock = false

  43.    

  44.     update
  45.    
  46.   end

  47.   def self.exit
  48.    
  49.    
  50.     @mouse_sprite.bitmap.dispose

  51.     @mouse_sprite.dispose

  52.     @show_cursor = true

  53. #    $HookEnd.call

  54.     $ShowCursor.call(1)

  55.   end

  56.   def self.mouse_debug

  57.     return @mouse_debug.bitmap

  58.   end

  59.    
  60.   def self.update

  61.   
  62.     left_down = $GetKeyState.call(0x01)

  63.     right_down = $GetKeyState.call(0x02)
  64.    

  65.     @click_lock = false

  66.     mouse_x, mouse_y = self.get_mouse_pos
  67.    
  68.    
  69.     if @mouse_sprite != nil

  70.       @mouse_sprite.x = mouse_x

  71.       @mouse_sprite.y = mouse_y

  72.     end

  73.     if left_down[7] == 1

  74.       @left_repeat = (not @left_repeat)

  75.       @left_trigger = (not @left_press)

  76.       @left_press = true

  77.     else

  78.       @left_press = false

  79.       @left_trigger = false

  80.       @left_repeat = false

  81.     end

  82.     if right_down[7] == 1

  83.       @right_repeat = (not @right_repeat)

  84.       @right_trigger = (not @right_press)

  85.       @right_press = true

  86.     else

  87.       @right_press = false

  88.       @right_trigger = false

  89.       @right_repeat = false

  90.     end

  91.   end

  92.   def self.get_mouse_pos

  93.     point_var = [0, 0].pack('ll')

  94.     if $GetCursorPos.call(point_var) != 0

  95.       if $ScreenToClient.call($Window_HWND, point_var) != 0

  96.         x, y = point_var.unpack('ll')

  97.         if (x < 0) or (x > 10000) then x = 0 end

  98.         if (y < 0) or (y > 10000) then y = 0 end

  99.         if x > 640 then x = 640 end

  100.         if y > 480 then y = 480 end

  101.         return x, y

  102.       else

  103.         return 0, 0

  104.       end

  105.     else

  106.       return 0, 0

  107.     end

  108.   end

  109.   def self.press?(mouse_code)

  110.     if mouse_code == LEFT

  111.       if @click_lock

  112.         return false

  113.       else

  114.         return @left_press

  115.       end

  116.     elsif mouse_code == RIGHT

  117.       return @right_press

  118.     else

  119.       return false

  120.     end

  121.   end

  122.   def self.trigger?(mouse_code)

  123.     if mouse_code == LEFT

  124.       if @click_lock

  125.         return false

  126.       else

  127.         return @left_trigger

  128.       end

  129.     elsif mouse_code == RIGHT

  130.       return @right_trigger

  131.     else

  132.       return false

  133.     end

  134.   end

  135.   def self.repeat?(mouse_code)

  136.     if mouse_code == LEFT

  137.       if @click_lock

  138.         return false

  139.       else

  140.         return @left_repeat

  141.       end

  142.     elsif mouse_code == RIGHT

  143.       return @right_repeat

  144.     else

  145.       return false

  146.     end

  147.   end

  148.   def self.click_lock?

  149.     return @click_lock

  150.   end

  151.   def self.click_lock

  152.     @click_lock = true

  153.   end

  154.   def self.click_unlock

  155.     @click_lock = false

  156.   end

  157. end

  158. module Input

  159.   if @self_update == nil

  160.     @self_update = method('update')

  161.     @self_press = method('press?')

  162.     @self_trigger = method('trigger?')

  163.     @self_repeat = method('repeat?')

  164.   end

  165.   def self.update

  166.     @self_update.call

  167.     Mouse.update

  168.   end

  169.   def self.press?(key_code)

  170.     if @self_press.call(key_code)

  171.       return true

  172.     end

  173.     if key_code == C

  174.       return Mouse.press?(Mouse::LEFT)

  175.     elsif key_code == B

  176.       return Mouse.press?(Mouse::RIGHT)

  177.     else

  178.       return @self_press.call(key_code)

  179.     end

  180.   end

  181.   def self.trigger?(key_code)

  182.     if @self_trigger.call(key_code)

  183.       return true

  184.     end

  185.     if key_code == C

  186.       return Mouse.trigger?(Mouse::LEFT)

  187.     elsif key_code == B

  188.       return Mouse.trigger?(Mouse::RIGHT)

  189.     else

  190.       return @self_trigger.call(key_code)

  191.     end

  192.   end

  193.   def self.repeat?(key_code)

  194.     if @self_repeat.call(key_code)

  195.       return true

  196.     end

  197.     if key_code == C

  198.       return Mouse.repeat?(Mouse::LEFT)

  199.     elsif key_code == B

  200.       return Mouse.repeat?(Mouse::RIGHT)

  201.     else

  202.       return @self_repeat.call(key_code)

  203.     end

  204.   end

  205. end

  206. class Window_Selectable

  207.   if @self_alias == nil

  208.     alias self_update update

  209.     @self_alias = true

  210.   end

  211.   def update

  212.     #self.cursor_rect.empty

  213.     self_update

  214.     if self.active and @item_max > 0

  215.       index_var = @index

  216.       tp_index = @index

  217.       mouse_x, mouse_y = Mouse.get_mouse_pos

  218.       mouse_not_in_rect = true

  219.       for i in 0...@item_max

  220.         @index = i

  221.         update_cursor_rect

  222.         top_x = self.cursor_rect.x + self.x + 16

  223.         top_y = self.cursor_rect.y + self.y + 16

  224.         bottom_x = top_x + self.cursor_rect.width

  225.         bottom_y = top_y + self.cursor_rect.height

  226.         if (mouse_x > top_x) and (mouse_y > top_y) and

  227.            (mouse_x < bottom_x) and (mouse_y < bottom_y)

  228.           mouse_not_in_rect = false

  229.           if tp_index != @index

  230.             tp_index = @index

  231.             $game_system.se_play($data_system.cursor_se)

  232.           end

  233.           break

  234.         end

  235.       end

  236.       if mouse_not_in_rect

  237.         @index = index_var

  238.         update_cursor_rect

  239.         Mouse.click_lock

  240.       else

  241.         Mouse.click_unlock               

  242.       end

  243.     end

  244.   end

  245. end

  246. class Window_NameInput

  247.   if @self_alias == nil

  248.     alias self_update update

  249.     @self_alias = true

  250.   end

  251.   def update

  252.     #self.cursor_rect.empty

  253.     self_update

  254.     if self.active

  255.       index_var = @index

  256.       mouse_x, mouse_y = Mouse.get_mouse_pos

  257.       mouse_not_in_rect = true

  258.       for i in (0...CHARACTER_TABLE.size).to_a.push(180)

  259.         @index = i

  260.         update_cursor_rect

  261.         top_x = self.cursor_rect.x + self.x + 16

  262.         top_y = self.cursor_rect.y + self.y + 16

  263.         bottom_x = top_x + self.cursor_rect.width

  264.         bottom_y = top_y + self.cursor_rect.height

  265.         #

  266.         if (mouse_x > top_x) and (mouse_y > top_y) and

  267.            (mouse_x < bottom_x) and (mouse_y < bottom_y)

  268.           mouse_not_in_rect = false

  269.           break

  270.         end

  271.       end

  272.       if mouse_not_in_rect

  273.         @index = index_var

  274.         update_cursor_rect

  275.         Mouse.click_lock

  276.       else

  277.         Mouse.click_unlock

  278.       end

  279.     end

  280.   end

  281. end

  282. class Window_InputNumber

  283.   if @self_alias == nil

  284.     alias self_update update

  285.     @self_alias = true

  286.   end

  287.   def update

  288.     #self.cursor_rect.empty

  289.     self_update

  290.     mouse_x, mouse_y = Mouse.get_mouse_pos

  291.     if self.active and @digits_max > 0

  292.       index_var = @index

  293.       mouse_not_in_rect = true

  294.       for i in 0...@digits_max

  295.         @index = i

  296.         update_cursor_rect

  297.         top_x = self.cursor_rect.x + self.x + 16

  298.         bottom_x = top_x + self.cursor_rect.width

  299.         #

  300.         if (mouse_x > top_x) and (mouse_x < bottom_x)

  301.           mouse_not_in_rect = false

  302.           break

  303.         end

  304.       end

  305.       if mouse_not_in_rect

  306.         @index = index_var

  307.         update_cursor_rect

  308.         Mouse.click_lock

  309.       else

  310.         Mouse.click_unlock

  311.       end

  312.     end

  313.     if @last_mouse_y == nil

  314.       @last_mouse_y = mouse_y

  315.     end

  316.     check_pos = (@last_mouse_y - mouse_y).abs

  317.     if check_pos > 10

  318.       $game_system.se_play($data_system.cursor_se)

  319.       place = 10 ** (@digits_max - 1 - @index)

  320.       n = @number / place % 10

  321.       @number -= n * place

  322.       n = (n + 1) % 10 if mouse_y < @last_mouse_y

  323.       n = (n + 9) % 10 if mouse_y > @last_mouse_y

  324.       @number += n * place

  325.       refresh

  326.       @last_mouse_y = mouse_y

  327.     end

  328.   end

  329. end

  330. class Scene_File

  331.   if @self_alias == nil

  332.     alias self_update update

  333.     @self_alias = true

  334.   end

  335.   def update

  336.     mouse_x, mouse_y = Mouse.get_mouse_pos

  337.     Mouse.click_lock

  338.     idx = 0

  339.     for i in @savefile_windows

  340.       top_x = i.x + 16

  341.       top_y = i.y + 16

  342.       bottom_x = top_x + i.width

  343.       bottom_y = top_y + i.height

  344.       if (mouse_x > top_x) and (mouse_y > top_y) and

  345.          (mouse_x < bottom_x) and (mouse_y < bottom_y)

  346.         i.selected = true

  347.         if @file_index != idx

  348.           @file_index = idx

  349.           $game_system.se_play($data_system.cursor_se)

  350.         end            

  351.         Mouse.click_unlock

  352.       else

  353.         i.selected = false

  354.       end

  355.       idx += 1

  356.     end

  357.     self_update

  358.   end

  359. end

  360. class Arrow_Enemy

  361.   if @self_alias == nil

  362.     alias self_update update

  363.     @self_alias = true

  364.   end

  365.   def update

  366.     mouse_x, mouse_y = Mouse.get_mouse_pos

  367.     idx = 0

  368.     for i in $game_troop.enemies do

  369.       if i.exist?

  370.         top_x = i.screen_x - self.ox

  371.         top_y = i.screen_y - self.oy

  372.         bottom_x = top_x + self.src_rect.width

  373.         bottom_y = top_y + self.src_rect.height

  374.         if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and

  375.            (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)

  376.           if @index != idx

  377.             $game_system.se_play($data_system.cursor_se)

  378.             @index = idx

  379.           end

  380.         end

  381.       end

  382.       idx += 1

  383.     end

  384.     self_update

  385.   end

  386. end

  387. class Arrow_Actor

  388.   if @self_alias == nil

  389.     alias self_update update

  390.     @self_alias = true

  391.   end

  392.   def update

  393.     mouse_x, mouse_y = Mouse.get_mouse_pos

  394.     idx = 0

  395.     for i in $game_party.actors do

  396.       if i.exist?

  397.         top_x = i.screen_x - self.ox

  398.         top_y = i.screen_y - self.oy

  399.         bottom_x = top_x + self.src_rect.width

  400.         bottom_y = top_y + self.src_rect.height

  401.         if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and

  402.            (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)

  403.           if @index != idx

  404.             $game_system.se_play($data_system.cursor_se)

  405.             @index = idx

  406.           end

  407.         end

  408.       end

  409.       idx += 1

  410.     end

  411.     self_update

  412.   end

  413. end

  414. class Game_Player

  415.   if @self_alias == nil

  416.     alias self_update update

  417.     @self_alias = true

  418.   end

  419.   def update

  420.     mouse_x, mouse_y = Mouse.get_mouse_pos



  421.     if @last_move_x == nil

  422.       @last_move_x = false

  423.     end

  424.     if Mouse.press?(Mouse::LEFT)

  425.       last_moving = moving?

  426.       last_direction = @direction

  427.       unless moving? or $game_system.map_interpreter.running? or

  428.              @move_route_forcing or $game_temp.message_window_showing

  429.         last_x = @x

  430.         if @last_move_x

  431.           @last_move_x = false

  432.         elsif mouse_x > screen_x + 16

  433.           move_right

  434.         elsif mouse_x < screen_x - 16

  435.           move_left

  436.         end

  437.         last_y = @y

  438.         if last_x != @x

  439.           @last_move_x = true

  440.         elsif mouse_y > screen_y

  441.           move_down

  442.         elsif mouse_y < screen_y - 32

  443.           move_up

  444.         end

  445.         if last_y != @y

  446.           @last_move_x = false

  447.         elsif not @last_move_x

  448.           case last_direction

  449.           when 2

  450.             turn_down

  451.           when 4

  452.             turn_left

  453.           when 6

  454.             turn_right

  455.           when 8

  456.             turn_up

  457.           end

  458.         end

  459.       end

  460.     end

  461.     self_update

  462.   end

  463. end

  464. Mouse.init

  465. END { Mouse.exit }

复制代码



试过按照以下方式修改脚本,但是直接报错

      if $game_switches[99]
      @mouse_sprite.bitmap = Bitmap.new('Graphics/Pictures/mouse2.png')
    else
      @mouse_sprite.bitmap = Bitmap.new('Graphics/Pictures/mouse1.png')
      end

Lv5.捕梦者

梦石
0
星屑
33038
在线时间
10469 小时
注册时间
2009-3-15
帖子
4756
发表于 2019-9-30 18:47:17 | 显示全部楼层
本帖最后由 soulsaga 于 2019-9-30 19:03 编辑

报错正常..因为开关还未被初始化..
用开关控制基本不可行..等大神救吧..
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9587
在线时间
563 小时
注册时间
2017-9-28
帖子
208
发表于 2019-9-30 19:33:04 | 显示全部楼层
将此脚本插入鼠标脚本下方
  1. # coding: utf-8

  2. class << Mouse
  3.   alias _init_478918 init unless method_defined? :_init_478918
  4.   def init(*args)
  5.     _init_478918(*args)
  6.     @mouse_sprite.bitmap.dispose
  7.     @mouse_sprite.bitmap = RPG::Cache.picture('mouse1')
  8.   end

  9.   alias _update_478918 update unless method_defined? :_update_478918
  10.   def update(*args)
  11.     _update_478918(*args)
  12.     if $game_switches && $game_switches[99]
  13.       @mouse_sprite.bitmap = RPG::Cache.picture('mouse2')
  14.     else
  15.       @mouse_sprite.bitmap = RPG::Cache.picture('mouse1')
  16.     end
  17.   end
  18. end
复制代码

评分

参与人数 2星屑 +120 +2 收起 理由
RyanBern + 120 + 1 认可答案
zsefvv + 1 认可答案

查看全部评分

喵喵喵
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
1
星屑
985
在线时间
231 小时
注册时间
2006-2-3
帖子
82
 楼主| 发表于 2019-9-30 22:27:25 | 显示全部楼层
hyrious 发表于 2019-9-30 19:33
将此脚本插入鼠标脚本下方

谢谢大佬,可以用
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
79
在线时间
8 小时
注册时间
2019-10-10
帖子
6
发表于 2019-11-6 10:11:01 | 显示全部楼层
厉害啊!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-3-28 20:35

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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