forked from miwelc/QTron
/
ventana.cpp
278 lines (243 loc) · 10.8 KB
/
ventana.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#include <QtGui>
#include "ventana.h"
Ventana::~Ventana() {
delete visorOpenGL;
}
Ventana::Ventana() {
setWindowTitle(tr("QTron. Miguel Cantón Cortés"));
visorOpenGL = new VisorOpenGL;
setCentralWidget(visorOpenGL);
crearMenu();
}
void Ventana::crearMenu() {
Juego = menuBar()->addMenu(tr("&Juego"));
nuevoJuego = new QAction(tr("&Empezar partida nueva"), this);
nuevoJuego->setStatusTip(tr("Empezar partida nueva"));
connect(nuevoJuego, SIGNAL(triggered()), this, SLOT(empezarPartida()));
Juego->addAction(nuevoJuego);
pausar = new QAction(tr("&Pausar partida"), this);
pausar->setStatusTip(tr("Pausar partida"));
connect(pausar, SIGNAL(triggered()), this, SLOT(pausarPartida()));
Juego->addAction(pausar);
terminar = new QAction(tr("&Finalizar Partida"), this);
terminar->setStatusTip(tr("Finalizar Partida"));
connect(terminar, SIGNAL(triggered()), this, SLOT(terminarPartida()));
Juego->addAction(terminar);
Juego->addSeparator();
salir = new QAction(tr("&Salir"), this);
salir->setStatusTip(tr("Salir"));
connect(salir, SIGNAL(triggered()), this, SLOT(close()));
Juego->addAction(salir);
Opciones = menuBar()->addMenu(tr("&Opciones"));
NJugadores = new QAction(tr("&Elegir número de jugadores"), this);
NJugadores->setStatusTip(tr("Elegir número de jugadores"));
connect(NJugadores, SIGNAL(triggered()), this, SLOT(elegirNJugadores()));
Opciones->addAction(NJugadores);
TamTablero = new QAction(tr("&Elegir el tamaño del tablero"), this);
TamTablero->setStatusTip(tr("Elegir el tamaño del tablero"));
connect(TamTablero, SIGNAL(triggered()), this, SLOT(elegirTamTablero()));
Opciones->addAction(TamTablero);
Velocidad = new QAction(tr("&Elegir velocidad de las motos"), this);
Velocidad->setStatusTip(tr("Elegir velocidad de las motos"));
connect(Velocidad, SIGNAL(triggered()), this, SLOT(setVelocidad()));
Opciones->addAction(Velocidad);
ModosVisualizacion = menuBar()->addMenu(tr("&Modos de Visualización"));
Reflejos = new QAction(tr("&Activar/Desactivar reflejos"), this);
Reflejos->setStatusTip(tr("Activar/Desactivar reflejos"));
connect(Reflejos, SIGNAL(triggered()), this, SLOT(elegirReflejos()));
ModosVisualizacion->addAction(Reflejos);
Ejes = new QAction(tr("&Mostrar/Ocultar ejes"), this);
Ejes->setStatusTip(tr("Mostrar/Ocultar ejes"));
connect(Ejes, SIGNAL(triggered()), this, SLOT(elegirEjes()));
ModosVisualizacion->addAction(Ejes);
ModosVisualizacion->addSeparator();
CamaraLibre = new QAction(tr("&Cámara Libre"), this);
CamaraLibre->setStatusTip(tr("Cámara Libre"));
connect(CamaraLibre, SIGNAL(triggered()), this, SLOT(setCamaraLibre()));
ModosVisualizacion->addAction(CamaraLibre);
ModosVisualizacion->addSeparator();
Puntos = new QAction(tr("&Puntos"), this);
Puntos->setStatusTip(tr("Puntos"));
connect(Puntos, SIGNAL(triggered()), this, SLOT(modoPuntos()));
ModosVisualizacion->addAction(Puntos);
Lineas = new QAction(tr("&Lineas"), this);
Lineas->setStatusTip(tr("Lineas"));
connect(Lineas, SIGNAL(triggered()), this, SLOT(modoLineas()));
ModosVisualizacion->addAction(Lineas);
Solido = new QAction(tr("&Solido"), this);
Solido->setStatusTip(tr("Solido"));
connect(Solido, SIGNAL(triggered()), this, SLOT(modoSolido()));
ModosVisualizacion->addAction(Solido);
Ajedrez = new QAction(tr("&Ajedrez"), this);
Ajedrez->setStatusTip(tr("Ajedrez"));
connect(Ajedrez, SIGNAL(triggered()), this, SLOT(modoAjedrez()));
ModosVisualizacion->addAction(Ajedrez);
this->Flat = new QAction(tr("&Suavizado Flat"), this);
this->Flat->setStatusTip(tr("Suavizado Flat"));
connect(this->Flat, SIGNAL(triggered()), this, SLOT(modoFlat()));
ModosVisualizacion->addAction(this->Flat);
Smooth = new QAction(tr("&Suavizado Smooth"), this);
Smooth->setStatusTip(tr("Suavizado Smooth"));
connect(Smooth, SIGNAL(triggered()), this, SLOT(modoSmooth()));
ModosVisualizacion->addAction(Smooth);
fullScreen = menuBar()->addMenu(tr("&Pantalla"));
pantCompleta = new QAction(tr("&Completa"), this);
pantCompleta->setStatusTip(tr("Completa"));
connect(pantCompleta, SIGNAL(triggered()), this, SLOT(showFullScreen()));
fullScreen->addAction(pantCompleta);
pantNormal = new QAction(tr("&Ventana"), this);
pantNormal->setStatusTip(tr("Ventana"));
connect(pantNormal, SIGNAL(triggered()), this, SLOT(showNormal()));
fullScreen->addAction(pantNormal);
Extra = menuBar()->addMenu(tr("&Extra"));
Ayuda = new QAction(tr("&Ayuda"), this);
Ayuda->setStatusTip(tr("Ayuda"));
connect(Ayuda, SIGNAL(triggered()), this, SLOT(showAyuda()));
Extra->addAction(Ayuda);
Acerca = new QAction(tr("&Acerca"), this);
Acerca->setStatusTip(tr("Acerca"));
connect(Acerca, SIGNAL(triggered()), this, SLOT(showAcerca()));
Extra->addAction(Acerca);
Extra->addSeparator();
Demo = new QAction(tr("&Demo"), this);
Demo->setStatusTip(tr("Demo"));
connect(Demo, SIGNAL(triggered()), this, SLOT(showDemo()));
Extra->addAction(Demo);
}
void Ventana::empezarPartida() {
visorOpenGL->setModo(JUEGO);
visorOpenGL->juego.iniciarPartida();
}
void Ventana::pausarPartida() {
visorOpenGL->juego.pausarPartida();
}
void Ventana::terminarPartida() {
visorOpenGL->setModo(MENU);
}
void Ventana::elegirNJugadores() {
bool ok;
int i = QInputDialog::getInteger(this, tr("Número de Jugadores"),tr("Número:"), 2, 1, 8, 1, &ok);
if(ok)
visorOpenGL->juego.setNumeroMotos(i);
}
void Ventana::elegirTamTablero() {
bool ok;
int i = QInputDialog::getInteger(this, tr("Tamaño de tablero"),tr("Tamaño:"), 300, 100, 1000, 10, &ok);
if(ok)
visorOpenGL->juego.setTamanoTablero(i);
}
void Ventana::setVelocidad() {
bool ok;
int i = QInputDialog::getInteger(this, tr("Velocidad de las motos"),tr("Velocidad:"), 3, 1, 10, 1, &ok);
if(ok)
visorOpenGL->juego.motos.setVelocidadMotos(i/10.0);
}
void Ventana::elegirReflejos() {
QStringList opciones;
opciones << tr("Activar Reflejos") << tr("Desactivar Reflejos");
bool ok;
QString item = QInputDialog::getItem(this, tr("Opciones"),tr("Elección:"), opciones, 0, false, &ok);
if(ok && !item.isEmpty())
visorOpenGL->juego.setReflejos(item == tr("Activar Reflejos"));
}
void Ventana::elegirEjes() {
QStringList opciones;
opciones << tr("Mostrar Ejes") << tr("Ocultar Ejes");
bool ok;
QString item = QInputDialog::getItem(this, tr("Opciones"),tr("Elección:"), opciones, 0, false, &ok);
if(ok && !item.isEmpty())
visorOpenGL->juego.setEjes(item == tr("Mostrar Ejes"));
}
void Ventana::modoPuntos() {
visorOpenGL->juego.setModoDibujo(0);
visorOpenGL->demo.setModoDibujo(0);
}
void Ventana::modoLineas() {
visorOpenGL->juego.setModoDibujo(1);
visorOpenGL->demo.setModoDibujo(1);
}
void Ventana::modoSolido() {
visorOpenGL->juego.setModoDibujo(2);
visorOpenGL->demo.setModoDibujo(2);
}
void Ventana::modoAjedrez() {
visorOpenGL->juego.setModoDibujo(3);
visorOpenGL->demo.setModoDibujo(3);
}
void Ventana::modoFlat() {
visorOpenGL->juego.setModoDibujo(4);
visorOpenGL->juego.setModoSuavizado(GL_FLAT);
visorOpenGL->demo.setModoDibujo(4);
visorOpenGL->demo.setModoSuavizado(GL_FLAT);
}
void Ventana::modoSmooth() {
visorOpenGL->juego.setModoDibujo(4);
visorOpenGL->juego.setModoSuavizado(GL_SMOOTH);
visorOpenGL->demo.setModoDibujo(4);
visorOpenGL->demo.setModoSuavizado(GL_SMOOTH);
}
void Ventana::setCamaraLibre() {
QStringList opciones;
opciones << tr("Activar") << tr("Desactivar") << "" << tr("Configurar cámara nueva");
bool ok;
QString item = QInputDialog::getItem(this, tr("Cámara Libre"),tr("Elección:"), opciones, 0, false, &ok);
if(ok && !item.isEmpty()) {
visorOpenGL->juego.setCamaraLibre(item == tr("Activar"));
if(item == tr("Configurar cámara nueva")) {
Vertice VRP;
Vertice VPN;
Vertice VUP;
VRP.x = QInputDialog::getDouble(this, tr("Configurar cámara nueva"),tr("VRP.x:"), -15, -150, 150, 0.5, &ok);
if(!ok) return;
VRP.y = QInputDialog::getDouble(this, tr("Configurar cámara nueva"),tr("VRP.y:"), 10, -150, 150, 0.5, &ok);
if(!ok) return;
VRP.z = QInputDialog::getDouble(this, tr("Configurar cámara nueva"),tr("VRP.z:"), -20, -150, 150, 0.5, &ok);
if(!ok) return;
VPN.x = QInputDialog::getDouble(this, tr("Configurar cámara nueva"),tr("VPN.x:"), 0, -150, 150, 0.5, &ok);
if(!ok) return;
VPN.y = QInputDialog::getDouble(this, tr("Configurar cámara nueva"),tr("VPN.y:"), 0.5, -150, 150, 0.5, &ok);
if(!ok) return;
VPN.z = QInputDialog::getDouble(this, tr("Configurar cámara nueva"),tr("VPN.z:"), -1, -150, 150, 0.5, &ok);
if(!ok) return;
VUP.x = QInputDialog::getDouble(this, tr("Configurar cámara nueva"),tr("VUP.x:"), 0, -150, 150, 0.5, &ok);
if(!ok) return;
VUP.y = QInputDialog::getDouble(this, tr("Configurar cámara nueva"),tr("VUP.y:"), 1, -150, 150, 0.5, &ok);
if(!ok) return;
VUP.z = QInputDialog::getDouble(this, tr("Configurar cámara nueva"),tr("VUP.z:"), 0, -150, 150, 0.5, &ok);
if(!ok) return;
visorOpenGL->demo.camara.configurarCamara(VRP, VPN, VUP);
visorOpenGL->juego.camaraLibre.configurarCamara(VRP, VPN, VUP);
visorOpenGL->juego.setCamaraLibre(true);
}
}
}
void Ventana::showAcerca() {
QMessageBox msgBox;
QString mensaje = QString("Juego creado por Miguel Cantón Cortés. (Informática Gráfica, 2011) ");
msgBox.setText(mensaje);
msgBox.setWindowTitle("Acerca");
msgBox.exec();
}
void Ventana::showAyuda() {
QMessageBox msgBox;
QString mensaje = QString("Mostrando ayuda...");
visorOpenGL->menu.showAyuda();
visorOpenGL->setModo(MENU);
msgBox.setText(mensaje);
msgBox.setWindowTitle("Ayuda");
msgBox.exec();
visorOpenGL->menu.showFondo();
}
void Ventana::showDemo() {
QStringList opciones;
opciones << tr("Figuras") << tr("Hormigas");
bool ok;
QString item = QInputDialog::getItem(this, tr("Modo Demo"),tr("Modo:"), opciones, 0, false, &ok);
if(ok && !item.isEmpty()) {
if(item == tr("Figuras"))
visorOpenGL->demo.setModoDemo(FIGURAS);
else
visorOpenGL->demo.setModoDemo(HORMIGAS);
visorOpenGL->setModo(DEMO);
}
}