Gabz

Extreme Save-Load

Jan 24th, 2014
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.02 KB | None | 0 0
  1. #=============================================================================
  2. # * Mundo RPG Maker Extreme Save Load
  3. #---------------------------------------------------------------------------
  4. # Autor: Gab!
  5. # Data:  24/01/14
  6. #---------------------------------------------------------------------------
  7. # Créditos:
  8. #   * Tweening:
  9. #     - Robert Penner
  10. #     - UziMonkey
  11. #--------------------------------------------------------------------------
  12. # Instruções de instalação:
  13. #   - Cole abaixo do script "Extreme Menu".
  14. #=============================================================================
  15.  
  16. # Remove cenas anteriores antes de modificar
  17. [:Scene_File, :Scene_Load, :Scene_Save].each{|scene|
  18.   Object.send(:remove_const, scene)
  19. }
  20.  
  21. #==============================================================================
  22. # ** Menu_SaveFile_Window
  23. #------------------------------------------------------------------------------
  24. #  Mostra a informação de save e criação de novo jogo
  25. #==============================================================================
  26.  
  27. class SaveLoad_SaveFile_Window < Menu_SaveFile_Window
  28.   #-------------------------------------------------------------------------
  29.   # * Redesenha atores
  30.   #-------------------------------------------------------------------------
  31.   def redraw_chars
  32.     y = 86 + line_height * 7
  33.     contents.clear_rect(0, y, contents_width, contents_height - y)
  34.     if @data
  35.       space = (contents_width / @data[:characters].size)
  36.       @data[:characters].each_with_index{|data, index|
  37.         draw_character(data[0], data[1], (index + 0.5) * space, y)        
  38.       }
  39.     else
  40.       return
  41.       chars = $game_party.battle_members
  42.       space = (contents_width / chars.size)
  43.  
  44.       chars.each_with_index{|char, index|
  45.         draw_character(char.character_name, char.character_index, (index + 0.5) * space, y)
  46.       }
  47.     end
  48.   end
  49.  
  50.   #-------------------------------------------------------------------------
  51.   # * Redesenha janela
  52.   #   complete : Redesenho completo?
  53.   #-------------------------------------------------------------------------
  54.   def refresh(complete = false)
  55.     if complete
  56.       contents.clear
  57.      
  58.       if @data
  59.         contents.blt(0, line_height, @preview, @preview.rect)
  60.         @previewRect.y = 86 + 4 * line_height
  61.         draw_text(@previewRect, @data[:playtime_s], 1)
  62.       else
  63.         change_color(system_color)
  64.         draw_text(@previewRect, Vocab[:FreeSlot], 1)
  65.         change_color(normal_color)
  66.         @previewRect.y += line_height
  67.         draw_text(@previewRect, Vocab[:NewSave], 1)
  68.       end
  69.      
  70.       change_color(system_color)
  71.       @previewRect.y = 86 + 3 * line_height
  72.       draw_text(@previewRect, Vocab[:PlayTime], 1)
  73.       @previewRect.y = 86 + 6 * line_height
  74.       draw_text(@previewRect, Vocab[:Party], 1)
  75.       change_color(normal_color)
  76.     elsif !@data
  77.       @previewRect.y = 86 + 4 * line_height
  78.       contents.clear_rect(@previewRect)
  79.       draw_text(@previewRect, $game_system.playtime_s, 1)
  80.     end
  81.    
  82.     redraw_chars
  83.   end
  84. end
  85.  
  86. #==============================================================================
  87. # ** Scene_File
  88. #------------------------------------------------------------------------------
  89. #  Esta classe executa o processamento da tela de salvar e carregar.
  90. #==============================================================================
  91. class Scene_File < Scene_Base
  92.   #--------------------------------------------------------------------------
  93.   # * Inicialização do processo
  94.   #--------------------------------------------------------------------------
  95.   def start
  96.     super
  97.     @index = self.first_savefile_index
  98.    
  99.     process_move_data
  100.     create_background
  101.     create_savefile_windows
  102.     show_save_windows
  103.     init_selection
  104.   end
  105.   #-------------------------------------------------------------------------
  106.   # * Processa informação de movimento
  107.   #-------------------------------------------------------------------------
  108.   def process_move_data
  109.     [
  110.       [:SaveEnter, :@saveEnter],
  111.       [:SaveMove,  :@saveMove ],
  112.     ].each{|key, var|
  113.       data  = MRM::ExtremeMenu::Animation[key]
  114.       moveData = {
  115.         :style => Tween::EASERS[data[0]] || Tween::Linear,
  116.         :time  => data[1]
  117.       }
  118.       moveData[:off] = data[2] if data[2]
  119.       self.instance_variable_set(var, moveData)
  120.     }
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * Criação do plano de fundo
  124.   #--------------------------------------------------------------------------
  125.   def create_background
  126.     @background_sprite = Sprite.new
  127.     @background_sprite.bitmap = SceneManager.background_bitmap
  128.     @background_sprite.color.set(16, 16, 16, 128)
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Disposição do plano de fundo
  132.   #--------------------------------------------------------------------------
  133.   def dispose_background
  134.     @background_sprite.dispose
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # * Finalização do processo
  138.   #--------------------------------------------------------------------------
  139.   def terminate
  140.     super
  141.     dispose_background
  142.     @saveWindows.each(&:dispose)
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # * Atualização da tela
  146.   #--------------------------------------------------------------------------
  147.   def update
  148.     super
  149.     Tween.update
  150.     @saveWindows.each(&:update)
  151.     update_savefile_selection
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # * Criação das janelas dos arquivos salvos [+]
  155.   #--------------------------------------------------------------------------
  156.   def create_savefile_windows
  157.     @saveWindows = []
  158.     index, continue = self.createFeed
  159.     x, y, w, h   = Graphics.width, 0, Graphics.width/3, Graphics.height
  160.    
  161.     begin
  162.       @saveWindows << SaveLoad_SaveFile_Window.new(x, y, w, h, index, continue)
  163.       @saveWindows.last.contents_opacity = 0
  164.       continue = DataManager.load_header(index += 1)
  165.     end until not continue or index >= DataManager.savefile_max
  166.    
  167.     @saveWindows.shift.dispose if @saveWindows.size == DataManager.savefile_max + 1
  168.   end
  169.  
  170.   #-------------------------------------------------------------------------
  171.   # * Material para criação das janelas de save
  172.   #-------------------------------------------------------------------------
  173.   def createFeed
  174.     return [-1, false]
  175.   end
  176.  
  177.   #-------------------------------------------------------------------------
  178.   # * Mostra janelas de save
  179.   #-------------------------------------------------------------------------
  180.   def show_save_windows
  181.     baseX = (Graphics.width - @saveWindows.first.width) / 2
  182.    
  183.     @saveWindows.each_with_index{|window, index|
  184.       Tween.start(window, @saveEnter[:style], @saveEnter[:time], @saveEnter[:off] * index,
  185.         :x => baseX - ((@index - index) * window.width),
  186.         :contents_opacity => 255
  187.       )
  188.     }
  189.   end
  190.   #-------------------------------------------------------------------------
  191.   # * Move janelas de save
  192.   #-------------------------------------------------------------------------
  193.   def move_save_windows
  194.     baseX = (Graphics.width - @saveWindows.first.width) / 2
  195.    
  196.     @saveWindows.each_with_index{|window, index|
  197.       Tween.start(window, @saveMove[:style], @saveMove[:time],
  198.         :x => baseX - ((@index - index) * window.width)
  199.       )
  200.     }
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # * Inicialização da seleção
  204.   #--------------------------------------------------------------------------
  205.   def init_selection
  206.     @saveWindows[@index].active = true
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # * Atualização da seleção dos arquivos salvos
  210.   #--------------------------------------------------------------------------
  211.   def update_savefile_selection
  212.     return on_savefile_ok     if Input.trigger?(:C)
  213.     return on_savefile_cancel if Input.trigger?(:B)
  214.     update_cursor
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # * Salvando o arquivo [Confirmação]
  218.   #--------------------------------------------------------------------------
  219.   def on_savefile_ok
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # * Salvando o arquivo [Cancelamento]
  223.   #--------------------------------------------------------------------------
  224.   def on_savefile_cancel
  225.     Sound.play_cancel
  226.     return_scene
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # * Atualização do cursor
  230.   #--------------------------------------------------------------------------
  231.   def update_cursor
  232.     last_index = @index
  233.    
  234.     if    Input.repeat?(:LEFT)
  235.       @index -= 1
  236.     elsif Input.repeat?(:RIGHT)
  237.       @index += 1
  238.     end
  239.    
  240.     @index %= @saveWindows.size
  241.    
  242.     if @index != last_index
  243.       Sound.play_cursor
  244.       move_save_windows
  245.       @saveWindows[last_index].active = false
  246.       @saveWindows[@index].active     = true
  247.     end
  248.   end
  249. end
  250.  
  251. #==============================================================================
  252. # ** Scene_Load
  253. #------------------------------------------------------------------------------
  254. #  Esta classe executa o processamento da tela de carregar.
  255. #==============================================================================
  256.  
  257. class Scene_Load < Scene_File
  258.   #--------------------------------------------------------------------------
  259.   # * Aquisição do índice do primeiro arquivo selecionado
  260.   #--------------------------------------------------------------------------
  261.   def first_savefile_index
  262.     DataManager.latest_savefile_index
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # * Definição de arquivo salvo
  266.   #--------------------------------------------------------------------------
  267.   def on_savefile_ok
  268.     super
  269.     DataManager.load_game(@index) ? on_load_success : Sound.play_buzzer
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   # * Processo de carregamento aquivo bem sucedido
  273.   #--------------------------------------------------------------------------
  274.   def on_load_success
  275.     Sound.play_load
  276.     fadeout_all
  277.     $game_system.on_after_load
  278.     SceneManager.goto(Scene_Map)
  279.   end
  280.  
  281.   #-------------------------------------------------------------------------
  282.   # * Material para criação das janelas de save
  283.   #-------------------------------------------------------------------------
  284.   def createFeed
  285.     return [0, DataManager.load_header(0)]
  286.   end
  287. end
  288.  
  289. #==============================================================================
  290. # ** Scene_Save
  291. #------------------------------------------------------------------------------
  292. #  Esta classe executa o processamento da tela de salvar.
  293. #==============================================================================
  294.  
  295. class Scene_Save < Scene_File
  296.   #--------------------------------------------------------------------------
  297.   # * Aquisição do índice do primeiro arquivo selecionado
  298.   #--------------------------------------------------------------------------
  299.   def first_savefile_index
  300.     DataManager.last_savefile_index
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # * Definição de arquivo salvo
  304.   #--------------------------------------------------------------------------
  305.   def on_savefile_ok
  306.     super
  307.     i = @index.zero? ? @saveWindows.size : @index
  308.     DataManager.save_game(i - 1) ? on_save_success : Sound.play_buzzer
  309.   end
  310.   #--------------------------------------------------------------------------
  311.   # * Processo de salvar aquivo bem sucedido
  312.   #--------------------------------------------------------------------------
  313.   def on_save_success
  314.     Sound.play_save
  315.     return_scene
  316.   end
  317. end
Advertisement
Add Comment
Please, Sign In to add comment