1 #include "gamedialogs.h"
2
3 #include "scaler.h"
4 #include "gamestock.h"
5 #include "gamebutton.h"
6
7 ////////////////////////////////////////////////////////////////////////////////
8
9 class GradientButton : public GameButton
10 {
11 public:
GradientButton(GamePanel * parent,const QRect & rect,const QString & text)12 GradientButton(GamePanel *parent, const QRect &rect, const QString &text) :
13 GameButton(parent, rect, text)
14 {
15 setBackground(Qt::NoBrush);
16 setPen(QPen(QColor(Qt::white), 2));
17 setHoverBackground(QColor(0x2076b1));
18
19 setTextColor(Qt::white);
20 setTextHoverColor(Qt::white);
21
22 setFont(&gameStock->Font20);
23 }
24 };
25
26 ////////////////////////////////////////////////////////////////////////////////
27
28 #define ID_CANCEL 0
29 #define ID_OK 1
30
31 ////////////////////////////////////////////////////////////////////////////////
32
LevelWinDialog(GamePanelControl * panelControl)33 LevelWinDialog::LevelWinDialog(GamePanelControl *panelControl) :
34 GamePanel(panelControl, QRect(100,10,1024-100*2,768-20-70))
35 {
36 setBlocking();
37 setInsensitive();
38 //setBackBorderPaint(false);
39
40 setOpacity(0.9);
41 setPen(QPen(QColor(0x00ddff), 1));
42 setBackground(QColor(0x4b97c4));
43
44 setHoverPaint(false);
45
46 buttonOk = new GradientButton(this, QRect(1024-100-100-100-250,530,250,75), tr("Next Level"));
47 buttonOk->setId(ID_OK);
48 buttonOk->setPicture(&gameStock->Ok);
49
50 buttonCancel = new GradientButton(this, QRect(100,530,250,75), tr("Exit to Menu"));
51 buttonCancel->setId(ID_CANCEL);
52 buttonCancel->setPicture(&gameStock->Cancel);
53 }
54
paintContent(QPainter & p)55 void LevelWinDialog::paintContent(QPainter &p)
56 {
57 GamePanel::paintContent(p);
58
59 p.setOpacity(1);
60 p.setFont(gameStock->Font40);
61 p.setPen(QPen(QColor(0x030055)));
62
63 drawHCentered(p, 50, tr("Level %1 completed!").arg(level));
64
65 p.setFont(gameStock->Font20);
66
67 const int y30 = DY(40);
68
69 const int x1 = DX(300), x2 = DX(380), x3 = DX(600);
70 const int y1 = DY(250), y2 = DY(350);
71
72 p.drawPixmap(x1,y1, gameStock->Clock);
73 p.drawText(x3,y1+y30, QString("%1:%2").arg(time/60, 2, 10, QChar('0')).arg(time%60, 2, 10, QChar('0')));
74
75 p.drawPixmap(x1,y2, gameStock->Score);
76 p.drawText(x3,y2+y30, QString::number(score));
77
78 p.setPen(QPen(Qt::black));
79 p.drawText(x2,y1+y30, tr("Time left:"));
80 p.drawText(x2,y2+y30, tr("Score:"));
81 }
82
subcontrolClicked(int id)83 void LevelWinDialog::subcontrolClicked(int id)
84 {
85 switch (id)
86 {
87 case ID_OK:
88 emit okClicked();
89 close();
90 break;
91 case ID_CANCEL:
92 emit cancelClicked();
93 close();
94 break;
95 }
96 }
97
98 ////////////////////////////////////////////////////////////////////////////////
99
LevelFailDialog(GamePanelControl * panelControl)100 LevelFailDialog::LevelFailDialog(GamePanelControl *panelControl) :
101 LevelWinDialog(panelControl)
102 {
103 buttonOk->setText(tr("Restart Level"));
104 }
105
paintContent(QPainter & p)106 void LevelFailDialog::paintContent(QPainter &p)
107 {
108 GamePanel::paintContent(p);
109
110 p.setOpacity(1);
111 p.setFont(gameStock->Font40);
112 p.setPen(QPen(QColor(0x030055)));
113
114 drawHCentered(p, 50, tr("Level %1 failed :(").arg(level));
115
116 p.setFont(gameStock->Font20);
117
118 drawHCentered(p, 250, tr("Hope next time you'll do it better..."));
119 }
120
121 ////////////////////////////////////////////////////////////////////////////////
122
GameWinDialog(GamePanelControl * panelControl)123 GameWinDialog::GameWinDialog(GamePanelControl *panelControl) :
124 LevelWinDialog(panelControl)
125 {
126 buttonOk->setInvisible();
127
128 buttonCancel->setPosition(QPoint((rect().width()-250)/2, buttonCancel->rect().y()));
129 }
130
paintContent(QPainter & p)131 void GameWinDialog::paintContent(QPainter &p)
132 {
133 GamePanel::paintContent(p);
134
135 p.setOpacity(1);
136 p.setFont(gameStock->Font60);
137 p.setPen(QPen(QColor(0x030055)));
138
139 drawHCentered(p, 50, tr("You're the Winner!"));
140
141 p.setFont(gameStock->Font40);
142
143 drawHCentered(p, 200, tr("You finished all the levels!"));
144
145 p.setFont(gameStock->Font20);
146
147 const int y30 = DY(40);
148
149 const int x1 = DX(300), x2 = DX(420), x3 = DX(600);
150 const int /*y1 = DY(250), */y2 = DY(350)/*, y3 = DY(350)*/;
151
152 p.drawPixmap(x1,y2, gameStock->Score);
153 p.drawText(x3,y2+y30, QString::number(score));
154
155 p.setPen(QPen(Qt::black));
156 p.drawText(x2,y2+y30, tr("Score:"));
157 }
158
159 ////////////////////////////////////////////////////////////////////////////////
160