#include "RecipieOutput.h"

#include <XML.h>

#include "Globals.h"
#include "UIMLToolTip.h"

RecipieOutputElement::RecipieOutputElement()
    : Framework::UIMLElement()
{}

//! pr�ft, ob dieses UIML Element f�r ein bestimmtes xml Element zust�ndig
//! ist
bool RecipieOutputElement::isApplicableFor(Framework::XML::Element& element)
{
    return element.getName().istGleich("output");
}

//! erstellt eine neue Zeichnung zu einem gegebenen xml Element
Framework::Zeichnung* RecipieOutputElement::parseElement(
    Framework::XML::Element& element, Framework::UIMLContainer& generalFactory)
{
    SlotInfo info;
    info.itemCount = (int)element.getAttributeValue("amount");
    int itemType = (int)element.getAttributeValue("itemType");
    info.hp = (float)(double)element.getAttributeValue("hp");
    info.maxHp = (float)(double)element.getAttributeValue("maxHp");
    info.durability = (float)(double)element.getAttributeValue("durability");
    info.maxDurability
        = (float)(double)element.getAttributeValue("maxDurability");
    info.zItem = zItemType(itemType)->zIcon();
    return new RecipieOutput(info, element.zChild(0)->toString());
}

//! wendet die layout parameter zu einer Zeichnung an
void RecipieOutputElement::layout(Framework::XML::Element& element,
    Framework::Zeichnung& z,
    int pWidth,
    int pHeight,
    Framework::UIMLContainer& generalLayouter)
{
    UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter);
    z.setWidth(50);
    z.setHeight(50);
}

RecipieOutput::RecipieOutput(SlotInfo info, Framework::Text toolTipUIML)
    : info(info)
{
    setStyle(Framework::Zeichnung::Style::Erlaubt
             | Framework::Zeichnung::Style::Sichtbar);
    UIMLToolTip* tip = new UIMLToolTip();
    tip->setUIML(toolTipUIML);
    tip->setWarten(0.5);
    setToolTipZ(tip);
}

void RecipieOutput::render(Framework::Bild& rObj)
{
    ZeichnungHintergrund::render(rObj);
    if (!rObj.setDrawOptions(pos.x, pos.y, gr.x, gr.y)) return;
    info.render(-1, -1, rObj, 0, 0);
    rObj.releaseDrawOptions();
}