查看: 5078|回复: 7

[原创发布] 【原创】改良存读档系统优化版 Ver 1.2

[复制链接]
梦石
0
星屑
9557
在线时间
5074 小时
注册时间
2013-6-21
回帖
3459

开拓者贵宾剧作品鉴家

发表于 2013-6-21 19:57:18 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 RyanBern 于 2016-3-12 09:45 编辑

不知道有没有人发过类似的东西,不过好歹是原创,拿出来跟大家分享一下。
本脚本适用于RMXP。由于是借助RMXP预置脚本改的,所以应该不会有什么冲突,除非原有的系统被改得面目全非。


这是我刚入住6R时献上的第一个技术贴,不过没什么人气,现在拿出来返工一下。简单优化了一下脚本。
代码如下,有什么BUG欢迎报告:
  1. #=============================================================================
  2. # 改良存读档优化版 Ver 1.21
  3. #-----------------------------------------------------------------------------
  4. # By : RyanBern
  5. #-----------------------------------------------------------------------------
  6. # 功能说明:
  7. #     在原始的存读档系统上做了一些加强,提供了一些扩展内容,界面比较简单,可以
  8. #     试着在游戏中使用。
  9. #     1.屏蔽了 Window_SaveFile,而选择了可以滚动的 Window_Selectable,存档数量
  10. #       想存多少就存多少。
  11. #     2.自动存档功能,这个是为一些没有存档意识的玩家写的系统,有了它系统就可以
  12. #       按照一定规律自动保存进度,再也不用担心进度丢失了。存档的时机为主角切换
  13. #       到另一个地图之后,可以通过更改下面的常量来控制。
  14. #     3.存档覆盖提示功能,这个也是为一些粗心玩家设定的系统,当存储的位置已经有
  15. #       了文件时,再存档会跳出覆盖提示,避免误操作。
  16. #-----------------------------------------------------------------------------
  17. # 另外里面的 Window_Selectable 是我扩展的内容,可以单独拿出来使用,扩展的功能
  18. # 是可以指定每一行的行高,这样 Window_Selectable 滚动内容的行高就可以不必限制
  19. # 为 32 了。
  20. #-----------------------------------------------------------------------------
  21. # 更新记录:
  22. #     2014.12.25  精简代码,修复多了 end 的 BUG
  23. #     2016.03.12  缓解 F12 冲突的问题
  24. #=============================================================================
  25. module RB
  26.   # 存档数最大值
  27.   SAVES_MAX = 20
  28.   
  29.   # 如果打开12号开关,将不会自动存档
  30.   NO_AUTOSAVE = 12
  31.   
  32.   # 禁止自动存档的地图ID数组,如果主角移动前的地图的ID在数组中
  33.   # 那么切换地图后将不会自动存档
  34.   NO_AUTOSAVE_MAPS = []
  35. end

  36. #=============================================================================
  37. # ■ Window_Selectable
  38. #-----------------------------------------------------------------------------
  39. #  拥有光标的移动以及滚动功能的窗口类。
  40. #   RB 加强版,可以设定一行的高度
  41. #   指定某一行的高度可以这样 Window_Selectable.new(0, 0, 120, 120, 54)
  42. #   表示该窗口一行高度为 54,如果不写,默认为 32(原始默认高度)
  43. #=============================================================================

  44. class Window_Selectable < Window_Base
  45.   #--------------------------------------------------------------------------
  46.   # ● 定义实例变量
  47.   #--------------------------------------------------------------------------
  48.   attr_reader   :index                    # 光标位置
  49.   attr_reader   :help_window              # 帮助窗口
  50.   attr_accessor :row_height               # 行高
  51.   #--------------------------------------------------------------------------
  52.   # ● 初始画对像
  53.   #     x      : 窗口的 X 坐标
  54.   #     y      : 窗口的 Y 坐标
  55.   #     width  : 窗口的宽
  56.   #     height : 窗口的高
  57.   #--------------------------------------------------------------------------
  58.   def initialize(x, y, width, height, row_height=32)
  59.     super(x, y, width, height)
  60.     @item_max = 1
  61.     @column_max = 1
  62.     @index = -1
  63.     @row_height = row_height
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # ● 获取开头行
  67.   #--------------------------------------------------------------------------
  68.   def top_row
  69.     # 将窗口内容的传送源 Y 坐标、1 行的高 @row_height 等分
  70.     return self.oy / @row_height
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # ● 设置开头行
  74.   #     row : 显示开头的行
  75.   #--------------------------------------------------------------------------
  76.   def top_row=(row)
  77.     # row 未满 0 的场合更正为 0
  78.     if row < 0
  79.       row = 0
  80.     end
  81.     # row 超过 row_max - 1 的情况下更正为 row_max - 1
  82.     if row > row_max - 1
  83.       row = row_max - 1
  84.     end
  85.     # row 1 行高的 @row_height 倍、窗口内容的传送源 Y 坐标
  86.     self.oy = row * @row_height
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # ● 获取 1 页可以显示的行数
  90.   #--------------------------------------------------------------------------
  91.   def page_row_max
  92.     # 窗口的高度,设置画面的高度减去 32 ,除以 1 行的高度 @row_height
  93.     return (self.height - 32) / @row_height
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # ● 更新光标矩形
  97.   #--------------------------------------------------------------------------
  98.   def update_cursor_rect
  99.     # 光标位置不满 0 的情况下
  100.     if @index < 0
  101.       self.cursor_rect.empty
  102.       return
  103.     end
  104.     # 获取当前的行
  105.     row = @index / @column_max
  106.     # 当前行被显示开头行前面的情况下
  107.     if row < self.top_row
  108.       # 从当前行向开头行滚动
  109.       self.top_row = row
  110.     end
  111.     # 当前行被显示末尾行之后的情况下
  112.     if row > self.top_row + (self.page_row_max - 1)
  113.       # 从当前行向末尾滚动
  114.       self.top_row = row - (self.page_row_max - 1)
  115.     end
  116.     # 计算光标的宽
  117.     cursor_width = self.width / @column_max - 32
  118.     # 计算光标坐标
  119.     x = @index % @column_max * (cursor_width + 32)
  120.     y = @index / @column_max * @row_height - self.oy
  121.     # 更新光标矩形
  122.     self.cursor_rect.set(x, y, cursor_width, @row_height)
  123.   end
  124. end
  125. class Window_File < Window_Selectable
  126.   #--------------------------------------------------------------------------
  127.   # ● 初始化目标
  128.   #--------------------------------------------------------------------------
  129.   def initialize
  130.     super(0, 64, 640, 416 ,96)
  131.     @column_max = 1
  132.     case $scene
  133.     when Scene_Save
  134.       @item_max = RB::SAVES_MAX
  135.     when Scene_Load
  136.       @item_max = RB::SAVES_MAX + 1
  137.     end
  138.     refresh
  139.     self.index = 0
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   # ● 刷新
  143.   #--------------------------------------------------------------------------
  144.   def refresh
  145.     if @item_max == 0
  146.       return
  147.     end
  148.     self.contents = Bitmap.new(width - 32, @item_max * 96)
  149.     self.contents.clear
  150.     for j in 0...@item_max
  151.       x = 64
  152.       y = j * 96
  153.       self.contents.font.color = normal_color
  154.       case $scene
  155.       when Scene_Save
  156.       name = "文件 #{j + 1}"
  157.       self.contents.draw_text(4, y, 600, 32, name)
  158.       @filename = "Save#{j + 1}.rxdata"
  159.       @name_width = contents.text_size(name).width
  160.       @time_stamp = Time.at(0)
  161.       @file_exist = FileTest.exist?(@filename)
  162.       when Scene_Load
  163.         if j == 0
  164.           name = "自动存档"
  165.         else
  166.           name = "文件 #{j}"
  167.         end
  168.         self.contents.draw_text(4, y, 600, 32, name)
  169.       @filename = "Save#{j}.rxdata"
  170.       @name_width = contents.text_size(name).width
  171.       @time_stamp = Time.at(0)
  172.       @file_exist = FileTest.exist?(@filename)
  173.       end
  174.       if @file_exist
  175.         file = File.open(@filename, "r")
  176.         @time_stamp = file.mtime
  177.         @characters = Marshal.load(file)
  178.         @frame_count = Marshal.load(file)
  179.         @game_system = Marshal.load(file)
  180.         @game_switches = Marshal.load(file)
  181.         @game_variables = Marshal.load(file)
  182.         @total_sec = @frame_count / Graphics.frame_rate
  183.         file.close
  184.       end
  185.       # 存档文件存在的情况下
  186.       if @file_exist
  187.         # 描绘角色
  188.         for i in 0...@characters.size
  189.           bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
  190.           cw = bitmap.rect.width / 4
  191.           ch = bitmap.rect.height / 4
  192.           src_rect = Rect.new(0, 0, cw, ch)
  193.           x = 300 - @characters.size * 32 + i * 64 - cw / 2
  194.           self.contents.blt(x, 68 - ch + y, bitmap, src_rect)
  195.         end
  196.         # 描绘游戏时间
  197.         hour = @total_sec / 60 / 60
  198.         min = @total_sec / 60 % 60
  199.         sec = @total_sec % 60
  200.         time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  201.         self.contents.font.color = normal_color
  202.         self.contents.draw_text(4, 8 + y, 600, 32, time_string, 2)
  203.         # 描绘时间标记
  204.         self.contents.font.color = normal_color
  205.         time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
  206.         self.contents.draw_text(4, 40 + y, 600, 32, time_string, 2)
  207.       end
  208.     end
  209.   end
  210. end
  211. #==============================================================================
  212. # ■ Window_ReplaceConfirm
  213. #------------------------------------------------------------------------------
  214. #  确认是否覆盖原始存档的窗口
  215. #==============================================================================

  216. class Window_ReplaceConfirm < Window_Selectable
  217.   #--------------------------------------------------------------------------
  218.   # ● 初始化对像
  219.   #--------------------------------------------------------------------------
  220.   def initialize
  221.     super(160, 176, 320, 128)
  222.     self.contents = Bitmap.new(width - 32, height - 32)
  223.     @item_max = 2
  224.     @column_max = 2
  225.     @commands = ["是的",  "不要"]
  226.     refresh
  227.     self.index = 0
  228.   end
  229.   #--------------------------------------------------------------------------
  230.   # ● 刷新
  231.   #--------------------------------------------------------------------------
  232.   def refresh
  233.     self.contents.clear
  234.     self.contents.font.color = system_color
  235.     self.contents.draw_text(4, 0, 328, 32, "当前位置已经存在存档文件")
  236.     self.contents.draw_text(4, 32, 328, 32, "确认要覆盖当前存档文件吗?")
  237.     self.contents.font.color = normal_color
  238.     for i in 0...@item_max
  239.       draw_item(i)
  240.     end
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # ● 描绘项目
  244.   #     index : 项目编号
  245.   #--------------------------------------------------------------------------
  246.   def draw_item(index)
  247.     x = 4 + index * 144
  248.     self.contents.draw_text(x, 64, 128, 32, @commands[index])
  249.   end
  250.   def update_cursor_rect
  251.     if @index < 0
  252.       self.cursor_rect.empty
  253.     else
  254.       self.cursor_rect.set(@index * 144, 64, (self.width - 32) / 2, 32)
  255.     end
  256.   end
  257. end
  258. #==============================================================================
  259. # ■ Scene_File
  260. #------------------------------------------------------------------------------
  261. #  存档画面及读档画面的超级类。
  262. #==============================================================================

  263. class Scene_File
  264.   #--------------------------------------------------------------------------
  265.   # ● 主处理
  266.   #--------------------------------------------------------------------------
  267.   def main
  268.     # 生成帮助窗口
  269.     @help_window = Window_Help.new
  270.     @help_window.set_text(@help_text)
  271.     @file_window = Window_File.new
  272.     @file_window.index = $game_temp.last_file_index
  273.     @file_window.active = true
  274.     @confirm_window = Window_ReplaceConfirm.new
  275.     @confirm_window.active = false
  276.     @confirm_window.visible = false
  277.     @confirm_window.z = @file_window.z + 10
  278.     # 执行过渡
  279.     Graphics.transition
  280.     # 主循环
  281.     loop do
  282.       # 刷新游戏画面
  283.       Graphics.update
  284.       # 刷新输入信息
  285.       Input.update
  286.       # 刷新画面
  287.       update
  288.       # 如果画面被切换的话就中断循环
  289.       if $scene != self
  290.         break
  291.       end
  292.     end
  293.     # 准备过渡
  294.     Graphics.freeze
  295.     # 释放窗口
  296.     @help_window.dispose
  297.     @file_window.dispose
  298.     @confirm_window.dispose
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # ● 刷新画面
  302.   #--------------------------------------------------------------------------
  303.   def update
  304.     # 刷新窗口
  305.     @help_window.update
  306.     @file_window.update
  307.     @confirm_window.update
  308.     case $scene
  309.     when Scene_Save
  310.       if @file_window.active
  311.         update_file
  312.         return
  313.       end
  314.       if @confirm_window.active
  315.         update_confirm
  316.         return
  317.       end
  318.     when Scene_Load
  319.       # 按下 C 键的情况下
  320.       if Input.trigger?(Input::C)
  321.         # 调用过程 on_decision (定义继承目标)
  322.         on_decision(make_filename_load(@file_window.index))
  323.         $game_temp.last_file_index = @file_window.index
  324.         return
  325.       end
  326.       # 按下 B 键的情况下
  327.       if Input.trigger?(Input::B)
  328.         # 调用过程 on_cancel (定义继承目标)
  329.         on_cancel
  330.         return
  331.       end
  332.     end
  333.   end
  334.   #--------------------------------------------------------------------------
  335.   # ● 生成文件名
  336.   #     file_index : 文件名的索引 (0~3)
  337.   #--------------------------------------------------------------------------
  338.   def make_filename(file_index)
  339.     return "Save#{file_index + 1}.rxdata"
  340.   end
  341.   def make_filename_load(file_index)
  342.     return "Save#{file_index}.rxdata"
  343.   end
  344. end


  345. class Scene_Save < Scene_File
  346.   #--------------------------------------------------------------------------
  347.   # ● 初始化对像
  348.   #--------------------------------------------------------------------------
  349.   def initialize
  350.     super("要储存到哪个文件?")
  351.   end
  352.   def update_file
  353.     filename = make_filename(@file_window.index)
  354.     if Input.trigger?(Input::C)
  355.       $game_system.se_play($data_system.decision_se)
  356.       if FileTest.exist?(filename)
  357.         @file_window.active = false
  358.         @confirm_window.active = true
  359.         @confirm_window.visible = true
  360.       else
  361.         # 演奏存档 SE
  362.         $game_system.se_play($data_system.save_se)
  363.         # 写入存档数据
  364.         file = File.open(filename, "wb")
  365.         write_save_data(file)
  366.         file.close
  367.         # 如果被事件调用
  368.         if $game_temp.save_calling
  369.           # 清除存档调用标志
  370.           $game_temp.save_calling = false
  371.           # 切换到地图画面
  372.           $scene = Scene_Map.new
  373.           return
  374.         end
  375.         # 切换到菜单画面
  376.         $scene = Scene_Menu.new(4)
  377.       end
  378.     end
  379.     if Input.trigger?(Input::B)
  380.       # 演奏取消 SE
  381.       $game_system.se_play($data_system.cancel_se)
  382.       # 如果被事件调用
  383.       if $game_temp.save_calling
  384.         # 清除存档调用标志
  385.         $game_temp.save_calling = false
  386.         # 切换到地图画面
  387.         $scene = Scene_Map.new
  388.         return
  389.       end
  390.       # 切换到菜单画面
  391.       $scene = Scene_Menu.new(4)
  392.     end
  393.   end
  394.   def update_confirm
  395.     filename = make_filename(@file_window.index)
  396.     if Input.trigger?(Input::C)
  397.       case @confirm_window.index
  398.       when 0
  399.         # 演奏存档 SE
  400.         $game_system.se_play($data_system.save_se)
  401.         # 写入存档数据
  402.         file = File.open(filename, "wb")
  403.         write_save_data(file)
  404.         file.close
  405.         # 如果被事件调用
  406.         if $game_temp.save_calling
  407.           # 清除存档调用标志
  408.           $game_temp.save_calling = false
  409.           # 切换到地图画面
  410.           $scene = Scene_Map.new
  411.           return
  412.         end
  413.         # 切换到菜单画面
  414.         $scene = Scene_Menu.new(4)
  415.       when 1
  416.         $game_system.se_play($data_system.cancel_se)
  417.         @file_window.active = true
  418.         @confirm_window.active = false
  419.         @confirm_window.visible = false
  420.       end
  421.     end
  422.     if Input.trigger?(Input::B)
  423.       $game_system.se_play($data_system.cancel_se)
  424.       @file_window.active = true
  425.       @confirm_window.active = false
  426.       @confirm_window.visible = false
  427.     end
  428.   end
  429.   def autosave
  430.     filename = "Save0.rxdata"
  431.     file = File.open(filename, "wb")
  432.     write_save_data(file)
  433.     file.close
  434.   end
  435. end


  436. class Scene_Load < Scene_File
  437.   #--------------------------------------------------------------------------
  438.   # ● 初始化对像
  439.   #--------------------------------------------------------------------------
  440.   def initialize
  441.     # 再生成临时对像
  442.     $game_temp = Game_Temp.new
  443.     # 选择存档时间最新的文件
  444.     $game_temp.last_file_index = 0
  445.     latest_time = Time.at(0)
  446.     for i in 0..RB::SAVES_MAX
  447.       filename = make_filename_load(i)
  448.       if FileTest.exist?(filename)
  449.         file = File.open(filename, "r")
  450.         if file.mtime > latest_time
  451.           latest_time = file.mtime
  452.           $game_temp.last_file_index = i
  453.         end
  454.         file.close
  455.       end
  456.     end
  457.     super("要载入哪个文件?")
  458.   end
  459. end

  460. class Scene_Map
  461.   unless method_defined? :rb_transfer_player_20141225
  462.     alias rb_transfer_player_20141225 transfer_player
  463.     def transfer_player
  464.       rb_transfer_player_20141225
  465.       unless RB::NO_AUTOSAVE_MAPS.include?($game_map.map_id) || $game_switches[RB::NO_AUTOSAVE]
  466.         save = Scene_Save.new
  467.         save.autosave
  468.       end
  469.     end
  470.   end
  471. end
复制代码

附范例一枚:
Project5.rar (190.96 KB, 下载次数: 221)
注意有几个地方,我不知道该怎么标注,大家注意Scene_Save里面返回上一级的命令$scene = Scene_Menu.new(x),不同人的菜单不一样的,如果改过Scene_Menu的同学还请注意一下括号里面的数字。

点评

无图无真相  发表于 2013-7-28 19:59

评分

参与人数 1星屑 +6 收起 理由
龙和许也 + 6 塞糖

查看全部评分

梦石
0
星屑
1556
在线时间
626 小时
注册时间
2010-8-5
回帖
317
发表于 2013-7-28 19:44:54 | 显示全部楼层
这么好的帖子为啥没人呢.~~~占个沙发{:2_287:}
回复

使用道具 举报

梦石
0
星屑
130
在线时间
1 小时
注册时间
2013-7-30
回帖
2
发表于 2013-7-30 15:25:31 | 显示全部楼层
在下新手,受教了。

——新手玩家
回复

使用道具 举报

梦石
0
星屑
50
在线时间
11 小时
注册时间
2013-8-2
回帖
11
发表于 2013-8-2 16:33:30 | 显示全部楼层
好像不错个说,试试看
回复

使用道具 举报

梦石
0
星屑
50
在线时间
169 小时
注册时间
2010-7-7
回帖
38
发表于 2013-8-3 09:51:28 | 显示全部楼层
652行是不是多了一个end啊,有错误啊,删掉后可用
回复

使用道具 举报

梦石
0
星屑
9557
在线时间
5074 小时
注册时间
2013-6-21
回帖
3459

开拓者贵宾剧作品鉴家

 楼主| 发表于 2014-12-25 18:59:10 | 显示全部楼层
1.20版本更新,自顶一下。
主要更新的是修复了一些错误,另外精简了一些代码。
功能还是原来的
回复

使用道具 举报

梦石
0
星屑
9292
在线时间
2504 小时
注册时间
2011-5-20
回帖
14521

开拓者

发表于 2014-12-25 19:21:18 | 显示全部楼层
RyanBern 发表于 2014-12-25 01:59
1.20版本更新,自顶一下。
主要更新的是修复了一些错误,另外精简了一些代码。
功能还是原来的 ...

来个通用版吧(···这是在做什么···)
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复

使用道具 举报

梦石
0
星屑
287
在线时间
1580 小时
注册时间
2010-6-17
回帖
2818

开拓者贵宾

发表于 2017-2-1 12:27:57 | 显示全部楼层
要是想显示小截图怎么做啊?
快来点我一下,你会豁然开朗的
喵Kano特制
←开发中……

←暂时弃坑 电脑上资源全没
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部