using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace Scrabble
{
public enum ObjectClickedState
{
Normal,
Clicked,
Released
}
public abstract class ClickableGameplayObject : GameplayObject
{
public static bool OnLeaveTest=false;
public static bool OnLeaveTestRect = false;
ClickablePlayer clickablePlayer;
//int resize = 12;
// public Vector2 resize//used for hud
// {
// get;
// protected set;
// }
Vector2 resize = new Vector2(15, 15);
Point resize1 = new Point(15, 15);
//declaring point and rect
Point p1;
Rectangle eTile, eLetter;
public ObjectClickedState LeftState
{
get;
protected set;
}
public ObjectClickedState RightState
{
get;
protected set;
}
public Mouse ActiveMouse
{
get;
protected set;
}
public ClickableGameplayObject()
: base()
{
LeftState = RightState = ObjectClickedState.Normal;
}
//testing lines to see if onleace works
public virtual void OnLeftClick()
{
OnLeaveTest = false;
}
public virtual void OnHeldLeftClick() { }
public virtual void OnLeftRelease()
{
// OnLeaveTest = true;
}
public virtual void OnLeftNormal() { }
public virtual void OnRightClick() { }
public virtual void OnHeldRightClick() { }
public virtual void OnRightRelease() { }
public virtual void OnRightNormal() { }
public virtual void OnHover() { }
public virtual void OnLeave()
// public override void OnLeave()
{//now add code to //check game board position.
OnLeaveTest = true;
}
public Rectangle TestLetterDropRect
{
get;
set;
}
private void centerLetterOnTile()
{
eTile = new Rectangle(651, 372, 50, 50);
p1 = eTile.Location;
//eLetter = new Rectangle(clickablePlayer.Position.X, clickablePlayer.Position.Y, 50, 50);
//eLetter = new Rectangle(eTile.X, eTile.Y, 50, 50);
eLetter = new Rectangle(50,50, 50, 50);
if (eTile.Contains(eLetter) && OnLeaveTest == true)
{
eLetter.Location = eTile.Location;
}
else
{
OnLeaveTestRect = false;
}
//this code is commented out as i was trying to do it a different way, as eLetter is going to be the clickablePlayer
//but when i tried this code the line //clickablePlayer.Position = new Vector2(100, 100); was getting a null for clickablePlayer
/* //this is the current x and y on mouse position
Level.x = Level.currentState.X;
Level.y = Level.currentState.Y;
TestLetterDropRect = new Rectangle(651, 372, 50, 50);
//if rect contains mouse pointer(draggin lette) and mouse releases letter and moves outside the letter...the letter should move to the center of tile rect
if (!TestLetterDropRect.Contains(Level.x, Level.y) && OnLeaveTest == true)
{
OnLeaveTestRect = true;
//letter new position = rectangle /2
//resize is an int of size 12.
//clickablePlayer.Position = new Vector2(100, 100);
//clickablePlayer.Position = TestLetterDropRect.Y + resize;
}*/
}
public void Update(GameTime gameTime, Mouse activeMouse)
{
base.Update(gameTime);
centerLetterOnTile();
bool intersect = activeMouse.Rectangle.Intersects(Rectangle);
if (intersect || (ActiveMouse != null &&
(LeftState != ObjectClickedState.Normal || RightState != ObjectClickedState.Normal)))
{
ActiveMouse = activeMouse;
ActiveMouse.ClickedObject = this;
if (intersect) OnHover();
if (ActiveMouse.LeftClick && (LeftState == ObjectClickedState.Normal
|| LeftState == ObjectClickedState.Released))
{
LeftState = ObjectClickedState.Clicked;
OnLeftClick();
}
else if (ActiveMouse.LeftClick && LeftState == ObjectClickedState.Clicked)
{
OnHeldLeftClick();
}
else if (ActiveMouse.LeftRelease && LeftState == ObjectClickedState.Clicked)
{
LeftState = ObjectClickedState.Released;
OnLeftRelease();
}
else if (!ActiveMouse.LeftClick && LeftState == ObjectClickedState.Released)
{
LeftState = ObjectClickedState.Normal;
OnLeftNormal();
}
if (ActiveMouse.RightClick && (RightState == ObjectClickedState.Normal
|| RightState == ObjectClickedState.Released))
{
RightState = ObjectClickedState.Clicked;
OnRightClick();
}
else if (ActiveMouse.RightClick && LeftState == ObjectClickedState.Clicked)
{
OnHeldRightClick();
}
else if (ActiveMouse.RightRelease && RightState == ObjectClickedState.Clicked)
{
RightState = ObjectClickedState.Released;
OnRightRelease();
}
else if (!ActiveMouse.RightClick && RightState == ObjectClickedState.Released)
{
RightState = ObjectClickedState.Normal;
OnRightNormal();
}
}
else
//removes the mouse influence over the object do the folowing...(calls on leave)
{
if (ActiveMouse != null)
{
ActiveMouse.ClickedObject = null;
ActiveMouse = null;
OnLeave();
}
}
UpdateGameplayObject(gameTime);
}
protected abstract void UpdateGameplayObject(GameTime gameTime);
}
}