Example #1
0
void ItemContainer::refindSelectedItem()
{
    if (mSelectedItemIndex != NO_ITEM)
    {
        Item* item = mInventory->getItem(mSelectedItemIndex);

        if (item && item->getId() == mLastSelectedItemId &&
            item->getQuantity() > 0)
            return; // we're already fine

        // Otherwise ensure the invariant: we must point to an item of the
        // specified last ID, or nowhere at all.

        for (int i = 0; i < mMaxItems; i++)
        {
            Item* item = mInventory->getItem(i); 

            if (item && item->getId() == mLastSelectedItemId &&
                item->getQuantity() > 0)
            {
                mSelectedItemIndex = i;
                return;
            }
        }
    }

    mLastSelectedItemId = mSelectedItemIndex = NO_ITEM;
}
Example #2
0
void ItemContainer::draw(gcn::Graphics *graphics)
{
    if (!isVisible())
        return;

    const int columns = std::max(1, getWidth() / gridWidth);
    int gridSlot = 0;   // The visible slot for drawing this item

    for (int i = 0; i < mInventory->getSize(); i++)
    {
        Item *item = mInventory->getItem(i);

        if (!item || item->getQuantity() <= 0 || !passesFilter(item))
            continue;

        // Work out the object's position,
        const int itemX = (gridSlot % columns) * gridWidth;
        const int itemY = (gridSlot / columns) * gridHeight;

        // Draw selection image below selected item
        if (mSelectedItemIndex == i)
            static_cast<Graphics*>(graphics)->drawImage(mSelImg, itemX, itemY);

        // Draw item icon
        Image* image = item->getImage();

        if (image)
            static_cast<Graphics*>(graphics)->drawImage(image, itemX, itemY);

        // Draw item caption
        graphics->setFont(getFont());
        graphics->setColor(guiPalette->getColor(item->isEquipped() ? 
                               Palette::ITEM_EQUIPPED : Palette::TEXT));
        const std::string& text =
                item->isEquipped() ? STRING_EQUIPPED :
                item->getQuantity() == 1 ? STRING_ONE :
                toString(item->getQuantity());
        graphics->drawText(
                text,
                itemX + gridWidth / 2, itemY + gridHeight - 11,
                gcn::Graphics::CENTER);

        // Move on to the next visible slot
        gridSlot++;
    }

    // If there are no visible items, make sure nothing is selected;
    // and inform the selection-listeners.
    if (!gridSlot)
        selectNone();
}
Example #3
0
bool DropShortcut::dropItem(int cnt)
{
    const Inventory *inv = PlayerInfo::getInventory();
    if (!inv)
        return false;

    int itemId = 0;
    unsigned char itemColor = 1;
    while (mLastDropIndex < DROP_SHORTCUT_ITEMS && itemId < 1)
    {
        itemId = getItem(mLastDropIndex);
        itemColor = getItemColor(mLastDropIndex);
        mLastDropIndex ++;
    }
    if (itemId > 0)
    {
        Item *item = inv->findItem(itemId, itemColor);
        if (item && item->getQuantity() > 0)
        {
            Net::getInventoryHandler()->dropItem(item, cnt);
            return true;
        }
    }
    if (mLastDropIndex >= DROP_SHORTCUT_ITEMS)
        mLastDropIndex = 0;

    if (itemId < 1)
    {
        while (mLastDropIndex < DROP_SHORTCUT_ITEMS && itemId < 1)
        {
            itemId = getItem(mLastDropIndex);
            itemColor = getItemColor(mLastDropIndex);
            mLastDropIndex++;
        }
        if (itemId > 0)
        {
            Item *item = inv->findItem(itemId, itemColor);
            if (item && item->getQuantity() > 0)
            {
                Net::getInventoryHandler()->dropItem(item, cnt);
                return true;
            }
        }
        if (mLastDropIndex >= DROP_SHORTCUT_ITEMS)
            mLastDropIndex = 0;
    }
    return false;
}
Example #4
0
void StorageWindow::action(const gcn::ActionEvent &event)
{
    if (event.getId() == "close")
    {
        mItems->selectNone();
        close();
    }
    else if (event.getId() == "retrieve" || event.getId() == "default")
    {
        Item *item = mItems->getSelectedItem();

        if (!item)
            return;

        if (item->getQuantity() == 1)
        {
            removeStore(item, 1);
            selectNone();
        }
        // Choose amount of items to retrieve
        else
            new ItemAmountWindow(AMOUNT_STORE_REMOVE, this, item);
    }
    else if (event.getId() == "showpopupmenu")
        mItems->showPopupMenu(STORAGE, false);
}
Example #5
0
void InventoryWindow::action(const gcn::ActionEvent &event)
{
    Item *item = mItems->getSelectedItem();

    if (!item)
        return;

    if (event.getId() == "use")
    {
        if (item->isEquipment())
        {
            if (item->isEquipped())
                Net::getInventoryHandler()->unequipItem(item);
            else
                Net::getInventoryHandler()->equipItem(item);
        }
        else
            Net::getInventoryHandler()->useItem(item);
    }
    else if (event.getId() == "drop")
    {
        ItemAmountWindow::showWindow(ItemAmountWindow::ItemDrop, this, item);
    }
    else if (event.getId() == "split")
    {
        ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, this, item,
                                 (item->getQuantity() - 1));
    }
}
Example #6
0
void InventoryWindow::action(const gcn::ActionEvent &event)
{
    if (event.getId() == "outfit")
    {
        extern Window *outfitWindow;
        outfitWindow->setVisible(!outfitWindow->isVisible());
        if (outfitWindow->isVisible())
        {
            outfitWindow->requestMoveToTop();
        }
    }
    else if (event.getId() == "store")
    {
        if (!inventoryWindow->isVisible()) return;

        Item *item = inventoryWindow->getSelectedItem();

        if (!item)
            return;

        ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, this, item);
    }

    Item *item = mItems->getSelectedItem();

    if (!item)
        return;

    if (event.getId() == "use")
    {
        if (item->isEquipment())
        {
            if (item->isEquipped())
                Net::getInventoryHandler()->unequipItem(item);
            else
                Net::getInventoryHandler()->equipItem(item);
        }
        else
            Net::getInventoryHandler()->useItem(item);
    }
    else if (event.getId() == "drop")
    {
        ItemAmountWindow::showWindow(ItemAmountWindow::ItemDrop, this, item);
    }
    else if (event.getId() == "split")
    {
        ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, this, item,
                                 (item->getQuantity() - 1));
    }
    else if (event.getId() == "retrieve")
    {
        Item *item = mItems->getSelectedItem();

        if (!item)
            return;

        ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove, this,
                                     item);
    }
}
Example #7
0
void DropShortcut::dropFirst()
{
    if (!player_node)
        return;

    if (!Client::limitPackets(PACKET_DROP))
        return;

    const int itemId = getItem(0);
    const int itemColor = getItemColor(0);

    if (itemId > 0)
    {
        Item *item = PlayerInfo::getInventory()->findItem(itemId, itemColor);
        if (item && item->getQuantity())
        {
            if (player_node->isServerBuggy())
            {
                Net::getInventoryHandler()->dropItem(item,
                    player_node->getQuickDropCounter());
            }
            else
            {
                for (int i = 0; i < player_node->getQuickDropCounter(); i++)
                    Net::getInventoryHandler()->dropItem(item, 1);
            }
        }
    }
}
Example #8
0
void EquipmentWindow::draw(gcn::Graphics *graphics)
{
    // Draw window graphics
    Window::draw(graphics);

    Window::drawChildren(graphics);

    // Draw equipment boxes
    Graphics *g = static_cast<Graphics*>(graphics);

    for (int i = 0; i < mBoxesNumber; i++)
    {
        // When there is a background image, draw it centered in the box:
        if (mEquipBox[i].backgroundImage)
        {
            int posX = mEquipBox[i].posX
                + (BOX_WIDTH - mEquipBox[i].backgroundImage->getWidth()) / 2;
            int posY = mEquipBox[i].posY
                + (BOX_HEIGHT - mEquipBox[i].backgroundImage->getHeight()) / 2;
            g->drawImage(mEquipBox[i].backgroundImage, posX, posY);
        }

        if (i == mSelected)
        {
            const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT);

            // Set color to the highlight color
            g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha()));
            g->fillRectangle(gcn::Rectangle(mEquipBox[i].posX,
                                            mEquipBox[i].posY,
                                            BOX_WIDTH, BOX_HEIGHT));
        }

        // Set color black
        g->setColor(gcn::Color(0, 0, 0));
        // Draw box border
        g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY,
                                        BOX_WIDTH, BOX_HEIGHT));

        Item *item = mEquipment->getEquipment(i);
        if (item)
        {
            // Draw Item.
            Image *image = item->getImage();
            // Ensure the image is drawn with maximum opacity
            image->setAlpha(1.0f);
            g->drawImage(image,
                          mEquipBox[i].posX + 2,
                          mEquipBox[i].posY + 2);
            if (i == TmwAthena::EQUIP_PROJECTILE_SLOT)
            {
                g->setColor(Theme::getThemeColor(Theme::TEXT));
                graphics->drawText(toString(item->getQuantity()),
                                    mEquipBox[i].posX + (BOX_WIDTH / 2),
                                    mEquipBox[i].posY - getFont()->getHeight(),
                                    gcn::Graphics::CENTER);
            }
        }
    }
}
Example #9
0
void InventoryWindow::valueChanged(const gcn::SelectionEvent &event)
{
    if (!mInventory->isMainInventory())
        return;

    Item *item = mItems->getSelectedItem();

    if (mSplit && Net::getInventoryHandler()->
        canSplit(mItems->getSelectedItem()) && item)
    {
        ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, this, item,
                                     (item->getQuantity() - 1));
    }

    if (!item || item->getQuantity() == 0)
    {
        mUseButton->setEnabled(false);
        mDropButton->setEnabled(false);

        return;
    }

    mUseButton->setEnabled(true);
    mDropButton->setEnabled(true);

    if (item->isEquipment())
    {
        if (item->isEquipped())
            mUseButton->setCaption(_("Unequip"));
        else
            mUseButton->setCaption(_("Equip"));
    }
    else
    {
        mUseButton->setCaption(_("Use"));
    }

    if (item->getQuantity() > 1)
        mDropButton->setCaption(_("Drop..."));
    else
        mDropButton->setCaption(_("Drop"));

    if (Net::getInventoryHandler()->canSplit(item))
        mSplitButton->setEnabled(true);
    else
        mSplitButton->setEnabled(false);
}
//Copy Constructor
Item::Item(const Item& anItem) : Entity(anItem)
{
	m_iWeight = anItem.getWeight();
	m_iValue = anItem.getValue();
	m_iRarity = anItem.getRarity();
	m_iEnchantment = anItem.getEnchantment();
	m_iQuantity = anItem.getQuantity();
}
void setEquipment(int eAthenaSlot, int index, bool equiped)
{
    if (!eAthenaSlot)
        return;

    Item *item = player_node->getInventory()->getItem(index);

    if (!item)
        return;

    int position = 0;

    if (eAthenaSlot & 0x8000) {    // Arrows
        position = Equipment::EQUIP_PROJECTILE_SLOT;
    }
    else
    {
        /*
         * An item may occupy more than 1 slot.  If so, it's
         * only shown as equipped on the *first* slot.
         */
        int mask = 1;
        while (!(eAthenaSlot & mask))
        {
            mask <<= 1;
            position++;
        }

        position = EQUIP_POINTS[position];
    }

    if (equips[position])
        equips[position]->setEquipped(false);

    if (equiped && item)
    {
        equips[position] = item;
        item->setEquipped(true);
        player_node->mEquipment->setEquipment(position, item->getId(), item->getQuantity());

        if (debugEquipment)
        {
            logger->log("Equipping: %i %i at position %i",
                        index, eAthenaSlot, position);
        }
    }
    else
    {
        equips[position] = NULL;
        player_node->mEquipment->setEquipment(position, -1);

        if (debugEquipment)
        {
            logger->log("Unequipping: %i %i at position %i",
                        index, eAthenaSlot, position);
        }
    }
}
double ShoppingCart::totalPrice(){ //calculate and return the total price of the items in the shopping cart
	Item** item;  //pointer to current pointer to Item
	double total = 0.0;  //accumulate total

	for(item = itemList; item < itemList + arrayEnd; item++){  //dereference twice to get each item and add its price to the running total
		Item currentItem = **item;
		total += currentItem.getPrice() * currentItem.getQuantity();
	}
	return total;
}
void InventoryWindow::valueChanged(const gcn::SelectionEvent &event)
{
    if (mSplit && Net::getInventoryHandler()->canSplit(mItems->getSelectedItem()))
    {
        Item *item = mItems->getSelectedItem();

        if (item)
            ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, this, item,
                                 (item->getQuantity() - 1));
    }
}
Example #14
0
void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
{
    Window::mouseClicked(event);

    if (event.getButton() == gcn::MouseEvent::RIGHT)
    {
        Item *item = mItems->getSelectedItem();

        if (!item)
            return;

        /* Convert relative to the window coordinates to absolute screen
         * coordinates.
         */
        const int mx = event.getX() + getX();
        const int my = event.getY() + getY();
        viewport->showPopup(this, mx, my, item, isMainInventory());
    }

    if (event.getButton() == gcn::MouseEvent::LEFT)
    {
        if (instances.size() > 1 && keyboard.isKeyActive(keyboard.KEY_EMOTE))
        {
            Item *item = mItems->getSelectedItem();

            if(!item)
                return;
            if (mInventory->isMainInventory())
                Net::getInventoryHandler()->moveItem(Inventory::INVENTORY,
                                            item->getInvIndex(), item->getQuantity(),
                                            Inventory::STORAGE);
            else
                Net::getInventoryHandler()->moveItem(Inventory::STORAGE,
                                            item->getInvIndex(), item->getQuantity(),
                                            Inventory::INVENTORY);
        }
    }
}
//function to return the total cost of all items in the cart
double ShoppingCart::totalPrice()
{
	double total = 0.0;
	for (int i = 0; i < arrayEnd; i++)
	{
		double LineItemTotal = 0.0;
		Item currentLineItem = *arrayOfItems[i];
		LineItemTotal = currentLineItem.getPrice() * currentLineItem.getQuantity();
		total = total + LineItemTotal;

		cout << "Line Item Total is: " << LineItemTotal << endl;
		cout << "Running Total is: " << total << endl;
	}
	return total;
}
Example #16
0
void OutfitWindow::wearOutfit(int outfit)
{
    if (mItemsUnequip[outfit])
        unequipNotInOutfit(outfit);

    Item *item;
    for (int i = 0; i < OUTFIT_ITEM_COUNT; i++)
    {
        item = PlayerInfo::getInventory()->findItem(mItems[outfit][i]);
        if (item && !item->isEquipped() && item->getQuantity())
        {
            if (item->isEquippable())
                item->doEvent(Event::DoEquip);
        }
    }
}
Example #17
0
int ItemContainer::getVisibleSlot(const Item* searchItem) const
{
    int itemCount = NO_ITEM;
    for (int i = 0; i < mInventory->getSize(); i++)
    {
        Item *item = mInventory->getItem(i);

        if (!item || item->getQuantity() <= 0 || !passesFilter(item))
            continue;

        itemCount++;

        if (searchItem == item)
            return itemCount;
    }

    return NO_ITEM;
}
Example #18
0
Item* ItemContainer::getItemInVisibleSlot(const int gridSlot)
{
    int itemCount = NO_ITEM;
    for (int i = 0; i < mInventory->getSize(); i++)
    {
        Item *item = mInventory->getItem(i);

        if (!item || item->getQuantity() <= 0 || !passesFilter(item))
            continue;

        itemCount++;

        if (itemCount == gridSlot)
            return item;
    }

    return NULL;
}
Example #19
0
void OutfitWindow::wearOutfit(int outfit)
{
    Item *item;
    for (int i = 0; i < OUTFIT_ITEM_COUNT; i++)
    {
        item = player_node->getInventory()->findItem(mItems[outfit][i]);
        if (item && !item->isEquipped() && item->getQuantity())
        {
            if (item->isEquipment()) {
                Net::getInventoryHandler()->equipItem(item);
            }
        }
    }

    if (mItemsUnequip[outfit])
    {
        unequipNotInOutfit(outfit);
    }
}
Example #20
0
void ItemShortcut::useItem(int index)
{
    if (mItems[index])
    {
        Item *item = PlayerInfo::getInventory()->findItem(mItems[index]);
        if (item && item->getQuantity())
        {
            if (item->getInfo().getEquippable())
            {
                if (item->isEquipped())
                    item->doEvent(Event::DoUnequip);
                else
                    item->doEvent(Event::DoEquip);
            }
            else
            {
                item->doEvent(Event::DoUse);
            }
        }
    }
}
Example #21
0
void ItemContainer::recalculateHeight()
{
    int numOfItems = 0;

    for (int i = 0; i < mInventory->getSize(); i++)
    {
        Item *item = mInventory->getItem(i);

        if (!item || item->getQuantity() <= 0 || !passesFilter(item))
            continue;

        numOfItems++;
    }

    const int cols = std::max(1, getWidth() / gridWidth);
    const int rows = (numOfItems / cols) + (numOfItems % cols > 0 ? 1 : 0);
    const int height = rows * gridHeight + 8;

    if (height != getHeight())
        setHeight(height);
}
Example #22
0
void ItemContainer::showItemPopup(bool show)
{
    Item *item = getSelectedItem();

    if (!item || item->getQuantity() <= 0 || !passesFilter(item))
    {
        mItemPopup->setVisible(false);
        return;
    }

    if (item->getInfo().getName() != mItemPopup->getItemName())
        mItemPopup->setItem(item->getInfo());

    int x = 0;
    int y = 0;

    getPopupLocation(false, x, y);

    mItemPopup->updateColors();
    mItemPopup->view(x, y);
    mItemPopup->setVisible(mShowItemInfo ? show : false);
}
Example #23
0
void EquipmentWindow::draw(gcn::Graphics *graphics)
{
    // Draw window graphics
    Window::draw(graphics);

    Graphics *g = static_cast<Graphics*>(graphics);

    Window::drawChildren(graphics);

    int i = 0;
    const int fontHeight = getFont()->getHeight();

    for (std::vector<EquipmentBox*>::const_iterator it = mBoxes.begin(),
         it_end = mBoxes.end(); it != it_end; ++ it, ++ i)
    {
        EquipmentBox *box = *it;
        if (!box)
            continue;
        if (i == mSelected)
        {
            mHighlightColor.a = getGuiAlpha();
            // Set color to the highlight color
            g->setColor(mHighlightColor);
            g->fillRectangle(gcn::Rectangle(box->x, box->y,
                BOX_WIDTH, BOX_HEIGHT));
        }

        // Set color black
        g->setColor(mBorderColor);
        // Draw box border
        g->drawRectangle(gcn::Rectangle(box->x, box->y,
            BOX_WIDTH, BOX_HEIGHT));

        if (!mEquipment)
            continue;

        Item *item = mEquipment->getEquipment(i);
        if (item)
        {
            // Draw Item.
            Image *image = item->getImage();
            if (image)
            {
                image->setAlpha(1.0f); // Ensure the image is drawn
                                       // with maximum opacity
                g->drawImage(image, box->x + 2, box->y + 2);
                if (i == EQUIP_PROJECTILE_SLOT)
                {
                    g->setColor(getForegroundColor());
                    graphics->drawText(toString(item->getQuantity()),
                        box->x + (BOX_WIDTH / 2), box->y - fontHeight,
                        gcn::Graphics::CENTER);
                }
            }
        }
        else if (box->image)
        {
            g->drawImage(box->image, box->x + BOX_X_PAD,
                box->y + BOX_Y_PAD);
        }
    }
}
void ItemShortcutContainer::draw(gcn::Graphics *graphics)
{
    if (config.getValue("guialpha", 0.8) != mAlpha)
    {
        mAlpha = config.getValue("guialpha", 0.8);
        mBackgroundImg->setAlpha(mAlpha);
    }

    Graphics *g = static_cast<Graphics*>(graphics);

    graphics->setFont(getFont());

    for (int i = 0; i < mMaxItems; i++)
    {
        const int itemX = (i % mGridWidth) * mBoxWidth;
        const int itemY = (i / mGridWidth) * mBoxHeight;

        g->drawImage(mBackgroundImg, itemX, itemY);

        // Draw item keyboard shortcut.
        const std::string key = keyboard.keyString(keyboard.KEY_SHORTCUT_1 + i);
        graphics->setColor(guiPalette->getColor(Palette::TEXT));
        g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT);

        if (itemShortcut->getItem(i) < 0)
            continue;

        Item *item =
            player_node->getInventory()->findItem(itemShortcut->getItem(i));

        if (item)
        {
            // Draw item icon.
            Image* image = item->getImage();

            if (image)
            {
                std::string caption;
                if (item->getQuantity() > 1)
                    caption = toString(item->getQuantity());
                else if (item->isEquipped())
                    caption = "Eq.";

                g->drawImage(image, itemX, itemY);
                if (item->isEquipped())
                    g->setColor(guiPalette->getColor(Palette::ITEM_EQUIPPED));
                g->drawText(caption, itemX + mBoxWidth / 2,
                            itemY + mBoxHeight - 14, gcn::Graphics::CENTER);
            }
        }
    }

    if (mItemMoved)
    {
        // Draw the item image being dragged by the cursor.
        Image* image = mItemMoved->getImage();
        if (image)
        {
            const int tPosX = mCursorPosX - (image->getWidth() / 2);
            const int tPosY = mCursorPosY - (image->getHeight() / 2);

            g->drawImage(image, tPosX, tPosY);
            g->drawText(toString(mItemMoved->getQuantity()),
                        tPosX + mBoxWidth / 2, tPosY + mBoxHeight - 14,
                        gcn::Graphics::CENTER);
        }
    }
}
Example #25
0
void ItemContainer::draw(gcn::Graphics *graphics)
{
    Graphics *g = static_cast<Graphics*>(graphics);

    g->setFont(getFont());

    for (int i = 0; i < mGridColumns; i++)
    {
        for (int j = 0; j < mGridRows; j++)
        {
            int itemX = i * BOX_WIDTH;
            int itemY = j * BOX_HEIGHT;
            int itemIndex = (j * mGridColumns) + i;
            Item *item = mInventory->getItem(itemIndex);

            if (!item || item->getId() == 0)
                continue;

            Image *image = item->getImage();
            if (image)
            {
                if (itemIndex == mSelectedIndex)
                {
                    if (mSelectionStatus == SEL_DRAGGING) {
                        // Reposition the coords to that of the cursor.
                        itemX = mDragPosX - (BOX_WIDTH / 2);
                        itemY = mDragPosY - (BOX_HEIGHT / 2);
                    }
                    else {
                        // Draw selected image.
                        g->drawImage(mSelImg, itemX, itemY);
                    }
                }
                g->drawImage(image, itemX, itemY);
            }
            // Draw item caption
            std::string caption;
            if (item->getQuantity() > 1 || mForceQuantity)
                caption = toString(item->getQuantity());
            else if (item->isEquipped())
                caption = "Eq.";

            if (item->isEquipped())
                g->setColor(guiPalette->getColor(Palette::ITEM_EQUIPPED));
            else
                g->setColor(gcn::Color(0, 0, 0));

            g->drawText(caption, itemX + BOX_WIDTH / 2,
                        itemY + BOX_HEIGHT - 14, gcn::Graphics::CENTER);
        }
    }

    // Draw an orange box around the selected item
    if (isFocused() && mHighlightedIndex != -1)
    {
        const int itemX = (mHighlightedIndex % mGridColumns) * BOX_WIDTH;
        const int itemY = (mHighlightedIndex / mGridColumns) * BOX_HEIGHT;
        g->setColor(gcn::Color(255, 128, 0));
        g->drawRectangle(gcn::Rectangle(itemX, itemY, BOX_WIDTH, BOX_HEIGHT));
    }
}
Example #26
0
void EquipmentWindow::draw(gcn::Graphics *graphics)
{
    // Draw window graphics
    Window::draw(graphics);

    Item* item;

    graphics->pushClipArea(getChildrenArea());

    // A bitmask showing which slots will be affected
    // by the equip / unequip button.
    int highlightSlots = 0;

    if (mSelected != -1)
        highlightSlots = (1 << mSelected);

    Item* wouldEquip = mItems->getSelectedItem();

    if (wouldEquip)
        highlightSlots |= wouldEquip->getInfo().getEquipSlots();

    for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++)
    {
        const gcn::Rectangle &rect = mEquipIcon[i]->getDimension();

        if (highlightSlots & (1 << i))
        {
            const gcn::Color color = guiPalette->getColor(Palette::HIGHLIGHT);

            // Set color to the highligh color
            graphics->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha()));
            graphics->fillRectangle(rect);
        }

        // Set color black.
        graphics->setColor(gcn::Color(0, 0, 0));
        // Draw box border.
        graphics->drawRectangle(rect);

        item = (i != EQUIP_AMMO_SLOT) ?
               mInventory->getItem(mEquipment->getEquipment(i)) :
               mInventory->getItem(mEquipment->getArrows());
        if (item)
        {
            // Draw Item.
            Image* image = item->getImage();

            if (image != mEquipIcon[i]->getImage())
                mEquipIcon[i]->setImage(image);

            if (i == EQUIP_AMMO_SLOT)
            {
                graphics->setColor(guiPalette->getColor(Palette::TEXT));
                graphics->drawText(toString(item->getQuantity()),
                                   mEquipIcon[i]->getX() + (mEquipIcon[i]->getWidth() / 2),
                                   mEquipIcon[i]->getY() - getFont()->getHeight(),
                                   gcn::Graphics::CENTER);
            }
        }
        else if (mEquipIcon[i]->getImage())
            mEquipIcon[i]->setImage(NULL);
    }
    graphics->popClipArea();

    Window::drawChildren(graphics);
}
void InventoryWindow::action(const gcn::ActionEvent &event)
{
    if (event.getId() == "outfit")
    {
        extern Window *outfitWindow;
        outfitWindow->setVisible(!outfitWindow->isVisible());
        if (outfitWindow->isVisible())
        {
            outfitWindow->requestMoveToTop();
        }
    }

    Item *item = mItems->getSelectedItem();

    if (!item)
        return;

    if (event.getId() == "use")
    {
        if (item->isEquipment())
        {
            if (item->isEquipped())
                Net::getInventoryHandler()->unequipItem(item);
            else
                Net::getInventoryHandler()->equipItem(item);
        }
        else if (item->getId()>1099 && item->getId()<1200)
        {
            if (circuitWindow->isVisible())
            {
                circuitWindow->distributeOlay(item);
            }
            else if (similasyonPenceresi->isVisible())
            {
                if(similasyonPenceresi->getPencereDurum())
                {
                    Net::getInventoryHandler()->useItem(item);
                    similasyonPenceresi->nesneyiAl(item);
                }
                else
                    localChatTab->chatLog("Nesneyi kullanabilmek için similasyonu başlatmalısınız!!!",BY_SERVER);

            }
            else
            {
                localChatTab->chatLog("Bu nesneyi sadece devre tamir ederken kullanabilirsin.",BY_SERVER);
            }
        }
        else
            Net::getInventoryHandler()->useItem(item);
    }
    else if (event.getId() == "drop")
    {
        ItemAmountWindow::showWindow(ItemAmountWindow::ItemDrop, this, item);
    }
    else if (event.getId() == "split")
    {
        ItemAmountWindow::showWindow(ItemAmountWindow::ItemSplit, this, item,
                                 (item->getQuantity() - 1));
    }
}
Example #28
0
void InventoryWindow::action(const gcn::ActionEvent &event)
{
    if (event.getId() == "shortcuts")
    {
        itemShortcutWindow->setVisible(!itemShortcutWindow->isVisible());
        return;
    }

    Item *item = mItems->getSelectedItem();

    if (!item)
        return;

    if (event.getId() == "trade" && tradeWindow->canTrade())
    {
        if (item->getQuantity() == 1)
        {
            tradeWindow->tradeItem(item, 1);
            selectNone();
        }
        // Choose amount of items to trade
        else
            new ItemAmountWindow(AMOUNT_TRADE_ADD, tradeWindow, item);
    }
    else if (event.getId() == "store" && storageWindow->isVisible())
    {
        if (item->getQuantity() == 1)
        {
            storageWindow->addStore(item, 1);
            selectNone();
        }
        // Choose amount of items to store
        else
            new ItemAmountWindow(AMOUNT_STORE_ADD, storageWindow, item);
    }
    else if (event.getId() == "use" || event.getId() == "default")
    {
        if (item->isEquipment())
        {
            if (item->isEquipped())
                player_node->unequipItem(item);
            else
                player_node->equipItem(item);
        }
        else
        {
            if (item->getQuantity() == 1)
                selectNone();

            player_node->useItem(item);
        }
    }
    else if (event.getId() == "drop")
    {
        if (item->getQuantity() == 1)
        {
            player_node->dropItem(item, 1);
            selectNone();
        }
        // Choose amount of items to drop
        else
            new ItemAmountWindow(AMOUNT_ITEM_DROP, this, item);
    }
    else if (event.getId() == "showpopupmenu")
        mItems->showPopupMenu(INVENTORY, false);
}
Example #29
0
void ItemContainer::draw(gcn::Graphics *graphics)
{
    if (!mInventory || !mShowMatrix)
        return;

    Graphics *g = static_cast<Graphics*>(graphics);

    g->setFont(getFont());

    for (int j = 0; j < mGridRows; j++)
    {
        for (int i = 0; i < mGridColumns; i++)
        {
            int itemX = i * BOX_WIDTH;
            int itemY = j * BOX_HEIGHT;
            int itemIndex = j * mGridColumns + i;
            if (mShowMatrix[itemIndex] < 0)
                continue;

            Item *item = mInventory->getItem(mShowMatrix[itemIndex]);

            if (!item || item->getId() == 0)
                continue;

            Image *image = item->getImage();
            if (image)
            {
                if (mShowMatrix[itemIndex] == mSelectedIndex)
                {
                    if (mSelectionStatus == SEL_DRAGGING)
                    {
                        // Reposition the coords to that of the cursor.
                        itemX = mDragPosX - (BOX_WIDTH / 2);
                        itemY = mDragPosY - (BOX_HEIGHT / 2);
                    }
                    else
                    {
                        // Draw selection border image.
                        if (mSelImg)
                            g->drawImage(mSelImg, itemX, itemY);
                    }
                }
                image->setAlpha(1.0f); // ensure the image if fully drawn...
                g->drawImage(image, itemX, itemY);
            }
            // Draw item caption
            std::string caption;
            if (item->getQuantity() > 1 || mForceQuantity)
                caption = toString(item->getQuantity());
            else if (item->isEquipped())
                caption = "Eq.";

            if (item->isEquipped())
                g->setColor(mEquipedColor);
            else
                g->setColor(mUnEquipedColor);

            g->drawText(caption, itemX + BOX_WIDTH / 2,
                        itemY + BOX_HEIGHT - 14, gcn::Graphics::CENTER);
        }
    }

/*
    // Draw an orange box around the selected item
    if (isFocused() && mHighlightedIndex != -1 && mGridColumns)
    {
        const int itemX = (mHighlightedIndex % mGridColumns) * BOX_WIDTH;
        const int itemY = (mHighlightedIndex / mGridColumns) * BOX_HEIGHT;
        g->setColor(gcn::Color(255, 128, 0));
        g->drawRectangle(gcn::Rectangle(itemX, itemY, BOX_WIDTH, BOX_HEIGHT));
    }
*/
}
Example #30
0
void InventoryHandler::event(Event::Channel channel,
                             const Event &event)
{
    if (channel == Event::ItemChannel)
    {
        Item *item = event.getItem("item");

        if (!item)
            return;

        int index = item->getInvIndex();

        if (event.getType() == Event::DoEquip)
        {
            MessageOut msg(PGMSG_EQUIP);
            msg.writeInt8(index);
            gameServerConnection->send(msg);
        }
        else if (event.getType() == Event::DoUnequip)
        {
            MessageOut msg(PGMSG_UNEQUIP);
            msg.writeInt8(index);
            gameServerConnection->send(msg);

            // Tidy equipment directly to avoid weapon still shown bug,
            // for instance.
            mEquips.setEquipment(index, 0, 0);
        }
        else if (event.getType() == Event::DoUse)
        {
            MessageOut msg(PGMSG_USE_ITEM);
            msg.writeInt8(index);
            gameServerConnection->send(msg);
        }
        else if (event.getType() == Event::DoDrop)
        {
            int amount = event.getInt("amount", 1);

            MessageOut msg(PGMSG_DROP);
            msg.writeInt8(index);
            msg.writeInt8(amount);
            gameServerConnection->send(msg);
        }
        else if (event.getType() == Event::DoSplit)
        {
            int amount = event.getInt("amount", 1);

            int newIndex = PlayerInfo::getInventory()->getFreeSlot();
            if (newIndex > Inventory::NO_SLOT_INDEX)
            {
                MessageOut msg(PGMSG_MOVE_ITEM);
                msg.writeInt8(index);
                msg.writeInt8(newIndex);
                msg.writeInt8(amount);
                gameServerConnection->send(msg);
            }
        }
        else if (event.getType() == Event::DoMove)
        {
            int newIndex = event.getInt("newIndex", -1);

            if (newIndex >= 0)
            {
                if (index == newIndex)
                    return;

                MessageOut msg(PGMSG_MOVE_ITEM);
                msg.writeInt8(index);
                msg.writeInt8(newIndex);
                msg.writeInt8(item->getQuantity());
                gameServerConnection->send(msg);
            }
            else
            {
                /*int source = event.getInt("source");
                int destination = event.getInt("destination");
                int amount = event.getInt("amount", 1);*/

                // TODO
            }
        }
    }
}