Improve netplay setup dialog UX

* Focus "Hash Code" / "IP address" text box by default in "Connect"
* Focus game list in "Host" tab
* RETURN keypress now host/join depending on selected tab
* Remember last hosted game
* Remove PanicAlertT:
	* Simply log message to netplay window
	* Remove them when they are useless
* Show some netplay message in OSD
	* Chat messages
	* Pad buffer changes
	* Desync alerts
* Stop the game consistently when another player disconnects / crashes
* Prettify chat textbox
* Log netplay ping to OSD

Join scenario:
* Copy netplay code
* Open netplay
* Paste code
* Press enter

Host scenario:
* Open netplay
* Go to host tab
* Press enter
This commit is contained in:
Aestek
2016-02-02 16:35:27 +01:00
parent aa34e5e20e
commit 6a0fc4c438
13 changed files with 428 additions and 178 deletions

View File

@ -12,6 +12,7 @@
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/clipbrd.h>
#include <wx/colour.h>
#include <wx/dialog.h>
#include <wx/frame.h>
#include <wx/listbox.h>
@ -48,29 +49,13 @@
#include "DolphinWX/WxUtils.h"
#include "MD5Dialog.h"
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/VideoConfig.h"
NetPlayServer* NetPlayDialog::netplay_server = nullptr;
NetPlayClient* NetPlayDialog::netplay_client = nullptr;
NetPlayDialog* NetPlayDialog::npd = nullptr;
static wxString FailureReasonStringForHostLabel(int reason)
{
switch (reason)
{
case TraversalClient::BadHost:
return _("(Error: Bad host)");
case TraversalClient::VersionTooOld:
return _("(Error: Dolphin too old)");
case TraversalClient::ServerForgotAboutUs:
return _("(Error: Disconnected)");
case TraversalClient::SocketSendError:
return _("(Error: Socket)");
case TraversalClient::ResendTimeout:
return _("(Error: Timeout)");
default:
return _("(Error: Unknown)");
}
}
static std::string BuildGameName(const GameListItem& game)
{
// Lang needs to be consistent
@ -280,13 +265,13 @@ NetPlayDialog::~NetPlayDialog()
void NetPlayDialog::OnChat(wxCommandEvent&)
{
wxString text = m_chat_msg_text->GetValue();
std::string text = WxStrToStr(m_chat_msg_text->GetValue());
if (!text.empty())
{
netplay_client->SendChatMessage(WxStrToStr(text));
m_chat_text->AppendText(text.Prepend(" >> ").Append('\n'));
netplay_client->SendChatMessage(text);
m_chat_msg_text->Clear();
AddChatMessage(ChatMessageType::UserOut, text);
}
}
@ -406,11 +391,46 @@ void NetPlayDialog::OnAdjustBuffer(wxCommandEvent& event)
{
const int val = ((wxSpinCtrl*)event.GetEventObject())->GetValue();
netplay_server->AdjustPadBufferSize(val);
}
std::ostringstream ss;
ss << "< Pad Buffer: " << val << " >";
netplay_client->SendChatMessage(ss.str());
m_chat_text->AppendText(StrToWxStr(ss.str()).Append('\n'));
void NetPlayDialog::OnPadBufferChanged(u32 buffer)
{
m_pad_buffer = buffer;
wxThreadEvent evt(wxEVT_THREAD, NP_GUI_EVT_PAD_BUFFER_CHANGE);
GetEventHandler()->AddPendingEvent(evt);
}
void NetPlayDialog::OnDesync(u32 frame, const std::string& player)
{
m_desync_frame = frame;
m_desync_player = player;
wxThreadEvent evt(wxEVT_THREAD, NP_GUI_EVT_DESYNC);
GetEventHandler()->AddPendingEvent(evt);
}
void NetPlayDialog::OnConnectionLost()
{
wxThreadEvent evt(wxEVT_THREAD, NP_GUI_EVT_CONNECTION_LOST);
GetEventHandler()->AddPendingEvent(evt);
}
void NetPlayDialog::OnTraversalError(int error)
{
switch (error)
{
case TraversalClient::BadHost:
PanicAlertT("Couldn't look up central server");
break;
case TraversalClient::VersionTooOld:
PanicAlertT("Dolphin is too old for traversal server");
break;
case TraversalClient::ServerForgotAboutUs:
case TraversalClient::SocketSendError:
case TraversalClient::ResendTimeout:
wxThreadEvent evt(wxEVT_THREAD, NP_GUI_EVT_TRAVERSAL_CONNECTION_ERROR);
GetEventHandler()->AddPendingEvent(evt);
break;
}
}
void NetPlayDialog::OnQuit(wxCommandEvent&)
@ -477,17 +497,16 @@ void NetPlayDialog::OnThread(wxThreadEvent& event)
case NP_GUI_EVT_START_GAME:
// client start game :/
{
std::string game = FindCurrentGame();
if (game.empty())
WxUtils::ShowErrorDialog(_("Game not found!"));
else
netplay_client->StartGame(game);
netplay_client->StartGame(FindCurrentGame());
std::string msg = "Starting game";
AddChatMessage(ChatMessageType::Info, msg);
}
break;
case NP_GUI_EVT_STOP_GAME:
// client stop game
{
netplay_client->StopGame();
std::string msg = "Stopping game";
AddChatMessage(ChatMessageType::Info, msg);
}
break;
case NP_GUI_EVT_DISPLAY_MD5_DIALOG:
@ -515,6 +534,42 @@ void NetPlayDialog::OnThread(wxThreadEvent& event)
m_MD5_dialog->SetResult(payload.first, payload.second);
}
break;
case NP_GUI_EVT_PAD_BUFFER_CHANGE:
{
std::string msg = StringFromFormat("Pad buffer: %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
@ -522,8 +577,12 @@ void NetPlayDialog::OnThread(wxThreadEvent& event)
{
std::string s;
chat_msgs.Pop(s);
// PanicAlert("message: %s", s.c_str());
m_chat_text->AppendText(StrToWxStr(s).Append('\n'));
AddChatMessage(ChatMessageType::UserIn, s);
if (g_ActiveConfig.bShowNetPlayMessages)
{
OSD::AddMessage(s, OSD::Duration::NORMAL, OSD::Color::GREEN);
}
}
}
@ -690,7 +749,7 @@ void NetPlayDialog::UpdateHostLabel()
break;
case TraversalClient::Failure:
m_host_label->SetForegroundColour(*wxBLACK);
m_host_label->SetLabel(FailureReasonStringForHostLabel(g_TraversalClient->m_FailureReason));
m_host_label->SetLabel("...");
m_host_copy_btn->SetLabel(_("Retry"));
m_host_copy_btn->Enable();
m_host_copy_btn_is_retry = true;
@ -724,3 +783,36 @@ void NetPlayDialog::UpdateHostLabel()
}
}
}
void NetPlayDialog::AddChatMessage(ChatMessageType type, const std::string& msg)
{
wxColour colour = *wxBLACK;
std::string printed_msg = msg;
switch (type)
{
case ChatMessageType::Info:
colour = wxColour(0, 150, 150); // cyan
break;
case ChatMessageType::Error:
colour = *wxRED;
break;
case ChatMessageType::UserIn:
colour = wxColour(0, 150, 0); // green
printed_msg = "" + msg;
break;
case ChatMessageType::UserOut:
colour = wxColour(100, 100, 100); // grey
printed_msg = "" + msg;
break;
}
if (type == ChatMessageType::Info || type == ChatMessageType::Error)
printed_msg = "" + msg + "";
m_chat_text->SetDefaultStyle(wxTextAttr(colour));
m_chat_text->AppendText(StrToWxStr(printed_msg + "\n"));
}