Example #1
0
// 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'));
    }
}
Example #2
0
// 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(FindCurrentGame());
    std::string msg = "Starting game";
    AddChatMessage(ChatMessageType::Info, msg);
  }
  break;
  case NP_GUI_EVT_STOP_GAME:
    // client stop game
  {
    std::string msg = "Stopping game";
    AddChatMessage(ChatMessageType::Info, msg);
  }
  break;
  case NP_GUI_EVT_DISPLAY_MD5_DIALOG:
  {
    m_MD5_dialog = new MD5Dialog(this, netplay_server, netplay_client->GetPlayers(),
      event.GetString().ToStdString());
    m_MD5_dialog->Show();
  }
  break;
  case NP_GUI_EVT_MD5_PROGRESS:
  {
    if (m_MD5_dialog == nullptr || m_MD5_dialog->IsBeingDeleted())
      break;

    std::pair<int, int> payload = event.GetPayload<std::pair<int, int>>();
    m_MD5_dialog->SetProgress(payload.first, payload.second);
  }
  break;
  case NP_GUI_EVT_MD5_RESULT:
  {
    if (m_MD5_dialog == nullptr || m_MD5_dialog->IsBeingDeleted())
      break;

    std::pair<int, std::string> payload = event.GetPayload<std::pair<int, std::string>>();
    m_MD5_dialog->SetResult(payload.first, payload.second);
  }
  break;
  case NP_GUI_EVT_PAD_BUFFER_CHANGE:
  {
    std::string msg = StringFromFormat("Buffer size: %d", m_pad_buffer);

    if (g_ActiveConfig.bShowNetPlayMessages)
    {
      OSD::AddTypedMessage(OSD::MessageType::NetPlayBuffer, msg, OSD::Duration::NORMAL);
    }

    AddChatMessage(ChatMessageType::Info, msg);
  }
  break;
  case NP_GUI_EVT_DESYNC:
  {
    std::string msg = "Possible desync detected from player " + m_desync_player + " on frame " +
      std::to_string(m_desync_frame);

    AddChatMessage(ChatMessageType::Error, msg);

    if (g_ActiveConfig.bShowNetPlayMessages)
    {
      OSD::AddMessage(msg, OSD::Duration::VERY_LONG, OSD::Color::RED);
    }
  }
  break;
  case NP_GUI_EVT_CONNECTION_LOST:
  {
    std::string msg = "Lost connection to server";
    AddChatMessage(ChatMessageType::Error, msg);
  }
  break;
  case NP_GUI_EVT_TRAVERSAL_CONNECTION_ERROR:
  {
    std::string msg = "Traversal server connection error";
    AddChatMessage(ChatMessageType::Error, msg);
  }
  }

  // chat messages
  while (m_chat_msgs.Size())
  {
    std::string s;
    m_chat_msgs.Pop(s);
    AddChatMessage(ChatMessageType::UserIn, s);

    if (g_ActiveConfig.bShowNetPlayMessages)
    {
      OSD::AddMessage(s, OSD::Duration::NORMAL, OSD::Color::GREEN);
    }
  }
}