package uk.co.patrickhaston.mars;
import uk.co.patrickhaston.pdhsprites.PdhBitmapSprite;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;

public class MarsViewImage extends PdhBitmapSprite 
{
  // the view contains the orientation of the view.
  // the construction contains the orientation of the construction
  // the view contains the view scale (large, medium or small)
  MarsView theView = null;
  
  // The paintAt is used to paint the image in the right place at the right time
  // It is up to this class to find the correct image and draw it correctly
  public MarsViewImage()
  {
    super();
  }
  
  public MarsViewImage(Image i, Component v, MarsFrame f)
  {
    super(0, 0, i, f);
  }
  
  public void setView(MarsView view)
  {
    theView = view;
  }

  public void paintAt(Graphics g, int x, int y, int orientation, MarsView view, int cStatus, int objectSize)
  {
    theView = view;
    int sx = 0; // the source x co-ord of the image to be used
    int sy = 0; // the source y co-ord of the image to be used
    int s = 0; // the source size of the image to be used
    // These are currently hard coded - they should really be calculated for each image
    switch(theView.scale)
    {
      case 0: // large scale
        sx = 128 * orientation;
        sy = 0;
        s = 128;
        break;
      case 1: // medium scale
        sx = 64 * orientation;
        sy = 384;
        s = 64;
        break;
      case 2: // small scale
        sx = 256 + (32 * orientation);
        sy = 480;
        s = 32;
        break;
      case 3: // tiny scale
        sx = 384 + (16 * orientation);
        sy = 528;
        s = 16;
        break;
    }
    
    // find out which image to draw depending on the status of the object
    switch(cStatus)
    {
      case 4: //MarsConstruction.UNDER_CONSTRUCTION:
      case 0: //MarsConstruction.NOT_CREATED:
        // Use the second set of images
        sy = sy + s;
        break;
      case 1: //MarsConstruction.IN_USE:
      case 2: //MarsConstruction.NOT_IN_USE:
        // Use the top images
       break;
      case 3: //MarsConstruction.BROKEN:
        // Use the third set of images
        sy = sy + (s * 2);
    }
    sx *= objectSize/10;
    sy *= objectSize/10;
    s *= objectSize/10;
    g.drawImage(image, x, y, x+s, y+s, sx, sy, sx+s, sy+s, component);
    //g.drawLine(x, y, x+width, y+width);
    //g.drawString("x:" + x + " y:" + y + " width:" + width + " height:" + " sx:" + sx + " sy:" + sy + " s:" + s, x, y);
  }
  
  public Image getImage()
  {
    return image;
  }
}
