#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
# This is a superclass for the save screen and load screen.
#==============================================================================
class Scene_File
#--------------------------------------------------------------------------
# * Object Initialization
# help_text : text string shown in the help window
#--------------------------------------------------------------------------
def initialize(help_text)
@currentChoice=-1
@spriteset=nil
@help_text = help_text
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make help window
@help_window = Window_Help.new
@help_window.set_text(@help_text)
@help_window.opacity=200
@help_window.z=20000
# Make save file window
@savefile_windows = []
for i in 0..3
@savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
@savefile_windows[i].opacity=200
@savefile_windows[i].z=20000
end
# Select last file to be operated
@file_index = $game_temp.last_file_index
@savefile_windows[@file_index].selected = true
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@help_window.dispose
@spriteset.dispose if @spriteset
for i in @savefile_windows
i.dispose
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if @file_index != @currentChoice
@spriteset.dispose if @spriteset
@spriteset=nil
filename=make_filename(@file_index)
if FileTest.exist?(filename)
file = File.open(filename, "rb")
readTempSaveData(file)
file.close
@spriteset=Spriteset_Map.new
end
@currentChoice=@file_index
end
# Update windows
@help_window.update
for i in @savefile_windows
i.update
end
# If C button was pressed
if Input.trigger?(Input::C)
# Call method: on_decision (defined by the subclasses)
on_decision(make_filename(@file_index))
$game_temp.last_file_index = @file_index
return
end
# If B button was pressed
if Input.trigger?(Input::B)
# Call method: on_cancel (defined by the subclasses)
on_cancel
return
end
# If the down directional button was pressed
if Input.repeat?(Input::DOWN)
# If the down directional button pressed down is not a repeat,
# or cursor position is more in front than 3
if Input.trigger?(Input::DOWN) or @file_index < 3
# Play cursor SE
$game_system.se_play($data_system.cursor_se)
# Move cursor down
@savefile_windows[@file_index].selected = false
@file_index = (@file_index + 1) % 4
@savefile_windows[@file_index].selected = true
return
end
end
# If the up directional button was pressed
if Input.repeat?(Input::UP)
# If the up directional button pressed down is not a repeatã€
# or cursor position is more in back than 0
if Input.trigger?(Input::UP) or @file_index > 0
# Play cursor SE
$game_system.se_play($data_system.cursor_se)
# Move cursor up
@savefile_windows[@file_index].selected = false
@file_index = (@file_index + 3) % 4
@savefile_windows[@file_index].selected = true
return
end
end
end
#--------------------------------------------------------------------------
# * Make File Name
# file_index : save file index (0-3)
#--------------------------------------------------------------------------
def make_filename(file_index)
return "Save#{file_index + 1}.rxdata"
end
def readTempSaveData(file)
# Read character data for drawing save file
characters = Marshal.load(file)
# Read frame count for measuring play time
Marshal.load(file)
# Read each type of game object
Marshal.load(file)
Marshal.load(file)
Marshal.load(file)
Marshal.load(file)
$game_screen = Marshal.load(file)
Marshal.load(file)
Marshal.load(file)
Marshal.load(file)
$game_map = Marshal.load(file)
$game_player = Marshal.load(file)
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
end
class Scene_Save
def main
@oldvars=[$game_map,$game_player,$game_screen]
super
$game_map=@oldvars[0]
$game_player=@oldvars[1]
$game_screen=@oldvars[2]
end
def on_decision(filename)
# Play save SE
$game_system.se_play($data_system.save_se)
# Write save data
file = File.open(filename, "wb")
$game_map=@oldvars[0]
$game_player=@oldvars[1]
$game_screen=@oldvars[2]
write_save_data(file)
file.close
# If called from event
if $game_temp.save_calling
# Clear save call flag
$game_temp.save_calling = false
# Switch to map screen
$scene = Scene_Map.new
return
end
# Switch to menu screen
$scene = Scene_Menu.new(4)
end
end