| 174 | } |
| 175 | |
| 176 | bool MenuModeMasterServerJoin::clientButtonPressed(const CEGUI::EventArgs&) |
| 177 | { |
| 178 | CEGUI::Window* mainWin = getModeManager().getGui().getGuiSheet(Gui::guiSheet::multiMasterServerJoinMenu); |
| 179 | CEGUI::MultiColumnList* levelSelectList = static_cast<CEGUI::MultiColumnList*>( |
| 180 | mainWin->getChild("LevelWindowFrame/LevelSelect")); |
| 181 | CEGUI::Window* infoText = mainWin->getChild("LoadingText"); |
| 182 | |
| 183 | if(levelSelectList->getSelectedCount() == 0) |
| 184 | { |
| 185 | infoText->setText("Please select a level first."); |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | CEGUI::Editbox* editNick = static_cast<CEGUI::Editbox*>( |
| 190 | mainWin->getChild("LevelWindowFrame/NickEdit")); |
| 191 | std::string nick = editNick->getText().c_str(); |
| 192 | CEGUI::String nickCeguiStr = reinterpret_cast<const CEGUI::utf8*>(nick.c_str()); |
| 193 | if (nickCeguiStr.empty()) |
| 194 | { |
| 195 | infoText->setText("Please enter a nickname."); |
| 196 | return true; |
| 197 | } |
| 198 | else if (nickCeguiStr.length() > 20) |
| 199 | { |
| 200 | infoText->setText("Please enter a shorter nickname. (20 letters max.)"); |
| 201 | return true; |
| 202 | } |
| 203 | |
| 204 | CEGUI::ListboxItem* selItem = levelSelectList->getFirstSelectedItem(); |
| 205 | uint32_t id = selItem->getID(); |
| 206 | |
| 207 | if(id >= mMasterServerGames.size()) |
| 208 | { |
| 209 | OD_LOG_ERR("index too high=" + Helper::toString(id) + ", size=" + Helper::toString(mMasterServerGames.size())); |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | MasterServerGame& selGame = mMasterServerGames[id]; |
| 214 | |
| 215 | ODFrameListener::getSingleton().getClientGameMap()->setLocalPlayerNick(nick); |
| 216 | |
| 217 | const std::string& ip = selGame.mIp; |
| 218 | const int32_t& port = selGame.mPort; |
| 219 | uint32_t timeout = ConfigManager::getSingleton().getClientConnectionTimeout(); |
| 220 | std::string replayFilename = ResourceManager::getSingleton().getReplayDataPath() |
| 221 | + ResourceManager::getSingleton().buildReplayFilename(); |
| 222 | if(!ODClient::getSingleton().connect(ip, port, timeout, replayFilename)) |
| 223 | { |
| 224 | // Error while connecting |
| 225 | infoText->setText("Could not connect to: " + ip + ", port=" + Helper::toString(port)); |
| 226 | return true; |
| 227 | } |
| 228 | |
| 229 | infoText->setText("Loading..."); |
| 230 | return true; |
| 231 | } |
| 232 | |
| 233 | bool MenuModeMasterServerJoin::updateDescription(const CEGUI::EventArgs&) |
nothing calls this directly
no test coverage detected