-
Notifications
You must be signed in to change notification settings - Fork 201
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
[al] Add support for default rgba values and color threshold for exporting #2250
Changes from 4 commits
8830860
48a55ee
5521e43
c86b9b1
7801aee
536565b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,10 +142,26 @@ bool PluginTranslatorOptions::addInt(const char* optionName, int defaultValue) | |
//---------------------------------------------------------------------------------------------------------------------- | ||
AL_MAYA_UTILS_PUBLIC | ||
bool PluginTranslatorOptions::addFloat(const char* optionName, float defaultValue) | ||
{ | ||
return addFloat(optionName, defaultValue, 1, "", true); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- | ||
bool PluginTranslatorOptions::addFloat(const char* optionName, float value, int precision) | ||
{ | ||
return addFloat(optionName, value, precision, "", true); | ||
} | ||
|
||
bool PluginTranslatorOptions::addFloat( | ||
const char* optionName, | ||
float value, | ||
int precision, | ||
const char* controller, | ||
bool state) | ||
{ | ||
if (isOption(optionName)) | ||
return false; | ||
m_options.emplace_back(optionName, defaultValue); | ||
m_options.emplace_back(optionName, value, precision, controller, state); | ||
return true; | ||
} | ||
|
||
|
@@ -544,21 +560,54 @@ void PluginTranslatorOptions::generateIntGlobals( | |
|
||
//---------------------------------------------------------------------------------------------------------------------- | ||
void PluginTranslatorOptions::generateFloatGlobals( | ||
const char* const prefix, | ||
const MString& niceName, | ||
const MString& optionName, | ||
MString& code, | ||
float value) | ||
const char* const prefix, | ||
const MString& niceName, | ||
const MString& optionName, | ||
MString& code, | ||
float value, | ||
int precision, | ||
const std::string& controller, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be nicer to pass as MString, other parameters are passed using that type (except prefix for some reason). It gets converted to a MString in the function anwyay. Other wise the parameters would now take all three of: const char*, MString and std::string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
bool enableState) | ||
{ | ||
MString valueStr; | ||
valueStr = value; | ||
MString controlName = MString(prefix) + "_" + makeName(optionName); | ||
// Check and add on/off command if any | ||
MString onOffCmd; | ||
MString postUpdateCmd; | ||
MString deferredPostUpdateCmd; | ||
if (!controller.empty()) { | ||
MString prefixedCtrl(MString(prefix) + "_" + makeName(controller.c_str())); | ||
if (enableState) { | ||
onOffCmd = "checkBox -e " | ||
"-onCommand \"floatFieldGrp -e -en 1 " | ||
+ controlName | ||
+ "\" " | ||
"-offCommand \"floatFieldGrp -e -en 0 " | ||
+ controlName + "\" " + prefixedCtrl + "; "; | ||
// And update the default state according to the checkbox | ||
postUpdateCmd = "floatFieldGrp -e -en `checkBox -q -v " + prefixedCtrl + "` " | ||
+ controlName + "; "; | ||
} else { | ||
onOffCmd = "checkBox -e " | ||
"-onCommand \"floatFieldGrp -e -en 0 " | ||
+ controlName | ||
+ "\" " | ||
"-offCommand \"floatFieldGrp -e -en 1 " | ||
+ controlName + "\" " + prefixedCtrl + "; "; | ||
postUpdateCmd = "floatFieldGrp -e -en (`checkBox -q -v " + prefixedCtrl + "` ? 0: 1) " | ||
+ controlName + "; "; | ||
} | ||
onOffCmd += postUpdateCmd; | ||
deferredPostUpdateCmd = MString() + "eval(\"" + postUpdateCmd + "\");"; | ||
} | ||
|
||
MString createCommand = MString("global proc create_") + controlName + "() {" | ||
+ MString("floatFieldGrp -l \"") + niceName + "\" -v1 " + valueStr + " " + controlName | ||
+ ";}\n"; | ||
+ MString("floatFieldGrp -l \"") + niceName + "\" -v1 " + valueStr + " -pre " + precision | ||
+ " " + controlName + ";" + onOffCmd + "}\n"; | ||
MString postCommand = MString("global proc post_") + controlName | ||
+ "(string $value){ eval (\"floatFieldGrp -e -v1 \" + $value + \" " + controlName | ||
+ "\");}\n"; | ||
+ "(string $value){ eval (\"floatFieldGrp -e -v1 \" + $value + \" " + controlName + "\");" | ||
+ deferredPostUpdateCmd + "}\n"; | ||
MString buildCommand = MString("global proc string build_") + controlName | ||
+ "(){ string $str = \"" + makeName(optionName) + "=\" + `floatFieldGrp -q -v1 " | ||
+ controlName + "` + \";\"; return $str;}\n"; | ||
|
@@ -644,7 +693,15 @@ MString PluginTranslatorOptions::generateGUI(const char* const prefix, MString& | |
generateIntGlobals(prefix, opt->name, opt->name, guiCode, opt->defInt); | ||
break; | ||
case OptionType::kFloat: | ||
generateFloatGlobals(prefix, opt->name, opt->name, guiCode, opt->defFloat); | ||
generateFloatGlobals( | ||
prefix, | ||
opt->name, | ||
opt->name, | ||
guiCode, | ||
opt->defFloat, | ||
opt->precision, | ||
opt->controller, | ||
opt->enableState); | ||
break; | ||
case OptionType::kString: | ||
generateStringGlobals(prefix, opt->name, opt->name, guiCode, opt->defString.asChar()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,6 +309,29 @@ class PluginTranslatorOptions | |
AL_MAYA_UTILS_PUBLIC | ||
bool addFloat(const char* optionName, float defaultValue = 0.0f); | ||
|
||
/// \brief Add a float value with precision to the translator options | ||
/// \param optionName the name of the option | ||
/// \param value the default value for the option | ||
/// \param precision the default precision for the option | ||
/// \return true if the option was successfully added. False if the option is a duplicate | ||
AL_MAYA_UTILS_PUBLIC | ||
bool addFloat(const char* optionName, float value, int precision); | ||
|
||
/// \brief Add a float value with precision and controller state to the translator options | ||
/// \param optionName the name of the option | ||
/// \param value the default value for the option | ||
/// \param precision the default precision for the option | ||
/// \param controller the controller UI name that triggers enabling | ||
/// \param state the state for enabling this field | ||
/// \return true if the option was successfully added. False if the option is a duplicate | ||
AL_MAYA_UTILS_PUBLIC | ||
bool addFloat( | ||
const char* optionName, | ||
float value, | ||
int precision, | ||
const char* controller, | ||
bool state); | ||
|
||
/// \brief Add a string value to the translator options | ||
/// \param optionName the name of the option | ||
/// \param defaultValue the default value for the option | ||
|
@@ -387,6 +410,9 @@ class PluginTranslatorOptions | |
MString defString; ///< default string value | ||
std::vector<MString> enumStrings; ///< the text values for the enums | ||
OptionType type; ///< the type of the option | ||
int precision { 1 }; | ||
std::string controller {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: I'd use a MString instead of std::string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
bool enableState { true }; | ||
|
||
/// \brief ctor | ||
/// \param name the name of the option | ||
|
@@ -411,9 +437,17 @@ class PluginTranslatorOptions | |
/// \brief ctor | ||
/// \param name the name of the option | ||
/// \param defVal the default value | ||
Option(const char* const name, const float& defVal) | ||
Option( | ||
const char* const name, | ||
const float& defVal, | ||
int defPre, | ||
const char* defController, | ||
bool defState) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, I'd rename defState to enableState. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
: name(name) | ||
, type(OptionType::kFloat) | ||
, precision(defPre) | ||
, controller(defController ? defController : "") | ||
, enableState(defState) | ||
{ | ||
defFloat = defVal; | ||
} | ||
|
@@ -480,7 +514,10 @@ class PluginTranslatorOptions | |
const MString& niceName, | ||
const MString& optionName, | ||
MString& code, | ||
float); | ||
float, | ||
int, | ||
const std::string&, | ||
bool); | ||
static void generateStringGlobals( | ||
const char* const prefix, | ||
const MString& niceName, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below, in generateFloatGlobals, you receive this as enableState, which I think is a better name that "state". It makes the purpose of the parameter clearer. I would change it here to be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.