[XPA] How can I show a preview of a map?

Started by SolarisSpell, March 23, 2021, 10:08:25 am

Previous topic - Next topic

SolarisSpell

Hi

I'd like to ask how can you show a preview of a map with RPG Maker XPA

I have two scripts that do this. One is a save system that, when selecting which file to load, shows where you were when you saved your game. The other one, is a teleport script that allows you to select where do you want to teleport and shows in a window the map you are selecting.

But after upgrading to XP Ace, both scripts still works, but shows nothing. Where the preview of the map used to be, now is just nothing.

I wanted to ask which code should I use to show the preview of a different map, so I can implement it in these scripts again.

Thanks

KK20

Please mention what these scripts are as I cannot help you without looking at the code itself.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

SolarisSpell

Thanks

I was asking in case it was something simple and maybe I could be able to insert it by myself

This is the script:
#Save System

class Window_File < Window_Selectable

  #------------------------
  # ● initialize
  #--------------------------------------------------------------------------
  def initialize()
    super(0, 64, 320, 416)
    self.contents = Bitmap.new(width - 32, 99 * 32)
#    self.contents.font.name = $fontface
#    self.contents.font.size = $fontsize
    index = $game_temp.last_file_index == nil ? 0 : $game_temp.last_file_index
    self.index = index
    @item_max = 99
    refresh
  end
 
  #--------------------------------------------------------------------------
  # ● refresh the window
  #--------------------------------------------------------------------------
  def refresh
    time_stamp = Time.at(0)
    for i in 0...99
      filename = "Save#{i + 1}.rxdata"
      self.contents.draw_text(1, i * 32, 32, 32, " "+(i + 1).to_s, 1)
      if FileTest.exist?(filename)
        file = File.open(filename, "rb")
        read_save_data(file)
        file.close
        case (@game_variables[14]) #Naming the chapter of the game
        when 0
          @texto = "Chapter 1"
        when 1
          @texto = "Chapter 2"
      #and so on...
      end
     
      # Draw the name with other color when playing in higher difficulty
      self.contents.font.color = arriba_color if @game_switches[150]
      self.contents.draw_text(1, i * 32, 32, 32, " "+(i + 1).to_s, 1) if @game_switches[150]
      self.contents.draw_text(30, i * 32, 284, 32, " "+@texto.to_s)
      self.contents.font.color = normal_color
     
      end
    end
  end
 
  def read_save_data(file)
    characters = Marshal.load(file)
    frame_count = Marshal.load(file)
    @game_system = Marshal.load(file)
    @game_switches = Marshal.load(file)
    @game_variables = Marshal.load(file)
    @game_self_switches = Marshal.load(file)
    @game_screen = Marshal.load(file)
    @game_actors = Marshal.load(file)
    @game_party = Marshal.load(file)
    @game_troop = Marshal.load(file)
    @game_map = Marshal.load(file)
    @game_player = Marshal.load(file)
  end
end

#==============================================================================
# ■ Window_FileStatus
#------------------------------------------------------------------------------
#  This window shows the status of the currently selected save file
#==============================================================================

class Window_FileStatus < Window_Base

  #--------------------------------------------------------------------------
  # ● initialize
  #--------------------------------------------------------------------------
  def initialize(save_window)
    super(320, 64, 320, 416)
    self.contents = Bitmap.new(width - 32, height - 32)
#    self.contents.font.name = $fontface
#    self.contents.font.size = $fontsize
    @save_window = save_window
    @index = @save_window.index
    rect = Rect.new(x + 16, y + (height - 32) / 2 + 16, width - 32, (height - 32) / 2)
    @viewport = Viewport.new(rect)
    @viewport.z = z + 10
    refresh
  end
 
  #--------------------------------------------------------------------------
  # ● dispose the map and the window
  #--------------------------------------------------------------------------
  def dispose
    tilemap_dispose
    @viewport.dispose
    super
  end
 
  #--------------------------------------------------------------------------
  # ● refresh the window
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    tilemap_dispose
    filename = "Save#{@index + 1}.rxdata"
    return unless FileTest.exist?(filename)
    file = File.open(filename, "r")
    Marshal.load(file)
    frame_count = Marshal.load(file)
    for i in 0...6
      Marshal.load(file)
    end
    party = Marshal.load(file)
    Marshal.load(file)
    map = Marshal.load(file)
    for i in 0...party.actors.size
      actor = party.actors[i]
      x = i % 2 * 144 + 4
      y = i / 2 * 64
      draw_actor_name(actor, x + 50, y)
      draw_actor_level(actor, x + 50, y + 24)
      draw_actor_graphic(actor, x + 10, y + 55)

      bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
      cw = bitmap.width / 4
      ch = bitmap.height / 4
      src_rect = Rect.new(0, 0, cw, ch)
      self.contents.blt((x+10) - cw / 2, (y+55) - ch, bitmap, src_rect)
      #self.contents.blt(x,y+5, bitmap, src_rect)
    end
    total_sec = frame_count / Graphics.frame_rate
    hour = total_sec / 60 / 60
    min = total_sec / 60 % 60
    sec = total_sec % 60
    text = sprintf("%02d:%02d:%02d", hour, min, sec)
    map_name = load_data("Data/MapInfos.rxdata")[map.map_id].name
    self.contents.font.color = system_color
    self.contents.draw_text(4, 128, 150, 32, "Played time:")
    self.contents.draw_text(4, 160, 50, 32, "Area:")
    self.contents.font.color = normal_color
    self.contents.draw_text(155, 128, 140, 32, " "+text)
    self.contents.draw_text(60, 160, 230, 32, map_name)
    @tilemap = Tilemap.new(@viewport)
    @tilemap.tileset = RPG::Cache.tileset(map.tileset_name)
    for i in 0..6
      autotile_name = map.autotile_names[i]
      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
    end
    @tilemap.map_data = map.data
    @tilemap.ox = map.display_x / 4 + 176
    @tilemap.oy = map.display_y / 4 + 148
  end
 
  #--------------------------------------------------------------------------
  # ● tilemap_dispose
  #--------------------------------------------------------------------------
  def tilemap_dispose
    unless @tilemap == nil
      @tilemap.tileset.dispose
      for i in 0..6
        @tilemap.autotiles[i].dispose
      end
      @tilemap.dispose
      @tilemap = nil
    end
  end
 
  #--------------------------------------------------------------------------
  # ● update
  #--------------------------------------------------------------------------
  def update
    @tilemap.update if @tilemap != nil
    if @index != @save_window.index
      @index = @save_window.index
      refresh
    end
    super
  end
end

#==============================================================================
# ■ Scene_File
#------------------------------------------------------------------------------
#  Base scene for load and save menus.
#==============================================================================

class Scene_File

  #--------------------------------------------------------------------------
  # ● initialize the scene
  #--------------------------------------------------------------------------
  def initialize(help_text)
    @help_text = help_text
  end
 
  #--------------------------------------------------------------------------
  # ● main
  #--------------------------------------------------------------------------
  def main
    @pic = Sprite.new
    #if $game_variables[98] == nil
    #@pic.bitmap = Bitmap.new("Graphics/Pictures/Menú.jpg")
    #else
    # 
    #case ($game_variables[98])
    #when 0
    #  @pic.bitmap = Bitmap.new("Graphics/Pictures/Menú.jpg")
    #when 1
    #  @pic.bitmap = Bitmap.new("Graphics/Pictures/LidantorFondo.jpg")
    #end
    #
    #end
    @help_window = Window_Help.new
    @help_window.back_opacity = 160
    @help_window.set_text(@help_text, 1)
    @file_window = Window_File.new
    @file_window.back_opacity = 160
    @status_window = Window_FileStatus.new(@file_window)
    @status_window.back_opacity = 160
    @com = Window_Command.new(96, [" Yes", " No"])
    @com.back_opacity = 160
    @com.index = 1
    @com.x = 272
    @com.y = 192
    @com.z = 1000
    @com.visible = false
    @com.active = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose
    @file_window.dispose
    @status_window.dispose
  end
 
  #--------------------------------------------------------------------------
  # ● update
  #--------------------------------------------------------------------------
  def update
    @help_window.update
    @file_window.update
    @status_window.update
    @com.update
    if @com.visible
       @help_window.set_text("Overwrite?",1)
       update_com
       return
    end
    if Input.trigger?(Input::C)
      decision
      $game_temp.last_file_index = @file_index
      return
    end
    if Input.trigger?(Input::B)
      cancel
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● return the selected file's name
  #--------------------------------------------------------------------------
  def filename
    return "Save#{@file_window.index + 1}.rxdata"
  end

  def update_com
   if Input.trigger?(Input::C)
     $game_system.se_play($data_system.decision_se)
     case @com.index
     when 0
       write_save_data
       @com.active = false
       @com.visible = false
       @file_window.active = true
       @help_window.set_text("Choose where to save",1)
     when 1
       @com.active = false
       @com.visible = false
       @file_window.active = true
       @help_window.set_text("Choose where to save",1)
     end
   end
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     @com.active = false
     @com.visible = false
     @file_window.active = true
     @help_window.set_text("Choose where to save",1)
   end
 end

end

#==============================================================================
# ■ Scene_Save
#------------------------------------------------------------------------------
#  Save menu
#==============================================================================

class Scene_Save < Scene_File
 
  #--------------------------------------------------------------------------
  # ● initialize the save menu
  #--------------------------------------------------------------------------
  def initialize
    super("Choose where to save")
  end
  #--------------------------------------------------------------------------
  # ● decision key pressed
  #--------------------------------------------------------------------------
  def decision
    $game_system.se_play($data_system.decision_se)
    #file = File.open(filename, "wb")
    #write_save_data(file)
    #file.close
    check
  end
 
  #--------------------------------------------------------------------------
  # ● cancel key pressed
  #--------------------------------------------------------------------------
  def cancel
    $game_system.se_play($data_system.cancel_se)
    if $game_temp.save_calling
      $game_temp.save_calling = false
      if $game_system.on_map == true #WorldMap
        $game_system.map_coords = [$game_variables[226], $game_variables[227]]
        $scene = Scene_World_Map.new
        return
      else
        $scene = Scene_Map.new
        return
      end
    end
    $scene = Scene_Menu.new(1)
  end

  #--------------------------------------------------------------------------
  # ● save the current data into the selected file
  #--------------------------------------------------------------------------
  def write_save_data
    $game_system.se_play($data_system.save_se)
    file = File.open(filename, "wb")
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      characters.push([actor.character_name, actor.character_hue])
    end
    Marshal.dump(characters, file)
    Marshal.dump(Graphics.frame_count, file)
    $game_system.save_count += 1
    $game_system.magic_number = $data_system.magic_number
    Marshal.dump($game_system, file)
    Marshal.dump($game_switches, file)
    Marshal.dump($game_variables, file)
    Marshal.dump($game_self_switches, file)
    Marshal.dump($game_screen, file)
    Marshal.dump($game_actors, file)
    Marshal.dump($game_party, file)
    Marshal.dump($game_troop, file)
    Marshal.dump($game_map, file)
    Marshal.dump($game_player, file)
    file.close
    if $game_temp.save_calling
      $game_temp.save_calling = false
      if $game_system.on_map == true #WorldMap
        $game_system.map_coords = [$game_variables[226], $game_variables[227]]
        $scene = Scene_World_Map.new
        return
      else
        $scene = Scene_Map.new
        return
      end
    end
    $scene = Scene_Menu.new(1)
  end
 
  def check
    if FileTest.exist? ("Save#{@file_window.index + 1}.rxdata")
      @com.visible = true
      @com.active = true
      @file_window.active = false
    else
      write_save_data
    end
  end
end

#==============================================================================
# ■ Scene_Load
#------------------------------------------------------------------------------
#  Load menu
#==============================================================================

class Scene_Load < Scene_File
 
  #--------------------------------------------------------------------------
  # ● initialize the menu
  #--------------------------------------------------------------------------
  def initialize
  @pic = Sprite.new

  #if $game_variables[98] == nil
  #@pic.bitmap = Bitmap.new("Graphics/Pictures/Menú.jpg")
  #else
  # 
  #case ($game_variables[98])
  #when 0
  #  @pic.bitmap = Bitmap.new("Graphics/Pictures/Menú.jpg")
  #when 1
  #  @pic.bitmap = Bitmap.new("Graphics/Pictures/LidantorFondo.jpg")
  #else
  #  @pic.bitmap = Bitmap.new("Graphics/Pictures/Menú.jpg")
  #end
  #
  #end
 
  $game_temp = Game_Temp.new
  $game_temp.last_file_index = 0
  latest_time = Time.at(0)
  for i in 0..99
    filename = "Save#{i + 1}.rxdata"
    if FileTest.exist?(filename)
      file = File.open(filename, "r")
      if file.mtime > latest_time
        latest_time = file.mtime
        $game_temp.last_file_index = i
      end
      file.close
    end
  end
  super("Choose file to load")
end

  #--------------------------------------------------------------------------
  # ● decision key pressed
  #--------------------------------------------------------------------------
  def decision
    unless FileTest.exist?(filename)
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    $game_system.se_play($data_system.load_se)
    file = File.open(filename, "rb")
    read_save_data(file)
    file.close
    $game_system.bgm_play($game_system.playing_bgm)
    $game_system.bgs_play($game_system.playing_bgs)
    $game_map.update
    $scene = Scene_Map.new
  end

  #--------------------------------------------------------------------------
  # ● cancel key pressed
  #--------------------------------------------------------------------------
  def cancel
    $game_system.se_play($data_system.cancel_se)
    $scene = Scene_Title.new
  end
  #--------------------------------------------------------------------------
  # ● load the selected file
  #--------------------------------------------------------------------------
  def read_save_data(file)
    characters = Marshal.load(file)
    Graphics.frame_count = Marshal.load(file)
    $game_system = Marshal.load(file)
    $game_switches = Marshal.load(file)
    $game_variables = Marshal.load(file)
    $game_self_switches = Marshal.load(file)
    $game_screen = Marshal.load(file)
    $game_actors = Marshal.load(file)
    $game_party = Marshal.load(file)
    $game_troop = Marshal.load(file)
    $game_map = Marshal.load(file)
    $game_player = Marshal.load(file)
    if $game_system.magic_number != $data_system.magic_number
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    $game_party.refresh
  end
end

I have prepared a demo to show it:
Save System Demo


In normal RPG Maker XP, it shows where you saved with a little preview:
Spoiler: ShowHide


But, in my project, after updating to XPA, it doesn't show that map preview:
Spoiler: ShowHide



I wanted to know if it is possible to make it work again or if this isn't possible with XPA

Thanks

KK20

My Tilemap rewrite handles a bit differently than vanilla's, so a couple tweaks are needed.

First, locate this section of the script and add the following line I mark:
    @tilemap.map_data = map.data
    @tilemap.priorities = map.priorities # <<<<<<<<<<<<<<<<<<<<< THIS ONE HERE
    @tilemap.ox = map.display_x / 4 + 176
    @tilemap.oy = map.display_y / 4 + 148
And in the update method further below, you need to change it to draw
@tilemap.draw if @tilemap != nil

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

SolarisSpell

It works perfectly, thanks a lot

Of all the problems I encountered after updating to XPA, this one was defeating me.
For all other it seems I have found a work around