#include "stdafx.h"
#include "SelectionCircleButtons.h"

#include "CellWarsGameManager.h"
#include "CellWarsMTManager.h"
#include "MultiSelectionCircle.h"

SelectionCircleButtonRemoveSelection::SelectionCircleButtonRemoveSelection(int buttonSlot, CellWarsMTManager *useThisMultiTouchManager, 
	MultiSelectionCircle *belongsToMultiSelectionCircle, bool isMirrored) : SelectionButton(buttonSlot, useThisMultiTouchManager, belongsToMultiSelectionCircle, isMirrored)
{
	SetName("RemoveSelectionButton");
	SetSprite("Resources/Images/removeSelection active.png");
}

SelectionCircleButtonRemoveSelection::~SelectionCircleButtonRemoveSelection()
{
}

void SelectionCircleButtonRemoveSelection::PreDestroy()
{
	useThisMTManager->removeTouchableFromCallbackList(this);
	useThisMTManager = NULL;
}

void SelectionCircleButtonRemoveSelection::click()
{
	useThisMTManager->removeMultiSelectionCircle(belongsToThisMSCircle);
}



SelectionCircleButtonReplicate::SelectionCircleButtonReplicate(int buttonSlot, CellWarsMTManager *useThisMultiTouchManager, 
	MultiSelectionCircle *belongsToMultiSelectionCircle, bool isMirrored) : SelectionButton(buttonSlot, useThisMultiTouchManager, belongsToMultiSelectionCircle, isMirrored)
{
	SetName("ReplicateSelectionButton");
	SetSprite("Resources/Images/replicate.png");
}

SelectionCircleButtonReplicate::SelectionCircleButtonReplicate(int buttonSlot, CellWarsMTManager *useThisMultiTouchManager, 
	Bacterium *belongsToBacterium, bool isMirrored) : SelectionButton(buttonSlot, useThisMultiTouchManager, belongsToBacterium, isMirrored)
{
	SetName("ReplicateSelectionButton");
	SetSprite("Resources/Images/replicate.png");
}

SelectionCircleButtonReplicate::~SelectionCircleButtonReplicate()
{
	//std::cout << "~SelectionCircleButtonReplicate " << _name << std::endl;
}

void SelectionCircleButtonReplicate::PreDestroy()
{
	useThisMTManager->removeTouchableFromCallbackList(this);
	useThisMTManager = NULL;
}

void SelectionCircleButtonReplicate::click()
{
	if (belongsToThisMSCircle)
		belongsToThisMSCircle->replicateSelected();
	else if (belongsToThisBacterium)
		belongsToThisBacterium->replicate();
}
	
void SelectionCircleButtonReplicate::Update(float dt)
{
	SelectionButton::Update(dt);
	bool isActive = false;
	if ((belongsToThisMSCircle && belongsToThisMSCircle->anySelectedHasFullResources()) ||
		(belongsToThisBacterium && belongsToThisBacterium->hasFullResources()))
	{
		isActive = true;
	}
	if (isActive)
	{
		SetSprite("Resources/Images/replicate active.png");
	}
	else
	{
		SetSprite("Resources/Images/replicate.png");
	}
}



SelectionCircleButtonUpgrade::SelectionCircleButtonUpgrade(int buttonSlot, CellWarsMTManager *useThisMultiTouchManager, 
	MultiSelectionCircle *belongsToMultiSelectionCircle, bool isMirrored) : SelectionButton(buttonSlot, useThisMultiTouchManager, belongsToMultiSelectionCircle, isMirrored)
{
	SetName("UpgradeSelectionButton");
	SetSprite("Resources/Images/upgrade.png");

	//std::cout << "SelectionCircleButtonReplicate " << _name << std::endl;
}

SelectionCircleButtonUpgrade::SelectionCircleButtonUpgrade(int buttonSlot, CellWarsMTManager *useThisMultiTouchManager, 
	Bacterium *belongsToBacterium, bool isMirrored) : SelectionButton(buttonSlot, useThisMultiTouchManager, belongsToBacterium, isMirrored)
{
	SetName("UpgradeSelectionButton");
	SetSprite("Resources/Images/upgrade.png");

	//std::cout << "SelectionCircleButtonReplicate " << _name << std::endl;
}

SelectionCircleButtonUpgrade::~SelectionCircleButtonUpgrade()
{
	//std::cout << "~SelectionCircleButtonReplicate " << _name << std::endl;
}

void SelectionCircleButtonUpgrade::PreDestroy()
{
	useThisMTManager->removeTouchableFromCallbackList(this);
	useThisMTManager = NULL;

	//std::cout << "predestroy SelectionCircleButtonReplicate " << _name << std::endl;
}

void SelectionCircleButtonUpgrade::click()
{
	if (belongsToThisMSCircle)
		belongsToThisMSCircle->upgradeSelected();
	else if (belongsToThisBacterium)
		belongsToThisBacterium->upgrade();
}
	
void SelectionCircleButtonUpgrade::Update(float dt)
{
	SelectionButton::Update(dt);
	bool isActive = false;
	if ((belongsToThisMSCircle && belongsToThisMSCircle->anySelectedHasFullResources()) ||
		(belongsToThisBacterium && belongsToThisBacterium->hasFullResources()))
	{
		isActive = true;
	}
	if (isActive)
	{
		SetSprite("Resources/Images/upgrade active.png");
	}
	else
	{
		SetSprite("Resources/Images/upgrade.png");
	}
}