#==============================================================================
# @> Overwrite Check ~ Karin's Soulkeeper, 2015
#------------------------------------------------------------------------------
# v1.1 - Feb 22 16 : Minors tweaks to @con window handling
# v1.0 - May 08 15 : Started & finished.
#------------------------------------------------------------------------------
# * Description:
# This script adds an extra confirmation step when attempting to overwrite
# an already occupied save slot.
#------------------------------------------------------------------------------
# * To Use:
# Put this script below Materials and above Main.
#------------------------------------------------------------------------------
# * Compatibility:
# Aliased: Scene_Save.create_savefile_windows, Scene_Save.on_savefile_ok
# Overwrite: Scene_Save.update_savefile_selection.
# If you have any other scripts that modify the said methods,
# you must put this script somewhere below it.
#------------------------------------------------------------------------------
# * Terms:
# Free to use in any kind of project, with or without credit. I wouldn't
# really mind. Though I'd appreciate it! (^w^)/
# Just don't, you know, claim that you made this here script yourself,
# Because that's just mean (._.)
#==============================================================================

#CUSTOMIZATION OPTIONS
module KS
module Overwrite_Check
#--------------------------------------------------------------------------
# Set the confirmation message to be displayed in the help window
#--------------------------------------------------------------------------
HELP_TEXT = "A saved game is already present. Overwrite?"

#--------------------------------------------------------------------------
# Set the sfx to play when an overwrite is attempted (checks Audio/SE/)
#--------------------------------------------------------------------------
ALERT_SFX = "Item1"

#--------------------------------------------------------------------------
# Set the text for the 'confirm overwrite' command
#--------------------------------------------------------------------------
OVERWRITE = "Overwrite"

#--------------------------------------------------------------------------
# Set the text for the 'cancel overwrite' command
#--------------------------------------------------------------------------
CANCEL = "Cancel"

end
end

# END OF CUSTOMIZATION OPTIONS

#==============================================================================
# ** Alias Class: Scene_Save
#------------------------------------------------------------------------------
# This class performs save screen processing.
#==============================================================================

class Scene_Save < Scene_File

#--------------------------------------------------------------------------
# * Alias: Create Save File Window
#--------------------------------------------------------------------------
alias normal_stuff create_savefile_windows
def create_savefile_windows
@con = Window_Con.new
@con.set_handler(:y, method(:as_you_were))
@con.set_handler(:n, method(:on_ovr_cancel))
@con.set_handler(:cancel, method(:on_ovr_cancel))
@con.close
normal_stuff
end

#--------------------------------------------------------------------------
# * Alias: Confirm Save File
#--------------------------------------------------------------------------
alias as_you_were on_savefile_ok
def on_savefile_ok
filename = DataManager.make_filename(index)
if FileTest.exist?(filename)
print "Overwrite Attempted: #{filename};\n"
@savefile_windows.deactivate
@con.visible = true
@con.activate
@con.open
@help_window.set_text(KS::Overwrite_Check::HELP_TEXT)
Audio.se_play(sprintf("Audio/SE/%s", KS::Overwrite_Check::ALERT_SFX))
else
as_you_were
end
end
#--------------------------------------------------------------------------
# * Overwrite: Update Save File Selection
#--------------------------------------------------------------------------
def update_savefile_selection
return on_savefile_ok if Input.trigger?(:C)
return on_savefile_cancel if Input.trigger?(:B)
update_cursor unless @con.open?
end
#--------------------------------------------------------------------------
# * New: Handle Overwrite Cancel
#--------------------------------------------------------------------------
def on_ovr_cancel
@con.visible = false
@con.deactivate
@con.close
@savefile_windows.activate
@help_window.set_text(help_window_text)
end
end

#==============================================================================
# ** New Class: Window_Con
#------------------------------------------------------------------------------
# Brings up a simple confirmation window.
#==============================================================================
class Window_Con < Window_Command
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0)
update_placement
self.visible = false
open
end
#--------------------------------------------------------------------------
# * Draw Command Names Centred
#--------------------------------------------------------------------------
def draw_item(index)
change_color(normal_color, command_enabled?(index))
draw_text(item_rect_for_text(index), command_name(index), 1)
end
#--------------------------------------------------------------------------
# * Get Window Width
#--------------------------------------------------------------------------
def window_width
return 128
end
#--------------------------------------------------------------------------
# * Update Window Position
#--------------------------------------------------------------------------
def update_placement
self.x = (Graphics.width - width) / 2
self.y = (Graphics.height - height) / 2
end
#--------------------------------------------------------------------------
# * Create Command List
#--------------------------------------------------------------------------
def make_command_list
add_command(KS::Overwrite_Check::OVERWRITE, :y)
add_command(KS::Overwrite_Check::CANCEL, :n)
end
end