/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ // Original file Copyright Crytek GMBH or its affiliates, used under license. global int $g_enableValidateHelpWindow = false; proc string cryValidateGetMessageList() { string $s; $s = `cryValidatePlugin messages getMessageList`; return $s; } global proc string[] cryValidateDecodeMessageString( string $message ) { string $decode[]; string $tokens[]; $numTokens = `tokenize $message "," $tokens`; if( $numTokens == 5 ) { $decode[0] = $tokens[0]; // Enable $decode[1] = $tokens[1]; // IsCritical $decode[2] = $tokens[2]; // MessageType $decode[3] = $tokens[3]; // FocusNode $decode[4] = $tokens[4]; // MessageText } return $decode; } proc int cryValidateAllowExport() { string $s; $s = `cryValidatePlugin messages messageSource`; if( $s == "EXPORT" ) return 1; return 0; } proc cryValidateShowIgnoreState() { // Disable the messages in the list string $s; $s = `cryValidateGetMessageList`; string $messages[]; $messageCount = `tokenize $s ";" $messages`; string $childControls[]; $childControls = `layout -q -childArray CRYVALIDATE_COLUMNLAYOUT`; layout -e -visible 0 CRYVALIDATE_COLUMNLAYOUT; int $allDisabled = 1; if( size($s) > 0 ) { int $childNum = 0; for( $message in $messages ) { string $decode[]; $decode = `cryValidateDecodeMessageString $message`; $child = $childControls[$childNum]; string $rowChildren[]; $rowChildren = `layout -q -childArray $child`; int $enable = $decode[0]; $enable = 1-$enable; int $isCritical = $decode[1]; float $colG = .85; if( $isCritical ) $colG = .65; $messageControl = $rowChildren[0]; if( $enable == 1 ) { control -e -enable true -bgc .95 $colG .65 $messageControl; $allDisabled = 0; } else { control -e -enable false -bgc .4 .4 .4 $messageControl; } $childNum++; } } // Disable the export button if all the errors haven't been ignored. if( $allDisabled ) { button -e -enable true CRYVALIDATE_EXPORT; } else { button -e -enable false CRYVALIDATE_EXPORT; } layout -e -visible 1 CRYVALIDATE_COLUMNLAYOUT; } global proc cryValidateCopyMessageText( string $messageText ) { cryMayaSupportPlugin copyToClipboard $messageText; } proc cryValidatePopulateMessageList() { global int $g_enableValidateHelpWindow; setParent CRYVALIDATE_COLUMNLAYOUT; string $childControls[]; $childControls = `layout -q -childArray CRYVALIDATE_COLUMNLAYOUT`; for( $child in $childControls ) { deleteUI $child; } string $s; $s = `cryValidateGetMessageList`; if( size($s) > 0 ) { string $messages[]; $messageCount = `tokenize $s ";" $messages`; int $messageNum = 0; for( $message in $messages ) { string $decode[]; $decode = `cryValidateDecodeMessageString $message`; string $messageType = $decode[2]; $rowName = `rowLayout -numberOfColumns 3 -columnWidth3 300 65 65 -adjustableColumn 1 -columnAlign 1 "left" -columnAlign 2 "center" -columnAlign 3 "center" -columnAttach 2 "both" 0 -columnAttach 3 "both" 0 -bgc .4 .4 .4`; { int $isCritical = $decode[1]; int $hasFocus = 1; if( size($decode[3]) == 0 || $decode[3] == "*" ) $hasFocus = 0; int $allowIgnoreAllType = 1; if( $isCritical ) $allowIgnoreAllType = 0; int $allowExport = `cryValidateAllowExport`; int $showIgnore = 1; if( $allowExport == 0 ) $showIgnore = 0; string $messageText = $decode[4]; $messageTextControl = `text -h 22 -label (" "+$messageText)`; $ignoreButton = `button -align "center" -label "Ignore" -enable (1-$isCritical) -command ( "cryValidateIgnoreMessage "+$messageNum )`; $focusButton = `button -align "center" -label "Focus" -enable $hasFocus -command ( "cryValidateFocus \""+$decode[3]+"\"" )`; if( $showIgnore == 0 ) { button -e -visible false $ignoreButton; rowLayout -e -columnWidth 2 1 $rowName; } popupMenu -parent $rowName -button 3 CRYVALIDATE_IDMENU; { menuItem -label "Copy message text" -command ( "cryValidateCopyMessageText \""+$messageText+"\"" ); menuItem -divider true; if( $showIgnore == 1 ) { menuItem -label "Ignore" -enable (1-$isCritical) -command ( "cryValidateIgnoreMessage "+$messageNum ); menuItem -label "Ignore all messages of this type" -enable $allowIgnoreAllType -command ( "cryValidateIgnoreMessageType "+$messageNum ); menuItem -divider true; } menuItem -label "Focus" -enable $hasFocus -command ( "cryValidateFocus \""+$decode[3]+"\"" ); menuItem -divider true; menuItem -label "Validate Message Settings" -command ("cryValidateMessageControl \""+$decode[2]+"\""); if ($g_enableValidateHelpWindow) { menuItem -label "Validate Help" -command ("cryValidateHelpWindow"); } if( `cryValidateFixCanFix $messageType` ) { menuItem -divider true; menuItem -label "Auto Fix Problem" -command("cryValidateFix " +$messageType+" \""+$decode[3]+"\""); } } } setParent ..; $messageNum++; } } else { text -label "No validate messages." -align "center" -bgc .4 .4 .4; } cryValidateShowIgnoreState; } global proc cryValidateIgnoreMessage( int $messageNum ) { cryValidatePlugin messages ignoreMessage $messageNum; cryValidateShowIgnoreState; } global proc cryValidateIgnoreMessageType( int $inMessageNum ) { string $s; $s = `cryValidateGetMessageList`; if( size($s) > 0 ) { string $messages[]; $messageCount = `tokenize $s ";" $messages`; string $inMessageType = ""; if( $inMessageNum < size($messages) ) { string $message = $messages[$inMessageNum]; string $decode[]; $decode = `cryValidateDecodeMessageString $message`; $inMessageType = $decode[2]; } int $messageNum = 0; for( $message in $messages ) { string $decode[]; $decode = `cryValidateDecodeMessageString $message`; string $messageType = $decode[2]; if( $messageType == $inMessageType ) { cryValidatePlugin messages ignoreMessage $messageNum; } $messageNum++; } } cryValidateShowIgnoreState; } global proc cryValidateFocus( string $focusNode ) { if( `startsWith $focusNode "loc"` ) { string $tokens[]; $numTokens = `tokenize $focusNode ":" $tokens`; if( $numTokens == 4 ) // Should be "loc x y z" { string $userUnit = `currentUnit -q -linear`; // It seems that some RC errors give values that are 100 times smaller then meters. TODO: work out whats going on with RC. float $x = (float)(`strip $tokens[1]`) * 100.0; float $y = (float)(`strip $tokens[2]`) * 100.0; float $z = (float)(`strip $tokens[3]`) * 100.0; // Convert to the current UI unit. $x = `convertUnit -fromUnit "meter" -toUnit $userUnit (""+$x)`; // Need to concat it to a string as convertUnit will only work with a string $y = `convertUnit -fromUnit "meter" -toUnit $userUnit (""+$y)`; $z = `convertUnit -fromUnit "meter" -toUnit $userUnit (""+$z)`; // Swap for y-up if needed if( `upAxis -q -axis` == "y" ) { $temp = $y; $y = $z; $z = -$temp; } string $focusLocatorName = "CRYFOCUSLOCATOR"; if( !`objExists $focusLocatorName` ) { spaceLocator -p 0 0 0 -absolute -n $focusLocatorName; xform -absolute -translation $x $y $z $focusLocatorName; } else { spaceLocator -e -p 0 0 0 -absolute $focusLocatorName; xform -absolute -translation $x $y $z $focusLocatorName; } select $focusLocatorName; fitPanel -selected; } } else if( $focusNode != "*" ) { eval("select -r "+$focusNode); } } global proc cryValidateCloseWindow() { if( `window -exists CRYVALIDATE_WINDOW` ) { deleteUI -window CRYVALIDATE_WINDOW; } } global proc cryValidateCloseAndReset() { cryValidateCloseWindow; cryValidatePlugin reset; // Remove all messages and un-mark any ignored ones. } global proc cryValidateExport() { // Tell the exporter to use the same options as the last time it was run. string $options = ""; $options += "cryExportType=postValidateReexport" + ";"; file -op $options -typ "MayaCryExport" -pr -ea "dummyExportName"; } global proc cryValidateRevalidate() { cryValidateCloseWindow; evalDeferred( "cryValidatePlugin recheck" ); } global proc cryValidateCreateControls( int $selected ) { global int $g_enableValidateHelpWindow; // Save the window prefs. We need to do this as the window will move to the location in the prefs when // the main form layout is deleted. windowPref -saveAll; if( `layout -exists CRYVALIDATE_FORMLAYOUT` ) return; formLayout -numberOfDivisions 100 -visible false CRYVALIDATE_FORMLAYOUT; { popupMenu -button 3 CRYVALIDATE_FORMIDMENU; { menuItem -label "Validate Message Settings" -command ("cryValidateMessageControl \"\""); if ($g_enableValidateHelpWindow) { menuItem -label "Validate Help" -command ("cryValidateHelpWindow"); } } scrollLayout -childResizable true -hst 0 -vst 15 -bgc .4 .4 .4 CRYVALIDATE_SCROLLLAYOUT; { columnLayout -adjustableColumn true -columnOffset "both" 5 -rowSpacing 5 -bgc .4 .4 .4 CRYVALIDATE_COLUMNLAYOUT; { } setParent ..; } setParent ..; button -label "Continue Export" -command ("cryValidateExport") CRYVALIDATE_EXPORT; button -label "Re-Validate" -command ("cryValidateRevalidate") CRYVALIDATE_REVALIDATE; button -label "Close" -command ("cryValidateCloseAndReset") CRYVALIDATE_CLOSE; } // Show or hide the export button int $enableExport = `cryValidateAllowExport`; int $firstAttach = 0; int $secondAttach = 0; if( $enableExport ) { button -e -visible true CRYVALIDATE_EXPORT; $firstAttach = 33; $secondAttach = 66; } else { button -e -visible false CRYVALIDATE_EXPORT; $firstAttach = 0; $secondAttach = 50; } formLayout -edit -attachForm CRYVALIDATE_SCROLLLAYOUT "top" 5 -attachForm CRYVALIDATE_SCROLLLAYOUT "left" 5 -attachForm CRYVALIDATE_SCROLLLAYOUT "right" 5 -attachControl CRYVALIDATE_SCROLLLAYOUT "bottom" 5 CRYVALIDATE_CLOSE -attachForm CRYVALIDATE_EXPORT "bottom" 5 -attachForm CRYVALIDATE_EXPORT "left" 5 -attachPosition CRYVALIDATE_EXPORT "right" 5 $firstAttach -attachNone CRYVALIDATE_EXPORT "top" -attachForm CRYVALIDATE_REVALIDATE "bottom" 5 -attachPosition CRYVALIDATE_REVALIDATE "left" 5 $firstAttach -attachPosition CRYVALIDATE_REVALIDATE "right" 5 $secondAttach -attachNone CRYVALIDATE_REVALIDATE "top" -attachForm CRYVALIDATE_CLOSE "bottom" 5 -attachPosition CRYVALIDATE_CLOSE "left" 5 $secondAttach -attachForm CRYVALIDATE_CLOSE "right" 5 -attachNone CRYVALIDATE_CLOSE "top" CRYVALIDATE_FORMLAYOUT; cryValidatePopulateMessageList; formLayout -e -visible true CRYVALIDATE_FORMLAYOUT; } proc cryValidateCreateWindow() { global int $g_enableValidateHelpWindow; // If the window exists but is not visible, close it - and reset the messages. if( `window -ex CRYVALIDATE_WINDOW` && !`window -q -vis CRYVALIDATE_WINDOW`) { cryValidateCloseAndReset; } if(!`window -ex CRYVALIDATE_WINDOW`) { if(`windowPref -exists CRYVALIDATE_WINDOW`) { windowPref -wh 800 400 -tlc `windowPref -q -topEdge CRYVALIDATE_WINDOW` `windowPref -q -leftEdge CRYVALIDATE_WINDOW` CRYVALIDATE_WINDOW; //windowPref -remove CRYVALIDATE_WINDOW; } window -titleBar true -title "Lumberyard Validate" -sizeable true -mnb false -mxb false CRYVALIDATE_WINDOW; cryValidateCreateControls 0; showWindow CRYVALIDATE_WINDOW; int $dontShow = `cryValidateHelpLoadDontShow`; if( !$dontShow && $g_enableValidateHelpWindow ) { cryValidateHelpWindow; } } else { cryValidatePopulateMessageList; } } proc cryValidateSourceDependencies() { //eval("source cryExport.mel"); // Removed from here as resourcing the script will it is running is causing heap corruption in OpenMaya.dll eval("source cryValidateFix.mel"); if( !`cryPluginIsLoaded` ) cryLoadPluginQuiet; } global proc cryValidate( ) { cryValidateSourceDependencies(); cryValidateCreateWindow(); } global proc cryValidateRunBasic( ) { cryValidateSourceDependencies(); cryValidatePlugin basic silentIfClean; } global proc cryValidateRunComplete( ) { cryValidateSourceDependencies(); cryValidatePlugin complete silentIfClean; } global proc string cryValidateIsMessageWindowVisible() { // Window has to be open and visible if( `window -ex CRYVALIDATE_WINDOW` && `window -q -vis CRYVALIDATE_WINDOW`) { return "1"; } return "0"; } // Progress window. global proc cryValidateProgressUpdate( string $text, float $amount ) { progressWindow -edit -progress $amount -status ("Validating:" + $amount+"%"+" : "+$text); } global proc cryValidateProgressCloseWindow() { progressWindow -endProgress; } global proc cryValidateProgress( ) { int $amount = 0; progressWindow -title "Validating" -progress $amount -status " Validating: 0% " -isInterruptable false; } ////////////////////////////////// // Help Window ////////////////////////////////// global proc cryValidateHelpSaveDontShow( int $value ) { optionVar -iv "cryValidateHelpDontShow" $value; } global proc int cryValidateHelpLoadDontShow( ) { int $value = 0; if(`optionVar -exists "cryValidateHelpDontShow"` ) { $value = `optionVar -q "cryValidateHelpDontShow"`; } return $value; } global proc cryValidateHelpCloseWindow() { if( `control -exists CRYVALIDATEHELP_DONTSHOW` ) { int $value = `checkBox -q -value CRYVALIDATEHELP_DONTSHOW`; cryValidateHelpSaveDontShow $value; } deleteUI -window CRYVALIDATEHELP_WINDOW; } global proc cryValidateMessageHelp( string $messageType ) { cryMayaSupportPlugin start "http://confluence/display/SNT/Maya+Validate+Message+Help#groupNodeHasNoChildren"; } global proc cryValidateHelpWindow( ) { if(!`window -ex CRYVALIDATEHELP_WINDOW`) { if(`windowPref -exists CRYVALIDATEHELP_WINDOW`) { windowPref -remove CRYVALIDATEHELP_WINDOW; } window -widthHeight 750 450 -titleBar true -title "Lumberyard Validate Help" -sizeable true -mnb false -mxb false CRYVALIDATEHELP_WINDOW; formLayout -numberOfDivisions 100 -visible false CRYVALIDATEHELP_FORMLAYOUT; { string $helpText = "Export Validation.\n\n"; $helpText += "The validation runs before the exporter. If the validation produces any messages the export will be stopped and no files are written. You can also run the validation from the Crytek shelf.\n\n"; $helpText += "There are two types of messages produced by the validation, critical and ignorable. If there are any critical messages you can't export until they are fixed. Ignorable messages can be ignored but will come back the next time the validation is run. They really should be fixed as well as it will be annoying to have to ignore them every time for every export.\n\n"; $helpText += "\nIgnoring Messages.\n\n"; $helpText += "If the scene has ignorable messages, the validate window will pop up when the `Export` button is clicked. If you ignore the messages you can conplete the export by clicking the `Continue Export` at the bottom of the validate window. \nSo the process is:\n - Click `Export`.\n - 'Ignore' messages.\n - Click `Continue Export`.\n - Wait for the export to finish.\n - Close validate window.\nIf there are no messages to display the validate window is not shown and the export happens with the first click of the `Export` button.\n\n"; $helpText += "\nFocus Button.\n\n"; $helpText += "There is also a `Focus` button. This will select the node or component that caused the message and make it easier the find the problem. The focus button will be grayed out if there is nothing to focus on.\n\n"; scrollField -editable false -wordWrap true -text $helpText CRYVALIDATEHELP_HELPTEXT; checkBox -label "Don't show this dialog again." CRYVALIDATEHELP_DONTSHOW; button -label "Close" -command ("cryValidateHelpCloseWindow;") CRYVALIDATEHELP_CLOSE; } setParent ..; formLayout -edit -attachForm CRYVALIDATEHELP_HELPTEXT "top" 5 -attachForm CRYVALIDATEHELP_HELPTEXT "left" 5 -attachForm CRYVALIDATEHELP_HELPTEXT "right" 5 -attachControl CRYVALIDATEHELP_HELPTEXT "bottom" 5 CRYVALIDATEHELP_DONTSHOW -attachNone CRYVALIDATEHELP_DONTSHOW "top" -attachForm CRYVALIDATEHELP_DONTSHOW "left" 5 -attachForm CRYVALIDATEHELP_DONTSHOW "right" 5 -attachControl CRYVALIDATEHELP_DONTSHOW "bottom" 5 CRYVALIDATEHELP_CLOSE -attachNone CRYVALIDATEHELP_CLOSE "top" -attachForm CRYVALIDATEHELP_CLOSE "left" 5 -attachForm CRYVALIDATEHELP_CLOSE "right" 5 -attachForm CRYVALIDATEHELP_CLOSE "bottom" 5 CRYVALIDATEHELP_FORMLAYOUT; int $dontShow = `cryValidateHelpLoadDontShow`; checkBox -edit -value $dontShow CRYVALIDATEHELP_DONTSHOW; showWindow CRYVALIDATEHELP_WINDOW; } } ////////////////////////////////// // This function is only here to use as a debug tool. // There is no way to get to this function though the UI. ////////////////////////////////// global proc cryValidateDebugIgnoreAll( ) { string $s; $s = `cryValidateGetMessageList`; if( size($s) > 0 ) { string $messages[]; $messageCount = `tokenize $s ";" $messages`; for( $i = 0;$i<$messageCount;$i ++ ) { cryValidatePlugin messages ignoreMessage $i; } } cryValidateShowIgnoreState; }