PortalPortal  InícioInício  FAQFAQ  BuscarBuscar  Registrar-seRegistrar-se  Conectar-se  

Compartilhe|

Advanced Save/Load

Ver o tópico anterior Ver o tópico seguinte Ir em baixo
AutorMensagem
Douglanilo
avatar
Mestre
Mestre

Masculino Postagens : 959
Data de inscrição : 02/04/2009


Ver perfil do usuário http://www.twevergrand.com
MensagemAssunto: Advanced Save/Load Dom Maio 17, 2009 10:00 pm

Avanced Save/Load
Por GuiRPG


Introdução
Esse é um menu que eu retirei do Menu Horizontal e fiz mudanças para que possam usar livremente sem precisar do menu horizonal, ele tira screenshot e muito mais.
Não precisa DLL

Screenshot


Como Usar
Crie um novo script em cima de Main e cole o script.

script
Código:
#===========================================================================
# Advanced Save/Load
#---------------------------------------------------------------------------
# Por GuiRPG
# Esse script modifica o sistema de salvar e carregar
#==========================================================================

module Vocab
 
  File  = "Arq." # Aqui tá bom, mas se quise mexer...
 
  end

module GuiRPG
 
  NUMERO_MAX_DE_SAVES = 99 # Número Máximo de Saves
 
  DIR_SAVES = "Graphics/Saves/" # Diretório dos Arquivos Salvos (Recomendado deixar assim)
 
end


class Game_Temp
 attr_accessor :menu_bitmap             
 attr_accessor :sub_menu_bitmap         
 attr_accessor :save_bitmap           
 alias ini initialize
 def initialize
  ini
  @menu_bitmap = Bitmap.new(1, 1)
  @sub_menu_bitmap = Bitmap.new(1, 1)
  @save_bitmap = Bitmap.new(1, 1)
 end
end

 
 
class Window_SaveFile < Window_Base

 attr_reader  :filename               
 attr_reader  :file_exist           

 def initialize(file_index, filename)
  super(176, 59, 304, 298)
  @file_index = file_index
  @filename = filename
  load_gamedata
  refresh(@file_index)
 end

 def load_gamedata
  @file_exist = FileTest.exist?(GuiRPG::DIR_SAVES + @filename)
  if @file_exist
    file = File.open(GuiRPG::DIR_SAVES + @filename, "r")
    begin
      @characters    = Marshal.load(file)
      @frame_count    = Marshal.load(file)
      @last_bgm      = Marshal.load(file)
      @last_bgs      = Marshal.load(file)
      @game_system    = Marshal.load(file)
      @game_message  = Marshal.load(file)
      @game_switches  = Marshal.load(file)
      @game_variables = Marshal.load(file)
      @total_sec = @frame_count / Graphics.frame_rate
    rescue
      @file_exist = false
    ensure
      file.close
    end
  end
 end

 
 def refresh(index)
  file_index = index
  self.contents.clear
  self.contents.font.color = normal_color
  if @file_exist
    self.contents.fill_rect(0, 0, 272,208+2, Color.new(0,0,64))
    if FileTest.exist?(GuiRPG::DIR_SAVES + @filename.split(/\./)[0] + ".png")
      self.contents.blur
      draw_save_bitmap(0,0)
    else
      self.contents.draw_text(0, 64, 304-32, 24, "inválido", 1)
    end
    draw_party_characters(108, 288-56)
    draw_playtime(0, 288+8-56, contents.width-4, 2)
  else
    self.contents.draw_text(0, 288-56, contents.width-4, 24, "Nenhum Arquivo Salvo", 1)
  end
 end

 
 def file_index=(file_index)
  @file_index = file_index
 end

def draw_party_characters(x, y)
  for i in
    name = @characters[i][0]
    index = @characters[i][1]
    draw_character(name, index, x + i * 48, y)
  end
 end

def draw_save_bitmap(x, y)
  bitmap = Bitmap.new(GuiRPG::DIR_SAVES + @filename.split(/\./)[0] + ".png")
  rect = Rect.new(0, 0, 0, 0)
  rect.width = bitmap.width
  rect.height = bitmap.height
  self.contents.blt(x, y, bitmap, rect)
  bitmap.dispose
 end


 
 def draw_playtime(x, y, width, align)
  hour = @total_sec / 60 / 60
  min = @total_sec / 60 % 60
  sec = @total_sec % 60
  time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  self.contents.font.color = normal_color
  self.contents.draw_text(x, y, width, WLH, time_string, 2)
 end
end

class Window_Menu_Command < Window_Selectable

 attr_reader  :commands             


 def initialize(width, commands, column_max = 16, row_max = 0, spacing = 8)
  if row_max == 0
    row_max = (commands.size + column_max - 1) / column_max
  end
  super(0, 416-54, width, row_max * WLH + 32, spacing)
  @commands = commands
  @item_max = commands.size
  @column_max = column_max
  self.index = 0
 end

 def refresh
  self.contents.clear
  for i in 0...@item_max
    draw_item(i)
  end
 end

def draw_item(index, enabled = true)
  rect = item_rect(index)
  rect.width -= 8
  self.contents.clear_rect(rect)
  self.contents.font.color = normal_color
  self.contents.font.color.alpha = enabled ? 255 : 128
 end

 def update_help
  text = $data_system.game_title
  if @commands[self.index] != nil
    text += ": " + @commands[self.index]
  end
  @help_window.set_text(text)
 end
end

class Scene_Base

 def create_menu_background
  @menuback_sprite = Sprite.new
  @menuback_sprite.bitmap = $game_temp.background_bitmap
  update_menu_background
 end

 def create_sub_menu_background
  @menuback_sprite = Sprite.new
  @menuback_sprite.bitmap = $game_temp.sub_menu_bitmap
  update_menu_background
 end

 def snapshot_for_save
  d_rect = Rect.new(0, 0, 272, 208)
  s_rect = Rect.new(0, 0, 544, 416)
  save_bitmap = Graphics.snap_to_bitmap
  $game_temp.save_bitmap.dispose
  $game_temp.save_bitmap = Bitmap.new(272, 208)
  $game_temp.save_bitmap.stretch_blt(d_rect, save_bitmap, s_rect)
 end
end

class Scene_Map < Scene_Base

 def terminate
  super
  snapshot_for_save               
  if $scene.is_a?(Scene_Battle)   
    @spriteset.dispose_characters 
  end
  snapshot_for_background         
  snapshot_for_menu               
  @spriteset.dispose
  @message_window.dispose
  if $scene.is_a?(Scene_Battle)   
    perform_battle_transition     
  end
 end

 def snapshot_for_menu
  $game_temp.menu_bitmap.dispose
  $game_temp.menu_bitmap = Graphics.snap_to_bitmap
 end

 def call_menu
  if $game_temp.menu_beep
    Sound.play_decision
    $game_temp.menu_beep = false
  end
  $game_temp.next_scene = nil
  $scene = Scene_Menu.new
 end
end

class Scene_Title < Scene_Base

 def check_continue
  @continue_enabled = (Dir.glob(GuiRPG::DIR_SAVES + 'Save*.rvdata').size > 0)
 end
end

class Scene_Status < Scene_Base

 def start
  super
  create_sub_menu_background
  @actor = $game_party.members[@actor_index]
  @status_window = Window_Status.new(@actor)
  @status_window.openness = 0
 end

 def post_start
  super
  open_status_window
 end

 def pre_terminate
  super
  close_status_window
 end

 def open_status_window
  @status_window.open
  begin
    @status_window.update
    Graphics.update
  end until @status_window.openness == 255
 end

 def close_status_window
  @status_window.close
  begin
    @status_window.update
    Graphics.update
  end until @status_window.openness == 0
 end
end

class Scene_File < Scene_Base


 def initialize(saving, from_title, from_event)
  @saving = saving
  @from_title = from_title
  @from_event = from_event
 end

 def start
  super
  @help_window = Window_Help.new
  unless $game_temp.sub_menu_bitmap.width == 1
    @help_window.opacity = 0
    create_sub_menu_background
  else
    create_title_graphic
  end
  create_command_window
  if @saving
    @index = $game_temp.last_file_index
    @help_window.set_text(Vocab::SaveMessage)
  else
    @index = self.latest_file_index
    @help_window.set_text(Vocab::LoadMessage)
  end
  @refresh_index = @command_window.index = @index
  @item_max = GuiRPG::NUMERO_MAX_DE_SAVES
  create_savefile_window
  @savefile_window.openness = 0
 end

 def terminate
  super
  dispose_menu_background
  @help_window.dispose
  dispose_item_windows
 end

 def return_scene
  if @from_title
    $scene = Scene_Title.new
  elsif @from_event
    $scene = Scene_Map.new
  else
    $scene = Scene_Menu.new(4)
  end
 end

 def update
  super
  update_menu_background
  @help_window.update
  update_savefile_windows
  update_savefile_selection
 end

 def post_start
  super
  open_savefile_window
 end

 def pre_terminate
  super
  close_savefile_window
 end

 def create_title_graphic
  @menuback_sprite = Sprite.new
  @menuback_sprite.bitmap = Cache.system("Title")
 end

 def create_command_window
  file_names = []
  for i in 0...GuiRPG::NUMERO_MAX_DE_SAVES
    id = sprintf("%02d", i+1)
    file_names.push(Vocab::File + "\s" + id)
  end
  @command_window = Window_Command.new(112, file_names)
  @command_window.height = 298
  @command_window.x = 64
  @command_window.y = 59
  @command_window.openness = 0
 end

 def create_savefile_window
  @savefile_window = Window_SaveFile.new(@command_window.index, make_filename(@command_window.index))
 end

 def dispose_item_windows
  @command_window.dispose
  @savefile_window.dispose
 end

 def open_savefile_window
  @command_window.open
  @savefile_window.open
  begin
    @command_window.update
    @savefile_window.update
    Graphics.update
  end until @savefile_window.openness == 255
 end

 def close_savefile_window
  @command_window.close
  @savefile_window.close
  begin
    @command_window.update
    @savefile_window.update
    Graphics.update
  end until @savefile_window.openness == 0
 end

 def update_savefile_windows
  @command_window.update
  @savefile_window.update
 end

 def update_savefile_selection
  if Input.trigger?(Input::C)
    determine_savefile
  end
  if Input.trigger?(Input::B)
    Sound.play_cancel
    return_scene
  end
  if @refresh_index != @command_window.index
    @refresh_index = @command_window.index
    @savefile_window.dispose
    create_savefile_window
    end
 end

 def determine_savefile
  if @saving
    Sound.play_save
    do_save
  else
    if @savefile_window.file_exist
      Sound.play_load
      do_load
    else
      Sound.play_buzzer
      return
    end
  end
  $game_temp.last_file_index = @index
 end

 
 def make_filename(file_index)
  return "Save#{file_index + 1}.rvdata"
 end

 def latest_file_index
  index = 0
  latest_time = Time.at(0)
  for i in 0...GuiRPG::NUMERO_MAX_DE_SAVES
    file_name = make_filename(i)
    if FileTest.exist?(GuiRPG::DIR_SAVES + file_name)
      file = File.open(GuiRPG::DIR_SAVES + file_name, "r")
      if file.mtime > latest_time
        latest_time = file.mtime
        index = i
      end
    end
  end
  return index
 end

 def do_save
  file_name = make_filename(@command_window.index)
  $game_temp.save_bitmap.make_png(file_name.split(/\./)[0], GuiRPG::DIR_SAVES)
  file = File.open(GuiRPG::DIR_SAVES + file_name, "wb")
  write_save_data(file)
  file.close
  return_scene
 end

 def do_load
  file_name = make_filename(@command_window.index)
  file = File.open(GuiRPG::DIR_SAVES + file_name, "rb")
  read_save_data(file)
  file.close
  $scene = Scene_Map.new
  RPG::BGM.fade(1500)
  Graphics.fadeout(60)
  Graphics.wait(40)
  @last_bgm.play
  @last_bgs.play
 end
end

module Zlib
 class Png_File < GzipWriter

  def make_png(bitmap_Fx)
    @bitmap_Fx = bitmap_Fx
    self.write(make_header)
    self.write(make_ihdr)
    self.write(make_idat)
    self.write(make_iend)
  end
 
 
 
  def make_header
    return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*")
  end
 
 
 
  def make_ihdr
    ih_size = [13].pack("N")
    ih_sign = "IHDR"
    ih_width = [@bitmap_Fx.width].pack("N")
    ih_height = [@bitmap_Fx.height].pack("N")
    ih_bit_depth = [8].pack("C")
    ih_color_type = [6].pack("C")
    ih_compression_method = [0].pack("C")
    ih_filter_method = [0].pack("C")
    ih_interlace_method = [0].pack("C")
    string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
              ih_compression_method + ih_filter_method + ih_interlace_method
    ih_crc = [Zlib.crc32(string)].pack("N")
    return ih_size + string + ih_crc
  end
 
 
 
  def make_idat
    header = "\x49\x44\x41\x54"
    data = make_bitmap_data
    data = Zlib::Deflate.deflate(data, 8)
    crc = [Zlib.crc32(header + data)].pack("N")
    size = [data.length].pack("N")
    return size + header + data + crc
  end
 
 
 
  def make_bitmap_data
    gz = Zlib::GzipWriter.open('hoge.gz')
    t_Fx = 0
    w = @bitmap_Fx.width
    h = @bitmap_Fx.height
    data = []
    for y in 0...h
      data.push(0)
      for x in 0...w
        t_Fx += 1
        if t_Fx % 10000 == 0
          Graphics.update
        end
        if t_Fx % 100000 == 0
          s = data.pack("C*")
          gz.write(s)
          data.clear
        end
        color = @bitmap_Fx.get_pixel(x, y)
        red = color.red
        green = color.green
        blue = color.blue
        alpha = color.alpha
        data.push(red)
        data.push(green)
        data.push(blue)
        data.push(alpha)
      end
    end
    s = data.pack("C*")
    gz.write(s)
    gz.close   
    data.clear
    gz = Zlib::GzipReader.open('hoge.gz')
    data = gz.read
    gz.close
    File.delete('hoge.gz')
    return data
  end
 
 
 
  def make_iend
    ie_size = [0].pack("N")
    ie_sign = "IEND"
    ie_crc = [Zlib.crc32(ie_sign)].pack("N")
    return ie_size + ie_sign + ie_crc
  end
 end
end
class Bitmap

 def make_png(name="Gui_Img_Save", path="",mode=0)
  make_dir(path) if path != ""
  Zlib::Png_File.open("temp.gz") {|gz|
    gz.make_png(self)
  }
  Zlib::GzipReader.open("temp.gz") {|gz|
    $read = gz.read
  }
  f = File.open(path + name + ".png","wb")
  f.write($read)
  f.close
  File.delete('temp.gz')
  end

 def make_dir(path)
  dir = path.split("/")
  for i in 0...dir.size
    unless dir == "."
      add_dir = dir[0..i].join("/")
      begin
        Dir.mkdir(add_dir)
      rescue
      end
    end
  end
 end
end

Créditos:
GuiRPG - Por criar o script
Douglanilo - Por postar na Ever Grand


Última edição por Douglanilo em Ter Out 13, 2009 4:27 pm, editado 1 vez(es)
Voltar ao Topo Ir em baixo
zero
avatar
Membro Especial
Membro Especial

Postagens : 301
Data de inscrição : 14/05/2009


Ver perfil do usuário http://animechaos.forumeiros.com/
MensagemAssunto: Re: Advanced Save/Load Ter Out 13, 2009 3:21 pm

Ao que parece o topico foi editado na RMB mas vc falou das imagems tem esta do propio topico:

http://img390.imageshack.us/img390/3273/screenshotsuperscripthz0.png
Voltar ao Topo Ir em baixo
Douglanilo
avatar
Mestre
Mestre

Masculino Postagens : 959
Data de inscrição : 02/04/2009


Ver perfil do usuário http://www.twevergrand.com
MensagemAssunto: Re: Advanced Save/Load Ter Out 13, 2009 4:28 pm

Valeu zero.

Screenshot colocada.

Até o/

_________________________________________
Voltar ao Topo Ir em baixo
Conteúdo patrocinado




MensagemAssunto: Re: Advanced Save/Load

Voltar ao Topo Ir em baixo

Advanced Save/Load

Ver o tópico anterior Ver o tópico seguinte Voltar ao Topo
Página 1 de 1

Permissão deste fórum:Você não pode responder aos tópicos neste fórum
The World of EverGrand :: Programação em Linguagens :: Ruby Game Scripting System :: Scripts :: RPG Maker VX-