赞 | 7 |
VIP | 866 |
好人卡 | 185 |
积分 | 32 |
经验 | 130059 |
最后登录 | 2024-10-29 |
在线时间 | 3618 小时 |
Lv3.寻梦者 双子人
- 梦石
- 0
- 星屑
- 3185
- 在线时间
- 3618 小时
- 注册时间
- 2009-4-4
- 帖子
- 4154
|
本帖最后由 hys111111 于 2012-5-29 18:01 编辑
第29行更改存档页数
存档数目 = 存档页数 * 4
- #==============================================================================
- # ☆★☆ Custom Save☆★☆
- #------------------------------------------------------------------------------
- # - FantasyDR
- #------------------------------------------------------------------------------
- # MSN: [email][email protected][/email]
- #------------------------------------------------------------------------------
- # - 2006.7.18
- #------------------------------------------------------------------------------
- # 自定义存档数据排列顺序并校验存档
- #==============================================================================
- #==============================================================================
- # ■ Scene_File
- #------------------------------------------------------------------------------
- # 存档画面及读档画面的超级类。
- #==============================================================================
- class Scene_File
- #--------------------------------------------------------------------------
- # ● 存档密钥,请定义成自己的密钥
- # 密钥不同的存档将无法被读取
- #--------------------------------------------------------------------------
- SAVE_KEY = 20080125
- #发布自己的游戏时,请一定要把上面的数字换掉
- #--------------------------------------------------------------------------
- # ● 常量 (存档页数)
- #--------------------------------------------------------------------------
- MaxPages = 2
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # help_text : 帮助窗口显示的字符串
- #--------------------------------------------------------------------------
- def initialize(help_text)
- @help_text = help_text
- @slots = MaxPages * 4
- end
- #--------------------------------------------------------------------------
- # ● 主处理
- #--------------------------------------------------------------------------
- def main
- # 生成帮助窗口
- @help_window = Window_Help.new
- @help_window.set_text(@help_text)
- @file_index = $game_temp.last_file_index
- # 生成存档文件窗口
- @savefile_windows = []
- # 选择最后操作的文件
- for i in @file_index / 4 * 4..@file_index / 4 * 4 + 3
- load_window(i)
- @savefile_windows[i].visible = true
- end
- @savefile_windows[@file_index].selected = true
- # 执行过渡
- Graphics.transition
- # 主循环
- loop do
- # 刷新游戏画面
- Graphics.update
- # 刷新输入信息
- Input.update
- # 刷新画面
- update
- # 如果画面被切换的话就中断循环
- if $scene != self
- break
- end
- end
-
- # 准备过渡
- Graphics.freeze
- # 释放窗口
- @help_window.dispose
- for i in 0...@slots
- @savefile_windows[i].dispose if @savefile_windows[i] != nil
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- # 刷新窗口
- @help_window.update
- for i in @file_index / 4 * 4..@file_index / 4 * 4 + 3
- @savefile_windows[i].update if @savefile_windows[i].visible
- end
- # 按下 C 键的情况下
- if Input.trigger?(Input::C)
- # 调用过程 on_decision (定义继承目标)
- on_decision(make_filename(@file_index))
- $game_temp.last_file_index = @file_index
- return
- end
- # 按下 B 键的情况下
- if Input.trigger?(Input::B)
- # 调用过程 on_cancel (定义继承目标)
- on_cancel
- return
- end
- # 按下方向键下的情况下
- if Input.repeat?(Input::DOWN)
- # 演奏光标 SE
- $game_system.se_play($data_system.cursor_se)
- # 光标向下移动
- @savefile_windows[@file_index].selected = false
- @file_index = (@file_index + 1) % @slots
- # 翻到下一页的情况下
- if @file_index % 4 == 0
- for index in @file_index / 4 * 4..@file_index / 4 * 4 + 3
- @savefile_windows[(index + @slots - 4) % @slots].visible = false
- load_window(index)
- @savefile_windows[index].visible = true
- end
- end
- @savefile_windows[@file_index].selected = true
- return
- end
- # 按下方向键上的情况下
- if Input.repeat?(Input::UP)
- # 演奏光标 SE
- $game_system.se_play($data_system.cursor_se)
- # 光标向上移动
- @savefile_windows[@file_index].selected = false
- @file_index = (@file_index + @slots - 1) % @slots
- # 翻到上一页的情况下
- if @file_index % 4 == 3
- for index in @file_index / 4 * 4..@file_index / 4 * 4 + 3
- @savefile_windows[(index + 4) % @slots].visible = false
- load_window(index)
- @savefile_windows[index].visible = true
- end
- end
- @savefile_windows[@file_index].selected = true
- return
- end
- # 按下方向键左或者 L 的情况下
- if Input.repeat?(Input::LEFT) or Input.trigger?(Input::L)
- # 演奏光标 SE
- $game_system.se_play($data_system.cursor_se)
- # 前翻一页
- @savefile_windows[@file_index].selected = false
- @file_index = (@file_index + @slots - 4) % @slots
- for index in @file_index / 4 * 4..@file_index / 4 * 4 + 3
- @savefile_windows[(index + 4) % @slots].visible = false
- load_window(index)
- @savefile_windows[index].visible = true
- end
- @savefile_windows[@file_index].selected = true
- return
- end
- # 按下方向键右或者 R 的情况下
- if Input.repeat?(Input::RIGHT) or Input.trigger?(Input::R)
- # 演奏光标 SE
- $game_system.se_play($data_system.cursor_se)
- # 前翻一页
- @savefile_windows[@file_index].selected = false
- @file_index = (@file_index + 4) % @slots
- for index in @file_index / 4 * 4..@file_index / 4 * 4 + 3
- @savefile_windows[(index + @slots - 4) % @slots].visible = false
- load_window(index)
- @savefile_windows[index].visible = true
- end
- @savefile_windows[@file_index].selected = true
- return
- end
- end
- #--------------------------------------------------------------------------
- # ● 生成文件名
- # file_index : 文件名的索引 (0~n)
- #--------------------------------------------------------------------------
- def make_filename(file_index)
- return "Save#{file_index + 1}.rxdata"
- end
- #--------------------------------------------------------------------------
- # ● 载入当前页存档
- # 避免因存档位过多造成的卡壳现象
- #--------------------------------------------------------------------------
- def load_window(i)
- if @savefile_windows[i] != nil
- return
- else
- @savefile_windows[i] = Window_SaveFile.new(i, make_filename(i))
- end
- end
- end
- #==============================================================================
- # ■ Scene_Load
- #------------------------------------------------------------------------------
- # 处理读档画面的类。
- #==============================================================================
- class Scene_Load < Scene_File
- #--------------------------------------------------------------------------
- # ● 初始化对像
- #--------------------------------------------------------------------------
- def initialize()#save_max = SAVE_MAX)
- # 再生成临时对像
- $game_temp = Game_Temp.new
- # 选择存档时间最新的文件
- $game_temp.last_file_index = 0
- latest_time = Time.at(0)
- for i in 0..7
- filename = make_filename(i)
- if FileTest.exist?(filename)
- begin
- file = Zlib::GzipReader.open(filename)
- rescue
- next
- end
- if file.mtime > latest_time
- latest_time = file.mtime
- $game_temp.last_file_index = i
- end
- file.close
- end
- end
- super("要载入哪个文件?")#,"读取",save_max)
- end
- #--------------------------------------------------------------------------
- # ● 确定时的处理
- #--------------------------------------------------------------------------
- def on_decision(filename)
- # 文件不存在的情况下
- unless FileTest.exist?(filename)
- # 演奏冻结 SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- # 演奏读档 SE
- $game_system.se_play($data_system.load_se)
- # 写入存档数据
- begin
- file = Zlib::GzipReader.open(filename)
- read_save_data(file)
- rescue
- # 演奏冻结 SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- file.close
- # 还原 BGM、BGS
- $game_system.bgm_play($game_system.playing_bgm)
- $game_system.bgs_play($game_system.playing_bgs)
- # 刷新地图 (执行并行事件)
- $game_map.update
- # 切换到地图画面
- $scene = Scene_Map.new
- end
- #--------------------------------------------------------------------------
- # ● 取消时的处理
- #--------------------------------------------------------------------------
- def on_cancel
- # 演奏取消 SE
- $game_system.se_play($data_system.cancel_se)
- # 切换到标题画面
- $scene = Scene_Title.new
- end
- #--------------------------------------------------------------------------
- # ● 读取存档数据
- # file : 读取用文件对像 (已经打开)
- #--------------------------------------------------------------------------
- def read_save_data(file)
- # 读取描绘存档文件用的角色数据
- characters = Marshal.load(file)
- # 读取测量游戏时间用画面计数
- Graphics.frame_count = Marshal.load(file)
- # 读取校验
- crcs = Marshal.load(file)
- # 读取文档字串
- strings = Marshal.load(file)
- # 校验检测
- key = SAVE_KEY
- strings.each_index do |i|
- key = Zlib.crc32(strings[i],key)
- unless crcs[i] == key
- file.close
- raise "file check error"
- return
- end
- end
- # 读取各种游戏对像
- $game_system = Marshal.load(Zlib::Inflate.inflate(strings[0]))
- $game_variables = Marshal.load(Zlib::Inflate.inflate(strings[1]))
- $game_self_switches = Marshal.load(Zlib::Inflate.inflate(strings[2]))
- $game_switches = Marshal.load(Zlib::Inflate.inflate(strings[3]))
- $game_troop = Marshal.load(Zlib::Inflate.inflate(strings[4]))
- $game_map = Marshal.load(Zlib::Inflate.inflate(strings[5]))
- $game_player = Marshal.load(Zlib::Inflate.inflate(strings[6]))
- $game_screen = Marshal.load(Zlib::Inflate.inflate(strings[7]))
- $game_actors = Marshal.load(Zlib::Inflate.inflate(strings[8]))
- $game_party = Marshal.load(Zlib::Inflate.inflate(strings[9]))
- # $data_enemies = Marshal.load(Zlib::Inflate.inflate(strings[10]))
- # $floorenemies = Marshal.load(Zlib::Inflate.inflate(strings[11]))
- # $fledam = Marshal.load(Zlib::Inflate.inflate(strings[12]))
-
- # 魔法编号与保存时有差异的情况下
- # (加入编辑器的编辑过的数据)
- if $game_system.magic_number != $data_system.magic_number
- # 重新装载地图
- $game_map.setup($game_map.map_id)
- $game_player.center($game_player.x, $game_player.y)
- end
- # 刷新同伴成员
- $game_party.refresh
- end
- end
- #==============================================================================
- # ■ Scene_Load2
- #------------------------------------------------------------------------------
- # 处理读档画面的类。
- #==============================================================================
- class Scene_Load2 < Scene_File
- #--------------------------------------------------------------------------
- # ● 初始化对像
- #--------------------------------------------------------------------------
- def initialize()#save_max = SAVE_MAX)
- # 再生成临时对像
- $game_temp = Game_Temp.new
- # 选择存档时间最新的文件
- $game_temp.last_file_index = 0
- latest_time = Time.at(0)
- for i in 0..7
- filename = make_filename(i)
- if FileTest.exist?(filename)
- begin
- file = Zlib::GzipReader.open(filename)
- rescue
- next
- end
- if file.mtime > latest_time
- latest_time = file.mtime
- $game_temp.last_file_index = i
- end
- file.close
- end
- end
- super("要载入哪个文件?")#,"读取",save_max)
- end
- #--------------------------------------------------------------------------
- # ● 确定时的处理
- #--------------------------------------------------------------------------
- def on_decision(filename)
- # 文件不存在的情况下
- unless FileTest.exist?(filename)
- # 演奏冻结 SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- # 演奏读档 SE
- $game_system.se_play($data_system.load_se)
- # 写入存档数据
- begin
- file = Zlib::GzipReader.open(filename)
- read_save_data(file)
- rescue
- # 演奏冻结 SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- file.close
- # 还原 BGM、BGS
- $game_system.bgm_play($game_system.playing_bgm)
- $game_system.bgs_play($game_system.playing_bgs)
- # 刷新地图 (执行并行事件)
- $game_map.update
- # 切换到地图画面
- $scene = Scene_Map.new
- end
- #--------------------------------------------------------------------------
- # ● 取消时的处理
- #--------------------------------------------------------------------------
- def on_cancel
- # 演奏取消 SE
- $game_system.se_play($data_system.cancel_se)
- # 切换到标题画面
- $scene = Scene_Map.new
- end
- #--------------------------------------------------------------------------
- # ● 读取存档数据
- # file : 读取用文件对像 (已经打开)
- #--------------------------------------------------------------------------
- def read_save_data(file)
- # 读取描绘存档文件用的角色数据
- characters = Marshal.load(file)
- # 读取测量游戏时间用画面计数
- Graphics.frame_count = Marshal.load(file)
- # 读取校验
- crcs = Marshal.load(file)
- # 读取文档字串
- strings = Marshal.load(file)
- # 校验检测
- key = SAVE_KEY
- strings.each_index do |i|
- key = Zlib.crc32(strings[i],key)
- unless crcs[i] == key
- file.close
- raise "file check error"
- return
- end
- end
- # 读取各种游戏对像
- $game_system = Marshal.load(Zlib::Inflate.inflate(strings[0]))
- $game_variables = Marshal.load(Zlib::Inflate.inflate(strings[1]))
- $game_self_switches = Marshal.load(Zlib::Inflate.inflate(strings[2]))
- $game_switches = Marshal.load(Zlib::Inflate.inflate(strings[3]))
- $game_troop = Marshal.load(Zlib::Inflate.inflate(strings[4]))
- $game_map = Marshal.load(Zlib::Inflate.inflate(strings[5]))
- $game_player = Marshal.load(Zlib::Inflate.inflate(strings[6]))
- $game_screen = Marshal.load(Zlib::Inflate.inflate(strings[7]))
- $game_actors = Marshal.load(Zlib::Inflate.inflate(strings[8]))
- $game_party = Marshal.load(Zlib::Inflate.inflate(strings[9]))
- # $data_enemies = Marshal.load(Zlib::Inflate.inflate(strings[10]))
- # $floorenemies = Marshal.load(Zlib::Inflate.inflate(strings[11]))
- # $fledam = Marshal.load(Zlib::Inflate.inflate(strings[12]))
-
- # 魔法编号与保存时有差异的情况下
- # (加入编辑器的编辑过的数据)
- if $game_system.magic_number != $data_system.magic_number
- # 重新装载地图
- $game_map.setup($game_map.map_id)
- $game_player.center($game_player.x, $game_player.y)
- end
- # 刷新同伴成员
- $game_party.refresh
- end
- end
- #==============================================================================
- # 自定义存档菜单
- #==============================================================================
- #==============================================================================
- # ■ Scene_Save
- #------------------------------------------------------------------------------
- # 处理存档画面的类。
- #==============================================================================
- class Scene_Save < Scene_File
- #--------------------------------------------------------------------------
- # ● 初始化对像
- #--------------------------------------------------------------------------
- def initialize()#save_max = SAVE_MAX)
- super("要保存到这个文件吗?")#,"存入",save_max)
- end
- #--------------------------------------------------------------------------
- # ● 确定时的处理
- #--------------------------------------------------------------------------
- def on_decision(filename)
- # 演奏存档 SE
- $game_system.se_play($data_system.save_se)
- # 写入存档数据
- file = Zlib::GzipWriter.open(filename,9)
- write_save_data(file)
- file.close
- # 如果被事件调用
- if $game_temp.save_calling
- # 清除存档调用标志
- $game_temp.save_calling = false
- # 切换到地图画面
- $scene = Scene_Map.new
- return
- end
- # 切换到地图画面
- $scene = Scene_Map.new
- end
- #--------------------------------------------------------------------------
- # ● 取消时的处理
- #--------------------------------------------------------------------------
- def on_cancel
- # 演奏取消 SE
- $game_system.se_play($data_system.cancel_se)
- # 如果被事件调用
- if $game_temp.save_calling
- # 清除存档调用标志
- $game_temp.save_calling = false
- # 切换到地图画面
- $scene = Scene_Map.new
- return
- end
- # 切换到地图画面
- $scene = Scene_Map.new
- end
- #--------------------------------------------------------------------------
- # ● 写入存档数据
- # file : 写入用文件对像 (已经打开)
- #--------------------------------------------------------------------------
- def write_save_data(file)
- # 生成描绘存档文件用的角色图形
- characters = []
- for i in 0...$game_party.actors.size
- actor = $game_party.actors[i]
- characters.push([actor.character_name, actor.character_hue,actor.id])
- end
-
- strings = []
-
- # 写入描绘存档文件用的角色数据
- Marshal.dump(characters,file)
- # 写入测量游戏时间用画面计数
- Marshal.dump(Graphics.frame_count,file)
- # 增加 1 次存档次数
- $game_system.save_count += 1
- # 保存魔法编号
- # (将编辑器保存的值以随机值替换)
- $game_system.magic_number = $data_system.magic_number
-
- # 写入各种游戏对像
- $game_switches[4]=true#楼层第一次刷新的开关打开以便读档后刷新
-
- strings.push(Zlib::Deflate.deflate(Marshal.dump($game_system)))
- strings.push(Zlib::Deflate.deflate(Marshal.dump($game_variables)))
- strings.push(Zlib::Deflate.deflate(Marshal.dump($game_self_switches)))
- strings.push(Zlib::Deflate.deflate(Marshal.dump($game_switches)))
- strings.push(Zlib::Deflate.deflate(Marshal.dump($game_troop)))
- strings.push(Zlib::Deflate.deflate(Marshal.dump($game_map)))
- strings.push(Zlib::Deflate.deflate(Marshal.dump($game_player)))
- strings.push(Zlib::Deflate.deflate(Marshal.dump($game_screen)))
- strings.push(Zlib::Deflate.deflate(Marshal.dump($game_actors)))
- strings.push(Zlib::Deflate.deflate(Marshal.dump($game_party)))
- # strings.push(Zlib::Deflate.deflate(Marshal.dump($data_enemies)))
- # strings.push(Zlib::Deflate.deflate(Marshal.dump($floorenemies)))
- # strings.push(Zlib::Deflate.deflate(Marshal.dump($fledam)))
-
-
- # 计算校验值
- crcs = []
- key = SAVE_KEY
- strings.each do |i|
- key = Zlib.crc32(i,key)
- crcs.push(key)
- end
- Marshal.dump(crcs,file)
- Marshal.dump(strings,file)
- end
- end
- #==============================================================================
- # ■ Window_SaveFile
- #------------------------------------------------------------------------------
- # 显示存档以及读档画面、保存文件的窗口。
- #==============================================================================
- class Window_SaveFile < Window_Base
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # file_index : 存档文件的索引 (0~n)
- # filename : 文件名
- #--------------------------------------------------------------------------
- def initialize(file_index, filename,viewport=nil)
- super(0, 64 + file_index % 4 * 104, 640, 104)
- self.contents = Bitmap.new(width - 32, height - 32)
-
- @file_index = file_index
- @filename = "Save#{file_index + 1}.rxdata"
- @time_stamp = Time.at(0)
- @file_exist = FileTest.exist?(@filename)
-
- if @file_exist
- begin
- file = Zlib::GzipReader.open(filename)
- @time_stamp = file.mtime
- @characters = Marshal.load(file)
- @frame_count = Marshal.load(file)
- @total_sec = @frame_count / Graphics.frame_rate
- file.close
- rescue
- @file_exist = false
- end
- end
-
- self.refresh
- @selected = false
- end
- end
复制代码 |
|