| 
 
| 赞 | 1 |  
| VIP | 246 |  
| 好人卡 | 87 |  
| 积分 | 1 |  
| 经验 | 34142 |  
| 最后登录 | 2015-1-15 |  
| 在线时间 | 323 小时 |  
 Lv1.梦旅人 
	梦石0 星屑55 在线时间323 小时注册时间2010-8-21帖子666 | 
| 
这个是更新版本子选项的范例工程....这
x
加入我们,或者,欢迎回来。您需要 登录 才可以下载或查看,没有帐号?注册会员  
 个工程可以浏览游戏根目录的文件,
 并且可以打开txt文件(为了偷懒,不能自动换行,不能翻页....),图片文件,音乐文件,当然,大家可以自
 
 己扩展!截图如下:
 
   
   
   
   当然,这个需要更新版本子选项脚本,以及文字渐变脚本,这个"浏览器"代码如下:
 
 注意:因为不明原因,无法识别第二级中文文件夹(只能识别第一级),并且换了操作系统之后,出现了
 迭代太深的错误(原系统没问题,所以测试的时候,极可能出现bug...)
 范例:复制代码#==============================================================================
# ■ Graphics 
#------------------------------------------------------------------------------
#  更待指定帧数 
#==============================================================================
def Graphics.wait(n)
  n.times{self.update;yield if defined? yield}
end
#==============================================================================
# ■ Scene_File_Scan
#------------------------------------------------------------------------------
#  RM 文件浏览器
#==============================================================================
class Scene_File_Scan
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #--------------------------------------------------------------------------
  def initialize
    # 穷举文件
    old_d =  Dir.pwd
    @true_files = Dir["*"]
    for i in 0...@true_files.size
      @true_files[i] = directory(@true_files[i],true) if directory?(@true_files[i])
    end
    Dir.chdir(old_d)
    @files = directory!
  end
  #--------------------------------------------------------------------------
  # ● 循环操作文件夹
  #--------------------------------------------------------------------------
  def directory(filename,first=false)
    now_d = Dir.pwd
    Dir.chdir("#{filename}/")
    files = Dir["*"]
    Dir.chdir(now_d)
    return "#{filename}(空文件夹)" if files.size == 0
    return [filename] + files if first
    for i in 0...files.size
      if directory?(files[i])
        files[i] = directory(files[i])
      end
    end
    [filename] + files
  end
  #--------------------------------------------------------------------------
  # ● 循环操作文件夹
  #--------------------------------------------------------------------------
  def directory!(filename=@true_files)
    array = []
    for unit in filename
      unit.is_a?(Array) ? array << directory!(unit) : array << File.basename(unit)
    end
    array
  end
  #--------------------------------------------------------------------------
  # ● 是文件夹? 默认不支持中文全角符号,只有再定义了...
  #--------------------------------------------------------------------------
  def directory?(filename)
    begin
      file = File.open("#{filename}/test.txt","wb")
    rescue
      return false
    end
    file.close
    File.delete("#{filename}/test.txt")
    return true
  end
  #--------------------------------------------------------------------------
  # ● 主处理
  #--------------------------------------------------------------------------
  def main
    # 生成窗口
    @helper_window = Window_Help.new
    @folder_window = Window_Folder.new(0,64,640,480-64,@files)
    @helper_window.set_text("名称:#{file_name}    #{file_kind(file_name)[0]}")
    # 执行过渡
    Graphics.transition
    # 主循环
    loop do
      # 刷新游戏画面
      Graphics.update
      # 刷新输入信息
      Input.update
      # 刷新画面
      update
      # 如果画面被切换的话就中断循环
      if $scene != self
        break
      end
    end
    # 准备过渡
    Graphics.freeze
    # 释放窗口
    @folder_window.dispose
    @helper_window.dispose
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面
  #--------------------------------------------------------------------------
  def update
    # 刷新窗口
    @folder_window.update
    # C键被按下的情况下
    if Input.repeat?(Input::DOWN) or Input.repeat?(Input::UP)
      # eval("@true_files#{@folder_window.index.new_to_s}")
      @helper_window.set_text("名称:#{file_name}    #{file_kind(file_name)[0]}")
    end
    if Input.trigger?(Input::C) and @folder_window.c
      $game_system.se_play($data_system.decision_se)
      case file_kind(file_name)[1]
      when 1
        text = File.open(file_name).read.split("\n")
        window = Window_Base.new(-640,64,640, 480-64)
        window.contents = Bitmap.new(640-32,text.size*32)
        window.z = 999
        color1 = Color.new(255,  0,  0)
        color2 = Color.new(255,255,255)
        for i in 0...text.size
          len = window.contents.text_size(text[i]).width
          window.contents.draw_text(0,i*32,len,32,text[i],0,[8,color1,color2])
        end
        window.move_to(0,64,20)
        Graphics.wait(20){window.update}
        loop do
          Graphics.update
          Input.update
          break if Input.trigger?(Input::B) or Input.trigger?(Input::C)
        end
        window.move_to(-640,64,20)
        Graphics.wait(20){window.update}
        window.dispose
      when 2
        
      when 3
        bitmap = Bitmap.new(file_name)
        window = Window_Base.new(640,0,bitmap.width+32, bitmap.height + 32)
        window.contents = bitmap
        window.z = 999
        window.move_to((640 - window.width)/2,(480 - window.height)/2,20)
        Graphics.wait(20){window.update}
        loop do
          Graphics.update
          Input.update
          break if Input.trigger?(Input::B) or Input.trigger?(Input::C)
        end
        window.move_to(640,0,20)
        Graphics.wait(20){window.update}
        bitmap.dispose
        window.dispose
      when 4
        Audio.bgm_play(file_name)
      else
        @helper_window.set_text("不可识别的文件类型")
        Graphics.wait(20)
        @helper_window.set_text("名称:#{file_name}    #{file_kind(file_name)[0]}")
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 文件名称
  #--------------------------------------------------------------------------
  def file_name(array=@true_files,index=@folder_window.index)
    return get_command_name(array[index[0]]) if index.size == 1
    file_name array[index[0]],index[1...index.size]
  end
  #--------------------------------------------------------------------------
  # ● 再次 取得项目名称
  #--------------------------------------------------------------------------
  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
  #--------------------------------------------------------------------------
  # ● 文件类型
  #--------------------------------------------------------------------------
  def file_kind(filename)
    extname = File.extname(filename).downcase 
    case extname
    when ".txt"
      return "txt文本档案", 1
    when ".rxdata"
      return "RMXP用文件" , 2
    when ".png"
      return "png位图"    , 3
    when ".bmp"
      return "bmp位图"    , 3
    when ".jpg"
      return "jpg图像"    , 3
    when ".mp3"
      return "mp3音频文件", 4
    when ".wav"
      return "波形录音"   , 4
    when ".mid"
      return "MIDI文件"   , 4
    when ".ogg"
      return "ogg音频文件", 4
    when  ".wma"
      return "wma音频文件", 4
    else
      a = extname == "" ? (directory?(filename) ? "夹" : "") : ""
      a = "夹" if filename.include?("(空文件夹)")
      return "#{extname[1...extname.size]}文件#{a}",0
    end
  end
end
#==============================================================================
# ■ Window_Base
#------------------------------------------------------------------------------
#  游戏中全部窗口的超级类。
#==============================================================================
class Window_Base < Window
  #--------------------------------------------------------------------------
  # ● 初始化
  #--------------------------------------------------------------------------
  alias isa_dust_initialize initialize
  def initialize(*a)
    isa_dust_initialize(*a)
    @move_count = 0
    @move_to_x  = 0
    @move_to_y  = 0
  end
  #--------------------------------------------------------------------------
  # ● 真 移动
  #--------------------------------------------------------------------------
  def move_to(x,y,count)
    @move_to_x = x
    @move_to_y = y
    @move_count= count
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  alias isa_dust_update update
  def update
    isa_dust_update
    # 移动完毕时,直接返回
    return if @move_count <= 0
    self.x += (@move_to_x - self.x)/@move_count.to_f
    self.y += (@move_to_y - self.y)/@move_count.to_f
    @move_count -= 1
  end
end
 RM文件浏览器.rar
(358.27 KB, 下载次数: 214) | 
 |