#-----------------------------------------------------------------------------#
# 脚本设定 #
#-----------------------------------------------------------------------------#
# 说明: #
# ①主要采用了Snap To Bitmap这脚本省去了DLL。 #
# ②采用了禁术,各位不用到处改脚本了,不过冲突率也大增== #
# ③脚本当中采用的脚本归原作者所有。 #
# ④设置区域的变量请自行更改。 #
#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
# 创建存档文件夹 #
#-----------------------------------------------------------------------------#
Dir.mkdir("Saves/") unless FileTest.directory?("Saves/")
#-----------------------------------------------------------------------------#
# 存档界面用窗口 #
#-----------------------------------------------------------------------------#
class Window_Save < Window_Base
#---------------------------------------------------------------------------#
# 初始化 #
#---------------------------------------------------------------------------#
def initialize
super(160,64,640-160,480-64)#(160,64,800,736)
self.contents = Bitmap.new(width-32,height-32)
@_index = -1
#refresh(0, nil)
end
#---------------------------------------------------------------------------#
# 刷新 #
#---------------------------------------------------------------------------#
def refresh(index, filename)
if index != @_index
# 清除原有资料
self.contents.clear
@sprite.dispose if @sprite != nil
@sprite = nil
# 开始读取资料
@file_index = index
@filename = filename
@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)
@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)
@bitmap = @game_system.snap_bitmap
@total_sec = @frame_count / Graphics.frame_rate
file.close
# 描绘角色
([email]0...@characters.size[/email]).each do |i|
x = i*56 + 24
bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
self.contents.blt(x,328,bitmap,Rect.new(0,0,bitmap.width/4,bitmap.height/4))
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(0,320,448,32,time_string,2)
# 描绘时间标记
self.contents.font.color = normal_color
time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
self.contents.draw_text(0,352,448,32,time_string, 2)
else
self.contents.draw_text(0,320,448,32,"无存档",1)
end
@_index = index
end
end
#---------------------------------------------------------------------------#
# 释放 #
#---------------------------------------------------------------------------#
def dispose
super
@sprite.dispose if @sprite != nil
@sprite = nil
end
end
#-----------------------------------------------------------------------------#
# 存档界面 #
#-----------------------------------------------------------------------------#
class Scene_Load
#---------------------------------------------------------------------------#
# 初始化 #
#---------------------------------------------------------------------------#
def initialize
super("要载入哪个文件?")
end
#---------------------------------------------------------------------------#
# 主执行 #
#---------------------------------------------------------------------------#
def main
# 再生成临时对像
$game_temp = Game_Temp.new
# 选择存档时间最新的文件
$game_temp.last_file_index = 0
latest_time = Time.at(0)
if @filenames == nil
@filenames = []
Dir.foreach("Saves") do |s|
@filenames << $1 if /(.+?)\.rxdata/ === s
end
if @filenames.empty?
@filenames = ["无存档"]
end
end
([email]0...@filenames.size[/email]).each do |i|
filename = make_filename(i)
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
@command_window = Window_Command.new(160,@filenames)
@command_window.height = 480-64#736
@command_window.y = 64
@command_window.active = true
# 存档资料窗口
@save_window = Window_Save.new
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果画面切换的话的就中断循环
if $scene != self
break
end
end
# 准备过渡
Graphics.freeze
# 释放窗口
@save_window.dispose
@command_window.dispose
end
#---------------------------------------------------------------------------#
# 刷新 #
#---------------------------------------------------------------------------#
def update
update_command
end
#---------------------------------------------------------------------------#
# 选择存档窗口刷新 #
#---------------------------------------------------------------------------#
def update_command
@command_window.update
filename = @filenames[@command_window.index]
@save_window.refresh(@command_window.index, filename)
# 按下取消键
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?(filename)
# 演奏冻结 SE
$game_system.se_play($data_system.buzzer_se)
return
end
# 演奏读档 SE
$game_system.se_play($data_system.load_se)
# 写入存档数据
file = File.open(filename, "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_Menu.new(0)
end
end
#---------------------------------------------------------------------------#
# 读档 #
#---------------------------------------------------------------------------#
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