- 注册时间
- 2004-10-15
- 最后登录
- 2005-11-5
④见习
- 积分
- 320
|

楼主 |
发表于 2004-11-17 11:49:06
|
显示全部楼层
Window_SaveFile
#==============================================================================
# ■ Window_SaveFile
#------------------------------------------------------------------------------
# 显示存档以及读档画面、保存文件的窗口。
#==============================================================================
class Window_SaveFile < Window_Base
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :filename # 文件名
attr_reader :selected # 选择状态
#--------------------------------------------------------------------------
# ● 初始化对像
# file_index : 存档文件的索引 (0~3)
# filename : 文件名
#--------------------------------------------------------------------------
def initialize(file_index,head_index,filename)
if head_index==nil
head_index=0
end
super(0, 64 + (file_index-head_index)%4 * 104, 640, 104)
self.contents = Bitmap.new(width - 32, height - 32)
@file_index = file_index
@filename = \"Save#{@file_index + 1}.rxdata\"
@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)
@game_system = Marshal.load(file)
@game_switches = Marshal.load(file)
@game_variables = Marshal.load(file)
@total_sec = @frame_count / Graphics.frame_rate
file.close
end
refresh
@selected = false
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# 描绘文件编号
self.contents.font.color = normal_color
name = \"文件 #{@file_index + 1}\"
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(@characters[0], @characters[1])
cw = bitmap.rect.width / 4
ch = bitmap.rect.height / 4
src_rect = Rect.new(0, 0, cw, ch)
x = 300 - @characters.size * 32 + i * 64 - 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, 8, 600, 32, time_string, 2)
# 描绘时间标记
self.contents.font.color = normal_color
time_string = @time_stamp.strftime(\"%Y/%m/%d %H:%M\")
self.contents.draw_text(4, 40, 600, 32, time_string, 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_File
#==============================================================================
# ■ Scene_File
#------------------------------------------------------------------------------
# 存档画面及读档画面的超级类。
#==============================================================================
class Scene_File
def initialize(help_text)
@help_text = help_text
end
def main
@help_window = Window_Help.new
@help_window.set_text(@help_text)
@hindex=0
@file_index = $game_temp.last_file_index
if @file_index>=4
@hindex=@file_index-3
end
@savefile_windows = []
for i in 0..3
@savefile_windows.push(Window_SaveFile.new(@hindex+i,@hindex,make_filename(i)))
end
@savefile_windows[@file_index-@hindex].selected = true
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
end
#--------------------------------------------------------------------------
# ● 更新
#--------------------------------------------------------------------------
def update
@help_window.update
for i in @savefile_windows
i.update
end
#确定
if Input.trigger?(Input::C)
on_decision(make_filename(@file_index))
$game_temp.last_file_index = @file_index
return
end
#取消
if Input.trigger?(Input::B)
on_cancel
return
end
if Input.repeat?(Input: OWN)
if @file_index-@hindex< 3
$game_system.se_play($data_system.cursor_se)
@savefile_windows[@file_index-@hindex].selected = false
@file_index += 1
@savefile_windows[@file_index-@hindex].selected = true
return
end
#下面为自行添加的
if @file_index==@hindex+3 and @file_index<19
$game_system.se_play($data_system.cursor_se)
@hindex+=1
@file_index+=1
for i in 0..3
@savefile_windows.dispose
end
@savefile_windows = []
for i in 0..3
@savefile_windows.push(Window_SaveFile.new(i+@hindex,@hindex,make_filename(i+@hindex)))
end
@savefile_windows[@file_index-@hindex].selected = true
return
end
#第一段自行添加的结束了
end
if Input.repeat?(Input::UP)
if @file_index > @hindex
$game_system.se_play($data_system.cursor_se)
@savefile_windows[@file_index-@hindex].selected = false
@file_index-=1
@savefile_windows[@file_index-@hindex].selected = true
return
end
#下面为自行添加的
if @file_index==@hindex and @file_index>0
$game_system.se_play($data_system.cursor_se)
@file_index-=1
@hindex-=1
for i in 0..3
@savefile_windows.dispose
end
#@savefile_windows = []
for i in 0..3
@savefile_windows=Window_SaveFile.new(i+@hindex,@hindex,make_filename(i+@hindex))
end
@savefile_windows[@file_index-@hindex].selected = true
end
#第二次自行添加的结束了
end
end
#--------------------------------------------------------------------------
# ● 生成文件名
# file_index : 文件名的索引 (0~19)
#--------------------------------------------------------------------------
def make_filename(file_index)
return \"Save#{file_index + 1}.rxdata\"
end
end
Scene_Load
#==============================================================================
# ■ 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..98
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(\"要载入哪个文件?\")
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_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)
# 魔法编号与保存时有差异的情况下
# (加入编辑器的编辑过的数据)
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_Title
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
# 处理标题画面的类。
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# ● 住处理
#--------------------------------------------------------------------------
def main
# 战斗测试的情况下
if $BTEST
battle_test
return
end
# 载入数据库
$data_actors = load_data(\"Data/Actors.rxdata\")
$data_classes = load_data(\"Data/Classes.rxdata\")
$data_skills = load_data(\"Data/Skills.rxdata\")
$data_items = load_data(\"Data/Items.rxdata\")
$data_weapons = load_data(\"Data/Weapons.rxdata\")
$data_armors = load_data(\"Data/Armors.rxdata\")
$data_enemies = load_data(\"Data/Enemies.rxdata\")
$data_troops = load_data(\"Data/Troops.rxdata\")
$data_states = load_data(\"Data/States.rxdata\")
$data_animations = load_data(\"Data/Animations.rxdata\")
$data_tilesets = load_data(\"Data/Tilesets.rxdata\")
$data_common_events = load_data(\"Data/CommonEvents.rxdata\")
$data_system = load_data(\"Data/System.rxdata\")
# 生成系统对像
$game_system = Game_System.new
# 生成标题图形
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.title($data_system.title_name)
# 生成命令窗口
s1 = \"新游戏\"
s2 = \"继续\"
s3 = \"退出\"
@command_window = Window_Command.new(192, [s1, s2, s3])
@command_window.back_opacity = 160
@command_window.x = 320 - @command_window.width / 2
@command_window.y = 288
# 判定继续的有效性
# 存档文件一个也不存在的时候也调查
# 有効为 @continue_enabled 为 true、無効为 false
@continue_enabled = false
for i in 0..98
if FileTest.exist?(\"Save#{i+1}.rxdata\")
@continue_enabled = true
end
end
# 继续为有效的情况下、光标停止在继续上
# 无效的情况下、继续的文字显示为灰色
if @continue_enabled
@command_window.index = 1
else
@command_window.disable_item(1)
end
# 演奏标题 BGM
$game_system.bgm_play($data_system.title_bgm)
# 停止演奏 ME、BGS
Audio.me_stop
Audio.bgs_stop
# 执行过渡
Graphics.transition
# 主循环
loop do
# 刷新游戏画面
Graphics.update
# 刷新输入信息
Input.update
# 刷新画面
update
# 如果画面被切换就中断循环
if $scene != self
break
end
end
# 装备过渡
Graphics.freeze
# 释放命令窗口
@command_window.dispose
# 释放标题图形
@sprite.bitmap.dispose
@sprite.dispose
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 刷新命令窗口
@command_window.update
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 命令窗口的光标位置的分支
case @command_window.index
when 0 # 新游戏
command_new_game
when 1 # 继续
command_continue
when 2 # 退出
command_shutdown
end
end
end
end
|
|