#==============================================================================
# ■ Scene_Map
#==============================================================================
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
# ● 结束处理
#--------------------------------------------------------------------------
def terminate
super
snapshot_for_save # 截图存档
if $scene.is_a?(Scene_Battle) # 正在切换战斗画面的情况下
@spriteset.dispose_characters # 为了生成背景隐藏角色
end
snapshot_for_background # 背景图快照
snapshot_for_menu # 菜单背景图快照
@spriteset.dispose
@message_window.dispose
if $scene.is_a?(Scene_Battle) # 正在切换战斗画面的情况下
perform_battle_transition # 执行战斗前变换
end
end
#--------------------------------------------------------------------------
# ● 菜单背景快照
#--------------------------------------------------------------------------
def snapshot_for_menu
$game_temp.menu_bitmap.dispose
$game_temp.menu_bitmap = Graphics.snap_to_bitmap
end
#--------------------------------------------------------------------------
# ● 切换至菜单画面
#--------------------------------------------------------------------------
def call_menu
if $game_temp.menu_beep
Sound.play_decision
$game_temp.menu_beep = false
end
$game_temp.next_scene = nil
$scene = Scene_Menu.new(0, true)
end
end
#==============================================================================
# ■ Scene_Title
#==============================================================================
class Scene_Title < Scene_Base
#--------------------------------------------------------------------------
# ● 判断继续是否有效
#--------------------------------------------------------------------------
def check_continue
@continue_enabled = (Dir.glob(SAVE_DIR + 'Save*.rvdata').size > 0)
end
end
#==============================================================================
# ■ Scene_Menu
#==============================================================================
class Scene_Menu < Scene_Base
#--------------------------------------------------------------------------
# ● 初始化对象
# menu_index : 指令光标初期位置
# show : 是否动态出现菜单
#--------------------------------------------------------------------------
def initialize(menu_index = 0, show = false)
@menu_index = menu_index
@status_index = 0 @show = show
end
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_menu_background
create_command_window
@gold_window = Window_Gold.new(384, 360)
@gold_window.opacity = 0
@gold_window.y = @show ? 416 : 360
@status_window = Window_MenuTarget.new(64, 144)
@status_window.visible = false
@status_window.openness = 0
@help_window = Window_Help.new
@help_window.y = @show ? -56 : 0
@command_window.help_window = @help_window
end
#--------------------------------------------------------------------------
# ● 结束处理
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@command_window.dispose
@gold_window.dispose
@status_window.dispose
@help_window.dispose
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
update_menu_background
@command_window.update
@gold_window.update
@status_window.update
@help_window.update
loop do
break if @help_window.y >= 0
@help_window.y += 8
@gold_window.y -= 8
@command_window.y -= 8
Graphics.update
end
@help_window.y = 0
@command_window.y = 360
if @command_window.active
update_command_selection
if @menu_index != @command_window.index
@menu_index = @command_window.index
@command_window.refresh
end
elsif @status_window.active
update_actor_selection
if @status_index != @status_window.index
@status_index = @status_window.index
@status_window.refresh
end
end
end
#--------------------------------------------------------------------------
# ● 打开指令窗口
#--------------------------------------------------------------------------
def show_status_window
@status_window.open
begin
@status_window.update
Graphics.update
end until @status_window.openness == 255
end
#--------------------------------------------------------------------------
# ● 关闭指令窗口
#--------------------------------------------------------------------------
def hide_status_window
@status_window.close
begin
@status_window.update
Graphics.update
end until @status_window.openness == 0
end
#--------------------------------------------------------------------------
# ● 菜单背景快照
#--------------------------------------------------------------------------
def snapshot_for_sub_menu
$game_temp.sub_menu_bitmap.dispose
$game_temp.sub_menu_bitmap = Graphics.snap_to_bitmap
end
#--------------------------------------------------------------------------
# ● 生成菜单画面背景
#--------------------------------------------------------------------------
def create_menu_background
@menuback_sprite = Sprite.new
@menuback_sprite.bitmap = $game_temp.menu_bitmap
update_menu_background
end
#--------------------------------------------------------------------------
# ● 生成指令窗口
#--------------------------------------------------------------------------
def create_command_window
s1 = Vocab::item
s2 = Vocab::skill
s3 = Vocab::equip
s4 = Vocab::status
s5 = Vocab::save
s6 = Vocab::game_end
@command_window = Window_Menu_Command.new(640, [s1, s2, s3, s4, s5, s6])
@command_window.y = @show ? 510 : 360
@command_window.index = @menu_index
@command_window.refresh
if $game_party.members.size == 0 # 同伴人数为 0 的情况下
@command_window.draw_item(0, false) # 物品无效化
@command_window.draw_item(1, false) # 特技无效化
@command_window.draw_item(2, false) # 装备无效化
@command_window.draw_item(3, false) # 状态无效化
end
if $game_system.save_disabled # 禁止存档的情况下
@command_window.draw_item(4, false) # 存档无效化
end
end
#--------------------------------------------------------------------------
# ● 更新指令选择
#--------------------------------------------------------------------------
def update_command_selection
if Input.trigger?(Input::B)
loop do
break if @help_window.y <= -56
@help_window.y -= 8
@gold_window.y += 8
@command_window.y += 8
Graphics.update
end
Sound.play_cancel
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
if $game_party.members.size == 0 and @command_window.index < 4
Sound.play_buzzer
return
elsif $game_system.save_disabled and @command_window.index == 4
Sound.play_buzzer
return
end
Sound.play_decision
case @command_window.index
when 0 # 物品
@help_window.set_text("")
snapshot_for_sub_menu
$scene = Scene_Item.new
when 1,2,3 # 特技、装备、状态
@help_window.set_text("")
snapshot_for_sub_menu
start_actor_selection
when 4 # 存档
@help_window.set_text("")
snapshot_for_sub_menu
$scene = Scene_File.new(true, false, false)
when 5 # 游戏结束
@help_window.set_text("")
snapshot_for_sub_menu
$scene = Scene_End.new
end
end
end
#--------------------------------------------------------------------------
# ● アクター選択の開始
#--------------------------------------------------------------------------
def start_actor_selection
@command_window.active = false
@status_window.active = true
@status_window.visible = true
show_status_window
if $game_party.last_actor_index < @status_window.item_max
@status_window.index = $game_party.last_actor_index
else
@status_window.index = 0
end
end
#--------------------------------------------------------------------------
# ● アクター選択の終了
#--------------------------------------------------------------------------
def end_actor_selection
@command_window.active = true
@status_window.active = false
hide_status_window
@status_window.visible = false
@status_window.index = -1
end
#--------------------------------------------------------------------------
# ● アクター選択の更新
#--------------------------------------------------------------------------
def update_actor_selection
if Input.trigger?(Input::B)
Sound.play_cancel
end_actor_selection
elsif Input.trigger?(Input::C)
$game_party.last_actor_index = @status_window.index
Sound.play_decision
case @command_window.index
when 1 # スキル
$scene = Scene_Menu_Skill.new(@status_window.index)
when 2 # 装備
$scene = Scene_Equip.new(@status_window.index)
when 3 # ステータス
$scene = Scene_Status.new(@status_window.index)
end
end
end
end
#==============================================================================
# ■ Scene_Item
#==============================================================================
class Scene_Item < Scene_Base
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_sub_menu_background
@viewport = Viewport.new(0, 0, 640, 480)
@help_window = Window_Help.new
@help_window.opacity = 0
@help_window.viewport = @viewport
@item_window = Window_Item.new(64, 112, 510, 176)
@item_window.viewport = @viewport
@item_window.help_window = @help_window
@item_window.openness = 0
@item_window.active = false
@target_window = Window_MenuTarget.new(64, 232)
@actor_index = 0
hide_target_window
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
update_menu_background
@help_window.update
@item_window.update
@target_window.update
if @item_window.active
update_item_selection
elsif @target_window.active
if @actor_index != @target_window.index
@actor_index = @target_window.index
@target_window.refresh
end
update_target_selection
end
end
#--------------------------------------------------------------------------
# ● 开始后处理
#--------------------------------------------------------------------------
def post_start
super
open_item_window
end
#--------------------------------------------------------------------------
# ● 结束前处理
#--------------------------------------------------------------------------
def pre_terminate
super
close_item_window
end
#--------------------------------------------------------------------------
# ● 打开指令窗口
#--------------------------------------------------------------------------
def open_item_window
@item_window.open
begin
@item_window.update
Graphics.update
end until @item_window.openness == 255
end
#--------------------------------------------------------------------------
# ● 关闭指令窗口
#--------------------------------------------------------------------------
def close_item_window
@item_window.close
begin
@item_window.update
Graphics.update
end until @item_window.openness == 0
end
#--------------------------------------------------------------------------
# ● 确定物品
#--------------------------------------------------------------------------
def determine_item
if @item.for_friend?
show_target_window
if @item.for_all?
@target_window.index = 99
else
if $game_party.last_target_index < @target_window.item_max
@target_window.index = $game_party.last_target_index
else
@target_window.index = 0
end
end
else
use_item_nontarget
end
end
#--------------------------------------------------------------------------
# ● 显示目标窗口
#--------------------------------------------------------------------------
def show_target_window
loop do
@item_window.y -= 8
Graphics.update
break if @item_window.y <= 56
end
@item_window.active = false
@target_window.visible = true
@target_window.active = true
end
#--------------------------------------------------------------------------
# ● 不显示目标窗口
#--------------------------------------------------------------------------
def hide_target_window
@target_window.visible = false
loop do
@item_window.y += 8
Graphics.update
break if @item_window.y >= 112
end
@item_window.active = true
@target_window.active = false
@viewport.rect.set(0, 0, 640, 480)
@viewport.ox = 0
end
end
#==============================================================================
# ■ Scene_Menu_Skill
#==============================================================================
class Scene_Menu_Skill < Scene_Base
#--------------------------------------------------------------------------
# ● 初始化对象
# actor_index : 角色索引
#--------------------------------------------------------------------------
def initialize(actor_index = 0, equip_index = 0)
@actor_index = actor_index
end
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_sub_menu_background
@actor = $game_party.members[@actor_index]
@viewport = Viewport.new(0, 0, 640, 480)
@help_window = Window_Help.new
@help_window.opacity = 0
@help_window.viewport = @viewport
@skill_window = Window_Skill.new(64, 112, 510, 176, @actor)
@skill_window.viewport = @viewport
@skill_window.help_window = @help_window
@skill_window.openness = 0
@skill_window.open
@target_window = Window_MenuTarget.new(64, 232)
hide_target_window
end
#--------------------------------------------------------------------------
# ● 结束处理
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@help_window.dispose
@skill_window.dispose
@target_window.dispose
end
#--------------------------------------------------------------------------
# ● 开始后处理
#--------------------------------------------------------------------------
def post_start
super
open_skill_window
end
#--------------------------------------------------------------------------
# ● 结束前处理
#--------------------------------------------------------------------------
def pre_terminate
super
close_skill_window
end
#--------------------------------------------------------------------------
# ● 打开指令窗口
#--------------------------------------------------------------------------
def open_skill_window
@skill_window.open
begin
@skill_window.update
Graphics.update
end until @skill_window.openness == 255
end
#--------------------------------------------------------------------------
# ● 关闭指令窗口
#--------------------------------------------------------------------------
def close_skill_window
@skill_window.close
begin
@skill_window.update
Graphics.update
end until @skill_window.openness == 0
end
#--------------------------------------------------------------------------
# ● 还原至原来的画面
#--------------------------------------------------------------------------
def return_scene
$scene = Scene_Menu.new(1)
end
#--------------------------------------------------------------------------
# ● 切换至下一名角色的画面
#--------------------------------------------------------------------------
def next_actor
@actor_index += 1
@actor_index %= $game_party.members.size
$scene = Scene_Skill.new(@actor_index)
end
#--------------------------------------------------------------------------
# ● 切换至上一名角色的画面
#--------------------------------------------------------------------------
def prev_actor
@actor_index += $game_party.members.size - 1
@actor_index %= $game_party.members.size
$scene = Scene_Skill.new(@actor_index)
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
update_menu_background
@help_window.update
@skill_window.update
@target_window.update
if @skill_window.active
update_skill_selection
elsif @target_window.active
if @actor_index != @target_window.index
@actor_index = @target_window.index
@target_window.refresh
end
update_target_selection
end
end
#--------------------------------------------------------------------------
# ● 更新选择特技
#--------------------------------------------------------------------------
def update_skill_selection
if Input.trigger?(Input::B)
Sound.play_cancel
return_scene
elsif Input.trigger?(Input::R)
Sound.play_cursor
next_actor
elsif Input.trigger?(Input::L)
Sound.play_cursor
prev_actor
elsif Input.trigger?(Input::C)
@skill = @skill_window.skill
if @skill != nil
@actor.last_skill_id = @skill.id
end
if @actor.skill_can_use?(@skill)
Sound.play_decision
determine_skill
else
Sound.play_buzzer
end
end
end
#--------------------------------------------------------------------------
# ● 确定特技
#--------------------------------------------------------------------------
def determine_skill
if @skill.for_friend?
show_target_window
if @skill.for_all?
@target_window.index = 99
elsif @skill.for_user?
@target_window.index = @actor_index + 100
else
if $game_party.last_target_index < @target_window.item_max
@target_window.index = $game_party.last_target_index
else
@target_window.index = 0
end
end
else
use_skill_nontarget
end
end
#--------------------------------------------------------------------------
# ● 更新选择目标
#--------------------------------------------------------------------------
def update_target_selection
if Input.trigger?(Input::B)
Sound.play_cancel
hide_target_window
elsif Input.trigger?(Input::C)
if not @actor.skill_can_use?(@skill)
Sound.play_buzzer
else
determine_target
end
end
end
#--------------------------------------------------------------------------
# ● 确定目标
# 无效的情况下 (在不能战斗的情况下使用恢复剂) 播放 buzzer 的 SE。
#--------------------------------------------------------------------------
def determine_target
used = false
if @skill.for_all?
for target in $game_party.members
target.skill_effect(@actor, @skill)
used = true unless target.skipped
end
elsif @skill.for_user?
target = $game_party.members[@target_window.index - 100]
target.skill_effect(@actor, @skill)
used = true unless target.skipped
else
$game_party.last_target_index = @target_window.index
target = $game_party.members[@target_window.index]
target.skill_effect(@actor, @skill)
used = true unless target.skipped
end
if used
use_skill_nontarget
else
Sound.play_buzzer
end
end
#--------------------------------------------------------------------------
# ● 显示目标窗口
#--------------------------------------------------------------------------
def show_target_window
loop do
@skill_window.y -= 8
Graphics.update
break if @skill_window.y <= 56
end
@skill_window.active = false
@target_window.visible = true
@target_window.active = true
end
#--------------------------------------------------------------------------
# ● 不显示目标窗口
#--------------------------------------------------------------------------
def hide_target_window
@target_window.visible = false
loop do
@skill_window.y += 8
Graphics.update
break if @skill_window.y >= 112
end
@skill_window.active = true
@target_window.active = false
@viewport.rect.set(0, 0, 640, 480)
@viewport.ox = 0
end
#--------------------------------------------------------------------------
# ● 使用特技 (也适用于我方对象以外的效果)
#--------------------------------------------------------------------------
def use_skill_nontarget
Sound.play_use_skill
@actor.mp -= @actor.calc_mp_cost(@skill)
@skill_window.refresh
@target_window.refresh
if $game_party.all_dead?
$scene = Scene_Gameover.new
elsif @skill.common_event_id > 0
$game_temp.common_event_id = @skill.common_event_id
$scene = Scene_Map.new
end
end
end
#==============================================================================
# ■ Scene_Equip
#==============================================================================
class Scene_Equip < Scene_Base
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_sub_menu_background
@actor = $game_party.members[@actor_index]
@help_window = Window_Help.new
@help_window.opacity = 0
create_item_windows
@equip_window = Window_Equip.new(64, 56, @actor)
@equip_window.help_window = @help_window
@equip_window.index = @equip_index
@equip_window.openness = 0
@status_window = Window_EquipStatus.new(64, 208, @actor)
@status_window.openness = 0
end
#--------------------------------------------------------------------------
# ● 生成物品窗口
#--------------------------------------------------------------------------
def create_item_windows
@item_windows = []
for i in 0...EQUIP_TYPE_MAX
@item_windows = Window_EquipItem.new(272, 208, 208, 152, @actor, i)
@item_windows.help_window = @help_window
@item_windows.visible = (@equip_index == i)
@item_windows.y = 208
@item_windows.height = 152
@item_windows.active = false
@item_windows.index = -1
end
@item_windows[@equip_index].openness = 0
end
#--------------------------------------------------------------------------
# ● 开始后处理
#--------------------------------------------------------------------------
def post_start
super
open_equip_window
end
#--------------------------------------------------------------------------
# ● 结束前处理
#--------------------------------------------------------------------------
def pre_terminate
super
close_equip_window
end
#--------------------------------------------------------------------------
# ● 打开指令窗口
#--------------------------------------------------------------------------
def open_equip_window
@item_windows[@equip_window.index].open
@status_window.open
@equip_window.open
begin
@item_windows[@equip_window.index].update
@status_window.update
@equip_window.update
Graphics.update
end until @equip_window.openness == 255
end
#--------------------------------------------------------------------------
# ● 关闭指令窗口
#--------------------------------------------------------------------------
def close_equip_window
@item_windows[@equip_window.index].close
@status_window.close
@equip_window.close
begin
@item_windows[@equip_window.index].update
@status_window.update
@equip_window.update
Graphics.update
end until @equip_window.openness == 0
end
end
#==============================================================================
# ■ Scene_Status
#==============================================================================
class Scene_Status < Scene_Base
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_sub_menu_background
@actor = $game_party.members[@actor_index]
@status_window = Window_Status.new(@actor)
@status_window.openness = 0
end
#--------------------------------------------------------------------------
# ● 开始后处理
#--------------------------------------------------------------------------
def post_start
super
open_status_window
end
#--------------------------------------------------------------------------
# ● 结束前处理
#--------------------------------------------------------------------------
def pre_terminate
super
close_status_window
end
#--------------------------------------------------------------------------
# ● 打开指令窗口
#--------------------------------------------------------------------------
def open_status_window
@status_window.open
begin
@status_window.update
Graphics.update
end until @status_window.openness == 255
end
#--------------------------------------------------------------------------
# ● 关闭指令窗口
#--------------------------------------------------------------------------
def close_status_window
@status_window.close
begin
@status_window.update
Graphics.update
end until @status_window.openness == 0
end
end
#==============================================================================
# ■ Scene_File
#------------------------------------------------------------------------------
# 处理文件的类。
#==============================================================================
class Scene_File < Scene_Base
#--------------------------------------------------------------------------
# ● 初始化对象
# saving : 存档标志 (false 为载入画面)
# from_title : 调用标题画面的 "继续" 标志
# from_event : 事件的 "调用存档画面" 的调用标志
#--------------------------------------------------------------------------
def initialize(saving, from_title, from_event)
@saving = saving
@from_title = from_title
@from_event = from_event
end
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
@help_window = Window_Help.new
unless $game_temp.sub_menu_bitmap.width == 1
@help_window.opacity = 0
create_sub_menu_background
else
create_title_graphic
end
create_command_window
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
@refresh_index = @command_window.index = @index
@item_max = MAX_SAVE_ID
create_savefile_window
@savefile_window.openness = 0
end
#--------------------------------------------------------------------------
# ● 结束处理
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@help_window.dispose
dispose_item_windows
end
#--------------------------------------------------------------------------
# ● 还原至原先的画面
#--------------------------------------------------------------------------
def return_scene
if @from_title
$scene = Scene_Title.new
elsif @from_event
$scene = Scene_Map.new
else
$scene = Scene_Menu.new(4)
end
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
update_menu_background
@help_window.update
update_savefile_windows
update_savefile_selection
end
#--------------------------------------------------------------------------
# ● 开始后处理
#--------------------------------------------------------------------------
def post_start
super
open_savefile_window
end
#--------------------------------------------------------------------------
# ● 结束前处理
#--------------------------------------------------------------------------
def pre_terminate
super
close_savefile_window
end
#--------------------------------------------------------------------------
# ● 生成标题画面背景
#--------------------------------------------------------------------------
def create_title_graphic
@menuback_sprite = Sprite.new
@menuback_sprite.bitmap = Cache.system("Title")
end
#--------------------------------------------------------------------------
# ● 生成存档文件列表窗口
#--------------------------------------------------------------------------
def create_command_window
file_names = []
for i in 0...MAX_SAVE_ID
id = sprintf("%02d", i+1)
file_names.push(Vocab::File + "\s" + id)
end
@command_window = Window_Command.new(112, file_names)
@command_window.height = 298
@command_window.x = 64
@command_window.y = 59
@command_window.openness = 0
end
#--------------------------------------------------------------------------
# ● 生成存档文件窗口
#--------------------------------------------------------------------------
def create_savefile_window
@savefile_window = Window_SaveFile.new(@command_window.index, make_filename(@command_window.index))
end
#--------------------------------------------------------------------------
# ● 释放存档文件
#--------------------------------------------------------------------------
def dispose_item_windows
@command_window.dispose
@savefile_window.dispose
end
#--------------------------------------------------------------------------
# ● 打开指令窗口
#--------------------------------------------------------------------------
def open_savefile_window
@command_window.open
@savefile_window.open
begin
@command_window.update
@savefile_window.update
Graphics.update
end until @savefile_window.openness == 255
end
#--------------------------------------------------------------------------
# ● 关闭指令窗口
#--------------------------------------------------------------------------
def close_savefile_window
@command_window.close
@savefile_window.close
begin
@command_window.update
@savefile_window.update
Graphics.update
end until @savefile_window.openness == 0
end
#--------------------------------------------------------------------------
# ● 更新存档文件窗口
#--------------------------------------------------------------------------
def update_savefile_windows
@command_window.update
@savefile_window.update
end
#--------------------------------------------------------------------------
# ● 更新存档文件选择
#--------------------------------------------------------------------------
def update_savefile_selection
if Input.trigger?(Input::C)
determine_savefile
end
if Input.trigger?(Input::B)
Sound.play_cancel
return_scene
end
if @refresh_index != @command_window.index
@refresh_index = @command_window.index
@savefile_window.dispose
create_savefile_window
end
end
#--------------------------------------------------------------------------
# ● 确定存档文件
#--------------------------------------------------------------------------
def determine_savefile
if @saving
Sound.play_save
do_save
else
if @savefile_window.file_exist
Sound.play_load
do_load
else
Sound.play_buzzer
return
end
end
$game_temp.last_file_index = @index
end
#--------------------------------------------------------------------------
# ● 生成文件名
# file_index : 存档文件索引 (0~3)
#--------------------------------------------------------------------------
def make_filename(file_index)
return "Save#{file_index + 1}.rvdata"
end
#--------------------------------------------------------------------------
# ● 按时间戳选择最新的文件
#--------------------------------------------------------------------------
def latest_file_index
index = 0
latest_time = Time.at(0) # 时间戳
for i in 0...MAX_SAVE_ID
file_name = make_filename(i)
if FileTest.exist?(SAVE_DIR + file_name)
file = File.open(SAVE_DIR + file_name, "r")
if file.mtime > latest_time
latest_time = file.mtime
index = i
end
end
end
return index
end
#--------------------------------------------------------------------------
# ● 执行存档
#--------------------------------------------------------------------------
def do_save
file_name = make_filename(@command_window.index)
$game_temp.save_bitmap.make_png(file_name.split(/\./)[0], SAVE_DIR)
file = File.open(SAVE_DIR + file_name, "wb")
write_save_data(file)
file.close
return_scene
end
#--------------------------------------------------------------------------
# ● 执行载入
#--------------------------------------------------------------------------
def do_load
file_name = make_filename(@command_window.index)
file = File.open(SAVE_DIR + file_name, "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
end
#==============================================================================
# 本脚本出自www.66rpg.com,转载请注明。
#==============================================================================
# Bitmap to PNG By 轮回者
#==============================================================================
# 对Bitmap对象直接使用
# bitmap_obj.make_png(name[, path])
# name:保存文件名
# path:保存路径
# 感谢66、夏娜、金圭子的提醒和帮助!
#==============================================================================
module Zlib
class Png_File < GzipWriter
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def make_png(bitmap_Fx)
@bitmap_Fx = bitmap_Fx
self.write(make_header)
self.write(make_ihdr)
self.write(make_idat)
self.write(make_iend)
end
#--------------------------------------------------------------------------
# ● PNG文件头数据块
#--------------------------------------------------------------------------
def make_header
return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*")
end
#--------------------------------------------------------------------------
# ● PNG文件情报头数据块(IHDR)
#--------------------------------------------------------------------------
def make_ihdr
ih_size = [13].pack("N")
ih_sign = "IHDR"
ih_width = [@bitmap_Fx.width].pack("N")
ih_height = [@bitmap_Fx.height].pack("N")
ih_bit_depth = [8].pack("C")
ih_color_type = [6].pack("C")
ih_compression_method = [0].pack("C")
ih_filter_method = [0].pack("C")
ih_interlace_method = [0].pack("C")
string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
ih_compression_method + ih_filter_method + ih_interlace_method
ih_crc = [Zlib.crc32(string)].pack("N")
return ih_size + string + ih_crc
end
#--------------------------------------------------------------------------
# ● 生成图像数据(IDAT)
#--------------------------------------------------------------------------
def make_idat
header = "\x49\x44\x41\x54"
data = make_bitmap_data
data = Zlib::Deflate.deflate(data, 8)
crc = [Zlib.crc32(header + data)].pack("N")
size = [data.length].pack("N")
return size + header + data + crc
end
#--------------------------------------------------------------------------
# ● 从Bitmap对象中生成图像数据 mode
#--------------------------------------------------------------------------
def make_bitmap_data
gz = Zlib::GzipWriter.open('hoge.gz')
t_Fx = 0
w = @bitmap_Fx.width
h = @bitmap_Fx.height
data = []
for y in 0...h
data.push(0)
for x in 0...w
t_Fx += 1
if t_Fx % 10000 == 0
Graphics.update
end
if t_Fx % 100000 == 0
s = data.pack("C*")
gz.write(s)
data.clear
end
color = @bitmap_Fx.get_pixel(x, y)
red = color.red
green = color.green
blue = color.blue
alpha = color.alpha
data.push(red)
data.push(green)
data.push(blue)
data.push(alpha)
end
end
s = data.pack("C*")
gz.write(s)
gz.close
data.clear
gz = Zlib::GzipReader.open('hoge.gz')
data = gz.read
gz.close
File.delete('hoge.gz')
return data
end
#--------------------------------------------------------------------------
# ● PNG文件尾数据块(IEND)
#--------------------------------------------------------------------------
def make_iend
ie_size = [0].pack("N")
ie_sign = "IEND"
ie_crc = [Zlib.crc32(ie_sign)].pack("N")
return ie_size + ie_sign + ie_crc
end
end
end
#==============================================================================
# ■ Bitmap
#------------------------------------------------------------------------------
# 关联到Bitmap。
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# ● 关联
#--------------------------------------------------------------------------
def make_png(name="like", path="",mode=0)
make_dir(path) if path != ""
Zlib::Png_File.open("temp.gz") {|gz|
gz.make_png(self)
}
Zlib::GzipReader.open("temp.gz") {|gz|
$read = gz.read
}
f = File.open(path + name + ".png","wb")
f.write($read)
f.close
File.delete('temp.gz')
end
#--------------------------------------------------------------------------
# ● 生成保存路径
#--------------------------------------------------------------------------
def make_dir(path)
dir = path.split("/")
for i in 0...dir.size
unless dir == "."
add_dir = dir[0..i].join("/")
begin
Dir.mkdir(add_dir)
rescue
end
end
end
end
end[/pre]