Main Menu
  • Welcome to The RPG Maker Resource Kit.

Portraits in save menu?

Started by AgentArsonist, May 24, 2009, 11:10:47 AM

0 Members and 1 Guest are viewing this topic.

AgentArsonist

Hello again!
I've been trying to figure this out by looking up instances where faces are drawn in other menus and trying to duplicate it.. but so far no go.
All I want to is to show the actors portrait (or a smaller version thereof) on the save file screen. Will probably have to move it around until I find just the right spot for it.. using x,y chords.. but honestly I have no idea of how to do this at all.

I searched on here and on another rmvx/xp site but no luck yet.

Can anyone help me out with this? Sorry for the newbishness, but I am learning slowly

Thanks

modern algebra

Look at:
  #--------------------------------------------------------------------------
  # * Draw Party Characters
  #     x : Draw spot X coordinate
  #     y : Draw spot Y coordinate
  #--------------------------------------------------------------------------
  def draw_party_characters(x, y)
    for i in 0...@characters.size
      name = @characters[i][0]
      index = @characters[i][1]
      draw_character(name, index, x + i * 48, y)
    end
  end


You'll need to do something similar. Except, instead of draw_character, you'll want to draw_face (name, index, x, y)

More importantly, however, you need to retrieve the actor data from the save file. What I would do is I would add that data to the @characters array when you save a file. Those lines are in Scene_File

  def write_save_data(file)
    characters = []
    for actor in $game_party.members
      characters.push([actor.character_name, actor.character_index])
    end


Change it to:


  def write_save_data(file)
    characters = []
    for actor in $game_party.members
      characters.push([actor.character_name, actor.character_index, actor.face_name, actor.face_index])
    end


Then this code would work for drawing faces back in Window_SaveFile:


  #--------------------------------------------------------------------------
  # * Draw Party Faces
  #     x : Draw spot X coordinate
  #     y : Draw spot Y coordinate
  #--------------------------------------------------------------------------
  def draw_party_faces(x, y)
    for i in 0...@characters.size
      name = @characters[i][2]
      index = @characters[i][3]
      draw_face (name, index, x + i * 48, y)
    end
  end


That would corrupt all old save files though, so you'd need to delete them all.


AgentArsonist

I really appreciate your help. I guess it was far more complicated to do something simple than I thought..
I was wondering if you tested this though? The portraits aren't showing up, but maybe I did something wrong. I don't get any syntax errors though and I deleted the old save file and started a new one. Ideas? Is it just not showing up because of the coords?

modern algebra

Well, you need to call that method somewhere. It is pretty simple in any case, you just need to load the data from the save file to draw it.

You need to draw it in the refresh method, so something like:



  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    name = Vocab::File + " #{@file_index + 1}"
    self.contents.draw_text(4, 0, 200, WLH, name)
    @name_width = contents.text_size(name).width
    if @file_exist
      draw_party_characters(152, 58)
      draw_party_faces (152, 58)
      draw_playtime(0, 34, contents.width - 4, 2)
    end
  end


I assume you'll want to play around with the coordinates in the draw_party_faces method of course.

AgentArsonist

#4
For some reason it is not showing up, however I messed with the coordinates a little and after that one of my character sprites vanished.. almost as if it got covered up, but there was no visible picture.

I'm kinda lost.. haha

#==============================================================================
# ** Window_SaveFile
#------------------------------------------------------------------------------
#  This window displays save files on the save and load screens.
#==============================================================================

class Window_SaveFile < Window_Base
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :filename                 # filename
  attr_reader   :file_exist               # file existence flag
  attr_reader   :time_stamp               # timestamp
  attr_reader   :selected                 # selected
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     file_index : save file index (0-3)
  #     filename   : filename
  #--------------------------------------------------------------------------
  def initialize(file_index, filename)
    super(0, 56 + file_index % 4 * 90, 544, 90)
    @file_index = file_index
    @filename = filename
    load_gamedata
    refresh
    @selected = false
  end
  #--------------------------------------------------------------------------
  # * Load Partial Game Data
  #    By default, switches and variables are not used (for expansion use,
  #    such as displaying place names)
  #--------------------------------------------------------------------------
  def load_gamedata
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      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
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    name = Vocab::File + " #{@file_index + 1}"
    self.contents.draw_text(4, 0, 200, WLH, name)
    @name_width = contents.text_size(name).width
    if @file_exist
      draw_party_characters(152, 58)
      draw_playtime(0, 34, contents.width - 4, 2)
    end
  end
 
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    name = Vocab::File + " #{@file_index + 1}"
    self.contents.draw_text(4, 0, 200, WLH, name)
    @name_width = contents.text_size(name).width
    if @file_exist
      draw_party_characters(175, 100)
      draw_party_faces (152, 58)
      draw_playtime(0, 34, contents.width - 4, 2)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Party Characters
  #     x : Draw spot X coordinate
  #     y : Draw spot Y coordinate
  #--------------------------------------------------------------------------
  def draw_party_characters(x, y)
    for i in 0...@characters.size
      name = @characters[i][0]
      index = @characters[i][1]
      draw_character(name, index, x + i * 48, y)
    end
  end
#--------------------------------------------------------------------------
  # * Draw Party Faces
  #     x : Draw spot X coordinate
  #     y : Draw spot Y coordinate
  #--------------------------------------------------------------------------
  def draw_party_faces(x, y)
    for i in 0...@characters.size
      name = @characters[i][2]
      index = @characters[i][3]
      draw_face (name, index, x + i * 48, y)
    end
  end
 
 
  #--------------------------------------------------------------------------
  # * Draw Play Time
  #     x : Draw spot X coordinate
  #     y : Draw spot Y coordinate
  #     width : Width
  #     align : Alignment
  #--------------------------------------------------------------------------
  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
  #--------------------------------------------------------------------------
  # * Set Selected
  #     selected : new selected (true = selected, false = unselected)
  #--------------------------------------------------------------------------
  def selected=(selected)
    @selected = selected
    update_cursor
  end
  #--------------------------------------------------------------------------
  # * Update cursor
  #--------------------------------------------------------------------------
  def update_cursor
    if @selected
      self.cursor_rect.set(0, 0, @name_width + 8, WLH)
    else
      self.cursor_rect.empty
    end
  end
end

AgentArsonist

Did I do something wrong there?

???

modern algebra

Well, yeah, your coordinates are way off. I told you you'd need to mess around with them. For one thing, the window is only 90 pixels high, meaning only 58 pixels are available. So drawing the files at 150, 58, is going to draw them outside of the visible window. 150, 0 makes more sense, but even still you can't possibly fit the whole face onto the file without enlarging it. Also, the way it draws x coordinates I took directly from characters with the intention that you would modify them to fit with what you have in mind, as it is it's (x + i * 48) meaning that it takes the x argument (150, from what you have) and adds 48 for each member index. So first actor at 150, second actor at 198, etc... Since faces are 96x96 you'll want to make that difference larger.

Also, if you don't want to enlarge the window, then you'll need to draw only a smaller section of the face. To do that, you would want to not use the Window_Base draw_face method and do it manually instead. You can look at the draw_face method and see how they do it, and then just make it smaller. I can help you with that if that's what you want to do. It would almost certainly be better to make extra, thinner face edits in an image editing program and use those instead.