QTfrontend/pages.cpp
changeset 3786 0907b0fd5714
parent 3767 2416a3f51c77
child 3833 58afaa38781b
equal deleted inserted replaced
3785:7056284fd97c 3786:0907b0fd5714
  1061     roomsList->verticalHeader()->setVisible(false);
  1061     roomsList->verticalHeader()->setVisible(false);
  1062     roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
  1062     roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
  1063     roomsList->setAlternatingRowColors(true);
  1063     roomsList->setAlternatingRowColors(true);
  1064     pageLayout->addWidget(roomsList, 1, 0, 3, 1);
  1064     pageLayout->addWidget(roomsList, 1, 0, 3, 1);
  1065     pageLayout->setRowStretch(2, 100);
  1065     pageLayout->setRowStretch(2, 100);
       
  1066     
       
  1067     QHBoxLayout * filterLayout = new QHBoxLayout();
       
  1068     
       
  1069     QLabel * stateLabel = new QLabel(this);
       
  1070     stateLabel->setText(tr("State:"));
       
  1071     CBState = new QComboBox(this);
       
  1072     CBState->addItem(QComboBox::tr("Any"));
       
  1073     CBState->addItem(QComboBox::tr("In lobby"));
       
  1074     CBState->addItem(QComboBox::tr("In progress"));
       
  1075     filterLayout->addWidget(stateLabel);
       
  1076     filterLayout->addWidget(CBState);
       
  1077     filterLayout->addSpacing(30);
       
  1078     
       
  1079     QLabel * ruleLabel = new QLabel(this);
       
  1080     ruleLabel->setText(tr("Rules:"));
       
  1081     CBRules = new QComboBox(this);
       
  1082     CBRules->addItem(QComboBox::tr("Any"));
       
  1083     CBRules->addItem(QComboBox::tr("Default"));
       
  1084     CBRules->addItem(QComboBox::tr("Pro mode"));
       
  1085     CBRules->addItem(QComboBox::tr("Shoppa"));
       
  1086     CBRules->addItem(QComboBox::tr("Basketball"));
       
  1087     CBRules->addItem(QComboBox::tr("Minefield"));
       
  1088     CBRules->addItem(QComboBox::tr("Barrel mayhem"));
       
  1089     CBRules->addItem(QComboBox::tr("Tunnel hogs"));
       
  1090     filterLayout->addWidget(ruleLabel);
       
  1091     filterLayout->addWidget(CBRules);
       
  1092     filterLayout->addSpacing(30);
       
  1093     
       
  1094     QLabel * weaponLabel = new QLabel(this);
       
  1095     weaponLabel->setText(tr("Weapons:"));
       
  1096     CBWeapons = new QComboBox(this);
       
  1097     CBWeapons->addItem(QComboBox::tr("Any"));
       
  1098     CBWeapons->addItem(QComboBox::tr("Basketball"));
       
  1099     CBWeapons->addItem(QComboBox::tr("Crazy"));
       
  1100     CBWeapons->addItem(QComboBox::tr("Default"));
       
  1101     CBWeapons->addItem(QComboBox::tr("Minefield"));
       
  1102     CBWeapons->addItem(QComboBox::tr("Pro mode"));
       
  1103     CBWeapons->addItem(QComboBox::tr("Shoppa"));
       
  1104     filterLayout->addWidget(weaponLabel);
       
  1105     filterLayout->addWidget(CBWeapons);
       
  1106     filterLayout->addSpacing(30);
       
  1107 
       
  1108     QLabel * searchLabel = new QLabel(this);
       
  1109     searchLabel->setText(tr("Search:"));
       
  1110     searchText = new QLineEdit(this);
       
  1111     searchText->setMaxLength(60);
       
  1112     filterLayout->addWidget(searchLabel);
       
  1113     filterLayout->addWidget(searchText);
       
  1114 
       
  1115     pageLayout->addLayout(filterLayout, 4, 0);
  1066 
  1116 
  1067     chatWidget = new HWChatWidget(this, gameSettings, sdli, false);
  1117     chatWidget = new HWChatWidget(this, gameSettings, sdli, false);
  1068     pageLayout->addWidget(chatWidget, 4, 0, 1, 2);
  1118     pageLayout->addWidget(chatWidget, 5, 0, 1, 2);
  1069     pageLayout->setRowStretch(4, 350);
  1119     pageLayout->setRowStretch(5, 350);
  1070 
  1120 
  1071     BtnCreate = addButton(tr("Create"), pageLayout, 0, 1);
  1121     BtnCreate = addButton(tr("Create"), pageLayout, 0, 1);
  1072     BtnJoin = addButton(tr("Join"), pageLayout, 1, 1);
  1122     BtnJoin = addButton(tr("Join"), pageLayout, 1, 1);
  1073     BtnRefresh = addButton(tr("Refresh"), pageLayout, 3, 1);
  1123     BtnRefresh = addButton(tr("Refresh"), pageLayout, 3, 1);
  1074 
  1124     BtnClear = addButton(tr("Clear"), pageLayout, 4, 1);
  1075     BtnBack = addButton(":/res/Exit.png", pageLayout, 5, 0, true);
  1125 
  1076     BtnAdmin = addButton(tr("Admin features"), pageLayout, 5, 1);
  1126     BtnBack = addButton(":/res/Exit.png", pageLayout, 6, 0, true);
       
  1127     BtnAdmin = addButton(tr("Admin features"), pageLayout, 6, 1);
  1077 
  1128 
  1078     connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick()));
  1129     connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick()));
  1079     connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick()));
  1130     connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick()));
  1080     connect(BtnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClick()));
  1131     connect(BtnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClick()));
       
  1132     connect(BtnClear, SIGNAL(clicked()), this, SLOT(onClearClick()));
  1081     connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick()));
  1133     connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick()));
       
  1134     connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
       
  1135     connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
       
  1136     connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
       
  1137     connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onRefreshClick()));
       
  1138     connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection);
       
  1139     
       
  1140     gameInLobby = false;
  1082 }
  1141 }
  1083 
  1142 
  1084 void PageRoomsList::setAdmin(bool flag)
  1143 void PageRoomsList::setAdmin(bool flag)
  1085 {
  1144 {
  1086     BtnAdmin->setVisible(flag);
  1145     BtnAdmin->setVisible(flag);
  1087 }
  1146 }
  1088 
  1147 
  1089 void PageRoomsList::setRoomsList(const QStringList & list)
  1148 void PageRoomsList::setRoomsList(const QStringList & list)
  1090 {
  1149 {
       
  1150     listFromServer = list;
       
  1151     
  1091     roomsList->clear();
  1152     roomsList->clear();
  1092     roomsList->setColumnCount(7);
  1153     roomsList->setColumnCount(7);
  1093     roomsList->setHorizontalHeaderLabels(
  1154     roomsList->setHorizontalHeaderLabels(
  1094             QStringList() <<
  1155             QStringList() <<
  1095             QTableWidget::tr("Room Name") <<
  1156             QTableWidget::tr("Room Name") <<
  1111 //  roomsList->horizontalHeader()->resizeSection(6, 100);
  1172 //  roomsList->horizontalHeader()->resizeSection(6, 100);
  1112 
  1173 
  1113     // set resize modes
  1174     // set resize modes
  1114 //  roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
  1175 //  roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
  1115 
  1176 
       
  1177     bool gameCanBeJoined = true;
       
  1178 
  1116     if (list.size() % 8)
  1179     if (list.size() % 8)
  1117         return;
  1180         return;
  1118 
  1181 
  1119     roomsList->setRowCount(list.size() / 8);
  1182     roomsList->setRowCount(list.size() / 8);
  1120     for(int i = 0, r = 0; i < list.size(); i += 8, r++)
  1183     for(int i = 0, r = 0; i < list.size(); i += 8, r++)
  1121     {
  1184     {
       
  1185         // if we are joining a game
       
  1186         if (gameInLobby) {
       
  1187             if (gameInLobbyName == list[i + 1]) {
       
  1188                 gameCanBeJoined = list[i].compare("True");
       
  1189             }
       
  1190         }
       
  1191         
       
  1192         // check filter settings
       
  1193         #define NO_FILTER_MATCH roomsList->setRowCount(roomsList->rowCount() - 1); --r; continue
       
  1194         
       
  1195         if (list[i].compare("True") && CBState->currentIndex() == 2) { NO_FILTER_MATCH; }
       
  1196         if (list[i].compare("False") && CBState->currentIndex() == 1) { NO_FILTER_MATCH; }
       
  1197         if (CBRules->currentIndex() != 0 && list[i + 6].compare(CBRules->currentText())) { NO_FILTER_MATCH; }
       
  1198         if (CBWeapons->currentIndex() != 0 && list[i + 7].compare(CBWeapons->currentText())) { NO_FILTER_MATCH; }
       
  1199         bool found = list[i + 1].contains(searchText->text(), Qt::CaseInsensitive);
       
  1200         if (!found) {
       
  1201             for (int a = 4; a <= 7; ++a) {
       
  1202                 QString compString = list[i + a];
       
  1203                 if (a == 5 && compString == "+rnd+") {
       
  1204                     compString = "Random Map";
       
  1205                 } else if (a == 5 && compString == "+maze+") {
       
  1206                     compString = "Random Maze";
       
  1207                 }
       
  1208                 if (compString.contains(searchText->text(), Qt::CaseInsensitive)) {
       
  1209                     found = true;
       
  1210                     break;
       
  1211                 }
       
  1212             }
       
  1213         }
       
  1214         if (!searchText->text().isEmpty() && !found) { NO_FILTER_MATCH; }
       
  1215         
  1122         QTableWidgetItem * item;
  1216         QTableWidgetItem * item;
  1123         item = new QTableWidgetItem(list[i + 1]); // room name
  1217         item = new QTableWidgetItem(list[i + 1]); // room name
  1124         item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  1218         item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  1125         
  1219         
  1126         // pick appropriate room icon and tooltip (game in progress yes/no; later maybe locked rooms etc.)
  1220         // pick appropriate room icon and tooltip (game in progress yes/no; later maybe locked rooms etc.)
  1189    roomsList->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
  1283    roomsList->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
  1190    roomsList->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents);
  1284    roomsList->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents);
  1191    roomsList->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents);
  1285    roomsList->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents);
  1192    roomsList->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents);
  1286    roomsList->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents);
  1193 
  1287 
       
  1288     if (gameInLobby) {
       
  1289         gameInLobby = false;
       
  1290         if (gameCanBeJoined) {
       
  1291             emit askForJoinRoom(gameInLobbyName);
       
  1292         } else {
       
  1293             emit askJoinConfirmation(gameInLobbyName);
       
  1294         }
       
  1295     }
       
  1296 
  1194 //  roomsList->resizeColumnsToContents();
  1297 //  roomsList->resizeColumnsToContents();
  1195 }
  1298 }
  1196 
  1299 
  1197 void PageRoomsList::onCreateClick()
  1300 void PageRoomsList::onCreateClick()
  1198 {
  1301 {
  1212     {
  1315     {
  1213         QMessageBox::critical(this,
  1316         QMessageBox::critical(this,
  1214                 tr("Error"),
  1317                 tr("Error"),
  1215                 tr("Please select room from the list"),
  1318                 tr("Please select room from the list"),
  1216                 tr("OK"));
  1319                 tr("OK"));
  1217         return ;
  1320         return;
  1218     }
  1321     }
  1219     emit askForJoinRoom(curritem->data(Qt::DisplayRole).toString());
  1322 
       
  1323     for (int i = 0; i < listFromServer.size(); i += 8) {
       
  1324         if (listFromServer[i + 1] == curritem->data(Qt::DisplayRole).toString()) {
       
  1325             gameInLobby = listFromServer[i].compare("True");
       
  1326             break;
       
  1327         }
       
  1328     }
       
  1329     
       
  1330     if (gameInLobby) {
       
  1331         gameInLobbyName = curritem->data(Qt::DisplayRole).toString();
       
  1332         emit askForRoomList();
       
  1333     } else {
       
  1334         emit askForJoinRoom(curritem->data(Qt::DisplayRole).toString());
       
  1335     }
  1220 }
  1336 }
  1221 
  1337 
  1222 void PageRoomsList::onRefreshClick()
  1338 void PageRoomsList::onRefreshClick()
  1223 {
  1339 {
  1224     emit askForRoomList();
  1340     emit askForRoomList();
  1225 }
  1341 }
  1226 
  1342 
       
  1343 void PageRoomsList::onClearClick()
       
  1344 {
       
  1345     CBState->setCurrentIndex(0);
       
  1346     CBRules->setCurrentIndex(0);
       
  1347     CBWeapons->setCurrentIndex(0);
       
  1348     searchText->clear();
       
  1349 }
       
  1350 
       
  1351 void PageRoomsList::onJoinConfirmation(const QString & room)
       
  1352 {
       
  1353     if (QMessageBox::warning(this,
       
  1354         tr("Warning"),
       
  1355         tr("The game you are trying to join has started.\nDo you still want to join the room?"),
       
  1356         QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
       
  1357     {
       
  1358         emit askForJoinRoom(room);
       
  1359     }
       
  1360 }
  1227 
  1361 
  1228 PageConnecting::PageConnecting(QWidget* parent) :
  1362 PageConnecting::PageConnecting(QWidget* parent) :
  1229     AbstractPage(parent)
  1363     AbstractPage(parent)
  1230 {
  1364 {
  1231     QGridLayout * pageLayout = new QGridLayout(this);
  1365     QGridLayout * pageLayout = new QGridLayout(this);