赞 | 0 |
VIP | 0 |
好人卡 | 1 |
积分 | 1 |
经验 | 3966 |
最后登录 | 2016-9-10 |
在线时间 | 53 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 53 小时
- 注册时间
- 2016-2-10
- 帖子
- 21
|
2楼
楼主 |
发表于 2016-3-19 15:39:38
|
只看该作者
本帖最后由 Rivendell 于 2016-3-19 20:09 编辑
#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
# This class performs the save and load screen processing.
#==============================================================================
module FATE_SCENE_FILE
EXMNU_INCSF_FILE_MAX = 10
EXMNU_INCSF_WINDOW_HEIGHT = 120
WY = 22
HEIGHT = 60
TIME_NAME = "游戏时间"
MAP_NAME = "所在地 "
SAVE_CONFIRM = "确定保存到这个位置上吗?"
LORD_CONFIRM = "确定读取这个位置吗?"
end
class Scene_File < Scene_Base
#--------------------------------------------------------------------------
# * 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
#--------------------------------------------------------------------------
def initialize(saving, from_title, from_event)
@saving = saving
@from_title = from_title
@from_event = from_event
@menu_effect = []
end
#--------------------------------------------------------------------------
# * Start processing
#--------------------------------------------------------------------------
def start
super
@menu_file = false
$game_temp.mode = 0
if $last_scene.is_a?(Scene_Menu)
@menu_file = true
$game_temp.mode = 1
end
@file_max = FATE_SCENE_FILE::EXMNU_INCSF_FILE_MAX
create_menubackground
create_command_window
@help_window = Window_Help.new
if @menu_file == true
@help_window.opacity = 0
@help_ex_window = Window_SaveHelpEx.new(-216, -16, 576, 448)
@help_ex_window.opacity = 0
#@help_ex_window.z = 999
@back_sprite = Sprite.new
@back_sprite.bitmap = Cache.menu("MenuSaveBack")
end
create_savefile_windows
if @saving
@index = $game_temp.last_file_index
@help_window.set_text(Vocab::SaveMessage)
else
@index = self.latest_file_index
@help_window.set_text(Vocab::LoadMessage)
end
@savefile_windows[@index].selected = true
wh = FATE_SCENE_FILE::EXMNU_INCSF_WINDOW_HEIGHT
adj = (416 - @help_window.height) % wh
@help_window.height += adj
@page_file_max = ((416 - @help_window.height) / wh).truncate
for i in 0...@file_max
window = @savefile_windows
if @index > @page_file_max - 1
if @index < @file_max - @page_file_max - 1
@top_row = @index
window.y -= @index * window.height
elsif @index >= @file_max - @page_file_max
@top_row = @file_max - @page_file_max
window.y -= (@file_max - @page_file_max) * window.height
else
@top_row = @index
window.y -= @index * window.height
end
end
window.y += adj
window.visible = (window.y >= @help_window.height and
window.y < @help_window.height + @page_file_max * window.height)
end
if @menu_file == true
for i in 1..3
@menu_effect = Plane.new
@menu_effect.bitmap = Cache.menu("MenuEffect#{i}")
@menu_effect.z = -3
@menu_effect.opacity = 224
end
end
end
def create_menubackground
if @menu_file == true
@menuback = Sprite.new
@menuback.bitmap = Cache.menu(FATE_SCENE::MENU_BACK)
@menuback.opacity = 224
@menuback.z = -4
end
@menuback_sprite = Sprite.new
@menuback_sprite.bitmap = $game_temp.background_bitmap
@menuback_sprite.z = -5
update_menu_background
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@menuback.dispose if @menu_file == true
@menuback_sprite.dispose
@command_window.dispose
@help_window.dispose
dispose_item_windows
if @menu_file == true
@help_ex_window.dispose
@back_sprite.bitmap.dispose
@back_sprite.dispose
for i in 1..3
@menu_effect.dispose
end
end
end
#--------------------------------------------------------------------------
# * Return to Original Screen
#--------------------------------------------------------------------------
def return_scene
if @from_title
$scene = Scene_Title.new
elsif @from_event
$scene = Scene_Map.new
elsif @saving
$scene = Scene_Menu.new(6)
else
$scene = Scene_Menu.new(6)
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if @menu_file == true
@menu_effect[1].oy += 3
@menu_effect[2].oy += 1
end
update_menu_background
@help_window.update
if @menu_file == true
@help_window.slide(0, @help_window.y)
@help_window.contents_opacity += 16 if @help_window.contents_opacity < 255
@help_ex_window.slide(-16, -16)
if Input.dir4 != 0
@help_window.x = -80
@help_window.contents_opacity = 0
end
end
unless @command_window.active
update_savefile_windows
update_savefile_selection
end
if @command_window.active
@command_window.update
update_fileconfirm_command_selection
end
end
#--------------------------------------------------------------------------
# ● 確認コマンドウィンドウの作成
#--------------------------------------------------------------------------
def create_command_window
s1 = "是"
s2 = "否"
$game_temp.mode = 2 if @menu_file == true
@command_window = Window_Command.new(160, [s1, s2])
@command_window.x = 544 / 2 - @command_window.width / 2
@command_window.y = 416 / 2 - @command_window.height / 2
@command_window.z = 99999
@command_window.index = 0
@command_window.active = false
@command_window.openness = 0
$game_temp.mode = 1 if @menu_file == true
end
#--------------------------------------------------------------------------
# * Create Save File Window
#--------------------------------------------------------------------------
def create_savefile_windows
@top_row = 0
@savefile_windows = []
for i in 0...@file_max
@savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
end
end
#--------------------------------------------------------------------------
# * Dispose of Save File Window
#--------------------------------------------------------------------------
def dispose_item_windows
for window in @savefile_windows
window.dispose
end
end
#--------------------------------------------------------------------------
# * Update Save File Window
#--------------------------------------------------------------------------
def update_savefile_windows
for window in @savefile_windows
window.update
end
end
#--------------------------------------------------------------------------
# * Update Save File Selection
#--------------------------------------------------------------------------
def update_savefile_selection
if Input.trigger?(Input::C)
if @saving
Sound.play_decision
start_fileconfirm_command_selection
else
if @savefile_windows[@index].file_exist
Sound.play_decision
start_fileconfirm_command_selection
else
Sound.play_buzzer
return
end
end
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
end
end
end
#--------------------------------------------------------------------------
# ● ファイル確認コマンド選択の開始
#--------------------------------------------------------------------------
def start_fileconfirm_command_selection
Input.update
@command_window.active = true
if @saving
@help_window.set_text(FATE_SCENE_FILE::SAVE_CONFIRM)
else
@help_window.set_text(FATE_SCENE_FILE::LORD_CONFIRM)
end
begin
@command_window.update
Graphics.update
@command_window.openness += 40
end until @command_window.openness == 255
end
#--------------------------------------------------------------------------
# ● ファイル確認コマンド選択の終了
#--------------------------------------------------------------------------
def end_fileconfirm_command_selection
@command_window.active = false
begin
@command_window.update
Graphics.update
@command_window.openness -= 40
end until @command_window.openness == 0
@command_window.index = 0
if @saving
@help_window.set_text(Vocab::SaveMessage)
else
@help_window.set_text(Vocab::LoadMessage)
end
end
#--------------------------------------------------------------------------
# ● ファイル確認コマンドの更新
#--------------------------------------------------------------------------
def update_fileconfirm_command_selection
if Input.trigger?(Input::B)
Sound.play_cancel
end_fileconfirm_command_selection
elsif Input.trigger?(Input::C)
case @command_window.index
when 0
determine_savefile
when 1
Sound.play_cancel
end_fileconfirm_command_selection
end
end
end
#--------------------------------------------------------------------------
# * Confirm Save File
#--------------------------------------------------------------------------
def determine_savefile
if @saving
Sound.play_save
do_save
else
if @savefile_windows[@index].file_exist
Sound.play_load
do_load
else
Sound.play_buzzer
return
end
end
$game_temp.last_file_index = @index
end
#--------------------------------------------------------------------------
# * Move cursor down
# wrap : Wraparound allowed
#--------------------------------------------------------------------------
def cursor_down(wrap)
if @index < @file_max - 1 or wrap
@index = (@index + 1) % @file_max
for i in 0...@file_max
window = @savefile_windows
if @index == 0
@top_row = 0
window.y = @help_window.height + i % @file_max * window.height
elsif @index - @top_row > @page_file_max - 1
window.y -= window.height
end
window.visible = (window.y >= @help_window.height and
window.y < @help_window.height + @page_file_max * window.height)
end
if @index - @top_row > @page_file_max - 1
@top_row += 1
end
end
end
#--------------------------------------------------------------------------
# * Move cursor up
# wrap : Wraparound allowed
#--------------------------------------------------------------------------
def cursor_up(wrap)
if @index > 0 or wrap
@index = (@index - 1 + @file_max) % @file_max
for i in 0...@file_max
window = @savefile_windows
if @index == @file_max - 1
@top_row = @file_max - @page_file_max
window.y = @help_window.height + i % @file_max * window.height
window.y -= (@file_max - @page_file_max) * window.height
elsif @index - @top_row < 0
window.y += window.height
end
window.visible = (window.y >= @help_window.height and
window.y < @help_window.height + @page_file_max * window.height)
end
if @index - @top_row < 0
@top_row -= 1
end
end
end
#--------------------------------------------------------------------------
# * Create Filename
# file_index : save file index (0-3)
#--------------------------------------------------------------------------
def make_filename(file_index)
return FATE::SaveFolder+(file_index + 1).to_s+FATE::SaveFileExt
end
#--------------------------------------------------------------------------
# * Select File With Newest Timestamp
#--------------------------------------------------------------------------
def latest_file_index
index = 0
latest_time = Time.at(0)
for i in 0...@savefile_windows.size
if @savefile_windows.time_stamp > latest_time
latest_time = @savefile_windows.time_stamp
index = i
end
end
return index
end
#--------------------------------------------------------------------------
# * Execute Save
#--------------------------------------------------------------------------
def do_save
file = File.open(@savefile_windows[@index].filename, "wb")
write_save_data(file)
file.close
return_scene
end
#--------------------------------------------------------------------------
# * Execute Load
#--------------------------------------------------------------------------
def do_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
#--------------------------------------------------------------------------
# * Write Save Data
# file : write file object (opened)
#--------------------------------------------------------------------------
def write_save_data(file)
map_info = load_data("Data/MapInfos.rvdata")
map_info = map_info[$game_map.map_id]
map_info = map_info.name
n = map_info.split('')
t = ""
for i in 0...n.size
break if n == "#"
t += n
end
map_info = t
characters = []
face = []
for actor in $game_party.members
characters.push([actor.character_name, actor.character_index])
face.push([actor.face_name, actor.face_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(map_info, file)
Marshal.dump(characters, file)
Marshal.dump(face, 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)
end
#--------------------------------------------------------------------------
# * Read Save Data
# file : file object for reading (opened)
#--------------------------------------------------------------------------
def read_save_data(file)
map_info = Marshal.load(file)
characters = Marshal.load(file)
face = Marshal.load(file)
Graphics.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)
if $game_system.version_id != $data_system.version_id
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
$game_switches[280] = true
end
end
附上脚本 |
|