Advertisement
Guest User

cRmGSS - Scene File Confirmation

a guest
Jan 9th, 2012
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.86 KB | None | 0 0
  1. #==============================================================================
  2. # ** SceneFile_Confirmation
  3. #------------------------------------------------------------------------------
  4. # Author: JohnBolton
  5. # www.centrorpgmaker.com
  6. #==============================================================================
  7. # Adds a confirnation window on Scene_File, whose options are:
  8. #
  9. # - Save/Load/Rewrite
  10. # - Delete
  11. # - Cancel
  12. #
  13. #==============================================================================
  14.  
  15. module Bolton92
  16.   module Save_load_delete_confirmation
  17.     Options = {
  18.    
  19.   #--------------------------------------------------------------------------
  20.   # * Settings
  21.   #--------------------------------------------------------------------------
  22.    
  23.     "Option1_tosave" => "Save",
  24.    
  25.     "Option1_torewrite" => "Rewrite",
  26.  
  27.     "Option1_toload" => "Load",
  28.    
  29.     "Option2" => "Delete",
  30.    
  31.     "Option3" => "Cancel"
  32.    
  33.     }
  34.    
  35.     Width_Window = 160
  36.    
  37.   end
  38. end
  39.  
  40. #----------------------------------------------------------------------------
  41. # ** Game_System
  42. #----------------------------------------------------------------------------
  43. #============================================================================
  44.  
  45. class Game_System
  46.   #--------------------------------------------------------------------------
  47.   # * Instance Variables‎
  48.   #--------------------------------------------------------------------------
  49.   attr_accessor :delete_enabled
  50.   attr_accessor :index_save_confirmation
  51.   #--------------------------------------------------------------------------
  52.   # * Modification of the initialize method
  53.   #--------------------------------------------------------------------------
  54.   alias bolton92_system_initialize initialize
  55.   def initialize
  56.     bolton92_system_initialize
  57.     @delete_enabled = 1
  58.     @index_save_confirmation = 1
  59.   end
  60. end
  61.  
  62. #----------------------------------------------------------------------------
  63. # ** Window_Confirmation
  64. #----------------------------------------------------------------------------
  65. #============================================================================
  66.  
  67. class Window_Confirmation < Window_Command
  68.   include Bolton92::Save_load_delete_confirmation
  69.   #--------------------------------------------------------------------------
  70.   # * Starting the process
  71.   #--------------------------------------------------------------------------
  72.   def initialize
  73.     super(0, 0)
  74.     update_placement
  75.     self.openness = 0
  76.     open
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # * Acquisition of the window width
  80.   #--------------------------------------------------------------------------
  81.   def window_width
  82.     return Width_Window
  83.   end
  84.   #--------------------------------------------------------------------------
  85.   #     x : coordinate X
  86.   #     y : coordinate Y
  87.   #--------------------------------------------------------------------------
  88.   def update_placement
  89.     self.x = (Graphics.width - width) / 2
  90.     self.y = (Graphics.height - height) / 2
  91.   end
  92.   #--------------------------------------------------------------------------
  93.   # * Creating the list of commands
  94.   #--------------------------------------------------------------------------
  95.   def make_command_list
  96.     if $game_system.delete_enabled and $game_system.index_save_confirmation
  97.       add_command(Options["Option1_torewrite"], :confirm)
  98.     elsif $game_system.delete_enabled == false and $game_system.index_save_confirmation
  99.       add_command(Options["Option1_tosave"], :confirm)
  100.     elsif $game_system.index_save_confirmation == false
  101.       add_command(Options["Option1_toload"], :confirm, $game_system.delete_enabled)
  102.     end
  103.     add_command(Options["Option2"], :delete, $game_system.delete_enabled)    
  104.     add_command(Options["Option3"], :cancel)
  105.   end
  106. end
  107.  
  108. #==============================================================================
  109. # ** Scene_File
  110. #------------------------------------------------------------------------------
  111. #==============================================================================
  112.  
  113. class Scene_File
  114.   #--------------------------------------------------------------------------
  115.   # * Modification of the start method
  116.   #--------------------------------------------------------------------------
  117.   alias bolton92_start start
  118.   def start
  119.     bolton92_start
  120.     create_window_confirmation
  121.     check_scene
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # * Check Scene
  125.   #--------------------------------------------------------------------------
  126.   def check_scene
  127.     if self.to_s.include?("Scene_Load")
  128.       $game_system.index_save_confirmation = false
  129.     else
  130.       $game_system.index_save_confirmation = true
  131.     end
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # * Modification of the update method
  135.   #--------------------------------------------------------------------------
  136.   alias bolton92_update update
  137.   def update    
  138.     check_delete
  139.     bolton92_update
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   # * Check delete
  143.   #--------------------------------------------------------------------------
  144.   def check_delete
  145.     index = sprintf("Save%02d.rvdata2", @index + 1)
  146.     if File.exist?(index.to_s)
  147.       $game_system.delete_enabled = true
  148.     else
  149.       $game_system.delete_enabled = false
  150.     end
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # * Update the selection of the selected files
  154.   #--------------------------------------------------------------------------
  155.   def update_savefile_selection
  156.     unless @window_confirmation.active
  157.       if Input.trigger?(:C)
  158.         active_window_confirmation
  159.       elsif Input.trigger?(:B)
  160.         Sound.play_cancel
  161.         return_scene
  162.       end
  163.       return update_cursor  
  164.     end
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # * Declaration of Window_Confirmation
  168.   #--------------------------------------------------------------------------
  169.   def create_window_confirmation
  170.     @window_confirmation = Window_Confirmation.new
  171.     @window_confirmation.set_handler(:confirm, method(:on_savefile_ok))
  172.     @window_confirmation.set_handler(:delete, method(:delete))
  173.     @window_confirmation.set_handler(:cancel, method(:on_savefile_cancel))
  174.     restore_savefile_window
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * Cancel
  178.   #--------------------------------------------------------------------------
  179.   def on_savefile_cancel
  180.     restore_savefile_window
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # * Delete
  184.   #--------------------------------------------------------------------------
  185.   def delete
  186.     if DataManager.delete_save_file(@index)
  187.       restore_savefile_window
  188.     end
  189.   end
  190.   #--------------------------------------------------------------------------
  191.   # * Activation of Window_Confirmation
  192.   #--------------------------------------------------------------------------
  193.   def active_window_confirmation
  194.     Sound.play_ok
  195.     create_window_confirmation
  196.     @window_confirmation.active = true
  197.     @window_confirmation.visible = true
  198.     @window_confirmation.select_symbol(:confirm)
  199.     @savefile_windows[@index].active = false
  200.     @window_confirmation.refresh
  201.   end  
  202.   #--------------------------------------------------------------------------
  203.   # * Activation of the file list
  204.   #--------------------------------------------------------------------------
  205.   def restore_savefile_window
  206.     @window_confirmation.active = false
  207.     @window_confirmation.visible = false
  208.     @savefile_windows[@index].active = true
  209.     @savefile_windows[@index].refresh
  210.   end
  211. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement