-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevelselectscene.cpp
70 lines (55 loc) · 1.95 KB
/
levelselectscene.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
#include "levelselectscene.h"
#include <QPushButton>
#include <QPainter>
#include <QMenuBar>
#include "mypushbutton.h"
#include "playscene.h"
#include <QSound>
LevelSelectScene::LevelSelectScene(QWidget *parent) :MyMainWindow(parent)
{
this->setWindowTitle("关卡选择");
//设置返回按扭
MyPushButton *btnback =new MyPushButton(":/res/BackButton.png",":/res/BackButtonSelected.png",this);
btnback->resize(72,32);
connect(btnback,&QPushButton::clicked,this,&LevelSelectScene::backBtnClicked);
btnback->move(this->width()-btnback->width(),this->height()-btnback->height());
//构建关卡按扭
const int colWidth = 70;
const int rowHeight = 70;
//设置偏移量
const int xOffset = 25;
const int yOffset = 130;
for(int i=0;i<20;i++){
MyPushButton *btn = new MyPushButton(":/res/LevelIcon.png",":/res/LevelIcon.png",this);
btn->resize(57,57);
btn->setText(QString::number(i+1));
int row = i/4;
int col = i%4;
int x = col*colWidth + xOffset;
int y = row*rowHeight + yOffset;
btn->move(x,y);
connect(btn,&MyPushButton::clicked,[=](){
QSound::play(":/res/TapButtonSound.wav");
PlayScene *playscene = new PlayScene(i+1);
playscene->setAttribute(Qt::WA_DeleteOnClose);
this->hide();
playscene->move(this->pos());
playscene->show();
connect(playscene,PlayScene::backBtnClicked,[=](){
QSound::play(":/res/BackButtonSound.wav");
this->move(playscene->pos());
this->show();
playscene->close();
});
});
}
}
void LevelSelectScene::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.translate(0,menuBar()->height());
QPixmap pm(":/res/OtherSceneBg.png");
painter.drawPixmap(0,0,this->width(),this->height(),pm);
pm.load(":/res/Title.png");
painter.drawPixmap(0,0,pm);
}