示例#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);
}
示例#3
0
文件: itempopup.cpp 项目: B-Rich/mana
void ItemPopup::setItem(const ItemInfo &item, bool showImage)
{
    if (item.getName() == mItemName->getCaption())
        return;

    int space = 0;

    Image *oldImage = mIcon->getImage();
    if (oldImage)
        oldImage->decRef();

    if (showImage)
    {
        ResourceManager *resman = ResourceManager::getInstance();
        Image *image = resman->getImage(
                                  paths.getStringValue("itemIcons")
                                  + item.getDisplay().image);

        mIcon->setImage(image);
        if (image)
        {
            int x = getPadding();
            int y = getPadding();
            mIcon->setPosition(x, y);
            space = mIcon->getWidth();
        }
    }
    else
    {
        mIcon->setImage(0);
    }

    mItemType = item.getItemType();

    std::string caption = item.getName();
    if (!mItemEquipSlot.empty())
        caption += " (" + mItemEquipSlot + ")";

    mItemName->setCaption(caption);
    mItemName->adjustSize();
    mItemName->setForegroundColor(getColorFromItemType(mItemType));
    mItemName->setPosition(getPadding() + space, getPadding());

    mItemDesc->setTextWrapped(item.getDescription(), ITEMPOPUP_WRAP_WIDTH);
    {
        const std::vector<std::string> &effect = item.getEffect();
        std::string temp = "";
        for (std::vector<std::string>::const_iterator it = effect.begin(),
             it_end = effect.end(); it != it_end; ++it)
            temp += temp.empty() ? *it : "\n" + *it;
        mItemEffect->setTextWrapped(temp, ITEMPOPUP_WRAP_WIDTH);
    }
    mItemWeight->setTextWrapped(strprintf(_("Weight: %s"),
                                Units::formatWeight(item.getWeight()).c_str()),
                                ITEMPOPUP_WRAP_WIDTH);

    int minWidth = mItemName->getWidth() + space;

    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 fontHeight = getFont()->getHeight();

    int nameHeight;
    if (mIcon->getHeight() > 2 * fontHeight)
        nameHeight = mIcon->getHeight();
    else
        nameHeight = 2 * fontHeight;

    if (item.getEffect().empty())
    {
        setContentSize(minWidth, nameHeight +
                        (numRowsDesc + numRowsWeight + 1) * fontHeight);

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

        mItemWeight->setPosition(getPadding(), nameHeight + (numRowsDesc +
                                    numRowsEffect + 1) * fontHeight);
    }

    mItemDesc->setPosition(getPadding(), nameHeight);
    mItemEffect->setPosition(getPadding(), nameHeight +
                            (numRowsDesc + 1) * fontHeight);
}