~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/gui/widgets/itemshortcutcontainer.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-07-11 10:09:41 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20130711100941-f0rwuvcwgl8ulqo8
Tags: 1.3.7.7.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "client.h"
26
26
#include "configuration.h"
 
27
#include "dragdrop.h"
27
28
#include "inventory.h"
28
29
#include "inputmanager.h"
29
30
#include "item.h"
50
51
ItemShortcutContainer::ItemShortcutContainer(const unsigned number) :
51
52
    ShortcutContainer(),
52
53
    mItemClicked(false),
53
 
    mItemMoved(nullptr),
54
54
    mNumber(number),
55
55
    mItemPopup(new ItemPopup),
56
56
    mSpellPopup(new SpellPopup),
222
222
            }
223
223
        }
224
224
    }
225
 
 
226
 
    if (mItemMoved)
227
 
    {
228
 
        // Draw the item image being dragged by the cursor.
229
 
        const Image *const image = mItemMoved->getImage();
230
 
        if (image)
231
 
        {
232
 
            const int tPosX = mCursorPosX - (image->mBounds.w / 2);
233
 
            const int tPosY = mCursorPosY - (image->mBounds.h / 2);
234
 
            const std::string str = toString(mItemMoved->getQuantity());
235
 
 
236
 
            g->drawImage(image, tPosX, tPosY);
237
 
            font->drawString(g, str,
238
 
                tPosX + (mBoxWidth - font->getWidth(str)) / 2,
239
 
                tPosY + mBoxHeight - 14);
240
 
        }
241
 
    }
242
225
    BLOCK_END("ItemShortcutContainer::draw")
243
226
}
244
227
 
250
233
 
251
234
    if (event.getButton() == gcn::MouseEvent::LEFT)
252
235
    {
253
 
        if (!mItemMoved && mItemClicked)
 
236
        if (dragDrop.isEmpty() && mItemClicked)
254
237
        {
 
238
            mItemClicked = false;
 
239
 
255
240
            const int index = getIndexFromGrid(event.getX(), event.getY());
256
241
            if (index == -1)
257
242
                return;
262
247
            if (itemId < 0)
263
248
                return;
264
249
 
 
250
            event.consume();
265
251
            if (itemId < SPELL_MIN_ID)
266
 
            {
 
252
            {   // items
267
253
                if (!PlayerInfo::getInventory())
268
254
                    return;
269
255
 
270
 
                Item *const item = PlayerInfo::getInventory()->findItem(
 
256
                const Item *const item = PlayerInfo::getInventory()->findItem(
271
257
                    itemId, itemColor);
272
258
 
273
259
                if (item)
274
260
                {
275
 
                    mItemMoved = item;
276
261
                    selShortcut->removeItem(index);
 
262
                    dragDrop.dragItem(item, DRAGDROP_SOURCE_SHORTCUTS, index);
 
263
                }
 
264
                else
 
265
                {
 
266
                    dragDrop.clear();
277
267
                }
278
268
            }
279
 
            else if (itemId < SKILL_MIN_ID && spellManager)
280
 
            {
 
269
            else if (itemId < SKILL_MIN_ID)
 
270
            {   // spells/commands
 
271
                if (!spellManager)
 
272
                {
 
273
                    dragDrop.clear();
 
274
                    return;
 
275
                }
 
276
 
281
277
                const TextCommand *const spell = spellManager->getSpellByItem(
282
278
                    itemId);
283
279
                if (spell)
 
280
                {
284
281
                    selShortcut->removeItem(index);
 
282
                    dragDrop.dragCommand(spell,
 
283
                        DRAGDROP_SOURCE_SHORTCUTS, index);
 
284
                    dragDrop.setItem(itemId);
 
285
                }
 
286
                else
 
287
                {
 
288
                    dragDrop.clear();
 
289
                }
285
290
            }
286
291
            else
287
 
            {
288
 
                selShortcut->removeItem(index);
 
292
            {   // skills
 
293
                if (!skillDialog)
 
294
                {
 
295
                    dragDrop.clear();
 
296
                    return;
 
297
                }
 
298
                const SkillInfo *const skill
 
299
                    = skillDialog->getSkillByItem(itemId);
 
300
                if (skill)
 
301
                {
 
302
                    selShortcut->removeItem(index);
 
303
                    dragDrop.dragSkill(skill,
 
304
                        DRAGDROP_SOURCE_SHORTCUTS, index);
 
305
                    dragDrop.setItem(itemId);
 
306
                }
 
307
                else
 
308
                {
 
309
                    dragDrop.clear();
 
310
                }
289
311
            }
290
312
        }
291
 
        if (mItemMoved)
292
 
        {
293
 
            mCursorPosX = event.getX();
294
 
            mCursorPosY = event.getY();
295
 
        }
296
313
    }
297
314
}
298
315
 
348
365
 
349
366
        const int index = getIndexFromGrid(event.getX(), event.getY());
350
367
        if (index == -1)
351
 
        {
352
 
            mItemMoved = nullptr;
353
368
            return;
354
 
        }
355
 
        if (mItemMoved)
356
 
        {
357
 
            selShortcut->setItems(index, mItemMoved->getId(),
358
 
                mItemMoved->getColor());
359
 
            mItemMoved = nullptr;
360
 
        }
361
 
        else if (selShortcut->getItem(index) && mItemClicked)
362
 
        {
363
 
            selShortcut->useItem(index);
364
 
        }
365
 
 
366
 
        if (mItemClicked)
367
 
            mItemClicked = false;
 
369
 
 
370
        if (dragDrop.isEmpty())
 
371
        {
 
372
            if (selShortcut->getItem(index) && mItemClicked)
 
373
                selShortcut->useItem(index);
 
374
        }
 
375
        else
 
376
        {
 
377
            if (dragDrop.getSource() == DRAGDROP_SOURCE_SHORTCUTS)
 
378
            {
 
379
                const int oldIndex = dragDrop.getTag();
 
380
                selShortcut->setItem(oldIndex, dragDrop.getItem(),
 
381
                    dragDrop.getItemColor());
 
382
                selShortcut->swap(oldIndex, index);
 
383
            }
 
384
            else
 
385
            {
 
386
                selShortcut->setItem(index, dragDrop.getItem(),
 
387
                    dragDrop.getItemColor());
 
388
            }
 
389
            dragDrop.clear();
 
390
            dragDrop.deselect();
 
391
        }
 
392
 
 
393
        mItemClicked = false;
368
394
    }
369
395
}
370
396