#include "stdafx.h"
#include "FormTouchButtons.h"

#include "CellWarsGameManager.h"
#include "CellWarsMTManager.h"
#include "HelpScreen.h"

#define TIME_PER_TICK 0.33f

StartButton::StartButton(CellWarsMTManager *useThisMultiTouchManager) : 
TouchButton(useThisMultiTouchManager)
{
	SetName("StartButton");
	SetSprite("Resources/Images/start.png");
}

StartButton::~StartButton()
{
}

void StartButton::click()
{
	theCellWarsGame.startGame();
}



ReStartButton::ReStartButton(CellWarsMTManager *useThisMultiTouchManager) : 
TouchButton(useThisMultiTouchManager)
{
	SetName("ReStartButton");
	SetSprite("Resources/Images/replay.png");
}

ReStartButton::~ReStartButton()
{
}

void ReStartButton::click()
{
	theCellWarsGame.showStart();
}



ExitButton::ExitButton(CellWarsMTManager *useThisMultiTouchManager) : 
TouchButton(useThisMultiTouchManager)
{
	SetName("ExitButton");
	SetSprite("Resources/Images/exit.png");
}

ExitButton::~ExitButton()
{
}

void ExitButton::click()
{
	theCellWarsGame.endGame();
}



HelpButton::HelpButton(CellWarsMTManager *useThisMultiTouchManager) : 
TouchButton(useThisMultiTouchManager)
{
	SetName("HelpButton");
	SetSprite("Resources/Images/help.png");
}

HelpButton::~HelpButton()
{
}

void HelpButton::click()
{
	theCellWarsGame.showHelp();
}



SwitchHelpButton::SwitchHelpButton(CellWarsMTManager *useThisMultiTouchManager) : 
TouchButton(useThisMultiTouchManager), isOnThisHelpScreen(NULL)
{
	SetName("SwitchHelpButton");
	SetSprite("Resources/Images/start.png");
}

SwitchHelpButton::~SwitchHelpButton()
{
}

void SwitchHelpButton::setHelpScreen(HelpScreen *belongsToThisHelpScreen)
{
	isOnThisHelpScreen = belongsToThisHelpScreen;
}

void SwitchHelpButton::click()
{
	if (isOnThisHelpScreen)
		isOnThisHelpScreen->gotoNextPage();
}



IncreaseVolumeButton::IncreaseVolumeButton(CellWarsMTManager *useThisMultiTouchManager) : 
TouchButton(useThisMultiTouchManager), timeSinceLastTick(0)
{
	SetName("IncreaseVolumeButton");
	SetSprite("Resources/Images/inVolButton.png");
}

IncreaseVolumeButton::~IncreaseVolumeButton()
{
}

void IncreaseVolumeButton::click()
{
}

void IncreaseVolumeButton::Update(float dt)
{
	TouchButton::Update(dt);

	if (isAlreadyTouched())
	{
		timeSinceLastTick += dt;

		if (timeSinceLastTick > TIME_PER_TICK)
		{
			timeSinceLastTick = 0;
			theCellWarsGame.setMainVolume(theCellWarsGame.getMainVolume() + 0.05f);
		}
	}
}



DecreaseVolumeButton::DecreaseVolumeButton(CellWarsMTManager *useThisMultiTouchManager) : 
TouchButton(useThisMultiTouchManager), timeSinceLastTick(0)
{
	SetName("DecreaseVolumeButton");
	SetSprite("Resources/Images/deVolButton.png");
}

DecreaseVolumeButton::~DecreaseVolumeButton()
{
}

void DecreaseVolumeButton::click()
{
}

void DecreaseVolumeButton::Update(float dt)
{
	TouchButton::Update(dt);

	if (isAlreadyTouched())
	{
		timeSinceLastTick += dt;

		if (timeSinceLastTick > TIME_PER_TICK)
		{
			timeSinceLastTick = 0;
			theCellWarsGame.setMainVolume(theCellWarsGame.getMainVolume() - 0.05f);
		}
	}
}