设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2279|回复: 0
打印 上一主题 下一主题

[已经解决] 事件标题与截图存档的问题。

[复制链接]

Lv1.梦旅人

Mist

梦石
0
星屑
49
在线时间
80 小时
注册时间
2010-9-16
帖子
283
跳转到指定楼层
1
发表于 2010-9-29 11:08:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 嵐。 于 2010-9-29 12:53 编辑

使用的是沉影前辈的截图脚本。因为是使用事件做标题于是设置了条件分歧-脚本:$continue_enabled 来实现读档
但是在测试的时候发现没有反应。有尝试在Save*.rvdata前面添加save\。不过好像在vx里没有用处。请教下前辈们如何才能调出截图存档?
  1. #==============================================================================
  2. # vx新截图存档 by 沉影不器
  3. #------------------------------------------------------------------------------
  4. # ☆ 核心部分是内存位图的输入输出
  5. #    (快速存储Bitmap的Marshal 作者: 柳之一) 强大啊
  6. #------------------------------------------------------------------------------
  7. # ▼ 相比rmxp正版截图存档(作者: 柳柳),主要变动如下:
  8. #     ① 省去了 screenshot.dll 文件 (因快速存储Bitmap的Marshal的存在)
  9. #     ② 无须人工新建存档文件夹,脚本将自建
  10. #     ③ 方便地更改最大存档数,只需设置最大值
  11. #==============================================================================
  12. MAX_SAVE_ID = 10
  13. SAVE_DIR = "Saves/"                       
  14. #==============================================================================
  15. # (快速存储Bitmap的Marshal 作者: 柳之一) 强大啊
  16. #==============================================================================
  17. class Font
  18.   def marshal_dump
  19.   end
  20.   def marshal_load(obj)
  21.   end
  22. end

  23. class Bitmap
  24.   # 传送到内存的API函数
  25.   RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
  26.   RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')
  27.   def _dump(limit)
  28.     data = "rgba" * width * height
  29.     RtlMoveMemory_pi.call(data, address, data.length)
  30.     [width, height, Zlib::Deflate.deflate(data)].pack("LLa*") # 压缩
  31.   end
  32.   def self._load(str)
  33.     w, h, zdata = str.unpack("LLa*")
  34.     b = self.new(w, h)
  35.     RtlMoveMemory_ip.call(b.address, Zlib::Inflate.inflate(zdata), w * h * 4)
  36.     return b
  37.   end
  38. # [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头
  39.   def address
  40.     buffer, ad = "rgba", object_id * 2 + 16
  41.     RtlMoveMemory_pi.call(buffer, ad, 4)
  42.     ad = buffer.unpack("L")[0] + 8
  43.     RtlMoveMemory_pi.call(buffer, ad, 4)
  44.     ad = buffer.unpack("L")[0] + 16
  45.     RtlMoveMemory_pi.call(buffer, ad, 4)
  46.     return buffer.unpack("L")[0]
  47.   end
  48. end

  49. #==============================================================================
  50. # ■ Game_Temp
  51. #==============================================================================
  52. class Game_Temp
  53.   #--------------------------------------------------------------------------
  54.   # ● 定义实例变量
  55.   #--------------------------------------------------------------------------
  56.   attr_accessor :save_bitmap        # 存档位图
  57.   #--------------------------------------------------------------------------
  58.   # ● 初始化对象
  59.   #--------------------------------------------------------------------------
  60.   alias ini initialize
  61.   def initialize
  62.     ini
  63.     @save_bitmap = Bitmap.new(1, 1)
  64.   end
  65. end

  66. #==============================================================================
  67. # ■ Window_SaveFile
  68. #==============================================================================
  69. class Window_SaveFile < Window_Base
  70.   #--------------------------------------------------------------------------
  71.   # ● 定义实例变量
  72.   #--------------------------------------------------------------------------
  73.   attr_reader   :filename                 # 文件名
  74.   attr_reader   :file_exist               # 文件存在标志
  75.   #--------------------------------------------------------------------------
  76.   # ● 初始化对象
  77.   #     file_index : 存档文件索引 (0~3)
  78.   #     filename   : 文件名
  79.   #--------------------------------------------------------------------------
  80.   def initialize(file_index, filename)
  81.     super(160, 56, 384, 360)
  82.     @file_index = file_index
  83.     @filename = filename
  84.     make_dir(SAVE_DIR) if SAVE_DIR != nil
  85.     load_gamedata
  86.     refresh(@file_index)
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # ● 读取部分游戏数据
  90.   #--------------------------------------------------------------------------
  91.   def load_gamedata
  92.     @file_exist = FileTest.exist?(SAVE_DIR + @filename)
  93.     if @file_exist
  94.       file = File.open(SAVE_DIR + @filename, "r")
  95.       begin
  96.         @characters          = Marshal.load(file)
  97.         @frame_count         = Marshal.load(file)
  98.         @last_bgm            = Marshal.load(file)
  99.         @last_bgs            = Marshal.load(file)
  100.         @game_system         = Marshal.load(file)
  101.         @game_message        = Marshal.load(file)
  102.         @game_switches       = Marshal.load(file)
  103.         @game_variables      = Marshal.load(file)
  104.         @game_self_switches  = Marshal.load(file)
  105.         @game_actors         = Marshal.load(file)
  106.         @game_party          = Marshal.load(file)
  107.         @game_troop          = Marshal.load(file)
  108.         @game_map            = Marshal.load(file)
  109.         @game_player         = Marshal.load(file)
  110.         # 读取截图
  111.         @file_bitmap         = Marshal.load(file)
  112.         @total_sec = @frame_count / Graphics.frame_rate
  113.       rescue
  114.         @file_exist = false
  115.       ensure
  116.         file.close
  117.       end
  118.     end
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # ● 刷新
  122.   #     index : 索引
  123.   #--------------------------------------------------------------------------
  124.   def refresh(index)
  125.     file_index = index
  126.     self.contents.clear
  127.     self.contents.font.color = normal_color
  128.     if @file_exist
  129.       # 描绘底部阴影
  130.       self.contents.fill_rect(12+3, 4+3, 326,249, Color.new(0,0,64))
  131.       # 描绘截图
  132.       draw_snap_bitmap(12, 4)
  133.       draw_party_characters(152, 296)
  134.       draw_playtime(0, 296+8, contents.width - 40, 2)
  135.     else
  136.       self.contents.draw_text(0, 296, 384-32, 24, "-No Data-", 1)
  137.     end
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # ◎ 更改索引
  141.   #     index : 索引
  142.   #--------------------------------------------------------------------------
  143.   def file_index=(file_index)
  144.     @file_index = file_index
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # ● 描绘游戏人物
  148.   #     x : 描画先 X 座標
  149.   #     y : 描画先 Y 座標
  150.   #--------------------------------------------------------------------------
  151.   def draw_party_characters(x, y)
  152.     for i in [email protected]
  153.       name = @characters[i][0]
  154.       index = @characters[i][1]
  155.       draw_character(name, index, x + i * 48, y)
  156.     end
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # ◎ 生成保存路径
  160.   #     path : 路径
  161.   #--------------------------------------------------------------------------
  162.   def make_dir(path)
  163.     dir = path.split("/")
  164.     for i in 0...dir.size
  165.       unless dir == "."
  166.         add_dir = dir[0..i].join("/")
  167.         begin
  168.           Dir.mkdir(add_dir)
  169.         rescue
  170.         end
  171.       end
  172.     end
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # ◎ 生成文件名
  176.   #     file_index : 存档文件索引 (0~3)
  177.   #--------------------------------------------------------------------------
  178.   def make_filename(file_index)
  179.     return "Save#{file_index + 1}.rvdata"
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # ◎ 描绘截图
  183.   #     x : 描画先 X 座標
  184.   #     y : 描画先 Y 座標
  185.   #--------------------------------------------------------------------------
  186.   def draw_snap_bitmap(x, y)
  187.     bitmap = @file_bitmap
  188.     if bitmap == nil
  189.       self.contents.draw_text(0, 112, 384-32, 24, "找不到截图文件!", 1)
  190.     else
  191.       self.contents.blur
  192.       rect = Rect.new(0, 0, 0, 0)
  193.       rect.width = bitmap.width
  194.       rect.height = bitmap.height
  195.       self.contents.blt(x, y, bitmap, rect)
  196.     end
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # ● 描绘游戏时间
  200.   #     x     : 描绘目标 X 坐标
  201.   #     y     : 描绘目标 Y 坐标
  202.   #     width : 宽
  203.   #     align : 配置
  204.   #--------------------------------------------------------------------------
  205.   def draw_playtime(x, y, width, align)
  206.     hour = @total_sec / 60 / 60
  207.     min = @total_sec / 60 % 60
  208.     sec = @total_sec % 60
  209.     time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  210.     self.contents.font.color = normal_color
  211.     self.contents.draw_text(x, y, width, WLH, time_string, 2)
  212.   end
  213. end

  214. #==============================================================================
  215. # ■ Scene_Base
  216. #==============================================================================
  217. class Scene_Base
  218.   #--------------------------------------------------------------------------
  219.   # ◎ 生成存档位图快照
  220.   #--------------------------------------------------------------------------
  221.   def snapshot_for_save
  222.     d_rect = Rect.new(0, 0, 326, 249)
  223.     s_rect = Rect.new(0, 0, 544, 416)
  224.     save_bitmap = Graphics.snap_to_bitmap
  225.     $game_temp.save_bitmap.dispose
  226.     $game_temp.save_bitmap = Bitmap.new(326, 249)
  227.     $game_temp.save_bitmap.stretch_blt(d_rect, save_bitmap, s_rect)
  228.   end
  229. end

  230. #==============================================================================
  231. # ■ Scene_Map
  232. #==============================================================================
  233. class Scene_Map < Scene_Base
  234.   #--------------------------------------------------------------------------
  235.   # ● 结束处理
  236.   #--------------------------------------------------------------------------
  237.   alias save_terminate terminate
  238.   def terminate
  239.     snapshot_for_save
  240.     save_terminate
  241.   end
  242. end

  243. #==============================================================================
  244. # ■ Scene_Title
  245. #==============================================================================
  246. class Scene_Title < Scene_Base
  247.   #--------------------------------------------------------------------------
  248.   # ● 判断继续是否有效
  249.   #--------------------------------------------------------------------------
  250.   def check_continue
  251.     @continue_enabled = (Dir.glob(SAVE_DIR + 'Save*.rvdata').size > 0)
  252.   end
  253. end

  254. #==============================================================================
  255. # ■ Scene_File
  256. #------------------------------------------------------------------------------
  257. #  处理文件的类。
  258. #==============================================================================
  259. class Scene_File < Scene_Base
  260.   #--------------------------------------------------------------------------
  261.   # ● 初始化对象
  262.   #     saving     : 存档标志 (false 为载入画面)
  263.   #     from_title : 调用标题画面的 "继续" 标志
  264.   #     from_event : 事件的 "调用存档画面" 的调用标志
  265.   #--------------------------------------------------------------------------
  266.   def initialize(saving, from_title, from_event)
  267.     @saving = saving
  268.     @from_title = from_title
  269.     @from_event = from_event
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   # ● 开始处理
  273.   #--------------------------------------------------------------------------
  274.   def start
  275.     super
  276.     create_menu_background
  277.     @help_window = Window_Help.new
  278.     create_command_window
  279.     if @saving
  280.       @index = $game_temp.last_file_index
  281.       @help_window.set_text(Vocab::SaveMessage)
  282.     else
  283.       @index = self.latest_file_index
  284.       @help_window.set_text(Vocab::LoadMessage)
  285.     end
  286.     @refresh_index = @command_window.index = @index
  287.     @item_max = MAX_SAVE_ID
  288.     create_savefile_window
  289.   end
  290.   #--------------------------------------------------------------------------
  291.   # ● 结束处理
  292.   #--------------------------------------------------------------------------
  293.   def terminate
  294.     super
  295.     dispose_menu_background
  296.     @help_window.dispose
  297.     dispose_item_windows
  298.   end
  299.   #--------------------------------------------------------------------------
  300.   # ● 还原至原先的画面
  301.   #--------------------------------------------------------------------------
  302.   def return_scene
  303.     if @from_title
  304.       $scene = Scene_Title.new
  305.     elsif @from_event
  306.       $scene = Scene_Map.new
  307.     else
  308.       $scene = Scene_Menu.new(4)
  309.     end
  310.   end
  311.   #--------------------------------------------------------------------------
  312.   # ● 更新画面
  313.   #--------------------------------------------------------------------------
  314.   def update
  315.     super
  316.     update_menu_background
  317.     @help_window.update
  318.     update_savefile_windows
  319.     update_savefile_selection
  320.   end
  321.   #--------------------------------------------------------------------------
  322.   # ◎ 生成存档文件列表窗口
  323.   #--------------------------------------------------------------------------
  324.   def create_command_window
  325.     file_names = []
  326.     digit = MAX_SAVE_ID.to_s.size
  327.     str_f = ""
  328.     digit.times{|n| str_f += "0"}
  329.     str_f[str_f.size-1, 1] = digit.to_s
  330.     for i in 0...MAX_SAVE_ID
  331.       id = sprintf("%#{str_f}d", i+1)
  332.       file_names.push(Vocab::File + "\s" + id)
  333.     end
  334.     @command_window = Window_Command.new(160, file_names)
  335.     @command_window.height = 360
  336.     @command_window.y = 56
  337.   end
  338.   #--------------------------------------------------------------------------
  339.   # ● 生成存档文件窗口
  340.   #--------------------------------------------------------------------------
  341.   def create_savefile_window
  342.     @savefile_window = Window_SaveFile.new(@command_window.index, make_filename(@command_window.index))
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # ● 释放存档文件
  346.   #--------------------------------------------------------------------------
  347.   def dispose_item_windows
  348.     @command_window.dispose
  349.     @savefile_window.dispose
  350.   end
  351.   #--------------------------------------------------------------------------
  352.   # ● 更新存档文件窗口
  353.   #--------------------------------------------------------------------------
  354.   def update_savefile_windows
  355.     @command_window.update
  356.     @savefile_window.update
  357.   end
  358.   #--------------------------------------------------------------------------
  359.   # ● 更新存档文件选择
  360.   #--------------------------------------------------------------------------
  361.   def update_savefile_selection
  362.     if Input.trigger?(Input::C)
  363.       determine_savefile
  364.     end
  365.     if Input.trigger?(Input::B)
  366.       Sound.play_cancel
  367.       return_scene
  368.     end
  369.     if @refresh_index != @command_window.index
  370.       @refresh_index = @command_window.index
  371.       @savefile_window.dispose
  372.       create_savefile_window
  373.       end
  374.   end
  375.   #--------------------------------------------------------------------------
  376.   # ● 确定存档文件
  377.   #--------------------------------------------------------------------------
  378.   def determine_savefile
  379.     if @saving
  380.       Sound.play_save
  381.       do_save
  382.     else
  383.       if @savefile_window.file_exist
  384.         Sound.play_load
  385.         do_load
  386.       else
  387.         Sound.play_buzzer
  388.         return
  389.       end
  390.     end
  391.     $game_temp.last_file_index = @index
  392.   end
  393.   #--------------------------------------------------------------------------
  394.   # ◎ 生成文件名
  395.   #     file_index : 存档文件索引
  396.   #--------------------------------------------------------------------------
  397.   def make_filename(file_index)
  398.     return "Save#{file_index + 1}.rvdata"
  399.   end
  400.   #--------------------------------------------------------------------------
  401.   # ● 按时间戳选择最新的文件
  402.   #--------------------------------------------------------------------------
  403.   def latest_file_index
  404.     index = 0
  405.     latest_time = Time.at(0) # 时间戳
  406.     for i in 0...MAX_SAVE_ID
  407.       file_name = make_filename(i)
  408.       if FileTest.exist?(SAVE_DIR + file_name)
  409.         file = File.open(SAVE_DIR + file_name, "r")
  410.         if file.mtime > latest_time
  411.           latest_time = file.mtime
  412.           index = i
  413.         end
  414.       end
  415.     end
  416.     return index
  417.   end
  418.   #--------------------------------------------------------------------------
  419.   # ● 执行存档
  420.   #--------------------------------------------------------------------------
  421.   def do_save
  422.     file_name = make_filename(@command_window.index)
  423.     file = File.open(SAVE_DIR + file_name, "wb")
  424.     write_save_data(file)
  425.     # 保存位图
  426.     $file_bitmap = $game_temp.save_bitmap
  427.     Marshal.dump($file_bitmap, file)
  428.     file.close
  429.     return_scene
  430.   end
  431.   #--------------------------------------------------------------------------
  432.   # ● 执行载入
  433.   #--------------------------------------------------------------------------
  434.   def do_load
  435.     file_name = make_filename(@command_window.index)
  436.     file = File.open(SAVE_DIR + file_name, "rb")
  437.     read_save_data(file)
  438.     file.close
  439.     $scene = Scene_Map.new
  440.     RPG::BGM.fade(1500)
  441.     Graphics.fadeout(60)
  442.     Graphics.wait(40)
  443.     @last_bgm.play
  444.     @last_bgs.play
  445.   end
  446. end
复制代码
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-28 02:11

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表