Project1

标题: 求一个能用的存档管理脚本 [打印本页]

作者: DoloStar    时间: 2014-10-17 18:02
标题: 求一个能用的存档管理脚本
本帖最后由 DoloStar 于 2014-10-19 06:12 编辑

天干宝典里找到的档案管理
用读取和删除的时候提示错误
不然就是不能用...
有谁能分享一下嘛?
万分感谢
作者: DoloStar    时间: 2014-10-19 06:13
@RyanBern 就是可以删除进度的脚本
作者: DoloStar    时间: 2014-10-19 16:34
DoloStar 发表于 2014-10-19 06:13
@RyanBern 就是可以删除进度的脚本

@RyanBern 如果可以带上一个读取功能OuO万分感谢
作者: RyanBern    时间: 2014-10-19 19:18
写了一个,我就不放范例了,脚本复制过去后如果出现SyntaxError就看看有么有Url什么的,去掉就是了。
有问题再找我吧。
RUBY 代码复制
  1. #============================================================================
  2. # 简易存档管理系统
  3. #----------------------------------------------------------------------------
  4. # By : RyanBern
  5. #============================================================================
  6. =begin
  7.  
  8. 功能:把存档,读档,删档糅合到了一起,一个场景能实现三个功能。
  9. 档位增加到了6个。
  10. 注意,进行删档的时候不会有确认提示,会直接把档删了。如果要加确认提示的话,再联
  11. 系我吧。其实是我偷懒了。
  12.  
  13. 脚本插入到Main前即可,没有对原始脚本改动,冲突可能性小。
  14. 需要手动改几个地方(如果对应行找不到就开一下搜索,在相应脚本内部搜即可)
  15.  
  16. 1.Scene_Title,48行,for i in 0..3改成for i in 0..5
  17. 2.Scene_Title,157行,$scene = Scene_Load.new改成$scene = Scene_File_Manager.new(true)
  18. 3.Scene_Map,224行,$scene = Scene_Save.new改成$scene = Scene_File_Manager.new
  19. 4.Scene_Menu,160行,$scene = Scene_Save.new改成$scene = Scene_File_Manager.new
  20.  
  21. 不想要这个脚本的时候记得把上面几处都改成原来的样子。
  22.  
  23. =end
  24. class Window_File < Window_Selectable
  25.   def initialize
  26.     super(0, 128, 640, 352)
  27.     self.contents = Bitmap.new(width - 32, height - 32)
  28.     @item_max = 6
  29.     self.index = 0
  30.     refresh
  31.   end
  32.   def refresh
  33.     (0...6).each do |i|
  34.       draw_item(i)
  35.     end
  36.   end
  37.   def draw_item(index)
  38.     filename = "Save#{index + 1}.rxdata"
  39.     time_stamp = Time.at(0)
  40.     file_exist = FileTest.exist?(filename)
  41.     if file_exist
  42.       file = File.open(filename, "r")
  43.       time_stamp = file.mtime
  44.       characters = Marshal.load(file)
  45.       frame_count = Marshal.load(file)
  46.       game_system = Marshal.load(file)
  47.       game_switches = Marshal.load(file)
  48.       game_variables = Marshal.load(file)
  49.       total_sec = frame_count / Graphics.frame_rate
  50.       file.close
  51.     end
  52.     x = 4
  53.     y = index * 52
  54.     self.contents.fill_rect(x, y, self.contents.width - 4, 52, Color.new(0,0,0,0))
  55.     self.contents.font.size = 18
  56.     # 描绘文件编号
  57.     self.contents.font.color = normal_color
  58.     name = "文件 #{index + 1}"
  59.     self.contents.draw_text(4, y, 54, 32, name)
  60.     @name_width = contents.text_size(name).width
  61.     # 存档文件存在的情况下
  62.     if file_exist
  63.       # 描绘角色
  64.       for i in 0...characters.size
  65.         bitmap = RPG::Cache.character(characters[i][0], characters[i][1])
  66.         cw = bitmap.rect.width / 4
  67.         ch = bitmap.rect.height / 4
  68.         src_rect = Rect.new(0, 0, cw, ch)
  69.         cx = 96 + i * (cw + 8)
  70.         self.contents.blt(cx, y + (52 - ch) / 2, bitmap, src_rect)
  71.       end
  72.       # 描绘游戏时间
  73.       hour = total_sec / 60 / 60
  74.       min = total_sec / 60 % 60
  75.       sec = total_sec % 60
  76.       time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  77.       self.contents.font.size = 16
  78.       self.contents.font.color = normal_color
  79.       self.contents.draw_text(x + 444, y, 160, 24, time_string, 2)
  80.       # 描绘时间标记
  81.       self.contents.font.color = normal_color
  82.       time_string = time_stamp.strftime("%Y/%m/%d %H:%M")
  83.       self.contents.draw_text(x + 444, y + 24, 160, 24, time_string, 2)
  84.     end
  85.   end
  86.   def update_cursor_rect
  87.     if @index < 0
  88.       self.cursor_rect.empty
  89.     else
  90.       self.cursor_rect.set(0, @index * 52, self.width - 32, 52)
  91.     end
  92.   end
  93. end
  94.  
  95. class Window_File_Command < Window_Selectable
  96.   def initialize
  97.     super(0, 64, 640, 64)
  98.     self.contents = Bitmap.new(width - 32, height - 32)
  99.     @column_max = 3
  100.     @item_max = 3
  101.     self.index = 0
  102.     @commands = ["存档", "读档", "档案管理"]
  103.     refresh
  104.   end
  105.   def refresh
  106.     (0...3).each do |i|
  107.       draw_item(i)
  108.     end
  109.   end
  110.   def draw_item(index, color = normal_color)
  111.     x = 4 + index * width / @column_max
  112.     y = 0
  113.     w = self.contents.width / @column_max
  114.     self.contents.fill_rect(x, y, w, 32, Color.new(0,0,0,0))
  115.     self.contents.font.color = color
  116.     self.contents.draw_text(x, y, w, 32, @commands[index])
  117.   end
  118.   def disable_item(index)
  119.     draw_item(index, disabled_color)
  120.   end
  121.   def update_help
  122.     texts = ["保存当前进度", "读取已有进度", "进行存档管理"]
  123.     @help_window.set_text(texts[self.index])
  124.   end
  125. end
  126.  
  127. class Scene_File_Manager
  128.   def initialize(save_disabled = false)
  129.     @save_disabled = save_disabled
  130.   end
  131.   def main
  132.     @dummy_window = Window_Base.new(0, 128, 640, 352)
  133.     @help_window = Window_Help.new
  134.     @file_window = Window_File.new
  135.     @file_window.visible = false
  136.     @file_window.active = false
  137.     @command_window = Window_File_Command.new
  138.     @command_window.help_window = @help_window
  139.     if @save_disabled
  140.       @command_window.disable_item(0)
  141.     end
  142.     Graphics.transition
  143.     loop do
  144.       Graphics.update
  145.       Input.update
  146.       update
  147.       if $scene != self
  148.         break
  149.       end
  150.     end
  151.     Graphics.freeze
  152.     @dummy_window.dispose
  153.     @help_window.dispose
  154.     @command_window.dispose
  155.     @file_window.dispose
  156.   end
  157.   def update
  158.     @file_window.update
  159.     @command_window.update
  160.     if @command_window.active
  161.       update_command
  162.       return
  163.     end
  164.     if @file_window.active
  165.       update_file
  166.     end
  167.   end
  168.   def update_command
  169.     if Input.trigger?(Input::B)
  170.       $game_system.se_play($data_system.cancel_se)
  171.       if $game_temp.save_calling
  172.         $game_temp.save_calling = false
  173.         $scene = Scene_Map.new
  174.       elsif @save_disbled
  175.         $scene = Scene_Title.new
  176.       else
  177.         $scene = Scene_Menu.new(5)
  178.       end
  179.       return
  180.     end
  181.     if Input.trigger?(Input::C)
  182.       if @save_disabled && @command_window.index == 0
  183.         $game_system.se_play($data_system.buzzer_se)
  184.         return
  185.       end
  186.       $game_system.se_play($data_system.decision_se)
  187.       @command_window.active = false
  188.       @dummy_window.visible = false
  189.       @file_window.visible = true
  190.       @file_window.active = true
  191.       return
  192.     end
  193.   end
  194.   def update_file
  195.     if Input.trigger?(Input::B)
  196.       $game_system.se_play($data_system.cancel_se)
  197.       @file_window.visible = false
  198.       @file_window.active = false
  199.       @dummy_window.visible = true
  200.       @command_window.active = true
  201.       return
  202.     end
  203.     if Input.trigger?(Input::C)
  204.       filename = "Save#{@file_window.index + 1}.rxdata"
  205.       case @command_window.index
  206.       when 0
  207.         $game_system.se_play($data_system.save_se)
  208.         write_save_data(filename)
  209.         if $game_temp.save_calling
  210.           $game_temp.save_calling = false
  211.           $scene = Scene_Map.new
  212.         else
  213.           $scene = Scene_Menu.new(5)
  214.         end
  215.         return
  216.       when 1
  217.         if FileTest.exist?(filename)
  218.           $game_system.se_play($data_system.load_se)
  219.           $game_temp = Game_Temp.new
  220.           read_save_data(filename)
  221.           $game_system.bgm_play($game_system.playing_bgm)
  222.           $game_system.bgs_play($game_system.playing_bgs)
  223.           $game_map.update
  224.           $scene = Scene_Map.new
  225.         else
  226.           $game_system.se_play($data_system.buzzer_se)
  227.         end
  228.         return
  229.       when 2
  230.         if FileTest.exist?(filename)
  231.           $game_system.se_play($data_system.decision_se)
  232.           File.delete(filename)
  233.           @file_window.draw_item(@file_window.index)
  234.         else
  235.           $game_system.se_play($data_system.buzzer_se)
  236.         end
  237.         return
  238.       end
  239.     end
  240.   end
  241.   def write_save_data(filename)
  242.     file = File.open(filename, "wb")
  243.     characters = []
  244.     for i in 0...$game_party.actors.size
  245.       actor = $game_party.actors[i]
  246.       characters.push([actor.character_name, actor.character_hue])
  247.     end
  248.     Marshal.dump(characters, file)
  249.     Marshal.dump(Graphics.frame_count, file)
  250.     $game_system.save_count += 1
  251.     $game_system.magic_number = $data_system.magic_number
  252.     Marshal.dump($game_system, file)
  253.     Marshal.dump($game_switches, file)
  254.     Marshal.dump($game_variables, file)
  255.     Marshal.dump($game_self_switches, file)
  256.     Marshal.dump($game_screen, file)
  257.     Marshal.dump($game_actors, file)
  258.     Marshal.dump($game_party, file)
  259.     Marshal.dump($game_troop, file)
  260.     Marshal.dump($game_map, file)
  261.     Marshal.dump($game_player, file)
  262.     file.close
  263.   end
  264.   def read_save_data(filename)
  265.     file = File.open(filename, "rb")
  266.     characters = Marshal.load(file)
  267.     Graphics.frame_count = Marshal.load(file)
  268.     $game_system        = Marshal.load(file)
  269.     $game_switches      = Marshal.load(file)
  270.     $game_variables     = Marshal.load(file)
  271.     $game_self_switches = Marshal.load(file)
  272.     $game_screen        = Marshal.load(file)
  273.     $game_actors        = Marshal.load(file)
  274.     $game_party         = Marshal.load(file)
  275.     $game_troop         = Marshal.load(file)
  276.     $game_map           = Marshal.load(file)
  277.     $game_player        = Marshal.load(file)
  278.     if $game_system.magic_number != $data_system.magic_number
  279.       $game_map.setup($game_map.map_id)
  280.       $game_player.center($game_player.x, $game_player.y)
  281.     end
  282.     $game_party.refresh
  283.     file.close
  284.   end
  285. end






欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1