Home > RGSS Script Reference > Scene_File
Scene_File
Inherits from: None
Description: This class handles the elements on the "file selection" menu that are common to both saving and loading. This class's two child classes, Scene_Save and Scene_Load, handle the elements specific to saving and loading, respectively.
class Scene_File
# ------------------------------------
def initialize(help_text)
@help_text = help_text
end
# ------------------------------------
def main
@help_window = Window_Help.new
@help_window.set_text(@help_text)
@savefile_windows = []
for i in 0..3
@savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
end
@file_index = $game_temp.last_file_index
@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 < 3
$game_system.se_play($data_system.cursor_se)
@savefile_windows[@file_index].selected = false
@file_index = (@file_index + 1) % 4
@savefile_windows[@file_index].selected = true
return
end
end
if Input.repeat?(Input::UP)
if Input.trigger?(Input::UP) or @file_index > 0
$game_system.se_play($data_system.cursor_se)
@savefile_windows[@file_index].selected = false
@file_index = (@file_index + 3) % 4
@savefile_windows[@file_index].selected = true
return
end
end
end
# ------------------------------------
def make_filename(file_index)
return "Save#{file_index + 1}.rxdata"
end
end
|
Help_Text: The text to be displayed in the help window.
Help_Window: A Window_Help object respresenting the help window shown on the file selection menu.
SaveFile_Windows: An array of Window_SaveFile objects, one for each of the save files.
File_Index: The index of the currently selected file.
Initialize
Arguments: None
Local Variables: None
How it Works: This method sets the help text to the appropriate value.
Main
Arguments: None
Local Variables: None
How it Works: This is the main method for this class. First, the help window and help text are set up. Then, the save file windows are set up. Starting with an empty array, each of the four save file winodws are set up with their associated index and filename. The @file_index = $game_temp.last_file_index statement sets the currently selected file to the last file either saved or loaded, depending on whether the user is saving or loading. The main loop is the loop seen in pretty much every "Scene" class. It updates the graphics, checks for input, and updates the window contents repeatedly until the value of $Scene changes (the user either selects a file or cancels). Once the scene changes, the rest of the method does garbage collection on the windows.
Update
Arguments: None
Local Variables: None
How it Works: This method updates the help window, save file windows, and responds to user input. First, the contents of the help window and the save file windows are updated. Then, the method processes input from the user. If the user presses "C" (decision key), then the Scene_Save#On_Decision or Scene_Load#On_Decision method is called, depending on whether the user is saving or loading. Also, the value of $game_temp.last_file_index is set to the selected file, so that next time the user saves or loads, this file will be selected by default. If the user presses "B" (cancel key), then either Scene_Save#On_Cancel or Scene_Load#On_Cancel is called, depending on whether the user is saving or loading. If the user presses the down arrow, then the cursor sound effect is played, and the currently selected index is incremented and modded by 4 (to prevent the selection cursor from moving beyond the last file). If the user presses the up arrow, then the cursor sound effect is played, and the currently selected index is decremented and modded by 4 (to prevent the selection cursor from moving past the first file).
Make_Filename
Arguments: None
Local Variables: None
How it Works: This method constructs the filename of the save file corresponding to the currently selected save file index. This is done by starting with the string "Save#", then adding an integer equal to the index of the currently selected save file, plus 1 (because internally, the save files start from 0), and then adds ".rxdata".
|
|