Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMSUSD-717: USD Prefs: "Use Display Color" preferences are maintained when user cancels change #3553

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions plugin/adsk/scripts/mayaUsd_preferenceTab.mel
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ global proc mayaUsd_PrefUntexturedModeChanged()
if (`radioButtonGrp -exists usdPrefUntexturedMode`) {
int $sel = `radioButtonGrp -q -select usdPrefUntexturedMode`;
optionVar -iv mayaUsd_ShowDisplayColorTextureOff ($sel == 2);

// Set a temporary optionVar saying that we have changed the untextured mode
// so in case user cancels, we can do reset again.
optionVar -transient -iv mayaUsd_PrefUntexturedModeChanged 1;
Comment on lines +97 to +100
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transient optionvars are not saved when exiting Maya. ogs -reset is not a cheap operation so we should not just call it unless needed (such as when opening the pref dialog we don't need to call it). Use this optionvar to keep track of when the untextured mode pref changes and only call ogs -reset when needed.

ogs -reset;
}
}
Expand All @@ -104,6 +108,13 @@ global proc mayaUsd_PrefInitOptionVars(int $forceFactoryDefault)
string $saveLayerFormatArgBinaryOptionPref = `python("import mayaUsd.lib as mlib; mlib.OptionVarTokens.SaveLayerFormatArgBinaryOption")`;
string $confirmExistingFileSaveOptionPref = `python("import mayaUsd.lib as mlib; mlib.OptionVarTokens.ConfirmExistingFileSave")`;

// Special case for the resetting the untextured mode.
if ($forceFactoryDefault && `optionVar -exists "mayaUsd_ShowDisplayColorTextureOff"`) {
if (`optionVar -q "mayaUsd_ShowDisplayColorTextureOff"`) {
optionVar -transient -iv mayaUsd_PrefUntexturedModeChanged 1;
}
}

int $mjv = `about -majorVersion`;
if ($mjv <= 2022) {
if ($forceFactoryDefault || !`optionVar -exists mayaUsd_SerializedUsdEditsLocation`) {
Expand Down Expand Up @@ -155,8 +166,13 @@ global proc mayaUsd_PrefInitOptionVars(int $forceFactoryDefault)
-iv mayaUsd_ShowDisplayColorTextureOff false
;
}
// Need to refresh the viewport for display mayaUsd_ShowDisplayColorTextureOff
ogs -reset;

if ($forceFactoryDefault && `optionVar -q mayaUsd_PrefUntexturedModeChanged`)
{
// Need to refresh the viewport for display mayaUsd_ShowDisplayColorTextureOff
optionVar -remove mayaUsd_PrefUntexturedModeChanged;
ogs -reset;
}
}

global proc mayaUsd_PrefCreateTab()
Expand Down Expand Up @@ -392,10 +408,22 @@ global proc mayaUsd_PrefHoldState(string $mode)
};
prefsHoldOptionVars($prefOptionVars, $mode);

if ($mode == "remove") {
// Finalize preference changes into MayaUsd.
if ($mode == "save") {
// Preferences dialog was opened, make sure we don't have this transient optionVar.
optionVar -remove mayaUsd_PrefUntexturedModeChanged;
}

if ($mode == "restore") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation seems off here..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it is a mix of tabs/spaces. I'll fix it.

if (`optionVar -q mayaUsd_PrefUntexturedModeChanged`) {
// Need to refresh the viewport for display mayaUsd_ShowDisplayColorTextureOff
ogs -reset;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the mayaUsd_PrefUntexturedModeChanged optionVar once the viewport is reset?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is covered by the "restore" case just below. when you click cancel on the prefs dialog this function will be called twice (restore, then remove). When you click save from the prefs dialog it will be called with "remove".

}
}

if ($mode == "remove") {
optionVar -remove mayaUsd_PrefUntexturedModeChanged;
}

global string $gPreferenceWindow;
if (`window -exists $gPreferenceWindow`) {
setParent mayaUsd_PrefLayout;
Expand Down