TA的每日心情 | 开心 5 天前 |
---|
签到天数: 33 天 连续签到: 1 天 [LV.5]常住居民I
管理员
- 积分
- 7144
|
以为小500行能搞定了,尼玛又整了姐一千多行……Window_NameInput类神马,能不能不要辣么坑……
虽然所有的scene和window类全部犁过了,但还是真怕哪些犄角旮旯里有漏掉的。
0.93 update
1. 增加对L/R/X/Y/Z按键的鼠标处理(其实就是按Ctrl和Alt修饰)
2. 鼠标增加开关设置,可以在设置中指定开或者关,也可以设置为一个数,表示绑定到这个编号的开关
3. 支持交换左右键
注意插入的位置,默认系统插哪都行,SEP核心系统如果用了窗口增强要插在所有增强的后面,毕竟鼠标最重要的就是操作窗口
RUBY 代码 - #==============================================================================
- # ■ SEP 全鼠标处理核心 v0.93 by SailCat
- #------------------------------------------------------------------------------
- # 方法:本脚本插入Main之前使用
- # 依赖:无
- # 版本:v0.93 (Build 180121)
- # 效果:
- # 1. 全鼠标响应(不含滚轮)
- # 2. 注入Input模块的update处理和trigger处理
- # 3. 默认设置中,单击左键等于按C,单击右键等于按B,单击中键等于按A
- # 按住CTRL键单击左/右键等于按R或L,按住ALT键单击左/右/中键等于按Z/Y/X
- # 4. 注入了对所有窗口(默认引擎中)以及战斗目标箭头的鼠标操作处理
- # 5. 地图上可以按住鼠标来移动
- # 6. 鼠标操作可以通过配置来开关
- # 配置:重复延迟和重复间隔速率,双击设定和行走设定,光标图片等
- # 冲突:其他类似脚本
- # 说明:
- # 1. 调用全鼠标方法为Mouse.press?(按键名称),表示对应的键处于按下状态。
- # 键名为以下5个之一:L(左)、R(右)、M(中)、X1(自定1)、X2(自定2)
- # 2. 上述press?也可替换为click?, repeat?, release?或trigger?,分别表示:
- # 单击(按下并松开一次),按住不放,松开瞬间,按下瞬间
- # 3. 双击并不是自动判定的,需要通过begin_dblclick和check_dblclick手动开启,
- # 然后用Mouse.dblclick?(按键名称)判定,这是为了避免误操作问题。
- # 4. 本脚本并不依赖窗口增强脚本,但如果你使用了窗口增强脚本,
- # 请将本脚本插入到窗口增强类脚本的后面。
- #==============================================================================
- #==============================================================================
- # ■ SailCat's 插件公用
- #==============================================================================
- module SailCat
- $sailcat_import ||= {}
- #--------------------------------------------------------------------------
- # ● 脚本配置区
- #--------------------------------------------------------------------------
- module Mouse_Config
- MOUSE_ENABLED = true # 是否启用鼠标(true是,false否,数字绑定开关)
- REPEAT_DELAY = 8 # 首次重复前的延迟值(帧)
- REPEAT_SPEED = 4 # 每次重复点击的间隔(帧),越大越慢
- DBLCLICK_TIME = 20 # 双击判定最长有效间隔(帧)
- DBLCLICK_MOVE = 3 # 双击判定最多有效移动(像素)
- C_DBLCLICK = false # 按下C键是否要求双击
- MOVE_DIR8 = false # 是否为八方向行走
- CURSOR_PIC = "" # 鼠标指针图片,为空是默认的图片(白色箭头)
- LEFT_HANDED = false # 是否为左手鼠标(交换左右键)
- #--------------------------------------------------------------------------
- # ● 配置检查,请勿更改
- #--------------------------------------------------------------------------
- unless REPEAT_SPEED > 0
- raise"重复点击的间隔不能低于1帧"
- end
- unless DBLCLICK_TIME > 0
- raise"双击判定的间隔不能低于1帧"
- end
- unless DBLCLICK_MOVE >= 0
- raise"双击判定的移动不能低于0像素"
- end
- end
- #--------------------------------------------------------------------------
- # ● 植入
- #--------------------------------------------------------------------------
- $sailcat_import[:Mouse] = 0.93
- end
- #==============================================================================
- # ■ 鼠标全局指针
- #==============================================================================
- $mouse_pointer = Sprite.new
- ifSailCat::Mouse_Config::CURSOR_PIC != ""
- # 加载图片
- $mouse_pointer.bitmap = RPG::Cache.picture(SailCat::Mouse_Config.CURSOR_PIC)
- else
- # 绘制默认图片
- $mouse_pointer.bitmap = Bitmap.new(13, 18)
- black = Color.new(0, 0, 0, 255)
- white = Color.new(255, 255, 255, 255)
- for y in0..17
- case y
- when0..11
- $mouse_pointer.bitmap.set_pixel(0, y, black)
- $mouse_pointer.bitmap.fill_rect(1, y, y - 1, 1, white)if y > 1
- $mouse_pointer.bitmap.set_pixel(y, y, black)
- when12
- $mouse_pointer.bitmap.set_pixel(0, y, black)
- $mouse_pointer.bitmap.fill_rect(1, y, 4, 1, white)
- $mouse_pointer.bitmap.fill_rect(5, y, 8, 1, black)
- when13..17
- $mouse_pointer.bitmap.set_pixel(0, y, black)
- $mouse_pointer.bitmap.fill_rect(1, y, 16 - y, 1, white)if y < 16
- $mouse_pointer.bitmap.set_pixel(17 - y, y, black)
- end
- end
- end
- # 设为可见,半透明,总在最上
- $mouse_pointer.visible = true
- $mouse_pointer.opacity = 160
- $mouse_pointer.z = 2147483647
- #==============================================================================
- # ■ 全鼠标处理核心
- #==============================================================================
- module Mouse
- includeSailCat::Mouse_Config
- #--------------------------------------------------------------------------
- # ● 常量
- #--------------------------------------------------------------------------
- NONE, M, X1, X2 = 0, 4, 5, 6
- L = LEFT_HANDED ? 2 : 1
- R = LEFT_HANDED ? 1 : 2
- #--------------------------------------------------------------------------
- # ● API
- #--------------------------------------------------------------------------
- GetCursorPos = Win32API.new("user32", "GetCursorPos", "p", "i")
- ScreenToClient = Win32API.new("user32", "ScreenToClient", "ip", "i")
- GetActiveWindow = Win32API.new("user32", "GetActiveWindow", "", "i")
- GetAsyncKeyState = Win32API.new("user32", "GetAsyncKeyState", "i", "i")
- #--------------------------------------------------------------------------
- # ● 鼠标按键和光标数据
- #--------------------------------------------------------------------------
- Flags = {}
- Data = {:x => 0, :y => 0, :key => NONE, :frame => 0, :dx => 0, :dy => 0}
- #--------------------------------------------------------------------------
- # ● 鼠标是否可用
- #--------------------------------------------------------------------------
- defself.enabled?
- if MOUSE_ENABLED.is_a?(Fixnum)
- $game_switches ? $game_switches[MOUSE_ENABLED] : true
- else
- MOUSE_ENABLED
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新鼠标输入,该方法每帧调用1次
- #--------------------------------------------------------------------------
- defself.update
- if enabled?
- s = [0, 0].pack("l*")
- GetCursorPos.call(s)
- ScreenToClient.call(hwnd, s)
- Data[:x], Data[:y] = s.unpack("l*")
- $mouse_pointer.visible = trueunless$mouse_pointer.visible
- $mouse_pointer.x = Data[:x]
- $mouse_pointer.y = Data[:y]
- Data[:key] = NONE ifData[:frame] == -1
- Data[:frame] += 1
- Flags.each_keydo |k|
- if GetAsyncKeyState.call(k) & 32768 != 0
- Flags[k] += 1
- else
- Flags[k] >= 0 ? Flags[k] = -1 : Flags.delete(k)
- end
- end
- elsif$mouse_pointer.visible
- $mouse_pointer.visible = false
- Data[:key] = NONE
- end
- end
- #--------------------------------------------------------------------------
- # ● 判断对应的键是否被按下
- #--------------------------------------------------------------------------
- defself.press?(key)
- returnfalseunless enabled?
- key = const_get(key)if key.is_a?(Symbol)
- returntrueif Flags[key] && Flags[key] >= 0
- GetAsyncKeyState.call(key) & 32768 != 0 ? (Flags[key] ||= 0; true) : false
- end
- #--------------------------------------------------------------------------
- # ● 判断对应的键是否被松开
- #--------------------------------------------------------------------------
- defself.release?(key)
- returnfalseunless enabled?
- key = const_get(key)if key.is_a?(Symbol)
- Flags[key] == -1
- end
- #--------------------------------------------------------------------------
- # ● 判断对应的键是否被触发
- #--------------------------------------------------------------------------
- defself.trigger?(key)
- returnfalseunless enabled?
- key = const_get(key)if key.is_a?(Symbol)
- Flags[key] ? Flags[key] == 0 : press?(key)
- end
- #--------------------------------------------------------------------------
- # ● 判断对应的键是否被点击
- #--------------------------------------------------------------------------
- defself.click?(key)
- returnfalseunless enabled?
- key = const_get(key)if key.is_a?(Symbol)
- Flags[key] ? release?(key) : (press?(key); false)
- end
- #--------------------------------------------------------------------------
- # ● 判断对应的键是否被按住
- #--------------------------------------------------------------------------
- defself.repeat?(key)
- returnfalseunless enabled?
- key = const_get(key)if key.is_a?(Symbol)
- Flags[key] ? (Flags[key] >= REPEAT_DELAY and(Flags[key] - REPEAT_DELAY) %
- REPEAT_SPEED == 0) : press?(key)
- end
- #--------------------------------------------------------------------------
- # ● 判断对应的键是否被双击
- #--------------------------------------------------------------------------
- defself.dblclick?(key)
- returnfalseunless enabled?
- key = const_get(key)if key.is_a?(Symbol)
- Data[:key] == key andData[:frame] == -1
- end
- #--------------------------------------------------------------------------
- # ● 获得窗口句柄
- #--------------------------------------------------------------------------
- defself.hwnd
- @hwnd ||= GetActiveWindow.call
- end
- #--------------------------------------------------------------------------
- # ● 获得鼠标指针坐标
- #--------------------------------------------------------------------------
- defself.x; Data[:x]; end
- defself.y; Data[:y]; end
- #--------------------------------------------------------------------------
- # ● 双击开始处理
- #--------------------------------------------------------------------------
- defself.begin_dblclick(key)
- key = const_get(key)if key.is_a?(Symbol)
- Data[:key] = key
- Data[:frame] = 0
- Data[:dx] = x
- Data[:dy] = y
- # 按的是左键,不要求C键双击的情况下,判定成功
- Data[:frame] = -1unless C_DBLCLICK or key != L
- end
- #--------------------------------------------------------------------------
- # ● 双击检查处理
- #--------------------------------------------------------------------------
- defself.check_dblclick(key)
- key = const_get(key)if key.is_a?(Symbol)
- # 如果按的键不是要检查的双击键,双击失败
- return begin_dblclick(key)ifData[:key] != key
- # 如果按的键间隔时间过长了,双击失败
- return begin_dblclick(key)ifData[:frame] > DBLCLICK_TIME
- # 如果两次按键中鼠标移动太多了,双击失败
- return begin_dblclick(key)if(x - Data[:dx]).abs > DBLCLICK_MOVE
- return begin_dblclick(key)if(y - Data[:dy]).abs > DBLCLICK_MOVE
- # 设置双击标记
- Data[:frame] = -1
- end
- end
- #==============================================================================
- # ■ Input 模块的注入
- #==============================================================================
- module Input
- class = dy.abs
- dx < 0 ? turn_left : turn_right
- else
- dy < 0 ? turn_up : turn_down
- end
- when6
- move_right
- when7
- move_upper_left
- when8
- move_up
- when9
- move_upper_right
- end
- Mouse.check_dblclick(:L)if Mouse.click?(:L)
- end
- end
- #--------------------------------------------------------------------------
- # ● 获得鼠标的指向四方向
- #--------------------------------------------------------------------------
- def mouse_dir4
- return0unless Mouse.press?(:L)
- dx = Mouse.x - self.screen_x
- dy = Mouse.y - self.screen_y + 16
- return5unless dx.abs > 16or dy.abs > 16
- dx.abs < dy.abs ? [8, 5, 2][(dy 0) + 1] : [4, 5, 6][(dx 0) + 1]
- end
- #--------------------------------------------------------------------------
- # ● 获得鼠标的指向八方向
- #--------------------------------------------------------------------------
- def mouse_dir8
- return0unless Mouse.press?(:L)
- dx = Mouse.x - self.screen_x
- dy = Mouse.y - self.screen_y + 16
- return5unless dx.abs > 16or dy.abs > 16
- angle = (Math.atan2(dy, dx) / Math::PI * 180 + 202.5).round
- [4, 7, 8, 9, 6, 3, 2, 1][angle / 45 & 7]
- end
- end
- #==============================================================================
- # ■ Window_Base
- #==============================================================================
- class Window_Base
- #--------------------------------------------------------------------------
- # ● 方法重定义
- #--------------------------------------------------------------------------
- unless method_defined?(:sailcat_sepmouse_update)
- alias sailcat_sepmouse_update update
- end
- #--------------------------------------------------------------------------
- # ● 相对于本窗口的坐标变换
- #--------------------------------------------------------------------------
- def mouse_x; Mouse.x - x; end
- def mouse_y; Mouse.y - y; end
- #--------------------------------------------------------------------------
- # ● 相对于窗口内容的坐标变换
- #--------------------------------------------------------------------------
- def contents_x; mouse_x - 16 + ox; end
- def contents_y; mouse_y - 16 + oy; end
- #--------------------------------------------------------------------------
- # ● 更新
- #--------------------------------------------------------------------------
- def update
- update_mouse if respond_to_mouse?
- sailcat_sepmouse_update
- end
- #--------------------------------------------------------------------------
- # ● 指针位置判定
- #--------------------------------------------------------------------------
- def mouse_over?(rect = Rect.new(x, y, width, height))
- mouse_x.between?(rect.x, rect.x + rect.width - 1)and
- mouse_y.between?(rect.y, rect.y + rect.height - 1)
- end
- #--------------------------------------------------------------------------
- # ● 响应鼠标判定
- #--------------------------------------------------------------------------
- def respond_to_mouse?
- contents != niland visible
- end
- #--------------------------------------------------------------------------
- # ● 响应选择判定
- #--------------------------------------------------------------------------
- def respond_to_select?
- false
- end
- #--------------------------------------------------------------------------
- # ● 更新鼠标操作
- #--------------------------------------------------------------------------
- def update_mouse
- update_mouse_scroll unlessself.is_a?(Window_Selectable)andnot active
- update_mouse_select if respond_to_select?
- update_cursor_rect if respond_to?(:update_cursor_rect)
- end
- #--------------------------------------------------------------------------
- # ● 更新鼠标滚动窗口内容
- #--------------------------------------------------------------------------
- def update_mouse_scroll
- # 内容可以水平滚动的情况下
- if contents.width > width - 32
- # 如果单击左右箭头区域
- if Mouse.repeat?(:L)and mouse_y >= 16and mouse_y < height - 16
- if mouse_x >= 0and mouse_x < 16
- # 向左侧滚动窗口内容
- scroll_left
- elsif mouse_x >= width - 16and mouse_x < width
- # 向右侧滚动窗口内容
- scroll_right
- end
- end
- end
- # 内容可以垂直滚动的情况下
- if contents.height > height - 32
- # 如果单击上下箭头区域
- if Mouse.repeat?(:L)and mouse_x >= 16and mouse_x < width - 16
- if mouse_y >= 0and mouse_y < 16
- # 向上方滚动窗口内容
- scroll_up
- elsif mouse_y >= height - 16and mouse_y < height
- # 向下方滚动窗口内容
- scroll_down
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 滚动的单位X值
- #--------------------------------------------------------------------------
- def scroll_x
- Font.default_size
- end
- #--------------------------------------------------------------------------
- # ● 滚动的单位Y值
- #--------------------------------------------------------------------------
- def scroll_y
- returnself.line_heightif respond_to?(:line_height)
- 32
- end
- #--------------------------------------------------------------------------
- # ● 向左滚动
- #--------------------------------------------------------------------------
- def scroll_left
- self.ox = [ox - scroll_x, 0].max
- end
- #--------------------------------------------------------------------------
- # ● 向右滚动
- #--------------------------------------------------------------------------
- def scroll_right
- # 保证显示整字
- d = (contents.width + 32 - width) % scroll_x
- d = scroll_x - d if d > 0
- self.ox = [ox + scroll_x, contents.width + 32 - width + d].min
- end
- #--------------------------------------------------------------------------
- # ● 向上滚动
- #--------------------------------------------------------------------------
- def scroll_up
- self.oy = [oy - scroll_y, 0].max
- end
- #--------------------------------------------------------------------------
- # ● 向下滚动
- #--------------------------------------------------------------------------
- def scroll_down
- # 保证显示整行
- d = (contents.height + 32 - height) % scroll_y
- d = scroll_y - d if d > 0
- self.oy = ([oy + scroll_y, contents.height + 32 - height + d].min)
- end
- end
- #==============================================================================
- # ■ Window_Selectable
- #==============================================================================
- class Window_Selectable
- #--------------------------------------------------------------------------
- # ● 响应选择判定
- #--------------------------------------------------------------------------
- def respond_to_select?
- active
- end
- #--------------------------------------------------------------------------
- # ● 响应鼠标选择
- #--------------------------------------------------------------------------
- def update_mouse_select
- # 点击内容有效区域的情况下
- if mouse_over?(Rect.new(16, 16, width - 32, height - 32))
- # 点击左键的情况下,检查点击项目
- update_click_select if Mouse.click?(:L)
- # 按住左键的情况下,检查选择项目
- update_check_select if Mouse.press?(:L)
- end
- end
- #--------------------------------------------------------------------------
- # ● 检查点击项目
- #--------------------------------------------------------------------------
- def update_click_select
- # 如果鼠标所在的项就是当前项,检查双击
- Mouse.check_dblclick(:L)if click_index == @index
- end
- #--------------------------------------------------------------------------
- # ● 检查选择项目
- #--------------------------------------------------------------------------
- def update_check_select
- # 如果被点击的项并非当前项
- if click_index != @index
- # 演奏光标SE
- $game_system.se_play($data_system.cursor_se)
- # 选中当前项
- self.index = [[click_index, 0].max, @item_max - 1].min
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新向上滚动
- #--------------------------------------------------------------------------
- def scroll_up
- super
- # 移到区域外的情况下,带动光标一起移动
- if@index / @column_max > self.top_row + (self.page_row_max - 1)
- $game_system.se_play($data_system.cursor_se)
- self.index -= @column_max
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新向下滚动
- #--------------------------------------------------------------------------
- def scroll_down
- super
- # 移到区域外的情况下,带动光标一起移动
- if@index / @column_max < self.top_row
- $game_system.se_play($data_system.cursor_se)
- self.index = [@index + @column_max, @item_max - 1].min
- end
- end
- #--------------------------------------------------------------------------
- # ● 滚动的单位X值
- #--------------------------------------------------------------------------
- def scroll_x
- padding = respond_to?(:cursor_padding) ? cursor_padding : 32
- (contents.width + padding) / @column_max
- end
- #--------------------------------------------------------------------------
- # ● 滚动的单位Y值
- #--------------------------------------------------------------------------
- def scroll_y
- respond_to?(:item_height) ? self.item_height : super
- end
- #--------------------------------------------------------------------------
- # ● 取得光标所指的项目
- #--------------------------------------------------------------------------
- def click_index
- [@item_max - 1, contents_y / scroll_y * @column_max +
- contents_x / scroll_x].min
- end
- end
- #==============================================================================
- # ■ Window_MenuStatus
- #==============================================================================
- class Window_MenuStatus
- #--------------------------------------------------------------------------
- # ● 项目的行高,但已被窗口增强核心重新定义的情况例外
- #--------------------------------------------------------------------------
- unless$sailcat_import[:WindowCore]
- def item_height; 116; end
- end
- end
- #==============================================================================
- # ■ Window_Target
- #==============================================================================
- class Window_Target
- #--------------------------------------------------------------------------
- # ● 项目的行高,但已被窗口增强核心重新定义的情况例外
- #--------------------------------------------------------------------------
- unless$sailcat_import[:WindowCore]
- def item_height; 116; end
- end
- end
- #==============================================================================
- # ■ Window_NameInput
- #==============================================================================
- class Window_NameInput
- #--------------------------------------------------------------------------
- # ● 响应选择判定
- #--------------------------------------------------------------------------
- def respond_to_select?
- active
- end
- #--------------------------------------------------------------------------
- # ● 响应鼠标选择
- #--------------------------------------------------------------------------
- def update_mouse_select
- # 点击内容有效区域的情况下
- if mouse_over?(Rect.new(16, 16, width - 32, height - 32))
- # 点击左键的情况下,检查点击项目
- update_click_select if Mouse.click?(:L)
- # 按住左键的情况下,检查选择项目
- update_check_select if Mouse.press?(:L)
- end
- end
- #--------------------------------------------------------------------------
- # ● 检查点击项目
- #--------------------------------------------------------------------------
- def update_click_select
- # 如果鼠标所在的项就是当前项,处理双击
- if click_index == @index
- Mouse.begin_dblclick(:L)unless on_command?
- Mouse.check_dblclick(:L)
- end
- end
- #--------------------------------------------------------------------------
- # ● 检查选择项目
- #--------------------------------------------------------------------------
- def update_check_select
- # 如果被点击的项并非当前项
- if click_index != @indexand click_index >= 0
- # 演奏光标SE
- $game_system.se_play($data_system.cursor_se)
- # 选中当前项
- @index = [[click_index, 0].max, item_max - 1].min
- end
- end
- #--------------------------------------------------------------------------
- # ● [确定]的判定
- #--------------------------------------------------------------------------
- def on_command?
- @index >= item_max - 1
- end
- #--------------------------------------------------------------------------
- # ● 最大项目数
- #--------------------------------------------------------------------------
- def item_max
- if respond_to?(:choices_max)
- choices_max
- elsif$sailcat_import[:WindowCore]
- CHARACTER_TABLE_NORMAL.size
- else
- CHARACTER_TABLE.size + 1
- end
- end
- #--------------------------------------------------------------------------
- # ● 取得光标所指的项目
- #--------------------------------------------------------------------------
- def click_index
- mx, my = mouse_x - 16, mouse_y - 16
- 0.upto(item_max - 1)do |i|
- r = item_rect(i)
- if(mx - r.x).between?(0, r.width - 1)and
- (my - r.y).between?(0, r.height - 1)
- return i
- end
- end
- -1
- end
- #--------------------------------------------------------------------------
- # ● 取得某项的光标区域
- #--------------------------------------------------------------------------
- def item_rect(index)
- last_index = @index
- @index = index
- update_cursor_rect
- rect = cursor_rect.clone
- @index = last_index
- update_cursor_rect
- rect
- end
- end
- #==============================================================================
- # ■ Window_InputNumber
- #==============================================================================
- class Window_InputNumber
- #--------------------------------------------------------------------------
- # ● 方法重定义
- #--------------------------------------------------------------------------
- unless method_defined?(:sailcat_sepmouse_initialize)
- alias sailcat_sepmouse_initialize initialize
- alias sailcat_sepmouse_update_cursor_rect update_cursor_rect
- end
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # digits_max : 位数
- #--------------------------------------------------------------------------
- def initialize(digits_max)
- @up_arrow = Sprite.new
- @down_arrow = Sprite.new
- sailcat_sepmouse_initialize(digits_max)
- @up_arrow.bitmap = @down_arrow.bitmap = self.windowskin
- @up_arrow.src_rect = Rect.new(self.windowskin.width - 40, 16, 16, 7)
- @down_arrow.src_rect = Rect.new(self.windowskin.width - 40, 41, 16, 7)
- @up_arrow.z = @down_arrow.z = z + 1
- end
- #--------------------------------------------------------------------------
- # ● 设置内容不透明度
- #--------------------------------------------------------------------------
- def contents_opacity=(opacity)
- super
- @up_arrow.opacity = @down_arrow.opacity = opacity
- end
- #--------------------------------------------------------------------------
- # ● 更新光标矩形
- #--------------------------------------------------------------------------
- def update_cursor_rect
- sailcat_sepmouse_update_cursor_rect
- offset = $sailcat_import[:WindowCore] ? 24 + @cursor_width >> 1 : 16
- @up_arrow.x = @down_arrow.x = x + @index * @cursor_width + offset
- @up_arrow.y = y + 7
- @down_arrow.y = y + height - 14
- end
- #--------------------------------------------------------------------------
- # ● 释放
- #--------------------------------------------------------------------------
- def dispose
- @up_arrow.dispose
- @down_arrow.dispose
- super
- end
- #--------------------------------------------------------------------------
- # ● 响应选择判定
- #--------------------------------------------------------------------------
- def respond_to_select?
- active
- end
- #--------------------------------------------------------------------------
- # ● 响应鼠标选择
- #--------------------------------------------------------------------------
- def update_mouse_select
- # 点击内容有效区域的情况下
- if mouse_over?(Rect.new(16, 16, width - 32, height - 32))
- # 点击左键的情况下,检查点击项目
- update_click_select if Mouse.click?(:L)
- # 按住左键的情况下,检查选择项目
- update_check_select if Mouse.press?(:L)
- # 点击上箭头的情况下
- elsif Mouse.x.between?(@up_arrow.x, @up_arrow.x + 15)and
- Mouse.y.between?(@up_arrow.y, @up_arrow.y + 6)
- update_value(+2)if Mouse.repeat?(:L)
- # 点击下箭头的情况下
- elsif Mouse.x.between?(@down_arrow.x, @down_arrow.x + 15)and
- Mouse.y.between?(@down_arrow.y, @down_arrow.y + 6)
- update_value(-2)if Mouse.repeat?(:L)
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新数值
- #--------------------------------------------------------------------------
- unless$sailcat_import[:WindowCore]
- def update_value(delta)
- $game_system.se_play($data_system.cursor_se)
- place = 10 ** (@digits_max - 1 - @index)
- n = @number / place % 10
- @number -= n * place
- n = (n + 1) % 10if delta > 0
- n = (n + 9) % 10if delta < 0
- @number += n * place
- refresh
- end
- end
- #--------------------------------------------------------------------------
- # ● 检查点击项目
- #--------------------------------------------------------------------------
- def update_click_select
- # 如果鼠标所在的项就是当前项,检查双击
- Mouse.check_dblclick(:L)if click_index == @index
- end
- #--------------------------------------------------------------------------
- # ● 检查选择项目
- #--------------------------------------------------------------------------
- def update_check_select
- # 如果被点击的项并非当前项
- if click_index != @index
- # 演奏光标SE
- $game_system.se_play($data_system.cursor_se)
- # 选中当前项
- @index = [[click_index, 0].max, @digits_max - 1].min
- end
- end
- #--------------------------------------------------------------------------
- # ● 取得光标所指的项目
- #--------------------------------------------------------------------------
- def click_index
- contents_x / @cursor_width
- end
- end
- #==============================================================================
- # ■ Window_Message
- #==============================================================================
- class Window_Message
- #--------------------------------------------------------------------------
- # ● 响应选择判定
- #--------------------------------------------------------------------------
- def respond_to_select?
- contents_opacity == 255and@input_number_window.nil?
- end
- #--------------------------------------------------------------------------
- # ● 响应鼠标选择
- #--------------------------------------------------------------------------
- def update_mouse_select
- # 当前是消息结束待机的情况下
- if pause or(@text andnot@text.empty?)
- # 左键单击视同双击
- if Mouse.click?(:L)
- Mouse.begin_dblclick(:L)
- Mouse.check_dblclick(:L)
- end
- # 当前是处理选择项的情况下,执行原处理
- elsif active
- super
- end
- end
- #--------------------------------------------------------------------------
- # ● 检查选择项目
- #--------------------------------------------------------------------------
- def update_check_select
- # 点击项不在列表区域的情况下,返回
- returnif click_index < 0
- super
- end
- #--------------------------------------------------------------------------
- # ● 取得光标所指的项目
- #--------------------------------------------------------------------------
- def click_index
- # 变换坐标为相对于内容的值
- mx, my = mouse_x - 16, mouse_y - 16 - $game_temp.choice_start * scroll_y
- # 多列的情况下考虑列间距
- padding = respond_to?(:cursor_padding) ? cursor_padding : 32
- [@item_max - 1, (self.top_row + my / scroll_y) * @column_max +
- mx / ((contents.width + padding) / @column_max)].min
- end
- end
- #==============================================================================
- # ■ Arrow_Base
- #==============================================================================
- class Arrow_Base
- #--------------------------------------------------------------------------
- # ● 方法重定义
- #--------------------------------------------------------------------------
- unless method_defined?(:sailcat_sepmouse_update)
- alias sailcat_sepmouse_update update
- end
- #--------------------------------------------------------------------------
- # ● 更新
- #--------------------------------------------------------------------------
- def update
- update_mouse
- sailcat_sepmouse_update
- end
- #--------------------------------------------------------------------------
- # ● 更新鼠标处理
- #--------------------------------------------------------------------------
- def update_mouse
- # 点击左键,指向有效的情况下
- if(Mouse.trigger?(:L)or Mouse.release?(:L))and click_index >= 0
- # 点击当前指向战斗者的情况下
- if click_index == @index
- # 执行双击检查
- Mouse.check_dblclick(:L)if Mouse.click?(:L)
- # 点击的不是当前战斗者的情况下
- else
- # 演奏光标 SE
- $game_system.se_play($data_system.cursor_se)
- @index = click_index
- # 开始准备双击
- Mouse.begin_dblclick(:L)if Mouse.click?(:L)
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 取得光标所指的项目
- #--------------------------------------------------------------------------
- def click_index
- members.sort{|a, b| b.screen_z - a.screen_z}.eachdo |c|
- nextif c.is_a?(Game_Enemy)andnot c.exist?
- bitmap = RPG::Cache.battler(c.battler_name, c.battler_hue)
- x = c.screen_x - (bitmap.width >> 1)
- y = c.screen_y - bitmap.height
- if Mouse.x.between?(x, x + bitmap.width - 1)and
- Mouse.y.between?(y, y + bitmap.height - 1)
- return c.index
- end
- end
- return-1
- end
- end
- #==============================================================================
- # ■ Arrow_Enemy
- #==============================================================================
- class Arrow_Enemy
- #--------------------------------------------------------------------------
- # ● 队伍成员
- #--------------------------------------------------------------------------
- def members; $game_troop.enemies; end
- end
- #==============================================================================
- # ■ Arrow_Actor
- #==============================================================================
- class Arrow_Actor
- #--------------------------------------------------------------------------
- # ● 队伍成员
- #--------------------------------------------------------------------------
- def members; $game_party.actors; end
- end
- #==============================================================================
- # ■ Scene_File
- #==============================================================================
- class Scene_File
- #--------------------------------------------------------------------------
- # ● 方法重定义
- #--------------------------------------------------------------------------
- unless method_defined?(:sailcat_sepmouse_update)
- alias sailcat_sepmouse_update update
- end
- #--------------------------------------------------------------------------
- # ● 更新
- #--------------------------------------------------------------------------
- def update
- update_mouse
- sailcat_sepmouse_update
- end
- #--------------------------------------------------------------------------
- # ● 更新鼠标处理
- #--------------------------------------------------------------------------
- def update_mouse
- # 点击左键,窗口有效的情况下
- if(Mouse.press?(:L)or Mouse.release?(:L))and click_index >= 0
- # 如果被点击的项就是当前项
- if click_index + (@top_index || 0) == @file_index
- # 执行双击检查
- Mouse.check_dblclick(:L)if Mouse.click?(:L)
- # 如果被点击的项并非当前项
- elsif@savefile_windows[click_index].is_a?(Window_SaveFile)
- # 演奏光标SE
- $game_system.se_play($data_system.cursor_se)
- # 选中当前项
- @savefile_windows[@file_index % 4].selected = false
- @file_index = [[click_index, 0].max, @savefile_windows.size - 1].min +
- (@top_index || 0)
- @savefile_windows[@file_index % 4].selected = true
- # 开始准备双击
- Mouse.begin_dblclick(:L)if Mouse.click?(:L)
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 取得光标所指的项目
- #--------------------------------------------------------------------------
- def click_index
- @savefile_windows.each_with_indexdo |w, i|
- return i if w.mouse_over?
- end
- return-1
- end
- end
- #==============================================================================
- # ■ Scene_Battle
- #==============================================================================
- class Scene_Battle
- #--------------------------------------------------------------------------
- # ● 方法重定义
- #--------------------------------------------------------------------------
- unless method_defined?(:sailcat_sepmouse_update_phase5)
- alias sailcat_sepmouse_update_phase5 update_phase5
- end
- #--------------------------------------------------------------------------
- # ● 画面更新 (结束战斗回合)
- #--------------------------------------------------------------------------
- def update_phase5
- sailcat_sepmouse_update_phase5
- update_mouse_phase5
- end
- #--------------------------------------------------------------------------
- # ● 更新鼠标处理 (结束战斗回合)
- #--------------------------------------------------------------------------
- def update_mouse_phase5
- # 等待计数已归 0 ,按左或右键的情况下
- if@phase5_wait_count == 0and(Mouse.click?(:L)or Mouse.click?(:R))
- # 战斗结束
- battle_end(0)
- end
- end
- end
- #==============================================================================
- # ■ Scene_Name
- #==============================================================================
- class Scene_Name
- #--------------------------------------------------------------------------
- # ● 方法重定义
- #--------------------------------------------------------------------------
- unless method_defined?(:sailcat_sepmouse_update)
- alias sailcat_sepmouse_update update
- end
- #--------------------------------------------------------------------------
- # ● 更新
- #--------------------------------------------------------------------------
- def update
- update_mouse
- sailcat_sepmouse_update
- end
- #--------------------------------------------------------------------------
- # ● 更新鼠标处理
- #--------------------------------------------------------------------------
- def update_mouse
- unless$sailcat_import[:WindowCore]
- # 右击鼠标的情况下
- if Mouse.click?(:R)and@edit_window.index > 0
- # 演奏取消 SE
- $game_system.se_play($data_system.cancel_se)
- # 删除文字
- @edit_window.back
- end
- end
- end
- end
- #==============================================================================
- # ■ Scene_Gameover
- #==============================================================================
- class Scene_Gameover
- #--------------------------------------------------------------------------
- # ● 方法重定义
- #--------------------------------------------------------------------------
- unless method_defined?(:sailcat_sepmouse_update)
- alias sailcat_sepmouse_update update
- end
- #--------------------------------------------------------------------------
- # ● 更新
- #--------------------------------------------------------------------------
- def update
- update_mouse
- sailcat_sepmouse_update
- end
- #--------------------------------------------------------------------------
- # ● 更新鼠标处理
- #--------------------------------------------------------------------------
- def update_mouse
- # 点击鼠标左键或右键的情况下
- if Mouse.click?(:L)or Mouse.click?(:R)
- # 切换到标题画面
- $scene = Scene_Title.new
- end
- end
- end
复制代码
本帖来自P1论坛作者king,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址: https://rpg.blue/forum.php?mod=viewthread&tid=405063 若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。 |
|