Presets: Bugfix: 'Enable Patches' system-menu item is now properly aligned with presets behavior.

- previously: was always not-grayed-out even if presets were enabled, and would get applied on only next restart if set only by preset.
- Also, the presets system now nicely supports menu items too.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4251 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
avihal@gmail.com 2011-01-22 20:40:04 +00:00
parent 101a60a5a4
commit f19dc6f9fb
7 changed files with 90 additions and 14 deletions

View File

@ -779,7 +779,7 @@ bool AppConfig::IsOkApplyPreset(int n)
return false;
}
Console.WriteLn("Applying Preset %d ...", n);
//Console.WriteLn("Applying Preset %d ...", n);
//Have some original and default values at hand to be used later.
Pcsx2Config::GSOptions original_GS = EmuOptions.GS;
@ -800,7 +800,7 @@ bool AppConfig::IsOkApplyPreset(int n)
// (however, vsync IS controlled by the presets).
//
// So, if changing the scope of the presets (making them affect more or less values), the relevant GUI entities
// shoulld me modified to support it.
// should me modified to support it.
//Force some settings as a (current) base for all presets.
@ -1088,6 +1088,8 @@ void AppSaveSettings()
return;
}
Console.WriteLn("Saving ini files...");
SaveUiSettings();
SaveVmSettings();

View File

@ -307,11 +307,17 @@ public:
static bool isOkGetPresetTextAndColor(int n, wxString& label, wxColor& c);
bool IsOkApplyPreset(int n);
//flags to allow manual application of settings to GUI entities. Used by the presets system.
static const int APPLY_FLAG_MANUALLY_PROPAGATE = 0x01;
static const int APPLY_FLAG_FROM_PRESET = 0x02;
//The next 2 flags are used with ApplyConfigToGui which the presets system use:
//Indicates that the scope is only for preset-related items.
static const int APPLY_FLAG_FROM_PRESET = 0x01;
//Indicates that the change should manually propagate to sub items because it's called directly and not as an event.
//Currently used by some panels which contain sub-panels which are affected by presets.
static const int APPLY_FLAG_MANUALLY_PROPAGATE = 0x02;
};
extern void AppLoadSettings();

View File

@ -241,6 +241,7 @@ void Dialogs::BaseConfigurationDialog::OnOk_Click( wxCommandEvent& evt )
{
ScopedOkButtonDisabler disabler(this);
//same as for OnApply_Click
Apply();
if( m_ApplyState.ApplyAll() )
@ -257,7 +258,7 @@ void Dialogs::BaseConfigurationDialog::OnApply_Click( wxCommandEvent& evt )
{
ScopedOkButtonDisabler disabler(this);
//if current instance also holds settings that need application, Apply them.
//if current instance also holds settings that need to be applied, apply them.
//Currently only used by SysConfigDialog, which applies the preset and derivatives (menu system).
//Needs to come before actual panels Apply since they enable/disable themselves upon Preset state,
// so the preset needs to be applied first.
@ -270,8 +271,12 @@ void Dialogs::BaseConfigurationDialog::OnApply_Click( wxCommandEvent& evt )
AppSaveSettings();
}
//avih: FIXME: ? for some reason, this OnCancel_Click is called twice when clicking cancel or closing the dialog (Jake's code?).
void Dialogs::BaseConfigurationDialog::OnCancel_Click( wxCommandEvent& evt )
{
//same as for Ok/Apply: let SysConfigDialog clean-up the presets and derivatives (menu system) if needed.
Cancel();
evt.Skip();
if( m_listbook ) GetConfSettingsTabName() = m_labels[m_listbook->GetSelection()];
}

View File

@ -77,6 +77,7 @@ namespace Dialogs
virtual wxString& GetConfSettingsTabName() const=0;
virtual void Apply() {};
virtual void Cancel() {};
};
// --------------------------------------------------------------------------------------
@ -90,6 +91,7 @@ namespace Dialogs
static wxString GetNameStatic() { return L"CoreSettings"; }
wxString GetDialogName() const { return GetNameStatic(); }
void Apply();
void Cancel();
protected:
virtual wxString& GetConfSettingsTabName() const { return g_Conf->SysSettingsTabName; }

View File

@ -21,6 +21,7 @@
#include "BaseConfigurationDialog.inl"
#include "ModalPopups.h"
#include "Panels/ConfigurationPanels.h"
#include "MainFrame.h"
using namespace Panels;
using namespace pxSizerFlags;
@ -99,6 +100,29 @@ void Dialogs::SysConfigDialog::UpdateGuiForPreset ( int presetIndex, bool preset
}
}
//Main menus behavior regarding presets and changes/cancel/apply from SysConfigDialog:
//1. As long as preset-related values were not changed at SysConfigDialog, menus behave normally.
//2. After the first preset-related change at SysConfigDialog (this function) and before Apply/Ok/Cancel:
// - The menus reflect the temporary pending values, but these preset-controlled items are grayed out even if temporarily presets is unchecked.
//3. When clicking Ok/Apply/Cancel at SysConfigDialog, the menus are re-alligned with g_Conf (including gray out or not as needed).
//NOTE: Enabling the presets and disabling them wihout clicking Apply leaves the pending menu config at last preset values
// (consistent with SysConfigDialog behavior). But unlike SysConfigDialog, the menu items stay grayed out.
// Clicking cancel will revert all pending changes, but clicking apply will commit them, and this includes the menus.
// E.g.:
// 1. Patches (menu) is disabled and presets (SysConfigDialog) is disabled.
// 2. Opening config and checking presets without apply --> patches are visually enabled and grayed out (not yet applied to g_Conf)
// 3. Unchecking presets, still without clicking apply --> patches are visually still enabled (last preset values) and grayed out.
// 4. Clicking Apply (presets still unchecked) --> patches will be enabled and not grayed out, presets are disabled.
// --> If clicking Cancel instead of Apply at 4., will revert everything to the state of 1 (preset disabled, patches disabled and not grayed out).
bool origEnable=preset.EnablePresets;
preset.EnablePresets=true; // will cause preset-related items to be grayed out at the menus regardless of their value.
if ( GetMainFramePtr() )
GetMainFramePtr()->ApplyConfigToGui( preset, AppConfig::APPLY_FLAG_FROM_PRESET | AppConfig::APPLY_FLAG_MANUALLY_PROPAGATE );
// Not really needed as 'preset' is local and dumped anyway. For the sake of future modifications of more GUI elements.
preset.EnablePresets=origEnable;
}
void Dialogs::SysConfigDialog::AddPresetsControl()
@ -191,8 +215,19 @@ void Dialogs::SysConfigDialog::Apply()
//Console.WriteLn("Applying preset to to g_Conf: Preset index: %d, EnablePresets: %s", (int)m_slider_presets->GetValue(), m_check_presets->IsChecked()?"true":"false");
g_Conf->EnablePresets = m_check_presets->IsChecked();
g_Conf->PresetIndex = m_slider_presets->GetValue();
if (GetMainFramePtr())
GetMainFramePtr()->CommitPreset_noTrigger();
}
//Update the main menu system to reflect the original configuration on cancel.
//The config panels don't need this because they just reload themselves with g_Conf when re-opened next time.
//But the menu system has a mostly persistent state that reflects g_Conf (except for when presets are used).
void Dialogs::SysConfigDialog::Cancel()
{
if (GetMainFramePtr())
GetMainFramePtr()->ApplyConfigToGui( *g_Conf, AppConfig::APPLY_FLAG_FROM_PRESET | AppConfig::APPLY_FLAG_MANUALLY_PROPAGATE );
}
Dialogs::SysConfigDialog::SysConfigDialog(wxWindow* parent)
: BaseConfigurationDialog( parent, AddAppName(_("Emulation Settings - %s")), 580 )

View File

@ -634,24 +634,46 @@ void MainEmuFrame::ApplyCoreStatus()
menubar.Enable( MenuId_Sys_Shutdown, SysHasValidState() || CorePlugins.AreAnyInitialized() );
}
//Apply a config to the menu such that the menu reflects it properly
void MainEmuFrame::ApplySettings()
{
ApplyConfigToGui(*g_Conf);
}
//MainEmuFrame needs to be aware which items are affected by presets if AppConfig::APPLY_FLAG_FROM_PRESET is on.
//currently only EnablePatches is affected when the settings come from a preset.
void MainEmuFrame::ApplyConfigToGui(AppConfig& configToApply, int flags)
{
wxMenuBar& menubar( *GetMenuBar() );
menubar.Check( MenuId_EnablePatches, g_Conf->EmuOptions.EnablePatches );
menubar.Check( MenuId_EnableCheats, g_Conf->EmuOptions.EnableCheats );
menubar.Check( MenuId_EnableHostFs, g_Conf->EmuOptions.HostFs );
menubar.Check( MenuId_CDVD_Info, g_Conf->EmuOptions.CdvdVerboseReads );
menubar.Check( MenuId_EnablePatches, configToApply.EmuOptions.EnablePatches );
menubar.Enable( MenuId_EnablePatches, !configToApply.EnablePresets );
if ( !(flags & AppConfig::APPLY_FLAG_FROM_PRESET) )
{//these should not be affected by presets
menubar.Check( MenuId_EnableCheats, configToApply.EmuOptions.EnableCheats );
menubar.Check( MenuId_EnableHostFs, configToApply.EmuOptions.HostFs );
menubar.Check( MenuId_CDVD_Info, configToApply.EmuOptions.CdvdVerboseReads );
#ifdef __LINUX__
menubar.Check( MenuId_Console_Stdio, g_Conf->EmuOptions.ConsoleToStdio );
menubar.Check( MenuId_Console_Stdio, configToApply.EmuOptions.ConsoleToStdio );
#endif
menubar.Check( MenuId_Config_Multitap0Toggle, g_Conf->EmuOptions.MultitapPort0_Enabled );
menubar.Check( MenuId_Config_Multitap1Toggle, g_Conf->EmuOptions.MultitapPort1_Enabled );
menubar.Check( MenuId_Config_Multitap0Toggle, configToApply.EmuOptions.MultitapPort0_Enabled );
menubar.Check( MenuId_Config_Multitap1Toggle, configToApply.EmuOptions.MultitapPort1_Enabled );
}
UpdateIsoSrcSelection();
UpdateIsoSrcSelection(); //shouldn't be affected by presets but updates from g_Conf anyway and not from configToApply, so no problem here.
}
//write pending preset settings from the gui to g_Conf,
// without triggering an overall "settingsApplied" event.
void MainEmuFrame::CommitPreset_noTrigger()
{
wxMenuBar& menubar( *GetMenuBar() );
g_Conf->EmuOptions.EnablePatches = menubar.IsChecked( MenuId_EnablePatches );
}
// ------------------------------------------------------------------------
// "Extensible" Plugin Menus
// ------------------------------------------------------------------------

View File

@ -147,9 +147,13 @@ public:
bool Destroy();
void ApplyConfigToGui( AppConfig& configToApply, int flags=0 ); //flags are: AppConfig::APPLY_CONFIG_FROM_PRESET and (currently unused) AppConfig::APPLY_CONFIG_MANUALLY PROPAGATE
void CommitPreset_noTrigger();
protected:
void DoGiveHelp(const wxString& text, bool show);
//Apply here is from config to GUI.
void ApplySettings();
void ApplyCoreStatus();