1111#include " Common/Processor/ProcessorIncludes.h"
1212
1313ChataigneTimeTrigger::ChataigneTimeTrigger (StringRef name) :
14+ alreadyTriggered(false ),
1415 TimeTrigger(name)
1516{
16- csm.reset (new ConsequenceManager ());
17+ triggerCondition = addEnumParameter (" Evaluate conditions" , " Where to check the condition, and wether the consequences can be triggered again more than one time" );
18+ triggerCondition->addOption (" Only once" , onlyOnce);
19+ triggerCondition->addOption (" Only on enter and exit" , onlyEnterExit);
20+ triggerCondition->addOption (" Always" , always);
21+
22+ onValidExit = addEnumParameter (" On exit (active)" , " Action when exiting the Trigger if the trigger is active" );
23+ onValidExit->addOption (" Deactivate - Trigger FALSE" , action_triggerFalse);
24+ onValidExit->addOption (" Nothing" , action_nothing);
25+ onValidExit->addOption (" Deactivate - No Trigger" , action_deactivate);
26+
27+ onInvalidExit = addEnumParameter (" On exit (inactive)" , " Action when exiting the Trigger if the trigger is inactive or the condition is false" );
28+ onInvalidExit->addOption (" Nothing" , action_nothing);
29+ onInvalidExit->addOption (" Deactivate - No Trigger" , action_deactivate);
30+ onInvalidExit->addOption (" Deactivate - Trigger TRUE" , action_triggerTrue);
31+ onInvalidExit->addOption (" Deactivate - Trigger FALSE" , action_triggerFalse);
32+ onInvalidExit->addOption (" Deactivate - Trigger both" , action_triggerBoth);
33+
34+ onRewind = addEnumParameter (" On rewind" , " Action when jumping back in the sequence before the trigger" );
35+ onRewind->addOption (" Deactivate - Trigger FALSE" , action_triggerFalse);
36+ onRewind->addOption (" Deactivate - No Trigger" , action_deactivate);
37+
38+ cdm.reset (new ConditionManager (nullptr ));
39+ addChildControllableContainer (cdm.get ());
40+ cdm->addConditionManagerListener (this );
41+
42+ csm.reset (new ConsequenceManager (" Consequences : TRUE" ));
43+ untcsm.reset (new ConsequenceManager (" Consequences : FALSE" ));
1744 addChildControllableContainer (csm.get ());
45+ addChildControllableContainer (untcsm.get ());
46+
47+ triggerAtAnyTime = true ;
48+
49+ updateTriggerParams ();
1850}
1951
2052ChataigneTimeTrigger::~ChataigneTimeTrigger ()
2153{
2254}
2355
56+ void ChataigneTimeTrigger::updateTriggerParams ()
57+ {
58+ bool longTrigger = length->floatValue () > 0 .f ;
59+ triggerCondition->hideInEditor = !longTrigger;
60+ onValidExit->hideInEditor = !longTrigger;
61+ onInvalidExit->hideInEditor = !longTrigger;
62+
63+ if (longTrigger)
64+ {
65+ triggerAtAnyTime = triggerCondition->getValueDataAsEnum <evaluateSetting>() != onlyEnterExit;
66+ bool ct = cdm->getIsValid (0 , true ) && (triggerCondition->getValueDataAsEnum <evaluateSetting>() != onlyOnce || !alreadyTriggered);
67+ canTrigger->setValue (ct);
68+ }
69+ else
70+ {
71+ triggerAtAnyTime = false ;
72+ alreadyTriggered = false ;
73+ canTrigger->setValue (cdm->getIsValid (0 , true ));
74+ }
75+ }
76+
2477void ChataigneTimeTrigger::onContainerParameterChangedInternal (Parameter* p)
2578{
2679 TimeTrigger::onContainerParameterChangedInternal (p);
2780
2881 if (p == enabled)
2982 {
3083 csm->setForceDisabled (!enabled->boolValue ());
84+ untcsm->setForceDisabled (!enabled->boolValue ());
85+ }
86+ else if (p == triggerCondition || p == length)
87+ {
88+ updateTriggerParams ();
89+ }
90+ }
91+
92+ void ChataigneTimeTrigger::conditionManagerValidationChanged (ConditionManager*, int multiplexIndex, bool dispatchOnChangeOnly)
93+ {
94+ updateTriggerParams ();
95+
96+ if (collisionState && triggerAtAnyTime && !cdm->getIsValid (0 , true ))
97+ {
98+ unTrigger ();
3199 }
32100}
33101
@@ -36,15 +104,80 @@ void ChataigneTimeTrigger::triggerInternal()
36104 csm->triggerAll ();
37105}
38106
107+ void ChataigneTimeTrigger::unTriggerInternal ()
108+ {
109+ untcsm->triggerAll ();
110+ alreadyTriggered = true ;
111+ updateTriggerParams ();
112+ }
113+
114+ void ChataigneTimeTrigger::exitedInternal (bool rewind)
115+ {
116+ bool exitCondition = triggerAtAnyTime ? isTriggered->boolValue () : cdm->getIsValid (0 , true );
117+
118+ if (rewind)
119+ {
120+ switch (onRewind->getValueDataAsEnum <possibleActions>())
121+ {
122+ case action_deactivate:
123+ isTriggered->setValue (false );
124+ break ;
125+
126+ case action_triggerFalse:
127+ unTrigger ();
128+ break ;
129+
130+ default :
131+ break ;
132+ }
133+ }
134+ else if (exitCondition)
135+ {
136+ switch (onValidExit->getValueDataAsEnum <possibleActions>())
137+ {
138+ case action_deactivate:
139+ isTriggered->setValue (false );
140+ break ;
141+
142+ case action_triggerFalse:
143+ unTrigger ();
144+ break ;
145+
146+ default :
147+ break ;
148+ }
149+ }
150+ else
151+ {
152+ enum possibleActions param = onInvalidExit->getValueDataAsEnum <possibleActions>();
153+ if (param == action_triggerTrue || param == action_triggerBoth)
154+ {
155+ csm->triggerAll ();
156+ }
157+
158+ if (param == action_triggerFalse || param == action_triggerBoth)
159+ {
160+ untcsm->triggerAll ();
161+ }
162+ }
163+
164+ alreadyTriggered = false ;
165+ updateTriggerParams ();
166+ }
167+
39168var ChataigneTimeTrigger::getJSONData (bool includeNonOverriden)
40169{
41170 var data = TimeTrigger::getJSONData (includeNonOverriden);
42171 data.getDynamicObject ()->setProperty (" consequences" , csm->getJSONData ());
172+ data.getDynamicObject ()->setProperty (" untriggerConsequences" , untcsm->getJSONData ());
173+ data.getDynamicObject ()->setProperty (" conditions" , cdm->getJSONData ());
43174 return data;
44175}
45176
46177void ChataigneTimeTrigger::loadJSONDataInternal (var data)
47178{
48179 TimeTrigger::loadJSONDataInternal (data);
49180 csm->loadJSONData (data.getProperty (" consequences" , var ()));
181+ untcsm->loadJSONData (data.getProperty (" untriggerConsequences" , var ()));
182+ cdm->loadJSONData (data.getProperty (" conditions" , var ()));
50183}
0 commit comments