Advertisement
Rafael_Sol_Maker

RAFAEL_SOL_MAKER's VX SAVE 2003 STYLE v1.2a

Nov 17th, 2011
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.13 KB | None | 0 0
  1. #===============================================================================
  2. #                 RAFAEL_SOL_MAKER's VX SAVE 2003 STYLE v1.2a
  3. #                   Based on 'Save Estilo 2003' by UNIR.
  4. #-------------------------------------------------------------------------------
  5. # Description : Enables to increase the number of saveslots beyond the default
  6. #               that are only 4, for the wished number.
  7. #               Also modify the scene so it resembles more the one from
  8. #               RPG Maker 2003 showing character faces and money.
  9. #               Compatible with 544x416 and 640x480 resolutions.
  10. #-------------------------------------------------------------------------------
  11. # How to Use: Configure the total of saveslots in the configurable module.
  12. #-------------------------------------------------------------------------------
  13. # Special Thanks: UNIR
  14. #-------------------------------------------------------------------------------
  15. #===============================================================================
  16.  
  17. #===============================================================================
  18. # UPDATES
  19. #-------------------------------------------------------------------------------
  20. # VX SAVE 2003 STYLE v1.2 -> v1.2a
  21. # * Now the title scene can load the save files again...
  22. #   (Oops, how I could forget this?!)
  23. # VX SAVE 2003 STYLE v1.1 -> v1.2
  24. # * Now the file name is generated with 2 digits, even if it's lesser than 10;
  25. #     Eg.: 'Save01.rvdata'
  26. # * The saveslots got a separated folder(created automatically, if needed)
  27. #     [Game's root path]/Saveslots/
  28. #-------------------------------------------------------------------------------
  29. #===============================================================================
  30.  
  31. module PowerPackVX_General_Configs  
  32.   # BASIC SYSTEM ADJUSTS
  33.   Total_Saveslots = 15  # Total of avaliable saveslots
  34. end
  35.  
  36.  
  37. module Vocab  
  38.   # NEW WORDS!
  39.   Money       = "Money"
  40.   Time        = "Time"
  41. end
  42.  
  43. #==============================================================================
  44. # Window_SaveFile
  45. #------------------------------------------------------------------------------
  46. # Shows the save game screen and allows to save and load a file.
  47. #==============================================================================
  48.  
  49. class Window_SaveFile < Window_Base
  50. include PowerPackVX_General_Configs
  51.  
  52.   def initialize(file_index, filename, top = 0)
  53.     y = top + (file_index % Total_Saveslots) * 120
  54.     super(0, y, Graphics.width, 120)
  55.     @file_index = file_index
  56.     @filename = filename
  57.     load_gamedata
  58.     refresh
  59.     @selected = false
  60.   end
  61.  
  62.   def load_gamedata
  63.     @time_stamp = Time.at(0)
  64.     @file_exist = FileTest.exist?(@filename)
  65.     if @file_exist
  66.       file = File.open(@filename, "r")
  67.       @time_stamp = file.mtime
  68.       begin
  69.         @characters         = Marshal.load(file)
  70.         @frame_count        = Marshal.load(file)
  71.         @last_bgm           = Marshal.load(file)
  72.         @last_bgs           = Marshal.load(file)
  73.         @game_system        = Marshal.load(file)
  74.         @game_message       = Marshal.load(file) #
  75.         @game_switches      = Marshal.load(file) #
  76.         @game_variables     = Marshal.load(file) #
  77.         @game_self_switches = Marshal.load(file) #
  78.         @game_actors        = Marshal.load(file) #
  79.         @game_party         = Marshal.load(file)
  80.         @total_sec = @frame_count / Graphics.frame_rate
  81.       rescue
  82.         @file_exist = false
  83.       ensure
  84.         file.close
  85.       end
  86.     end
  87.   end
  88.  
  89.   def refresh
  90.     self.contents.clear
  91.     name = Vocab::File + " #{@file_index + 1}"
  92.     self.contents.draw_text(4, 0, 200, WLH, name)
  93.     @name_width = contents.text_size(name).width
  94.     if @file_exist
  95.       draw_party_characters(176, 0)
  96.       draw_money (4, 32, 176)
  97.       draw_playtime(4, 64, 176)
  98.     end
  99.   end
  100.  
  101.   def draw_party_characters(x, y, spacing = 16)
  102.     interval = []
  103.     for i in 0...@characters.size.to_i; interval.push i; end; interval.reverse!
  104.     for i in interval
  105.       name = @characters[i][2]
  106.       index = @characters[i][3]      
  107.       diff = Graphics.width - 544
  108.       scale = 64 + (diff.to_f * 0.3).to_i
  109.       draw_face(name, index, x + i * scale + (i * spacing) , y)
  110.     end
  111.   end
  112.  
  113.   def draw_playtime(x, y, width)    
  114.     hour = @total_sec / 60 / 60
  115.     min = @total_sec  / 60 % 60
  116.     sec = @total_sec  % 60 % 60
  117.     if hour > 99
  118.       hour = 99
  119.       min  = 00
  120.     end
  121.     time_string = Vocab::Time
  122.     cx = contents.text_size(time_string).width
  123.     self.contents.font.color = normal_color
  124.     self.contents.draw_text(x, y, cx, WLH, time_string)
  125.     time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  126.     self.contents.font.color = system_color
  127.     self.contents.draw_text(cx + 18, y, width - cx + 4, WLH, time_string)
  128.   end
  129.  
  130.   def draw_money(x, y, width)
  131.     string = Vocab::Money + ' ' + @game_party.gold.to_s
  132.     cx = contents.text_size(string).width
  133.     self.contents.font.color = normal_color
  134.     self.contents.draw_text(x, y, cx, WLH, string, 0)
  135.     self.contents.font.color = system_color
  136.     self.contents.draw_text(cx + 4, y, width - cx + 4, WLH, Vocab::gold, 0)  
  137.   end  
  138.  
  139.   def update_cursor
  140.     if @selected
  141.       self.cursor_rect.set(0, 0, 168, height - 32)
  142.     else
  143.       self.cursor_rect.empty
  144.     end
  145.   end
  146. end
  147.  
  148. #==============================================================================
  149. # Scene_File
  150. #------------------------------------------------------------------------------
  151. # Operation of saved files on screen class.
  152. #==============================================================================
  153.  
  154. class Scene_File < Scene_Base
  155. include PowerPackVX_General_Configs
  156.  
  157.   def write_save_data(file)
  158.     characters = []    
  159.     for actor in $game_party.members
  160.       characters.push([ actor.character_name, actor.character_index,
  161.                         actor.face_name, actor.face_index,
  162.                         actor.name, actor.level ])
  163.     end
  164.     $game_system.save_count += 1
  165.     $game_system.version_id = $data_system.version_id
  166.     @last_bgm = RPG::BGM::last
  167.     @last_bgs = RPG::BGS::last
  168.     Marshal.dump(characters,           file)
  169.     Marshal.dump(Graphics.frame_count, file)
  170.     Marshal.dump(@last_bgm,            file)
  171.     Marshal.dump(@last_bgs,            file)
  172.     Marshal.dump($game_system,         file)
  173.     Marshal.dump($game_message,        file)
  174.     Marshal.dump($game_switches,       file)
  175.     Marshal.dump($game_variables,      file)
  176.     Marshal.dump($game_self_switches,  file)
  177.     Marshal.dump($game_actors,         file)
  178.     Marshal.dump($game_party,          file)
  179.     Marshal.dump($game_troop,          file)
  180.     Marshal.dump($game_map,            file)
  181.     Marshal.dump($game_player,         file)
  182.   end
  183.  
  184.   def start
  185.     super    
  186.     @file_max = Total_Saveslots
  187.     create_menu_background    
  188.     @help_window = Window_Help.new
  189.     @page_file_max = ((Graphics.height - @help_window.height) / 120).truncate
  190.     @spacing = ((Graphics.height - @help_window.height) - (@page_file_max * 120)) / 2
  191.    
  192.     create_dir_if_needed
  193.     create_savefile_windows
  194.     create_arrows
  195.     if @saving
  196.       @index = $game_temp.last_file_index
  197.       @help_window.set_text(Vocab::SaveMessage)
  198.     else
  199.       @index = self.latest_file_index
  200.       @help_window.set_text(Vocab::LoadMessage)
  201.     end
  202.     @savefile_windows[@index].selected = true
  203.     for i in 0...@file_max
  204.       window = @savefile_windows[i]
  205.       if @index > @page_file_max - 1
  206.         if @index < @file_max - @page_file_max - 1
  207.           @top_row = @index
  208.           window.y -= @index * window.height
  209.         elsif @index >= @file_max - @page_file_max
  210.           @top_row = @file_max - @page_file_max
  211.           window.y -= (@file_max - @page_file_max) * window.height
  212.         else
  213.           @top_row = @index
  214.           window.y -= @index * window.height
  215.         end
  216.       end
  217.       window.visible = (window.y >= (@help_window.height + @spacing)  and
  218.       window.y < (@help_window.height + @spacing) + @page_file_max * window.height)
  219.     end
  220.   end
  221.  
  222.   alias sol_maker_terminate terminate unless $@
  223.   def terminate
  224.     sol_maker_terminate
  225.     dispose_arrows
  226.   end
  227.  
  228.   def create_dir_if_needed
  229.     Dir.mkdir("Saveslots") unless File.directory?("Saveslots")
  230.   end
  231.  
  232.   def create_arrows
  233.     @sprite_arrow = Sprite.new
  234.     @bitmap_arrow = Bitmap.new (16, Graphics.height - @help_window.height)
  235.     @sprite_arrow.bitmap = @bitmap_arrow
  236.     @sprite_arrow.x = ( Graphics.width / 2) - 8
  237.     @sprite_arrow.y = @help_window.height
  238.     @sprite_arrow.z = 100
  239.   end
  240.  
  241.   def dispose_arrows
  242.     @bitmap_arrow.dispose unless @bitmap_arrow.nil?
  243.     @sprite_arrow.dispose unless @sprite_arrow.nil?    
  244.   end
  245.  
  246.   def update_arrows
  247.     filename = $game_system.windowskin
  248.     unless filename.nil?
  249.       bitmap = Cache.system(filename)
  250.     else
  251.       bitmap = Cache.system("Window")
  252.     end
  253.     @bitmap_arrow.clear    
  254.     @bitmap_arrow.blt (0, 0, bitmap,
  255.                           Rect.new(88,16,16,16)) if @index >  0
  256.     @bitmap_arrow.blt (0, @bitmap_arrow.height - 16, Cache.system("Window"),
  257.                           Rect.new(88,32,16,16)) if @index < Total_Saveslots - 1
  258.   end
  259.  
  260.   def create_savefile_windows
  261.     @top_row = 0
  262.     @savefile_windows = []
  263.     for i in 0...@file_max
  264.       @savefile_windows.push(Window_SaveFile.new(i, make_filename(i),@help_window.height))
  265.     end
  266.     for i in @savefile_windows
  267.       i.y += @spacing
  268.     end
  269.   end
  270.  
  271.   def make_filename(file_index)
  272.     return "Saveslots/Save" + sprintf("%02d", file_index + 1) + ".rvdata"
  273.   end
  274.  
  275.   def update_savefile_selection
  276.     if Input.trigger?(Input::C)
  277.       determine_savefile
  278.     elsif Input.trigger?(Input::B)
  279.       Sound.play_cancel
  280.       return_scene
  281.     else
  282.       last_index = @index
  283.       if Input.repeat?(Input::DOWN)  
  284.           cursor_down(Input.trigger?(Input::DOWN))
  285.       end
  286.       if Input.repeat?(Input::UP)
  287.         cursor_up(Input.trigger?(Input::UP))  
  288.       end
  289.       if @index != last_index
  290.         Sound.play_cursor
  291.         @savefile_windows[last_index].selected = false
  292.         @savefile_windows[@index].selected = true
  293.       end      
  294.     end
  295.     update_arrows
  296.   end
  297.  
  298.   def determine_savefile
  299.     if @saving
  300.       Sound.play_save
  301.       do_save
  302.     else
  303.       if @savefile_windows[@index].file_exist
  304.         Sound.play_load
  305.         do_load
  306.       else
  307.         Sound.play_buzzer
  308.         return
  309.       end
  310.     end
  311.     $game_temp.last_file_index = @index
  312.   end
  313.  
  314.   def cursor_down(wrap)
  315.     Sound.play_buzzer if wrap and @index == Total_Saveslots - 1
  316.     if @index < @file_max - 1
  317.       @index = (@index + 1) % @file_max
  318.       for i in 0...@file_max
  319.         window = @savefile_windows[i]
  320.         if @index == 0
  321.           @top_row = 0
  322.           window.y = (@help_window.height + @spacing) + i % @file_max * window.height
  323.         elsif @index - @top_row > @page_file_max - 1
  324.           window.y -= window.height
  325.         end
  326.         window.visible = (window.y >= (@help_window.height + @spacing) and
  327.           window.y < (@help_window.height + @spacing) + @page_file_max * window.height)
  328.       end
  329.       if @index - @top_row > @page_file_max - 1
  330.         @top_row += 1
  331.       end
  332.     end
  333.   end
  334.  
  335.   def cursor_up(wrap)
  336.     Sound.play_buzzer if wrap and @index == 0
  337.     if @index > 0
  338.       @index = (@index - 1 + @file_max) % @file_max
  339.       for i in 0...@file_max
  340.         window = @savefile_windows[i]
  341.         if @index == @file_max - 1
  342.           @top_row = @file_max - @page_file_max
  343.           window.y = (@help_window.height + @spacing) + i % @file_max * window.height          
  344.           window.y -= (@file_max - @page_file_max) * window.height
  345.         elsif @index - @top_row < 0
  346.           window.y += window.height
  347.         end
  348.         window.visible = (window.y >= (@help_window.height + @spacing) and
  349.           window.y < (@help_window.height + @spacing) + @page_file_max * window.height)        
  350.       end
  351.       if @index - @top_row < 0
  352.         @top_row -= 1
  353.       end
  354.     end
  355.   end
  356.  
  357. end
  358.  
  359. class Scene_Title < Scene_Base
  360.   def check_continue
  361.     @continue_enabled = (Dir.glob('Saveslots/Save*.rvdata').size > 0)
  362.   end
  363. end
  364.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement