package nullarbor;

import com.sun.j3d.utils.universe.PlatformGeometry;
import nullarbor.model.Label3D;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import java.awt.Color;
import java.awt.Font;
import nullarbor.model.FontLoader;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Credits
{
    private static final float FADE_PORTION = 0.25f;
    private Font font;
    private long length;
    private long clength;
    private String[] credits;
    private int prev;
    PlatformGeometry pg;

    Label3D label;


    public Credits(String[] credits, String font, long length)
    {
        FontLoader fontLoader = new FontLoader();
        this.font = fontLoader.getFont("beaggressive");
        this.font = this.font.deriveFont(72.0f);
        this.length = length;
        this.credits = credits;
        clength = length / credits.length;
        prev = -1;
    }

    public PlatformGeometry getPlatformGeometry(long time)
    {
        int i = (int)(credits.length * time / length);
//        int j = (int)(time % clength);

        if(i > credits.length)
        {
            return null;
        }
        if(i != prev)
        {
//            label = new Label3D(credits[i], new Point3f( -0.41f, 0.292f, -1.0f),
            label = new Label3D(credits[i], new Point3f( -0.2f, 0.2f, -1.0f),
                                new Color3f(Color.RED), font, 1.0f);
//            label = new Label3D(credits[i], new Point3f( -0.35f, 0.275f, -1.0f),
//                                new Color3f(Color.BLUE.darker()), font, 1.0f);
            pg = new PlatformGeometry();
            pg.addChild(label);

            System.out.println("created new label");
            prev = i;
        }
/*
        else
        {
            float alpha = 1.0f; // 1.0 = visible, 0.0 = invisible
            if(j < FADE_PORTION * clength)
            {
                alpha = ((float)j / (float)clength) / FADE_PORTION;
            }
            else if (j > (1.0f - FADE_PORTION) * clength)
            {
                alpha = ((float)(clength - j) / (float)clength) / FADE_PORTION;
            }
//            label.setTextAlpha(alpha);
            System.out.println("set alpha to "+alpha);
//            System.out.println("time = "+time+" clength = "+clength);
//            System.out.println("j = "+j+" alpha = "+alpha);

        }
*/
        return pg;
    }
}
