/*
* LinkedObject.cs
* Authors: Karl Orosz
* Copyright (c) 2007-2008 Cornell University
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.
*/
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace StarJack
{
public abstract class LinkedObject:GameObject
{
Entity mLinkedSquare;
protected bool mKeepSwatch = true;
bool mEnabled;
public virtual bool Enabled
{
get { return mEnabled; }
set
{
mEnabled = value;
if (mEnabled)
{
Texture = mEnabledTexture;
Enable();
}
else
{
Texture = mDisabledTexture;
Disable();
}
}
}
///
/// Sets the
///
new public int X
{
get { return base.X; }
set
{
mLinkedSquare.X = X;
}
}
///
/// Sets the
///
new public int Y
{
get { return base.Y; }
set
{
base.Y = value;
mLinkedSquare.Y = value;
}
}
///
/// Sets the
///
new public int Width
{
get { return base.Width; }
set
{
base.Width = value;
mLinkedSquare.Width = value;
}
}
///
/// Sets the
///
new public int Height
{
get { return base.Height; }
set
{
base.Height = value;
mLinkedSquare.Height = value;
}
}
///
/// Sets the
///
new public int[] Position
{
get { return base.Position; }
set
{
base.Position = value;
mLinkedSquare.X = X;
mLinkedSquare.Y = Y;
}
}
new public string Group
{
get { return base.Group; }
set
{
base.Group = value;
EnabledTexture = GroupTextures["Active"];
foreach (String s in GroupTextures.Keys)
{
Console.WriteLine(s);
}
DisabledTexture = GroupTextures["Inactive"];
mLinkedSquare.Group = value;
mLinkedSquare.TextureName = "Swatch";
mLinkedSquare.Name = "Swatch";
}
}
// new public bool Enabled { get { return mHackable; } set { mHackable = value; base.Enabled = value; } }
private Color mLinkedColor;
public Color LinkedColor { get { return mLinkedColor; } set { mLinkedColor = value; mLinkedSquare.Color = value; } }
//Variables for the Active texture.
//This will be shown when an object has not been hacked;
public string EnabledTextureName
{
get { if (mEnabledTexture == null) { return null; } return mEnabledTexture.Name; }
set { if (mEnabledTexture == null) { mEnabledTexture = new TextureInfo(value); } else { mEnabledTexture.Name = value; } }
}
protected TextureInfo mEnabledTexture;
public TextureInfo EnabledTexture { get { return mEnabledTexture; } set { mEnabledTexture = value; EnabledTextureName = mEnabledTexture.Name; } }
//Variables for the inactive texture.
//This will be shown when an object is Disabled
public string DisabledTextureName
{
get { if (mDisabledTexture == null) { return null; } return mDisabledTexture.Name; }
set { if (mDisabledTexture == null) { mDisabledTexture = new TextureInfo(value); } else { mDisabledTexture.Name = value; } }
}
protected TextureInfo mDisabledTexture;
public TextureInfo DisabledTexture { get { return mDisabledTexture; } set { mDisabledTexture = value; DisabledTextureName = mDisabledTexture.Name; } }
protected LinkedObject mLinked;
public LinkedObject Linked { get { return mLinked; }
set
{
mLinked = value;
Enabled = mLinked.Enabled;
LinkedColor = mLinked.LinkedColor;
}
}
protected string mLinkedName;
public string LinkedName
{
get { return mLinkedName; }
set { mLinkedName = value; }
}
public LinkedObject(string name, bool tileMode):base(name,tileMode)
{
Facing= Direction.None;
mLinkedSquare = new Entity();
mLinkedSquare.Texture = new TextureInfo("Square");
mLinkedSquare.Name = "NoSwatch";
mLinkedSquare.Depth = 0.4f;
// mLinkedSquare.Color = mColor;
Height = Height;
Width = Width;
}
Rectangle mLinkedSqaureDest;
public override void LoadContent(ContentManager content)
{
base.LoadContent(content);
if (mDisabledTexture != null)
{
mDisabledTexture.LoadContent(content);
}
if (mEnabledTexture != null)
{
mEnabledTexture.LoadContent(content);
}
mLinkedSquare.LoadContent(content);
// Enabled = Enabled;
}
public override void Update(Microsoft.Xna.Framework.GameTime time)
{
if (mLinked != null && mLinked.Enabled != mEnabled)
{
Enabled = mLinked.Enabled;
}
base.Update(time);
}
public override void Draw(SpriteBatch pSpriteBatch)
{
base.Draw(pSpriteBatch);
// pSpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None);
if (mLinkedSquare.Texture != null && (Enabled || mKeepSwatch))
{
mLinkedSquare.Draw(pSpriteBatch);
}
//pSpriteBatch.Draw(mLinkedSquare.Asset, mLinkedSqaureDest,mLinkedSquare.Source, LinkedColor,mRotation,Vector2.Zero,SpriteEffects.None,0.4f);
//pSpriteBatch.End();
}
public abstract void Enable();
public abstract void Disable();
}
}