赞 | 0 |
VIP | 10 |
好人卡 | 3 |
积分 | 1 |
经验 | 3584 |
最后登录 | 2015-10-25 |
在线时间 | 134 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 134 小时
- 注册时间
- 2009-3-29
- 帖子
- 470
|
图片存档- #==============================================================================
- # vx新截图存档 by 沉影不器
- #------------------------------------------------------------------------------
- # 原版作者: 柳柳
- # 脚本插件: 轮回者
- # 注: 保存截图使用<<Bitmap to PNG>>脚本插件(删debug部分)
- #------------------------------------------------------------------------------
- # ▼ 相比rmxp正版截图存档,主要变动如下:
- # ① 省去了 screenshot.dll 文件
- # ② 无须人工新建存档文件夹,脚本将自建
- # ③ 方便地更改最大存档数,只需设置最大值
- #==============================================================================
- MAX_SAVE_ID = 12 # 最大存档数
- SAVE_DIR = "Saves/" # 改变的存档目录
- #==============================================================================
- # ■ Game_Temp
- #==============================================================================
- class Game_Temp
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_accessor :save_bitmap # 存档位图
- #--------------------------------------------------------------------------
- # ● 初始化对象
- #--------------------------------------------------------------------------
- alias ini initialize
- def initialize
- ini
- @save_bitmap = Bitmap.new(1, 1)
- end
- end
- #==============================================================================
- # ■ Window_SaveFile
- #==============================================================================
- class Window_SaveFile < Window_Base
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :filename # 文件名
- attr_reader :file_exist # 文件存在标志
- #--------------------------------------------------------------------------
- # ● 初始化对象
- # file_index : 存档文件索引 (0~3)
- # filename : 文件名
- #--------------------------------------------------------------------------
- def initialize(file_index, filename)
- super(160, 56, 384, 360)
- @file_index = file_index
- @filename = filename
- load_gamedata
- refresh(@file_index)
- end
- #--------------------------------------------------------------------------
- # ● 读取部分游戏数据
- #--------------------------------------------------------------------------
- def load_gamedata
- @file_exist = FileTest.exist?(SAVE_DIR + @filename)
- if @file_exist
- file = File.open(SAVE_DIR + @filename, "r")
- begin
- @characters = Marshal.load(file)
- @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)
- @total_sec = @frame_count / Graphics.frame_rate
- rescue
- @file_exist = false
- ensure
- file.close
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- # index : 索引
- #--------------------------------------------------------------------------
- def refresh(index)
- file_index = index
- self.contents.clear
- self.contents.font.color = normal_color
- if @file_exist
- self.contents.fill_rect(40+3, 24+3, 272,208, Color.new(0,0,64))
- if FileTest.exist?(SAVE_DIR + @filename.split(/\./)[0] + ".png")
- self.contents.blur
- draw_save_bitmap(40, 24)
- else
- self.contents.draw_text(0, 112, 384-32, 24, "找不到截图文件!", 1)
- end
- draw_party_characters(152, 288)
- draw_playtime(0, 288+8, contents.width - 40, 2)
- else
- self.contents.draw_text(0, 288, 384-32, 24, "无此存档!", 1)
- end
- end
- #--------------------------------------------------------------------------
- # ● 更改索引
- # index : 索引
- #--------------------------------------------------------------------------
- def file_index=(file_index)
- @file_index = file_index
- end
- #--------------------------------------------------------------------------
- # ● 描绘截图
- # x : 描画先 X 座標
- # y : 描画先 Y 座標
- #--------------------------------------------------------------------------
- def draw_party_characters(x, y)
- for i in [email protected]
- name = @characters[i][0]
- index = @characters[i][1]
- draw_character(name, index, x + i * 48, y)
- end
- end
- #--------------------------------------------------------------------------
- # ● パーティキャラの描画
- # x : 描画先 X 座標
- # y : 描画先 Y 座標
- #--------------------------------------------------------------------------
- def draw_save_bitmap(x, y)
- bitmap = Bitmap.new(SAVE_DIR + @filename.split(/\./)[0] + ".png")
- rect = Rect.new(0, 0, 0, 0)
- rect.width = bitmap.width
- rect.height = bitmap.height
- self.contents.blt(x, y, bitmap, rect)
- bitmap.dispose
- end
- #--------------------------------------------------------------------------
- # ● 描绘游戏时间
- # x : 描绘目标 X 坐标
- # y : 描绘目标 Y 坐标
- # width : 宽
- # align : 配置
- #--------------------------------------------------------------------------
- def draw_playtime(x, y, width, align)
- 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(x, y, width, WLH, time_string, 2)
- end
- end
- #==============================================================================
- # ■ Scene_Base
- #==============================================================================
- class Scene_Base
- #--------------------------------------------------------------------------
- # ● 生成存档位图快照
- #--------------------------------------------------------------------------
- def snapshot_for_save
- d_rect = Rect.new(0, 0, 272, 208)
- s_rect = Rect.new(0, 0, 544, 416)
- save_bitmap = Graphics.snap_to_bitmap
- $game_temp.save_bitmap.dispose
- $game_temp.save_bitmap = Bitmap.new(272, 208)
- $game_temp.save_bitmap.stretch_blt(d_rect, save_bitmap, s_rect)
- end
- end
- #==============================================================================
- # ■ Scene_Map
- #==============================================================================
- class Scene_Map < Scene_Base
- #--------------------------------------------------------------------------
- # ● 结束处理
- #--------------------------------------------------------------------------
- alias save_terminate terminate
- def terminate
- snapshot_for_save
- save_terminate
- 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_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
- create_menu_background
- @help_window = Window_Help.new
- 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
- 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 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(160, file_names)
- @command_window.height = 360
- @command_window.y = 56
- 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 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
复制代码 删除存档的脚本- #==============================================================================
- # ■ 删除存档v1.1(载图存档版) by 一箭烂
- #------------------------------------------------------------------------------
- # 按下delete就会弹出选择窗, 然后选择删除。
- #
- # - *1.1.0* (2011-04-01) By 一箭烂(YiJL)
- # *会弹出选择窗选择是否删除
- #
- # - *1.0.0* (2011-04-27) By 一箭烂(YiJL)
- # *初版
- #==============================================================================
- class Scene_File
- Key = Win32API.new("user32","GetAsyncKeyState","i","i")
- #--------------------------------------------------------------------------
- # ● 开始
- #--------------------------------------------------------------------------
- alias del_start start
- def start
- del_start
- @del_window = Window_DelFile.new
- @del_window.z = 500
- end
- #--------------------------------------------------------------------------
- # ● 更新幀
- #--------------------------------------------------------------------------
- alias del_update update
- def update
- del_update
- @del_window.update
- end
- #--------------------------------------------------------------------------
- # ● 更新选择
- #--------------------------------------------------------------------------
- def update_savefile_selection
- if Input.trigger?(Input::C)
- if @del_window.visible
- case @del_window.index
- when 0
- do_delete
- @del_window.visible = false
- when 1
- @del_window.visible = false
- end
- else
- determine_savefile
- end
- elsif Input.trigger?(Input::B)
- if @del_window.visible
- @del_window.visible = false
- else
- Sound.play_cancel
- return_scene
- end
- elsif Key.call(0x2E) & 1 != 0
- @del_window.visible = true
- end
- if @refresh_index != @command_window.index and @del_window.visible == false
- @refresh_index = @command_window.index
- @savefile_window.dispose
- create_savefile_window
- end
- @command_window.active = !@del_window.visible
- end
- #--------------------------------------------------------------------------
- # ● 删除存档
- #--------------------------------------------------------------------------
- def do_delete
- if FileTest.exist?(SAVE_DIR + make_filename(@command_window.index))
- File.delete(SAVE_DIR + make_filename(@command_window.index))
- @refresh_index = @command_window.index
- @savefile_window.dispose
- create_savefile_window
- else
- Sound.play_buzzer
- end
- end
- #--------------------------------------------------------------------------
- # ● 退出场景
- #--------------------------------------------------------------------------
- alias del_terminate terminate
- def terminate
- del_terminate
- @del_window.dispose
- end
- end
- #==============================================================================
- # ■ Window_DelFile
- #==============================================================================
- class Window_DelFile < Window_Selectable
- #--------------------------------------------------------------------------
- # ● 对象初始化
- #--------------------------------------------------------------------------
- def initialize
- super((544-250)/2, (416-100)/2, 250, 90)
- self.contents.draw_text(0, 0, 250-32, 24, "是否删除存档?", 1)
- self.contents.draw_text(0, 32, 93, 24, "是", 1)
- self.contents.draw_text(125, 32, 93, 24, "否", 1)
- @item_max = 2
- @column_max = 2
- @index = 1
- self.visible = false
- end
- #--------------------------------------------------------------------------
- # ● 帧更新
- #--------------------------------------------------------------------------
- def update
- super
- if self.visible
- if cursor_movable?
- 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
- end
- end
- update_cursor
- call_update_help
- end
- end
- #--------------------------------------------------------------------------
- # ● 选择矩形
- #--------------------------------------------------------------------------
- def item_rect(index)
- rect = Rect.new(0, 0, 0, 0)
- rect.width = (contents.width + @spacing) / @column_max - @spacing
- rect.height = WLH
- rect.x = index % @column_max * (rect.width + @spacing)
- rect.y = index / @column_max * WLH + 32
- return rect
- end
- end
复制代码 |
|