2013-04-18 03:43:35 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <cstddef>
|
2010-05-01 19:10:35 +00:00
|
|
|
#include <sstream>
|
2013-03-03 23:56:40 +00:00
|
|
|
#include <string>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <wx/anybutton.h>
|
|
|
|
#include <wx/arrstr.h>
|
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/chartype.h>
|
|
|
|
#include <wx/checkbox.h>
|
|
|
|
#include <wx/choice.h>
|
|
|
|
#include <wx/defs.h>
|
|
|
|
#include <wx/dialog.h>
|
|
|
|
#include <wx/event.h>
|
|
|
|
#include <wx/frame.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/listbox.h>
|
2014-07-25 01:46:46 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/notebook.h>
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/spinctrl.h>
|
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
#include <wx/translation.h>
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Common/FifoQueue.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/IniFile.h"
|
|
|
|
|
|
|
|
#include "Core/ConfigManager.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Core/CoreParameter.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/NetPlayClient.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Core/NetPlayProto.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/NetPlayServer.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Core/HW/EXI_Device.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
|
|
|
#include "DolphinWX/Frame.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "DolphinWX/GameListCtrl.h"
|
|
|
|
#include "DolphinWX/ISOFile.h"
|
2014-07-08 14:49:33 +00:00
|
|
|
#include "DolphinWX/Main.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/NetWindow.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
class wxWindow;
|
|
|
|
|
2014-02-17 04:51:41 +00:00
|
|
|
#define NETPLAY_TITLEBAR "Dolphin NetPlay"
|
2014-09-22 12:28:10 +00:00
|
|
|
#define INITIAL_PAD_BUFFER_SIZE 5
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
BEGIN_EVENT_TABLE(NetPlayDiag, wxFrame)
|
|
|
|
EVT_COMMAND(wxID_ANY, wxEVT_THREAD, NetPlayDiag::OnThread)
|
|
|
|
END_EVENT_TABLE()
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
static NetPlayServer* netplay_server = nullptr;
|
|
|
|
static NetPlayClient* netplay_client = nullptr;
|
|
|
|
NetPlayDiag *NetPlayDiag::npd = nullptr;
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static std::string BuildGameName(const GameListItem& game)
|
2013-03-03 23:56:40 +00:00
|
|
|
{
|
2013-03-04 00:29:56 +00:00
|
|
|
// Lang needs to be consistent
|
|
|
|
auto const lang = 0;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-03-04 00:29:56 +00:00
|
|
|
std::string name(game.GetBannerName(lang));
|
|
|
|
if (name.empty())
|
|
|
|
name = game.GetVolumeName(lang);
|
2013-04-17 03:29:01 +00:00
|
|
|
|
|
|
|
if (game.GetRevision() != 0)
|
|
|
|
return name + " (" + game.GetUniqueID() + ", Revision " + std::to_string((long long)game.GetRevision()) + ")";
|
|
|
|
else
|
|
|
|
return name + " (" + game.GetUniqueID() + ")";
|
2013-03-03 23:56:40 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void FillWithGameNames(wxListBox* game_lbox, const CGameListCtrl& game_list)
|
2013-03-03 23:56:40 +00:00
|
|
|
{
|
|
|
|
for (u32 i = 0 ; auto game = game_list.GetISO(i); ++i)
|
|
|
|
game_lbox->Append(StrToWxStr(BuildGameName(*game)));
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:01:50 +00:00
|
|
|
NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* const game_list)
|
2014-05-17 17:17:28 +00:00
|
|
|
: wxFrame(parent, wxID_ANY, NETPLAY_TITLEBAR)
|
2010-05-01 19:10:35 +00:00
|
|
|
, m_game_list(game_list)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-06-06 03:52:11 +00:00
|
|
|
IniFile inifile;
|
2011-02-28 20:40:15 +00:00
|
|
|
inifile.Load(File::GetUserPath(D_CONFIG_IDX) + "Dolphin.ini");
|
2010-06-06 03:52:11 +00:00
|
|
|
IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay");
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
wxPanel* const panel = new wxPanel(this);
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
// top row
|
2014-03-06 04:02:34 +00:00
|
|
|
wxStaticText* const nick_lbl = new wxStaticText(panel, wxID_ANY, _("Nickname :"));
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-06-06 03:52:11 +00:00
|
|
|
std::string nickname;
|
|
|
|
netplay_section.Get("Nickname", &nickname, "Player");
|
2013-03-03 02:34:53 +00:00
|
|
|
m_nickname_text = new wxTextCtrl(panel, wxID_ANY, StrToWxStr(nickname));
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
wxBoxSizer* const nick_szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
nick_szr->Add(nick_lbl, 0, wxCENTER);
|
|
|
|
nick_szr->Add(m_nickname_text, 0, wxALL, 5);
|
2009-07-06 02:10:26 +00:00
|
|
|
|
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
// tabs
|
2014-03-06 04:02:34 +00:00
|
|
|
wxNotebook* const notebook = new wxNotebook(panel, wxID_ANY);
|
|
|
|
wxPanel* const connect_tab = new wxPanel(notebook, wxID_ANY);
|
2011-01-05 04:35:46 +00:00
|
|
|
notebook->AddPage(connect_tab, _("Connect"));
|
2014-03-06 04:02:34 +00:00
|
|
|
wxPanel* const host_tab = new wxPanel(notebook, wxID_ANY);
|
2011-01-05 04:35:46 +00:00
|
|
|
notebook->AddPage(host_tab, _("Host"));
|
2009-07-06 02:10:26 +00:00
|
|
|
|
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
// connect tab
|
|
|
|
{
|
2014-03-06 04:02:34 +00:00
|
|
|
wxStaticText* const ip_lbl = new wxStaticText(connect_tab, wxID_ANY, _("Address :"));
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-06-06 03:52:11 +00:00
|
|
|
std::string address;
|
|
|
|
netplay_section.Get("Address", &address, "localhost");
|
2013-02-28 08:39:06 +00:00
|
|
|
m_connect_ip_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(address));
|
2010-06-06 03:52:11 +00:00
|
|
|
|
2014-03-06 04:02:34 +00:00
|
|
|
wxStaticText* const port_lbl = new wxStaticText(connect_tab, wxID_ANY, _("Port :"));
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-06-06 03:52:11 +00:00
|
|
|
// string? w/e
|
|
|
|
std::string port;
|
2013-10-29 05:23:17 +00:00
|
|
|
netplay_section.Get("ConnectPort", &port, "2626");
|
2013-02-28 08:39:06 +00:00
|
|
|
m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, StrToWxStr(port));
|
2010-05-01 19:10:35 +00:00
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
wxButton* const connect_btn = new wxButton(connect_tab, wxID_ANY, _("Connect"));
|
2014-05-17 16:49:00 +00:00
|
|
|
connect_btn->Bind(wxEVT_BUTTON, &NetPlaySetupDiag::OnJoin, this);
|
2010-05-01 19:10:35 +00:00
|
|
|
|
2011-02-27 02:27:43 +00:00
|
|
|
wxStaticText* const alert_lbl = new wxStaticText(connect_tab, wxID_ANY,
|
2013-04-10 03:03:26 +00:00
|
|
|
_("ALERT:\n\n"
|
|
|
|
"Netplay will only work with the following settings:\n"
|
|
|
|
" - Enable Dual Core [OFF]\n"
|
|
|
|
" - DSP Emulator Engine Must be the same on all computers!\n"
|
|
|
|
" - DSP on Dedicated Thread [OFF]\n"
|
2013-09-23 06:56:17 +00:00
|
|
|
" - Manually set the extensions for each wiimote\n"
|
2013-04-10 03:03:26 +00:00
|
|
|
"\n"
|
|
|
|
"All players should use the same Dolphin version and settings.\n"
|
|
|
|
"All memory cards must be identical between players or disabled.\n"
|
2013-08-07 03:48:52 +00:00
|
|
|
"Wiimote support is probably terrible. Don't use it.\n"
|
2013-04-10 03:03:26 +00:00
|
|
|
"\n"
|
2014-03-06 04:02:34 +00:00
|
|
|
"The host must have the chosen TCP port open/forwarded!\n"));
|
2010-05-01 19:10:35 +00:00
|
|
|
|
|
|
|
wxBoxSizer* const top_szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
top_szr->Add(ip_lbl, 0, wxCENTER | wxRIGHT, 5);
|
|
|
|
top_szr->Add(m_connect_ip_text, 3);
|
|
|
|
top_szr->Add(port_lbl, 0, wxCENTER | wxRIGHT | wxLEFT, 5);
|
|
|
|
top_szr->Add(m_connect_port_text, 1);
|
|
|
|
|
|
|
|
wxBoxSizer* const con_szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
con_szr->Add(top_szr, 0, wxALL | wxEXPAND, 5);
|
|
|
|
con_szr->AddStretchSpacer(1);
|
|
|
|
con_szr->Add(alert_lbl, 0, wxLEFT | wxRIGHT | wxEXPAND, 5);
|
|
|
|
con_szr->AddStretchSpacer(1);
|
|
|
|
con_szr->Add(connect_btn, 0, wxALL | wxALIGN_RIGHT, 5);
|
|
|
|
|
|
|
|
connect_tab->SetSizerAndFit(con_szr);
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
2010-05-01 19:10:35 +00:00
|
|
|
|
|
|
|
// host tab
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2014-03-06 04:02:34 +00:00
|
|
|
wxStaticText* const port_lbl = new wxStaticText(host_tab, wxID_ANY, _("Port :"));
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-06-06 03:52:11 +00:00
|
|
|
// string? w/e
|
|
|
|
std::string port;
|
2013-10-29 05:23:17 +00:00
|
|
|
netplay_section.Get("HostPort", &port, "2626");
|
2013-02-28 08:39:06 +00:00
|
|
|
m_host_port_text = new wxTextCtrl(host_tab, wxID_ANY, StrToWxStr(port));
|
2010-05-01 19:10:35 +00:00
|
|
|
|
2011-01-05 17:56:08 +00:00
|
|
|
wxButton* const host_btn = new wxButton(host_tab, wxID_ANY, _("Host"));
|
2014-05-17 16:49:00 +00:00
|
|
|
host_btn->Bind(wxEVT_BUTTON, &NetPlaySetupDiag::OnHost, this);
|
2010-05-01 19:10:35 +00:00
|
|
|
|
2013-04-10 03:03:26 +00:00
|
|
|
m_game_lbox = new wxListBox(host_tab, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxLB_SORT);
|
2014-05-17 16:49:00 +00:00
|
|
|
m_game_lbox->Bind(wxEVT_LISTBOX_DCLICK, &NetPlaySetupDiag::OnHost, this);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-03-03 23:56:40 +00:00
|
|
|
FillWithGameNames(m_game_lbox, *game_list);
|
2010-05-01 19:10:35 +00:00
|
|
|
|
|
|
|
wxBoxSizer* const top_szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
top_szr->Add(port_lbl, 0, wxCENTER | wxRIGHT, 5);
|
|
|
|
top_szr->Add(m_host_port_text, 0);
|
2013-07-09 00:13:02 +00:00
|
|
|
#ifdef USE_UPNP
|
|
|
|
m_upnp_chk = new wxCheckBox(host_tab, wxID_ANY, _("Forward port (UPnP)"));
|
|
|
|
top_szr->Add(m_upnp_chk, 0, wxALL | wxALIGN_RIGHT, 5);
|
|
|
|
#endif
|
2010-05-01 19:10:35 +00:00
|
|
|
|
|
|
|
wxBoxSizer* const host_szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
host_szr->Add(top_szr, 0, wxALL | wxEXPAND, 5);
|
|
|
|
host_szr->Add(m_game_lbox, 1, wxLEFT | wxRIGHT | wxEXPAND, 5);
|
|
|
|
host_szr->Add(host_btn, 0, wxALL | wxALIGN_RIGHT, 5);
|
|
|
|
|
|
|
|
host_tab->SetSizerAndFit(host_szr);
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
2010-05-01 19:10:35 +00:00
|
|
|
|
|
|
|
// bottom row
|
2011-01-05 04:35:46 +00:00
|
|
|
wxButton* const quit_btn = new wxButton(panel, wxID_ANY, _("Quit"));
|
2014-05-17 16:49:00 +00:00
|
|
|
quit_btn->Bind(wxEVT_BUTTON, &NetPlaySetupDiag::OnQuit, this);
|
2010-05-01 19:10:35 +00:00
|
|
|
|
|
|
|
// main sizer
|
|
|
|
wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
main_szr->Add(nick_szr, 0, wxALL | wxALIGN_RIGHT, 5);
|
|
|
|
main_szr->Add(notebook, 1, wxLEFT | wxRIGHT | wxEXPAND, 5);
|
|
|
|
main_szr->Add(quit_btn, 0, wxALL | wxALIGN_RIGHT, 5);
|
|
|
|
|
|
|
|
panel->SetSizerAndFit(main_szr);
|
|
|
|
|
|
|
|
//wxBoxSizer* const diag_szr = new wxBoxSizer(wxVERTICAL);
|
2010-05-02 23:01:50 +00:00
|
|
|
//diag_szr->Add(panel, 1, wxEXPAND);
|
2010-05-01 19:10:35 +00:00
|
|
|
//SetSizerAndFit(diag_szr);
|
|
|
|
|
|
|
|
main_szr->SetSizeHints(this);
|
|
|
|
|
|
|
|
Center();
|
|
|
|
Show();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 03:52:11 +00:00
|
|
|
NetPlaySetupDiag::~NetPlaySetupDiag()
|
|
|
|
{
|
|
|
|
IniFile inifile;
|
2011-02-28 20:40:15 +00:00
|
|
|
const std::string dolphin_ini = File::GetUserPath(D_CONFIG_IDX) + "Dolphin.ini";
|
2010-06-06 03:52:11 +00:00
|
|
|
inifile.Load(dolphin_ini);
|
|
|
|
IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay");
|
|
|
|
|
2013-02-28 04:37:38 +00:00
|
|
|
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()));
|
2010-06-06 03:52:11 +00:00
|
|
|
|
|
|
|
inifile.Save(dolphin_ini);
|
2014-03-09 20:14:26 +00:00
|
|
|
main_frame->g_NetPlaySetupDiag = nullptr;
|
2010-06-06 03:52:11 +00:00
|
|
|
}
|
|
|
|
|
2013-07-22 08:21:56 +00:00
|
|
|
void NetPlaySetupDiag::MakeNetPlayDiag(int port, const std::string &game, bool is_hosting)
|
|
|
|
{
|
|
|
|
NetPlayDiag *&npd = NetPlayDiag::GetInstance();
|
|
|
|
std::string ip;
|
|
|
|
npd = new NetPlayDiag(m_parent, m_game_list, game, is_hosting);
|
|
|
|
if (is_hosting)
|
|
|
|
ip = "127.0.0.1";
|
|
|
|
else
|
|
|
|
ip = WxStrToStr(m_connect_ip_text->GetValue());
|
|
|
|
|
|
|
|
netplay_client = new NetPlayClient(ip, (u16)port, npd, WxStrToStr(m_nickname_text->GetValue()));
|
|
|
|
if (netplay_client->is_connected)
|
|
|
|
{
|
|
|
|
npd->Show();
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
npd->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 01:55:29 +00:00
|
|
|
void NetPlaySetupDiag::OnHost(wxCommandEvent&)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2011-02-27 02:27:43 +00:00
|
|
|
NetPlayDiag *&npd = NetPlayDiag::GetInstance();
|
|
|
|
if (npd)
|
2010-05-01 19:10:35 +00:00
|
|
|
{
|
2014-07-25 01:46:46 +00:00
|
|
|
WxUtils::ShowErrorDialog(_("A NetPlay window is already open!"));
|
2009-07-06 02:10:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-05-01 19:10:35 +00:00
|
|
|
|
|
|
|
if (-1 == m_game_lbox->GetSelection())
|
|
|
|
{
|
2014-07-25 01:46:46 +00:00
|
|
|
WxUtils::ShowErrorDialog(_("You must choose a game!"));
|
2009-07-06 02:10:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-28 04:37:38 +00:00
|
|
|
std::string game(WxStrToStr(m_game_lbox->GetStringSelection()));
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
unsigned long port = 0;
|
|
|
|
m_host_port_text->GetValue().ToULong(&port);
|
2013-07-22 08:21:56 +00:00
|
|
|
netplay_server = new NetPlayServer(u16(port));
|
|
|
|
netplay_server->ChangeGame(game);
|
2013-08-14 21:05:11 +00:00
|
|
|
netplay_server->AdjustPadBufferSize(INITIAL_PAD_BUFFER_SIZE);
|
2013-07-22 08:21:56 +00:00
|
|
|
if (netplay_server->is_connected)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2013-07-09 00:13:02 +00:00
|
|
|
#ifdef USE_UPNP
|
2014-03-10 11:30:55 +00:00
|
|
|
if (m_upnp_chk->GetValue())
|
2013-07-22 08:21:56 +00:00
|
|
|
netplay_server->TryPortmapping(port);
|
2013-07-09 00:13:02 +00:00
|
|
|
#endif
|
2013-09-19 02:14:04 +00:00
|
|
|
MakeNetPlayDiag(port, game, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-25 01:46:46 +00:00
|
|
|
WxUtils::ShowErrorDialog(_("Failed to listen. Is another instance of the NetPlay server running?"));
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 01:55:29 +00:00
|
|
|
void NetPlaySetupDiag::OnJoin(wxCommandEvent&)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2011-02-27 02:27:43 +00:00
|
|
|
NetPlayDiag *&npd = NetPlayDiag::GetInstance();
|
|
|
|
if (npd)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2014-07-25 01:46:46 +00:00
|
|
|
WxUtils::ShowErrorDialog(_("A NetPlay window is already open!"));
|
2010-05-01 19:10:35 +00:00
|
|
|
return;
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
unsigned long port = 0;
|
|
|
|
m_connect_port_text->GetValue().ToULong(&port);
|
2013-07-22 08:21:56 +00:00
|
|
|
MakeNetPlayDiag(port, "", false);
|
2010-05-01 19:10:35 +00:00
|
|
|
}
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-11-16 01:55:29 +00:00
|
|
|
void NetPlaySetupDiag::OnQuit(wxCommandEvent&)
|
2010-05-01 19:10:35 +00:00
|
|
|
{
|
|
|
|
Destroy();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2011-02-27 02:27:43 +00:00
|
|
|
NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game_list,
|
|
|
|
const std::string& game, const bool is_hosting)
|
2014-05-17 17:17:28 +00:00
|
|
|
: wxFrame(parent, wxID_ANY, NETPLAY_TITLEBAR)
|
2010-05-01 19:10:35 +00:00
|
|
|
, m_selected_game(game)
|
2014-03-09 20:14:26 +00:00
|
|
|
, m_start_btn(nullptr)
|
2013-08-15 13:05:20 +00:00
|
|
|
, m_game_list(game_list)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-05-01 19:10:35 +00:00
|
|
|
wxPanel* const panel = new wxPanel(this);
|
|
|
|
|
|
|
|
// top crap
|
2011-02-27 02:27:43 +00:00
|
|
|
m_game_btn = new wxButton(panel, wxID_ANY,
|
2013-02-28 04:37:38 +00:00
|
|
|
StrToWxStr(m_selected_game).Prepend(_(" Game : ")),
|
2011-02-27 02:27:43 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-05-02 23:01:50 +00:00
|
|
|
if (is_hosting)
|
2014-05-17 16:49:00 +00:00
|
|
|
m_game_btn->Bind(wxEVT_BUTTON, &NetPlayDiag::OnChangeGame, this);
|
2010-05-02 23:01:50 +00:00
|
|
|
else
|
|
|
|
m_game_btn->Disable();
|
2010-05-01 19:10:35 +00:00
|
|
|
|
|
|
|
// middle crap
|
|
|
|
|
|
|
|
// chat
|
|
|
|
m_chat_text = new wxTextCtrl(panel, wxID_ANY, wxEmptyString
|
|
|
|
, wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxTE_MULTILINE);
|
|
|
|
|
|
|
|
m_chat_msg_text = new wxTextCtrl(panel, wxID_ANY, wxEmptyString
|
|
|
|
, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
|
2014-05-17 16:49:00 +00:00
|
|
|
m_chat_msg_text->Bind(wxEVT_TEXT_ENTER, &NetPlayDiag::OnChat, this);
|
2014-05-23 11:20:40 +00:00
|
|
|
m_chat_msg_text->SetMaxLength(2000);
|
2010-05-01 19:10:35 +00:00
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
wxButton* const chat_msg_btn = new wxButton(panel, wxID_ANY, _("Send"));
|
2014-05-17 16:49:00 +00:00
|
|
|
chat_msg_btn->Bind(wxEVT_BUTTON, &NetPlayDiag::OnChat, this);
|
2010-05-01 19:10:35 +00:00
|
|
|
|
|
|
|
wxBoxSizer* const chat_msg_szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
chat_msg_szr->Add(m_chat_msg_text, 1);
|
|
|
|
chat_msg_szr->Add(chat_msg_btn, 0);
|
|
|
|
|
2011-01-05 17:56:08 +00:00
|
|
|
wxStaticBoxSizer* const chat_szr = new wxStaticBoxSizer(wxVERTICAL, panel, _("Chat"));
|
2010-05-01 19:10:35 +00:00
|
|
|
chat_szr->Add(m_chat_text, 1, wxEXPAND);
|
|
|
|
chat_szr->Add(chat_msg_szr, 0, wxEXPAND | wxTOP, 5);
|
|
|
|
|
2013-04-10 03:03:26 +00:00
|
|
|
m_player_lbox = new wxListBox(panel, wxID_ANY, wxDefaultPosition, wxSize(256, -1));
|
2010-05-01 19:10:35 +00:00
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
wxStaticBoxSizer* const player_szr = new wxStaticBoxSizer(wxVERTICAL, panel, _("Players"));
|
2010-05-01 19:10:35 +00:00
|
|
|
player_szr->Add(m_player_lbox, 1, wxEXPAND);
|
|
|
|
// player list
|
|
|
|
if (is_hosting)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2014-05-29 22:59:07 +00:00
|
|
|
m_player_lbox->Bind(wxEVT_LISTBOX, &NetPlayDiag::OnPlayerSelect, this);
|
|
|
|
m_kick_btn = new wxButton(panel, wxID_ANY, _("Kick Player"));
|
|
|
|
m_kick_btn->Bind(wxEVT_BUTTON, &NetPlayDiag::OnKick, this);
|
|
|
|
player_szr->Add(m_kick_btn, 0, wxEXPAND | wxTOP, 5);
|
|
|
|
m_kick_btn->Disable();
|
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
wxButton* const player_config_btn = new wxButton(panel, wxID_ANY, _("Configure Pads"));
|
2014-05-17 16:49:00 +00:00
|
|
|
player_config_btn->Bind(wxEVT_BUTTON, &NetPlayDiag::OnConfigPads, this);
|
2010-05-01 19:10:35 +00:00
|
|
|
player_szr->Add(player_config_btn, 0, wxEXPAND | wxTOP, 5);
|
|
|
|
}
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
wxBoxSizer* const mid_szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
mid_szr->Add(chat_szr, 1, wxEXPAND | wxRIGHT, 5);
|
|
|
|
mid_szr->Add(player_szr, 0, wxEXPAND);
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
// bottom crap
|
2011-01-05 04:35:46 +00:00
|
|
|
wxButton* const quit_btn = new wxButton(panel, wxID_ANY, _("Quit"));
|
2014-05-17 16:49:00 +00:00
|
|
|
quit_btn->Bind(wxEVT_BUTTON, &NetPlayDiag::OnQuit, this);
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
wxBoxSizer* const bottom_szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
if (is_hosting)
|
|
|
|
{
|
2013-08-14 22:14:29 +00:00
|
|
|
m_start_btn = new wxButton(panel, wxID_ANY, _("Start"));
|
2014-05-17 16:49:00 +00:00
|
|
|
m_start_btn->Bind(wxEVT_BUTTON, &NetPlayDiag::OnStart, this);
|
2013-08-14 22:14:29 +00:00
|
|
|
bottom_szr->Add(m_start_btn);
|
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
bottom_szr->Add(new wxStaticText(panel, wxID_ANY, _("Buffer:")), 0, wxLEFT | wxCENTER, 5 );
|
2014-09-22 12:28:10 +00:00
|
|
|
wxSpinCtrl* const padbuf_spin = new wxSpinCtrl(panel, wxID_ANY, std::to_string(INITIAL_PAD_BUFFER_SIZE)
|
2013-08-14 21:05:11 +00:00
|
|
|
, wxDefaultPosition, wxSize(64, -1), wxSP_ARROW_KEYS, 0, 200, INITIAL_PAD_BUFFER_SIZE);
|
2014-05-17 16:49:00 +00:00
|
|
|
padbuf_spin->Bind(wxEVT_SPINCTRL, &NetPlayDiag::OnAdjustBuffer, this);
|
2010-05-05 04:31:21 +00:00
|
|
|
bottom_szr->Add(padbuf_spin, 0, wxCENTER);
|
2013-04-07 16:18:07 +00:00
|
|
|
|
2013-08-17 01:42:38 +00:00
|
|
|
m_memcard_write = new wxCheckBox(panel, wxID_ANY, _("Write memcards (GC)"));
|
|
|
|
bottom_szr->Add(m_memcard_write, 0, wxCENTER);
|
|
|
|
}
|
2013-04-07 17:04:44 +00:00
|
|
|
|
2013-09-03 19:50:41 +00:00
|
|
|
m_record_chkbox = new wxCheckBox(panel, wxID_ANY, _("Record input"));
|
|
|
|
bottom_szr->Add(m_record_chkbox, 0, wxCENTER);
|
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
bottom_szr->AddStretchSpacer(1);
|
|
|
|
bottom_szr->Add(quit_btn);
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
// main sizer
|
|
|
|
wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
main_szr->Add(m_game_btn, 0, wxEXPAND | wxALL, 5);
|
|
|
|
main_szr->Add(mid_szr, 1, wxEXPAND | wxLEFT | wxRIGHT, 5);
|
|
|
|
main_szr->Add(bottom_szr, 0, wxEXPAND | wxALL, 5);
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
panel->SetSizerAndFit(main_szr);
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
main_szr->SetSizeHints(this);
|
|
|
|
SetSize(512, 512-128);
|
|
|
|
|
|
|
|
Center();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
NetPlayDiag::~NetPlayDiag()
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2013-07-22 08:21:56 +00:00
|
|
|
if (netplay_client)
|
|
|
|
{
|
|
|
|
delete netplay_client;
|
2014-03-09 20:14:26 +00:00
|
|
|
netplay_client = nullptr;
|
2013-07-22 08:21:56 +00:00
|
|
|
}
|
|
|
|
if (netplay_server)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2013-07-22 08:21:56 +00:00
|
|
|
delete netplay_server;
|
2014-03-09 20:14:26 +00:00
|
|
|
netplay_server = nullptr;
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
2014-03-09 20:14:26 +00:00
|
|
|
npd = nullptr;
|
2010-05-01 19:10:35 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 01:55:29 +00:00
|
|
|
void NetPlayDiag::OnChat(wxCommandEvent&)
|
2010-05-01 19:10:35 +00:00
|
|
|
{
|
2014-07-13 18:29:03 +00:00
|
|
|
wxString text = m_chat_msg_text->GetValue();
|
2010-05-01 19:10:35 +00:00
|
|
|
|
2014-07-13 18:29:03 +00:00
|
|
|
if (!text.empty())
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2014-07-13 18:29:03 +00:00
|
|
|
if (text.length() > 2000)
|
|
|
|
text.erase(2000);
|
|
|
|
|
|
|
|
netplay_client->SendChatMessage(WxStrToStr(text));
|
|
|
|
m_chat_text->AppendText(text.Prepend(" >> ").Append('\n'));
|
2010-05-01 19:10:35 +00:00
|
|
|
m_chat_msg_text->Clear();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-22 08:21:56 +00:00
|
|
|
void NetPlayDiag::GetNetSettings(NetSettings &settings)
|
|
|
|
{
|
|
|
|
SConfig &instance = SConfig::GetInstance();
|
2013-09-02 23:55:25 +00:00
|
|
|
settings.m_CPUthread = instance.m_LocalCoreStartupParameter.bCPUThread;
|
2014-01-08 22:58:27 +00:00
|
|
|
settings.m_CPUcore = instance.m_LocalCoreStartupParameter.iCPUCore;
|
2013-07-22 08:21:56 +00:00
|
|
|
settings.m_DSPHLE = instance.m_LocalCoreStartupParameter.bDSPHLE;
|
2014-02-23 14:14:27 +00:00
|
|
|
settings.m_DSPEnableJIT = instance.m_DSPEnableJIT;
|
2013-07-22 08:21:56 +00:00
|
|
|
settings.m_WriteToMemcard = m_memcard_write->GetValue();
|
2013-09-05 00:16:28 +00:00
|
|
|
settings.m_EXIDevice[0] = instance.m_EXIDevice[0];
|
|
|
|
settings.m_EXIDevice[1] = instance.m_EXIDevice[1];
|
2013-07-22 08:21:56 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 18:47:32 +00:00
|
|
|
std::string NetPlayDiag::FindGame()
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2013-03-03 23:56:40 +00:00
|
|
|
// find path for selected game, sloppy..
|
|
|
|
for (u32 i = 0 ; auto game = m_game_list->GetISO(i); ++i)
|
|
|
|
if (m_selected_game == BuildGameName(*game))
|
2013-07-22 08:21:56 +00:00
|
|
|
return game->GetFileName();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-07-25 01:46:46 +00:00
|
|
|
WxUtils::ShowErrorDialog(_("Game not found!"));
|
2013-07-22 08:21:56 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetPlayDiag::OnStart(wxCommandEvent&)
|
|
|
|
{
|
|
|
|
NetSettings settings;
|
|
|
|
GetNetSettings(settings);
|
|
|
|
netplay_server->SetNetSettings(settings);
|
2014-08-02 22:28:26 +00:00
|
|
|
netplay_server->StartGame();
|
2010-05-01 19:10:35 +00:00
|
|
|
}
|
2009-09-02 21:00:45 +00:00
|
|
|
|
2011-02-08 15:36:15 +00:00
|
|
|
void NetPlayDiag::BootGame(const std::string& filename)
|
|
|
|
{
|
|
|
|
main_frame->BootGame(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetPlayDiag::StopGame()
|
|
|
|
{
|
|
|
|
main_frame->DoStop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// NetPlayUI methods called from ---NETPLAY--- thread
|
|
|
|
void NetPlayDiag::Update()
|
|
|
|
{
|
|
|
|
wxCommandEvent evt(wxEVT_THREAD, 1);
|
|
|
|
GetEventHandler()->AddPendingEvent(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetPlayDiag::AppendChat(const std::string& msg)
|
|
|
|
{
|
|
|
|
chat_msgs.Push(msg);
|
|
|
|
// silly
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
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?
|
2013-02-28 04:37:38 +00:00
|
|
|
evt.SetString(StrToWxStr(filename));
|
2011-02-08 15:36:15 +00:00
|
|
|
GetEventHandler()->AddPendingEvent(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetPlayDiag::OnMsgStartGame()
|
|
|
|
{
|
|
|
|
wxCommandEvent evt(wxEVT_THREAD, NP_GUI_EVT_START_GAME);
|
|
|
|
GetEventHandler()->AddPendingEvent(evt);
|
2013-08-14 22:14:29 +00:00
|
|
|
if (m_start_btn)
|
|
|
|
m_start_btn->Disable();
|
2013-10-15 21:28:01 +00:00
|
|
|
m_record_chkbox->Disable();
|
2011-02-08 15:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetPlayDiag::OnMsgStopGame()
|
|
|
|
{
|
|
|
|
wxCommandEvent evt(wxEVT_THREAD, NP_GUI_EVT_STOP_GAME);
|
|
|
|
GetEventHandler()->AddPendingEvent(evt);
|
2013-08-14 22:14:29 +00:00
|
|
|
if (m_start_btn)
|
|
|
|
m_start_btn->Enable();
|
2013-10-15 21:28:01 +00:00
|
|
|
m_record_chkbox->Enable();
|
2011-02-08 15:36:15 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 04:31:21 +00:00
|
|
|
void NetPlayDiag::OnAdjustBuffer(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
const int val = ((wxSpinCtrl*)event.GetEventObject())->GetValue();
|
2013-07-22 08:21:56 +00:00
|
|
|
netplay_server->AdjustPadBufferSize(val);
|
2010-05-05 04:31:21 +00:00
|
|
|
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss << "< Pad Buffer: " << val << " >";
|
2013-07-22 08:21:56 +00:00
|
|
|
netplay_client->SendChatMessage(ss.str());
|
2014-05-17 17:17:28 +00:00
|
|
|
m_chat_text->AppendText(StrToWxStr(ss.str()).Append('\n'));
|
2010-05-05 04:31:21 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 01:55:29 +00:00
|
|
|
void NetPlayDiag::OnQuit(wxCommandEvent&)
|
2010-05-01 19:10:35 +00:00
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
// update gui
|
|
|
|
void NetPlayDiag::OnThread(wxCommandEvent& event)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-05-01 19:10:35 +00:00
|
|
|
// player list
|
2010-06-06 03:52:11 +00:00
|
|
|
m_playerids.clear();
|
2010-05-01 19:10:35 +00:00
|
|
|
std::string tmps;
|
2013-07-22 08:21:56 +00:00
|
|
|
netplay_client->GetPlayerList(tmps, m_playerids);
|
2010-06-06 03:52:11 +00:00
|
|
|
|
2014-05-24 16:13:49 +00:00
|
|
|
wxString selection;
|
|
|
|
if (m_player_lbox->GetSelection() != wxNOT_FOUND)
|
|
|
|
selection = m_player_lbox->GetString(m_player_lbox->GetSelection());
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
m_player_lbox->Clear();
|
|
|
|
std::istringstream ss(tmps);
|
|
|
|
while (std::getline(ss, tmps))
|
2013-02-28 04:37:38 +00:00
|
|
|
m_player_lbox->Append(StrToWxStr(tmps));
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2014-05-24 16:13:49 +00:00
|
|
|
// remove ping from selection string, in case it has changed
|
|
|
|
selection.erase(selection.find_last_of("|") + 1);
|
|
|
|
|
2014-07-13 18:29:03 +00:00
|
|
|
if (!selection.empty())
|
2014-05-24 16:13:49 +00:00
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < m_player_lbox->GetCount(); ++i)
|
|
|
|
{
|
2014-07-13 18:29:03 +00:00
|
|
|
if (selection == m_player_lbox->GetString(i).Mid(0, selection.length()))
|
2014-05-24 16:13:49 +00:00
|
|
|
{
|
|
|
|
m_player_lbox->SetSelection(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-06 03:52:11 +00:00
|
|
|
|
2014-05-23 06:20:22 +00:00
|
|
|
// flash window in taskbar when someone joins if window isn't active
|
|
|
|
static u8 numPlayers = 1;
|
|
|
|
bool focus = (wxWindow::FindFocus() == this || (wxWindow::FindFocus() != nullptr && wxWindow::FindFocus()->GetParent() == this) ||
|
|
|
|
(wxWindow::FindFocus() != nullptr && wxWindow::FindFocus()->GetParent() != nullptr
|
|
|
|
&& wxWindow::FindFocus()->GetParent()->GetParent() == this));
|
|
|
|
if (netplay_server != nullptr && numPlayers < m_playerids.size() && !focus)
|
|
|
|
{
|
|
|
|
RequestUserAttention();
|
|
|
|
}
|
|
|
|
numPlayers = m_playerids.size();
|
|
|
|
|
2010-05-02 04:24:49 +00:00
|
|
|
switch (event.GetId())
|
2010-05-01 19:10:35 +00:00
|
|
|
{
|
2010-05-02 23:01:50 +00:00
|
|
|
case NP_GUI_EVT_CHANGE_GAME :
|
2010-05-02 04:24:49 +00:00
|
|
|
// update selected game :/
|
2010-05-02 23:01:50 +00:00
|
|
|
{
|
2013-02-28 04:37:38 +00:00
|
|
|
m_selected_game.assign(WxStrToStr(event.GetString()));
|
2011-01-05 04:35:46 +00:00
|
|
|
m_game_btn->SetLabel(event.GetString().Prepend(_(" Game : ")));
|
2010-05-02 23:01:50 +00:00
|
|
|
}
|
2010-05-02 04:24:49 +00:00
|
|
|
break;
|
2010-05-02 23:01:50 +00:00
|
|
|
case NP_GUI_EVT_START_GAME :
|
2010-05-02 04:24:49 +00:00
|
|
|
// client start game :/
|
2010-05-02 23:01:50 +00:00
|
|
|
{
|
2013-07-22 08:21:56 +00:00
|
|
|
netplay_client->StartGame(FindGame());
|
2010-05-02 23:01:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NP_GUI_EVT_STOP_GAME :
|
|
|
|
// client stop game
|
|
|
|
{
|
2013-07-22 08:21:56 +00:00
|
|
|
netplay_client->StopGame();
|
2010-05-02 23:01:50 +00:00
|
|
|
}
|
2010-05-02 04:24:49 +00:00
|
|
|
break;
|
2010-05-01 19:10:35 +00:00
|
|
|
}
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2010-05-01 19:10:35 +00:00
|
|
|
// chat messages
|
|
|
|
while (chat_msgs.Size())
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-05-01 19:10:35 +00:00
|
|
|
std::string s;
|
|
|
|
chat_msgs.Pop(s);
|
|
|
|
//PanicAlert("message: %s", s.c_str());
|
2014-05-17 17:17:28 +00:00
|
|
|
m_chat_text->AppendText(StrToWxStr(s).Append('\n'));
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-02 23:01:50 +00:00
|
|
|
|
2010-11-16 01:55:29 +00:00
|
|
|
void NetPlayDiag::OnChangeGame(wxCommandEvent&)
|
2010-05-02 23:01:50 +00:00
|
|
|
{
|
|
|
|
wxString game_name;
|
|
|
|
ChangeGameDiag* const cgd = new ChangeGameDiag(this, m_game_list, game_name);
|
|
|
|
cgd->ShowModal();
|
|
|
|
|
|
|
|
if (game_name.length())
|
|
|
|
{
|
2013-02-28 04:37:38 +00:00
|
|
|
m_selected_game = WxStrToStr(game_name);
|
2013-07-22 08:21:56 +00:00
|
|
|
netplay_server->ChangeGame(m_selected_game);
|
2011-01-05 17:56:08 +00:00
|
|
|
m_game_btn->SetLabel(game_name.Prepend(_(" Game : ")));
|
2010-05-02 23:01:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 01:55:29 +00:00
|
|
|
void NetPlayDiag::OnConfigPads(wxCommandEvent&)
|
2010-06-06 03:52:11 +00:00
|
|
|
{
|
2013-08-18 13:43:01 +00:00
|
|
|
PadMapping mapping[4];
|
2013-09-22 18:27:52 +00:00
|
|
|
PadMapping wiimotemapping[4];
|
2013-08-18 13:43:01 +00:00
|
|
|
std::vector<const Player *> player_list;
|
|
|
|
netplay_server->GetPadMapping(mapping);
|
2013-09-22 18:27:52 +00:00
|
|
|
netplay_server->GetWiimoteMapping(wiimotemapping);
|
2013-08-18 13:43:01 +00:00
|
|
|
netplay_client->GetPlayers(player_list);
|
2013-09-22 18:27:52 +00:00
|
|
|
PadMapDiag pmd(this, mapping, wiimotemapping, player_list);
|
2011-03-17 04:26:01 +00:00
|
|
|
pmd.ShowModal();
|
2013-08-18 13:43:01 +00:00
|
|
|
netplay_server->SetPadMapping(mapping);
|
2013-09-22 18:27:52 +00:00
|
|
|
netplay_server->SetWiimoteMapping(wiimotemapping);
|
2010-06-06 03:52:11 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 22:59:07 +00:00
|
|
|
void NetPlayDiag::OnKick(wxCommandEvent&)
|
|
|
|
{
|
|
|
|
wxString selection = m_player_lbox->GetStringSelection();
|
|
|
|
unsigned long player = 0;
|
|
|
|
selection.Mid(selection.find_last_of("[") + 1, selection.find_last_of("]")).ToULong(&player);
|
|
|
|
|
|
|
|
netplay_server->KickPlayer((u8)player);
|
|
|
|
|
|
|
|
m_player_lbox->SetSelection(wxNOT_FOUND);
|
|
|
|
wxCommandEvent event;
|
|
|
|
OnPlayerSelect(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetPlayDiag::OnPlayerSelect(wxCommandEvent&)
|
|
|
|
{
|
|
|
|
if (m_player_lbox->GetSelection() > 0)
|
|
|
|
m_kick_btn->Enable();
|
|
|
|
else
|
|
|
|
m_kick_btn->Disable();
|
|
|
|
}
|
|
|
|
|
2013-09-03 19:50:41 +00:00
|
|
|
bool NetPlayDiag::IsRecording()
|
|
|
|
{
|
|
|
|
return m_record_chkbox->GetValue();
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:01:50 +00:00
|
|
|
ChangeGameDiag::ChangeGameDiag(wxWindow* const parent, const CGameListCtrl* const game_list, wxString& game_name)
|
2014-03-06 04:02:34 +00:00
|
|
|
: wxDialog(parent, wxID_ANY, _("Change Game"))
|
2010-05-02 23:01:50 +00:00
|
|
|
, m_game_name(game_name)
|
|
|
|
{
|
2013-04-10 03:03:26 +00:00
|
|
|
m_game_lbox = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxLB_SORT);
|
2014-05-17 16:49:00 +00:00
|
|
|
m_game_lbox->Bind(wxEVT_LISTBOX_DCLICK, &ChangeGameDiag::OnPick, this);
|
2010-05-02 23:01:50 +00:00
|
|
|
|
2013-03-03 23:56:40 +00:00
|
|
|
FillWithGameNames(m_game_lbox, *game_list);
|
2010-05-02 23:01:50 +00:00
|
|
|
|
2011-03-17 04:26:01 +00:00
|
|
|
wxButton* const ok_btn = new wxButton(this, wxID_OK, _("Change"));
|
2014-05-17 16:49:00 +00:00
|
|
|
ok_btn->Bind(wxEVT_BUTTON, &ChangeGameDiag::OnPick, this);
|
2010-05-02 23:01:50 +00:00
|
|
|
|
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
szr->Add(m_game_lbox, 1, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 5);
|
|
|
|
szr->Add(ok_btn, 0, wxALL | wxALIGN_RIGHT, 5);
|
|
|
|
|
2011-03-17 04:26:01 +00:00
|
|
|
SetSizerAndFit(szr);
|
|
|
|
SetFocus();
|
2010-05-02 23:01:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-17 04:26:01 +00:00
|
|
|
void ChangeGameDiag::OnPick(wxCommandEvent& event)
|
2010-05-02 23:01:50 +00:00
|
|
|
{
|
|
|
|
// return the selected game name
|
|
|
|
m_game_name = m_game_lbox->GetStringSelection();
|
2011-03-17 04:26:01 +00:00
|
|
|
EndModal(wxID_OK);
|
2010-05-02 23:01:50 +00:00
|
|
|
}
|
2010-06-06 03:52:11 +00:00
|
|
|
|
2013-09-22 18:27:52 +00:00
|
|
|
PadMapDiag::PadMapDiag(wxWindow* const parent, PadMapping map[], PadMapping wiimotemap[], std::vector<const Player *>& player_list)
|
2014-03-06 04:02:34 +00:00
|
|
|
: wxDialog(parent, wxID_ANY, _("Configure Pads"))
|
2010-06-06 03:52:11 +00:00
|
|
|
, m_mapping(map)
|
2013-09-22 18:27:52 +00:00
|
|
|
, m_wiimapping (wiimotemap)
|
2013-08-18 13:43:01 +00:00
|
|
|
, m_player_list(player_list)
|
2010-06-06 03:52:11 +00:00
|
|
|
{
|
|
|
|
wxBoxSizer* const h_szr = new wxBoxSizer(wxHORIZONTAL);
|
2013-08-23 13:54:22 +00:00
|
|
|
h_szr->AddSpacer(10);
|
2010-06-06 03:52:11 +00:00
|
|
|
|
2013-08-18 13:43:01 +00:00
|
|
|
wxArrayString player_names;
|
|
|
|
player_names.Add(_("None"));
|
2013-10-29 05:09:01 +00:00
|
|
|
for (auto& player : m_player_list)
|
|
|
|
player_names.Add(player->name);
|
2010-06-06 03:52:11 +00:00
|
|
|
|
|
|
|
for (unsigned int i=0; i<4; ++i)
|
|
|
|
{
|
2013-08-18 13:43:01 +00:00
|
|
|
wxBoxSizer* const v_szr = new wxBoxSizer(wxVERTICAL);
|
2014-05-17 17:17:28 +00:00
|
|
|
v_szr->Add(new wxStaticText(this, wxID_ANY, (wxString(_("Pad ")) + (wxChar)('0'+i))),
|
2013-08-18 13:43:01 +00:00
|
|
|
1, wxALIGN_CENTER_HORIZONTAL);
|
2010-06-06 03:52:11 +00:00
|
|
|
|
2013-08-18 13:43:01 +00:00
|
|
|
m_map_cbox[i] = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, player_names);
|
2014-05-17 16:49:00 +00:00
|
|
|
m_map_cbox[i]->Bind(wxEVT_CHOICE, &PadMapDiag::OnAdjust, this);
|
2013-08-18 13:43:01 +00:00
|
|
|
if (m_mapping[i] == -1)
|
|
|
|
m_map_cbox[i]->Select(0);
|
|
|
|
else
|
|
|
|
for (unsigned int j = 0; j < m_player_list.size(); j++)
|
|
|
|
if (m_mapping[i] == m_player_list[j]->pid)
|
|
|
|
m_map_cbox[i]->Select(j + 1);
|
2010-06-06 03:52:11 +00:00
|
|
|
|
2013-08-18 13:43:01 +00:00
|
|
|
v_szr->Add(m_map_cbox[i], 1);
|
2010-06-06 03:52:11 +00:00
|
|
|
|
2011-03-17 04:26:01 +00:00
|
|
|
h_szr->Add(v_szr, 1, wxTOP | wxEXPAND, 20);
|
2013-08-18 13:43:01 +00:00
|
|
|
h_szr->AddSpacer(10);
|
2010-06-06 03:52:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 03:48:52 +00:00
|
|
|
for (unsigned int i=0; i<4; ++i)
|
|
|
|
{
|
2013-09-22 18:27:52 +00:00
|
|
|
wxBoxSizer* const v_szr = new wxBoxSizer(wxVERTICAL);
|
2014-05-17 17:17:28 +00:00
|
|
|
v_szr->Add(new wxStaticText(this, wxID_ANY, (wxString(_("Wiimote ")) + (wxChar)('0'+i))),
|
2013-09-22 18:27:52 +00:00
|
|
|
1, wxALIGN_CENTER_HORIZONTAL);
|
2013-08-07 03:48:52 +00:00
|
|
|
|
2013-09-22 18:27:52 +00:00
|
|
|
m_map_cbox[i+4] = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, player_names);
|
2014-05-17 16:49:00 +00:00
|
|
|
m_map_cbox[i+4]->Bind(wxEVT_CHOICE, &PadMapDiag::OnAdjust, this);
|
2013-09-22 18:27:52 +00:00
|
|
|
if (m_wiimapping[i] == -1)
|
|
|
|
m_map_cbox[i+4]->Select(0);
|
|
|
|
else
|
|
|
|
for (unsigned int j = 0; j < m_player_list.size(); j++)
|
|
|
|
if (m_wiimapping[i] == m_player_list[j]->pid)
|
|
|
|
m_map_cbox[i+4]->Select(j + 1);
|
2013-08-07 03:48:52 +00:00
|
|
|
|
2013-09-22 18:27:52 +00:00
|
|
|
v_szr->Add(m_map_cbox[i+4], 1);
|
2013-08-07 03:48:52 +00:00
|
|
|
|
|
|
|
h_szr->Add(v_szr, 1, wxTOP | wxEXPAND, 20);
|
2013-09-22 18:27:52 +00:00
|
|
|
h_szr->AddSpacer(10);
|
2013-08-07 03:48:52 +00:00
|
|
|
}
|
|
|
|
|
2011-03-17 04:26:01 +00:00
|
|
|
wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
main_szr->Add(h_szr);
|
|
|
|
main_szr->AddSpacer(5);
|
|
|
|
main_szr->Add(CreateButtonSizer(wxOK), 0, wxEXPAND | wxLEFT | wxRIGHT, 20);
|
|
|
|
main_szr->AddSpacer(5);
|
|
|
|
SetSizerAndFit(main_szr);
|
|
|
|
SetFocus();
|
2010-06-06 03:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PadMapDiag::OnAdjust(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
(void)event;
|
2013-08-18 13:43:01 +00:00
|
|
|
for (unsigned int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
int player_idx = m_map_cbox[i]->GetSelection();
|
|
|
|
if (player_idx > 0)
|
|
|
|
m_mapping[i] = m_player_list[player_idx - 1]->pid;
|
|
|
|
else
|
|
|
|
m_mapping[i] = -1;
|
2013-09-22 18:27:52 +00:00
|
|
|
|
|
|
|
player_idx = m_map_cbox[i+4]->GetSelection();
|
|
|
|
if (player_idx > 0)
|
|
|
|
m_wiimapping[i] = m_player_list[player_idx - 1]->pid;
|
|
|
|
else
|
|
|
|
m_wiimapping[i] = -1;
|
2013-08-18 13:43:01 +00:00
|
|
|
}
|
2010-06-06 03:52:11 +00:00
|
|
|
}
|
2013-08-14 21:50:21 +00:00
|
|
|
|
|
|
|
void NetPlay::StopGame()
|
|
|
|
{
|
2014-03-09 20:14:26 +00:00
|
|
|
if (netplay_client != nullptr)
|
2013-09-03 01:54:28 +00:00
|
|
|
netplay_client->Stop();
|
2013-08-14 21:50:21 +00:00
|
|
|
}
|