扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 108|回复: 0

[转载发布] [更新:鼠标支持]子选项窗口

[复制链接]
累计送礼:
0 个
累计收礼:
0 个
  • TA的每日心情
    开心
    昨天 18:01
  • 签到天数: 114 天

    连续签到: 4 天

    [LV.6]常住居民II

    2338

    主题

    403

    回帖

    1万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    6
    卡币
    10632
    OK点
    16
    推广点
    0
    同能卷
    0
    积分
    13401

    灌水之王

    发表于 2024-4-19 18:57:16 | 显示全部楼层 |阅读模式
    1L普通版  2L鼠标版






    本脚本更新(呵呵,没有TJ),较上个版本(0.91)更新如下:
    1.代码简化,去除Bug
    2.支持多选项打开(上个版本只能把一个打开到底)
    3.用左右键执行上面(2)的功能[即:左键 退到上个选项层 右键 进入下个选项层]
    4.会自动在末尾追加一层"-----------" (占位置)
    效果如下,范例照旧稍后放出(http://rpg.blue/thread-175789-1-1.html就是截图..):


    代码如下:
    1. #______________________________________________________________________________# * 此脚本归66RPG - Idiot Script Association(ISA)所有,谢绝任何形式转载。#______________________________________________________________________________#==============================================================================# ■ 子选项 - Sub-option#------------------------------------------------------------------------------#   遵守协议:66RPG - Idiot Script Association(ISA)#   当前版本:0.9.5.0#------------------------------------------------------------------------------#   更新日记:沙漠.灰(2011.4.2)#             - 初始化#             沙漠.灰(2011.4.16)#             - 0.95版放出#==============================================================================#--------------------------------------------------------------------------# ● 资料记录#--------------------------------------------------------------------------module ISA   Use["子选项"] = [true, "0.9.5.0"]end#==============================================================================# ■ Window_Folder#------------------------------------------------------------------------------#  拥有光标的移动以及滚动功能、子项目的窗口类。#==============================================================================class Window_Folder < Window_Base  #--------------------------------------------------------------------------  # ● 定义实例变量  #--------------------------------------------------------------------------  attr_reader   :index                    # 光标位置  attr_reader   :c  #--------------------------------------------------------------------------  # ● 初始画对像  #     x      : 窗口的 X 坐标  #     y      : 窗口的 Y 坐标  #     width  : 窗口的宽  #     height : 窗口的高  #--------------------------------------------------------------------------  def initialize(x,y,width, height, commands)    super(x, y, width, height)    commands += ["-"*(width/11)]    # 初始化数据    @move_to        = 0    @to_refresh     = false    @commands_size  = 0    @c              = false    @index          = [0]    @spread_command = []    @disable_item   = []    commands.size.times{@spread_command.push(1)}    @true_commands  = commands    @object_id = 0    # 生成位图    self.contents = Bitmap.new(width - 32, @true_commands.self_all_plus * 32-32)    @v = Viewport.new(16+self.x, 16+self.y, width-32, height-32) ; @v.z = 999    @new_bitmap = Sprite.new(@v)    @new_bitmap.bitmap = Bitmap.new(width - 32, @true_commands.self_all_plus * 32-32)    index = 0 # 描绘顶层项目    # 描绘父项目    for unit in @true_commands      draw_command [index]      index += 1    end  end  #--------------------------------------------------------------------------  # ● 项目无效化 index : 项目编号  #--------------------------------------------------------------------------  def disable_item(index)    @disable_item.push(index)  end  #--------------------------------------------------------------------------  # ● 指定项目是否为父项目 index 所在位置  #--------------------------------------------------------------------------  def is_folder?(commands,index)    # 若指定项目为数组且子单元数目大于1就判定为父项目    if index.size == 1 and commands[index[0]].is_a?(Array)      return true if commands[index[0]].size > 1    elsif index.size > 1      return is_folder?(commands[index[0]],index[1...index.size])    end    false  end  #--------------------------------------------------------------------------  # ● 描绘项目名称 index 所在位置  branch 是否分支  #--------------------------------------------------------------------------  def draw_command(index,branch=false)    x, y = check_index_xy(index)    rect = Rect.new(x+32,y,self.width-32,32)    self.contents.font.color = disabled_color if @disable_item.include?(index)    name = get_command(@true_commands,index)    self.contents.draw_text(rect, name)    # 为父项目时,描绘指引    draw_flag(index,branch) if is_folder?(@true_commands,index)    self.contents.font.color = normal_color  end  #--------------------------------------------------------------------------  # ● 取得项目名称 index 所在位置  #--------------------------------------------------------------------------  def get_command(name_array,index)    return get_command_name(name_array[index[0]]) if index.size == 1    get_command name_array[index[0]],index[1...index.size]  end  #--------------------------------------------------------------------------  # ● 再次 取得项目名称 index 所在位置  #--------------------------------------------------------------------------  def get_command_name(name_array)    name_array.is_a?(String) ? name_array : name_array[0].is_a?(Array) ?  get_command_name(name_array[0]) : name_array[0]  end  #--------------------------------------------------------------------------  # ● 描绘项目标记 index 所在位置  #--------------------------------------------------------------------------  def draw_flag(index,branch=false)    x, y = check_index_xy index    src_rect  = Rect.new(x+16,y+10,16,16)    self.contents.fill_rect(src_rect, Color.new(0,0,0,0))    dest_rect = branch ? Rect.new(152, 40, 16, 16): Rect.new(168, 24, 16, 16)    src_bitmap= RPG::Cache.windowskin($game_system.windowskin_name)    self.contents.stretch_blt(src_rect, src_bitmap, dest_rect)  end  #--------------------------------------------------------------------------  # ● 检查 index 所在坐标  #--------------------------------------------------------------------------  def check_index_xy(index)    # 反复迭代,直到index最后一位    str = "["    if index[0] > 0      for i in 0...index[0]        str += @spread_command[i].true_to_s + "," rescue str += "1,"      end    end    if @spread_command[index[0]].is_a?(Array) and index.size > 1      str += check_spread(@spread_command[index[0]],index[1...index.size]) + ","    end    [index.size * 32 - 32, eval(str += "]").self_all_plus * 32]  end  #--------------------------------------------------------------------------  # ● 检查展开项目,返回项目数   #--------------------------------------------------------------------------  def check_spread(array,index)    str = "["    if index[0] > 0      for i in 0...index[0]        str += array[i].true_to_s + "," rescue str += "1,"      end    end    if array[index[0]].is_a?(Array) and index.size > 1      str += check_spread(array[index[0]],index[1...index.size]) + ","    end    str += "]"  end  #--------------------------------------------------------------------------  # ● 释放  #--------------------------------------------------------------------------  def dispose    @new_bitmap.bitmap.dispose    @new_bitmap.dispose    @v.dispose    super  end  #--------------------------------------------------------------------------  # ● 设置光标的位置  #--------------------------------------------------------------------------  def index=(index)    @index = index    update_cursor_rect  end  #--------------------------------------------------------------------------  # ● 检查指定项目大小 index :   #--------------------------------------------------------------------------  def check_command_size(index,commands=@true_commands)    return commands.size if index.size == 1    check_command_size(index[1...index.size],commands[index[0]])  end  #--------------------------------------------------------------------------  # ● 关闭展开父选项  #--------------------------------------------------------------------------  def folder(index,close=true)    if close      return if index.size == 1 if closed?(index)      return folder(index[0...index-1],close) if closed?(index)      x1, y1 = check_index_xy(index)      Graphics.freeze      temp = @spread_command.self_all_plus      eval("@spread_command#{@index.new_to_s} = 1 ")      new_height = ((@spread_command.self_all_plus - temp).abs + 1) * 32      src_rect      = Rect.new(0,0,self.width,self.contents.height)      dest_rect     = Rect.new(0,y1+new_height,self.width,self.contents.height)      @new_bitmap.bitmap.stretch_blt(src_rect, self.contents, dest_rect)      src_rect  = Rect.new(0,y1,self.width,self.contents.height)      self.contents.fill_rect(src_rect, Color.new(0,0,0,0))      @new_bitmap.y= y1 + new_height      @move_to     = -new_height + 32      @to_refresh  = -1      draw_command(@index,false)      Graphics.transition(10)    else      return if !is_folder?(@true_commands,index)      return @index.push(1) if !closed?(index)      new_height = check_command_size(index+[0]) * 32 - 32      x1, y1 = check_index_xy(index+[0])      @new_bitmap.bitmap.clear      @new_bitmap.y = y1 + 32      src_rect      = Rect.new(0 ,0    ,self.width,self.contents.height)      dest_rect     = Rect.new(0,y1+32,self.width,self.contents.height)      @new_bitmap.bitmap.stretch_blt(src_rect, self.contents, dest_rect)      src_rect  = Rect.new(0,y1,self.width,self.contents.height)      self.contents.fill_rect(src_rect, Color.new(0,0,0,0))      @move_to     = new_height      @to_refresh  = 1      draw_command(@index,true)      size = "1," * check_command_size(@index+[0])      eval("@spread_command#{@index.new_to_s} = [#{size}] ")    end  end  #--------------------------------------------------------------------------  # ● 移动项目  #--------------------------------------------------------------------------  def move_command    if @move_to == 0 and @to_refresh != 0      if @to_refresh == 1        @to_refresh = 0        for i in 1...check_command_size(@index+[0])          draw_command(@index+[i])        end        Graphics.freeze        src_rect  = Rect.new(@new_bitmap.x,@new_bitmap.y,self.width,self.contents.height)        dest_rect = Rect.new(0,0,self.width,self.contents.height)        self.contents.stretch_blt(src_rect, @new_bitmap.bitmap, dest_rect)        @new_bitmap.bitmap.clear        Graphics.transition(10)         @index  1    false  end  #--------------------------------------------------------------------------  # ● 刷新画面  #--------------------------------------------------------------------------  def update    super    move_command    return if @to_refresh != 0    if self.active       # 方向键下被按下的情况下      if Input.repeat?(Input::DOWN)        $game_system.se_play($data_system.cursor_se)        @index[-1] = (@index[-1]+1)%check_command_size(@index)        @index[-1] += 1 if @index.size > 1 and @index[-1] == 0        @index = [0] if @index == [@true_commands.size-1]      end      # 方向键上被按下的情况下      if Input.repeat?(Input::UP)        $game_system.se_play($data_system.cursor_se)        @index[-1] -= 1 if @index.size > 1 and @index[-1] == 1        @index[-1] -= 1 if @index == [0]        @index[-1] = (@index[-1]-1)%check_command_size(@index)      end      # 方向键左被按下的情况下      if Input.trigger?(Input::LEFT)        if @index.size == 1          $game_system.se_play($data_system.buzzer_se)        else          @index.pop          $game_system.se_play($data_system.cancel_se)        end      end      # 方向键右被按下的情况下      if Input.trigger?(Input::RIGHT)        if is_folder?(@true_commands,@index)          $game_system.se_play($data_system.decision_se)          folder(@index,false)        end      end      # B键被按下的情况下      if Input.trigger?(Input::B)        if @index.size == 1          $game_system.se_play($data_system.buzzer_se)        else          @index.pop          $game_system.se_play($data_system.cancel_se)          folder(@index)        end      end      # C键被按下的情况下      if Input.trigger?(Input::C)        @c = !is_folder?(@true_commands,@index)        if is_folder?(@true_commands,@index)          $game_system.se_play($data_system.decision_se)          folder(@index,false)        end      end    end    update_cursor_rect  end  #--------------------------------------------------------------------------  # ● 更新光标矩形  #--------------------------------------------------------------------------  def update_cursor_rect    x, y = check_index_xy(@index)    if y - self.oy >= self.height - 32      self.oy        += 32      @new_bitmap.oy += 32    elsif y - self.oy < 0      self.oy        -= 32      @new_bitmap.oy -= 32    end    self.cursor_rect.set(x, y-self.oy, [email protected]_to_s.size/3*32, 32)  endend#==============================================================================# ■ Array#------------------------------------------------------------------------------#  数组类  又拿数组开刀...#==============================================================================class Array  #--------------------------------------------------------------------------  # ● 转换 真 字符串  #--------------------------------------------------------------------------  def true_to_s    string = "["    for unit in self      string += unit.is_a?(Array) ? unit.true_to_s + "," : "#{unit},"    end    string + "]"  end  #--------------------------------------------------------------------------  # ● 转换 新 字符串  #--------------------------------------------------------------------------  def new_to_s    string = ""    for unit in self      string += "[#{unit}]"    end    string  end  #--------------------------------------------------------------------------  # ● 全部 自相加  #--------------------------------------------------------------------------  def self_all_plus    var = 0    self.each {|unit| var +=  unit.is_a?(Array) ? unit.self_all_plus : 1}    var  endend复制代码
    复制代码

    沙漠点灰于2011-5-1 17:50补充以下内容:
    鼠标版:
    用的鼠标脚本是没有内置dll的那个 Mouse.get_mouse_pos
    可以把我的两个范例(http://rpg.blue/thread-174282-1-1.html
    http://rpg.blue/thread-175789-1-1.html)替换掉
    下面美化脚本(移动光标):
    1. #==============================================================================# ■ Rect#------------------------------------------------------------------------------#  矩形类#==============================================================================# 移动帧数,自己改Cursor_Rect_Move = 10class Rect  # 设置  alias old_set set unless Rect.method_defined? "old_set"  def set(x,y,w,h,de=false)    if @target_rect.is_a?(Rect)      return if @target_rect == Rect.new(x,y,w,h)    end    if de      @cursor_rect_move = Cursor_Rect_Move      @target_rect = Rect.new(x,y,w,h)    else      self.old_set(x,y,w,h)    end  end  # 刷新  def update    return unless @target_rect and @cursor_rect_move    return if @cursor_rect_move  self.top_row + (self.page_row_max - 1)      # 从当前行向末尾滚动      self.top_row = row - (self.page_row_max - 1)    end    # 计算光标的宽    cursor_width = self.width / @column_max - 32    # 计算光标坐标    x = @index % @column_max * (cursor_width + 32)    y = @index / @column_max * 32 - self.oy    # 更新国标矩形    self.cursor_rect.set(x, y, cursor_width, 32,true)  endend#==============================================================================# ■ Window_Message#------------------------------------------------------------------------------#  显示文章的信息窗口。#==============================================================================class Window_Message < Window_Selectable  #--------------------------------------------------------------------------  # ● 刷新光标矩形  #--------------------------------------------------------------------------  def update_cursor_rect    if @index >= 0      n = $game_temp.choice_start + @index      self.cursor_rect.set(8, n * 32, @cursor_width, 32,true)    else      self.cursor_rect.empty    end  endend复制代码
    复制代码
    下面是鼠标版:
    1. * 此脚本归66RPG - Idiot Script Association(ISA)所有,谢绝任何形式转载。#______________________________________________________________________________#==============================================================================# ■ 子选项 - Sub-option#------------------------------------------------------------------------------#   遵守协议:66RPG - Idiot Script Association(ISA)#   当前版本:0.9.7.0#------------------------------------------------------------------------------#   更新日记:沙漠.灰(2011.4.2)#             - 初始化#             沙漠.灰(2011.4.16)#             - 0.95版放出#             沙漠.灰(2011.5.1)#             - 0.97版放出#=============================================================================class Window_Folder < Window_Base  #--------------------------------------------------------------------------  # ● 定义实例变量  #--------------------------------------------------------------------------  attr_reader   :index                    # 光标位置  attr_reader   :c  #--------------------------------------------------------------------------  # ● 初始画对像  #     x      : 窗口的 X 坐标  #     y      : 窗口的 Y 坐标  #     width  : 窗口的宽  #     height : 窗口的高  #--------------------------------------------------------------------------  def initialize(x,y,width, height, commands)    commands += ["-"*(width/11)]    super(x, y, width, height)    # 初始化数据    @move_to        = 0    @to_refresh     = false    @commands_size  = 0    @c              = false    @index          = [0]    @spread_command = []    @disable_item   = []    commands.size.times{@spread_command.push(1)}    @true_commands  = commands    @object_id = 0    # 生成位图    self.contents = Bitmap.new(width - 32, @true_commands.self_all_plus * 32-32)    @v = Viewport.new(16+self.x, 16+self.y, width-32, height-32) ; @v.z = 999    @new_bitmap = Sprite.new(@v)    @new_bitmap.bitmap = Bitmap.new(width - 32, @true_commands.self_all_plus * 32-32)    index = 0 # 描绘顶层项目    # 描绘父项目    for unit in @true_commands      draw_command [index]      index += 1    end  end  #--------------------------------------------------------------------------  # ● 项目无效化 index : 项目编号  #--------------------------------------------------------------------------  def disable_item(index)    @disable_item.push(index)  end  #--------------------------------------------------------------------------  # ● 指定项目是否为父项目 index 所在位置  #--------------------------------------------------------------------------  def is_folder?(commands,index)    # 若指定项目为数组且子单元数目大于1就判定为父项目    if index.size == 1 and commands[index[0]].is_a?(Array)      return true if commands[index[0]].size > 1    elsif index.size > 1      return is_folder?(commands[index[0]],index[1...index.size])    end    false  end  #--------------------------------------------------------------------------  # ● 描绘项目名称 index 所在位置  branch 是否分支  #--------------------------------------------------------------------------  def draw_command(index,branch=false)    x, y = check_index_xy(index)    rect = Rect.new(x+32,y,self.width-32,32)    self.contents.font.color = disabled_color if @disable_item.include?(index)    name = get_command(@true_commands,index)    self.contents.draw_text(rect, name)    # 为父项目时,描绘指引    draw_flag(index,branch) if is_folder?(@true_commands,index)    self.contents.font.color = normal_color  end  #--------------------------------------------------------------------------  # ● 取得项目名称 index 所在位置  #--------------------------------------------------------------------------  def get_command(name_array,index)    return get_command_name(name_array[index[0]]) if index.size == 1    get_command name_array[index[0]],index[1...index.size]  end  #--------------------------------------------------------------------------  # ● 再次 取得项目名称 index 所在位置  #--------------------------------------------------------------------------  def get_command_name(name_array)    name_array.is_a?(String) ? name_array : name_array[0].is_a?(Array) ?  get_command_name(name_array[0]) : name_array[0]  end  #--------------------------------------------------------------------------  # ● 描绘项目标记 index 所在位置  #--------------------------------------------------------------------------  def draw_flag(index,branch=false)    x, y = check_index_xy index    src_rect  = Rect.new(x+16,y+10,16,16)    self.contents.fill_rect(src_rect, Color.new(0,0,0,0))    dest_rect = branch ? Rect.new(152, 40, 16, 16): Rect.new(168, 24, 16, 16)    src_bitmap= RPG::Cache.windowskin($game_system.windowskin_name)    self.contents.stretch_blt(src_rect, src_bitmap, dest_rect)  end  #--------------------------------------------------------------------------  # ● 检查 index 所在坐标  #--------------------------------------------------------------------------  def check_index_xy(index)    # 反复迭代,直到index最后一位    str = "["    if index[0] > 0      for i in 0...index[0]        str += @spread_command[i].true_to_s + "," rescue str += "1,"      end    end    if @spread_command[index[0]].is_a?(Array) and index.size > 1      str += check_spread(@spread_command[index[0]],index[1...index.size]) + ","    end    [index.size * 32 - 32, eval(str += "]").self_all_plus * 32]  end  #--------------------------------------------------------------------------  # ● 检查展开项目,返回项目数   #--------------------------------------------------------------------------  def check_spread(array,index)    str = "["    if index[0] > 0      for i in 0...index[0]        str += array[i].true_to_s + "," rescue str += "1,"      end    end    if array[index[0]].is_a?(Array) and index.size > 1      str += check_spread(array[index[0]],index[1...index.size]) + ","    end    str += "]"  end  #--------------------------------------------------------------------------  # ● 释放  #--------------------------------------------------------------------------  def dispose    @new_bitmap.bitmap.dispose    @new_bitmap.dispose    @v.dispose    super  end  #--------------------------------------------------------------------------  # ● 设置光标的位置  #--------------------------------------------------------------------------  def index=(index)    @index = index    update_cursor_rect  end  #--------------------------------------------------------------------------  # ● 检查指定项目大小 index :   #--------------------------------------------------------------------------  def check_command_size(index,commands=@true_commands)    return commands.size if index.size == 1    check_command_size(index[1...index.size],commands[index[0]])  end  #--------------------------------------------------------------------------  # ● 关闭\展开父选项  #--------------------------------------------------------------------------  def folder(index,close=true)    if close      return if index.size == 1 if closed?(index)      return folder(index[0...index-1],close) if closed?(index)      x1, y1 = check_index_xy(index)      Graphics.freeze      temp = @spread_command.self_all_plus      eval("@spread_command#{@index.new_to_s} = 1 ")      new_height = ((@spread_command.self_all_plus - temp).abs + 1) * 32      src_rect      = Rect.new(0,0,self.width,self.contents.height)      dest_rect     = Rect.new(0,y1+new_height,self.width,self.contents.height)      @new_bitmap.bitmap.stretch_blt(src_rect, self.contents, dest_rect)      src_rect  = Rect.new(0,y1,self.width,self.contents.height)      self.contents.fill_rect(src_rect, Color.new(0,0,0,0))      @new_bitmap.y= y1 + new_height      @move_to     = -new_height + 32      @to_refresh  = -1      draw_command(@index,false)      Graphics.transition(10)    else      return if !is_folder?(@true_commands,index)      return @index.push(1) if !closed?(index)      new_height = check_command_size(index+[0]) * 32 - 32      x1, y1 = check_index_xy(index+[0])      @new_bitmap.bitmap.clear      @new_bitmap.y = y1 + 32      src_rect      = Rect.new(0 ,0    ,self.width,self.contents.height)      dest_rect     = Rect.new(0,y1+32,self.width,self.contents.height)      @new_bitmap.bitmap.stretch_blt(src_rect, self.contents, dest_rect)      src_rect  = Rect.new(0,y1,self.width,self.contents.height)      self.contents.fill_rect(src_rect, Color.new(0,0,0,0))      @move_to     = new_height      @to_refresh  = 1      draw_command(@index,true)      size = "1," * check_command_size(@index+[0])      eval("@spread_command#{@index.new_to_s} = [#{size}] ")    end  end  #--------------------------------------------------------------------------  # ● 移动项目  #--------------------------------------------------------------------------  def move_command    if @move_to == 0 and @to_refresh != 0      if @to_refresh == 1        @to_refresh = 0        for i in 1...check_command_size(@index+[0])          draw_command(@index+[i])        end        Graphics.freeze        src_rect  = Rect.new(@new_bitmap.x,@new_bitmap.y,self.width,self.contents.height)        dest_rect = Rect.new(0,0,self.width,self.contents.height)        self.contents.stretch_blt(src_rect, @new_bitmap.bitmap, dest_rect)        @new_bitmap.bitmap.clear        Graphics.transition(10)         @index  1    false  end  #--------------------------------------------------------------------------  # ● 刷新画面  #--------------------------------------------------------------------------  def update    super    move_command    return if @to_refresh != 0    if self.active       # 方向键下被按下的情况下      if Input.repeat?(Input::DOWN)        $game_system.se_play($data_system.cursor_se)        @index[-1] = (@index[-1]+1)%check_command_size(@index)        @index[-1] += 1 if @index.size > 1 and @index[-1] == 0        @index = [0] if @index == [@true_commands.size-1]      end      # 方向键上被按下的情况下      if Input.repeat?(Input::UP)        $game_system.se_play($data_system.cursor_se)        @index[-1] -= 1 if @index.size > 1 and @index[-1] == 1        @index[-1] -= 1 if @index == [0]        @index[-1] = (@index[-1]-1)%check_command_size(@index)      end      # 方向键左被按下的情况下      if Input.trigger?(Input::LEFT)        if @index.size == 1          $game_system.se_play($data_system.buzzer_se)        else          @index.pop          $game_system.se_play($data_system.cancel_se)        end      end      # 方向键右被按下的情况下      if Input.trigger?(Input::RIGHT)        if is_folder?(@true_commands,@index)          $game_system.se_play($data_system.decision_se)          folder(@index,false)        end      end      # B键被按下的情况下      if Input.trigger?(Input::B)        if @index.size == 1          $game_system.se_play($data_system.buzzer_se)        else          @index.pop          $game_system.se_play($data_system.cancel_se)          folder(@index)        end      end      # C键被按下的情况下      if Input.trigger?(Input::C)        @c = !is_folder?(@true_commands,@index)        if is_folder?(@true_commands,@index)          $game_system.se_play($data_system.decision_se)          folder(@index,false)        end      end    end    update_cursor_rect  end  #--------------------------------------------------------------------------  # ● 更新光标矩形  #--------------------------------------------------------------------------  def update_cursor_rect    return if @move_to != 0    mouse_x, mouse_y = Mouse.get_mouse_pos    # y 坐标修正    mouse_y -= 16    if mouse_x > self.x and mouse_x < self.x + self.width and      mouse_y > self.y - 32 and self.y > mouse_y and self.oy > 0      self.oy        -= 32      @new_bitmap.oy -= 32    end    iindex = @index.dup    begin      if mouse_y > self.y and mouse_y < self.y + self.height and        mouse_x > self.x and mouse_x < self.x + self.width        pos = ((mouse_y - self.y+self.oy)/32).to_i        str = @spread_command.true_to_s.pos(pos+1,"1") + "2"        size = str.unit_size("[")-str.unit_size("]")        str += "]" * size        begin          @index = eval((eval(str)).pos_(2).gsub("]["){","})        rescue          @index = eval((eval(str)).pos_(2))        end        @index = [@true_commands.size-2] if @index.size == 1 and @index[0] == @true_commands.size-1      end    rescue      # 超过范围      @index = iindex    end    x, y = check_index_xy(@index)    if y - self.oy >= self.height - 32      self.oy        += 32      @new_bitmap.oy += 32    elsif y - self.oy < 0      self.oy        -= 32      @new_bitmap.oy -= 32    end    self.cursor_rect.set(x, y-self.oy, [email protected]_to_s.size/3*32, 32, true)  endend#==============================================================================# ■ Array#------------------------------------------------------------------------------#  数组类  又拿数组开刀...#==============================================================================class Array  #--------------------------------------------------------------------------  # ● 返回目标位置 [[1,1,1,1],1,1,2]  #--------------------------------------------------------------------------  def pos_(unit)    string = ""    times = 0    for i in self      if i.is_a?(Array)        string += "[#{times}]#{i.pos_(unit)}" if i.true_to_s.include?(unit.to_s)      else        string += "[#{times}]" if i == unit        break if i == unit      end      times += 1    end    string  end  #--------------------------------------------------------------------------  # ● 转换 真 字符串  #--------------------------------------------------------------------------  def true_to_s    string = "["    for unit in self      string += unit.is_a?(Array) ? unit.true_to_s + "," : "#{unit},"    end    string + "]"  end  #--------------------------------------------------------------------------  # ● 转换 新 字符串  #--------------------------------------------------------------------------  def new_to_s    string = ""    for unit in self      string += "[#{unit}]"    end    string  end  #--------------------------------------------------------------------------  # ● 全部 自相加  #--------------------------------------------------------------------------  def self_all_plus    var = 0    self.each {|unit| var +=  unit.is_a?(Array) ? unit.self_all_plus : 1}    var  endend#==============================================================================# ■ String#------------------------------------------------------------------------------#  字符类  拿字符开刀了!#==============================================================================class String  def pos(var,str)    temp = 0    self.size.times {|i|    temp += 1 if self[i,1] == str    return self[0,i] if temp == var}  end  def unit_size(unit)    temp = 0    self.size.times {|i|    temp += 1 if self[i,1] == unit}    return temp  endend复制代码
    复制代码
    最后,附赠范例(RM文件浏览,据说可以拿来CG、BGM鉴赏)

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

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2025-3-15 04:36 , Processed in 0.114045 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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