void NetPlayDiag::OnStart(wxCommandEvent&) { NetSettings settings; GetNetSettings(settings); netplay_server->SetNetSettings(settings); netplay_server->StartGame(FindGame()); }
void GameListModel::RemoveGame(const std::string& path) { int entry = FindGame(path); if (entry < 0) return; beginRemoveRows(QModelIndex(), entry, entry); m_games.removeAt(entry); endRemoveRows(); }
void GameListModel::UpdateGame(const std::shared_ptr<const UICommon::GameFile>& game) { int index = FindGame(game->GetFilePath()); if (index < 0) { AddGame(game); } else { m_games[index] = game; emit dataChanged(createIndex(index, 0), createIndex(index + 1, columnCount(QModelIndex()))); } }
void GameListModel::UpdateGame(const std::shared_ptr<const UICommon::GameFile>& game) { int index = FindGame(game->GetFilePath()); if (index < 0) { beginInsertRows(QModelIndex(), m_games.size(), m_games.size()); m_games.push_back(game); endInsertRows(); } else { m_games[index] = game; emit dataChanged(createIndex(index, 0), createIndex(index + 1, columnCount(QModelIndex()))); } }
// update gui void NetPlayDiag::OnThread(wxCommandEvent& event) { // player list m_playerids.clear(); std::string tmps; netplay_client->GetPlayerList(tmps, m_playerids); const int selection = m_player_lbox->GetSelection(); m_player_lbox->Clear(); std::istringstream ss(tmps); while (std::getline(ss, tmps)) m_player_lbox->Append(StrToWxStr(tmps)); m_player_lbox->SetSelection(selection); switch (event.GetId()) { case NP_GUI_EVT_CHANGE_GAME : // update selected game :/ { m_selected_game.assign(WxStrToStr(event.GetString())); m_game_btn->SetLabel(event.GetString().Prepend(_(" Game : "))); } break; case NP_GUI_EVT_START_GAME : // client start game :/ { netplay_client->StartGame(FindGame()); } break; case NP_GUI_EVT_STOP_GAME : // client stop game { netplay_client->StopGame(); } break; } // chat messages while (chat_msgs.Size()) { std::string s; chat_msgs.Pop(s); //PanicAlert("message: %s", s.c_str()); m_chat_text->AppendText(StrToWxStr(s).Append('\n')); } }
// update gui void NetPlayDialog::OnThread(wxThreadEvent& event) { if (m_is_hosting && m_host_label && g_TraversalClient) { UpdateHostLabel(); } // player list m_playerids.clear(); std::string tmps; netplay_client->GetPlayerList(tmps, m_playerids); wxString selection; if (m_player_lbox->GetSelection() != wxNOT_FOUND) selection = m_player_lbox->GetString(m_player_lbox->GetSelection()); m_player_lbox->Clear(); std::istringstream ss(tmps); while (std::getline(ss, tmps)) m_player_lbox->Append(StrToWxStr(tmps)); // remove ping from selection string, in case it has changed selection.erase(selection.rfind('|') + 1); if (!selection.empty()) { for (unsigned int i = 0; i < m_player_lbox->GetCount(); ++i) { if (selection == m_player_lbox->GetString(i).substr(0, selection.length())) { m_player_lbox->SetSelection(i); break; } } } // flash window in taskbar when someone joins if window isn't active static u8 numPlayers = 1; if (netplay_server != nullptr && numPlayers < m_playerids.size() && !HasFocus()) { RequestUserAttention(); } numPlayers = m_playerids.size(); switch (event.GetId()) { case NP_GUI_EVT_CHANGE_GAME: // update selected game :/ { m_selected_game = WxStrToStr(event.GetString()); wxString button_label = event.GetString(); m_game_btn->SetLabel(button_label.Prepend(_(" Game : "))); } break; case NP_GUI_EVT_START_GAME: // client start game :/ { netplay_client->StartGame(FindGame()); } break; case NP_GUI_EVT_STOP_GAME: // client stop game { netplay_client->StopGame(); } break; } // chat messages while (chat_msgs.Size()) { std::string s; chat_msgs.Pop(s); // PanicAlert("message: %s", s.c_str()); m_chat_text->AppendText(StrToWxStr(s).Append('\n')); } }
std::string NetPlayDialog::FindCurrentGame() { return FindGame(m_selected_game); }