Advertisement
neutale

Save Slot Plus

Aug 27th, 2019
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 22.54 KB | None | 0 0
  1. #encoding:utf-8
  2.  
  3. =begin
  4. *******************************************************************************************
  5.  
  6.    * Save Slot Plus *
  7.  
  8.                        for RGSS3
  9.  
  10.         Ver 1.02   2013.07.27
  11.  
  12.    Author:魂(Lctseng),Bahamut Forum ID:play123
  13.    The original text published in: Bahamut RPG master Hara version
  14.  
  15.    Reprint please keep this label
  16.  
  17.    Home link:http://home.gamer.com.tw/homeindex.php?owner=play123
  18.  
  19.    Summary:
  20.                        Enhanced save file
  21.  
  22.  
  23.     This script modifies or redefines the following categories:
  24.                           1.DataManager
  25.                           2.Game_Party
  26.                           3.Game_Interpreter
  27.                           4.Window_SaveFile
  28.                           5.Scene_File
  29.                           6.Scene_Save
  30.                           7.Scene_Load
  31.                          
  32.                          
  33.                         Newly defined category:
  34.                           1.Window_Save_Decision
  35.                           2.Window_Load_Decision
  36.                        
  37.                          
  38.                         Modules and global variables that can be modified:
  39.                           1.Enable enhanced save:$Lctseng_Enable_SaveSlot_Plus
  40.                           2.Enable event save:$Lctseng_Enable_Auto_Save
  41.                           3.Show actor name:$Lctseng_SaveFileEX_Enable_Draw_Actor_Name
  42.                           4.Other settings:Lctseng_Save_Plus_Settings
  43.                        
  44.                          
  45.                          
  46.  
  47. *******************************************************************************************
  48.  
  49. =end
  50.  
  51.  
  52. $Lctseng_Enable_SaveSlot_Plus  = true #Whether to enable the enhanced save
  53. $Lctseng_Enable_Auto_Save  = true #Whether to enable autosave feature
  54. $Lctseng_SaveFileEX_Enable_Draw_Actor_Name = true #Whether to show actor name
  55.  
  56. module Lctseng_Save_Plus_Settings
  57.  
  58.   MAX_SAVE_SLOT = 16 #Max savefiles, doesn't include autosave, can be 0 after autosave is enabled
  59.  
  60.   NAME_OF_AUTO_SAVE_FILE = "Autosave" #The name for autosave file
  61.  
  62.   THE_POSITION_OF_ACTOR_NAMES = 75 #Y coordinate when drawing actor name
  63.  
  64.  
  65. end
  66.  
  67. #*******************************************************************************************
  68. #
  69. #   DO NOT MODIFY UNLESS YOU KNOW WHAT TO DO !
  70. #
  71. #*******************************************************************************************
  72.  
  73. #--------------------------------------------------------------------------
  74. # ★ Record script information
  75. #--------------------------------------------------------------------------
  76. if !$lctseng_scripts  
  77.   $lctseng_scripts = {}
  78. end
  79. $lctseng_scripts[:save_file_ex] = "1.02"
  80.  
  81. puts "Load script: Lctseng - saveslot_plus:#{$lctseng_scripts[:save_file_ex]}"
  82.  
  83.  
  84. #encoding:utf-8
  85. #==============================================================================
  86. # ■ DataManager
  87. #------------------------------------------------------------------------------
  88. #  All global variables used in the game are initialized here.
  89. #==============================================================================
  90.  
  91. module DataManager
  92.   include Lctseng_Save_Plus_Settings
  93.   #--------------------------------------------------------------------------
  94.   # ● Number of savefiles - redefinition
  95.   #--------------------------------------------------------------------------
  96.   class << self
  97.     alias lctseng_savefile_max savefile_max
  98.   end
  99.   #--------------------------------------------------------------------------
  100.   def self.savefile_max
  101.     return $Lctseng_Enable_Auto_Save ? MAX_SAVE_SLOT  + 1   : MAX_SAVE_SLOT
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # ● Real time format
  105.   #--------------------------------------------------------------------------
  106.   def self.gain_time_string
  107.     time = Time.new
  108.     return time.strftime("Year:%Y Month:%m Day:%d(%a) %X")
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # ● Create save header - redefinition
  112.   #--------------------------------------------------------------------------
  113.   class << self
  114.     alias lctseng_make_save_header make_save_header
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   def self.make_save_header
  118.     header = {}
  119.     header[:characters] = $game_party.characters_for_savefile
  120.     header[:names] = $game_party.names_for_savefile
  121.     header[:playtime_s] = $game_system.playtime_s
  122.     header[:time_log] = gain_time_string
  123.     header[:map_name] = $game_map.display_name
  124.     header
  125.   end
  126. end
  127.  
  128.  
  129. #encoding:utf-8
  130. #==============================================================================
  131. # ■ Game_Party
  132. #------------------------------------------------------------------------------
  133. #  Class that manages the team. Keep information about money and items.
  134. #  See $game_party for an example of this class.
  135. #==============================================================================
  136.  
  137. class Game_Party < Game_Unit
  138.   #--------------------------------------------------------------------------
  139.   # ● Save file display - redefinition - face index
  140.   #--------------------------------------------------------------------------
  141.   alias lctseng_characters_for_savefile  characters_for_savefile
  142.   #--------------------------------------------------------------------------
  143.   def characters_for_savefile
  144.     unless $Lctseng_Enable_SaveSlot_Plus
  145.       lctseng_characters_for_savefile
  146.     else
  147.       battle_members.collect do |actor|
  148.         [actor.face_name, actor.face_index]
  149.       end
  150.     end
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # ● Name used to display savefile
  154.   #--------------------------------------------------------------------------
  155.   def names_for_savefile
  156.       battle_members.collect do |actor|
  157.         actor.name#sprintf("Lv:%d",actor.level)
  158.       end
  159.   end
  160. end
  161.  
  162.  
  163. #encoding:utf-8
  164. #==============================================================================
  165. # ■ Game_Interpreter
  166. #------------------------------------------------------------------------------
  167. #   Interpreter for scenes.
  168. #   Class used for Game_Map, Game_Troop, and Game_Event.
  169. #==============================================================================
  170.  
  171. class Game_Interpreter
  172.   #--------------------------------------------------------------------------
  173.   # ● Start autosave
  174.   #--------------------------------------------------------------------------
  175.   def excute_auto_save
  176.     DataManager.save_game(0) if $Lctseng_Enable_Auto_Save
  177.   end
  178. end
  179.  
  180.  
  181. #==============================================================================
  182. # ■ Window_Save_Decision
  183. #==============================================================================
  184.  
  185. class Window_Save_Decision < Window_HorzCommand
  186.  
  187.   #--------------------------------------------------------------------------
  188.   # ● Initialization object
  189.   #--------------------------------------------------------------------------
  190.   def initialize(x =  (Graphics.width - window_width )/2 , y=   (Graphics.height / 2 ) -( line_height / 2 )  )
  191.     super(x, y)
  192.     self.z  =  300
  193.   end
  194.   #--------------------------------------------------------------------------
  195.   # ● Window width
  196.   #--------------------------------------------------------------------------
  197.   def window_width
  198.     return 300
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # ● Window height
  202.   #--------------------------------------------------------------------------
  203.   def window_height
  204.     return 50
  205.   end
  206.   #--------------------------------------------------------------------------
  207.   # ● Display
  208.   #--------------------------------------------------------------------------
  209.   def show?
  210.     return self.visible
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # ● Column length
  214.   #--------------------------------------------------------------------------
  215.   def col_max
  216.     return 2
  217.   end
  218.   #--------------------------------------------------------------------------
  219.   # ● Update scene
  220.   #--------------------------------------------------------------------------
  221.   def update
  222.     super
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● Create command
  226.   #--------------------------------------------------------------------------
  227.   def make_command_list
  228.     s=["Okay", "Cancel" ]         #Command name
  229.     add_command( s[0] ,    :sr_ok)    
  230.     add_command( s[1] ,    :sr_no)    
  231.   end
  232. end
  233.  
  234. #==============================================================================
  235. # ■ Window_Load_Decision
  236. #==============================================================================
  237.  
  238. class Window_Load_Decision < Window_HorzCommand
  239.  
  240.   #--------------------------------------------------------------------------
  241.   # ● Initialization object
  242.   #--------------------------------------------------------------------------
  243.   def initialize(x =  (Graphics.width - window_width) /2, y=   (Graphics.height / 2 ) -( line_height / 2 )  )
  244.     super(x, y)
  245.     self.z  =  300
  246.   end
  247.   #--------------------------------------------------------------------------
  248.   # ● Window width
  249.   #--------------------------------------------------------------------------
  250.   def window_width
  251.     return 300
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # ● Window height
  255.   #--------------------------------------------------------------------------
  256.   def window_height
  257.     return 50
  258.   end
  259.   #--------------------------------------------------------------------------
  260.   # ● Display
  261.   #--------------------------------------------------------------------------
  262.   def show?
  263.     return self.visible
  264.   end
  265.   #--------------------------------------------------------------------------
  266.   # ● Column length
  267.   #--------------------------------------------------------------------------
  268.   def col_max
  269.     return 2
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   # ● Update scene
  273.   #--------------------------------------------------------------------------
  274.   def update
  275.     super
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # ● Create command
  279.   #--------------------------------------------------------------------------
  280.   def make_command_list
  281.     s=["Okay", "Cancel" ]         #Command name
  282.     add_command( s[0] ,    :lr_ok)    
  283.     add_command( s[1] ,    :lr_no)    
  284.   end
  285. end
  286.  
  287. #encoding:utf-8
  288. #==============================================================================
  289. # ■ Window_SaveFile
  290. #------------------------------------------------------------------------------
  291. #  Window for displaying save files and load scene.
  292. #==============================================================================
  293.  
  294. class Window_SaveFile < Window_Base
  295.  
  296.   #--------------------------------------------------------------------------
  297.   # ● Refresh - redefinition
  298.   #--------------------------------------------------------------------------
  299.   alias lctseng_refresh refresh
  300.   #--------------------------------------------------------------------------
  301.   def refresh
  302.     unless $Lctseng_Enable_SaveSlot_Plus
  303.       contents.clear
  304.       change_color(normal_color)
  305.       if $Lctseng_Enable_Auto_Save
  306.         if @file_index==0
  307.           name = Lctseng_Save_Plus_Settings::NAME_OF_AUTO_SAVE_FILE
  308.         else
  309.           name = Vocab::File + " #{@file_index }"
  310.         end
  311.       else
  312.         name = Vocab::File + " #{@file_index +1}"
  313.       end
  314.       draw_text(4, 0, 200, line_height, name)
  315.       @name_width = text_size(name).width
  316.       draw_party_characters(152, 58)
  317.       draw_playtime(0, contents.height - line_height, contents.width - 4, 2)
  318.       return
  319.     end
  320.     contents.clear
  321.     change_color(normal_color)
  322.     if $Lctseng_Enable_Auto_Save
  323.       if @file_index==0
  324.         name = Lctseng_Save_Plus_Settings::NAME_OF_AUTO_SAVE_FILE
  325.       else
  326.         name = Vocab::File + " #{@file_index }"
  327.       end
  328.     else
  329.       name = Vocab::File + " #{@file_index +1}"
  330.     end
  331.     draw_text(4, 0, 200, line_height, name)
  332.     @name_width = text_size(name).width
  333.     draw_party_faces(0, line_height + 5)
  334.     draw_party_names(0, line_height + Lctseng_Save_Plus_Settings::THE_POSITION_OF_ACTOR_NAMES) if $Lctseng_SaveFileEX_Enable_Draw_Actor_Name
  335.     draw_playtime(0, contents.height - line_height, contents.width - 4, 2)
  336.     draw_time_log(0, 0 , contents.width - 4, 2)
  337.     draw_map_log(0, contents.height - line_height, contents.width - 4, 0)
  338.   end
  339.   #--------------------------------------------------------------------------
  340.   # ● Party's face
  341.   #--------------------------------------------------------------------------
  342.   def draw_party_faces(x, y)
  343.     header = DataManager.load_header(@file_index)
  344.     return unless header
  345.     header[:characters].each_with_index do |data, i|
  346.       draw_face(data[0], data[1], x + i * 100, y) rescue nil
  347.     end
  348.   end
  349.   #--------------------------------------------------------------------------
  350.   # ● Party's name
  351.   #--------------------------------------------------------------------------
  352.   def draw_party_names(x, y,width = 100)
  353.     header = DataManager.load_header(@file_index)
  354.     return unless header
  355.     return unless header[:names]
  356.     header[:names].each_with_index do |name, i|
  357.        draw_text( x + i * 100, y, width, line_height, name) rescue nil
  358.     end
  359.   end
  360.   #--------------------------------------------------------------------------
  361.   # ● Playtime - redefinition
  362.   #--------------------------------------------------------------------------
  363.   alias lctseng_draw_playtime draw_playtime
  364.   #--------------------------------------------------------------------------
  365.   def draw_playtime(x, y, width, align)
  366.     unless $Lctseng_Enable_SaveSlot_Plus
  367.       lctseng_draw_playtime(x, y, width, align)
  368.       return
  369.     end
  370.     header = DataManager.load_header(@file_index)
  371.     return unless header
  372.     draw_text(x, y, width, line_height,"Play time: " + header[:playtime_s], 2)
  373.   end
  374.   #--------------------------------------------------------------------------
  375.   # ● Real time display on file
  376.   #--------------------------------------------------------------------------
  377.   def draw_time_log(x, y, width, align)
  378.     header = DataManager.load_header(@file_index)
  379.     return unless header
  380.     draw_text(x, y, width, line_height,  header[:time_log], align) rescue nil
  381.   end
  382.   #--------------------------------------------------------------------------
  383.   # ● Location appear on the save file
  384.   #--------------------------------------------------------------------------
  385.   def draw_map_log(x, y, width, align)
  386.     header = DataManager.load_header(@file_index)
  387.     return unless header
  388.     draw_text(x, y, width, line_height, "Location: " + header[:map_name], align) rescue nil
  389.   end
  390.   end
  391.  
  392. #encoding:utf-8
  393. #==============================================================================
  394. # ■ Scene_File
  395. #------------------------------------------------------------------------------
  396. #  Parent class for save scene and load scene
  397. #==============================================================================
  398.  
  399. class Scene_File < Scene_MenuBase
  400.   #--------------------------------------------------------------------------
  401.   # ● Start processing - redefinition
  402.   #--------------------------------------------------------------------------
  403.   alias lctseng_start start
  404.   #--------------------------------------------------------------------------
  405.   def start
  406.     lctseng_start
  407.     create_decision_windows
  408.   end
  409.   #--------------------------------------------------------------------------
  410.   # ● Number of saves at a time - redefinition
  411.   #--------------------------------------------------------------------------
  412.   alias lctseng_visible_max visible_max
  413.   #--------------------------------------------------------------------------
  414.   def visible_max
  415.     unless $Lctseng_Enable_SaveSlot_Plus
  416.       return lctseng_visible_max
  417.     end
  418.     return 2
  419.   end
  420.   #--------------------------------------------------------------------------
  421.   # ● Create confirmation windows
  422.   #--------------------------------------------------------------------------
  423.   def create_decision_windows
  424.     @save_decision = Window_Save_Decision.new
  425.     @load_decision = Window_Load_Decision.new
  426.     @save_decision.hide
  427.     @load_decision.hide
  428.     @save_decision.deactivate
  429.     @load_decision.deactivate
  430.     @save_decision.set_handler(:sr_ok   ,method(:on_save_really_ok  ))
  431.     @save_decision.set_handler(:sr_no   ,method(:on_save_really_no  ))
  432.     @load_decision.set_handler(:lr_ok   ,method(:on_load_really_ok  ))
  433.     @load_decision.set_handler(:lr_no   ,method(:on_load_really_no  ))    
  434.     @load_decision.set_handler(:cancel   ,method(:on_load_really_no  ))    
  435.   end
  436.   #--------------------------------------------------------------------------
  437.   # ● Check cancel - redefinition
  438.   #--------------------------------------------------------------------------
  439.   alias lctseng_on_savefile_cancel on_savefile_cancel
  440.   #--------------------------------------------------------------------------
  441.   def on_savefile_cancel
  442.     if @save_decision.active
  443.       on_save_really_no
  444.     elsif @load_decision.active
  445.       on_load_really_ok
  446.     else
  447.       lctseng_on_savefile_cancel
  448.     end
  449.   end
  450.   #--------------------------------------------------------------------------
  451.   # ● Update cursor - redefinition
  452.   #--------------------------------------------------------------------------
  453.   alias lctseng_saveEX_update_cursor update_cursor
  454.   #--------------------------------------------------------------------------
  455.   def update_cursor
  456.     if @save_decision.active || @load_decision.active
  457.      
  458.     else
  459.       lctseng_saveEX_update_cursor
  460.     end
  461.   end
  462.   #--------------------------------------------------------------------------
  463.   # ● Check save
  464.   #--------------------------------------------------------------------------
  465.   def on_save_really_ok
  466.   end
  467.   #--------------------------------------------------------------------------
  468.   # ● No save
  469.   #--------------------------------------------------------------------------
  470.   def on_save_really_no
  471.   end
  472.   #--------------------------------------------------------------------------
  473.   # ● Confirm load
  474.   #--------------------------------------------------------------------------
  475.   def on_load_really_ok
  476.   end
  477.   #--------------------------------------------------------------------------
  478.   # ● Cancel load
  479.   #--------------------------------------------------------------------------
  480.   def on_load_really_no
  481.   end
  482. end
  483.  
  484. #encoding:utf-8
  485. #==============================================================================
  486. # ■ Scene_Save
  487. #------------------------------------------------------------------------------
  488. #  Check scene
  489. #==============================================================================
  490.  
  491. class Scene_Save < Scene_File
  492.   #--------------------------------------------------------------------------
  493.   # ● Check save - redefinition
  494.   #--------------------------------------------------------------------------
  495.   alias lctseng_on_savefile_ok on_savefile_ok
  496.   #--------------------------------------------------------------------------
  497.   def on_savefile_ok
  498.     if @index == 0&&$Lctseng_Enable_Auto_Save
  499.       Sound.play_buzzer
  500.       return
  501.     end
  502.     @savefile_windows.each {|window| window.deactivate }
  503.     if Dir.glob(DataManager.make_filename(@index)).empty?
  504.       @save_decision.select(0)
  505.     else
  506.       @save_decision.select(1)
  507.     end
  508.     @save_decision.show
  509.     @save_decision.activate
  510.     Sound.play_ok
  511.   end
  512.   #--------------------------------------------------------------------------
  513.   # ● Save confirm
  514.   #--------------------------------------------------------------------------
  515.   def on_save_really_ok
  516.     @savefile_windows.each {|window| window.activate }
  517.     @save_decision.hide
  518.     @save_decision.deactivate
  519.     lctseng_on_savefile_ok
  520.   end
  521.   #--------------------------------------------------------------------------
  522.   # ● Save?
  523.   #--------------------------------------------------------------------------
  524.   def on_save_really_no
  525.     @savefile_windows.each {|window| window.activate }
  526.     @save_decision.hide
  527.     @save_decision.deactivate
  528.     Sound.play_cancel
  529.   end
  530.   #--------------------------------------------------------------------------
  531.   # ● Handling save - redefining
  532.   #--------------------------------------------------------------------------
  533.   alias lctseng_on_save_success on_save_success
  534.    #--------------------------------------------------------------------------
  535.   def on_save_success
  536.     Sound.play_save
  537.     @savefile_windows[@index].refresh#.each {|window| window.refresh }
  538.   end
  539. end
  540.  
  541. #encoding:utf-8
  542. #==============================================================================
  543. # ■ Scene_Load
  544. #------------------------------------------------------------------------------
  545. #  Load scene
  546. #==============================================================================
  547.  
  548. class Scene_Load < Scene_File
  549.   #--------------------------------------------------------------------------
  550.   # ★ Redefinition
  551.   #--------------------------------------------------------------------------
  552.   unless @lctseng_for_savefile_ex_alias
  553.     alias lctseng_for_savefile_ex_On_savefile_ok on_savefile_ok # file check
  554.     @lctseng_for_savefile_ex_alias = true
  555.   end
  556.   #--------------------------------------------------------------------------
  557.   # ● Save confimation
  558.   #--------------------------------------------------------------------------
  559.   def on_savefile_ok
  560.     @savefile_windows.each {|window| window.deactivate }
  561.     @load_decision.select(0)
  562.     @load_decision.show
  563.     @load_decision.activate
  564.     Sound.play_ok
  565.   end
  566.   #--------------------------------------------------------------------------
  567.   # ● Loaf confirmation
  568.   #--------------------------------------------------------------------------
  569.   def on_load_really_ok
  570.     @savefile_windows.each {|window| window.activate }
  571.     @load_decision.hide
  572.     @load_decision.deactivate
  573.     lctseng_for_savefile_ex_On_savefile_ok
  574.   end
  575.   #--------------------------------------------------------------------------
  576.   # ● Cancel load
  577.   #--------------------------------------------------------------------------
  578.   def on_load_really_no
  579.     @savefile_windows.each {|window| window.activate }
  580.     @load_decision.hide
  581.     @load_decision.deactivate
  582.     Sound.play_cancel
  583.   end
  584. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement