forked from Haroooold/motaGroup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackpack.cpp
96 lines (82 loc) · 2.35 KB
/
backpack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* File: backpack.cpp
* ----------------
* This file implements backpack.h interface.
*/
#include "backpack.h"
#include "Game.h"
#include "Mapfly.h"
#include <QDebug>
extern Game* game;
backpack::backpack()
{
}
/*
* Implementation notes: showFrame()
* ---------------------------------
* Draw the backpack frame.
*/
void backpack::showFrame()
{
// create frame
backpackFrame = new QGraphicsRectItem();
backpackFrame->setRect(220, 0, 200, 440);
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::darkCyan);
backpackFrame->setBrush(brush);
game->scene->addItem(backpackFrame);
backpackFrame->setFlag(QGraphicsItem::ItemIsFocusable); // avoid events' influence
backpackFrame->setFocus();
qDebug() << backpackFrame;
// add BACK button
backButton = new Button(QString("BACK"), 200, 40);
double bxPos = 220;
double byPos = 400;
backButton->setPos(bxPos, byPos);
connect(backButton, SIGNAL(clicked()), this, SLOT(back()));
game->scene->addItem(backButton);
// add Item button
for (int item_i = 0; item_i < itemButton.size(); item_i++) {
byPos = item_i*40;
itemButton[item_i]->setPos(bxPos, byPos);
game->scene->addItem(itemButton[item_i]);
if (itemButton[item_i]->getButtonText() == QString("FLY FLOOR")) {
connect(itemButton[item_i], SIGNAL(clicked()), this, SLOT(flyFloor()));
}
// connect
}
}
void backpack::addNewItem(int itemID)
{
itemButton.enqueue(new Button(getNameOfItem(itemID), 200, 40));
}
QString backpack::getNameOfItem(int itemID)
{
switch(itemID) {
case 303: return QString("FLY FLOOR");
case 304: return QString("MONSTER SEARCH");
default: return QString("???");
}
}
void backpack::back()
{
game->scene->removeItem(backpackFrame);
game->scene->removeItem(backButton);
for (int item_i = 0; item_i < itemButton.size(); item_i++) {
game->scene->removeItem(itemButton[item_i]);
}
game->hero->setFocusToSelf();
}
void backpack::flyFloor()
{
qDebug() << backpackFrame;
game->scene->removeItem(backpackFrame);
qDebug() << "aaaaaa";
game->scene->removeItem(backButton);
for (int item_i = 0; item_i < itemButton.size(); item_i++) {
game->scene->removeItem(itemButton[item_i]);
}
MapFly* mapfly = new MapFly();
mapfly->showFrame();
}