Window_SaveFile
#============================================
# ¡ Window_SaveFile
#----------------------------------------------
# @ƒZ[ƒu‰æ–Ê‚¨‚æ‚у[ƒh‰æ–ʂং·‚éAƒZ[ƒuƒtƒ@ƒCƒ‹‚̃EƒBƒ“ƒhƒE‚Å‚·B
#============================================
class Window_SaveFile < Window_Base
#------------------------------------------
# œ ŒöŠJƒCƒ“ƒXƒ^ƒ“ƒX•Ï”
#------------------------------------------
attr_reader :filename # ƒtƒ@ƒCƒ‹–¼
attr_reader :selected # ‘I‘ðó‘Ô
#------------------------------------------
# œ ƒIƒuƒWƒFƒNƒg‰Šú‰»
# file_index : ƒZ[ƒuƒtƒ@ƒCƒ‹‚̃Cƒ“ƒfƒbƒNƒX (0`3)
# filename : ƒtƒ@ƒCƒ‹–¼
#------------------------------------------
def initialize(file_index, filename)
super(0, 64 + file_index % 4 * 104, 640, 104)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
@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
#------------------------------------------
# œ ƒŠƒtƒŒƒbƒVƒ…
#------------------------------------------
def refresh
self.contents.clear
name = "Slot #{@file_index + 1}"
self.contents.font.color = normal_color
name = "File #{@file_index + 1}"
self.contents.draw_text(4, 0, 600, 32, name)
@name_width = contents.text_size(name).width
# ƒZ[ƒuƒtƒ@ƒCƒ‹‚ª‘¶Ý‚·‚éê‡
if @file_exist
# ƒLƒƒƒ‰ƒNƒ^[‚ð•`‰æ
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
# ƒvƒŒƒCŠÔ‚ð•`‰æ
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)
# ƒ^ƒCƒ€ƒXƒ^ƒ“ƒv‚ð•`‰æ
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
#------------------------------------------
# œ ‘I‘ðó‘Ô‚ÌÝ’è
# selected : V‚µ‚¢‘I‘ðó‘Ô (true=‘I‘ð false=”ñ‘I‘ð)
#------------------------------------------
def selected=(selected)
@selected = selected
update_cursor_rect
end
#------------------------------------------
# œ ƒJ[ƒƒ‹‚Ì‹éŒ`XV
#------------------------------------------
def update_cursor_rect
if @selected
self.cursor_rect.set(0, 0, @name_width + 8, 32)
else
self.cursor_rect.empty
end
end
end
# ¡ Window_SaveFile
#----------------------------------------------
# @ƒZ[ƒu‰æ–Ê‚¨‚æ‚у[ƒh‰æ–ʂং·‚éAƒZ[ƒuƒtƒ@ƒCƒ‹‚̃EƒBƒ“ƒhƒE‚Å‚·B
#============================================
class Window_SaveFile < Window_Base
#------------------------------------------
# œ ŒöŠJƒCƒ“ƒXƒ^ƒ“ƒX•Ï”
#------------------------------------------
attr_reader :filename # ƒtƒ@ƒCƒ‹–¼
attr_reader :selected # ‘I‘ðó‘Ô
#------------------------------------------
# œ ƒIƒuƒWƒFƒNƒg‰Šú‰»
# file_index : ƒZ[ƒuƒtƒ@ƒCƒ‹‚̃Cƒ“ƒfƒbƒNƒX (0`3)
# filename : ƒtƒ@ƒCƒ‹–¼
#------------------------------------------
def initialize(file_index, filename)
super(0, 64 + file_index % 4 * 104, 640, 104)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
@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
#------------------------------------------
# œ ƒŠƒtƒŒƒbƒVƒ…
#------------------------------------------
def refresh
self.contents.clear
name = "Slot #{@file_index + 1}"
self.contents.font.color = normal_color
name = "File #{@file_index + 1}"
self.contents.draw_text(4, 0, 600, 32, name)
@name_width = contents.text_size(name).width
# ƒZ[ƒuƒtƒ@ƒCƒ‹‚ª‘¶Ý‚·‚éê‡
if @file_exist
# ƒLƒƒƒ‰ƒNƒ^[‚ð•`‰æ
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
# ƒvƒŒƒCŠÔ‚ð•`‰æ
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)
# ƒ^ƒCƒ€ƒXƒ^ƒ“ƒv‚ð•`‰æ
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
#------------------------------------------
# œ ‘I‘ðó‘Ô‚ÌÝ’è
# selected : V‚µ‚¢‘I‘ðó‘Ô (true=‘I‘ð false=”ñ‘I‘ð)
#------------------------------------------
def selected=(selected)
@selected = selected
update_cursor_rect
end
#------------------------------------------
# œ ƒJ[ƒƒ‹‚Ì‹éŒ`XV
#------------------------------------------
def update_cursor_rect
if @selected
self.cursor_rect.set(0, 0, @name_width + 8, 32)
else
self.cursor_rect.empty
end
end
end
Publicité