Skip to content

Commit

Permalink
Merge pull request #4427 from lioncash/config-update
Browse files Browse the repository at this point in the history
DolphinWX: Enable/disable config UI options based on core state
  • Loading branch information
lioncash committed Nov 6, 2016
2 parents 3924a99 + c2d00d2 commit 136a104
Show file tree
Hide file tree
Showing 25 changed files with 293 additions and 187 deletions.
1 change: 1 addition & 0 deletions Source/Core/DolphinWX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ set(GUI_SRCS
SoftwareVideoConfigDialog.cpp
TASInputDlg.cpp
VideoConfigDiag.cpp
WxEventUtils.cpp
WXInputBase.cpp
WxUtils.cpp)

Expand Down
79 changes: 42 additions & 37 deletions Source/Core/DolphinWX/Config/AdvancedConfigPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "DolphinWX/Config/AdvancedConfigPane.h"

#include <cmath>

#include <wx/checkbox.h>
Expand All @@ -14,14 +16,14 @@

#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "DolphinWX/Config/AdvancedConfigPane.h"
#include "DolphinWX/DolphinSlider.h"
#include "DolphinWX/WxEventUtils.h"

AdvancedConfigPane::AdvancedConfigPane(wxWindow* parent, wxWindowID id) : wxPanel(parent, id)
{
InitializeGUI();
LoadGUIValues();
RefreshGUI();
BindEvents();
}

void AdvancedConfigPane::InitializeGUI()
Expand All @@ -31,22 +33,10 @@ void AdvancedConfigPane::InitializeGUI()
new DolphinSlider(this, wxID_ANY, 100, 0, 150, wxDefaultPosition, FromDIP(wxSize(200, -1)));
m_clock_override_text = new wxStaticText(this, wxID_ANY, "");

m_clock_override_checkbox->Bind(wxEVT_CHECKBOX,
&AdvancedConfigPane::OnClockOverrideCheckBoxChanged, this);
m_clock_override_slider->Bind(wxEVT_SLIDER, &AdvancedConfigPane::OnClockOverrideSliderChanged,
this);

m_custom_rtc_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Custom RTC"));
m_custom_rtc_date_picker = new wxDatePickerCtrl(this, wxID_ANY);
m_custom_rtc_time_picker = new wxTimePickerCtrl(this, wxID_ANY);

m_custom_rtc_checkbox->Bind(wxEVT_CHECKBOX, &AdvancedConfigPane::OnCustomRTCCheckBoxChanged,
this);
m_custom_rtc_date_picker->Bind(wxEVT_DATE_CHANGED, &AdvancedConfigPane::OnCustomRTCDateChanged,
this);
m_custom_rtc_time_picker->Bind(wxEVT_TIME_CHANGED, &AdvancedConfigPane::OnCustomRTCTimeChanged,
this);

wxStaticText* const clock_override_description =
new wxStaticText(this, wxID_ANY, _("Higher values can make variable-framerate games "
"run at a higher framerate, at the expense of CPU. "
Expand Down Expand Up @@ -122,6 +112,33 @@ void AdvancedConfigPane::LoadGUIValues()
LoadCustomRTC();
}

void AdvancedConfigPane::BindEvents()
{
m_clock_override_checkbox->Bind(wxEVT_CHECKBOX,
&AdvancedConfigPane::OnClockOverrideCheckBoxChanged, this);
m_clock_override_checkbox->Bind(wxEVT_UPDATE_UI, &AdvancedConfigPane::OnUpdateCPUClockControls,
this);

m_clock_override_slider->Bind(wxEVT_SLIDER, &AdvancedConfigPane::OnClockOverrideSliderChanged,
this);
m_clock_override_slider->Bind(wxEVT_UPDATE_UI, &AdvancedConfigPane::OnUpdateCPUClockControls,
this);

m_custom_rtc_checkbox->Bind(wxEVT_CHECKBOX, &AdvancedConfigPane::OnCustomRTCCheckBoxChanged,
this);
m_custom_rtc_checkbox->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning);

m_custom_rtc_date_picker->Bind(wxEVT_DATE_CHANGED, &AdvancedConfigPane::OnCustomRTCDateChanged,
this);
m_custom_rtc_date_picker->Bind(wxEVT_UPDATE_UI, &AdvancedConfigPane::OnUpdateRTCDateTimeEntries,
this);

m_custom_rtc_time_picker->Bind(wxEVT_TIME_CHANGED, &AdvancedConfigPane::OnCustomRTCTimeChanged,
this);
m_custom_rtc_time_picker->Bind(wxEVT_UPDATE_UI, &AdvancedConfigPane::OnUpdateRTCDateTimeEntries,
this);
}

void AdvancedConfigPane::OnClockOverrideCheckBoxChanged(wxCommandEvent& event)
{
SConfig::GetInstance().m_OCEnable = m_clock_override_checkbox->IsChecked();
Expand Down Expand Up @@ -188,17 +205,6 @@ void AdvancedConfigPane::LoadCustomRTC()
// Limit dates to a valid range (Jan 1/2000 to Dec 31/2099)
m_custom_rtc_date_picker->SetRange(wxDateTime(1, wxDateTime::Jan, 2000),
wxDateTime(31, wxDateTime::Dec, 2099));
if (Core::IsRunning())
{
m_custom_rtc_checkbox->Enable(false);
m_custom_rtc_date_picker->Enable(false);
m_custom_rtc_time_picker->Enable(false);
}
else
{
m_custom_rtc_date_picker->Enable(custom_rtc_enabled);
m_custom_rtc_time_picker->Enable(custom_rtc_enabled);
}
}

void AdvancedConfigPane::UpdateCustomRTC(time_t date, time_t time)
Expand All @@ -209,19 +215,18 @@ void AdvancedConfigPane::UpdateCustomRTC(time_t date, time_t time)
m_custom_rtc_time_picker->SetValue(custom_rtc);
}

void AdvancedConfigPane::RefreshGUI()
void AdvancedConfigPane::OnUpdateCPUClockControls(wxUpdateUIEvent& event)
{
// Don't allow users to edit the RTC while the game is running
if (Core::IsRunning())
if (!Core::IsRunning())
{
m_custom_rtc_checkbox->Disable();
m_custom_rtc_date_picker->Disable();
m_custom_rtc_time_picker->Disable();
}
// Allow users to edit CPU clock speed in game, but not while needing determinism
if (Core::IsRunning() && Core::g_want_determinism)
{
m_clock_override_checkbox->Disable();
m_clock_override_slider->Disable();
event.Enable(true);
return;
}

event.Enable(!Core::g_want_determinism);
}

void AdvancedConfigPane::OnUpdateRTCDateTimeEntries(wxUpdateUIEvent& event)
{
event.Enable(!Core::IsRunning() && m_custom_rtc_checkbox->IsChecked());
}
5 changes: 4 additions & 1 deletion Source/Core/DolphinWX/Config/AdvancedConfigPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class AdvancedConfigPane final : public wxPanel
private:
void InitializeGUI();
void LoadGUIValues();
void RefreshGUI();
void BindEvents();

void OnUpdateCPUClockControls(wxUpdateUIEvent&);
void OnUpdateRTCDateTimeEntries(wxUpdateUIEvent&);

void OnClockOverrideCheckBoxChanged(wxCommandEvent&);
void OnClockOverrideSliderChanged(wxCommandEvent&);
Expand Down
36 changes: 19 additions & 17 deletions Source/Core/DolphinWX/Config/AudioConfigPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "DolphinWX/Config/AudioConfigPane.h"

#include <string>

#include <wx/checkbox.h>
Expand All @@ -16,15 +18,15 @@
#include "Common/Common.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "DolphinWX/Config/AudioConfigPane.h"
#include "DolphinWX/DolphinSlider.h"
#include "DolphinWX/WxEventUtils.h"
#include "DolphinWX/WxUtils.h"

AudioConfigPane::AudioConfigPane(wxWindow* parent, wxWindowID id) : wxPanel(parent, id)
{
InitializeGUI();
LoadGUIValues();
RefreshGUI();
BindEvents();
}

void AudioConfigPane::InitializeGUI()
Expand All @@ -46,13 +48,6 @@ void AudioConfigPane::InitializeGUI()
new wxSpinCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 30);
m_audio_latency_label = new wxStaticText(this, wxID_ANY, _("Latency:"));

m_dsp_engine_radiobox->Bind(wxEVT_RADIOBOX, &AudioConfigPane::OnDSPEngineRadioBoxChanged, this);
m_dpl2_decoder_checkbox->Bind(wxEVT_CHECKBOX, &AudioConfigPane::OnDPL2DecoderCheckBoxChanged,
this);
m_volume_slider->Bind(wxEVT_SLIDER, &AudioConfigPane::OnVolumeSliderChanged, this);
m_audio_backend_choice->Bind(wxEVT_CHOICE, &AudioConfigPane::OnAudioBackendChanged, this);
m_audio_latency_spinctrl->Bind(wxEVT_SPINCTRL, &AudioConfigPane::OnLatencySpinCtrlChanged, this);

m_audio_backend_choice->SetToolTip(
_("Changing this will have no effect while the emulator is running."));
m_audio_latency_spinctrl->SetToolTip(_("Sets the latency (in ms). Higher values may reduce audio "
Expand Down Expand Up @@ -139,15 +134,22 @@ void AudioConfigPane::ToggleBackendSpecificControls(const std::string& backend)
m_volume_text->Enable(supports_volume_changes);
}

void AudioConfigPane::RefreshGUI()
void AudioConfigPane::BindEvents()
{
if (Core::IsRunning())
{
m_audio_latency_spinctrl->Disable();
m_audio_backend_choice->Disable();
m_dpl2_decoder_checkbox->Disable();
m_dsp_engine_radiobox->Disable();
}
m_dsp_engine_radiobox->Bind(wxEVT_RADIOBOX, &AudioConfigPane::OnDSPEngineRadioBoxChanged, this);
m_dsp_engine_radiobox->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning);

m_dpl2_decoder_checkbox->Bind(wxEVT_CHECKBOX, &AudioConfigPane::OnDPL2DecoderCheckBoxChanged,
this);
m_dpl2_decoder_checkbox->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning);

m_volume_slider->Bind(wxEVT_SLIDER, &AudioConfigPane::OnVolumeSliderChanged, this);

m_audio_backend_choice->Bind(wxEVT_CHOICE, &AudioConfigPane::OnAudioBackendChanged, this);
m_audio_backend_choice->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning);

m_audio_latency_spinctrl->Bind(wxEVT_SPINCTRL, &AudioConfigPane::OnLatencySpinCtrlChanged, this);
m_audio_latency_spinctrl->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning);
}

void AudioConfigPane::OnDSPEngineRadioBoxChanged(wxCommandEvent& event)
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/Config/AudioConfigPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AudioConfigPane final : public wxPanel
private:
void InitializeGUI();
void LoadGUIValues();
void RefreshGUI();
void BindEvents();

void PopulateBackendChoiceBox();
void ToggleBackendSpecificControls(const std::string& backend);
Expand Down
39 changes: 28 additions & 11 deletions Source/Core/DolphinWX/Config/ConfigMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "DolphinWX/Config/ConfigMain.h"

#include <wx/debug.h>
#include <wx/notebook.h>
#include <wx/panel.h>
#include <wx/sizer.h>
Expand All @@ -10,16 +13,15 @@
#include "Common/CommonTypes.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/Movie.h"
#include "Core/NetPlayProto.h"
#include "DolphinWX/Config/AdvancedConfigPane.h"
#include "DolphinWX/Config/AudioConfigPane.h"
#include "DolphinWX/Config/ConfigMain.h"
#include "DolphinWX/Config/GameCubeConfigPane.h"
#include "DolphinWX/Config/GeneralConfigPane.h"
#include "DolphinWX/Config/InterfaceConfigPane.h"
#include "DolphinWX/Config/PathConfigPane.h"
#include "DolphinWX/Config/WiiConfigPane.h"
#include "DolphinWX/GameListCtrl.h"
#include "DolphinWX/WxUtils.h"

// Sent by child panes to signify that the game list should
Expand All @@ -35,6 +37,7 @@ CConfigMain::CConfigMain(wxWindow* parent, wxWindowID id, const wxString& title,

Bind(wxEVT_CLOSE_WINDOW, &CConfigMain::OnClose, this);
Bind(wxEVT_BUTTON, &CConfigMain::OnCloseButton, this, wxID_CLOSE);
Bind(wxEVT_SHOW, &CConfigMain::OnShow, this);
Bind(wxDOLPHIN_CFG_REFRESH_LIST, &CConfigMain::OnSetRefreshGameListOnClose, this);

wxDialog::SetExtraStyle(GetExtraStyle() & ~wxWS_EX_BLOCK_EVENTS);
Expand All @@ -46,14 +49,22 @@ CConfigMain::~CConfigMain()
{
}

void CConfigMain::SetSelectedTab(int tab)
void CConfigMain::SetSelectedTab(wxWindowID tab_id)
{
// TODO : this is just a quick and dirty way to do it, possible cleanup

switch (tab)
switch (tab_id)
{
case ID_GENERALPAGE:
case ID_DISPLAYPAGE:
case ID_AUDIOPAGE:
Notebook->SetSelection(2);
case ID_GAMECUBEPAGE:
case ID_WIIPAGE:
case ID_PATHSPAGE:
case ID_ADVANCEDPAGE:
Notebook->SetSelection(Notebook->FindPage(Notebook->FindWindowById(tab_id)));
break;

default:
wxASSERT_MSG(false, wxString::Format("Invalid tab page ID specified (%d)", tab_id));
break;
}
}
Expand Down Expand Up @@ -96,16 +107,22 @@ void CConfigMain::CreateGUIControls()
SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED);
SetLayoutAdaptationLevel(wxDIALOG_ADAPTATION_STANDARD_SIZER);
SetSizerAndFit(main_sizer);
Center();
SetFocus();
}

void CConfigMain::OnClose(wxCloseEvent& WXUNUSED(event))
{
EndModal((m_refresh_game_list_on_close) ? wxID_OK : wxID_CANCEL);
Hide();

// Save the config. Dolphin crashes too often to only save the settings on closing
SConfig::GetInstance().SaveSettings();

if (m_refresh_game_list_on_close)
AddPendingEvent(wxCommandEvent{DOLPHIN_EVT_RELOAD_GAMELIST});
}

void CConfigMain::OnShow(wxShowEvent& event)
{
if (event.IsShown())
CenterOnParent();
}

void CConfigMain::OnCloseButton(wxCommandEvent& WXUNUSED(event))
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/DolphinWX/Config/ConfigMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CConfigMain : public wxDialog
long style = wxDEFAULT_DIALOG_STYLE);
virtual ~CConfigMain();

void SetSelectedTab(int tab);
void SetSelectedTab(wxWindowID tab_id);

enum
{
Expand All @@ -39,6 +39,7 @@ class CConfigMain : public wxDialog
void CreateGUIControls();
void OnClose(wxCloseEvent& event);
void OnCloseButton(wxCommandEvent& event);
void OnShow(wxShowEvent& event);
void OnSetRefreshGameListOnClose(wxCommandEvent& event);

wxNotebook* Notebook;
Expand Down

0 comments on commit 136a104

Please sign in to comment.