//	PickupAnnouncer.cpp - Used to announce which pickup's been collected.
//  ----------------------------------------------------------------------------
//	This file is part of 'NiallsAVLib', base code for any kind of audiovisual
//	apps.
//	Copyright (C) 2012  Niall Moody
//	
//	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 3 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, see <http://www.gnu.org/licenses/>.
//	----------------------------------------------------------------------------

#include "PickupAnnouncer.h"
#include "drawing/Drawer.h"

//------------------------------------------------------------------------------
PickupAnnouncer::PickupAnnouncer():
position(-640.0f),
posTweener(position, position, 0.0075f)
{
	posTweener.setIndex(1.0f);
}

//------------------------------------------------------------------------------
PickupAnnouncer::~PickupAnnouncer()
{

}

//------------------------------------------------------------------------------
void PickupAnnouncer::update()
{
	if(announcements.size() > 0)
	{
		if(!posTweener.getFinished())
			posTweener.tick();
		else
		{
			position = -1280.0f;
			posTweener.setIndex(1.0f);

			announcements.erase(announcements.begin());
			layout.clear();

			if(announcements.size() > 0)
			{
				position = 0.0f - (118.0f + (48.0f * announcements[0].text.length()));
				posTweener.reset(1280.0f);
			}
		}
	}
}

//------------------------------------------------------------------------------
void PickupAnnouncer::draw(shared_ptr<Drawer>& d)
{
	if(announcements.size() > 0)
	{
		d->drawImage(L"PickupTextLines",
					 TwoFloats(position, (d->getDrawingAreaSize().y*0.5f)-72.0f),
					 1.0f,
					 announcements[0].colour);

		d->drawText(announcements[0].text,
					L"BigFont",
					layout,
					TwoFloats(position+118.0f+8.0f, (d->getDrawingAreaSize().y*0.5f)+32.0f+8.0f),
					d->getDrawingAreaSize().x-125.0f,
					TextLayout::Left);

		d->drawText(announcements[0].text,
					L"BigFont",
					layout,
					TwoFloats(position+118.0f, (d->getDrawingAreaSize().y*0.5f)+32.0f),
					d->getDrawingAreaSize().x-125.0f,
					TextLayout::Left,
					1.0f,
					announcements[0].colour);
	}
}

//------------------------------------------------------------------------------
void PickupAnnouncer::trigger(const std::wstring& text, const ThreeFloats& col)
{
	Announcement ann;

	ann.text = text;
	ann.colour = col;
	announcements.push_back(ann);
	if(announcements.size() == 1)
	{
		position = 0.0f - (125.0f + (48.0f * announcements[0].text.length()));
		posTweener.reset(1280.0f);
	}
}
