From ca0b9481ea2be14032d4599bae3bc243f87b2179 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 16 Aug 2015 01:08:51 -0400 Subject: [PATCH] ChangeGameDialog: Internally set the chosen game name Passing in a reference to an empty string is unnecessary and overcomplicates design. --- .../Core/DolphinWX/NetPlay/ChangeGameDialog.cpp | 9 ++++++--- .../Core/DolphinWX/NetPlay/ChangeGameDialog.h | 6 ++++-- Source/Core/DolphinWX/NetPlay/NetWindow.cpp | 17 ++++++++--------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Source/Core/DolphinWX/NetPlay/ChangeGameDialog.cpp b/Source/Core/DolphinWX/NetPlay/ChangeGameDialog.cpp index 57da50a65d..98f6dec441 100644 --- a/Source/Core/DolphinWX/NetPlay/ChangeGameDialog.cpp +++ b/Source/Core/DolphinWX/NetPlay/ChangeGameDialog.cpp @@ -9,9 +9,8 @@ #include "DolphinWX/NetPlay/ChangeGameDialog.h" #include "DolphinWX/NetPlay/NetWindow.h" -ChangeGameDialog::ChangeGameDialog(wxWindow* parent, const CGameListCtrl* const game_list, wxString& game_name) +ChangeGameDialog::ChangeGameDialog(wxWindow* parent, const CGameListCtrl* const game_list) : wxDialog(parent, wxID_ANY, _("Change Game")) - , m_game_name(game_name) { m_game_lbox = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxLB_SORT); m_game_lbox->Bind(wxEVT_LISTBOX_DCLICK, &ChangeGameDialog::OnPick, this); @@ -29,9 +28,13 @@ ChangeGameDialog::ChangeGameDialog(wxWindow* parent, const CGameListCtrl* const SetFocus(); } +wxString ChangeGameDialog::GetChosenGameName() const +{ + return m_game_name; +} + void ChangeGameDialog::OnPick(wxCommandEvent& event) { - // return the selected game name m_game_name = m_game_lbox->GetStringSelection(); EndModal(wxID_OK); } diff --git a/Source/Core/DolphinWX/NetPlay/ChangeGameDialog.h b/Source/Core/DolphinWX/NetPlay/ChangeGameDialog.h index 6e4c24323c..cf530b556d 100644 --- a/Source/Core/DolphinWX/NetPlay/ChangeGameDialog.h +++ b/Source/Core/DolphinWX/NetPlay/ChangeGameDialog.h @@ -12,11 +12,13 @@ class wxListBox; class ChangeGameDialog final : public wxDialog { public: - ChangeGameDialog(wxWindow* parent, const CGameListCtrl* const game_list, wxString& game_name); + ChangeGameDialog(wxWindow* parent, const CGameListCtrl* const game_list); + + wxString GetChosenGameName() const; private: void OnPick(wxCommandEvent& event); wxListBox* m_game_lbox; - wxString& m_game_name; + wxString m_game_name; }; diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp index c604e38956..346b8b0932 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp @@ -445,17 +445,16 @@ void NetPlayDialog::OnThread(wxThreadEvent& event) void NetPlayDialog::OnChangeGame(wxCommandEvent&) { - wxString game_name; - - ChangeGameDialog cgd(this, m_game_list, game_name); + ChangeGameDialog cgd(this, m_game_list); cgd.ShowModal(); - if (game_name.length()) - { - m_selected_game = WxStrToStr(game_name); - netplay_server->ChangeGame(m_selected_game); - m_game_btn->SetLabel(game_name.Prepend(_(" Game : "))); - } + wxString game_name = cgd.GetChosenGameName(); + if (game_name.empty()) + return; + + m_selected_game = WxStrToStr(game_name); + netplay_server->ChangeGame(m_selected_game); + m_game_btn->SetLabel(game_name.Prepend(_(" Game : "))); } void NetPlayDialog::OnConfigPads(wxCommandEvent&)