示例#1
0
void ItemPopup::setItem(const ItemInfo &item)
{
    if (item.getName() == mItemName->getCaption())
        return;

    mItemType = item.getType();

    mItemName->setCaption(item.getName());
    mItemName->adjustSize();
    mItemName->setForegroundColor(getColor(mItemType));

    mItemDesc->setTextWrapped(item.getDescription(), 196);
    mItemEffect->setTextWrapped(item.getEffect(), 196);
    mItemWeight->setTextWrapped(strprintf(_("Weight: %s"),
                                Units::formatWeight(item.getWeight()).c_str()),
                                196);

    int minWidth = mItemName->getWidth();

    if (mItemDesc->getMinWidth() > minWidth)
        minWidth = mItemDesc->getMinWidth();
    if (mItemEffect->getMinWidth() > minWidth)
        minWidth = mItemEffect->getMinWidth();
    if (mItemWeight->getMinWidth() > minWidth)
        minWidth = mItemWeight->getMinWidth();

    minWidth += 8;
    setWidth(minWidth);

    const int numRowsDesc = mItemDesc->getNumberOfRows();
    const int numRowsEffect = mItemEffect->getNumberOfRows();
    const int numRowsWeight = mItemWeight->getNumberOfRows();
    const int height = getFont()->getHeight();

    if (item.getEffect().empty())
    {
        setContentSize(minWidth, (numRowsDesc + numRowsWeight + getPadding()) *
                       height);

        mItemWeight->setPosition(getPadding(), (numRowsDesc + getPadding()) *
                                 height);
    }
    else
    {
        setContentSize(minWidth, (numRowsDesc + numRowsEffect + numRowsWeight +
                       getPadding()) * height);

        mItemWeight->setPosition(getPadding(), (numRowsDesc + numRowsEffect +
                                 getPadding()) * height);
    }

    mItemDesc->setPosition(getPadding(), 2 * height);
    mItemEffect->setPosition(getPadding(), (numRowsDesc + getPadding()) * height);
}
示例#2
0
void ItemPopup::setItem(const ItemInfo &item)
{
    if (item.getName() == mItemName->getCaption())
        return;

    mItemName->setFont(gui->getBoldFont());
    mItemName->setCaption(item.getName());
    mItemName->setWidth(gui->getBoldFont()->getWidth(item.getName()));
    mItemDesc->setTextWrapped(item.getDescription(), 196);
    mItemEffect->setTextWrapped(item.getEffect(), 196);
    mItemWeight->setTextWrapped(_("Weight: ") + toString(item.getWeight()) +
                                _(" grams"), 196);
    mItemType = item.getType();

    int minWidth = mItemName->getWidth();

    if (mItemDesc->getMinWidth() > minWidth)
        minWidth = mItemDesc->getMinWidth();
    if (mItemEffect->getMinWidth() > minWidth)
        minWidth = mItemEffect->getMinWidth();
    if (mItemWeight->getMinWidth() > minWidth)
        minWidth = mItemWeight->getMinWidth();

    minWidth += 8;
    setWidth(minWidth);

    const int numRowsDesc = mItemDesc->getNumberOfRows();
    const int numRowsEffect = item.getEffect().empty() ? 0 : 
                              mItemEffect->getNumberOfRows();
    const int numRowsWeight = mItemWeight->getNumberOfRows();
    const int height = getFont()->getHeight();

    setContentSize(minWidth, (numRowsDesc + numRowsEffect + numRowsWeight +
                   getPadding()) * height);

    mItemWeight->setPosition(getPadding(), (numRowsDesc + numRowsEffect +
                             getPadding()) * height);

    mItemDesc->setPosition(getPadding(), 2 * height);
    mItemEffect->setPosition(getPadding(), (numRowsDesc + getPadding()) * height);
}