| 
									
										
										
										
											2009-07-28 21:32:10 +00:00
										 |  |  | // Copyright (C) 2003 Dolphin Project.
 | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, version 2.0.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU General Public License 2.0 for more details.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // A copy of the GPL 2.0 should have been included with the program.
 | 
					
						
							|  |  |  | // If not, see http://www.gnu.org/licenses/
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Official SVN repository and contact information can be found at
 | 
					
						
							|  |  |  | // http://code.google.com/p/dolphin-emu/
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | #include "NetPlay.h"
 | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | #include "NetWindow.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | #include <sstream>
 | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | #define _connect_macro_( b, f, c, s )	(b)->Connect( wxID_ANY, (c), wxCommandEventHandler( f ), (wxObject*)0, (wxEvtHandler*)s )
 | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | #define NETPLAY_TITLEBAR	"Dolphin NetPlay"
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-05 04:31:21 +00:00
										 |  |  | static NetPlay* netplay_ptr = NULL; | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-02 23:01:50 +00:00
										 |  |  | NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* const game_list) | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	: wxFrame(parent, wxID_ANY, wxT(NETPLAY_TITLEBAR), wxDefaultPosition, wxDefaultSize) | 
					
						
							|  |  |  | 	, m_game_list(game_list) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	//PanicAlert("ALERT: NetPlay is not 100%% functional !!!!");
 | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							|  |  |  | 	wxStaticText* const nick_lbl = new wxStaticText(panel, wxID_ANY, wxT("Nickname :"), wxDefaultPosition, wxDefaultSize); | 
					
						
							|  |  |  | 	m_nickname_text = new wxTextCtrl(panel, wxID_ANY, wxT("Player")); | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							|  |  |  | 	wxNotebook* const notebook = new wxNotebook(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize); | 
					
						
							|  |  |  | 	wxPanel* const connect_tab = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize); | 
					
						
							|  |  |  | 	notebook->AddPage(connect_tab, wxT("Connect")); | 
					
						
							|  |  |  | 	wxPanel* const host_tab = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize); | 
					
						
							|  |  |  | 	notebook->AddPage(host_tab, wxT("Host")); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	// connect tab
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	wxStaticText* const ip_lbl = new wxStaticText(connect_tab, wxID_ANY, wxT("Address :"), wxDefaultPosition, wxDefaultSize); | 
					
						
							|  |  |  | 	m_connect_ip_text = new wxTextCtrl(connect_tab, wxID_ANY, wxT("localhost")); | 
					
						
							|  |  |  | 	wxStaticText* const port_lbl = new wxStaticText(connect_tab, wxID_ANY, wxT("Port :"), wxDefaultPosition, wxDefaultSize); | 
					
						
							|  |  |  | 	m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, wxT("2626")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxButton* const connect_btn = new wxButton(connect_tab, wxID_ANY, wxT("Connect")); | 
					
						
							|  |  |  | 	_connect_macro_(connect_btn, NetPlaySetupDiag::OnJoin, wxEVT_COMMAND_BUTTON_CLICKED, this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxStaticText* const alert_lbl = new wxStaticText(connect_tab, wxID_ANY | 
					
						
							| 
									
										
										
										
											2010-05-02 04:24:49 +00:00
										 |  |  | 		, wxT("ALERT:\n\nNetPlay will currently only work properly when using the following settings:") | 
					
						
							|  |  |  | 			wxT("\n - Dual Core [OFF]") | 
					
						
							| 
									
										
										
										
											2010-05-05 04:31:21 +00:00
										 |  |  | 			wxT("\n - Audio Throttle [OFF/ON] (try both)") | 
					
						
							|  |  |  | 			wxT("\n - DSP LLE/HLE (try both)") | 
					
						
							|  |  |  | 			wxT("\n - Manually set the exact number of controllers that will be used to [Standard Controller]") | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 			wxT("\n\nAll players should try to use the same Dolphin version and settings.") | 
					
						
							|  |  |  | 			wxT("\nDisable all memory cards or send them to all players before starting.") | 
					
						
							| 
									
										
										
										
											2010-05-05 04:31:21 +00:00
										 |  |  | 			wxT("\nWiimote support has not been implemented.") | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 			wxT("\n\nYou must forward TCP port to host!!") | 
					
						
							|  |  |  | 		, wxDefaultPosition, wxDefaultSize); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	wxStaticText* const port_lbl = new wxStaticText(host_tab, wxID_ANY, wxT("Port :"), wxDefaultPosition, wxDefaultSize); | 
					
						
							|  |  |  | 	m_host_port_text = new wxTextCtrl(host_tab, wxID_ANY, wxT("2626")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxButton* const host_btn = new wxButton(host_tab, wxID_ANY, wxT("Host")); | 
					
						
							|  |  |  | 	_connect_macro_(host_btn, NetPlaySetupDiag::OnHost, wxEVT_COMMAND_BUTTON_CLICKED, this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_game_lbox = new wxListBox(host_tab, wxID_ANY); | 
					
						
							| 
									
										
										
										
											2010-05-02 04:24:49 +00:00
										 |  |  | 	_connect_macro_(m_game_lbox, NetPlaySetupDiag::OnHost, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	std::istringstream ss(game_list->GetGameNames()); | 
					
						
							|  |  |  | 	std::string game; | 
					
						
							|  |  |  | 	while (std::getline(ss,game)) | 
					
						
							|  |  |  | 		m_game_lbox->Append(wxString(game.c_str(), *wxConvCurrent)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxBoxSizer* const top_szr = new wxBoxSizer(wxHORIZONTAL); | 
					
						
							|  |  |  | 	top_szr->Add(port_lbl, 0, wxCENTER | wxRIGHT, 5); | 
					
						
							|  |  |  | 	top_szr->Add(m_host_port_text, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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
 | 
					
						
							|  |  |  | 	wxButton* const quit_btn = new wxButton(panel, wxID_ANY, wxT("Quit")); | 
					
						
							|  |  |  | 	_connect_macro_(quit_btn, NetPlaySetupDiag::OnQuit, wxEVT_COMMAND_BUTTON_CLICKED, this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 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-05-01 19:10:35 +00:00
										 |  |  | void NetPlaySetupDiag::OnHost(wxCommandEvent& event) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	if (::netplay_ptr) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		PanicAlert("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()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		PanicAlert("You must choose a game!!"); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	std::string game(m_game_lbox->GetStringSelection().mb_str()); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	NetPlayDiag* const 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); | 
					
						
							|  |  |  | 	if (::netplay_ptr->is_connected) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 		//NetPlayServerDiag* const npsd = 
 | 
					
						
							|  |  |  | 		npd->Show(); | 
					
						
							|  |  |  | 		Destroy(); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 		PanicAlert("Failed to Listen!!"); | 
					
						
							|  |  |  | 		npd->Destroy(); | 
					
						
							|  |  |  | 		// dialog will delete netplay
 | 
					
						
							|  |  |  | 		//delete ::netplay_ptr;
 | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | void NetPlaySetupDiag::OnJoin(wxCommandEvent& event) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	if (::netplay_ptr) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 		PanicAlert("A NetPlay window is already open!!"); | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	NetPlayDiag* const 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, std::string(m_nickname_text->GetValue().mb_str()), npd); | 
					
						
							|  |  |  | 	if (::netplay_ptr->is_connected) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 		//NetPlayServerDiag* const npsd = 
 | 
					
						
							|  |  |  | 		npd->Show(); | 
					
						
							|  |  |  | 		Destroy(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		//PanicAlert("Failed to Connect!!");
 | 
					
						
							|  |  |  | 		npd->Destroy(); | 
					
						
							|  |  |  | 		// dialog will delete netplay
 | 
					
						
							|  |  |  | 		//delete ::netplay_ptr;
 | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | void NetPlaySetupDiag::OnQuit(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Destroy(); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-02 23:01:50 +00:00
										 |  |  | NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game_list | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 						 , const std::string& game, const bool is_hosting) | 
					
						
							|  |  |  | 	: wxFrame(parent, wxID_ANY, wxT(NETPLAY_TITLEBAR), wxDefaultPosition, wxDefaultSize) | 
					
						
							|  |  |  | 	, m_selected_game(game) | 
					
						
							| 
									
										
										
										
											2010-05-01 21:27:48 +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
 | 
					
						
							|  |  |  | 	m_game_btn = new wxButton(panel, wxID_ANY | 
					
						
							|  |  |  | 		, wxString(m_selected_game.c_str(), *wxConvCurrent).Prepend(wxT(" Game : ")), wxDefaultPosition, wxDefaultSize, wxBU_LEFT); | 
					
						
							| 
									
										
										
										
											2010-05-02 23:01:50 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (is_hosting) | 
					
						
							|  |  |  | 		_connect_macro_(m_game_btn, NetPlayDiag::OnChangeGame, wxEVT_COMMAND_BUTTON_CLICKED, this); | 
					
						
							|  |  |  | 	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); | 
					
						
							|  |  |  | 	_connect_macro_(m_chat_msg_text, NetPlayDiag::OnChat, wxEVT_COMMAND_TEXT_ENTER, this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxButton* const chat_msg_btn = new wxButton(panel, wxID_ANY, wxT("Send")); | 
					
						
							|  |  |  | 	_connect_macro_(chat_msg_btn, NetPlayDiag::OnChat, wxEVT_COMMAND_BUTTON_CLICKED, this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxStaticBoxSizer* const chat_szr = new wxStaticBoxSizer(wxVERTICAL, panel, wxT("Chat")); | 
					
						
							|  |  |  | 	chat_szr->Add(m_chat_text, 1, wxEXPAND); | 
					
						
							|  |  |  | 	chat_szr->Add(chat_msg_szr, 0, wxEXPAND | wxTOP, 5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_player_lbox = new wxListBox(panel, wxID_ANY, wxDefaultPosition, wxSize(192,-1)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxStaticBoxSizer* const player_szr = new wxStaticBoxSizer(wxVERTICAL, panel, wxT("Players")); | 
					
						
							|  |  |  | 	player_szr->Add(m_player_lbox, 1, wxEXPAND); | 
					
						
							|  |  |  | 	// player list
 | 
					
						
							|  |  |  | 	if (is_hosting) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 		wxButton* const player_config_btn = new wxButton(panel, wxID_ANY, wxT("Configure Pads [not implemented]")); | 
					
						
							|  |  |  | 		player_config_btn->Disable(); | 
					
						
							|  |  |  | 		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
 | 
					
						
							|  |  |  | 	wxButton* const quit_btn = new wxButton(panel, wxID_ANY, wxT("Quit")); | 
					
						
							|  |  |  | 	_connect_macro_(quit_btn, NetPlayDiag::OnQuit, wxEVT_COMMAND_BUTTON_CLICKED, 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) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		wxButton* const start_btn = new wxButton(panel, wxID_ANY, wxT("Start")); | 
					
						
							|  |  |  | 		_connect_macro_(start_btn, NetPlayDiag::OnStart, wxEVT_COMMAND_BUTTON_CLICKED, this); | 
					
						
							|  |  |  | 		bottom_szr->Add(start_btn); | 
					
						
							| 
									
										
										
										
											2010-05-05 04:31:21 +00:00
										 |  |  | 		wxButton* const stop_btn = new wxButton(panel, wxID_ANY, wxT("Stop")); | 
					
						
							| 
									
										
										
										
											2010-05-02 23:01:50 +00:00
										 |  |  | 		_connect_macro_(stop_btn, NetPlayDiag::OnStop, wxEVT_COMMAND_BUTTON_CLICKED, this); | 
					
						
							|  |  |  | 		bottom_szr->Add(stop_btn); | 
					
						
							| 
									
										
										
										
											2010-05-05 04:31:21 +00:00
										 |  |  | 		bottom_szr->Add(new wxStaticText(panel, wxID_ANY, wxT("Buffer:")), 0, wxLEFT | wxCENTER, 5 ); | 
					
						
							|  |  |  | 		wxSpinCtrl* const padbuf_spin = new wxSpinCtrl(panel, wxID_ANY, wxT("20") | 
					
						
							|  |  |  | 			, wxDefaultPosition, wxSize(64, -1), wxSP_ARROW_KEYS, 0, 200, 20); | 
					
						
							|  |  |  | 		_connect_macro_(padbuf_spin, NetPlayDiag::OnAdjustBuffer, wxEVT_COMMAND_SPINCTRL_UPDATED, this); | 
					
						
							|  |  |  | 		wxButton* const padbuf_btn = new wxButton(panel, wxID_ANY, wxT("?"), wxDefaultPosition, wxSize(22, -1)); | 
					
						
							|  |  |  | 		_connect_macro_(padbuf_btn, NetPlayDiag::OnPadBuffHelp, wxEVT_COMMAND_BUTTON_CLICKED, this); | 
					
						
							|  |  |  | 		bottom_szr->Add(padbuf_spin, 0, wxCENTER); | 
					
						
							|  |  |  | 		bottom_szr->Add(padbuf_btn); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	if (::netplay_ptr) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 		delete netplay_ptr; | 
					
						
							|  |  |  | 		::netplay_ptr = NULL; | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NetPlayDiag::OnChat(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxString s = m_chat_msg_text->GetValue(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (s.Length()) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 		::netplay_ptr->SendChatMessage(std::string(s.mb_str())); | 
					
						
							|  |  |  | 		m_chat_text->AppendText(s.Prepend(wxT(" >> ")).Append(wxT('\n'))); | 
					
						
							|  |  |  | 		m_chat_msg_text->Clear(); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | void NetPlayDiag::OnStart(wxCommandEvent& event) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	// 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)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		std::getline(pss,ptmp); | 
					
						
							|  |  |  | 		if (m_selected_game == ntmp) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 			path = ptmp; | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	if (path.length()) | 
					
						
							|  |  |  | 		::netplay_ptr->StartGame(path); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		PanicAlert("Game not found!!"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-09-02 21:00:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-02 23:01:50 +00:00
										 |  |  | void NetPlayDiag::OnStop(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	::netplay_ptr->StopGame(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-05 04:31:21 +00:00
										 |  |  | void NetPlayDiag::OnPadBuffHelp(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const u64 time = ((NetPlayServer*)::netplay_ptr)->CalculateMinimumBufferTime(); | 
					
						
							|  |  |  | 	std::ostringstream ss; | 
					
						
							|  |  |  | 	ss << "< Calculated from pings: required buffer: " | 
					
						
							|  |  |  | 		<< time * (60/1000) << "(60fps) / " | 
					
						
							|  |  |  | 		<< time * (50/1000) << "(50fps) >\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_chat_text->AppendText(wxString(ss.str().c_str(), *wxConvCurrent)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NetPlayDiag::OnAdjustBuffer(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const int val = ((wxSpinCtrl*)event.GetEventObject())->GetValue(); | 
					
						
							|  |  |  | 	((NetPlayServer*)::netplay_ptr)->AdjustPadBufferSize(val); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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'))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | void NetPlayDiag::OnQuit(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 	// player list
 | 
					
						
							|  |  |  | 	std::string tmps; | 
					
						
							|  |  |  | 	::netplay_ptr->GetPlayerList(tmps); | 
					
						
							| 
									
										
										
										
											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)) | 
					
						
							|  |  |  | 		m_player_lbox->Append(wxString(tmps.c_str(), *wxConvCurrent)); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2010-05-01 19:10:35 +00:00
										 |  |  | 		m_selected_game.assign(event.GetString().mb_str()); | 
					
						
							|  |  |  | 		m_game_btn->SetLabel(event.GetString().Prepend(wxT(" 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
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2010-05-02 04:24:49 +00:00
										 |  |  | 		wxCommandEvent evt; | 
					
						
							|  |  |  | 		OnStart(evt); | 
					
						
							| 
									
										
										
										
											2010-05-02 23:01:50 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case NP_GUI_EVT_STOP_GAME : | 
					
						
							|  |  |  | 		// client stop game
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		wxCommandEvent evt; | 
					
						
							|  |  |  | 		OnStop(evt); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											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());
 | 
					
						
							|  |  |  | 		m_chat_text->AppendText(wxString(s.c_str(), *wxConvCurrent).Append(wxT('\n'))); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-05-02 23:01:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void NetPlayDiag::OnChangeGame(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxString game_name; | 
					
						
							|  |  |  | 	ChangeGameDiag* const cgd = new ChangeGameDiag(this, m_game_list, game_name); | 
					
						
							|  |  |  | 	cgd->ShowModal(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (game_name.length()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_selected_game = std::string(game_name.mb_str()); | 
					
						
							|  |  |  | 		::netplay_ptr->ChangeGame(m_selected_game); | 
					
						
							|  |  |  | 		m_game_btn->SetLabel(game_name.Prepend(wxT(" Game : "))); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ChangeGameDiag::ChangeGameDiag(wxWindow* const parent, const CGameListCtrl* const game_list, wxString& game_name) | 
					
						
							|  |  |  | 	: wxDialog(parent, wxID_ANY, wxT("Change Game"), wxDefaultPosition, wxDefaultSize) | 
					
						
							|  |  |  | 	, m_game_name(game_name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	wxPanel* const panel = new wxPanel(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_game_lbox = new wxListBox(panel, wxID_ANY); | 
					
						
							|  |  |  | 	_connect_macro_(m_game_lbox, ChangeGameDiag::OnPick, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, 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)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxButton* const ok_btn = new wxButton(panel, wxID_ANY, wxT("Change")); | 
					
						
							|  |  |  | 	_connect_macro_(ok_btn, ChangeGameDiag::OnPick, wxEVT_COMMAND_BUTTON_CLICKED, this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	panel->SetSizerAndFit(szr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wxBoxSizer* const dlg_szr = new wxBoxSizer(wxVERTICAL); | 
					
						
							|  |  |  | 	dlg_szr->Add(panel, 1, wxEXPAND); | 
					
						
							|  |  |  | 	SetSizerAndFit(dlg_szr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ChangeGameDiag::OnPick(wxCommandEvent& event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// warning removal
 | 
					
						
							|  |  |  | 	event.GetId(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// return the selected game name
 | 
					
						
							|  |  |  | 	m_game_name = m_game_lbox->GetStringSelection(); | 
					
						
							|  |  |  | 	Destroy(); | 
					
						
							|  |  |  | } |