Added support for numerical property suffixes

This commit is contained in:
parax0 2016-02-08 03:35:28 -07:00
parent c14e48bea5
commit 55b2c053ab
8 changed files with 45 additions and 8 deletions

View File

@ -469,6 +469,19 @@ void CTemplateWriter::SaveProperties(XMLDocument *pDoc, XMLElement *pParent, CSt
pElem->LinkEndChild(pRange);
}
// Suffix
if (pProp->IsNumerical())
{
TString Suffix = pProp->Suffix();
if (!Suffix.IsEmpty())
{
XMLElement *pSuffix = pDoc->NewElement("suffix");
pSuffix->SetText(*Suffix);
pElem->LinkEndChild(pSuffix);
}
}
// Cook Pref
ECookPreference CookPref = pProp->CookPreference();

View File

@ -58,9 +58,10 @@ public:
virtual bool CanHaveDefault() const = 0;
virtual bool IsNumerical() const = 0;
virtual bool HasValidRange() const { return false; }
virtual TString DefaultToString() { return ""; }
virtual TString RangeToString() { return ""; }
virtual bool HasValidRange() const { return false; }
virtual TString DefaultToString() const { return ""; }
virtual TString RangeToString() const { return ""; }
virtual TString Suffix() const { return ""; }
virtual void SetParam(const TString& rkParamName, const TString& rkValue)
{
@ -144,7 +145,7 @@ public:
virtual bool CanHaveDefault() const { return true; }
virtual bool IsNumerical() const { return false; }
virtual TString DefaultToString()
virtual TString DefaultToString() const
{
return mDefaultValue.ToString();
}
@ -178,7 +179,7 @@ public:
};
// TNumericalPropertyTemplate - Subclass of TTypedPropertyTemplate for numerical
// property types, and allows a min/max value to be tracked.
// property types, and allows a min/max value and a suffix to be tracked.
template<typename PropType, EPropertyType PropTypeEnum, class ValueClass>
class TNumericalPropertyTemplate : public TTypedPropertyTemplate<PropType,PropTypeEnum,ValueClass>
{
@ -187,6 +188,7 @@ class TNumericalPropertyTemplate : public TTypedPropertyTemplate<PropType,PropTy
ValueClass mMin;
ValueClass mMax;
TString mSuffix;
public:
TNumericalPropertyTemplate(u32 ID, CStructTemplate *pParent = 0)
@ -225,14 +227,24 @@ public:
mMax.FromString(Components.back());
}
}
else if (rkParamName == "suffix")
{
mSuffix = rkValue;
}
}
inline PropType GetMin()
virtual TString Suffix() const
{
return mSuffix;
}
inline PropType GetMin() const
{
return mMin.Get();
}
inline PropType GetMax()
inline PropType GetMax() const
{
return mMax.Get();
}
@ -242,6 +254,11 @@ public:
mMin.Set(rkMin);
mMax.Set(rkMax);
}
inline void SetSuffix(const TString& rkSuffix)
{
mSuffix = rkSuffix;
}
};
// Typedefs for all property types that don't need further functionality.

View File

@ -67,6 +67,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget *pParent, const QStyleOptionVie
WIntegralSpinBox *pSpinBox = new WIntegralSpinBox(pParent);
pSpinBox->setMinimum(INT16_MIN);
pSpinBox->setMaximum(INT16_MAX);
pSpinBox->setSuffix(TO_QSTRING(pProp->Template()->Suffix()));
CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int));
pOut = pSpinBox;
break;
@ -77,6 +78,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget *pParent, const QStyleOptionVie
WIntegralSpinBox *pSpinBox = new WIntegralSpinBox(pParent);
pSpinBox->setMinimum(INT32_MIN);
pSpinBox->setMaximum(INT32_MAX);
pSpinBox->setSuffix(TO_QSTRING(pProp->Template()->Suffix()));
CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int));
pOut = pSpinBox;
break;
@ -86,6 +88,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget *pParent, const QStyleOptionVie
{
WDraggableSpinBox *pSpinBox = new WDraggableSpinBox(pParent);
pSpinBox->setSingleStep(0.1);
pSpinBox->setSuffix(TO_QSTRING(pProp->Template()->Suffix()));
CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(double));
pOut = pSpinBox;
break;

View File

@ -316,7 +316,7 @@ QVariant CPropertyModel::data(const QModelIndex& rkIndex, int Role) const
// fall through
// Display property value to string for everything else
default:
return TO_QSTRING(pProp->ToString());
return TO_QSTRING(pProp->ToString() + pProp->Template()->Suffix());
}
}
}

View File

@ -3,6 +3,7 @@
<properties>
<property ID="0x852D3871" type="float">
<default>100.0</default>
<suffix>%</suffix>
</property>
<property ID="0x68ACBD86" type="long">
<default>0</default>

View File

@ -3,6 +3,7 @@
<properties>
<property ID="0x852D3871" type="float">
<default>100.0</default>
<suffix>%</suffix>
</property>
<property ID="0x68ACBD86" type="long">
<default>0</default>

View File

@ -3,6 +3,7 @@
<properties>
<property ID="0x852D3871" type="float">
<default>100.0</default>
<suffix>%</suffix>
</property>
<property ID="0x68ACBD86" type="long">
<default>0</default>

View File

@ -3,6 +3,7 @@
<properties>
<property ID="0x852D3871" type="float">
<default>100.0</default>
<suffix>%</suffix>
</property>
<property ID="0x68ACBD86" type="long">
<default>0</default>