/*
   client/targeticonbutton.cc
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#include "audio/audio.h"
#include "client/targeticonbutton.h"
#include "client/targets.h"
#include "core/commandbuffer.h"

namespace client
{

TargetIconButton::TargetIconButton(Widget *parent, const char *icon, const char *tooltip, const char *command, unsigned int flags) : IconButton(parent, icon, tooltip, command)
{
	set_label("targeticonbutton");
	entity_flags = flags;
}

TargetIconButton::~TargetIconButton()
{
	entity_flags = 0;
}

bool TargetIconButton::on_mousepress(const unsigned int button)
{
	if (button == SDL_BUTTON_LEFT)
	{
		if (enabled() && command().size() && targets::current())
		{
			core::cmd() << "@" << command() << " " << targets::current_id() << std::endl;
			audio::play("ui/clicked");
		}
		return true;
	}

	return false;
}

void TargetIconButton::draw()
{
	set_enabled(targets::current() && ((targets::current()->flags() & entity_flags) == entity_flags));
	ui::IconButton::draw();
}

}