Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #==============================================================================
  2. # ■ save & load screen customization
  3. #    Ver 0.02 2012/01/21 Fixed scene for event command “Save screen”
  4. #                          Fixed a bug that was not compatible with "Open"
  5. #    Ver 0.01 2011/12/25
  6. #    http://fweb.midi.co.jp/~mikagami/atelier/
  7. #------------------------------------------------------------------------------
  8. #
  9. # Change the appearance of the save screen and load screen with thumbnail.
  10. # Save location (map display name) in the save file and the game screen.
  11. #
  12. # ※Note!
  13. # ・Save files that are used before installing this script can no longer be used.
  14. # ・Because the thumbnail of the game screen is converted and saved,
  15. #  Save file size is relatively large. Also, the preview display speed is slow.
  16. # ・Although we have confirmed functionality, we do not guarantee zero defects.
  17. # ・The author holds the copyrights to this script. 水鏡幻姿 (Mikagami Atelier)
  18. #  However, you do not need the author's permission to use, revise, or redistribute this script.
  19. #  The author does not have an obligation to fulfill requests to revise the script or complete its unfinished parts.
  20. #  Instead of asking another person to revise the script, everybody will be happy if you revise it yourself.
  21. #
  22. #==============================================================================
  23.  
  24. module DataManager
  25.   #--------------------------------------------------------------------------
  26.   # ◎ Maximum number of save files (overwrite definition)
  27.   #--------------------------------------------------------------------------
  28.   def self.savefile_max
  29.     return 20 # Set a reasonable amount
  30.   end
  31.   #--------------------------------------------------------------------------
  32.   # ● Get save folder name
  33.   #--------------------------------------------------------------------------
  34.   def self.save_folder_name
  35.     return "Save"
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # ◎ Save file existence judgment (overwrite definition)
  39.   #--------------------------------------------------------------------------
  40.   def self.save_file_exists?
  41.     if save_folder_name == ""
  42.       path = 'Save*.rvdata2'
  43.     else
  44.       path = save_folder_name + '/Save*.rvdata2'
  45.     end
  46.     !Dir.glob(path).empty?
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # ◎ Create file name (overwrite definition)
  50.   #     index : File index
  51.   #--------------------------------------------------------------------------
  52.   def self.make_filename(index)
  53.     file_name = sprintf("Save%03d.rvdata2", index + 1)
  54.     if save_folder_name == ""
  55.       return file_name
  56.     else
  57.       return save_folder_name + '/' + file_name
  58.     end
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # ● Execution of save / preview
  62.   #--------------------------------------------------------------------------
  63.   def self.save_game_with_preview(index)
  64.     begin
  65.       save_game_without_rescue2(index)
  66.     rescue
  67.       delete_save_file(index)
  68.       false
  69.     end
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # ● Load execution and preview available
  73.   #--------------------------------------------------------------------------
  74.   def self.load_game2(index)
  75.     load_game_without_rescue2(index) rescue false
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ● Load preview
  79.   #--------------------------------------------------------------------------
  80.   def self.load_preview(index)
  81.     load_preview_without_rescue(index) rescue nil
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ● Execution of save and preview (no exception handling)
  85.   #--------------------------------------------------------------------------
  86.   def self.save_game_without_rescue2(index)
  87.     unless FileTest.directory?(save_folder_name)
  88.       if FileTest.exist?(save_folder_name)
  89.         msgbox "An error occurred during the save process. Please restart."
  90.         return false
  91.       end
  92.       Dir::mkdir(save_folder_name)
  93.       unless FileTest.directory?(save_folder_name)
  94.         msgbox "Save failed. Check your HDD/SSD free space, etc."
  95.         return false
  96.       end
  97.     end
  98.     File.open(make_filename(index), "wb") do |file|
  99.       $game_system.on_before_save
  100.       Marshal.dump(make_save_header2, file)
  101.       Marshal.dump(make_save_preview, file)
  102.       Marshal.dump(make_save_contents, file)
  103.       @last_savefile_index = index
  104.     end
  105.     return true
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # ● Load execution with preview (no exception handling)
  109.   #--------------------------------------------------------------------------
  110.   def self.load_game_without_rescue2(index)
  111.     File.open(make_filename(index), "rb") do |file|
  112.       Marshal.load(file)
  113.       Marshal.load(file)
  114.       extract_save_contents(Marshal.load(file))
  115.       reload_map_if_updated
  116.       @last_savefile_index = index
  117.     end
  118.     return true
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # ● Create / extend save header
  122.   #--------------------------------------------------------------------------
  123.   def self.make_save_header2
  124.     header = {}
  125.     header[:characters] = $game_party.characters_for_savefile
  126.     header[:playtime_s] = $game_system.playtime_s
  127.     header[:savetitle]  = $game_map.display_name
  128.     header
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # ● Load preview (no exception handling)
  132.   #--------------------------------------------------------------------------
  133.   def self.load_preview_without_rescue(index)
  134.     File.open(make_filename(index), "rb") do |file|
  135.       Marshal.load(file)
  136.       return array_to_bitmap(Marshal.load(file))
  137.     end
  138.     return nil
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # ● Create preview
  142.   #--------------------------------------------------------------------------
  143.   def self.make_save_preview
  144.     preview = bitmap_to_array($game_temp.save_preview_bmp)
  145.     preview
  146.   end
  147.   #--------------------------------------------------------------------------
  148.   # ● Convert preview bitmap to saveable array format
  149.   #     bitmap
  150.   #--------------------------------------------------------------------------
  151.   def self.bitmap_to_array(bitmap)
  152.     return unless bitmap
  153.     data = []
  154.     for i in 0...bitmap.width
  155.       data[i] = []
  156.       for j in 0...bitmap.height
  157.         color = bitmap.get_pixel(i, j)
  158.         value = (color.red.floor << 16) + (color.green.floor << 8) + color.blue.floor
  159.         data[i][j] = value
  160.       end
  161.     end
  162.     return data
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # ● Restore preview bitmap from array format to bitmap
  166.   #--------------------------------------------------------------------------
  167.   def self.array_to_bitmap(data)
  168.     return unless data
  169.     bitmap = Bitmap.new(data.size, data[0].size)
  170.     for i in 0...data.size
  171.       for j in 0...data[0].size
  172.         red   = (data[i][j] >> 16) & 0xff
  173.         green = (data[i][j] >> 8) & 0xff
  174.         blue  = data[i][j] & 0xff
  175.         color = Color.new(red, green, blue)
  176.         bitmap.set_pixel(i, j, color)
  177.       end
  178.     end
  179.     return bitmap
  180.   end
  181. end
  182.  
  183. class Game_Temp
  184.   #--------------------------------------------------------------------------
  185.   # ● Public instance variables
  186.   #--------------------------------------------------------------------------
  187.   attr_accessor :save_preview_bmp               # BMP for save preview
  188.   #--------------------------------------------------------------------------
  189.   # ● Object initialization
  190.   #--------------------------------------------------------------------------
  191.   alias _old001_initialize initialize
  192.   def initialize
  193.     _old001_initialize
  194.     @save_preview_bmp = Bitmap.new(1, 1)
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   # ● BMP for save preview
  198.   #--------------------------------------------------------------------------
  199.   def create_save_preview
  200.     @save_preview_bmp.dispose if @save_preview_bmp
  201.     @save_preview_bmp = Bitmap.new(224, 160)
  202.     rect = Rect.new(0, 0, 224, 160)
  203.     rect.x = $game_player.screen_x - 112
  204.     rect.y = $game_player.screen_y - 80 - 16
  205.     bitmap = Graphics.snap_to_bitmap
  206.     @save_preview_bmp.blt(0, 0, bitmap, rect)
  207.     bitmap.dispose
  208.   end
  209. end
  210.  
  211. class Game_Party < Game_Unit
  212.   #--------------------------------------------------------------------------
  213.   # ◎ Character image information for save file display (overwrite definition)
  214.   #--------------------------------------------------------------------------
  215.   def characters_for_savefile
  216.     battle_members.collect do |actor|
  217.       [actor.character_name, actor.character_index, actor.level, actor.name]
  218.     end
  219.   end
  220. end
  221.  
  222. #==============================================================================
  223. # ■ Window_SaveFileList
  224. #------------------------------------------------------------------------------
  225. #  Save file list window displayed on the save & load screen.
  226. #==============================================================================
  227. class Window_SaveFileList < Window_Selectable
  228.   #--------------------------------------------------------------------------
  229.   # ● Object initialization
  230.   #--------------------------------------------------------------------------
  231.   def initialize(x, y)
  232.     super(x, y, (Graphics.width - x) / 2, Graphics.height - y)
  233.     load_savefileheader
  234.     refresh
  235.     activate
  236.   end
  237.   #--------------------------------------------------------------------------
  238.   # ● Get number of items
  239.   #--------------------------------------------------------------------------
  240.   def item_max
  241.     DataManager.savefile_max
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ● Get item height
  245.   #--------------------------------------------------------------------------
  246.   def item_height
  247.     (height - standard_padding * 2) / 5
  248.   end
  249.   #--------------------------------------------------------------------------
  250.   # ● Drawing items
  251.   #--------------------------------------------------------------------------
  252.   def draw_item(index)
  253.     rect = item_rect_for_text(index)
  254.     text_h = rect.y + (rect.height - line_height * 2) / 2
  255.     name = Vocab::File + " #{index + 1}"
  256.     change_color(system_color)
  257.     draw_text(rect.x, text_h, rect.width, line_height, name)
  258.     return unless @data[index]
  259.     change_color(normal_color)
  260.     draw_playtime(rect.x, text_h, rect.width, line_height, index)
  261.     draw_savetitle(rect.x, text_h + line_height, rect.width, line_height, index)
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # ● Processing when the enter button is pressed
  265.   #--------------------------------------------------------------------------
  266.   def process_ok
  267.     call_ok_handler # Process with scene class
  268.   end
  269.   #--------------------------------------------------------------------------
  270.   # ● Read all save file headers
  271.   #--------------------------------------------------------------------------
  272.   def load_savefileheader
  273.     @data = []
  274.     for i in 0...item_max do @data[i] = DataManager.load_header(i) end
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # ● Drawing play time
  278.   #--------------------------------------------------------------------------
  279.   def draw_playtime(x, y, width, height, i)
  280.     draw_text(x, y, width, height, @data[i][:playtime_s], 2)
  281.   end
  282.   #--------------------------------------------------------------------------
  283.   # ● Drawing save titles
  284.   #--------------------------------------------------------------------------
  285.   def draw_savetitle(x, y, width, height, i)
  286.     title = @data[i][:savetitle]
  287.     title = "<NO TITLE>" if title == ""
  288.     draw_text(x, y, width, height, title)
  289.   end
  290. end
  291.  
  292. #==============================================================================
  293. # ■ Window_SaveFilePreview
  294. #------------------------------------------------------------------------------
  295. #  This is the save file window displayed during save & load screen.
  296. #==============================================================================
  297. class Window_SaveFilePreview < Window_Base
  298.   #--------------------------------------------------------------------------
  299.   # ● Object initialization
  300.   #--------------------------------------------------------------------------
  301.   def initialize(x, y)
  302.     super(x, y, Graphics.width - x, Graphics.height - y)
  303.     @file_no = -1
  304.     @bmps = []
  305.     @data = []
  306.   end
  307.   #--------------------------------------------------------------------------
  308.   # ● Dispose
  309.   #--------------------------------------------------------------------------
  310.   def dispose
  311.     for bmp in @bmps
  312.       next if bmp == nil or bmp.disposed?
  313.       bmp.dispose
  314.     end
  315.     super
  316.   end
  317.   #--------------------------------------------------------------------------
  318.   # ● Load save file and display preview
  319.   #     file_no : Save file number
  320.   #--------------------------------------------------------------------------
  321.   def set_preview(file_no)
  322.     return if @file_no == file_no
  323.     @file_no = file_no
  324.     refresh
  325.   end
  326.   #--------------------------------------------------------------------------
  327.   # ● Refresh
  328.   #--------------------------------------------------------------------------
  329.   def refresh
  330.     self.contents.clear
  331.     load_preview(@file_no)
  332.     return unless @data[@file_no]
  333.     bitmap = @bmps[@file_no]
  334.     start_x = (contents.width - bitmap.width) / 2
  335.     contents.fill_rect(start_x - 1, 7, bitmap.width + 2, bitmap.height + 2, Color.new(0, 0, 0))
  336.     contents.blt(start_x, 8, bitmap, bitmap.rect)
  337.     header = @data[@file_no]
  338.     header[:characters].each_with_index do |data, i|
  339.       break if i >= 4
  340.       character_y = bitmap.height + 22 + i * 40
  341.       draw_character(data[0], data[1], start_x + 16, character_y + 28)
  342.       draw_level_for_preview(data[2], start_x + 40, character_y)
  343.       draw_name_for_preview(data[3], start_x + 100, character_y, bitmap.width - start_x - 100)
  344.     end
  345.   end
  346.   #--------------------------------------------------------------------------
  347.   # ● Load preview data
  348.   #--------------------------------------------------------------------------
  349.   def load_preview(file_no)
  350.     return if @data[file_no]
  351.     @bmps[file_no] = DataManager.load_preview(file_no)
  352.     return unless @bmps[file_no]
  353.     @data[file_no] = DataManager.load_header(file_no)
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # ● Level drawing
  357.   #--------------------------------------------------------------------------
  358.   def draw_level_for_preview(level, x, y)
  359.     change_color(system_color)
  360.     draw_text(x, y, 24, line_height, Vocab::level_a)
  361.     change_color(normal_color)
  362.     draw_text(x + 24, y, 24, line_height, level, 2)
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # ● Actor name drawing
  366.   #--------------------------------------------------------------------------
  367.   def draw_name_for_preview(name, x, y, width)
  368.     change_color(normal_color)
  369.     draw_text(x, y, width, line_height, name)
  370.   end
  371. end
  372.  
  373. class Scene_File < Scene_MenuBase
  374.   #--------------------------------------------------------------------------
  375.   # ◎ Start processing (overwrite definition)
  376.   #--------------------------------------------------------------------------
  377.   def start
  378.     super
  379.     create_help_window
  380.     @filelist_window = Window_SaveFileList.new(0, @help_window.height)
  381.     @filelist_window.set_handler(:ok,     method(:on_savefile_ok))
  382.     @filelist_window.set_handler(:cancel, method(:on_savefile_cancel))
  383.     @preview_window = Window_SaveFilePreview.new(@filelist_window.width, @help_window.height)
  384.     init_selection
  385.   end
  386.   #--------------------------------------------------------------------------
  387.   # ◎ End processing (overwrite definition)
  388.   #--------------------------------------------------------------------------
  389.   def terminate
  390.     super
  391.   end
  392.   #--------------------------------------------------------------------------
  393.   # ◎ Initialize selected state (overwrite definition)
  394.   #--------------------------------------------------------------------------
  395.   def init_selection
  396.     index = first_savefile_index
  397.     @filelist_window.select(index)
  398.     @preview_window.set_preview(index)
  399.   end
  400.   #--------------------------------------------------------------------------
  401.   # ◎ Frame update (overwrite definition)
  402.   #--------------------------------------------------------------------------
  403.   def update
  404.     super
  405.     @preview_window.set_preview(@filelist_window.index)
  406.   end
  407. end
  408.  
  409. class Scene_Save < Scene_File
  410.   #--------------------------------------------------------------------------
  411.   # ◎ Save file (overwrite definition)
  412.   #--------------------------------------------------------------------------
  413.   def on_savefile_ok
  414.     super
  415.     if DataManager.save_game_with_preview(@filelist_window.index)
  416.       on_save_success
  417.     else
  418.       Sound.play_buzzer
  419.     end
  420.   end
  421. end
  422.  
  423. class Scene_Load < Scene_File
  424.   #--------------------------------------------------------------------------
  425.   # ◎ Save file (overwrite definition)
  426.   #--------------------------------------------------------------------------
  427.   def on_savefile_ok
  428.     super
  429.     if DataManager.load_game2(@filelist_window.index)
  430.       on_load_success
  431.     else
  432.       Sound.play_buzzer
  433.     end
  434.   end
  435. end
  436.  
  437. class Scene_Map < Scene_Base
  438.   #--------------------------------------------------------------------------
  439.   # ◎ End processing
  440.   #--------------------------------------------------------------------------
  441.   alias _old001_terminate terminate
  442.   def terminate
  443.     $game_temp.create_save_preview
  444.     _old001_terminate
  445.   end
  446. end