-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainmenuwidget2.cpp
182 lines (160 loc) · 4.39 KB
/
mainmenuwidget2.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "mainmenuwidget2.h"
#include <QTimer>
#include <QPixmap>
#include <QPainter>
#include "achievementwidget.h"
#include "basicpainter.h"
#include "mainmenuitems.h"
#include "gamecommonitems.h"
#include "puzzlemenuwidget.h"
#include "othergameinit.h"
#include "helpwidget2.h"
#include "mainmenuwidget.h"
#include "twoplayermainmenuwidget.h"
#define LOGICAL_WIDTH 1024
#define LOGICAL_HEIGHT 600
MainMenuWidget2::MainMenuWidget2()
{
achievementItem = new ButtonItem("Achievement");
achievementItem->setPos(QPointF(0.1, 0.55));
myItems.push_back(achievementItem);
helpItem = new ButtonItem("Help");
helpItem->setPos(QPointF(0.1, 0.65));
myItems.push_back(helpItem);
exitItem = new ButtonItem("Exit");
exitItem->setPos(QPointF(0.1, 0.8));
myItems.push_back(exitItem);
singleItem = new MainMenuGameItem(AbstractMainMenuItem::UnvisibleBig);
singleItem->setPos(QPointF(0.572, 0.4));
myItems.push_back(singleItem);
multipleItem = new MainMenuGameItem(AbstractMainMenuItem::UnvisibleBig);
multipleItem->setPos(QPointF(0.784, 0.69));
myItems.push_back(multipleItem);
}
void MainMenuWidget2::makePixmap(
#ifdef USE_PIXMAP
QPixmap& pixmap,
#else
QPainter* painter,
#endif
int width,
int height)
{
#ifdef USE_PIXMAP
makeBasicPixmap(pixmap, width, height);
addEffect(pixmap, width, height);
#else
makeBasicPixmap(painter, width, height);
addEffect(painter, width, height);
#endif
}
void MainMenuWidget2::makeBasicPixmap(
#ifdef USE_PIXMAP
QPixmap& pixmap,
#else
QPainter* painter,
#endif
int width,
int height)
{
#ifdef USE_PIXMAP
pixmap = QPixmap(width, height);
// Fill the pixmap with black background
pixmap.fill(Qt::black);
// Get the painter
QPainter *painter = new QPainter(&pixmap);
#endif
// Paint the background
BasicPainter::paintBackGround(BasicPainter::MainMenu2,
painter,
width,
height,
0);
// Paint the basic balls
BasicPainter::paintItems(painter,
myItems,
width,
height,
0);
#ifdef USE_PIXMAP
// End the paint and release the space
painter->end();
delete painter;
#endif
}
void MainMenuWidget2::addEffect(
#ifdef USE_PIXMAP
QPixmap& pixmap,
#else
QPainter* painter,
#endif
int width,
int height)
{
}
QPointF MainMenuWidget2::toScene(double xRate, double yRate)
{
return QPointF(xRate * LOGICAL_WIDTH,
yRate * LOGICAL_HEIGHT);
}
void MainMenuWidget2::dealPressed(QPointF mousePos, Qt::MouseButton button)
{
// Quit if it's a right button. May be abandoned later
if (button == Qt::RightButton)
{
emit giveControlTo(NULL, true);
delete this;
return;
}
// Create puzzle game if neccessary
if (helpItem->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
{
AbstractPixmapWidget *helpWidget = new HelpWidget2();
emit giveControlTo(helpWidget, false);
return;
}
// Go to achievement if neccessary
else if (achievementItem->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
{
AbstractPixmapWidget *achievementWidget = new AchievementWidget();
emit giveControlTo(achievementWidget, false);
return;
}
// Go to help if neccessary
else if (exitItem->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
{
emit giveControlTo(NULL, true);
delete this;
return;
}
// Exit if neccessary
else if (singleItem->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
{
AbstractPixmapWidget *menu = new MainMenuWidget();
emit giveControlTo(menu, false);
return;
}
// Two players timing game
else if (multipleItem->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
{
AbstractPixmapWidget *menu = new TwoPlayerMainMenuWidget();
emit giveControlTo(menu, false);
return;
}
}
void MainMenuWidget2::dealMoved(QPointF mousePos, Qt::MouseButton button)
{
}
void MainMenuWidget2::dealReleased(QPointF mousePos, Qt::MouseButton button)
{
}
MainMenuWidget2::~MainMenuWidget2()
{
// // Stop the timer
// t->stop();
// Release the space
// delete t;
for (int i = 0;i < myItems.size();++i)
delete myItems[i];
myItems.clear();
}