#==============================================================================
# ■ Window_SaveFile
#------------------------------------------------------------------------------
# 显示存档以及读档画面、保存文件的窗口。
#==============================================================================
class Window_SaveFile < Window_Base
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :filename # 文件名
attr_reader :selected # 选择状态
#--------------------------------------------------------------------------
# ● 初始化对像
# file_index : 存档文件的索引 (0~3)
# filename : 文件名
#--------------------------------------------------------------------------
def initialize(file_index, filename)
# 啊鲁~~这里为y坐标,宽,高做了分歧判定~~
case file_index
when 0
iy = 206+16+3-30-2
iw = 96
ih = 144
file_index =51
when 1
iy = 206+15+3-70-3
iw = 96
ih = 144
file_index = 140-7
when 2
iy = 206-12+3-16-3
iw = 96
ih = 144
file_index = 218+3
when 3
iy = 206-10+3-19-3
iw = 96
ih = 144
file_index = 317+4
when 4
iy = 206+22+3-75-4
iw = 96
ih = 144
file_index = 399+13
when 5
iy = 206-2+3-9-2
iw = 96
ih = 144
file_index = 490+4
else # 例外
iy = 206
iw = 96
ih = 144
file_index = 140+600
end
# ========================
super(file_index, iy, iw, ih) # 将变量代入参数~~
# super(file_index % 6 * 90+50, iy, iw, ih) # 将变量代入参数~~
self.opacity = 0 # 这个是边框和背景都透明
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
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
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# 描绘文件编号
self.contents.font.color = normal_color
name = ""#"文件 #{@file_index + 1}"
self.contents.draw_text(4, 0, 600, 32, name)
# 啊鲁~~其实这里是做一个记号~~就是下面会提到这里的...
@name_width = contents.text_size(name).width
# ==========================
# 存档文件存在的情况下
if @file_exist
# 描绘角色
for i in 0...@characters.size
bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
cw = bitmap.rect.width / 4
ch = bitmap.rect.height / 4
src_rect = Rect.new(0, 0, cw, ch)
x = 300 - @characters.size * 32 + i * 64 - cw / 2
self.contents.blt(x, 68 - ch, bitmap, src_rect)
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, 8, 600, 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, 40, 600, 32, time_string, 2)
end
end
#--------------------------------------------------------------------------
# ● 设置选择状态
# selected : 新的选择状态 (true=选择 false=不选择)
#--------------------------------------------------------------------------
def selected=(selected)
@selected = selected
update_cursor_rect
end
#--------------------------------------------------------------------------
# ● 刷新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
if @selected
# 啊鲁~~其实这里就是改光标位置和大小的地方,
# 宽度就是上面做记号的那一句再加8个像素,然后高度是32,
# 还有还有~~因为只在窗口里静态显示所以,坐标是固定的~~
self.cursor_rect.set(-15+5+3, -15+5+3, @name_width + 85-6, 32+110-10)
# ============================
else
self.cursor_rect.empty
end
end
end