From 55d2b184ec1b2c1adfe182ead937cedae1a8208d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 12 Apr 2009 07:24:04 +0000 Subject: [PATCH] added "toggle" an option for the property actuator. much less hassle then setting up a property sensor and 2 assignment actuators, or through python. --- source/blender/makesdna/DNA_actuator_types.h | 1 + source/blender/src/buttons_logic.c | 9 +++++++-- .../GameLogic/SCA_PropertyActuator.cpp | 17 +++++++++++++++++ .../gameengine/GameLogic/SCA_PropertyActuator.h | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/source/blender/makesdna/DNA_actuator_types.h b/source/blender/makesdna/DNA_actuator_types.h index 48432b8c6e2..2252126b46c 100644 --- a/source/blender/makesdna/DNA_actuator_types.h +++ b/source/blender/makesdna/DNA_actuator_types.h @@ -357,6 +357,7 @@ typedef struct FreeCamera { #define ACT_PROP_ASSIGN 0 #define ACT_PROP_ADD 1 #define ACT_PROP_COPY 2 +#define ACT_PROP_TOGGLE 3 /* constraint flag */ #define ACT_CONST_LOCX 1 diff --git a/source/blender/src/buttons_logic.c b/source/blender/src/buttons_logic.c index 56879f80198..1f604aa8480 100644 --- a/source/blender/src/buttons_logic.c +++ b/source/blender/src/buttons_logic.c @@ -1970,12 +1970,17 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh pa= act->data; - str= "Type %t|Assign %x0|Add %x1|Copy %x2"; + str= "Type%t|Assign%x0|Add %x1|Copy %x2|Toggle%x3"; uiDefButI(block, MENU, B_REDR, str, xco+30,yco-24,width-60, 19, &pa->type, 0, 31, 0, 0, "Type"); uiDefBut(block, TEX, 1, "Prop: ", xco+30,yco-44,width-60, 19, pa->name, 0, 31, 0, 0, "Property name"); - if(pa->type==ACT_PROP_COPY) { + + if(pa->type==ACT_PROP_TOGGLE) { + /* no ui */ + ysize -= 22; + } + else if(pa->type==ACT_PROP_COPY) { uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:", xco+10, yco-64, (width-20)/2, 19, &(pa->ob), "Copy from this Object"); uiDefBut(block, TEX, 1, "Prop: ", xco+10+(width-20)/2, yco-64, (width-20)/2, 19, pa->value, 0, 31, 0, 0, "Copy this property"); } diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 444c616870d..37df8a5c401 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -135,6 +135,23 @@ bool SCA_PropertyActuator::Update() } break; } + case KX_ACT_PROP_TOGGLE: + { + + CValue* newval; + CValue* oldprop = propowner->GetProperty(m_propname); + if (oldprop) + { + newval = new CBoolValue((oldprop->GetNumber()==0.0) ? true:false); + oldprop->SetValue(newval); + } else + { /* as not been assigned, evaluate as false, so assign true */ + newval = new CBoolValue(true); + propowner->SetProperty(m_propname,newval); + } + newval->Release(); + break; + } default: { diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.h b/source/gameengine/GameLogic/SCA_PropertyActuator.h index 6a975716ed0..bb841cf88ad 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.h +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.h @@ -43,6 +43,7 @@ class SCA_PropertyActuator : public SCA_IActuator KX_ACT_PROP_ASSIGN, KX_ACT_PROP_ADD, KX_ACT_PROP_COPY, + KX_ACT_PROP_TOGGLE, KX_ACT_PROP_MAX };