~ubuntu-branches/ubuntu/saucy/manaplus/saucy-proposed

« back to all changes in this revision

Viewing changes to src/gui/outfitwindow.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi, Andrei Karas, Patrick Matthäi
  • Date: 2013-06-10 10:53:26 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130610105326-c3xqk5ebcgy3jxmb
Tags: 1.3.6.9-1
[ Andrei Karas ]
* Add new files to copyright file.

[ Patrick Matthäi ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include "gui/outfitwindow.h"
24
24
 
25
25
#include "configuration.h"
 
26
#include "dragdrop.h"
26
27
#include "emoteshortcut.h"
27
28
#include "equipment.h"
28
29
#include "game.h"
78
79
        keyName(mCurrentOutfit).c_str()))),
79
80
    mBoxWidth(33),
80
81
    mBoxHeight(33),
81
 
    mCursorPosX(0),
82
 
    mCursorPosY(0),
83
82
    mGridWidth(4),
84
83
    mGridHeight(4),
85
 
    mItemMoved(nullptr),
86
84
    mItems(),
87
 
    mItemSelected(-1),
88
85
    mAwayOutfit(0),
89
86
    mBorderColor(getThemeColor(Theme::BORDER, 64)),
90
87
    mBackgroundColor(getThemeColor(Theme::BACKGROUND, 32)),
374
371
            }
375
372
        }
376
373
    }
377
 
    if (mItemMoved)
378
 
    {
379
 
        // Draw the item image being dragged by the cursor.
380
 
        const Image *const image = mItemMoved->getImage();
381
 
        if (image)
382
 
        {
383
 
            const int tPosX = mCursorPosX - (image->mBounds.w / 2);
384
 
            const int tPosY = mCursorPosY - (image->mBounds.h / 2);
385
 
 
386
 
            g->drawImage(image, tPosX, tPosY);
387
 
        }
388
 
    }
389
374
    BLOCK_END("OutfitWindow::draw")
390
375
}
391
376
 
394
379
{
395
380
    if (event.getButton() == gcn::MouseEvent::LEFT)
396
381
    {
397
 
        if (!mItemMoved && mItemClicked)
 
382
        if (dragDrop.isEmpty() && mItemClicked)
398
383
        {
399
384
            if (mCurrentOutfit < 0 || mCurrentOutfit
400
385
                >= static_cast<signed int>(OUTFITS_COUNT))
423
408
            {
424
409
                Item *const item = inv->findItem(itemId, itemColor);
425
410
                if (item)
426
 
                    mItemMoved = item;
 
411
                    dragDrop.dragItem(item, DRAGDROP_SOURCE_OUTFIT);
427
412
                else
428
 
                    mItemMoved = nullptr;
 
413
                    dragDrop.clear();
429
414
                mItems[mCurrentOutfit][index] = -1;
430
415
            }
431
416
        }
432
 
        if (mItemMoved)
433
 
        {
434
 
            mCursorPosX = event.getX();
435
 
            mCursorPosY = event.getY();
436
 
        }
437
417
    }
438
418
    Window::mouseDragged(event);
439
419
}
457
437
    mMoved = false;
458
438
    event.consume();
459
439
 
460
 
    // Stores the selected item if there is one.
461
 
    if (isItemSelected())
462
 
    {
463
 
        mItems[mCurrentOutfit][index] = mItemSelected;
464
 
        mItemColors[mCurrentOutfit][index] = mItemColorSelected;
465
 
 
466
 
        if (inventoryWindow)
467
 
            inventoryWindow->unselectItem();
468
 
    }
469
 
    else if (mItems[mCurrentOutfit][index])
 
440
    if (mItems[mCurrentOutfit][index] > 0)
470
441
    {
471
442
        mItemClicked = true;
472
443
    }
 
444
    else
 
445
    {
 
446
        if (dragDrop.isSelected())
 
447
        {
 
448
            mItems[mCurrentOutfit][index] = dragDrop.getSelected();
 
449
            mItemColors[mCurrentOutfit][index] = dragDrop.getSelectedColor();
 
450
            dragDrop.deselect();
 
451
        }
 
452
    }
 
453
 
473
454
    Window::mousePressed(event);
474
455
}
475
456
 
485
466
        const int index = getIndexFromGrid(event.getX(), event.getY());
486
467
        if (index == -1)
487
468
        {
488
 
            mItemMoved = nullptr;
 
469
            dragDrop.clear();
489
470
            Window::mouseReleased(event);
490
471
            return;
491
472
        }
492
473
        mMoved = false;
493
474
        event.consume();
494
 
        if (mItemMoved)
 
475
        if (!dragDrop.isEmpty())
495
476
        {
496
 
            mItems[mCurrentOutfit][index] = mItemMoved->getId();
497
 
            mItemColors[mCurrentOutfit][index] = mItemMoved->getColor();
498
 
            mItemMoved = nullptr;
 
477
            mItems[mCurrentOutfit][index] = dragDrop.getItem();
 
478
            mItemColors[mCurrentOutfit][index] = dragDrop.getItemColor();
 
479
            dragDrop.clear();
 
480
            dragDrop.deselect();
499
481
        }
500
482
        if (mItemClicked)
501
483
            mItemClicked = false;
505
487
 
506
488
int OutfitWindow::getIndexFromGrid(const int pointX, const int pointY) const
507
489
{
508
 
    const gcn::Rectangle tRect = gcn::Rectangle(
509
 
        10, 25, mGridWidth * mBoxWidth, mGridHeight * mBoxHeight);
 
490
    const gcn::Rectangle tRect = gcn::Rectangle(mPadding, mTitleBarHeight,
 
491
        mGridWidth * mBoxWidth, mGridHeight * mBoxHeight);
510
492
    if (!tRect.isPointInRect(pointX, pointY))
511
493
        return -1;
512
 
    const int index = (((pointY - 25) / mBoxHeight) * mGridWidth) +
513
 
        (pointX - 10) / mBoxWidth;
 
494
    const int index = (((pointY - mTitleBarHeight) / mBoxHeight) * mGridWidth)
 
495
        + (pointX - mPadding) / mBoxWidth;
514
496
    if (index >= static_cast<int>(OUTFIT_ITEM_COUNT) || index < 0)
515
497
        return -1;
516
498
    return index;
665
647
    wearOutfit(OUTFITS_COUNT);
666
648
}
667
649
 
668
 
void OutfitWindow::setItemSelected(const Item *const item)
669
 
{
670
 
    if (item)
671
 
    {
672
 
        mItemSelected = item->getId();
673
 
        mItemColorSelected = item->getColor();
674
 
    }
675
 
    else
676
 
    {
677
 
        mItemSelected = -1;
678
 
        mItemColorSelected = 1;
679
 
    }
680
 
}
681
 
 
682
650
void OutfitWindow::clearCurrentOutfit()
683
651
{
684
652
    if (mCurrentOutfit < 0 || mCurrentOutfit