저장

Advanced Save Menu 편집 20101005 Edition (SDK2용)

by Alkaid posted Oct 05, 2010
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

  파일을 좀 더 수정해서 세이브파일명까지 설정할 수 있도록 하였습니다.  세이브 디렉토리는 기본이 Game.exe가 있는 곳이고('.'), 그 외의 문자열을 쓰면 지정된 이름대로 세이브 디렉토리가 생성됩니다.


#==============================================================================
# ■ ASM - advanced save menu
#------------------------------------------------------------------------------
# by squall // squall@loeher.zzn.com
# edited by J.D. Slasha (1-20-06)
# monday the 28th of november 2005
#
# Allows to have up to 99 files.
# Files are stored inside of the folder 'Saves' inside of the game's folder.
# Don't forget to create that folder if it doesn't already exist.
#==============================================================================
# Save overwriting confirm by RPG Advocate
# Merged & Edited by L
# - 20??-??-??(Date cannot be determined):
# The maximum file quantity can be configured.
# Edited it for RMXP SDK.
# Included RPG Advocate's 'Save file overwriting confirmation'.
# Made it to show some more information, like current money in possesion.
# - 2010-09-11:
# Added save directory name and extension configuration.
# Scene_Title::main_test_continue is modified.
# - 2010-10-05: Added save file name configuration, edited some codes a bit.
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
if Object.const_defined?('SDK')
SDK.log('Advanced Save Menu', 'squall', 1.0, '2005-11-28')

#--------------------------------------------------------------------------
# * Begin SDK Requirement Check
#--------------------------------------------------------------------------
SDK.check_requirements(2.0, [1])

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Advanced Save Menu')

module ASM_Setup
SAVE_DIR = '.' #Save file location. Default: Root(.)
SAVE_EXT = 'rxdata' #Save file Extension. Default: rxdata
SAVE_NAME = 'Save' #Save file name. Default: Save
SAVE_MAX_FILES = 12
end

#==============================================================================
# ■ Window_File
#------------------------------------------------------------------------------
#  This window shows a list of recorded save files.
#==============================================================================

class Window_File < Window_Selectable
include ASM_Setup
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize()
super(0, 64, 320, 416)
self.contents = Bitmap.new(width - 32, SAVE_MAX_FILES * 32)
index = $game_temp.last_file_index == nil ? 0 : $game_temp.last_file_index
self.index = index
@item_max = SAVE_MAX_FILES
refresh
end
#--------------------------------------------------------------------------
# ● refresh the window
#--------------------------------------------------------------------------
def refresh
time_stamp = Time.at(0)
for i in 0...SAVE_MAX_FILES
filename = "#{SAVE_NAME}#{i + 1}.#{SAVE_EXT}"
self.contents.draw_text(1, i * 32, 32, 32, (i + 1).to_s, 1)
if FileTest.exist?("#{SAVE_DIR}/#{filename}")
size = File.size("#{SAVE_DIR}/#{filename}")
#if size.between?(1000, 999999)
if size.between?(1024, 1048575)
#size /= 1000
size /= 1024
size_str = "#{size} Kb"
#elsif size > 999999
elsif size > 1048575
#size /= 1000000
size /= 1048576
size_str = "#{size} Mb"
else
size_str = size.to_s
end
time_stamp = File.open("#{SAVE_DIR}/#{filename}", "r").mtime
date = time_stamp.strftime("%m/%d/%Y")
time = time_stamp.strftime("%H:%M")
self.contents.draw_text(38, i * 32, 120, 32, date)
self.contents.draw_text(160, i * 32, 100, 32, time)
self.contents.draw_text(0, i * 32, 284, 32, size_str, 2)
end
end
end
end

#==============================================================================
# ■ Window_FileStatus
#------------------------------------------------------------------------------
#  This window shows the status of the currently selected save file
#==============================================================================

class Window_FileStatus < Window_Base
include ASM_Setup
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize(save_window)
super(320, 64, 320, 416)
self.contents = Bitmap.new(width - 32, height - 32)
@save_window = save_window
@index = @save_window.index
rect = Rect.new(x + 16, y + (height - 32) / 2 + 16, width - 32, (height - 32) / 2)
@viewport = Viewport.new(rect)
@viewport.z = z + 10
refresh
end
#--------------------------------------------------------------------------
# ● dispose the map and the window
#--------------------------------------------------------------------------
def dispose
tilemap_dispose
@viewport.dispose
super
end
#--------------------------------------------------------------------------
# ● refresh the window
#--------------------------------------------------------------------------
def draw_actor_face(actor, x, y)
face = RPG::Cache.character("SaveFaces/" + actor.character_name, actor.character_hue)
fw = face.width
fh = face.height
src_rect = Rect.new(0, 0, fw, fh)
self.contents.blt(x - fw / 23, y - fh, face, src_rect)
end

def refresh
self.contents.clear
#tilemap_dispose
filename = "#{SAVE_NAME}#{@index + 1}.#{SAVE_EXT}"
return unless FileTest.exist?("#{SAVE_DIR}/#{filename}")
file = File.open("#{SAVE_DIR}/#{filename}", "r")
Marshal.load(file)
frame_count = Marshal.load(file)
for i in 0...6
Marshal.load(file)
end
party = Marshal.load(file)
Marshal.load(file)
map = Marshal.load(file)
for i in 0...party.actors.size
actor = party.actors[i]
#x = i % 1 * 144 +5
x = i % 2 * 144 + 4
#y = i / 1 * 94
#y = i / 2 * 64
y = i / 2 * 94
draw_actor_name(actor, x + 30, y)
draw_actor_level(actor, x + 30, y + 20)
draw_actor_graphic(actor, x + 10, y + 60)
#draw_actor_face(actor,x+10,y+400)
end
total_sec = frame_count / Graphics.frame_rate
hour = total_sec / 60 / 60
min = total_sec / 60 % 60
sec = total_sec % 60
text = sprintf("%02d:%02d:%02d", hour, min, sec)
map_name = load_data("Data/MapInfos.rxdata")[map.map_id].name
cx = contents.text_size($data_system.words.gold).width
self.contents.font.color = system_color
#self.contents.draw_text(164, 125, 120, 32, "Play Time: ")
#self.contents.draw_text(164, 170, 120, 32, "Location: ")
self.contents.draw_text(0, 288, 120, 32, "Money:")
self.contents.draw_text(280-cx, 288, cx, 32, $data_system.words.gold, 2)
self.contents.draw_text(0, 320, 120, 32, "Play Time:")
self.contents.draw_text(0, 352, 120, 32, "Location:")
self.contents.font.color = normal_color
#self.contents.draw_text(184, 145, 120, 32, text)
#self.contents.draw_text(184, 190, 120, 32, map_name)
self.contents.draw_text(100, 288, 180-cx-2, 32, party.gold.to_s, 2)
self.contents.draw_text(100, 320, 180, 32, text, 2)
self.contents.draw_text(100, 352, 180, 32, map_name, 2)

#@tilemap = Tilemap.new(@viewport)
#@tilemap.tileset = RPG::Cache.tileset(map.tileset_name)
for i in 0..6
#autotile_name = map.autotile_names[i]
# @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
end
#@tilemap.map_data = map.data
#@tilemap.ox = map.display_x / 4 + 176
#@tilemap.oy = map.display_y / 4 + 148
end
#--------------------------------------------------------------------------
# ● tilemap_dispose
#--------------------------------------------------------------------------
def tilemap_dispose
unless @tilemap == nil
@tilemap.tileset.dispose
for i in 0..6
@tilemap.autotiles[i].dispose
end
@tilemap.dispose
@tilemap = nil
end
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
@tilemap.update if @tilemap != nil
if @index != @save_window.index
@index = @save_window.index
refresh
end
super
end
end

#==============================================================================
# ■ Scene_File
#------------------------------------------------------------------------------
#  Base scene for load and save menus.
#==============================================================================

class Scene_File < SDK::Scene_Base
include ASM_Setup
#--------------------------------------------------------------------------
# ● initialize the scene
#--------------------------------------------------------------------------
def initialize(help_text)
@help_text = help_text
end
#--------------------------------------------------------------------------
# ● main
#--------------------------------------------------------------------------
def main_window
@help_window = Window_Help.new
@help_window.set_text(@help_text)
@file_window = Window_File.new
@status_window = Window_FileStatus.new(@file_window)
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
super
if Input.trigger?(Input::C)
decision
$game_temp.last_file_index = @file_index
return
end
if Input.trigger?(Input::B)
cancel
return
end
end
#--------------------------------------------------------------------------
# ● return the selected file's name
#--------------------------------------------------------------------------
def filename
return "#{SAVE_NAME}#{@file_window.index + 1}.#{SAVE_EXT}"
end
end

#SDK Edit
#==============================================================================
# ■ Scene_Save
#------------------------------------------------------------------------------
#  Save menu
#==============================================================================

class Scene_Save < Scene_File
include ASM_Setup
#--------------------------------------------------------------------------
# ● initialize the save menu
#--------------------------------------------------------------------------
def initialize
super("Select a file to record your progress.")
overwrite_confirm_window
end
#--------------
def overwrite_confirm_window
@confirm_window = Window_Base.new(120, 188, 400, 64) #추가
@confirm_window.contents = Bitmap.new(368, 32)
string = "이 파일에 덮어쓰시겠습니까?"
#@confirm_window.contents.font.name = ["Arial","굴림"]
@confirm_window.contents.font.size = 24
@confirm_window.contents.draw_text(4, 0, 368, 32, string)
@yes_no_window = Window_Command.new(100, ["Yes", "No"])
@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
#--------------------------------------------------------------------------
# ● decision key pressed
#--------------------------------------------------------------------------
def decision
Dir.mkdir(SAVE_DIR) unless FileTest.directory?(SAVE_DIR) # Make 'Saves' directory
if FileTest.exist?("#{SAVE_DIR}/#{filename}") #추가-저장할 파일을 덮어쓸 것인가?
@file_window.active = false
@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("#{SAVE_DIR}/#{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
savename = filename
$game_system.se_play($data_system.save_se)
file = File.open("#{SAVE_DIR}/#{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
@yes_no_window.active = false
@confirm_window.visible = false
@yes_no_window.visible = false
@yes_no_window.active = false
@yes_no_window.index = 1
@file_window.active = true
@mode = 0
end
end
if Input.trigger?(Input::B)
@yes_no_window.active = false
@confirm_window.visible = false
@yes_no_window.visible = false
@yes_no_window.active = false
@yes_no_window.index = 1
@file_window.active = true
@mode = 0
return
end
end
end
#--------------------------------------------------------------------------
# ● cancel key pressed
#--------------------------------------------------------------------------
def 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
#--------------------------------------------------------------------------
# ● save the current data into the selected file
#--------------------------------------------------------------------------
def write_save_data(file)
write_characters(file)
write_frame(file)
write_setup(file)
write_data(file)
end
#--------------------------------------------------------------------------
# * Make Character Data
#--------------------------------------------------------------------------
def write_characters(file)
# Make character data for drawing save 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)
end
#--------------------------------------------------------------------------
# * Write Frame Count
#--------------------------------------------------------------------------
def write_frame(file)
# Wrire frame count for measuring play time
Marshal.dump(Graphics.frame_count, file)
end
#--------------------------------------------------------------------------
# * Write Setup
#--------------------------------------------------------------------------
def write_setup(file)
$game_system.save_count += 1
$game_system.magic_number = $data_system.magic_number
end
#--------------------------------------------------------------------------
# * Write Data
#--------------------------------------------------------------------------
def write_data(file)
# Write each type of game object
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_party, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_map, file)
Marshal.dump($game_player, file)
end
end

#SDK Edit
#==============================================================================
# ■ Scene_Load
#------------------------------------------------------------------------------
#  Load menu
#==============================================================================

class Scene_Load < Scene_File
include ASM_Setup
#--------------------------------------------------------------------------
# ● initialize the menu
#--------------------------------------------------------------------------
def initialize
$game_temp = Game_Temp.new
$game_temp.last_file_index = 0
latest_time = Time.at(0)
for i in 0..SAVE_MAX_FILES-1
filename = "#{SAVE_NAME}#{i + 1}.#{SAVE_EXT}"
if FileTest.exist?("#{SAVE_DIR}/#{filename}")
file = File.open("#{SAVE_DIR}/#{filename}", "r")
if file.mtime > latest_time
latest_time = file.mtime
$game_temp.last_file_index = i
end
file.close
end
end
super("Select a file to load.")
end
#--------------------------------------------------------------------------
# ● decision key pressed
#--------------------------------------------------------------------------
def decision
unless FileTest.exist?("#{SAVE_DIR}/#{filename}")
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.load_se)
file = File.open("#{SAVE_DIR}/#{filename}", "rb")
read_save_data(file)
file.close
$game_system.bgm_play($game_system.playing_bgm)
$game_system.bgs_play($game_system.playing_bgs)
$game_map.update
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# ● cancel key pressed
#--------------------------------------------------------------------------
def cancel
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Title.new
end
#--------------------------------------------------------------------------
# ● load the selected file
#--------------------------------------------------------------------------
def read_save_data(file)
read_characters(file)
read_frame(file)
read_data(file)
read_edit
read_refresh
end
#--------------------------------------------------------------------------
# * Read Character Data
#--------------------------------------------------------------------------
def read_characters(file)
# Read character data for drawing save file
characters = Marshal.load(file)
end
#--------------------------------------------------------------------------
# * Read Frame Count
#--------------------------------------------------------------------------
def read_frame(file)
# Read frame count for measuring play time
Graphics.frame_count = Marshal.load(file)
end
#--------------------------------------------------------------------------
# * Read Data
#--------------------------------------------------------------------------
def read_data(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_party = Marshal.load(file)
$game_troop = Marshal.load(file)
$game_map = Marshal.load(file)
$game_player = Marshal.load(file)
end
#--------------------------------------------------------------------------
# * Read Edit
#--------------------------------------------------------------------------
def read_edit
# If magic number is different from when saving
# (if editing was added with editor)
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
end
#--------------------------------------------------------------------------
# * Refresh Game Party
#--------------------------------------------------------------------------
def read_refresh
# Refresh party members
$game_party.refresh
end
end


#SDK2 Edit
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs title screen processing.
#==============================================================================

class Scene_Title < SDK::Scene_Base
#--------------------------------------------------------------------------
# * Main Test Initialization
#--------------------------------------------------------------------------
def main_test_continue
# Set Continued Enabled Flag
@continue_enabled = (Dir.glob("#{ASM_Setup::SAVE_DIR}/#{ASM_Setup::SAVE_NAME}*.#{ASM_Setup::SAVE_EXT}").size > 0)
end
end

#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end
end