Fix an issue when a wiimote source is changed to a real wiimote in the wiimote config dialog while a game is running, and the wiimote was disconnected from the CPU. Only change the connection status when the dialog is closed.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7229 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2011-02-23 03:06:16 +00:00
parent 39573ca959
commit ceb03781dc
3 changed files with 50 additions and 13 deletions

View File

@ -105,9 +105,10 @@ void CFrame::ToggleLogConfigWindow(bool bShow)
{ {
if (!m_LogConfigWindow) if (!m_LogConfigWindow)
m_LogConfigWindow = new LogConfigWindow(this, m_LogWindow, IDM_LOGCONFIGWINDOW); m_LogConfigWindow = new LogConfigWindow(this, m_LogWindow, IDM_LOGCONFIGWINDOW);
const int nbIndex = IDM_LOGCONFIGWINDOW - IDM_LOGWINDOW;
DoAddPage(m_LogConfigWindow, DoAddPage(m_LogConfigWindow,
g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[1] : 0, g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[nbIndex] : 0,
g_pCodeWindow ? bFloatWindow[1] : false); g_pCodeWindow ? bFloatWindow[nbIndex] : false);
} }
else else
{ {
@ -147,9 +148,10 @@ void CFrame::ToggleConsole(bool bShow)
ConsoleWin->Reparent(ConsoleParent); ConsoleWin->Reparent(ConsoleParent);
ConsoleParent->Enable(); ConsoleParent->Enable();
const int nbIndex = IDM_CONSOLEWINDOW - IDM_LOGWINDOW;
DoAddPage(ConsoleParent, DoAddPage(ConsoleParent,
g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[1] : 0, g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[nbIndex] : 0,
g_pCodeWindow ? bFloatWindow[1] : false); g_pCodeWindow ? bFloatWindow[nbIndex] : false);
} }
else // Hide else // Hide
{ {

View File

@ -1,6 +1,7 @@
#include "WiimoteConfigDiag.h" #include "WiimoteConfigDiag.h"
#include "HW/Wiimote.h" #include "HW/Wiimote.h"
#include "HW/WiimoteReal/WiimoteReal.h"
#include "Frame.h" #include "Frame.h"
#define _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler(f), (wxObject*)0, (wxEvtHandler*)s) #define _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler(f), (wxObject*)0, (wxEvtHandler*)s)
@ -14,7 +15,7 @@ const wxString& ConnectedWiimotesString()
WiimoteConfigPage::WiimoteConfigPage(wxWindow* const parent, const int index) WiimoteConfigPage::WiimoteConfigPage(wxWindow* const parent, const int index)
: wxNotebookPage(parent, -1, wxDefaultPosition, wxDefaultSize) : wxNotebookPage(parent, -1, wxDefaultPosition, wxDefaultSize)
, m_index(index) , m_index(index), orig_source(g_wiimote_sources[index]), end_source(g_wiimote_sources[index])
{ {
// input source // input source
const wxString src_choices[] = { _("None"), const wxString src_choices[] = { _("None"),
@ -66,19 +67,20 @@ WiimoteConfigPage::WiimoteConfigPage(wxWindow* const parent, const int index)
WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin) WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin)
: wxDialog(parent, -1, _("Dolphin Wiimote Configuration"), wxDefaultPosition, wxDefaultSize) : wxDialog(parent, -1, _("Dolphin Wiimote Configuration"), wxDefaultPosition, wxDefaultSize)
, m_plugin(plugin) , m_plugin(plugin), m_save(false)
{ {
m_pad_notebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT); m_pad_notebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT);
for (unsigned int i = 0; i < 4; ++i) for (unsigned int i = 0; i < 4; ++i)
{ {
WiimoteConfigPage* const wpage = new WiimoteConfigPage(m_pad_notebook, i); WiimoteConfigPage* const wpage = new WiimoteConfigPage(m_pad_notebook, i);
//m_padpages.push_back(wpage);
m_pad_notebook->AddPage(wpage, wxString(_("Wiimote ")) + wxChar('1'+i)); m_pad_notebook->AddPage(wpage, wxString(_("Wiimote ")) + wxChar('1'+i));
} }
wxButton* const ok_button = new wxButton(this, -1, _("OK"), wxDefaultPosition); wxButton* const ok_button = new wxButton(this, -1, _("OK"), wxDefaultPosition);
_connect_macro_(ok_button, WiimoteConfigDiag::Save, wxEVT_COMMAND_BUTTON_CLICKED, this); _connect_macro_(ok_button, WiimoteConfigDiag::Save, wxEVT_COMMAND_BUTTON_CLICKED, this);
Connect(wxID_ANY, wxEVT_CLOSE_WINDOW, wxCloseEventHandler(WiimoteConfigDiag::OnClose), (wxObject*)0, this);
wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(m_pad_notebook, 1, wxEXPAND | wxALL, 5); main_sizer->Add(m_pad_notebook, 1, wxEXPAND | wxALL, 5);
main_sizer->Add(ok_button, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 5); main_sizer->Add(ok_button, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 5);
@ -128,11 +130,28 @@ void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent&)
void WiimoteConfigPage::SelectSource(wxCommandEvent& event) void WiimoteConfigPage::SelectSource(wxCommandEvent& event)
{ {
// should be kinda fine, maybe should just set when user clicks OK, w/e change it later // This needs to be changed now in order for refresh to work right.
g_wiimote_sources[m_index] = event.GetInt(); // Revert if the dialog is canceled.
g_wiimote_sources[m_index] = end_source = event.GetInt();
}
// Connect or disconnect emulated wiimotes (maybe do this in when OK is clicked too?). void WiimoteConfigPage::UpdateWiimoteStatus()
CFrame::ConnectWiimote(m_index, WIIMOTE_SRC_EMU & g_wiimote_sources[m_index]); {
if (orig_source != end_source)
{
// Disconnect first, otherwise the new source doesn't seem to work
CFrame::ConnectWiimote(m_index, false);
// Connect wiimotes
if (WIIMOTE_SRC_EMU & g_wiimote_sources[m_index])
CFrame::ConnectWiimote(m_index, true);
else if (WIIMOTE_SRC_REAL & g_wiimote_sources[m_index] && orig_source & WIIMOTE_SRC_EMU)
CFrame::ConnectWiimote(m_index, WiimoteReal::g_wiimotes[m_index]->IsConnected());
}
}
void WiimoteConfigPage::RevertSource()
{
g_wiimote_sources[m_index] = orig_source;
} }
void WiimoteConfigDiag::Save(wxCommandEvent&) void WiimoteConfigDiag::Save(wxCommandEvent&)
@ -150,8 +169,20 @@ void WiimoteConfigDiag::Save(wxCommandEvent&)
sec.Set("Source", (int)g_wiimote_sources[i]); sec.Set("Source", (int)g_wiimote_sources[i]);
} }
for (size_t p = 0; p < m_pad_notebook->GetPageCount(); ++p)
((WiimoteConfigPage*)m_pad_notebook->GetPage(p))->UpdateWiimoteStatus();
inifile.Save(ini_filename); inifile.Save(ini_filename);
m_save = true;
Close(); Close();
} }
void WiimoteConfigDiag::OnClose(wxCloseEvent& event)
{
if (!m_save)
for (size_t p = 0; p < m_pad_notebook->GetPageCount(); ++p)
((WiimoteConfigPage*)m_pad_notebook->GetPage(p))->RevertSource();
event.Skip();
}

View File

@ -21,11 +21,14 @@ public:
WiimoteConfigPage(wxWindow* const parent, const int index); WiimoteConfigPage(wxWindow* const parent, const int index);
void SelectSource(wxCommandEvent& event); void SelectSource(wxCommandEvent& event);
void UpdateWiimoteStatus();
void RevertSource();
wxStaticText* connected_wiimotes_txt; wxStaticText* connected_wiimotes_txt;
private: private:
const int m_index; const int m_index;
unsigned int orig_source, end_source;
}; };
class WiimoteConfigDiag : public wxDialog class WiimoteConfigDiag : public wxDialog
@ -43,10 +46,11 @@ public:
void UpdateGUI(); void UpdateGUI();
private: private:
void OnClose(wxCloseEvent& event);
InputPlugin& m_plugin; InputPlugin& m_plugin;
wxNotebook* m_pad_notebook; wxNotebook* m_pad_notebook;
bool m_save;
}; };