查看: 70|回复: 0

[转载发布] SEP 全鼠标脚本 v0.93 update

[复制链接]
  • TA的每日心情
    开心
    5 天前
  • 签到天数: 33 天

    连续签到: 1 天

    [LV.5]常住居民I

    2022

    主题

    32

    回帖

    7144

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    0
    卡币
    5074
    OK点
    16
    积分
    7144
    发表于 同元一千年八月七日(秋) | 显示全部楼层 |阅读模式
    以为小500行能搞定了,尼玛又整了姐一千多行……Window_NameInput类神马,能不能不要辣么坑……

    虽然所有的scene和window类全部犁过了,但还是真怕哪些犄角旮旯里有漏掉的。

    0.93 update
    1. 增加对L/R/X/Y/Z按键的鼠标处理(其实就是按Ctrl和Alt修饰)
    2. 鼠标增加开关设置,可以在设置中指定开或者关,也可以设置为一个数,表示绑定到这个编号的开关
    3. 支持交换左右键

    注意插入的位置,默认系统插哪都行,SEP核心系统如果用了窗口增强要插在所有增强的后面,毕竟鼠标最重要的就是操作窗口

    RUBY 代码
    1. #==============================================================================
    2. # ■ SEP 全鼠标处理核心 v0.93 by SailCat
    3. #------------------------------------------------------------------------------
    4. #   方法:本脚本插入Main之前使用
    5. #   依赖:无
    6. #   版本:v0.93 (Build 180121)
    7. #   效果:
    8. #     1. 全鼠标响应(不含滚轮)
    9. #     2. 注入Input模块的update处理和trigger处理
    10. #     3. 默认设置中,单击左键等于按C,单击右键等于按B,单击中键等于按A
    11. #        按住CTRL键单击左/右键等于按R或L,按住ALT键单击左/右/中键等于按Z/Y/X
    12. #     4. 注入了对所有窗口(默认引擎中)以及战斗目标箭头的鼠标操作处理
    13. #     5. 地图上可以按住鼠标来移动
    14. #     6. 鼠标操作可以通过配置来开关
    15. #   配置:重复延迟和重复间隔速率,双击设定和行走设定,光标图片等
    16. #   冲突:其他类似脚本
    17. #   说明:
    18. #     1. 调用全鼠标方法为Mouse.press?(按键名称),表示对应的键处于按下状态。
    19. #        键名为以下5个之一:L(左)、R(右)、M(中)、X1(自定1)、X2(自定2)
    20. #     2. 上述press?也可替换为click?, repeat?, release?或trigger?,分别表示:
    21. #        单击(按下并松开一次),按住不放,松开瞬间,按下瞬间
    22. #     3. 双击并不是自动判定的,需要通过begin_dblclick和check_dblclick手动开启,
    23. #        然后用Mouse.dblclick?(按键名称)判定,这是为了避免误操作问题。
    24. #     4. 本脚本并不依赖窗口增强脚本,但如果你使用了窗口增强脚本,
    25. #        请将本脚本插入到窗口增强类脚本的后面。
    26. #==============================================================================
    27. #==============================================================================
    28. # ■ SailCat's 插件公用
    29. #==============================================================================
    30. module SailCat
    31.   $sailcat_import ||= {}
    32.   #--------------------------------------------------------------------------
    33.   # ● 脚本配置区
    34.   #--------------------------------------------------------------------------
    35.   module Mouse_Config
    36.     MOUSE_ENABLED = true          # 是否启用鼠标(true是,false否,数字绑定开关)
    37.     REPEAT_DELAY = 8              # 首次重复前的延迟值(帧)
    38.     REPEAT_SPEED = 4              # 每次重复点击的间隔(帧),越大越慢
    39.     DBLCLICK_TIME = 20            # 双击判定最长有效间隔(帧)
    40.     DBLCLICK_MOVE = 3             # 双击判定最多有效移动(像素)
    41.     C_DBLCLICK = false            # 按下C键是否要求双击
    42.     MOVE_DIR8 = false             # 是否为八方向行走
    43.     CURSOR_PIC = ""               # 鼠标指针图片,为空是默认的图片(白色箭头)
    44.     LEFT_HANDED = false           # 是否为左手鼠标(交换左右键)
    45.     #--------------------------------------------------------------------------
    46.     # ● 配置检查,请勿更改
    47.     #--------------------------------------------------------------------------
    48.     unless REPEAT_SPEED > 0
    49.       raise"重复点击的间隔不能低于1帧"
    50.     end
    51.     unless DBLCLICK_TIME > 0
    52.       raise"双击判定的间隔不能低于1帧"
    53.     end
    54.     unless DBLCLICK_MOVE >= 0
    55.       raise"双击判定的移动不能低于0像素"
    56.     end
    57.   end
    58.   #--------------------------------------------------------------------------
    59.   # ● 植入
    60.   #--------------------------------------------------------------------------
    61.   $sailcat_import[:Mouse] = 0.93
    62. end
    63. #==============================================================================
    64. # ■ 鼠标全局指针
    65. #==============================================================================
    66. $mouse_pointer = Sprite.new
    67. ifSailCat::Mouse_Config::CURSOR_PIC != ""
    68.   # 加载图片
    69.   $mouse_pointer.bitmap = RPG::Cache.picture(SailCat::Mouse_Config.CURSOR_PIC)
    70. else
    71.   # 绘制默认图片
    72.   $mouse_pointer.bitmap = Bitmap.new(13, 18)
    73.   black = Color.new(0, 0, 0, 255)
    74.   white = Color.new(255, 255, 255, 255)
    75.   for y in0..17
    76.     case y
    77.     when0..11
    78.       $mouse_pointer.bitmap.set_pixel(0, y, black)
    79.       $mouse_pointer.bitmap.fill_rect(1, y, y - 1, 1, white)if y > 1
    80.       $mouse_pointer.bitmap.set_pixel(y, y, black)
    81.     when12
    82.       $mouse_pointer.bitmap.set_pixel(0, y, black)
    83.       $mouse_pointer.bitmap.fill_rect(1, y, 4, 1, white)
    84.       $mouse_pointer.bitmap.fill_rect(5, y, 8, 1, black)
    85.     when13..17
    86.       $mouse_pointer.bitmap.set_pixel(0, y, black)
    87.       $mouse_pointer.bitmap.fill_rect(1, y, 16 - y, 1, white)if y < 16
    88.       $mouse_pointer.bitmap.set_pixel(17 - y, y, black)
    89.     end
    90.   end
    91. end
    92. # 设为可见,半透明,总在最上
    93. $mouse_pointer.visible = true
    94. $mouse_pointer.opacity = 160
    95. $mouse_pointer.z = 2147483647
    96. #==============================================================================
    97. # ■ 全鼠标处理核心
    98. #==============================================================================
    99. module Mouse
    100.   includeSailCat::Mouse_Config
    101.   #--------------------------------------------------------------------------
    102.   # ● 常量
    103.   #--------------------------------------------------------------------------
    104.   NONE, M, X1, X2 = 0, 4, 5, 6
    105.   L = LEFT_HANDED ? 2 : 1
    106.   R = LEFT_HANDED ? 1 : 2
    107.   #--------------------------------------------------------------------------
    108.   # ● API
    109.   #--------------------------------------------------------------------------
    110.   GetCursorPos = Win32API.new("user32", "GetCursorPos", "p", "i")
    111.   ScreenToClient = Win32API.new("user32", "ScreenToClient", "ip", "i")
    112.   GetActiveWindow = Win32API.new("user32", "GetActiveWindow", "", "i")
    113.   GetAsyncKeyState = Win32API.new("user32", "GetAsyncKeyState", "i", "i")
    114.   #--------------------------------------------------------------------------
    115.   # ● 鼠标按键和光标数据
    116.   #--------------------------------------------------------------------------
    117.   Flags = {}
    118.   Data = {:x => 0, :y => 0, :key => NONE, :frame => 0, :dx => 0, :dy => 0}
    119.   #--------------------------------------------------------------------------
    120.   # ● 鼠标是否可用
    121.   #--------------------------------------------------------------------------
    122.   defself.enabled?
    123.     if MOUSE_ENABLED.is_a?(Fixnum)
    124.       $game_switches ? $game_switches[MOUSE_ENABLED] : true
    125.     else
    126.       MOUSE_ENABLED
    127.     end
    128.   end
    129.   #--------------------------------------------------------------------------
    130.   # ● 更新鼠标输入,该方法每帧调用1次
    131.   #--------------------------------------------------------------------------
    132.   defself.update
    133.     if enabled?
    134.       s = [0, 0].pack("l*")
    135.       GetCursorPos.call(s)
    136.       ScreenToClient.call(hwnd, s)
    137.       Data[:x], Data[:y] = s.unpack("l*")
    138.       $mouse_pointer.visible = trueunless$mouse_pointer.visible
    139.       $mouse_pointer.x = Data[:x]
    140.       $mouse_pointer.y = Data[:y]
    141.       Data[:key] = NONE ifData[:frame] == -1
    142.       Data[:frame] += 1
    143.       Flags.each_keydo |k|
    144.         if GetAsyncKeyState.call(k) & 32768 != 0
    145.           Flags[k] += 1
    146.         else
    147.           Flags[k] >= 0 ? Flags[k] = -1 : Flags.delete(k)
    148.         end
    149.       end
    150.     elsif$mouse_pointer.visible
    151.       $mouse_pointer.visible = false
    152.       Data[:key] = NONE
    153.     end
    154.   end
    155.   #--------------------------------------------------------------------------
    156.   # ● 判断对应的键是否被按下
    157.   #--------------------------------------------------------------------------
    158.   defself.press?(key)
    159.     returnfalseunless enabled?
    160.     key = const_get(key)if key.is_a?(Symbol)
    161.     returntrueif Flags[key] && Flags[key] >= 0
    162.     GetAsyncKeyState.call(key) & 32768 != 0 ? (Flags[key] ||= 0; true) : false
    163.   end
    164.   #--------------------------------------------------------------------------
    165.   # ● 判断对应的键是否被松开
    166.   #--------------------------------------------------------------------------
    167.   defself.release?(key)
    168.     returnfalseunless enabled?
    169.     key = const_get(key)if key.is_a?(Symbol)
    170.     Flags[key] == -1
    171.   end
    172.   #--------------------------------------------------------------------------
    173.   # ● 判断对应的键是否被触发
    174.   #--------------------------------------------------------------------------
    175.   defself.trigger?(key)
    176.     returnfalseunless enabled?
    177.     key = const_get(key)if key.is_a?(Symbol)
    178.     Flags[key] ? Flags[key] == 0 : press?(key)
    179.   end
    180.   #--------------------------------------------------------------------------
    181.   # ● 判断对应的键是否被点击
    182.   #--------------------------------------------------------------------------
    183.   defself.click?(key)
    184.     returnfalseunless enabled?
    185.     key = const_get(key)if key.is_a?(Symbol)
    186.     Flags[key] ? release?(key) : (press?(key); false)
    187.   end
    188.   #--------------------------------------------------------------------------
    189.   # ● 判断对应的键是否被按住
    190.   #--------------------------------------------------------------------------
    191.   defself.repeat?(key)
    192.     returnfalseunless enabled?
    193.     key = const_get(key)if key.is_a?(Symbol)
    194.     Flags[key] ? (Flags[key] >= REPEAT_DELAY and(Flags[key] - REPEAT_DELAY) %
    195.       REPEAT_SPEED == 0) : press?(key)
    196.   end
    197.   #--------------------------------------------------------------------------
    198.   # ● 判断对应的键是否被双击
    199.   #--------------------------------------------------------------------------
    200.   defself.dblclick?(key)
    201.     returnfalseunless enabled?
    202.     key = const_get(key)if key.is_a?(Symbol)
    203.     Data[:key] == key andData[:frame] == -1
    204.   end
    205.   #--------------------------------------------------------------------------
    206.   # ● 获得窗口句柄
    207.   #--------------------------------------------------------------------------
    208.   defself.hwnd
    209.     @hwnd ||= GetActiveWindow.call
    210.   end
    211.   #--------------------------------------------------------------------------
    212.   # ● 获得鼠标指针坐标
    213.   #--------------------------------------------------------------------------
    214.   defself.x;       Data[:x];            end
    215.   defself.y;       Data[:y];            end
    216.   #--------------------------------------------------------------------------
    217.   # ● 双击开始处理
    218.   #--------------------------------------------------------------------------
    219.   defself.begin_dblclick(key)
    220.     key = const_get(key)if key.is_a?(Symbol)
    221.     Data[:key] = key
    222.     Data[:frame] = 0
    223.     Data[:dx] = x
    224.     Data[:dy] = y
    225.     # 按的是左键,不要求C键双击的情况下,判定成功
    226.     Data[:frame] = -1unless C_DBLCLICK or key != L
    227.   end
    228.   #--------------------------------------------------------------------------
    229.   # ● 双击检查处理
    230.   #--------------------------------------------------------------------------
    231.   defself.check_dblclick(key)
    232.     key = const_get(key)if key.is_a?(Symbol)
    233.     # 如果按的键不是要检查的双击键,双击失败
    234.     return begin_dblclick(key)ifData[:key] != key
    235.     # 如果按的键间隔时间过长了,双击失败
    236.     return begin_dblclick(key)ifData[:frame] > DBLCLICK_TIME
    237.     # 如果两次按键中鼠标移动太多了,双击失败
    238.     return begin_dblclick(key)if(x - Data[:dx]).abs > DBLCLICK_MOVE
    239.     return begin_dblclick(key)if(y - Data[:dy]).abs > DBLCLICK_MOVE
    240.     # 设置双击标记
    241.     Data[:frame] = -1
    242.   end
    243. end
    244. #==============================================================================
    245. # ■ Input 模块的注入
    246. #==============================================================================
    247. module Input
    248.   class = dy.abs
    249.           dx < 0 ? turn_left : turn_right
    250.         else
    251.           dy < 0 ? turn_up : turn_down
    252.         end
    253.       when6
    254.         move_right
    255.       when7
    256.         move_upper_left
    257.       when8
    258.         move_up
    259.       when9
    260.         move_upper_right
    261.       end
    262.       Mouse.check_dblclick(:L)if Mouse.click?(:L)
    263.     end
    264.   end
    265.   #--------------------------------------------------------------------------
    266.   # ● 获得鼠标的指向四方向
    267.   #--------------------------------------------------------------------------
    268.   def mouse_dir4
    269.     return0unless Mouse.press?(:L)
    270.     dx = Mouse.x - self.screen_x
    271.     dy = Mouse.y - self.screen_y + 16
    272.     return5unless dx.abs > 16or dy.abs > 16
    273.     dx.abs < dy.abs ? [8, 5, 2][(dy  0) + 1] : [4, 5, 6][(dx  0) + 1]
    274.   end
    275.   #--------------------------------------------------------------------------
    276.   # ● 获得鼠标的指向八方向
    277.   #--------------------------------------------------------------------------
    278.   def mouse_dir8
    279.     return0unless Mouse.press?(:L)
    280.     dx = Mouse.x - self.screen_x
    281.     dy = Mouse.y - self.screen_y + 16
    282.     return5unless dx.abs > 16or dy.abs > 16
    283.     angle = (Math.atan2(dy, dx) / Math::PI * 180 + 202.5).round
    284.     [4, 7, 8, 9, 6, 3, 2, 1][angle / 45 & 7]
    285.   end
    286. end
    287. #==============================================================================
    288. # ■ Window_Base
    289. #==============================================================================
    290. class Window_Base
    291.   #--------------------------------------------------------------------------
    292.   # ● 方法重定义
    293.   #--------------------------------------------------------------------------
    294.   unless method_defined?(:sailcat_sepmouse_update)
    295.     alias sailcat_sepmouse_update update
    296.   end
    297.   #--------------------------------------------------------------------------
    298.   # ● 相对于本窗口的坐标变换
    299.   #--------------------------------------------------------------------------
    300.   def mouse_x;          Mouse.x - x;              end
    301.   def mouse_y;          Mouse.y - y;              end
    302.   #--------------------------------------------------------------------------
    303.   # ● 相对于窗口内容的坐标变换
    304.   #--------------------------------------------------------------------------
    305.   def contents_x;       mouse_x - 16 + ox;        end
    306.   def contents_y;       mouse_y - 16 + oy;        end
    307.   #--------------------------------------------------------------------------
    308.   # ● 更新
    309.   #--------------------------------------------------------------------------
    310.   def update
    311.     update_mouse if respond_to_mouse?
    312.     sailcat_sepmouse_update
    313.   end
    314.   #--------------------------------------------------------------------------
    315.   # ● 指针位置判定
    316.   #--------------------------------------------------------------------------
    317.   def mouse_over?(rect = Rect.new(x, y, width, height))
    318.     mouse_x.between?(rect.x, rect.x + rect.width - 1)and
    319.     mouse_y.between?(rect.y, rect.y + rect.height - 1)
    320.   end
    321.   #--------------------------------------------------------------------------
    322.   # ● 响应鼠标判定
    323.   #--------------------------------------------------------------------------
    324.   def respond_to_mouse?
    325.     contents != niland visible
    326.   end
    327.   #--------------------------------------------------------------------------
    328.   # ● 响应选择判定
    329.   #--------------------------------------------------------------------------
    330.   def respond_to_select?
    331.     false
    332.   end
    333.   #--------------------------------------------------------------------------
    334.   # ● 更新鼠标操作
    335.   #--------------------------------------------------------------------------
    336.   def update_mouse
    337.     update_mouse_scroll unlessself.is_a?(Window_Selectable)andnot active
    338.     update_mouse_select if respond_to_select?
    339.     update_cursor_rect if respond_to?(:update_cursor_rect)
    340.   end
    341.   #--------------------------------------------------------------------------
    342.   # ● 更新鼠标滚动窗口内容
    343.   #--------------------------------------------------------------------------
    344.   def update_mouse_scroll
    345.     # 内容可以水平滚动的情况下
    346.     if contents.width > width - 32
    347.       # 如果单击左右箭头区域
    348.       if Mouse.repeat?(:L)and mouse_y >= 16and mouse_y < height - 16
    349.         if mouse_x >= 0and mouse_x < 16
    350.           # 向左侧滚动窗口内容
    351.           scroll_left
    352.         elsif mouse_x >= width - 16and mouse_x < width
    353.           # 向右侧滚动窗口内容
    354.           scroll_right
    355.         end
    356.       end
    357.     end
    358.     # 内容可以垂直滚动的情况下
    359.     if contents.height > height - 32
    360.       # 如果单击上下箭头区域
    361.       if Mouse.repeat?(:L)and mouse_x >= 16and mouse_x < width - 16
    362.         if mouse_y >= 0and mouse_y < 16
    363.           # 向上方滚动窗口内容
    364.           scroll_up
    365.         elsif mouse_y >= height - 16and mouse_y < height
    366.           # 向下方滚动窗口内容
    367.           scroll_down
    368.         end
    369.       end
    370.     end
    371.   end
    372.   #--------------------------------------------------------------------------
    373.   # ● 滚动的单位X值
    374.   #--------------------------------------------------------------------------
    375.   def scroll_x
    376.     Font.default_size
    377.   end
    378.   #--------------------------------------------------------------------------
    379.   # ● 滚动的单位Y值
    380.   #--------------------------------------------------------------------------
    381.   def scroll_y
    382.     returnself.line_heightif respond_to?(:line_height)
    383.     32
    384.   end
    385.   #--------------------------------------------------------------------------
    386.   # ● 向左滚动
    387.   #--------------------------------------------------------------------------
    388.   def scroll_left
    389.     self.ox = [ox - scroll_x, 0].max
    390.   end
    391.   #--------------------------------------------------------------------------
    392.   # ● 向右滚动
    393.   #--------------------------------------------------------------------------
    394.   def scroll_right
    395.     # 保证显示整字
    396.     d = (contents.width + 32 - width) % scroll_x
    397.     d = scroll_x - d if d > 0
    398.     self.ox = [ox + scroll_x, contents.width + 32 - width + d].min
    399.   end
    400.   #--------------------------------------------------------------------------
    401.   # ● 向上滚动
    402.   #--------------------------------------------------------------------------
    403.   def scroll_up
    404.     self.oy = [oy - scroll_y, 0].max
    405.   end
    406.   #--------------------------------------------------------------------------
    407.   # ● 向下滚动
    408.   #--------------------------------------------------------------------------
    409.   def scroll_down
    410.     # 保证显示整行
    411.     d = (contents.height + 32 - height) % scroll_y
    412.     d = scroll_y - d if d > 0
    413.     self.oy = ([oy + scroll_y, contents.height + 32 - height + d].min)
    414.   end
    415. end
    416. #==============================================================================
    417. # ■ Window_Selectable
    418. #==============================================================================
    419. class Window_Selectable
    420.   #--------------------------------------------------------------------------
    421.   # ● 响应选择判定
    422.   #--------------------------------------------------------------------------
    423.   def respond_to_select?
    424.     active
    425.   end
    426.   #--------------------------------------------------------------------------
    427.   # ● 响应鼠标选择
    428.   #--------------------------------------------------------------------------
    429.   def update_mouse_select
    430.     # 点击内容有效区域的情况下
    431.     if mouse_over?(Rect.new(16, 16, width - 32, height - 32))
    432.       # 点击左键的情况下,检查点击项目
    433.       update_click_select if Mouse.click?(:L)
    434.       # 按住左键的情况下,检查选择项目
    435.       update_check_select if Mouse.press?(:L)
    436.     end
    437.   end
    438.   #--------------------------------------------------------------------------
    439.   # ● 检查点击项目
    440.   #--------------------------------------------------------------------------
    441.   def update_click_select
    442.     # 如果鼠标所在的项就是当前项,检查双击
    443.     Mouse.check_dblclick(:L)if click_index == @index
    444.   end
    445.   #--------------------------------------------------------------------------
    446.   # ● 检查选择项目
    447.   #--------------------------------------------------------------------------
    448.   def update_check_select
    449.     # 如果被点击的项并非当前项
    450.     if click_index != @index
    451.       # 演奏光标SE
    452.       $game_system.se_play($data_system.cursor_se)
    453.       # 选中当前项
    454.       self.index = [[click_index, 0].max, @item_max - 1].min
    455.     end
    456.   end
    457.   #--------------------------------------------------------------------------
    458.   # ● 更新向上滚动
    459.   #--------------------------------------------------------------------------
    460.   def scroll_up
    461.     super
    462.     # 移到区域外的情况下,带动光标一起移动
    463.     if@index / @column_max > self.top_row + (self.page_row_max - 1)
    464.       $game_system.se_play($data_system.cursor_se)
    465.       self.index -= @column_max
    466.     end
    467.   end
    468.   #--------------------------------------------------------------------------
    469.   # ● 更新向下滚动
    470.   #--------------------------------------------------------------------------
    471.   def scroll_down
    472.     super
    473.     # 移到区域外的情况下,带动光标一起移动
    474.     if@index / @column_max < self.top_row
    475.       $game_system.se_play($data_system.cursor_se)
    476.       self.index = [@index + @column_max, @item_max - 1].min
    477.     end
    478.   end
    479.   #--------------------------------------------------------------------------
    480.   # ● 滚动的单位X值
    481.   #--------------------------------------------------------------------------
    482.   def scroll_x
    483.     padding = respond_to?(:cursor_padding) ? cursor_padding : 32
    484.     (contents.width + padding) / @column_max
    485.   end
    486.   #--------------------------------------------------------------------------
    487.   # ● 滚动的单位Y值
    488.   #--------------------------------------------------------------------------
    489.   def scroll_y
    490.     respond_to?(:item_height) ? self.item_height : super
    491.   end
    492.   #--------------------------------------------------------------------------
    493.   # ● 取得光标所指的项目
    494.   #--------------------------------------------------------------------------
    495.   def click_index
    496.     [@item_max - 1, contents_y / scroll_y * @column_max +
    497.       contents_x / scroll_x].min
    498.   end
    499. end
    500. #==============================================================================
    501. # ■ Window_MenuStatus
    502. #==============================================================================
    503. class Window_MenuStatus
    504.   #--------------------------------------------------------------------------
    505.   # ● 项目的行高,但已被窗口增强核心重新定义的情况例外
    506.   #--------------------------------------------------------------------------
    507.   unless$sailcat_import[:WindowCore]
    508.     def item_height;  116;  end
    509.   end
    510. end
    511. #==============================================================================
    512. # ■ Window_Target
    513. #==============================================================================
    514. class Window_Target
    515.   #--------------------------------------------------------------------------
    516.   # ● 项目的行高,但已被窗口增强核心重新定义的情况例外
    517.   #--------------------------------------------------------------------------
    518.   unless$sailcat_import[:WindowCore]
    519.     def item_height;  116;  end
    520.   end
    521. end
    522. #==============================================================================
    523. # ■ Window_NameInput
    524. #==============================================================================
    525. class Window_NameInput
    526.   #--------------------------------------------------------------------------
    527.   # ● 响应选择判定
    528.   #--------------------------------------------------------------------------
    529.   def respond_to_select?
    530.     active
    531.   end
    532.   #--------------------------------------------------------------------------
    533.   # ● 响应鼠标选择
    534.   #--------------------------------------------------------------------------
    535.   def update_mouse_select
    536.     # 点击内容有效区域的情况下
    537.     if mouse_over?(Rect.new(16, 16, width - 32, height - 32))
    538.       # 点击左键的情况下,检查点击项目
    539.       update_click_select if Mouse.click?(:L)
    540.       # 按住左键的情况下,检查选择项目
    541.       update_check_select if Mouse.press?(:L)
    542.     end
    543.   end
    544.   #--------------------------------------------------------------------------
    545.   # ● 检查点击项目
    546.   #--------------------------------------------------------------------------
    547.   def update_click_select
    548.     # 如果鼠标所在的项就是当前项,处理双击
    549.     if click_index == @index
    550.       Mouse.begin_dblclick(:L)unless on_command?
    551.       Mouse.check_dblclick(:L)
    552.     end
    553.   end
    554.   #--------------------------------------------------------------------------
    555.   # ● 检查选择项目
    556.   #--------------------------------------------------------------------------
    557.   def update_check_select
    558.     # 如果被点击的项并非当前项
    559.     if click_index != @indexand click_index >= 0
    560.       # 演奏光标SE
    561.       $game_system.se_play($data_system.cursor_se)
    562.       # 选中当前项
    563.       @index = [[click_index, 0].max, item_max - 1].min
    564.     end
    565.   end
    566.   #--------------------------------------------------------------------------
    567.   # ● [确定]的判定
    568.   #--------------------------------------------------------------------------
    569.   def on_command?
    570.     @index >= item_max - 1
    571.   end
    572.   #--------------------------------------------------------------------------
    573.   # ● 最大项目数
    574.   #--------------------------------------------------------------------------
    575.   def item_max
    576.     if respond_to?(:choices_max)
    577.       choices_max
    578.     elsif$sailcat_import[:WindowCore]
    579.       CHARACTER_TABLE_NORMAL.size
    580.     else
    581.       CHARACTER_TABLE.size + 1
    582.     end
    583.   end
    584.   #--------------------------------------------------------------------------
    585.   # ● 取得光标所指的项目
    586.   #--------------------------------------------------------------------------
    587.   def click_index
    588.     mx, my = mouse_x - 16, mouse_y - 16
    589.     0.upto(item_max - 1)do |i|
    590.       r = item_rect(i)
    591.       if(mx - r.x).between?(0, r.width - 1)and
    592.         (my - r.y).between?(0, r.height - 1)
    593.         return i
    594.       end
    595.     end
    596.     -1
    597.   end
    598.   #--------------------------------------------------------------------------
    599.   # ● 取得某项的光标区域
    600.   #--------------------------------------------------------------------------
    601.   def item_rect(index)
    602.     last_index = @index
    603.     @index = index
    604.     update_cursor_rect
    605.     rect = cursor_rect.clone
    606.     @index = last_index
    607.     update_cursor_rect
    608.     rect
    609.   end
    610. end
    611. #==============================================================================
    612. # ■ Window_InputNumber
    613. #==============================================================================
    614. class Window_InputNumber
    615.   #--------------------------------------------------------------------------
    616.   # ● 方法重定义
    617.   #--------------------------------------------------------------------------
    618.   unless method_defined?(:sailcat_sepmouse_initialize)
    619.     alias sailcat_sepmouse_initialize initialize
    620.     alias sailcat_sepmouse_update_cursor_rect update_cursor_rect
    621.   end
    622.   #--------------------------------------------------------------------------
    623.   # ● 初始化对像
    624.   #     digits_max : 位数
    625.   #--------------------------------------------------------------------------
    626.   def initialize(digits_max)
    627.     @up_arrow = Sprite.new
    628.     @down_arrow = Sprite.new
    629.     sailcat_sepmouse_initialize(digits_max)
    630.     @up_arrow.bitmap = @down_arrow.bitmap = self.windowskin
    631.     @up_arrow.src_rect = Rect.new(self.windowskin.width - 40, 16, 16, 7)
    632.     @down_arrow.src_rect = Rect.new(self.windowskin.width - 40, 41, 16, 7)
    633.     @up_arrow.z = @down_arrow.z = z + 1
    634.   end
    635.   #--------------------------------------------------------------------------
    636.   # ● 设置内容不透明度
    637.   #--------------------------------------------------------------------------
    638.   def contents_opacity=(opacity)
    639.     super
    640.     @up_arrow.opacity = @down_arrow.opacity = opacity
    641.   end
    642.   #--------------------------------------------------------------------------
    643.   # ● 更新光标矩形
    644.   #--------------------------------------------------------------------------
    645.   def update_cursor_rect
    646.     sailcat_sepmouse_update_cursor_rect
    647.     offset = $sailcat_import[:WindowCore] ? 24 + @cursor_width >> 1 : 16
    648.     @up_arrow.x = @down_arrow.x = x + @index * @cursor_width + offset
    649.     @up_arrow.y = y + 7
    650.     @down_arrow.y = y + height - 14
    651.   end
    652.   #--------------------------------------------------------------------------
    653.   # ● 释放
    654.   #--------------------------------------------------------------------------
    655.   def dispose
    656.     @up_arrow.dispose
    657.     @down_arrow.dispose
    658.     super
    659.   end
    660.   #--------------------------------------------------------------------------
    661.   # ● 响应选择判定
    662.   #--------------------------------------------------------------------------
    663.   def respond_to_select?
    664.     active
    665.   end
    666.   #--------------------------------------------------------------------------
    667.   # ● 响应鼠标选择
    668.   #--------------------------------------------------------------------------
    669.   def update_mouse_select
    670.     # 点击内容有效区域的情况下
    671.     if mouse_over?(Rect.new(16, 16, width - 32, height - 32))
    672.       # 点击左键的情况下,检查点击项目
    673.       update_click_select if Mouse.click?(:L)
    674.       # 按住左键的情况下,检查选择项目
    675.       update_check_select if Mouse.press?(:L)
    676.     # 点击上箭头的情况下
    677.     elsif Mouse.x.between?(@up_arrow.x, @up_arrow.x + 15)and
    678.       Mouse.y.between?(@up_arrow.y, @up_arrow.y + 6)
    679.       update_value(+2)if Mouse.repeat?(:L)
    680.     # 点击下箭头的情况下
    681.     elsif Mouse.x.between?(@down_arrow.x, @down_arrow.x + 15)and
    682.       Mouse.y.between?(@down_arrow.y, @down_arrow.y + 6)
    683.       update_value(-2)if Mouse.repeat?(:L)
    684.     end
    685.   end
    686.   #--------------------------------------------------------------------------
    687.   # ● 更新数值
    688.   #--------------------------------------------------------------------------
    689.   unless$sailcat_import[:WindowCore]
    690.     def update_value(delta)
    691.       $game_system.se_play($data_system.cursor_se)
    692.       place = 10 ** (@digits_max - 1 - @index)
    693.       n = @number / place % 10
    694.       @number -= n * place
    695.       n = (n + 1) % 10if delta > 0
    696.       n = (n + 9) % 10if delta < 0
    697.       @number += n * place
    698.       refresh
    699.     end
    700.   end
    701.   #--------------------------------------------------------------------------
    702.   # ● 检查点击项目
    703.   #--------------------------------------------------------------------------
    704.   def update_click_select
    705.     # 如果鼠标所在的项就是当前项,检查双击
    706.     Mouse.check_dblclick(:L)if click_index == @index
    707.   end
    708.   #--------------------------------------------------------------------------
    709.   # ● 检查选择项目
    710.   #--------------------------------------------------------------------------
    711.   def update_check_select
    712.     # 如果被点击的项并非当前项
    713.     if click_index != @index
    714.       # 演奏光标SE
    715.       $game_system.se_play($data_system.cursor_se)
    716.       # 选中当前项
    717.       @index = [[click_index, 0].max, @digits_max - 1].min
    718.     end
    719.   end
    720.   #--------------------------------------------------------------------------
    721.   # ● 取得光标所指的项目
    722.   #--------------------------------------------------------------------------
    723.   def click_index
    724.     contents_x / @cursor_width
    725.   end
    726. end
    727. #==============================================================================
    728. # ■ Window_Message
    729. #==============================================================================
    730. class Window_Message
    731.   #--------------------------------------------------------------------------
    732.   # ● 响应选择判定
    733.   #--------------------------------------------------------------------------
    734.   def respond_to_select?
    735.     contents_opacity == 255and@input_number_window.nil?
    736.   end
    737.   #--------------------------------------------------------------------------
    738.   # ● 响应鼠标选择
    739.   #--------------------------------------------------------------------------
    740.   def update_mouse_select
    741.     # 当前是消息结束待机的情况下
    742.     if pause or(@text andnot@text.empty?)
    743.       # 左键单击视同双击
    744.       if Mouse.click?(:L)
    745.         Mouse.begin_dblclick(:L)
    746.         Mouse.check_dblclick(:L)
    747.       end
    748.     # 当前是处理选择项的情况下,执行原处理
    749.     elsif active
    750.       super
    751.     end
    752.   end
    753.   #--------------------------------------------------------------------------
    754.   # ● 检查选择项目
    755.   #--------------------------------------------------------------------------
    756.   def update_check_select
    757.     # 点击项不在列表区域的情况下,返回
    758.     returnif click_index < 0
    759.     super
    760.   end
    761.   #--------------------------------------------------------------------------
    762.   # ● 取得光标所指的项目
    763.   #--------------------------------------------------------------------------
    764.   def click_index
    765.     # 变换坐标为相对于内容的值
    766.     mx, my = mouse_x - 16, mouse_y - 16 - $game_temp.choice_start * scroll_y
    767.     # 多列的情况下考虑列间距
    768.     padding = respond_to?(:cursor_padding) ? cursor_padding : 32
    769.     [@item_max - 1, (self.top_row + my / scroll_y) * @column_max +
    770.       mx / ((contents.width + padding) / @column_max)].min
    771.   end
    772. end
    773. #==============================================================================
    774. # ■ Arrow_Base
    775. #==============================================================================
    776. class Arrow_Base
    777.   #--------------------------------------------------------------------------
    778.   # ● 方法重定义
    779.   #--------------------------------------------------------------------------
    780.   unless method_defined?(:sailcat_sepmouse_update)
    781.     alias sailcat_sepmouse_update update
    782.   end
    783.   #--------------------------------------------------------------------------
    784.   # ● 更新
    785.   #--------------------------------------------------------------------------
    786.   def update
    787.     update_mouse
    788.     sailcat_sepmouse_update
    789.   end
    790.   #--------------------------------------------------------------------------
    791.   # ● 更新鼠标处理
    792.   #--------------------------------------------------------------------------
    793.   def update_mouse
    794.     # 点击左键,指向有效的情况下
    795.     if(Mouse.trigger?(:L)or Mouse.release?(:L))and click_index >= 0
    796.       # 点击当前指向战斗者的情况下
    797.       if click_index == @index
    798.         # 执行双击检查
    799.         Mouse.check_dblclick(:L)if Mouse.click?(:L)
    800.       # 点击的不是当前战斗者的情况下
    801.       else
    802.         # 演奏光标 SE
    803.         $game_system.se_play($data_system.cursor_se)
    804.         @index = click_index
    805.         # 开始准备双击
    806.         Mouse.begin_dblclick(:L)if Mouse.click?(:L)
    807.       end
    808.     end
    809.   end
    810.   #--------------------------------------------------------------------------
    811.   # ● 取得光标所指的项目
    812.   #--------------------------------------------------------------------------
    813.   def click_index
    814.     members.sort{|a, b| b.screen_z - a.screen_z}.eachdo |c|
    815.       nextif c.is_a?(Game_Enemy)andnot c.exist?
    816.       bitmap = RPG::Cache.battler(c.battler_name, c.battler_hue)
    817.       x = c.screen_x - (bitmap.width >> 1)
    818.       y = c.screen_y - bitmap.height
    819.       if Mouse.x.between?(x, x + bitmap.width - 1)and
    820.         Mouse.y.between?(y, y + bitmap.height - 1)
    821.         return c.index
    822.       end
    823.     end
    824.     return-1
    825.   end
    826. end
    827. #==============================================================================
    828. # ■ Arrow_Enemy
    829. #==============================================================================
    830. class Arrow_Enemy
    831.   #--------------------------------------------------------------------------
    832.   # ● 队伍成员
    833.   #--------------------------------------------------------------------------
    834.   def members;          $game_troop.enemies;          end
    835. end
    836. #==============================================================================
    837. # ■ Arrow_Actor
    838. #==============================================================================
    839. class Arrow_Actor
    840.   #--------------------------------------------------------------------------
    841.   # ● 队伍成员
    842.   #--------------------------------------------------------------------------
    843.   def members;          $game_party.actors;           end
    844. end
    845. #==============================================================================
    846. # ■ Scene_File
    847. #==============================================================================
    848. class Scene_File
    849.   #--------------------------------------------------------------------------
    850.   # ● 方法重定义
    851.   #--------------------------------------------------------------------------
    852.   unless method_defined?(:sailcat_sepmouse_update)
    853.     alias sailcat_sepmouse_update update
    854.   end
    855.   #--------------------------------------------------------------------------
    856.   # ● 更新
    857.   #--------------------------------------------------------------------------
    858.   def update
    859.     update_mouse
    860.     sailcat_sepmouse_update
    861.   end
    862.   #--------------------------------------------------------------------------
    863.   # ● 更新鼠标处理
    864.   #--------------------------------------------------------------------------
    865.   def update_mouse
    866.     # 点击左键,窗口有效的情况下
    867.     if(Mouse.press?(:L)or Mouse.release?(:L))and click_index >= 0
    868.       # 如果被点击的项就是当前项
    869.       if click_index + (@top_index || 0) == @file_index
    870.         # 执行双击检查
    871.         Mouse.check_dblclick(:L)if Mouse.click?(:L)
    872.       # 如果被点击的项并非当前项
    873.       elsif@savefile_windows[click_index].is_a?(Window_SaveFile)
    874.         # 演奏光标SE
    875.         $game_system.se_play($data_system.cursor_se)
    876.         # 选中当前项
    877.         @savefile_windows[@file_index % 4].selected = false
    878.         @file_index = [[click_index, 0].max, @savefile_windows.size - 1].min +
    879.           (@top_index || 0)
    880.         @savefile_windows[@file_index % 4].selected = true
    881.         # 开始准备双击
    882.         Mouse.begin_dblclick(:L)if Mouse.click?(:L)
    883.       end
    884.     end
    885.   end
    886.   #--------------------------------------------------------------------------
    887.   # ● 取得光标所指的项目
    888.   #--------------------------------------------------------------------------
    889.   def click_index
    890.     @savefile_windows.each_with_indexdo |w, i|
    891.       return i if w.mouse_over?
    892.     end
    893.     return-1
    894.   end
    895. end
    896. #==============================================================================
    897. # ■ Scene_Battle
    898. #==============================================================================
    899. class Scene_Battle
    900.   #--------------------------------------------------------------------------
    901.   # ● 方法重定义
    902.   #--------------------------------------------------------------------------
    903.   unless method_defined?(:sailcat_sepmouse_update_phase5)
    904.     alias sailcat_sepmouse_update_phase5 update_phase5
    905.   end
    906.   #--------------------------------------------------------------------------
    907.   # ● 画面更新 (结束战斗回合)
    908.   #--------------------------------------------------------------------------
    909.   def update_phase5
    910.     sailcat_sepmouse_update_phase5
    911.     update_mouse_phase5
    912.   end
    913.   #--------------------------------------------------------------------------
    914.   # ● 更新鼠标处理 (结束战斗回合)
    915.   #--------------------------------------------------------------------------
    916.   def update_mouse_phase5
    917.     # 等待计数已归 0 ,按左或右键的情况下
    918.     if@phase5_wait_count == 0and(Mouse.click?(:L)or Mouse.click?(:R))
    919.       # 战斗结束
    920.       battle_end(0)
    921.     end
    922.   end
    923. end
    924. #==============================================================================
    925. # ■ Scene_Name
    926. #==============================================================================
    927. class Scene_Name
    928.   #--------------------------------------------------------------------------
    929.   # ● 方法重定义
    930.   #--------------------------------------------------------------------------
    931.   unless method_defined?(:sailcat_sepmouse_update)
    932.     alias sailcat_sepmouse_update update
    933.   end
    934.   #--------------------------------------------------------------------------
    935.   # ● 更新
    936.   #--------------------------------------------------------------------------
    937.   def update
    938.     update_mouse
    939.     sailcat_sepmouse_update
    940.   end
    941.   #--------------------------------------------------------------------------
    942.   # ● 更新鼠标处理
    943.   #--------------------------------------------------------------------------
    944.   def update_mouse
    945.     unless$sailcat_import[:WindowCore]
    946.       # 右击鼠标的情况下
    947.       if Mouse.click?(:R)and@edit_window.index > 0
    948.         # 演奏取消 SE
    949.         $game_system.se_play($data_system.cancel_se)
    950.         # 删除文字
    951.         @edit_window.back
    952.       end
    953.     end
    954.   end
    955. end
    956. #==============================================================================
    957. # ■ Scene_Gameover
    958. #==============================================================================
    959. class Scene_Gameover
    960.   #--------------------------------------------------------------------------
    961.   # ● 方法重定义
    962.   #--------------------------------------------------------------------------
    963.   unless method_defined?(:sailcat_sepmouse_update)
    964.     alias sailcat_sepmouse_update update
    965.   end
    966.   #--------------------------------------------------------------------------
    967.   # ● 更新
    968.   #--------------------------------------------------------------------------
    969.   def update
    970.     update_mouse
    971.     sailcat_sepmouse_update
    972.   end
    973.   #--------------------------------------------------------------------------
    974.   # ● 更新鼠标处理
    975.   #--------------------------------------------------------------------------
    976.   def update_mouse
    977.     # 点击鼠标左键或右键的情况下
    978.     if Mouse.click?(:L)or Mouse.click?(:R)
    979.       # 切换到标题画面
    980.       $scene = Scene_Title.new
    981.     end
    982.   end
    983. end
    复制代码


                 本帖来自P1论坛作者king,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=405063  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
    天天去同能,天天有童年!
    回复 论坛版权

    使用道具 举报

    ahome_bigavatar:guest
    ahome_bigavatar:welcomelogin
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2024-5-3 06:46 , Processed in 0.054191 second(s), 43 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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