#===============================================================================
#
Zelda File System
# v1.1 - 03/04/11
# by SowS
#-------------------------------------------------------------------------------
# Instructions:
# Copy and paste above main.
# Just make sure that your Actor database is not empty.
#-------------------------------------------------------------------------------
# Note:
# If you want to display the HPs and MPs, follow these steps:
# 1. Uncomment the commented lines (Ctrl + Q), specifically 289-290. They're the
# ones with #~ at the start.
# 2. Cut the commented lines at the bottom part of the script and paste them
# just below line 51. Uncomment them afterwards.
# 3. There you go. Now, the problem is that the guages and the text doesn't fit
# the window. That's the reason why I didn't include them... yet. If you have
# suggestions on how to fit them, post it and I'll try it.
#===============================================================================
$imported = {} if $imported == nil
$imported["SowSZeldaFileSystem"] = true
module SOWS_ZFS
#==============================================================================
# ** SETTINGS - START
#==============================================================================
# Background image
# Set to true if you want to use a background image. The dimension must be
# 544 x 416.
USE_BG = false
BG_FILENAME = "zfs_bg"
#----------------------------------------
# Texts used in the script
FILE_LABEL = "CHOOSE A FILE"
PRESS_START = "PRESS START"
START_LABEL = "START"
ERASE_LABEL = "ERASE"
# File Status window settings
# Set to true to display. Otherwise, false. You can change the
# position of the things set to true. format is [x, y]
#----------------------------------------
# Sprites of the party members
PARTY_SPRITES = true
PARTY_SPRITES_POS = [80, 106]
#----------------------------------------
# Faces of the party members
PARTY_FACES = true
PARTY_FACES_POS = [0, 10]
#----------------------------------------
# Time played
TIME_STAMP = true
TIME_STAMP_POS = [0, 150]
#----------------------------------------
# Current gold
GOLD_HELD = true
GOLD_HELD_POS = [0, 200]
#----------------------------------------
# Current map
MAP_ON = true
MAP_ON_POS = [0, 175]
#==============================================================================
# ** SETTINGS - END
#==============================================================================
end
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
# This class handles temporary data that is not included with save data.
# The instance of this class is referenced by $game_temp.
#==============================================================================
class Game_Temp
attr_accessor :filename
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias sows_zfs_initialize initialize unless $@
def initialize
sows_zfs_initialize
@filename = ""
end
end
#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
# This window deals with general command choices.
#==============================================================================
class Window_Start < Window_Command
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias sows_zfs_initialize initialize unless $@
def initialize(*args)
sows_zfs_initialize(*args)
self.opacity = 0
end
#--------------------------------------------------------------------------
# * Update cursor
#--------------------------------------------------------------------------
def update_cursor
self.cursor_rect.empty # Empty cursor
end
end
#==============================================================================
# ** Window_SaveFile
#------------------------------------------------------------------------------
# This window displays save files on the save and load screens.
#==============================================================================
class Window_SaveFile < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# file_index : save file index (0-3)
# filename : filename
#--------------------------------------------------------------------------
def initialize(file_index, filename)
super(0, 56 + file_index % 4 * 90, 544 / 3 - 32, 90)
@file_index = file_index
@filename = filename
load_gamedata
refresh
@selected = false
end
#--------------------------------------------------------------------------
# * Load Partial Game Data
# By default, switches and variables are not used (for expansion use,
# such as displaying place names)
#--------------------------------------------------------------------------
def load_gamedata
@time_stamp = Time.at(0)
@file_exist = FileTest.exist?(@filename)
if @file_exist
file = File.open(@filename, "r")
@time_stamp = file.mtime
begin
@characters = Marshal.load(file)
@frame_count = Marshal.load(file)
@last_bgm = Marshal.load(file)
@last_bgs = Marshal.load(file)
@game_system = Marshal.load(file)
@game_message = Marshal.load(file)
@game_switches = Marshal.load(file)
@game_variables = Marshal.load(file)
@game_self_switches = Marshal.load(file)
@game_actors = Marshal.load(file)
@total_sec = @frame_count / Graphics.frame_rate
rescue
@file_exist = false
ensure
file.close
end
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
filename = @file_exist ? @game_actors[1].name : ""
name = "#{@file_index + 1} " + filename
self.contents.draw_text(4, (self.contents.height - WLH) / 2, 200, WLH, name)
end
#--------------------------------------------------------------------------
# * Update cursor
#--------------------------------------------------------------------------
def update_cursor
if @selected
self.cursor_rect.set(0, (self.contents.height - WLH) / 2, self.contents.width, WLH)
else
self.cursor_rect.empty
end
end
end
#==============================================================================
# ** Window_FileCommand
#------------------------------------------------------------------------------
# This window displays the commands for the current file selected.
#==============================================================================
class Window_FileCommand < Window_Base
include SOWS_ZFS
#--------------------------------------------------------------------------
# * Object Initialization
# index : command index (0-1)
#--------------------------------------------------------------------------
def initialize(index)
super(544 / 3 * index, 326, 544 / 3, 90)
@index = index
refresh
@selected = false
self.visible = false
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
case @index
when 0; name = START_LABEL
when 1; name = ERASE_LABEL
end
self.contents.draw_text(4, (self.contents.height - WLH) / 2, self.contents.width - 4, WLH, name)
end
#--------------------------------------------------------------------------
# * Set Selected
# selected : new selected (true = selected, false = unselected)
#--------------------------------------------------------------------------
def selected=(selected)
@selected = selected
update_cursor
end
#--------------------------------------------------------------------------
# * Update cursor
#--------------------------------------------------------------------------
def update_cursor
if @selected
self.cursor_rect.set(0, (self.contents.height - WLH) / 2, self.contents.width, WLH)
else
self.cursor_rect.empty
end
end
end
#==============================================================================
# ** Window_FileStatus
#------------------------------------------------------------------------------
# This window displays the status of the current file selected.
#==============================================================================
class Window_FileStatus < Window_Base
include SOWS_ZFS
#--------------------------------------------------------------------------
# * Object Initialization
# file_index : save file index (0-3)
# filename : filename
#--------------------------------------------------------------------------
def initialize(filename)
super(544 / 3 - 32, 56, 544 / 3 * 2 + 32, 270)
@filename = filename
load_gamedata
refresh
self.visible = false
end
#--------------------------------------------------------------------------
# * Load Partial Game Data
# By default, switches and variables are not used (for expansion use,
# such as displaying place names)
#--------------------------------------------------------------------------
def load_gamedata
@time_stamp = Time.at(0)
@file_exist = FileTest.exist?(@filename)
if @file_exist
file = File.open(@filename, "r")
@time_stamp = file.mtime
begin
@characters = Marshal.load(file)
@frame_count = Marshal.load(file)
@last_bgm = Marshal.load(file)
@last_bgs = Marshal.load(file)
@game_system = Marshal.load(file)
@game_message = Marshal.load(file)
@game_switches = Marshal.load(file)
@game_variables = Marshal.load(file)
@game_self_switches = 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)
@total_sec = @frame_count / Graphics.frame_rate
rescue
@file_exist = false
ensure
file.close
end
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
if @file_exist
draw_party_faces(PARTY_FACES_POS[0], PARTY_FACES_POS[1]) if PARTY_FACES
draw_party_characters(PARTY_SPRITES_POS[0], PARTY_SPRITES_POS[1]) if PARTY_SPRITES
draw_playtime(TIME_STAMP_POS[0], TIME_STAMP_POS[1], contents.width - 4, 2) if TIME_STAMP
draw_currency_value(@game_party.gold, GOLD_HELD_POS[0], GOLD_HELD_POS[1], contents.width - 4) if GOLD_HELD
#~ draw_party_hp(HP_GAUGE_POS[0], HP_GAUGE_POS[1]) if HP_GAUGE
#~ draw_party_mp(MP_GAUGE_POS[0], MP_GAUGE_POS[1]) if MP_GAUGE
draw_map_name(MAP_ON_POS[0], MAP_ON_POS[1]) if MAP_ON
end
end
#--------------------------------------------------------------------------
# * Draw Party Characters's Faces
# x : Draw spot X coordinate
# y : Draw spot Y coordinate
#--------------------------------------------------------------------------
def draw_party_faces(x, y)
i = @game_party.members.size - 1
while i >= 0
name = @game_party.members[i].face_name
index = @game_party.members[i].face_index
draw_face(name, index, x + i * 88, y)
i -= 1
end
end
#--------------------------------------------------------------------------
# * Draw Party Characters Sprites
# x : Draw spot X coordinate
# y : Draw spot Y coordinate
#--------------------------------------------------------------------------
def draw_party_characters(x, y)
for i in 0...@characters.size
name = @characters[i][0]
index = @characters[i][1]
draw_character(name, index, x + i * 88, y)
end
end
#--------------------------------------------------------------------------
# * Draw Party Characters's HPs
# x : Draw spot X coordinate
# y : Draw spot Y coordinate
#--------------------------------------------------------------------------
def draw_party_hp(x, y)
for i in 0...@game_party.members.size
draw_actor_hp(@game_party.members[i], x + i * 76, y, 120)
end
end
#--------------------------------------------------------------------------
# * Draw Party Characters's FMPs
# x : Draw spot X coordinate
# y : Draw spot Y coordinate
#--------------------------------------------------------------------------
def draw_party_mp(x, y)
for i in 0...@game_party.members.size
draw_actor_mp(@game_party.members[i], x + i * 76, y, 120)
end
end
#--------------------------------------------------------------------------
# * Draw Map name
# x : Draw spot X coordinate
# y : Draw spot Y coordinate
#--------------------------------------------------------------------------
def draw_map_name(x, y)
name = load_data("Data/MapInfos.rvdata")[@game_map.map_id].name
self.contents.draw_text(x, y, contents.width - 4, WLH, name, 2)
end
#--------------------------------------------------------------------------
# * Draw Play Time
# x : Draw spot X coordinate
# y : Draw spot Y coordinate
# width : Width
# align : Alignment
#--------------------------------------------------------------------------
def draw_playtime(x, y, width, align)
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(x, y, width, WLH, time_string, 2)
end
#--------------------------------------------------------------------------
# * Set Selected
# selected : new selected (true = selected, false = unselected)
#--------------------------------------------------------------------------
def selected=(selected)
@selected = selected
if @selected; self.visible = true
else; self.visible = false
end
end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs the title screen processing.
#==============================================================================
class Scene_Title < Scene_Base
include SOWS_ZFS
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
@command_window.update
if Input.trigger?(Input::C)
Sound.play_decision
$scene = Scene_File.new(false, true, false)
$game_temp.filename = $game_actors[1].name
end
end
#--------------------------------------------------------------------------
# * Create Command Window
#--------------------------------------------------------------------------
def create_command_window
@command_window = Window_Start.new(172, [PRESS_START])
@command_window.x = (544 - @command_window.width) / 2
@command_window.y = 288
@command_window.openness = 0
@command_window.open
end
end
#==============================================================================
# ** Scene_Name
#------------------------------------------------------------------------------
# This class performs name input screen processing.
#==============================================================================
class Scene_Name < Scene_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(file_index = -1)
@file_index = file_index
end
#--------------------------------------------------------------------------
# * Start processing
#--------------------------------------------------------------------------
def start
super
create_menu_background
if @file_index != -1
$game_actors[1].name = $game_temp.filename
@actor = $game_actors[1]
max_char = 10
else
@actor = $game_actors[$game_temp.name_actor_id]
max_char = $game_temp.name_max_char
end
if !$imported["SowSNISDesign"]
@input_window = Window_NameInput.new
@edit_window = Window_NameEdit.new(@actor, max_char)
end
end
#--------------------------------------------------------------------------
# * Return to Original Screen
#--------------------------------------------------------------------------
def return_scene
if @file_index == -1
$scene = Scene_Map.new
else
$scene = Scene_File.new(true, false, false, @file_index)
@actor = nil
end
end
end
#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
# This class performs the save and load screen processing.
#==============================================================================
class Scene_File < Scene_Base
include SOWS_ZFS
#--------------------------------------------------------------------------
# * Object Initialization
# saving : save flag (if false, load screen)
# from_title : flag: it was called from "Continue" on the title screen
# from_event : flag: it was called from the "Call Save Screen" event
# from_nis : flag: it was called from the name input screen
#--------------------------------------------------------------------------
alias sows_zfs_initialize initialize unless $@
def initialize(saving, from_title, from_event, file_index = -1)
sows_zfs_initialize(saving, from_title, from_event)
@file_index = file_index
@cmd_index = 0
end
#--------------------------------------------------------------------------
# * Start processing
#--------------------------------------------------------------------------
def start
if @file_index != -1
Sound.play_save
# Make file
file = File.open("Save#{@file_index + 1}.rvdata", "wb")
write_save_data(file)
file.close
end
super
create_menu_background
@help_window = Window_Help.new
create_savefile_windows
create_filecommand_windows
@index = self.latest_file_index
@help_window.set_text(FILE_LABEL)
@savefile_windows[@index].selected = true
@filestatus_windows[@index].selected = true
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
alias sows_zfs_terminate terminate unless $@
def terminate
sows_zfs_terminate
dispose_status_windows
dispose_command_windows
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias sows_zfs_update update unless $@
def update
super
update_menu_background
@help_window.update
update_status_windows
update_savefile_windows
update_command_windows
if @filecommand_windows[0].visible
update_command_selection
else
update_savefile_selection
end
end
#--------------------------------------------------------------------------
# * Create File Command Window
#--------------------------------------------------------------------------
def create_filecommand_windows
@filecommand_windows = []
for i in 0..1
@filecommand_windows.push(Window_FileCommand.new(i))
end
end
#--------------------------------------------------------------------------
# * Dispose of File Status Window
#--------------------------------------------------------------------------
def dispose_status_windows
for window in @filestatus_windows
window.dispose
end
end
#--------------------------------------------------------------------------
# * Dispose File Command Window
#--------------------------------------------------------------------------
def dispose_command_windows
for window in @filecommand_windows
window.dispose
end
end
#--------------------------------------------------------------------------
# * Update File Command Window
#--------------------------------------------------------------------------
def update_command_windows
for window in @filecommand_windows
window.update
end
end
#--------------------------------------------------------------------------
# * Update Save File Window
#--------------------------------------------------------------------------
def update_status_windows
for window in @filestatus_windows
window.update
end
end
#--------------------------------------------------------------------------
# * Update Save File Selection
#--------------------------------------------------------------------------
def update_savefile_selection
if Input.trigger?(Input::C)
determine_savefile
elsif Input.trigger?(Input::B)
Sound.play_cancel
return_scene
else
last_index = @index
if Input.repeat?(Input::DOWN)
cursor_down(Input.trigger?(Input::DOWN))
end
if Input.repeat?(Input::UP)
cursor_up(Input.trigger?(Input::UP))
end
if @index != last_index
Sound.play_cursor
@savefile_windows[last_index].selected = false
@savefile_windows[@index].selected = true
@filestatus_windows[last_index].selected = false
@filestatus_windows[@index].selected = true
end
end
end
#--------------------------------------------------------------------------
# *Update File Command Selection
#--------------------------------------------------------------------------
def update_command_selection
if Input.trigger?(Input::C)
case @cmd_index
when 0; do_load
when 1; do_erase
end
elsif Input.trigger?(Input::B)
case @index
when 0; @savefile_windows[1].visible = @savefile_windows[2].visible = true
when 1; @savefile_windows[0].visible = @savefile_windows[2].visible = true
when 2; @savefile_windows[0].visible = @savefile_windows[1].visible = true
end
@savefile_windows[@index].selected = true
@filecommand_windows[@cmd_index].selected = false
@filecommand_windows[0].visible = false
@filecommand_windows[1].visible = false
@item_max = 3
else
last_index = @cmd_index
if Input.repeat?(Input::LEFT)
cursor_left(Input.trigger?(Input::LEFT))
end
if Input.repeat?(Input::RIGHT)
cursor_right
end
if @cmd_index != last_index
Sound.play_cursor
@filecommand_windows[last_index].selected = false
@filecommand_windows[@cmd_index].selected = true
end
end
end
#--------------------------------------------------------------------------
# * Move cursor right
# wrap : Wraparound allowed
#--------------------------------------------------------------------------
def cursor_right
if @cmd_index == 0; @cmd_index = 1
elsif @cmd_index == 1; @cmd_index = 0
end
end
#--------------------------------------------------------------------------
# * Move cursor left
# wrap : Wraparound allowed
#--------------------------------------------------------------------------
def cursor_left(wrap)
if @cmd_index > 0 or wrap
@cmd_index = (@cmd_index - 1 + @item_max) % @item_max
end
end
#--------------------------------------------------------------------------
# * Confirm Save File
#--------------------------------------------------------------------------
def determine_savefile
if @savefile_windows[@index].file_exist
case @index
when 0; @savefile_windows[1].visible = @savefile_windows[2].visible = false
when 1; @savefile_windows[0].visible = @savefile_windows[2].visible = false
when 2; @savefile_windows[0].visible = @savefile_windows[1].visible = false
end
@savefile_windows[@index].selected = false
@filecommand_windows[0].visible = true
@filecommand_windows[1].visible = true
@filecommand_windows[0].selected = true
@item_max = 2
else
do_save
end
$game_temp.last_file_index = @index
end
#--------------------------------------------------------------------------
# * Execute Save
#--------------------------------------------------------------------------
def do_save
# Set player location
confirm_player_location
Sound.play_decision
$game_party.setup_starting_members # Initial party
$game_map.setup($data_system.start_map_id) # Initial map position
$game_player.moveto($data_system.start_x, $data_system.start_y)
$game_player.refresh
$file_name = "Save#{@index + 1}.rvdata"
$scene = Scene_Name.new(@index)
end
#--------------------------------------------------------------------------
# * Execute Load
#--------------------------------------------------------------------------
def do_load
Sound.play_load
file = File.open(@savefile_windows[@index].filename, "rb")
read_save_data(file)
file.close
$scene = Scene_Map.new
RPG::BGM.fade(1500)
Graphics.fadeout(60)
Graphics.wait(40)
@last_bgm.play
@last_bgs.play
end
#--------------------------------------------------------------------------
# * Execute Load
#--------------------------------------------------------------------------
def do_erase
Sound.play_decision
File.delete(@savefile_windows[@index].filename)
$scene = Scene_File.new(true, false, false)
end
#--------------------------------------------------------------------------
# * Check Player Start Location Existence
#--------------------------------------------------------------------------
def confirm_player_location
if $data_system.start_map_id == 0
print "Player start location not set."
exit
end
end
#--------------------------------------------------------------------------
# * Create Save File Window
#--------------------------------------------------------------------------
def create_savefile_windows
@savefile_windows = []
@filestatus_windows = []
for i in 0..2
@savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
@filestatus_windows.push(Window_FileStatus.new(make_filename(i)))
end
@item_max = 3
end
#--------------------------------------------------------------------------
# * Write Save Data
# file : write file object (opened)
#--------------------------------------------------------------------------
alias sows_zfs_write_save_data write_save_data unless $@
def write_save_data(file)
sows_zfs_write_save_data(file)
Marshal.dump($file_name, file)
end
#--------------------------------------------------------------------------
# * Read Save Data
# file : file object for reading (opened)
#--------------------------------------------------------------------------
alias sows_zfs_read_save_data read_save_data unless $@
def read_save_data(file)
sows_zfs_read_save_data(file)
$file_name = Marshal.load(file)
end
#--------------------------------------------------------------------------
# * Create Menu Background
#--------------------------------------------------------------------------
alias sows_zfs_create_menu_background create_menu_background unless $@
def create_menu_background
if USE_BG
@menuback_sprite = Sprite.new
@menuback_sprite.bitmap = Cache.picture(BG_FILENAME)
@menuback_sprite.x = @menuback_sprite.y = 0
else
sows_zfs_create_menu_background
end
end
end
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
# This class performs the menu screen processing.
#==============================================================================
class Scene_Menu < Scene_Base
#--------------------------------------------------------------------------
# * Update Command Selection
#--------------------------------------------------------------------------
def update_command_selection
if Input.trigger?(Input::B)
Sound.play_cancel
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
if $game_party.members.size == 0 and @command_window.index < 4
Sound.play_buzzer
return
elsif $game_system.save_disabled and @command_window.index == 4
Sound.play_buzzer
return
end
Sound.play_decision
case @command_window.index
when 0 # Item
$scene = Scene_Item.new
when 1,2,3 # Skill, equipment, status
start_actor_selection
when 4 # Save
do_save if !$file_name.nil?
when 5 # End Game
$scene = Scene_End.new
end
end
end
#--------------------------------------------------------------------------
# * Execute Save
#--------------------------------------------------------------------------
def do_save
file = File.open($file_name, "wb")
write_save_data(file)
file.close
Sound.play_save
end
#--------------------------------------------------------------------------
# * Write Save Data
# file : write file object (opened)
#--------------------------------------------------------------------------
def write_save_data(file)
characters = []
for actor in $game_party.members
characters.push([actor.character_name, actor.character_index])
end
$game_system.save_count += 1
$game_system.version_id = $data_system.version_id
@last_bgm = RPG::BGM::last
@last_bgs = RPG::BGS::last
Marshal.dump(characters, file)
Marshal.dump(Graphics.frame_count, file)
Marshal.dump(@last_bgm, file)
Marshal.dump(@last_bgs, file)
Marshal.dump($game_system, file)
Marshal.dump($game_message, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_party, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_map, file)
Marshal.dump($game_player, file)
Marshal.dump($file_name, file)
end
end
#~ #----------------------------------------
#~ # Party members' HP
#~ HP_GAUGE = true
#~ HP_GAUGE_POS = [0, 108]
#~ #----------------------------------------
#~ # Party members' MP
#~ MP_GAUGE = true
#~ MP_GAUGE_POS = [0, 140]