From 7cc2e3146b55a04cab23db42f832aa306ea6514e Mon Sep 17 00:00:00 2001 From: John Peterson Date: Sat, 4 May 2013 19:27:39 +0200 Subject: [PATCH] Updating Cheats manager when the ISO is changed etc. The Cheats manager should be updated when the ISO is changed because it's non-modal Removing code that read the ID from file because the cheats manager only has a use when an emulation is running (when the ID doesn't need to be read from the ISO again because it's in a variable). This fixes loading Gecko codes for .wad during an emulation because "VolumeHandler::GetVolume()" return false in this case --- Source/Core/DolphinWX/Src/CheatsWindow.cpp | 47 ++++++++++++++------- Source/Core/DolphinWX/Src/CheatsWindow.h | 3 ++ Source/Core/DolphinWX/Src/FrameTools.cpp | 13 ++++++ Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp | 12 +++--- Source/Core/DolphinWX/Src/GeckoCodeDiag.h | 4 +- 5 files changed, 57 insertions(+), 22 deletions(-) diff --git a/Source/Core/DolphinWX/Src/CheatsWindow.cpp b/Source/Core/DolphinWX/Src/CheatsWindow.cpp index ba4918c917..522d30c764 100644 --- a/Source/Core/DolphinWX/Src/CheatsWindow.cpp +++ b/Source/Core/DolphinWX/Src/CheatsWindow.cpp @@ -14,6 +14,7 @@ #include "WxUtils.h" #define MAX_CHEAT_SEARCH_RESULTS_DISPLAY 256 +const std::string title = _("Cheats Manager"); extern std::vector arCodes; extern CFrame* main_frame; @@ -22,26 +23,15 @@ extern CFrame* main_frame; static wxCheatsWindow *g_cheat_window; wxCheatsWindow::wxCheatsWindow(wxWindow* const parent) - : wxDialog(parent, wxID_ANY, _("Cheats Manager"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxDIALOG_NO_PARENT) + : wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxDIALOG_NO_PARENT) { ::g_cheat_window = this; // Create the GUI controls Init_ChildControls(); - // Load Data - Load_ARCodes(); - - // Load Gecko Codes :/ - { - const DiscIO::IVolume* const vol = VolumeHandler::GetVolume(); - if (vol) - { - m_gameini_path = File::GetUserPath(D_GAMECONFIG_IDX) + vol->GetUniqueID() + ".ini"; - m_gameini.Load(m_gameini_path); - m_geckocode_panel->LoadCodes(m_gameini, Core::g_CoreStartupParameter.GetUniqueID()); - } - } + // load codes + UpdateGUI(); SetSize(wxSize(-1, 600)); Center(); @@ -119,7 +109,7 @@ void wxCheatsWindow::Init_ChildControls() m_Notebook_Main->AddPage(m_Tab_Log, _("Logging")); // Button Strip - wxButton* const button_apply = new wxButton(panel, wxID_APPLY, _("Apply"), wxDefaultPosition, wxDefaultSize); + button_apply = new wxButton(panel, wxID_APPLY, _("Apply"), wxDefaultPosition, wxDefaultSize); button_apply->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &wxCheatsWindow::OnEvent_ApplyChanges_Press, this); wxButton* const button_cancel = new wxButton(panel, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize); button_cancel->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &wxCheatsWindow::OnEvent_ButtonClose_Press, this); @@ -249,12 +239,34 @@ void wxCheatsWindow::OnEvent_Close(wxCloseEvent& ev) Destroy(); } +// load codes for a new ISO ID +void wxCheatsWindow::UpdateGUI() +{ + // load code + m_gameini_path = File::GetUserPath(D_GAMECONFIG_IDX) + Core::g_CoreStartupParameter.GetUniqueID() + ".ini"; + m_gameini.Load(m_gameini_path); + Load_ARCodes(); + Load_GeckoCodes(); + + // enable controls + button_apply->Enable(Core::IsRunning()); + + // write the ISO name in the title + if (Core::IsRunning()) + SetTitle(title + ": " + Core::g_CoreStartupParameter.GetUniqueID() + " - " + Core::g_CoreStartupParameter.m_strName); + else + SetTitle(title); +} + void wxCheatsWindow::Load_ARCodes() { using namespace ActionReplay; m_CheckListBox_CheatsList->Clear(); + if (!Core::IsRunning()) + return; + indexList.clear(); size_t size = GetCodeListSize(); for (size_t i = 0; i < size; i++) @@ -269,6 +281,11 @@ void wxCheatsWindow::Load_ARCodes() } } +void wxCheatsWindow::Load_GeckoCodes() +{ + m_geckocode_panel->LoadCodes(m_gameini, Core::g_CoreStartupParameter.GetUniqueID(), true); +} + void wxCheatsWindow::OnEvent_CheatsList_ItemSelected(wxCommandEvent& WXUNUSED (event)) { using namespace ActionReplay; diff --git a/Source/Core/DolphinWX/Src/CheatsWindow.h b/Source/Core/DolphinWX/Src/CheatsWindow.h index 293236e005..244e4d5b48 100644 --- a/Source/Core/DolphinWX/Src/CheatsWindow.h +++ b/Source/Core/DolphinWX/Src/CheatsWindow.h @@ -96,6 +96,7 @@ class wxCheatsWindow : public wxDialog public: wxCheatsWindow(wxWindow* const parent); ~wxCheatsWindow(); + void UpdateGUI(); protected: @@ -105,6 +106,7 @@ class wxCheatsWindow : public wxDialog }; // --- GUI Controls --- + wxButton* button_apply; wxNotebook *m_Notebook_Main; wxPanel *m_Tab_Cheats; @@ -134,6 +136,7 @@ class wxCheatsWindow : public wxDialog void Init_ChildControls(); void Load_ARCodes(); + void Load_GeckoCodes(); // --- Wx Events Handlers --- diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index 57c465abfa..e183669c86 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -1133,6 +1133,7 @@ void CFrame::OnConfigMain(wxCommandEvent& WXUNUSED (event)) CConfigMain ConfigMain(this); if (ConfigMain.ShowModal() == wxID_OK) m_GameListCtrl->Update(); + UpdateGUI(); } void CFrame::OnConfigGFX(wxCommandEvent& WXUNUSED (event)) @@ -1568,6 +1569,9 @@ void CFrame::UpdateGUI() if (DiscIO::CNANDContentManager::Access().GetNANDLoader(TITLEID_SYSMENU).IsValid()) GetMenuBar()->FindItem(IDM_LOAD_WII_MENU)->Enable(!Initialized); + // Tools + GetMenuBar()->FindItem(IDM_CHEATS)->Enable(SConfig::GetInstance().m_LocalCoreStartupParameter.bEnableCheats); + GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Enable(RunningWii); GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Enable(RunningWii); GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Enable(RunningWii); @@ -1675,6 +1679,15 @@ void CFrame::UpdateGUI() // Commit changes to manager m_Mgr->Update(); + + // Update non-modal windows + if (g_CheatsWindow) + { + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bEnableCheats) + g_CheatsWindow->UpdateGUI(); + else + g_CheatsWindow->Close(); + } } void CFrame::UpdateGameList() diff --git a/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp b/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp index 12685fac75..efd4a3a990 100644 --- a/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp +++ b/Source/Core/DolphinWX/Src/GeckoCodeDiag.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "GeckoCodeDiag.h" +#include "Core.h" #include "WxUtils.h" #include @@ -59,10 +60,10 @@ CodeConfigPanel::CodeConfigPanel(wxWindow* const parent) SetSizerAndFit(sizer_main); } -void CodeConfigPanel::UpdateCodeList() +void CodeConfigPanel::UpdateCodeList(bool checkRunning) { // disable the button if it doesn't have an effect - btn_download->Enable(!m_gameid.empty()); + btn_download->Enable((!checkRunning || Core::IsRunning()) && !m_gameid.empty()); m_listbox_gcodes->Clear(); // add the codes to the listbox @@ -80,14 +81,15 @@ void CodeConfigPanel::UpdateCodeList() UpdateInfoBox(evt); } -void CodeConfigPanel::LoadCodes(const IniFile& inifile, const std::string& gameid) +void CodeConfigPanel::LoadCodes(const IniFile& inifile, const std::string& gameid, bool checkRunning) { m_gameid = gameid; m_gcodes.clear(); - Gecko::LoadCodes(inifile, m_gcodes); + if (!checkRunning || Core::IsRunning()) + Gecko::LoadCodes(inifile, m_gcodes); - UpdateCodeList(); + UpdateCodeList(checkRunning); } void CodeConfigPanel::ToggleCode(wxCommandEvent& evt) diff --git a/Source/Core/DolphinWX/Src/GeckoCodeDiag.h b/Source/Core/DolphinWX/Src/GeckoCodeDiag.h index 66bbdbd4bb..0140966c5e 100644 --- a/Source/Core/DolphinWX/Src/GeckoCodeDiag.h +++ b/Source/Core/DolphinWX/Src/GeckoCodeDiag.h @@ -20,7 +20,7 @@ public: CodeConfigPanel(wxWindow* const parent); - void LoadCodes(const IniFile& inifile, const std::string& gameid = ""); + void LoadCodes(const IniFile& inifile, const std::string& gameid = "", bool checkRunning = false); const std::vector& GetCodes() const { return m_gcodes; } protected: @@ -29,7 +29,7 @@ protected: void DownloadCodes(wxCommandEvent&); //void ApplyChanges(wxCommandEvent&); - void UpdateCodeList(); + void UpdateCodeList(bool checkRunning = false); private: std::vector m_gcodes;