示例#1
0
void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
{
    Window::mousePressed(mouseEvent);

    if (!mEquipment)
        return;

    const int x = mouseEvent.getX();
    const int y = mouseEvent.getY();

    if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
    {
        if (mForing)
            return;
        // Checks if any of the presses were in the equip boxes.
        int i = 0;

        for (std::vector<EquipmentBox*>::const_iterator it = mBoxes.begin(),
             it_end = mBoxes.end(); it != it_end; ++ it, ++ i)
        {
            EquipmentBox *box = *it;
            if (!box)
                continue;
            Item *item = mEquipment->getEquipment(i);
            const gcn::Rectangle tRect(box->x, box->y,
                BOX_WIDTH, BOX_HEIGHT);

            if (tRect.isPointInRect(x, y) && item)
                setSelected(i);
        }
    }
    else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT)
    {
        if (Item *item = getItem(x, y))
        {
            if (mItemPopup)
                mItemPopup->setVisible(false);

            /* Convert relative to the window coordinates to absolute screen
             * coordinates.
             */
            const int mx = x + getX();
            const int my = y + getY();
            if (viewport)
            {
                if (mForing)
                    viewport->showUndressPopup(mx, my, mBeing, item);
                else
                    viewport->showPopup(this, mx, my, item, true);
            }
        }
    }
}
示例#2
0
int OutfitWindow::getIndexFromGrid(int pointX, int pointY) const
{
    const gcn::Rectangle tRect = gcn::Rectangle(
        10, 25, 10 + mGridWidth * mBoxWidth, 25 + mGridHeight * mBoxHeight);
    if (!tRect.isPointInRect(pointX, pointY))
        return -1;
    const int index = (((pointY - 25) / mBoxHeight) * mGridWidth) +
        (pointX - 10) / mBoxWidth;
    if (index >= OUTFIT_ITEM_COUNT)
        return -1;
    return index;
}
示例#3
0
Item *EquipmentWindow::getItem(int x, int y) const
{
    if (!mEquipment)
        return nullptr;

    int i = 0;

    for (std::vector<EquipmentBox*>::const_iterator it = mBoxes.begin(),
         it_end = mBoxes.end(); it != it_end; ++ it, ++ i)
    {
        EquipmentBox *box = *it;
        if (!box)
            continue;
        const gcn::Rectangle tRect(box->x, box->y,
            BOX_WIDTH, BOX_HEIGHT);

        if (tRect.isPointInRect(x, y))
            return mEquipment->getEquipment(i);
    }
    return nullptr;
}