BGE: Add level mode to property actuator

This patch adds to the existing property actuator a level mode, which is switching the property depending on the input level.

Reviewers: moguri

Reviewed By: moguri

Differential Revision: https://developer.blender.org/D652
This commit is contained in:
HG1 2014-07-17 22:27:58 -07:00 committed by Mitchell Stokes
parent a04a8039f0
commit 12a0cccfbf
5 changed files with 31 additions and 3 deletions

@ -1939,6 +1939,7 @@ static void draw_actuator_property(uiLayout *layout, PointerRNA *ptr)
switch (RNA_enum_get(ptr, "mode")) {
case ACT_PROP_TOGGLE:
case ACT_PROP_LEVEL:
break;
case ACT_PROP_ADD:
uiItemR(layout, ptr, "value", 0, NULL, ICON_NONE);

@ -397,6 +397,7 @@ typedef struct bActuator {
#define ACT_PROP_ADD 1
#define ACT_PROP_COPY 2
#define ACT_PROP_TOGGLE 3
#define ACT_PROP_LEVEL 4
/* constraint flag */
#define ACT_CONST_NONE 0

@ -1090,6 +1090,7 @@ static void rna_def_property_actuator(BlenderRNA *brna)
{ACT_PROP_ADD, "ADD", 0, "Add", ""},
{ACT_PROP_COPY, "COPY", 0, "Copy", ""},
{ACT_PROP_TOGGLE, "TOGGLE", 0, "Toggle", "For bool/int/float/timer properties only"},
{ACT_PROP_LEVEL, "LEVEL", 0, "Level", "For bool/int/float/timer properties only"},
{0, NULL, 0, NULL, NULL}
};

@ -69,13 +69,24 @@ bool SCA_PropertyActuator::Update()
bool bNegativeEvent = IsNegativeEvent();
RemoveAllEvents();
CValue* propowner = GetParent();
if (bNegativeEvent)
return false; // do nothing on negative events
{
if (m_type==KX_ACT_PROP_LEVEL)
{
CValue* newval = new CBoolValue(false);
CValue* oldprop = propowner->GetProperty(m_propname);
if (oldprop)
{
oldprop->SetValue(newval);
}
newval->Release();
}
return false;
}
CValue* propowner = GetParent();
CParser parser;
parser.SetContext( propowner->AddRef());
@ -97,6 +108,19 @@ bool SCA_PropertyActuator::Update()
}
newval->Release();
}
else if (m_type==KX_ACT_PROP_LEVEL)
{
CValue* newval = new CBoolValue(true);
CValue* oldprop = propowner->GetProperty(m_propname);
if (oldprop)
{
oldprop->SetValue(newval);
} else
{
propowner->SetProperty(m_propname,newval);
}
newval->Release();
}
else if ((userexpr = parser.ProcessText(m_exprtxt))) {
switch (m_type)
{

@ -44,6 +44,7 @@ class SCA_PropertyActuator : public SCA_IActuator
KX_ACT_PROP_ADD,
KX_ACT_PROP_COPY,
KX_ACT_PROP_TOGGLE,
KX_ACT_PROP_LEVEL,
KX_ACT_PROP_MAX
};