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

Project1

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

[已经过期] vx新版截图存档脚本显示“找不到截图文件”和存档日期问题

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
40 小时
注册时间
2005-12-30
帖子
41
跳转到指定楼层
1
发表于 2012-12-5 16:33:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 zhangmdk 于 2012-12-5 16:34 编辑

我正在往一个SLG的工程里整合“vx新版截图存档”脚本,结果发现可以正常存取档,但不能显示截图。
截图全部显示“找不到截图文件!”

游戏用的SRPG3D的SLG脚本,其中有个重写Since_File的类如下
  1. #==============================================================================
  2. # ■ Scene_File
  3. #------------------------------------------------------------------------------
  4. #  ファイル画面の処理を行うクラスです。
  5. #==============================================================================

  6. class Scene_File < Scene_Base
  7.   #--------------------------------------------------------------------------
  8.   # ● オブジェクト初期化
  9.   #     saving     : セーブフラグ (false ならロード画面)
  10.   #     from_title : タイトルの「コンティニュー」で呼び出されたフラグ
  11.   #     from_event : イベントの「セーブ画面の呼び出し」で呼び出されたフラグ
  12.   #--------------------------------------------------------------------------
  13.   alias tsrpg_scene_file_initialize initialize
  14.   def initialize(saving, from_title, from_event, from_srpg = false)
  15.     @from_srpg = from_srpg
  16.     tsrpg_scene_file_initialize(saving, from_title, from_event)
  17.   end
  18.   #--------------------------------------------------------------------------
  19.   # ● 元の画面へ戻る
  20.   #--------------------------------------------------------------------------
  21.   alias tsrpg_scene_file_return_scene return_scene
  22.   def return_scene
  23.     if @from_srpg
  24.       $scene = Scene_Srpg.new(false, true)
  25.       return
  26.     end
  27.     tsrpg_scene_file_return_scene
  28.   end
  29.   #--------------------------------------------------------------------------
  30.   # ● ロードの実行
  31.   #--------------------------------------------------------------------------
  32.   alias tsrpg_scene_file_do_load do_load
  33.   def do_load
  34.     if TSRPG::USE_SAVE
  35.       file = File.open(@savefile_windows[@index].filename, "r")
  36.       begin
  37.         @characters     = Marshal.load(file)
  38.         @frame_count    = Marshal.load(file)
  39.         @last_bgm       = Marshal.load(file)
  40.         @last_bgs       = Marshal.load(file)
  41.         @game_system    = Marshal.load(file)
  42.       ensure
  43.         file.close
  44.       end
  45.       file = File.open(@savefile_windows[@index].filename, "rb")
  46.       read_save_data(file)
  47.       file.close
  48.       if @game_system.in_srpg
  49.         $scene = Scene_Srpg.new
  50.       else
  51.         $scene = Scene_Map.new
  52.       end
  53.       RPG::BGM.fade(1500)
  54.       Graphics.fadeout(60)
  55.       Graphics.wait(40)
  56.       @last_bgm.play
  57.       @last_bgs.play
  58.     else
  59.       tsrpg_scene_file_do_load
  60.     end
  61.   end
  62.   #--------------------------------------------------------------------------
  63.   # ● セーブデータの書き込み
  64.   #     file : 書き込み用ファイルオブジェクト (オープン済み)
  65.   #--------------------------------------------------------------------------
  66.   alias tsrpg_scene_file_write_save_data write_save_data
  67.   def write_save_data(file)
  68.     $game_system.in_srpg = @from_srpg
  69.     tsrpg_scene_file_write_save_data(file)
  70.     Marshal.dump($game_srpgmap,        file)
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # ● セーブデータの読み込み
  74.   #     file : 読み込み用ファイルオブジェクト (オープン済み)
  75.   #--------------------------------------------------------------------------
  76.   alias tsrpg_scene_file_read_save_data read_save_data
  77.   def read_save_data(file)
  78.     tsrpg_scene_file_read_save_data(file)
  79.     $game_srpgmap        = Marshal.load(file)
  80.   end
  81. end
复制代码
截图的脚本是这个:http://www.66rpg.com/articles/3041

另外,我往存储类里加了需要存储$actor_fighted数组,如下:
  1.   #--------------------------------------------------------------------------
  2.   # ● 写入存档数据
  3.   #     file : 写入存档对象(已开启)
  4.   #--------------------------------------------------------------------------
  5.   def write_save_data(file)
  6.     characters = []
  7.     for actor in $game_party.members
  8.       characters.push([actor.character_name, actor.character_index])
  9.     end
  10.     $game_system.save_count += 1
  11.     $game_system.version_id = $data_system.version_id
  12.     @last_bgm = RPG::BGM::last
  13.     @last_bgs = RPG::BGS::last
  14.     Marshal.dump(characters,           file)
  15.     Marshal.dump(Graphics.frame_count, file)
  16.     Marshal.dump(@last_bgm,            file)
  17.     Marshal.dump(@last_bgs,            file)
  18.     Marshal.dump($game_system,         file)
  19.     Marshal.dump($game_message,        file)
  20.     Marshal.dump($game_switches,       file)
  21.     Marshal.dump($game_variables,      file)
  22.     Marshal.dump($game_self_switches,  file)
  23.     Marshal.dump($game_actors,         file)
  24.     Marshal.dump($game_party,          file)
  25.     Marshal.dump($game_troop,          file)
  26.     Marshal.dump($game_map,            file)
  27.     Marshal.dump($game_player,         file)
  28.     Marshal.dump($actor_fighted,       file)
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # ● 读出存档数据
  32.   #     file : 读出存档对象(已开启)
  33.   #--------------------------------------------------------------------------
  34.   def read_save_data(file)
  35.     characters           = Marshal.load(file)
  36.     Graphics.frame_count = Marshal.load(file)
  37.     @last_bgm            = Marshal.load(file)
  38.     @last_bgs            = Marshal.load(file)
  39.     $game_system         = Marshal.load(file)
  40.     $game_message        = Marshal.load(file)
  41.     $game_switches       = Marshal.load(file)
  42.     $game_variables      = Marshal.load(file)
  43.     $game_self_switches  = Marshal.load(file)
  44.     $game_actors         = Marshal.load(file)
  45.     $game_party          = Marshal.load(file)
  46.     $game_troop          = Marshal.load(file)
  47.     $game_map            = Marshal.load(file)
  48.     $game_player         = Marshal.load(file)
  49.     $actor_fighted       = Marshal.load(file)
  50.     if $game_system.version_id != $data_system.version_id
  51.       $game_map.setup($game_map.map_id)
  52.       $game_player.center($game_player.x, $game_player.y)
  53.     end
  54.   end
复制代码
分别放在了最下面的位置,和这个有影响么?
另外,我还整合了一个显示事件名称的脚本,但和Scene_File不发生关系。

请问问题可能出现在哪里?

PS:另外如果手动删除存档会导致进入读档画面时出错。

最后还想问一下,如果我想在读档界面显示存档日期,有没有简单的方法?

Lv1.梦旅人

梦石
0
星屑
50
在线时间
270 小时
注册时间
2010-2-4
帖子
1305
2
发表于 2012-12-5 18:47:20 | 只看该作者
- -b当然有影响了,如果你需要的是你链接中的脚本的效果那应该把那个放到最下面,main之上,并在那个脚本中修改,原来的Scene_File可以去掉...
好歹当年也当过大魔王过,orz
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
40 小时
注册时间
2005-12-30
帖子
41
3
 楼主| 发表于 2012-12-5 21:33:33 | 只看该作者
zhangbanxian 发表于 2012-12-5 18:47
- -b当然有影响了,如果你需要的是你链接中的脚本的效果那应该把那个放到最下面,main之上,并在那个脚本中 ...

没错,就是这么放的,但是无法截图啊……

关键是有没有调试的方法?

点评

- -b好吧,确实是vx,我眼花,但他的写法不像vx...那么出错信息咧...  发表于 2012-12-5 21:38
- -b其实,你没有发现那个脚本是va用的吗?(va=vx ace)  发表于 2012-12-5 21:36
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
40 小时
注册时间
2005-12-30
帖子
41
4
 楼主| 发表于 2012-12-5 22:02:48 | 只看该作者
zhangbanxian 发表于 2012-12-5 18:47
- -b当然有影响了,如果你需要的是你链接中的脚本的效果那应该把那个放到最下面,main之上,并在那个脚本中 ...

嗯,没用过VA啊……

我使用p去调试了一下,现在是这样的结果:
在do_save里,我在dump进存档前用p看了一下存入的数据。
  1.   def do_save
  2.     file_name = make_filename(@command_window.index)
  3.     file = File.open(SAVE_DIR + file_name, "wb")
  4.     write_save_data(file)
  5.     # 保存位图
  6.     $file_bitmap = $game_temp.save_bitmap
  7.     #p $file_bitmap
  8.     Marshal.dump($file_bitmap, file)
  9.     file.close
  10.     return_scene
  11.   end
复制代码
结果显示:$file_bitmap确实是一个bitmap数据(不过看不到图),有没有直接显示bitmap的方法?


载入数据部分:
  1.   def load_gamedata
  2.     @file_exist = FileTest.exist?(SAVE_DIR + @filename)
  3.     if @file_exist
  4.       file = File.open(SAVE_DIR + @filename, "r")
  5.       begin
  6.         @characters          = Marshal.load(file)
  7.         @frame_count         = Marshal.load(file)
  8.         @last_bgm            = Marshal.load(file)
  9.         @last_bgs            = Marshal.load(file)
  10.         @game_system         = Marshal.load(file)
  11.         @game_message        = Marshal.load(file)
  12.         @game_switches       = Marshal.load(file)
  13.         @game_variables      = Marshal.load(file)
  14.         @game_self_switches  = Marshal.load(file)
  15.         @game_actors         = Marshal.load(file)
  16.         @game_party          = Marshal.load(file)
  17.         @game_troop          = Marshal.load(file)
  18.         @game_map            = Marshal.load(file)
  19.         [url=home.php?mod=space&uid=14736]@game_player[/url]         = Marshal.load(file)
  20.         # 读取截图
  21.         @file_bitmap         = Marshal.load(file)
  22.         #p @file_bitmap
  23.         @total_sec = @frame_count / Graphics.frame_rate
  24.         #新增的角色出战判断数据
  25.         @actor_fighted       = Marshal.load(file)
  26.       rescue
  27.         @file_exist = false
  28.       ensure
  29.         file.close
  30.       end
  31.     end
  32.   end
复制代码
用p看的结果是nil。
现在的问题是读取存档时读取不到这个bitmap数据,读档后@file_bitmap是nil,所以显示“没有截图”的内容。

那么问题需要如何判断?
1、如何判断是否bitmap确实存入了存档?可以推断存储过程有没有问题。
2、如何判断载入方式是否正确?或者有没有其他载入法?
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
40 小时
注册时间
2005-12-30
帖子
41
5
 楼主| 发表于 2012-12-5 23:03:42 | 只看该作者
现在的问题应该就是在读取部分存档数据时
        @file_bitmap         = Marshal.load(file)

这段,读取后为nil,而范例游戏读出的确实是一个bitmap文件。
那么如何判断我到底有没有正确存入file_bitmap数据?

@沉影不器  
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
40 小时
注册时间
2005-12-30
帖子
41
6
 楼主| 发表于 2012-12-5 23:13:13 | 只看该作者
继续更新调试情况
使用了 bitmap 导出png的类:http://www.66rpg.com/articles/3324

在读取存档部分数据时
        @file_bitmap         = Marshal.load(file)
读取出的@file_bitmap是nil

但是
        $file_bitmap         = Marshal.load(file)
读取出的是bitmap

我使用
        $file_bitmap.make_png("111.png")
导出后发现截图是正确的,也就是存储过程是没问题的,问题在于读取的这部分。

如果我这里使用 @file_bitmap = $file_bitmap  强行赋值
结果是所有的存档位都显示“无此存档”……败了
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
40 小时
注册时间
2005-12-30
帖子
41
7
 楼主| 发表于 2012-12-5 23:22:00 | 只看该作者
好吧,发现问题了。
  1.   def load_gamedata
  2.     @file_exist = FileTest.exist?(SAVE_DIR + @filename)
  3.     if @file_exist
  4.       file = File.open(SAVE_DIR + @filename, "r")
  5.       begin
  6.         @characters          = Marshal.load(file)
  7.         @frame_count         = Marshal.load(file)
  8.         @last_bgm            = Marshal.load(file)
  9.         @last_bgs            = Marshal.load(file)
  10.         @game_system         = Marshal.load(file)
  11.         @game_message        = Marshal.load(file)
  12.         @game_switches       = Marshal.load(file)
  13.         @game_variables      = Marshal.load(file)
  14.         @game_self_switches  = Marshal.load(file)
  15.         @game_actors         = Marshal.load(file)
  16.         @game_party          = Marshal.load(file)
  17.         @game_troop          = Marshal.load(file)
  18.         @game_map            = Marshal.load(file)
  19.         [url=home.php?mod=space&uid=14736]@game_player[/url]         = Marshal.load(file)
  20.         # 读取截图
  21.         @file_bitmap         = Marshal.load(file)
  22.         $file_bitmap         = Marshal.load(file)
  23. #        $file_bitmap.make_png("111.png")
  24. #        p $file_bitmap
  25. #        @file_bitmap = $file_bitmap
  26. #        p @file_bitmap
  27.         @total_sec = @frame_count / Graphics.frame_rate
  28.         #新增的角色出战判断数据
  29.         @actor_fighted       = Marshal.load(file)
  30.       rescue
  31.         #@file_exist = false
  32.       ensure
  33.         file.close
  34.       end
  35.     end
  36.   end
复制代码
早应该想到这么做……
不知道什么原因导致@file_bitmap无法读取,但是$file_bitmap可以读取,所以直接用$file_bitmap去读取数据好了,但是会出现“没有存档”的问题。
其实是因为begin段出现了错误,但是到底是哪里错了不清楚,于是@file_exist = false了,所以注释掉这句,然后用$file_bitmap去赋值显示截图,然后正常了……汗
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
270 小时
注册时间
2010-2-4
帖子
1305
8
发表于 2012-12-6 10:25:41 | 只看该作者
本帖最后由 zhangbanxian 于 2012-12-6 10:34 编辑
zhangmdk 发表于 2012-12-5 23:22
好吧,发现问题了。早应该想到这么做……
不知道什么原因导致@file_bitmap无法读取,但是$file_bitmap可以 ...


- -b其实,我发现了一个很神奇的问题,就是你压根就没把bitmap对象存进去,就是do_save貌似没改,你用$file_bitmap去读不就没意义了,截图存档不就是为了在窗口上显示截图么...话说,我也没怎么用过vx...
可能是你多存了一个nil吧,你把@file_bitmap=和$file_bitmap=的顺序换一换就ok,大概你在存档过程中也dump @file_bitmap了,其实是不用的...

评分

参与人数 1星屑 +180 收起 理由
咕噜 + 180 精品文章

查看全部评分

好歹当年也当过大魔王过,orz
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
40 小时
注册时间
2005-12-30
帖子
41
9
 楼主| 发表于 2012-12-6 11:00:52 | 只看该作者
zhangbanxian 发表于 2012-12-6 10:25
- -b其实,我发现了一个很神奇的问题,就是你压根就没把bitmap对象存进去,就是do_save貌似没改,你用$fi ...

确实存进去了,代码是这段:
  1.   def do_save
  2.     file_name = make_filename(@command_window.index)
  3.     file = File.open(SAVE_DIR + file_name, "wb")
  4.     write_save_data(file)
  5.     # 保存位图
  6.     $file_bitmap = $game_temp.save_bitmap
  7.    
  8.     Marshal.dump($file_bitmap, file)
  9.     file.close
  10.     return_scene
  11.   end
复制代码
write_save_data之后加了dump,然后再关闭文件。
现在解决了,还是使用$file_bitmap去读取,然后用$file_bitmap赋值图片,变成没有存档是因为读取过程中有错误,然后被捕捉了,所以文件被判定为不存在,于是我将捕捉后的判定内容注释掉,一切正常了……OTL

现全部代码如下:
  1. #==============================================================================
  2. # vx新截图存档 by 沉影不器
  3. #------------------------------------------------------------------------------
  4. # ☆ 核心部分是内存位图的输入输出
  5. #    (快速存储Bitmap的Marshal 作者: 柳之一) 强大啊
  6. #------------------------------------------------------------------------------
  7. # ▼ 相比rmxp正版截图存档(作者: 柳柳),主要变动如下:
  8. #     ① 省去了 screenshot.dll 文件 (因快速存储Bitmap的Marshal的存在)
  9. #     ② 无须人工新建存档文件夹,脚本将自建
  10. #     ③ 方便地更改最大存档数,只需设置最大值
  11. #==============================================================================
  12. MAX_SAVE_ID = 12                          # 最大存档数
  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.         [url=home.php?mod=space&uid=14736]@game_player[/url]         = Marshal.load(file)
  110.         # 读取截图
  111.         @file_bitmap         = Marshal.load(file)
  112.         $file_bitmap         = Marshal.load(file)
  113.         @total_sec = @frame_count / Graphics.frame_rate
  114.       rescue
  115.         #@file_exist = false
  116.       ensure
  117.         file.close
  118.       end
  119.     end
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # ● 刷新
  123.   #     index : 索引
  124.   #--------------------------------------------------------------------------
  125.   def refresh(index)
  126.     file_index = index
  127.     self.contents.clear
  128.     self.contents.font.color = normal_color
  129.     if @file_exist
  130.       # 描绘底部阴影
  131.       self.contents.fill_rect(12+3, 4+3, 326,249, Color.new(0,0,64))
  132.       # 描绘截图
  133.       draw_snap_bitmap(12, 4)
  134.       draw_party_characters(152, 296)
  135.       draw_playtime(0, 296+8, contents.width - 40, 2)
  136.     else
  137.       self.contents.draw_text(0, 296, 384-32, 24, "无此存档!", 1)
  138.     end
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # ◎ 更改索引
  142.   #     index : 索引
  143.   #--------------------------------------------------------------------------
  144.   def file_index=(file_index)
  145.     @file_index = file_index
  146.   end
  147.   #--------------------------------------------------------------------------
  148.   # ● 描绘游戏人物
  149.   #     x : 描画先 X 座標
  150.   #     y : 描画先 Y 座標
  151.   #--------------------------------------------------------------------------
  152.   def draw_party_characters(x, y)
  153.     for i in [email protected]
  154.       name = @characters[i][0]
  155.       index = @characters[i][1]
  156.       draw_character(name, index, x + i * 48, y)
  157.     end
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   # ◎ 生成保存路径
  161.   #     path : 路径
  162.   #--------------------------------------------------------------------------
  163.   def make_dir(path)
  164.     dir = path.split("/")
  165.     for i in 0...dir.size
  166.       unless dir == "."
  167.         add_dir = dir[0..i].join("/")
  168.         begin
  169.           Dir.mkdir(add_dir)
  170.         rescue
  171.         end
  172.       end
  173.     end
  174.   end
  175.   #--------------------------------------------------------------------------
  176.   # ◎ 生成文件名
  177.   #     file_index : 存档文件索引 (0~3)
  178.   #--------------------------------------------------------------------------
  179.   def make_filename(file_index)
  180.     return "Save#{file_index + 1}.rvdata"
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # ◎ 描绘截图
  184.   #     x : 描画先 X 座標
  185.   #     y : 描画先 Y 座標
  186.   #--------------------------------------------------------------------------
  187.   def draw_snap_bitmap(x, y)
  188.     #bitmap = @file_bitmap
  189.     bitmap = $file_bitmap
  190.     if bitmap == nil
  191.       self.contents.draw_text(0, 112, 384-32, 24, "找不到截图文件!", 1)
  192.     else
  193.       self.contents.blur
  194.       rect = Rect.new(0, 0, 0, 0)
  195.       rect.width = bitmap.width
  196.       rect.height = bitmap.height
  197.       self.contents.blt(x, y, bitmap, rect)
  198.     end
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # ● 描绘游戏时间
  202.   #     x     : 描绘目标 X 坐标
  203.   #     y     : 描绘目标 Y 坐标
  204.   #     width : 宽
  205.   #     align : 配置
  206.   #--------------------------------------------------------------------------
  207.   def draw_playtime(x, y, width, align)
  208.     hour = @total_sec / 60 / 60
  209.     min = @total_sec / 60 % 60
  210.     sec = @total_sec % 60
  211.     time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  212.     self.contents.font.color = normal_color
  213.     self.contents.draw_text(x, y, width, WLH, time_string, 2)
  214.   end
  215. end

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

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

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

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

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-9-27 22:14

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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