#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().isEqual("output");
}

//! erstellt eine neue Drawable zu einem gegebenen xml Element
Framework::Drawable* 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());
}

bool RecipieOutputElement::updateElement(Framework::XML::Element& element,
    Framework::Drawable& z,
    Framework::UIMLContainer& generalFactory)
{
    return false;
}

//! wendet die layout parameter zu einer Drawable an
void RecipieOutputElement::layout(Framework::XML::Element& element,
    Framework::Drawable& 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::Drawable::Style::Allowed
             | Framework::Drawable::Style::Visible);
    UIMLToolTip* tip = new UIMLToolTip();
    tip->setUIML(toolTipUIML);
    tip->setWarten(0.5);
    setToolTipZ(tip);
}

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