#------------------------------------------------------------------------------
# Save_Load_FF7
# ----------------------------------------------
# By Veld
# ---------------------------------------------
# Ce script permet de modifier la scene de sauvegarde et de chargement :
# - Face set des personnages de l'equipe
# - Nom du premier personnage de l'equipe
# - niveau du premier personnage de l'equipe
# - Demande de confirmation de sauvegarde
# - choix dans le nombre de sauvegarde
# - Dans Graphic/Character creer un fichier Facesave
# - dans lequel vous ajouterai les Faceset ayant le même nom que les Battlecharset voulu
# - de taille 72*72
# - Script a ajouter au dessus de Main
#------------------------------------------------------------------------------
module ExtraConstants
NB_SAVE_SLOTS = 10 #changer le nombre de slot de sauvegarde
MODE_SLOTS = 0
end
# Window_SaveFile
#------------------------------------------------------------------------------
# ???????????????????????????????????
#==============================================================================
class Window_SaveFile < Window_Base
#--------------------------------------------------------------------------
# ? ??????????
#--------------------------------------------------------------------------
attr_reader :filename # ?????
attr_reader :selected # ????
#--------------------------------------------------------------------------
# ? ?????????
# file_index : ?????????????? (0~3)
# filename : ?????
#--------------------------------------------------------------------------
def initialize(file_index, filename)
super(0, 64 + file_index * 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 = "Sauvegarde#{@file_index + 1}.rxdata"
@game_party_leader = ""
@game_party_leadlvl = ""
#@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)
@total_sec = @frame_count / Graphics.frame_rate
@game_party = Marshal.load(file)
@game_map_name = Marshal.load(file)
@game_party_leader = @game_party.actors[0].name
@game_party_leadlvl = @game_party.actors[0].level.to_s
file.close
end
refresh
@selected = false
rescue
file.close
@selected = false
@file_exist = false
@game_party_leader = "Cette sauvegarde est corrompue - Choisissez une autre sauvegarde."
refresh
end
#--------------------------------------------------------------------------
# ? ??????
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# ?????????
self.contents.font.color = normal_color
if @game_party_leader == ""
name = "Vide"
else
name = "Slot #{@file_index + 1} "
end
self.contents.draw_text(4, 0, 600, 32, name)
@name_width = contents.text_size(name).width
# ??????????????
if @file_exist
# ?????????
for i in
0...@characters.size bitmap = RPG::Cache.character("Facesave/"+@characters[i][0], @characters[i][1])
cw = bitmap.rect.width
ch = bitmap.rect.height
src_rect = Rect.new(0, 0, cw, ch)
x = 240 - @characters.size * 32 + i * 76 - cw / 2
self.contents.blt(x, 68 - ch, bitmap, src_rect)
end
# ????????
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, 22, 600, 32, time_string, 2)
# ??????????
self.contents.font.color = normal_color
self.contents.draw_text(4, 45, 600, 32, @game_map_name, 2)
self.contents.font.color = Color.new(190 ,0,0, 255) # Ici pour modifier la couleur du nom du perso pricncipal
self.contents.draw_text(4, 0, 600, 32, @game_party_leader , 2)
self.contents.font.color = system_color
self.contents.draw_text(4, 22, 430, 32, "Level",2)
self.contents.font.color = normal_color
self.contents.draw_text(4, 22, 480, 32, @game_party_leadlvl ,2)
end
end
#--------------------------------------------------------------------------
# ? ???????
# selected : ??????? (true=?? false=???
#--------------------------------------------------------------------------
def selected=(selected)
@selected = selected
update_cursor_rect
end
#--------------------------------------------------------------------------
# ? ?????????
#--------------------------------------------------------------------------
def update_cursor_rect
if @selected
self.cursor_rect.set(0, 0, @name_width + 8, 32)
else
self.cursor_rect.empty
end
end
end
#====================================================#==========================
# ¦ Scene_Save
#------------------------------------------------------------------------------
# ?????????????????
#====================================================#==========================
class Scene_Save < Scene_File
# -----------------------------
def initialize
super("Voulez vous sauvegarder la partie ?")
@confirm_window = Window_Base.new(120, 188, 400, 64)
@confirm_window.contents = Bitmap.new(368, 32)
string = "Voulez vous remplacer cette sauvegarde ?"
@confirm_window.contents.font.name = "Arial"
@confirm_window.contents.font.size = $fontsize
@confirm_window.contents.draw_text(4, 0, 368, 32, string)
@yes_no_window = Window_Command.new(100, ["Oui", "Non"])
@confirm_window.visible = false
@confirm_window.z = 1500
@yes_no_window.visible = false
@yes_no_window.active = false
@yes_no_window.index = 1
@yes_no_window.x = 270
@yes_no_window.y = 252
@yes_no_window.z = 1500
@mode = 0
end
# -----------------------------
def on_decision(filename)
if FileTest.exist?(filename)
@confirm_window.visible = true
@yes_no_window.visible = true
@yes_no_window.active = true
@mode = 1
else
$game_system.se_play($data_system.save_se)
file = File.open(filename, "wb")
write_save_data(file)
file.close
if $game_temp.save_calling
$game_temp.save_calling = false
$scene = Scene_Map.new
return
end
$scene = Scene_Menu.new(4)
end
end
# -----------------------------
def update
if @mode == 0
super
else
@help_window.update
@yes_no_window.update
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
if @yes_no_window.index == 0
filename = make_filename(@file_index)
$game_system.se_play($data_system.save_se)
file = File.open(filename, "wb")
write_save_data(file)
file.close
if $game_temp.save_calling
$game_temp.save_calling = false
$scene = Scene_Map.new
else
$scene = Scene_Menu.new(4)
end
else
@confirm_window.visible = false
@yes_no_window.visible = false
@yes_no_window.active = false
@yes_no_window.index = 1
@mode = 0
end
end
if Input.trigger?(Input::B)
@confirm_window.visible = false
@yes_no_window.visible = false
@yes_no_window.active = false
@yes_no_window.index = 1
@mode = 0
return
end
end
end
# -----------------------------
def on_cancel
$game_system.se_play($data_system.cancel_se)
if $game_temp.save_calling
$game_temp.save_calling = false
$scene = Scene_Map.new
return
end
$scene = Scene_Menu.new(4)
end
# -----------------------------
def write_save_data(file)
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue])
end
Marshal.dump(characters, file)
Marshal.dump(Graphics.frame_count, file)
$game_system.save_count += 1
$game_system.magic_number = $data_system.magic_number
Marshal.dump($game_party, file)
Marshal.dump($game_map.name, file)
Marshal.dump($game_system, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_screen, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_map, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_player, file)
end
end
#==============================================================================
# ¦ Scene_Load
#------------------------------------------------------------------------------
# ?????????????????
#==============================================================================
class Scene_Load < Scene_File
#--------------------------------------------------------------------------
# ? ?????????
#--------------------------------------------------------------------------
def initialize
# ???????????????
$game_temp = Game_Temp.new
# ??????????????????
$game_temp.last_file_index = 0
latest_time = Time.at(0)
for i in 0..NB_SAVE_SLOTS-1
filename = make_filename(i)
if FileTest.exist?(filename)
file = File.open(filename, "r")
if file.mtime > latest_time
latest_time = file.mtime
$game_temp.last_file_index = i
end
file.close
end
end
super("Charger quelle partie ?")
end
#--------------------------------------------------------------------------
# ? ??????
#--------------------------------------------------------------------------
def on_decision(filename)
# ????????????
unless FileTest.exist?(filename)
# ??? SE ???
$game_system.se_play($data_system.buzzer_se)
return
end
# ??? SE ???
$game_system.se_play($data_system.load_se)
# ???????????
file = File.open(filename, "rb")
read_save_data(file)
file.close
# BGM?BGS ???
$game_system.bgm_play($game_system.playing_bgm)
$game_system.bgs_play($game_system.playing_bgs)
# ?????? (????????
$game_map.update
# ??????????
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# ? ?????????
#--------------------------------------------------------------------------
def on_cancel
# ????? SE ???
$game_system.se_play($data_system.cancel_se)
# ???????????
$scene = Scene_Title.new
end
#--------------------------------------------------------------------------
# ? ???????????
# file : ??????????????? (??????
#--------------------------------------------------------------------------
def read_save_data(file)
characters = Marshal.load(file)
Graphics.frame_count = Marshal.load(file)
$game_party = Marshal.load(file)
@game_map_name = Marshal.load(file)
$game_system = Marshal.load(file)
$game_switches = Marshal.load(file)
$game_variables = Marshal.load(file)
$game_self_switches = Marshal.load(file)
$game_screen = Marshal.load(file)
$game_actors = Marshal.load(file)
$game_map = Marshal.load(file)
$game_troop = Marshal.load(file)
$game_player = Marshal.load(file)
# ???????????????????
# (?????????????????
if $game_system.magic_number != $data_system.magic_number
# ????????
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
# ???????????????
$game_party.refresh
end
end
#==============================================================================
# ¦ Scene_File
#------------------------------------------------------------------------------
# ????????????????????????
#==============================================================================
class Scene_File
include ExtraConstants
def initialize(help_text)
@help_text = help_text
@first_window
@last_window
@top_window
@bottom_window
end
#--------------------------------------------------------------------------
# ? ?????
#--------------------------------------------------------------------------
def main
# ???????????
@help_window = Window_Help.new
@help_window.set_text(@help_text)
@top_window = 0
@bottom_window = NB_SAVE_SLOTS-1
@savefile_windows = []
for i in 0..NB_SAVE_SLOTS-1
@savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
if i == 0 then
@first_window = i
elsif i == 3 then
@last_window = i
end
end
# ??????????????
@file_index = $game_temp.last_file_index
if @file_index > NB_SAVE_SLOTS-1 then
@file_index = 0
end
@savefile_windows[@file_index].selected = true
if @file_index >3 then
@last_window = @file_index
@first_window = @file_index - 3
for i in 0...@savefile_windows.size
@savefile_windows[i].y = @savefile_windows[i].y - (104 * (@file_index- 3) )
if i < @first_window then
@savefile_windows[i].visible = false
end
end
end
# ?????????
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
if self.is_a?(Scene_Save)
@confirm_window.dispose
@yes_no_window.dispose
end
end
#--------------------------------------------------------------------------
# ? ??????
#--------------------------------------------------------------------------
def update
# ????????
@help_window.update
for i in @savefile_windows
i.update
end
# C ??????????
if Input.trigger?(Input::C)
# ???? on_decision (?????? ???
on_decision(make_filename(@file_index))
$game_temp.last_file_index = @file_index
return
end
# B ??????????
if Input.trigger?(Input::B)
# ???? on_cancel (?????? ???
on_cancel
return
end
if Input.repeat?(Input:: DOWN) or Input.trigger?(Input:: DOWN)
# ????????????????????????
# ?????????? 3 ??????
###
if @file_index == @last_window and @file_index == @bottom_window
if MODE_SLOTS == 1 then
$game_system.se_play($data_system.buzzer_se)
return
elsif NB_SAVE_SLOTS < 5 then
@savefile_windows[@file_index].selected = false
@file_index = 0
@savefile_windows[@file_index].selected = true
$game_system.se_play($data_system.cursor_se)
return
end
@savefile_windows[@top_window].y = @savefile_windows[@bottom_window].y + 104
@top_window = @top_window + 1
@bottom_window = @bottom_window + 1
if @bottom_window == NB_SAVE_SLOTS then
@bottom_window = 0
end
if @top_window == NB_SAVE_SLOTS then
@top_window = 0
end
end
if @file_index == @last_window
for i in @savefile_windows
i.y = i.y - 104
end
$game_system.se_play($data_system.cursor_se)
@savefile_windows[@file_index].selected = false
@savefile_windows[@first_window].visible = false
@file_index = @file_index + 1
if @file_index == NB_SAVE_SLOTS then
@file_index = 0
end
@savefile_windows[@file_index].selected = true
@savefile_windows[@file_index].visible = true
@first_window = @first_window + 1
@last_window = @last_window + 1
if @last_window == NB_SAVE_SLOTS then
@last_window = 0
end
if @first_window == NB_SAVE_SLOTS then
@first_window = 0
end
else
# ???? SE ???
$game_system.se_play($data_system.cursor_se)
# ?????????
@savefile_windows[@file_index].selected = false
@file_index = @file_index + 1
if @file_index == NB_SAVE_SLOTS then
@file_index = 0
end
@savefile_windows[@file_index].selected = true
@savefile_windows[@file_index].visible = true
return
end
end
if Input.repeat?(Input::UP) or Input.trigger?(Input::UP)
if @file_index == @first_window and @file_index == @top_window
if MODE_SLOTS == 1 then
$game_system.se_play($data_system.buzzer_se)
return
elsif NB_SAVE_SLOTS < 5 then
@savefile_windows[@file_index].selected = false
@file_index = NB_SAVE_SLOTS - 1
@savefile_windows[@file_index].selected = true
$game_system.se_play($data_system.cursor_se)
return
end
@savefile_windows[@bottom_window].y = @savefile_windows[@top_window].y - 104
@top_window = @top_window - 1
@bottom_window = @bottom_window - 1
if @bottom_window == -1 then
@bottom_window = NB_SAVE_SLOTS-1
end
if @top_window == -1 then
@top_window = NB_SAVE_SLOTS-1
end
end
if @file_index == @first_window
for i in @savefile_windows
i.y = i.y + 104
end
$game_system.se_play($data_system.cursor_se)
@savefile_windows[@file_index].selected = false
@file_index = @file_index - 1
if @file_index == -1 then
@file_index = NB_SAVE_SLOTS-1
end
@savefile_windows[@file_index].selected = true
@savefile_windows[@file_index].visible = true
@first_window = @first_window - 1
@last_window = @last_window - 1
if @last_window == -1 then
@last_window = NB_SAVE_SLOTS - 1
end
if @first_window == -1 then
@first_window = NB_SAVE_SLOTS-1
end
else
# ???? SE ???
$game_system.se_play($data_system.cursor_se)
# ?????????
@savefile_windows[@file_index].selected = false
@file_index = @file_index - 1
if @file_index == -1 then
@file_index = NB_SAVE_SLOTS - 1
end
@savefile_windows[@file_index].selected = true
@savefile_windows[@file_index].visible = true
return
end
end
end
#--------------------------------------------------------------------------
# ? ????????
# file_index : ?????????????? (0~3)
#--------------------------------------------------------------------------
def make_filename(file_index)
return "Sauvegarde#{file_index + 1}.rxdata"
end
end
#==============================================================================
# Game_Map
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
def name
$map_infos[@map_id]
end
end
#==============================================================================
# Scene_title
#==============================================================================
class Scene_Title
$map_infos = load_data("Data/MapInfos.rxdata")
for key in $map_infos.keys
$map_infos[key] = $map_infos[key].name
end
end