diff options
Diffstat (limited to 'Source/Core/DolphinWX/Src/NetWindow.cpp')
| -rw-r--r-- | Source/Core/DolphinWX/Src/NetWindow.cpp | 96 |
1 files changed, 51 insertions, 45 deletions
diff --git a/Source/Core/DolphinWX/Src/NetWindow.cpp b/Source/Core/DolphinWX/Src/NetWindow.cpp index 142a7ea00c..76bb76881b 100644 --- a/Source/Core/DolphinWX/Src/NetWindow.cpp +++ b/Source/Core/DolphinWX/Src/NetWindow.cpp @@ -18,11 +18,13 @@ #include <FileUtil.h> #include <IniFile.h> +#include "WxUtils.h" #include "NetPlay.h" #include "NetWindow.h" #include "Frame.h" #include <sstream> +#include <string> #define NETPLAY_TITLEBAR "Dolphin NetPlay" @@ -34,6 +36,24 @@ static NetPlay* netplay_ptr = NULL; extern CFrame* main_frame; NetPlayDiag *NetPlayDiag::npd = NULL; +std::string BuildGameName(const GameListItem& game) +{ + // Lang needs to be consistent + auto const lang = 0; + + std::string name(game.GetBannerName(lang)); + if (name.empty()) + name = game.GetVolumeName(lang); + + return name + " (" + game.GetUniqueID() + ")"; +} + +void FillWithGameNames(wxListBox* game_lbox, const CGameListCtrl& game_list) +{ + for (u32 i = 0 ; auto game = game_list.GetISO(i); ++i) + game_lbox->Append(StrToWxStr(BuildGameName(*game))); +} + NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* const game_list) : wxFrame(parent, wxID_ANY, wxT(NETPLAY_TITLEBAR), wxDefaultPosition, wxDefaultSize) , m_game_list(game_list) @@ -50,7 +70,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* std::string nickname; netplay_section.Get("Nickname", &nickname, "Player"); - m_nickname_text = new wxTextCtrl(panel, wxID_ANY, wxString::From8BitData(nickname.c_str())); + m_nickname_text = new wxTextCtrl(panel, wxID_ANY, StrToWxStr(nickname)); wxBoxSizer* const nick_szr = new wxBoxSizer(wxHORIZONTAL); nick_szr->Add(nick_lbl, 0, wxCENTER); @@ -72,7 +92,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* std::string address; netplay_section.Get("Address", &address, "localhost"); - m_connect_ip_text = new wxTextCtrl(connect_tab, wxID_ANY, wxString::FromAscii(address.c_str())); + m_connect_ip_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(address)); wxStaticText* const port_lbl = new wxStaticText(connect_tab, wxID_ANY, _("Port :"), wxDefaultPosition, wxDefaultSize); @@ -80,7 +100,7 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* // string? w/e std::string port; netplay_section.Get("ConnectPort", &port, "2626"); - m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, wxString::FromAscii(port.c_str())); + m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(port)); wxButton* const connect_btn = new wxButton(connect_tab, wxID_ANY, _("Connect")); connect_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &NetPlaySetupDiag::OnJoin, this); @@ -113,18 +133,15 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* // string? w/e std::string port; netplay_section.Get("HostPort", &port, "2626"); - m_host_port_text = new wxTextCtrl(host_tab, wxID_ANY, wxString::FromAscii(port.c_str())); + m_host_port_text = new wxTextCtrl(host_tab, wxID_ANY, StrToWxStr(port)); wxButton* const host_btn = new wxButton(host_tab, wxID_ANY, _("Host")); host_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &NetPlaySetupDiag::OnHost, this); m_game_lbox = new wxListBox(host_tab, wxID_ANY); m_game_lbox->Bind(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, &NetPlaySetupDiag::OnHost, this); - - std::istringstream ss(game_list->GetGameNames()); - std::string game; - while (std::getline(ss,game)) - m_game_lbox->Append(wxString(game.c_str(), *wxConvCurrent)); + + FillWithGameNames(m_game_lbox, *game_list); wxBoxSizer* const top_szr = new wxBoxSizer(wxHORIZONTAL); top_szr->Add(port_lbl, 0, wxCENTER | wxRIGHT, 5); @@ -167,10 +184,10 @@ NetPlaySetupDiag::~NetPlaySetupDiag() inifile.Load(dolphin_ini); IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); - netplay_section.Set("Nickname", m_nickname_text->GetValue().mb_str()); - netplay_section.Set("Address", m_connect_ip_text->GetValue().mb_str()); - netplay_section.Set("ConnectPort", m_connect_port_text->GetValue().mb_str()); - netplay_section.Set("HostPort", m_host_port_text->GetValue().mb_str()); + netplay_section.Set("Nickname", WxStrToStr(m_nickname_text->GetValue())); + netplay_section.Set("Address", WxStrToStr(m_connect_ip_text->GetValue())); + netplay_section.Set("ConnectPort", WxStrToStr(m_connect_port_text->GetValue())); + netplay_section.Set("HostPort", WxStrToStr(m_host_port_text->GetValue())); inifile.Save(dolphin_ini); main_frame->g_NetPlaySetupDiag = NULL; @@ -191,13 +208,13 @@ void NetPlaySetupDiag::OnHost(wxCommandEvent&) return; } - std::string game(m_game_lbox->GetStringSelection().mb_str()); + std::string game(WxStrToStr(m_game_lbox->GetStringSelection())); npd = new NetPlayDiag(m_parent, m_game_list, game, true); unsigned long port = 0; m_host_port_text->GetValue().ToULong(&port); netplay_ptr = new NetPlayServer(u16(port) - , std::string(m_nickname_text->GetValue().mb_str()), npd, game); + , WxStrToStr(m_nickname_text->GetValue()), npd, game); if (netplay_ptr->is_connected) { npd->Show(); @@ -222,8 +239,8 @@ void NetPlaySetupDiag::OnJoin(wxCommandEvent&) npd = new NetPlayDiag(m_parent, m_game_list, ""); unsigned long port = 0; m_connect_port_text->GetValue().ToULong(&port); - netplay_ptr = new NetPlayClient(std::string(m_connect_ip_text->GetValue().mb_str()) - , (u16)port, npd, std::string(m_nickname_text->GetValue().mb_str())); + netplay_ptr = new NetPlayClient(WxStrToStr(m_connect_ip_text->GetValue()) + , (u16)port, npd, WxStrToStr(m_nickname_text->GetValue())); if (netplay_ptr->is_connected) { npd->Show(); @@ -250,7 +267,7 @@ NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game // top crap m_game_btn = new wxButton(panel, wxID_ANY, - wxString(m_selected_game.c_str(), *wxConvCurrent).Prepend(_(" Game : ")), + StrToWxStr(m_selected_game).Prepend(_(" Game : ")), wxDefaultPosition, wxDefaultSize, wxBU_LEFT); if (is_hosting) @@ -351,7 +368,7 @@ void NetPlayDiag::OnChat(wxCommandEvent&) if (s.Length()) { - netplay_ptr->SendChatMessage(std::string(s.mb_str())); + netplay_ptr->SendChatMessage(WxStrToStr(s)); m_chat_text->AppendText(s.Prepend(wxT(" >> ")).Append(wxT('\n'))); m_chat_msg_text->Clear(); } @@ -359,24 +376,17 @@ void NetPlayDiag::OnChat(wxCommandEvent&) void NetPlayDiag::OnStart(wxCommandEvent&) { - // find path for selected game - std::string ntmp, ptmp, path; - std::istringstream nss(m_game_list->GetGameNames()), pss(m_game_list->GetGamePaths()); - - while(std::getline(nss,ntmp)) + // find path for selected game, sloppy.. + for (u32 i = 0 ; auto game = m_game_list->GetISO(i); ++i) { - std::getline(pss,ptmp); - if (m_selected_game == ntmp) + if (m_selected_game == BuildGameName(*game)) { - path = ptmp; - break; + netplay_ptr->StartGame(game->GetFileName()); + return; } } - - if (path.length()) - netplay_ptr->StartGame(path); - else - PanicAlertT("Game not found!!"); + + PanicAlertT("Game not found!"); } void NetPlayDiag::OnStop(wxCommandEvent&) @@ -412,7 +422,7 @@ void NetPlayDiag::OnMsgChangeGame(const std::string& filename) { wxCommandEvent evt(wxEVT_THREAD, NP_GUI_EVT_CHANGE_GAME); // TODO: using a wxString in AddPendingEvent from another thread is unsafe i guess? - evt.SetString(wxString(filename.c_str(), *wxConvCurrent)); + evt.SetString(StrToWxStr(filename)); GetEventHandler()->AddPendingEvent(evt); } @@ -436,7 +446,7 @@ void NetPlayDiag::OnPadBuffHelp(wxCommandEvent&) << time * (60.0f/1000) << "(60fps) / " << time * (50.0f/1000) << "(50fps) >\n"; - m_chat_text->AppendText(wxString(ss.str().c_str(), *wxConvCurrent)); + m_chat_text->AppendText(StrToWxStr(ss.str())); } void NetPlayDiag::OnAdjustBuffer(wxCommandEvent& event) @@ -447,7 +457,7 @@ void NetPlayDiag::OnAdjustBuffer(wxCommandEvent& event) std::ostringstream ss; ss << "< Pad Buffer: " << val << " >"; netplay_ptr->SendChatMessage(ss.str()); - m_chat_text->AppendText(wxString(ss.str().c_str(), *wxConvCurrent).Append(wxT('\n'))); + m_chat_text->AppendText(StrToWxStr(ss.str()).Append(wxT('\n'))); } void NetPlayDiag::OnQuit(wxCommandEvent&) @@ -468,7 +478,7 @@ void NetPlayDiag::OnThread(wxCommandEvent& event) m_player_lbox->Clear(); std::istringstream ss(tmps); while (std::getline(ss, tmps)) - m_player_lbox->Append(wxString(tmps.c_str(), *wxConvCurrent)); + m_player_lbox->Append(StrToWxStr(tmps)); m_player_lbox->SetSelection(selection); @@ -477,7 +487,7 @@ void NetPlayDiag::OnThread(wxCommandEvent& event) case NP_GUI_EVT_CHANGE_GAME : // update selected game :/ { - m_selected_game.assign(event.GetString().mb_str()); + m_selected_game.assign(WxStrToStr(event.GetString())); m_game_btn->SetLabel(event.GetString().Prepend(_(" Game : "))); } break; @@ -503,7 +513,7 @@ void NetPlayDiag::OnThread(wxCommandEvent& event) std::string s; chat_msgs.Pop(s); //PanicAlert("message: %s", s.c_str()); - m_chat_text->AppendText(wxString(s.c_str(), *wxConvCurrent).Append(wxT('\n'))); + m_chat_text->AppendText(StrToWxStr(s).Append(wxT('\n'))); } } @@ -515,7 +525,7 @@ void NetPlayDiag::OnChangeGame(wxCommandEvent&) if (game_name.length()) { - m_selected_game = std::string(game_name.mb_str()); + m_selected_game = WxStrToStr(game_name); netplay_ptr->ChangeGame(m_selected_game); m_game_btn->SetLabel(game_name.Prepend(_(" Game : "))); } @@ -549,11 +559,7 @@ ChangeGameDiag::ChangeGameDiag(wxWindow* const parent, const CGameListCtrl* cons m_game_lbox = new wxListBox(this, wxID_ANY); m_game_lbox->Bind(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, &ChangeGameDiag::OnPick, this); - // fill list with games - std::istringstream ss(game_list->GetGameNames()); - std::string game; - while (std::getline(ss,game)) - m_game_lbox->Append(wxString(game.c_str(), *wxConvCurrent)); + FillWithGameNames(m_game_lbox, *game_list); wxButton* const ok_btn = new wxButton(this, wxID_OK, _("Change")); ok_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ChangeGameDiag::OnPick, this); |
