class Window_File < Window_Base attr_accessor :index def initialize(index = 0) @backsp = Sprite.new # @backsp.bitmap = Bitmap.new("Graphics/Pictures/菜单底图.jpg") @backsp.z = 100 super(160,64,480,416) #这行可以不用 self.contents = Bitmap.new(width - 32, height - 32) @index = index #这里我要说明一句,之所以用sprite是为了放缩图片 @sprite = Sprite.new @sprite.visible = false @sprite.z = 100 @sp_ch = [] @sp_ch[0] = Sprite.new refresh end def refresh self.contents.clear for i in @sp_ch i.visible = false end @sprite.visible = false if FileTest.exist?(DIR+"Save#{@index}.rxdata") @sprite.visible = true if FileTest.exist?(DIR+"Save#{@index}.jpg") @sprite.bitmap = Bitmap.new(DIR+"Save#{@index}.jpg") else self.contents.draw_text(32,64,400,32,"截图似乎有点问题……您搞什么了您? ") end @sprite.x = 290 @sprite.y = 96 @sprite.z = 998 @sprite.zoom_x = 0.5 @sprite.zoom_y = 0.5 file = File.open(DIR+"Save#{@index}.rxdata", "r") @time_stamp = file.mtime @characters = Marshal.load(file) @frame_count = Marshal.load(file) @game_system = Marshal.load(file) @game_switches = Marshal.load(file) @game_variables = Marshal.load(file) @total_sec = @frame_count / Graphics.frame_rate file.close for i in [email]0...@characters.size[/email] @sp_ch[i] = Sprite.new @sp_ch[i].visible = true testname = @characters[i][2].name+"_f" @sp_ch[i].bitmap = Bitmap.new("Graphics/battlers/#{testname}") @sp_ch[i].zoom_x = 0.8 @sp_ch[i].zoom_y = 0.8 @sp_ch[i].x = 180 @sp_ch[i].y = 96 + i*90 @sp_ch[i].z = 101 end # 描绘游戏时间 hour = @total_sec / 60 / 60 min = @total_sec / 60 % 60 sec = @total_sec % 60 time_string = sprintf("%02d:%02d:%02d", hour, min, sec) self.contents.font.color = normal_color self.contents.draw_text(4, 326, 420, 32, time_string, 2) # 描绘时间标记 self.contents.font.color = normal_color time_string = @time_stamp.strftime("%Y/%m/%d %H:%M") self.contents.draw_text(4, 356, 420, 32, time_string, 2) else self.contents.draw_text(32,32,420,32,"这个存档是空的") end end def dispose super @sprite.dispose @backsp.dispose for i in @sp_ch i.dispose end end end class Window_File2 < Window_Base attr_accessor :index def initialize(index = 0) @backsp = Sprite.new # @backsp.bitmap = Bitmap.new("Graphics/Pictures/菜单底图.jpg") @backsp.z = 100 super(160,0,480,480) #这行可以不用 self.contents = Bitmap.new(width - 32, height - 32) @index = index #这里我要说明一句,之所以用sprite是为了放缩图片 @sprite = Sprite.new @sprite.visible = false @sprite.z = 100 @sp_ch = [] @sp_ch[0] = Sprite.new refresh end def refresh self.contents.clear for i in @sp_ch i.visible = false end @sprite.visible = false if FileTest.exist?(DIR+"Save#{@index}.rxdata") @sprite.visible = true if FileTest.exist?(DIR+"Save#{@index}.jpg") @sprite.bitmap = Bitmap.new(DIR+"Save#{@index}.jpg") else self.contents.draw_text(32,64,400,32,"截图似乎有点问题……您搞什么了您? ") end @sprite.x = 290 @sprite.y = 32 @sprite.z = 998 @sprite.zoom_x = 0.5 @sprite.zoom_y = 0.5 file = File.open(DIR+"Save#{@index}.rxdata", "r") @time_stamp = file.mtime @characters = Marshal.load(file) @frame_count = Marshal.load(file) @game_system = Marshal.load(file) @game_switches = Marshal.load(file) @game_variables = Marshal.load(file) @total_sec = @frame_count / Graphics.frame_rate file.close for i in [email]0...@characters.size[/email] @sp_ch[i] = Sprite.new @sp_ch[i].visible = true testname = @characters[i][2].name+"_f" @sp_ch[i].bitmap = Bitmap.new("Graphics/battlers/#{testname}") @sp_ch[i].x = 180 @sp_ch[i].y = 32 + i*110 @sp_ch[i].z = 101 end # 描绘游戏时间 hour = @total_sec / 60 / 60 min = @total_sec / 60 % 60 sec = @total_sec % 60 time_string = sprintf("%02d:%02d:%02d", hour, min, sec) self.contents.font.color = normal_color self.contents.draw_text(4, 390, 420, 32, time_string, 2) # 描绘时间标记 self.contents.font.color = normal_color time_string = @time_stamp.strftime("%Y/%m/%d %H:%M") self.contents.draw_text(4, 420, 420, 32, time_string, 2) else self.contents.draw_text(32,32,420,32,"这个存档是空的") end end def dispose super @sprite.dispose @backsp.dispose for i in @sp_ch i.dispose end end end $打开自动存档用的开关编号 = 1 $自动存档位置 = 0 $按下F5之后的自动存档的音效 = "Audio/SE/007-System07" $按下F5之后禁止存档时候的音效 = "Audio/Se/003-System03" DIR = "Save/" $打开自动存档开关之后调用的公共事件 = 0 #——默认未定义 $按下F5之后可以存档调用的公共事件 = 0 #——默认未定义 $按下F5之后禁止存档调用的公共事件 = 0 #——默认未定义 class Scene_Map alias auto_update update def update auto_update #——按下F5的时候自动存档,可以修改为F5,F6,F7,F8,也可以修改成默认按键但是不推荐。 #——注意在不可存档的时候是无效的 if Input.trigger?(Input::F5) unless $game_system.map_interpreter.running? if $game_system.save_disabled Audio.se_play($按下F5之后禁止存档时候的音效) $game_temp.common_event_id = $按下F5之后禁止存档调用的公共事件 else Audio.se_play($按下F5之后的自动存档的音效) $game_temp.common_event_id = $按下F5之后可以存档调用的公共事件 auto_save end end end #——当BOSS战之前打开一下定义的开关,即可自动存档 if $game_switches[$打开自动存档用的开关编号] == true $game_switches[$打开自动存档用的开关编号] = false $game_temp.common_event_id = $打开自动存档开关之后调用的公共事件 auto_save end end def auto_save #——这里定义了储存的文件,如果不希望用Save4可以自己修改编号 # 写入存档数据 Screen::shot file = File.open( DIR+"Save#{$自动存档位置}.rxdata", "wb") auto_save_data(file) if FileTest.exist?( DIR+"shot.jpg") File.rename( DIR+"shot.jpg", DIR+"Save#{$自动存档位置}.jpg") end file.close end def auto_save_data(file) #——以下定义内容和Scene_Save的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]) end # 写入描绘存档文件用的角色数据 Marshal.dump(characters, file) # 写入测量游戏时间用画面计数 Marshal.dump(Graphics.frame_count, file) # 增加 1 次存档次数 $game_system.save_count += 1 # 保存魔法编号 # (将编辑器保存的值以随机值替换) $game_system.magic_number = $data_system.magic_number # 写入各种游戏对像 Marshal.dump($game_system, file) Marshal.dump($game_switches, file) Marshal.dump($game_variables, file) Marshal.dump($game_self_switches, file) Marshal.dump($game_screen, file) Marshal.dump($game_actors, file) Marshal.dump($game_party, file) Marshal.dump($game_troop, file) Marshal.dump($game_map, file) Marshal.dump($game_player, file) end end DIR = "Save/" # 储存文件夹名,请制作游戏时自行建立此文件夹 module Screen @screen = Win32API.new 'screenshot', 'Screenshot', %w(l l l l p l l), '' @readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l' @findwindow = Win32API.new 'user32', 'FindWindowA', %w(p p), 'l' module_function def shot(file = "shot", typ = 1) # to add the right extension... if typ == 0 typname = ".bmp" elsif typ == 1 typname = ".jpg" elsif typ == 2 typname = ".png" end file_index = 0 dir = "Save/" # make the filename.... file_name = dir + file.to_s + typname.to_s # make the screenshot.... Attention dont change anything from here on.... @screen.call(0,0,640,480,file_name,handel,typ) end # find the game window... def handel game_name = "\0" * 256 @readini.call('Game','Title','',game_name,255,".\\Game.ini") game_name.delete!("\0") return @findwindow.call('RGSS Player',game_name) end end class Scene_Menu alias shotsave_main main def main if @menu_index == 0 Screen::shot end shotsave_main end end class Interpreter #-------------------------------------------------------------------------- # ● 调用存档画面 #-------------------------------------------------------------------------- def command_352 # 设置战斗中断标志 $game_temp.battle_abort = true # 设置调用存档标志 $game_temp.save_calling = true # 推进索引 @index += 1 # 结束 Screen::shot return false end end #============================================================================== # ■ Scene_Load #------------------------------------------------------------------------------ # 处理读档画面的类。 #============================================================================== class Scene_Load #-------------------------------------------------------------------------- # ● 初始化对像 #-------------------------------------------------------------------------- def initialize # 再生成临时对像 $game_temp = Game_Temp.new # 选择存档时间最新的文件 $game_temp.last_file_index = 0 latest_time = Time.at(0) for i in 0..51 filename = DIR+"Save#{i}.rxdata" if FileTest.exist?(filename) file = File.open(filename, "r") if file.mtime > latest_time latest_time = file.mtime $game_temp.last_file_index = i end file.close end end end def main @command_window = Window_Command.new(160,["自动存档","进度一","进度二", "进度三","进度四","进度五","进度六","进度七","进度八","进度九","进度十", "进度十一","进度十二","进度十三","进度十四","进度十五","进度十六", "进度十七","进度十八","进度十九","进度二十","进度二一","进度二二", "进度二三","进度二四","进度二五","进度二六","进度二七","进度二八", "进度二九","进度三十","进度三一","进度三二","进度三三","进度三四", "进度三五","进度三六","进度三七","进度三八","进度三九","进度四十", "进度四一","进度四二","进度四三","进度四四","进度四五","进度四六", "进度四七","进度四八","进度四九","进度五十"]) @command_window.y = 0 @command_window.height = 480 @command_window.index = $game_temp.last_file_index @content_window = Window_File2.new($game_temp.last_file_index) # 执行过渡 Graphics.transition # 主循环 loop do # 刷新游戏画面 Graphics.update # 刷新输入信息 Input.update # 刷新画面 update # 如果画面被切换的话就中断循环 if $scene != self break end end # 准备过渡 Graphics.freeze @command_window.dispose @content_window.dispose end def update @command_window.update if @command_window.index != @content_window.index @content_window.index = @command_window.index @content_window.refresh end #——————下面这一部分是原装脚本——————# if Input.trigger?(Input::B) # 演奏取消 SE $game_system.se_play($data_system.cancel_se) # 切换到标题画面 $scene = Scene_Title.new end #———————————————————————# if Input.trigger?(Input::C) # 文件不存在的情况下 unless FileTest.exist?(DIR+"Save#{@command_window.index}.rxdata") # 演奏冻结 SE $game_system.se_play($data_system.buzzer_se) return end # 演奏读档 SE $game_system.se_play($data_system.load_se) # 写入存档数据 file = File.open(DIR+"Save#{@command_window.index}.rxdata", "rb") read_save_data(file) 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 #———————————————————————# end #-------------------------------------------------------------------------- # ● 写入存档数据 # file : 写入用文件对像 (已经打开) #-------------------------------------------------------------------------- def read_save_data(file) # 读取描绘存档文件用的角色数据 characters = Marshal.load(file) # 读取测量游戏时间用画面计数 Graphics.frame_count = Marshal.load(file) # 读取各种游戏对像 $game_system = Marshal.load(file) $game_switches = Marshal.load(file) $game_variables = Marshal.load(file) $game_self_switches = Marshal.load(file) $game_screen = Marshal.load(file) $game_actors = Marshal.load(file) $game_party = Marshal.load(file) $game_troop = Marshal.load(file) $game_map = Marshal.load(file) $game_player = Marshal.load(file) # 魔法编号与保存时有差异的情况下 # (加入编辑器的编辑过的数据) 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 #============================================================================== # Window_LoadCommand #------------------------------------------------------------------------------ # 存取档画面选择按钮窗口 #============================================================================== class Window_LoadCommand < Window_Selectable #-------------------------------------------------------------------------- # 初始化对象 #-------------------------------------------------------------------------- def initialize super(320, 0, 320, 64) self.contents = Bitmap.new(width - 32, height - 32) @item_max = 2 @column_max = 2 @commands = ["读取", "存储"] refresh self.index = 0 end #-------------------------------------------------------------------------- # 刷新 #-------------------------------------------------------------------------- def refresh self.contents.clear for i in 0...@item_max draw_item(i) end end #-------------------------------------------------------------------------- # 描画按钮文字 #-------------------------------------------------------------------------- def draw_item(index) x = 4 + index * 160 self.contents.draw_text(x, 0, 144, 32, @commands[index]) end #-------------------------------------------------------------------------- # ● 项目无效化 # index : 项目编号 #-------------------------------------------------------------------------- def disable_item(index) draw_item(index, disabled_color) end end #============================================================================== # Scene_Loadsave #------------------------------------------------------------------------------ # 处理存取档画面的类。 #============================================================================== class Scene_Loadsave #-------------------------------------------------------------------------- # ● 初始化对像 # $last_savefile_index : 记录光标位置 #-------------------------------------------------------------------------- def initialize $last_savefile_index = 0 if $last_savefile_index == nil # 再生成临时对像 $game_temp = Game_Temp.new # 选择存档时间最新的文件 $game_temp.last_file_index = 0 latest_time = Time.at(0) for i in 0..51 filename = DIR+"Save#{i}.rxdata" if FileTest.exist?(filename) file = File.open(filename, "r") if file.mtime > latest_time latest_time = file.mtime $game_temp.last_file_index = i end file.close end end end #-------------------------------------------------------------------------- # 主处理 #-------------------------------------------------------------------------- def main @savestate = 0 # 生成窗口 @help_window = Window_LoadHelp.new @help_window.set_text("请选择.") @option_window = Window_LoadCommand.new @option_window.index = $last_savefile_index ######################################################## @command_window = Window_Command.new(160,["自动存档","进度一","进度二", "进度三","进度四","进度五","进度六","进度七","进度八","进度九","进度十", "进度十一","进度十二","进度十三","进度十四","进度十五","进度十六", "进度十七","进度十八","进度十九","进度二十","进度二一","进度二二", "进度二三","进度二四","进度二五","进度二六","进度二七","进度二八", "进度二九","进度三十","进度三一","进度三二","进度三三","进度三四", "进度三五","进度三六","进度三七","进度三八","进度三九","进度四十", "进度四一","进度四二","进度四三","进度四四","进度四五","进度四六", "进度四七","进度四八","进度四九","进度五十"]) @command_window.y = 64 @command_window.height = 416 @command_window.index = $game_temp.last_file_index @content_window = Window_File.new($game_temp.last_file_index) @command_window.active = false ###############覆盖存档 @confirm_window = Window_Base.new(120, 188, 400, 64) @confirm_window.contents = Bitmap.new(368, 32) string = "确定要覆盖这个进度吗?" @confirm_window.contents.font.name = "黑体" @confirm_window.contents.font.size = 24 @confirm_window.contents.draw_text(4, 0, 368, 32, string) @yes_no_window = Window_Command.new(100, ["覆盖", "取消"]) @confirm_window.z = 1500 @yes_no_window.index = 1 @yes_no_window.x = 270 @yes_no_window.y = 252 @yes_no_window.z = 1500 @confirm_window.visible = false @yes_no_window.visible = false @yes_no_window.active = false # 执行过渡 Graphics.transition # 主循环 loop do # 刷新游戏画面 Graphics.update # 刷新输入信息 Input.update # 刷新画面 update # 如果画面被切换的话就中断循环 if $scene != self break end end # 准备过渡 Graphics.freeze # 释放窗口 @command_window.dispose @content_window.dispose @confirm_window.dispose @yes_no_window.dispose @help_window.dispose @option_window.dispose end #-------------------------------------------------------------------------- # ● 刷新画面 #-------------------------------------------------------------------------- def update # 刷新窗口 @help_window.update @option_window.update # @content_window.update @command_window.update if @yes_no_window.active confirm_update return end @content_window.index = @command_window.index @content_window.refresh case @savestate when 0 if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) # 淡入淡出 BGM Audio.bgm_fade(800) # 返回地图 if $menu_call == false # 切换到地图画面 $scene = Scene_Map.new return end # 切换到菜单画面 $menu_call = false $scene = Scene_Menu.new(7) end if Input.trigger?(Input::C) case @option_window.index when 0 @command_window.active = true @option_window.active = false $game_system.se_play($data_system.decision_se) @help_window.set_text("请选择一个文件进行读取.") @savestate = 1 return when 1 @command_window.active = true @option_window.active = false $game_system.se_play($data_system.decision_se) @help_window.set_text("请选择一个文件进行存储.") @savestate = 2 return return end end when 1,2 if Input.trigger?(Input::C) if @savestate == 1 $menu_call = false load_file return else # 禁止存档的情况下 if $game_system.save_disabled @help_window.set_text("抱歉,这里禁止存储.") # 演奏冻结 SE $game_system.se_play($data_system.buzzer_se) return end $game_system.se_play($data_system.decision_se) $last_savefile_index = @option_window.index save_file return end end # 取消 if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) @command_window.active = false @help_window.set_text("请选择.") @savestate = 0 @option_window.active = true return end if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) @savestate = 2 @command_window.active = true return end end end #-------------------------------------------------------------------------- # 建立记录文件索引 #-------------------------------------------------------------------------- #-------------------------------------------------------------------------- # 读取记录文件 # filename : 被读取文件 #-------------------------------------------------------------------------- def load_file # 文件不存在的情况下 unless FileTest.exist?(DIR+"Save#{@command_window.index}.rxdata") # 演奏冻结 SE $game_system.se_play($data_system.buzzer_se) return end # 演奏读档 SE $game_system.se_play($data_system.load_se) # 写入存档数据 file = File.open(DIR+"Save#{@command_window.index}.rxdata", "rb") read_save_data(file) 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 #-------------------------------------------------------------------------- # ● 读取存档数据 # file : 读取用文件对像 (已经打开) #-------------------------------------------------------------------------- def read_save_data(file) # 读取描绘存档文件用的角色数据 characters = Marshal.load(file) # 读取测量游戏时间用画面计数 Graphics.frame_count = Marshal.load(file) # 读取各种游戏对像 $game_system = Marshal.load(file) $game_switches = Marshal.load(file) $game_variables = Marshal.load(file) $game_self_switches = Marshal.load(file) $game_screen = Marshal.load(file) $game_actors = Marshal.load(file) $game_party = Marshal.load(file) $game_troop = Marshal.load(file) $game_map = Marshal.load(file) $game_player = Marshal.load(file) # 魔法编号与保存时有差异的情况下 # (加入编辑器的编辑过的数据) 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 #-------------------------------------------------------------------------- # ● 写入存档文件 #-------------------------------------------------------------------------- def save_file if Input.trigger?(Input::C) unless FileTest.exist?(DIR+"Save#{@command_window.index}.rxdata") # 演奏冻结 SE # 演奏存档 SE $game_system.se_play($data_system.save_se) # 写入存档数据 file = File.open(DIR+"Save#{@command_window.index}.rxdata", "wb") write_save_data(file) if FileTest.exist?(DIR+"shot.jpg") File.rename(DIR+"shot.jpg", DIR+"Save#{@command_window.index}.jpg") end file.close $game_temp.last_file_index = @command_window.index # 如果被事件调用 if $game_temp.save_calling # 清除存档调用标志 $game_temp.save_calling = false @confirm_window.dispose # 切换到地图画面 $scene = Scene_Map.new return end # 切换到菜单画面 $scene = Scene_Map.new end @yes_no_window.active = true @command_window.active = false end #———————————————————————# end #------------------------------------------------------------------- def confirm_update @command_index = @command_window.index @confirm_window.visible = true @confirm_window.z = 1500 @yes_no_window.visible = true @yes_no_window.active = true @yes_no_window.z = 1500 @yes_no_window.update if Input.trigger?(Input::C) if @yes_no_window.index == 0 ####################################################### # 演奏存档 SE $game_system.se_play($data_system.save_se) # 写入存档数据 file = File.open(DIR+"Save#{@command_window.index}.rxdata", "wb") write_save_data(file) if FileTest.exist?(DIR+"shot.jpg") File.rename(DIR+"shot.jpg", DIR+"Save#{@command_window.index}.jpg") end file.close $game_temp.last_file_index = @command_window.index # 如果被事件调用 if $game_temp.save_calling # 清除存档调用标志 $game_temp.save_calling = false @confirm_window.dispose @content_window.dispose # 切换到地图画面 $scene = Scene_Map.new return end # 切换到菜单画面 $scene = Scene_Map.new else $game_system.se_play($data_system.cancel_se) @yes_no_window.active = false @command_window.active = true end end if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) @yes_no_window.active = false @command_window.active = true end 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]) end # 写入描绘存档文件用的角色数据 Marshal.dump(characters, file) # 写入测量游戏时间用画面计数 Marshal.dump(Graphics.frame_count, file) # 增加 1 次存档次数 $game_system.save_count += 1 # 保存魔法编号 # (将编辑器保存的值以随机值替换) $game_system.magic_number = $data_system.magic_number # 写入各种游戏对像 Marshal.dump($game_system, file) Marshal.dump($game_switches, file) Marshal.dump($game_variables, file) Marshal.dump($game_self_switches, file) Marshal.dump($game_screen, file) Marshal.dump($game_actors, file) Marshal.dump($game_party, file) Marshal.dump($game_troop, file) Marshal.dump($game_map, file) Marshal.dump($game_player, file) end end #============================================================================== # ■ Window_LoadHelp #------------------------------------------------------------------------------ # 存取档画面帮助信息的显示窗口。 #============================================================================== class Window_LoadHelp < Window_Base #-------------------------------------------------------------------------- # 初始化对象 #-------------------------------------------------------------------------- def initialize super(0, 0, 320, 64) self.contents = Bitmap.new(width - 32, height - 32) end #-------------------------------------------------------------------------- # 刷新文本 #-------------------------------------------------------------------------- def set_text(text, align = 1) if text != @text or align != @align self.contents.clear self.contents.font.color = normal_color self.contents.draw_text(4, 0, self.width - 40, 32, text, align) @text = text @align = align @actor = nil end self.visible = true end end #============================================================================== # Scene_Loadsave #------------------------------------------------------------------------------ # 处理存取档画面的类。 #============================================================================== class Scene_Loadsave #-------------------------------------------------------------------------- # ● 初始化对像 # $last_savefile_index : 记录光标位置 #-------------------------------------------------------------------------- def initialize $last_savefile_index = 0 if $last_savefile_index == nil # 再生成临时对像 $game_temp = Game_Temp.new # 选择存档时间最新的文件 $game_temp.last_file_index = 0 latest_time = Time.at(0) for i in 0..51 filename = DIR+"Save#{i}.rxdata" if FileTest.exist?(filename) file = File.open(filename, "r") if file.mtime > latest_time latest_time = file.mtime $game_temp.last_file_index = i end file.close end end end #-------------------------------------------------------------------------- # 主处理 #-------------------------------------------------------------------------- def main @savestate = 0 # 生成窗口 @help_window = Window_LoadHelp.new @help_window.set_text("请选择.") @option_window = Window_LoadCommand.new @option_window.index = $last_savefile_index ######################################################## @command_window = Window_Command.new(160,["自动存档","进度一","进度二", "进度三","进度四","进度五","进度六","进度七","进度八","进度九","进度十", "进度十一","进度十二","进度十三","进度十四","进度十五","进度十六", "进度十七","进度十八","进度十九","进度二十","进度二一","进度二二", "进度二三","进度二四","进度二五","进度二六","进度二七","进度二八", "进度二九","进度三十","进度三一","进度三二","进度三三","进度三四", "进度三五","进度三六","进度三七","进度三八","进度三九","进度四十", "进度四一","进度四二","进度四三","进度四四","进度四五","进度四六", "进度四七","进度四八","进度四九","进度五十"]) @command_window.y = 64 @command_window.height = 416 @command_window.index = $game_temp.last_file_index @content_window = Window_File.new($game_temp.last_file_index) @command_window.active = false ###############覆盖存档 @confirm_window = Window_Base.new(120, 188, 400, 64) @confirm_window.contents = Bitmap.new(368, 32) string = "确定要覆盖这个进度吗?" @confirm_window.contents.font.name = "黑体" @confirm_window.contents.font.size = 24 @confirm_window.contents.draw_text(4, 0, 368, 32, string) @yes_no_window = Window_Command.new(100, ["覆盖", "取消"]) @confirm_window.z = 1500 @yes_no_window.index = 1 @yes_no_window.x = 270 @yes_no_window.y = 252 @yes_no_window.z = 1500 @confirm_window.visible = false @yes_no_window.visible = false @yes_no_window.active = false # 执行过渡 Graphics.transition # 主循环 loop do # 刷新游戏画面 Graphics.update # 刷新输入信息 Input.update # 刷新画面 update # 如果画面被切换的话就中断循环 if $scene != self break end end # 准备过渡 Graphics.freeze # 释放窗口 @command_window.dispose @content_window.dispose @confirm_window.dispose @yes_no_window.dispose @help_window.dispose @option_window.dispose end #-------------------------------------------------------------------------- # ● 刷新画面 #-------------------------------------------------------------------------- def update # 刷新窗口 @help_window.update @option_window.update # @content_window.update @command_window.update if @yes_no_window.active confirm_update return end @content_window.index = @command_window.index @content_window.refresh case @savestate when 0 if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) # 淡入淡出 BGM Audio.bgm_fade(800) # 返回地图 if $menu_call == false # 切换到地图画面 $scene = Scene_Map.new return end # 切换到菜单画面 $menu_call = false $scene = Scene_Menu.new(7) end if Input.trigger?(Input::C) case @option_window.index when 0 @command_window.active = true @option_window.active = false $game_system.se_play($data_system.decision_se) @help_window.set_text("请选择一个文件进行读取.") @savestate = 1 return when 1 @command_window.active = true @option_window.active = false $game_system.se_play($data_system.decision_se) @help_window.set_text("请选择一个文件进行存储.") @savestate = 2 return return end end when 1,2 if Input.trigger?(Input::C) if @savestate == 1 $menu_call = false load_file return else # 禁止存档的情况下 if $game_system.save_disabled @help_window.set_text("抱歉,这里禁止存储.") # 演奏冻结 SE $game_system.se_play($data_system.buzzer_se) return end $game_system.se_play($data_system.decision_se) $last_savefile_index = @option_window.index save_file return end end # 取消 if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) @command_window.active = false @help_window.set_text("请选择.") @savestate = 0 @option_window.active = true return end if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) @savestate = 2 @command_window.active = true return end end end #-------------------------------------------------------------------------- # 建立记录文件索引 #-------------------------------------------------------------------------- #-------------------------------------------------------------------------- # 读取记录文件 # filename : 被读取文件 #-------------------------------------------------------------------------- def load_file # 文件不存在的情况下 unless FileTest.exist?(DIR+"Save#{@command_window.index}.rxdata") # 演奏冻结 SE $game_system.se_play($data_system.buzzer_se) return end # 演奏读档 SE $game_system.se_play($data_system.load_se) # 写入存档数据 file = File.open(DIR+"Save#{@command_window.index}.rxdata", "rb") read_save_data(file) 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 #-------------------------------------------------------------------------- # ● 读取存档数据 # file : 读取用文件对像 (已经打开) #-------------------------------------------------------------------------- def read_save_data(file) # 读取描绘存档文件用的角色数据 characters = Marshal.load(file) # 读取测量游戏时间用画面计数 Graphics.frame_count = Marshal.load(file) # 读取各种游戏对像 $game_system = Marshal.load(file) $game_switches = Marshal.load(file) $game_variables = Marshal.load(file) $game_self_switches = Marshal.load(file) $game_screen = Marshal.load(file) $game_actors = Marshal.load(file) $game_party = Marshal.load(file) $game_troop = Marshal.load(file) $game_map = Marshal.load(file) $game_player = Marshal.load(file) # 魔法编号与保存时有差异的情况下 # (加入编辑器的编辑过的数据) 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 #-------------------------------------------------------------------------- # ● 写入存档文件 #-------------------------------------------------------------------------- def save_file if Input.trigger?(Input::C) unless FileTest.exist?(DIR+"Save#{@command_window.index}.rxdata") # 演奏冻结 SE # 演奏存档 SE $game_system.se_play($data_system.save_se) # 写入存档数据 file = File.open(DIR+"Save#{@command_window.index}.rxdata", "wb") write_save_data(file) if FileTest.exist?(DIR+"shot.jpg") File.rename(DIR+"shot.jpg", DIR+"Save#{@command_window.index}.jpg") end file.close $game_temp.last_file_index = @command_window.index # 如果被事件调用 if $game_temp.save_calling # 清除存档调用标志 $game_temp.save_calling = false @confirm_window.dispose # 切换到地图画面 $scene = Scene_Map.new return end # 切换到菜单画面 $scene = Scene_Map.new end @yes_no_window.active = true @command_window.active = false end #———————————————————————# end #------------------------------------------------------------------- def confirm_update @command_index = @command_window.index @confirm_window.visible = true @confirm_window.z = 1500 @yes_no_window.visible = true @yes_no_window.active = true @yes_no_window.z = 1500 @yes_no_window.update if Input.trigger?(Input::C) if @yes_no_window.index == 0 ####################################################### # 演奏存档 SE $game_system.se_play($data_system.save_se) # 写入存档数据 file = File.open(DIR+"Save#{@command_window.index}.rxdata", "wb") write_save_data(file) if FileTest.exist?(DIR+"shot.jpg") File.rename(DIR+"shot.jpg", DIR+"Save#{@command_window.index}.jpg") end file.close $game_temp.last_file_index = @command_window.index # 如果被事件调用 if $game_temp.save_calling # 清除存档调用标志 $game_temp.save_calling = false @confirm_window.dispose @content_window.dispose # 切换到地图画面 $scene = Scene_Map.new return end # 切换到菜单画面 $scene = Scene_Map.new else $game_system.se_play($data_system.cancel_se) @yes_no_window.active = false @command_window.active = true end end if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) @yes_no_window.active = false @command_window.active = true end 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]) end # 写入描绘存档文件用的角色数据 Marshal.dump(characters, file) # 写入测量游戏时间用画面计数 Marshal.dump(Graphics.frame_count, file) # 增加 1 次存档次数 $game_system.save_count += 1 # 保存魔法编号 # (将编辑器保存的值以随机值替换) $game_system.magic_number = $data_system.magic_number # 写入各种游戏对像 Marshal.dump($game_system, file) Marshal.dump($game_switches, file) Marshal.dump($game_variables, file) Marshal.dump($game_self_switches, file) Marshal.dump($game_screen, file) Marshal.dump($game_actors, file) Marshal.dump($game_party, file) Marshal.dump($game_troop, file) Marshal.dump($game_map, file) Marshal.dump($game_player, file) end end
48.44 KB, 下载次数: 41
解压放到根目录即可
class Scene_File #——最大存档数量 SAVEFILE_MAX = 100 # ------------------- def initialize(help_text) @help_text = help_text end # ------------------- def main @help_window = Window_Help.new @help_window.set_text(@help_text) @savefile_windows = [] @cursor_displace = 0 for i in 0..3 @savefile_windows.push(Window_SaveFile.new(i, make_filename(i), i)) end @file_index = 0 @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 @savefile_windows i.dispose end end # ------------------- def update @help_window.update for i in @savefile_windows i.update end if Input.trigger?(Input::C) on_decision(make_filename(@file_index)) $game_temp.last_file_index = @file_index return end if Input.trigger?(Input::B) on_cancel return end if Input.repeat?(Input::DOWN) if Input.trigger?(Input::DOWN) or @file_index < SAVEFILE_MAX - 1 if @file_index == SAVEFILE_MAX - 1 $game_system.se_play($data_system.buzzer_se) return end @cursor_displace += 1 if @cursor_displace == 4 @cursor_displace = 3 for i in @savefile_windows i.dispose end @savefile_windows = [] for i in 0..3 f = i - 2 + @file_index name = make_filename(f) @savefile_windows.push(Window_SaveFile.new(f, name, i)) @savefile_windows[i].selected = false end end $game_system.se_play($data_system.cursor_se) @file_index = (@file_index + 1) if @file_index == SAVEFILE_MAX @file_index = SAVEFILE_MAX - 1 end for i in 0..3 @savefile_windows[i].selected = false end @savefile_windows[@cursor_displace].selected = true return end end if Input.repeat?(Input::UP) if Input.trigger?(Input::UP) or @file_index > 0 if @file_index == 0 $game_system.se_play($data_system.buzzer_se) return end @cursor_displace -= 1 if @cursor_displace == -1 @cursor_displace = 0 for i in @savefile_windows i.dispose end @savefile_windows = [] for i in 0..3 f = i - 1 + @file_index name = make_filename(f) @savefile_windows.push(Window_SaveFile.new(f, name, i)) @savefile_windows[i].selected = false end end $game_system.se_play($data_system.cursor_se) @file_index = (@file_index - 1) if @file_index == -1 @file_index = 0 end for i in 0..3 @savefile_windows[i].selected = false end @savefile_windows[@cursor_displace].selected = true return end end end # ------------------- def make_filename(file_index) return "Save/Save#{file_index + 1}.rxdata" end # ------------------- end class Window_SaveFile < Window_Base # ------------------- def initialize(file_index, filename, position) y = 64 + position * 104 super(0, y, 640, 104) self.contents = Bitmap.new(width - 32, height - 32) @file_index = file_index @filename = "Save/Save#{@file_index + 1}.rxdata" @time_stamp = Time.at(0) @file_exist = FileTest.exist?(@filename) if @file_exist file = File.open(@filename, "r") @time_stamp = file.mtime @characters = Marshal.load(file) @frame_count = Marshal.load(file) @game_system = Marshal.load(file) @game_switches = Marshal.load(file) @game_variables = Marshal.load(file) @total_sec = @frame_count / Graphics.frame_rate file.close end refresh @selected = false end end
255.02 KB, 下载次数: 23
范例
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |