158 ammoSchemeModel = new AmmoSchemeModel(this, NULL); |
158 ammoSchemeModel = new AmmoSchemeModel(this, NULL); |
159 for (int i = 0; i < ammoSchemeModel->predefSchemesNames.count(); i++) |
159 for (int i = 0; i < ammoSchemeModel->predefSchemesNames.count(); i++) |
160 CBRules->addItem(ammoSchemeModel->predefSchemesNames.at(i).toAscii().constData()); |
160 CBRules->addItem(ammoSchemeModel->predefSchemesNames.at(i).toAscii().constData()); |
161 |
161 |
162 CBWeapons->addItem(QComboBox::tr("Any")); |
162 CBWeapons->addItem(QComboBox::tr("Any")); |
163 for (int i = 0; i < cDefaultAmmos.count(); i++) { |
163 for (int i = 0; i < cDefaultAmmos.count(); i++) |
|
164 { |
164 QPair<QString,QString> ammo = cDefaultAmmos.at(i); |
165 QPair<QString,QString> ammo = cDefaultAmmos.at(i); |
165 CBWeapons->addItem(ammo.first.toAscii().constData()); |
166 CBWeapons->addItem(ammo.first.toAscii().constData()); |
166 } |
167 } |
167 |
168 |
168 gameInLobby = false; |
169 gameInLobby = false; |
197 QBrush orange(QColor(127, 127, 0)); |
198 QBrush orange(QColor(127, 127, 0)); |
198 QBrush yellow(QColor(255, 255, 0)); |
199 QBrush yellow(QColor(255, 255, 0)); |
199 QBrush green(QColor(0, 255, 0)); |
200 QBrush green(QColor(0, 255, 0)); |
200 |
201 |
201 listFromServer = list; |
202 listFromServer = list; |
202 |
203 |
203 QString selection = ""; |
204 QString selection = ""; |
204 |
205 |
205 if(QTableWidgetItem *item = roomsList->item(roomsList->currentRow(), 0)) |
206 if(QTableWidgetItem *item = roomsList->item(roomsList->currentRow(), 0)) |
206 selection = item->text(); |
207 selection = item->text(); |
207 |
208 |
208 roomsList->clear(); |
209 roomsList->clear(); |
209 roomsList->setColumnCount(7); |
210 roomsList->setColumnCount(7); |
210 roomsList->setHorizontalHeaderLabels( |
211 roomsList->setHorizontalHeaderLabels( |
211 QStringList() << |
212 QStringList() << |
212 QTableWidget::tr("Room Name") << |
213 QTableWidget::tr("Room Name") << |
213 QTableWidget::tr("C") << |
214 QTableWidget::tr("C") << |
214 QTableWidget::tr("T") << |
215 QTableWidget::tr("T") << |
215 QTableWidget::tr("Owner") << |
216 QTableWidget::tr("Owner") << |
216 QTableWidget::tr("Map") << |
217 QTableWidget::tr("Map") << |
217 QTableWidget::tr("Rules") << |
218 QTableWidget::tr("Rules") << |
218 QTableWidget::tr("Weapons") |
219 QTableWidget::tr("Weapons") |
219 ); |
220 ); |
220 |
221 |
221 // set minimum sizes |
222 // set minimum sizes |
222 // roomsList->horizontalHeader()->resizeSection(0, 200); |
223 // roomsList->horizontalHeader()->resizeSection(0, 200); |
223 // roomsList->horizontalHeader()->resizeSection(1, 50); |
224 // roomsList->horizontalHeader()->resizeSection(1, 50); |
224 // roomsList->horizontalHeader()->resizeSection(2, 50); |
225 // roomsList->horizontalHeader()->resizeSection(2, 50); |
238 roomsList->setRowCount(list.size() / 8); |
239 roomsList->setRowCount(list.size() / 8); |
239 for(int i = 0, r = 0; i < list.size(); i += 8, r++) |
240 for(int i = 0, r = 0; i < list.size(); i += 8, r++) |
240 { |
241 { |
241 // if we are joining a game |
242 // if we are joining a game |
242 // TODO: Should NOT be done here |
243 // TODO: Should NOT be done here |
243 if (gameInLobby) { |
244 if (gameInLobby) |
244 if (gameInLobbyName == list[i + 1]) { |
245 { |
|
246 if (gameInLobbyName == list[i + 1]) |
|
247 { |
245 gameCanBeJoined = list[i].compare("True"); |
248 gameCanBeJoined = list[i].compare("True"); |
246 } |
249 } |
247 } |
250 } |
248 |
251 |
249 // check filter settings |
252 // check filter settings |
250 #define NO_FILTER_MATCH roomsList->setRowCount(roomsList->rowCount() - 1); --r; continue |
253 #define NO_FILTER_MATCH roomsList->setRowCount(roomsList->rowCount() - 1); --r; continue |
251 |
254 |
252 if (list[i].compare("True") && CBState->currentIndex() == 2) { NO_FILTER_MATCH; } |
255 if (list[i].compare("True") && CBState->currentIndex() == 2) |
253 if (list[i].compare("False") && CBState->currentIndex() == 1) { NO_FILTER_MATCH; } |
256 { |
254 if (CBRules->currentIndex() != 0 && list[i + 6].compare(CBRules->currentText())) { NO_FILTER_MATCH; } |
257 NO_FILTER_MATCH; |
255 if (CBWeapons->currentIndex() != 0 && list[i + 7].compare(CBWeapons->currentText())) { NO_FILTER_MATCH; } |
258 } |
|
259 if (list[i].compare("False") && CBState->currentIndex() == 1) |
|
260 { |
|
261 NO_FILTER_MATCH; |
|
262 } |
|
263 if (CBRules->currentIndex() != 0 && list[i + 6].compare(CBRules->currentText())) |
|
264 { |
|
265 NO_FILTER_MATCH; |
|
266 } |
|
267 if (CBWeapons->currentIndex() != 0 && list[i + 7].compare(CBWeapons->currentText())) |
|
268 { |
|
269 NO_FILTER_MATCH; |
|
270 } |
256 bool found = list[i + 1].contains(searchText->text(), Qt::CaseInsensitive); |
271 bool found = list[i + 1].contains(searchText->text(), Qt::CaseInsensitive); |
257 if (!found) { |
272 if (!found) |
258 for (int a = 4; a <= 7; ++a) { |
273 { |
|
274 for (int a = 4; a <= 7; ++a) |
|
275 { |
259 QString compString = list[i + a]; |
276 QString compString = list[i + a]; |
260 if (a == 5 && compString == "+rnd+") { |
277 if (a == 5 && compString == "+rnd+") |
|
278 { |
261 compString = "Random Map"; |
279 compString = "Random Map"; |
262 } else if (a == 5 && compString == "+maze+") { |
280 } |
|
281 else if (a == 5 && compString == "+maze+") |
|
282 { |
263 compString = "Random Maze"; |
283 compString = "Random Maze"; |
264 } else if (a == 5 && compString == "+drawn+") { |
284 } |
|
285 else if (a == 5 && compString == "+drawn+") |
|
286 { |
265 compString = "Drawn Map"; |
287 compString = "Drawn Map"; |
266 } |
288 } |
267 if (compString.contains(searchText->text(), Qt::CaseInsensitive)) { |
289 if (compString.contains(searchText->text(), Qt::CaseInsensitive)) |
|
290 { |
268 found = true; |
291 found = true; |
269 break; |
292 break; |
270 } |
293 } |
271 } |
294 } |
272 } |
295 } |
273 if (!searchText->text().isEmpty() && !found) { NO_FILTER_MATCH; } |
296 if (!searchText->text().isEmpty() && !found) |
274 |
297 { |
|
298 NO_FILTER_MATCH; |
|
299 } |
|
300 |
275 QTableWidgetItem * item; |
301 QTableWidgetItem * item; |
276 item = new QTableWidgetItem(list[i + 1]); // room name |
302 item = new QTableWidgetItem(list[i + 1]); // room name |
277 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); |
303 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); |
278 |
304 |
279 // pick appropriate room icon and tooltip (game in progress yes/no; later maybe locked rooms etc.) |
305 // pick appropriate room icon and tooltip (game in progress yes/no; later maybe locked rooms etc.) |
280 if(list[i].compare("True")) |
306 if(list[i].compare("True")) |
281 { |
307 { |
282 item->setIcon(QIcon(":/res/iconTime.png"));// game is in lobby |
308 item->setIcon(QIcon(":/res/iconTime.png"));// game is in lobby |
283 item->setToolTip(tr("This game is in lobby.\nYou may join and start playing once the game starts.")); |
309 item->setToolTip(tr("This game is in lobby.\nYou may join and start playing once the game starts.")); |
323 // item->setIcon(QIcon(":/res/mapMaze.png")); |
349 // item->setIcon(QIcon(":/res/mapMaze.png")); |
324 } |
350 } |
325 else |
351 else |
326 { |
352 { |
327 item = new QTableWidgetItem(list[i + 5]); // selected map |
353 item = new QTableWidgetItem(list[i + 5]); // selected map |
328 |
354 |
329 // check to see if we've got this map |
355 // check to see if we've got this map |
330 // not perfect but a start |
356 // not perfect but a start |
331 if(!mapList->contains(list[i + 5])) |
357 if(!mapList->contains(list[i + 5])) |
332 { |
358 { |
333 item->setForeground(red); |
359 item->setForeground(red); |
334 item->setIcon(QIcon(":/res/mapMissing.png")); |
360 item->setIcon(QIcon(":/res/mapMissing.png")); |
335 } |
361 } |
336 else |
362 else |
337 { |
363 { |
338 // todo: mission icon? |
364 // todo: mission icon? |
339 // FIXME - need real icons. Disabling until then |
365 // FIXME - need real icons. Disabling until then |
340 // item->setIcon(QIcon(":/res/mapCustom.png")); |
366 // item->setIcon(QIcon(":/res/mapCustom.png")); |
341 } |
367 } |
342 } |
368 } |
343 |
369 |
344 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); |
370 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); |
345 item->setToolTip(tr("Games may be played on precreated or randomized maps.")); |
371 item->setToolTip(tr("Games may be played on precreated or randomized maps.")); |
346 roomsList->setItem(r, 4, item); |
372 roomsList->setItem(r, 4, item); |
347 |
373 |
348 item = new QTableWidgetItem(list[i + 6].left(24)); // selected game scheme |
374 item = new QTableWidgetItem(list[i + 6].left(24)); // selected game scheme |
366 roomsList->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents); |
392 roomsList->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents); |
367 roomsList->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents); |
393 roomsList->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents); |
368 roomsList->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents); |
394 roomsList->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents); |
369 |
395 |
370 // TODO: Should NOT be done here |
396 // TODO: Should NOT be done here |
371 if (gameInLobby) { |
397 if (gameInLobby) |
|
398 { |
372 gameInLobby = false; |
399 gameInLobby = false; |
373 if (gameCanBeJoined) { |
400 if (gameCanBeJoined) |
|
401 { |
374 emit askForJoinRoom(gameInLobbyName); |
402 emit askForJoinRoom(gameInLobbyName); |
375 } else { |
403 } |
|
404 else |
|
405 { |
376 emit askJoinConfirmation(gameInLobbyName); |
406 emit askJoinConfirmation(gameInLobbyName); |
377 } |
407 } |
378 } |
408 } |
379 |
409 |
380 // roomsList->resizeColumnsToContents(); |
410 // roomsList->resizeColumnsToContents(); |
384 { |
414 { |
385 if (roomName->text().size()) |
415 if (roomName->text().size()) |
386 emit askForCreateRoom(roomName->text()); |
416 emit askForCreateRoom(roomName->text()); |
387 else |
417 else |
388 QMessageBox::critical(this, |
418 QMessageBox::critical(this, |
389 tr("Error"), |
419 tr("Error"), |
390 tr("Please enter room name"), |
420 tr("Please enter room name"), |
391 tr("OK")); |
421 tr("OK")); |
392 } |
422 } |
393 |
423 |
394 void PageRoomsList::onJoinClick() |
424 void PageRoomsList::onJoinClick() |
395 { |
425 { |
396 QTableWidgetItem * curritem = roomsList->item(roomsList->currentRow(), 0); |
426 QTableWidgetItem * curritem = roomsList->item(roomsList->currentRow(), 0); |
397 if (!curritem) |
427 if (!curritem) |
398 { |
428 { |
399 QMessageBox::critical(this, |
429 QMessageBox::critical(this, |
400 tr("Error"), |
430 tr("Error"), |
401 tr("Please select room from the list"), |
431 tr("Please select room from the list"), |
402 tr("OK")); |
432 tr("OK")); |
403 return; |
433 return; |
404 } |
434 } |
405 |
435 |
406 for (int i = 0; i < listFromServer.size(); i += 8) { |
436 for (int i = 0; i < listFromServer.size(); i += 8) |
407 if (listFromServer[i + 1] == curritem->data(Qt::DisplayRole).toString()) { |
437 { |
|
438 if (listFromServer[i + 1] == curritem->data(Qt::DisplayRole).toString()) |
|
439 { |
408 gameInLobby = listFromServer[i].compare("True"); |
440 gameInLobby = listFromServer[i].compare("True"); |
409 break; |
441 break; |
410 } |
442 } |
411 } |
443 } |
412 |
444 |
413 if (gameInLobby) { |
445 if (gameInLobby) |
|
446 { |
414 gameInLobbyName = curritem->data(Qt::DisplayRole).toString(); |
447 gameInLobbyName = curritem->data(Qt::DisplayRole).toString(); |
415 emit askForRoomList(); |
448 emit askForRoomList(); |
416 } else { |
449 } |
|
450 else |
|
451 { |
417 emit askForJoinRoom(curritem->data(Qt::DisplayRole).toString()); |
452 emit askForJoinRoom(curritem->data(Qt::DisplayRole).toString()); |
418 } |
453 } |
419 } |
454 } |
420 |
455 |
421 void PageRoomsList::onRefreshClick() |
456 void PageRoomsList::onRefreshClick() |