/*
Tiamat - a role-playing game framework
SequenceFrame.java - class to represent a frame in a sequence
    
 Copyright  (C) 2005 Hugues Johnson
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package com.huguesjohnson.tiamat.graphics;

import com.huguesjohnson.ImageLoader;
import com.huguesjohnson.PathResolver;
import com.huguesjohnson.serialization.Formatter;
import com.huguesjohnson.serialization.Storable;
import java.awt.image.BufferedImage;
import java.io.File;

/** SequenceFrame.java - class to represent a frame in a sequence
 * @author  Hugues Johnson
 */
public class SequenceFrame implements Storable{
/* begin public properties */    
    //the text that's drawn in this frame
    private String text;
    /** Set the text to draw in this frame.
     * @param text The text to draw in this frame.
     */
    public void setText(String text){
        this.text=new String(text);
    }
    /** Returns the text to draw in this frame.
     * @return The text to draw in this frame.
     */
    public String getText(){
        return(this.text);
    }
    //the relative path to the background music for this frame
    private String bgMusicPath;
    /** Returns the relative path to the background music.
     * @return The relative path to the background music.
     */
    public String getBgMusicPath(){
        return(this.bgMusicPath);
    }
    /** Sets the relative path to the background music.
     * @param bgMusicPath The relative path to the background music.
     */
    public void setBgMusicPath(String bgMusicPath){
        this.bgMusicPath=new String(bgMusicPath);
    }
    /** Returns the absolute path to the background music.
     * @return The absolute path to the background music.
     */
    public String getBgMusicPathAbsolute(){
        return(PathResolver.getAbsolutePath(this.absoluteDir,this.bgMusicPath));
    }
    //relative path to the background image for this frame, setting this reloads the actual image
    private String bgImagePath;
    /** Sets the relative path to the background image.
     * @param bgImagePath The relative path to the background image.
     */
    public void setBgImagePath(String bgImagePath){ 
        this.bgImagePath=bgImagePath; 
        this.bgImage=ImageLoader.loadBufferedImage(this.getBgImagePathAbsolute());
    }
    /** Returns the relative path to the background image.
     * @return The relative path to the background image.
     */
    public String getBgImagePath(){ 
        return(this.bgImagePath); 
    }
    /** Returns the absolute path to the background image.
     * @return The absolute path to the background image.
     */
    public String getBgImagePathAbsolute(){ 
        return(PathResolver.getAbsolutePath(this.absoluteDir,this.bgImagePath)); 
    }
    //background image for this frame, change by setting bgImagePath
    private transient BufferedImage bgImage;
    /** Returns the background image for this frame.
     * @return The background image for this frame.
     */
    public BufferedImage getBgImage(){ 
        return(this.bgImage);
    }    
    //absolute path to the directory where images and background music are stored
    protected transient String absoluteDir;
    /** Sets the absolute path to the directory where images and background music are stored.
     * @param absoluteDir The new absolute directory.
     */
    public void setAbsoluteDir(String absoluteDir){
        if(absoluteDir.endsWith(File.separator)){
            this.absoluteDir=absoluteDir;
        } else{
            this.absoluteDir=absoluteDir+File.separator;
        }
    }    
/* end public properties */    
    
/* begin constructors */

    /** Creates a new instance of SequenceFrame. 
     */
    public SequenceFrame(){ }
    /** Creates a new instance of SequenceFrame. 
     * @param text The text to draw in this frame.
     * @param absoluteDir The new absolute directory.
     * @param bgImagePath The relative path to the background image.
     * @param bgMusicPath The relative path to the background music.
     */
    public SequenceFrame(String text,String absoluteDir,String bgImagePath,String bgMusicPath){
        this.setText(text);
        this.setAbsoluteDir(absoluteDir);
        this.setBgImagePath(bgImagePath);
        this.setBgMusicPath(bgMusicPath);
    }
/* end constructors */    

/* begin overides */
    /** The onDeserialize event should be fired after an object is de-serialized.
     * This allows objects to load transient members, set their working directory, and load Storable members if needed.
     * @param formatter the formatter to use to load any storable members
     * @param absoluteDir the working directory since all paths stored in the object should be relative
     */
    public void onDeserialize(Formatter formatter,String absoluteDir){
        //set the absolute directory
        this.setAbsoluteDir(absoluteDir);
        //load the background image
        this.bgImage=ImageLoader.loadBufferedImage(this.getBgImagePathAbsolute());
    }
/* end overides */    
}