using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Util;
namespace FaceOff
{
class TrayCell : Cell
{
private Logger mLogger;
public TrayCell(Logger logger)
{
mLogger = logger;
}
private Texture2D mFaceTexture;
public Texture2D FaceTexture
{
get { return mFaceTexture; }
set { mFaceTexture = value; }
}
private Vector2 mOriginalPosition;
public Vector2 OriginalPosition
{
get { return mOriginalPosition; }
set { mOriginalPosition = value; }
}
//time to wait for loading
private float loadTime = GameConfig.LoadTime;
//is the cell waiting to be clicked
private bool mPreLoad = true;
public bool PreLoad
{
get { return mPreLoad; }
set { mPreLoad = value; }
}
//has the cell been placed
private bool placed;
public bool Placed
{
get { return placed; }
set { placed = value; }
}
//is the cell loading
private bool mLoading = false;
public bool Loading
{
get { return mLoading; }
set { mLoading = value; }
}
//a reference to distinguish which cell this is in the tray
private int mReference;
public int Reference
{
get { return mReference; }
set { mReference = value; }
}
private bool isClicked = false;
public bool Clicked
{
get { return isClicked; }
set { isClicked = value; }
}
public void ApplyJitter(float jitter)
{
loadTime += jitter;
}
///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///
/// Provides a snapshot of timing values.
public void Update(GameTime gameTime, Vector2 mousePos)
{
//if the cell is currently clicked, then drag it to the mouse position
if(isClicked)
{
DrawPosition = new Vector2((mousePos.X - (Size / 2)), (mousePos.Y - (Size / 2)));
}
//if the cell is loading, then decrement the amount of time until it
//is done loading
else if (mLoading)
{
//subtract the time elapsed since the last update call from the
//time the user needs to wait for the cell to load
loadTime -= ((gameTime.ElapsedGameTime.Milliseconds)*0.001f);
if (loadTime <= 0)
{
mLoading = false;
mLogger.Write((int)EventCode.FO_FACELOADED + Reference - 1, "FO_FACELOADED Cell=" + Reference + "_Category=" + FaceLoader.CategoryNames[Category]);
//set the original texture
Texture = mFaceTexture;
Scale();
}
}
}
}
}