4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * Contributor(s): Blender Foundation (2008).
22 * ***** END GPL LICENSE BLOCK *****
27 #include "RNA_define.h"
28 #include "RNA_enum_types.h"
30 #include "rna_internal.h"
32 #include "DNA_constraint_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_sensor_types.h"
38 /* Always keep in alphabetical order */
39 EnumPropertyItem sensor_type_items[] ={
40 {SENS_ACTUATOR, "ACTUATOR", 0, "Actuator", ""},
41 {SENS_ALWAYS, "ALWAYS", 0, "Always", ""},
42 {SENS_ARMATURE, "ARMATURE", 0, "Armature", ""},
43 {SENS_COLLISION, "COLLISION", 0, "Collision", ""},
44 {SENS_DELAY, "DELAY", 0, "Delay", ""},
45 {SENS_JOYSTICK, "JOYSTICK", 0, "Joystick", ""},
46 {SENS_KEYBOARD, "KEYBOARD", 0, "Keyboard", ""},
47 {SENS_MESSAGE, "MESSAGE", 0, "Message", ""},
48 {SENS_MOUSE, "MOUSE", 0, "Mouse", ""},
49 {SENS_NEAR, "NEAR", 0, "Near", ""},
50 {SENS_PROPERTY, "PROPERTY", 0, "Property", ""},
51 {SENS_RADAR, "RADAR", 0, "Radar", ""},
52 {SENS_RANDOM, "RANDOM", 0, "Random", ""},
53 {SENS_RAY, "RAY", 0, "Ray", ""},
54 {SENS_TOUCH, "TOUCH", 0, "Touch", ""},
55 {0, NULL, 0, NULL, NULL}};
61 static StructRNA* rna_Sensor_refine(struct PointerRNA *ptr)
63 bSensor *sensor= (bSensor*)ptr->data;
65 switch(sensor->type) {
67 return &RNA_AlwaysSensor;
69 return &RNA_TouchSensor;
71 return &RNA_NearSensor;
73 return &RNA_KeyboardSensor;
75 return &RNA_PropertySensor;
77 return &RNA_ArmatureSensor;
79 return &RNA_MouseSensor;
81 return &RNA_CollisionSensor;
83 return &RNA_RadarSensor;
85 return &RNA_RandomSensor;
87 return &RNA_RaySensor;
89 return &RNA_MessageSensor;
91 return &RNA_JoystickSensor;
93 return &RNA_ActuatorSensor;
95 return &RNA_DelaySensor;
101 static void rna_Sensor_type_set(struct PointerRNA *ptr, int value)
103 bSensor *sens= (bSensor *)ptr->data;
104 if (value != sens->type)
111 /* Always keep in alphabetical order */
112 EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, int *free)
114 EnumPropertyItem *item= NULL;
118 if (ptr->type == &RNA_Sensor) {
119 ob = (Object *)ptr->id.data;
121 /* can't use ob from ptr->id.data because that enum is also used by operators */
122 ob = CTX_data_active_object(C);
125 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ACTUATOR);
126 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ALWAYS);
129 if (ob->type==OB_ARMATURE) {
130 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ARMATURE);
131 } else if(ob->type==OB_MESH) {
132 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_COLLISION);
136 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_DELAY);
137 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_JOYSTICK);
138 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_KEYBOARD);
139 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MESSAGE);
140 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MOUSE);
141 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_NEAR);
142 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_PROPERTY);
143 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RADAR);
144 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RANDOM);
145 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RAY);
148 if(ob->type==OB_MESH) {
149 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_TOUCH);
153 RNA_enum_item_end(&item, &totitem);
159 static void rna_Sensor_keyboard_key_set(struct PointerRNA *ptr, int value)
161 bSensor *sens= (bSensor *)ptr->data;
162 bKeyboardSensor *ks = sens->data;
164 if (ISKEYBOARD(value) && !ISKEYMODIFIER(value))
168 static void rna_Sensor_keyboard_modifier_set(struct PointerRNA *ptr, int value)
170 bSensor *sens= (bSensor *)ptr->data;
171 bKeyboardSensor *ks = sens->data;
173 if (ISKEYMODIFIER(value))
177 static void rna_Sensor_keyboard_modifier2_set(struct PointerRNA *ptr, int value)
179 bSensor *sens= (bSensor *)ptr->data;
180 bKeyboardSensor *ks = sens->data;
182 if (ISKEYMODIFIER(value))
186 static void rna_Sensor_tap_set(struct PointerRNA *ptr, int value)
188 bSensor *sens= (bSensor*)ptr->data;
195 static void rna_Sensor_level_set(struct PointerRNA *ptr, int value)
197 bSensor *sens= (bSensor*)ptr->data;
204 static void rna_Sensor_Armature_update(Main *bmain, Scene *scene, PointerRNA *ptr)
206 bSensor *sens= (bSensor *)ptr->data;
207 bArmatureSensor *as = sens->data;
208 Object *ob = (Object *)ptr->id.data;
210 char *posechannel= as->posechannel;
211 char *constraint= as->constraint;
213 /* check that bone exist in the active object */
214 if (ob->type == OB_ARMATURE && ob->pose) {
216 bPose *pose = ob->pose;
217 for (pchan=pose->chanbase.first; pchan; pchan=pchan->next) {
218 if (!strcmp(pchan->name, posechannel)) {
219 /* found it, now look for constraint channel */
221 for (con=pchan->constraints.first; con; con=con->next) {
222 if (!strcmp(con->name, constraint)) {
223 /* found it, all ok */
227 /* didn't find constraint, make empty */
233 /* didn't find any */
240 static void rna_def_sensor(BlenderRNA *brna)
245 srna= RNA_def_struct(brna, "Sensor", NULL);
246 RNA_def_struct_ui_text(srna, "Sensor", "Game engine logic brick to detect events");
247 RNA_def_struct_sdna(srna, "bSensor");
248 RNA_def_struct_refine_func(srna, "rna_Sensor_refine");
250 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
251 RNA_def_property_ui_text(prop, "Name", "Sensor name");
252 RNA_def_struct_name_property(srna, prop);
253 RNA_def_property_update(prop, NC_LOGIC, NULL);
255 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
256 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
257 RNA_def_property_enum_items(prop, sensor_type_items);
258 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_type_set", "rna_Sensor_type_itemf");
259 RNA_def_property_ui_text(prop, "Type", "");
260 RNA_def_property_update(prop, NC_LOGIC, NULL);
262 prop= RNA_def_property(srna, "expanded", PROP_BOOLEAN, PROP_NONE);
263 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_SHOW);
264 RNA_def_property_ui_text(prop, "Expanded", "Set sensor expanded in the user interface");
265 RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
266 RNA_def_property_update(prop, NC_LOGIC, NULL);
268 prop= RNA_def_property(srna, "invert", PROP_BOOLEAN, PROP_NONE);
269 RNA_def_property_ui_text(prop, "Invert Output", "Invert the level(output) of this sensor");
270 RNA_def_property_update(prop, NC_LOGIC, NULL);
272 prop= RNA_def_property(srna, "level", PROP_BOOLEAN, PROP_NONE);
273 RNA_def_property_ui_text(prop, "Level", "Level detector, trigger controllers of new states(only applicable upon logic state transition)");
274 RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_level_set");
275 RNA_def_property_update(prop, NC_LOGIC, NULL);
277 prop= RNA_def_property(srna, "pulse_true_level", PROP_BOOLEAN, PROP_NONE);
278 RNA_def_property_boolean_sdna(prop, NULL, "pulse", SENS_PULSE_REPEAT);
279 RNA_def_property_ui_text(prop, "Pulse True Level", "Activate TRUE level triggering (pulse mode)");
280 RNA_def_property_update(prop, NC_LOGIC, NULL);
282 prop= RNA_def_property(srna, "pulse_false_level", PROP_BOOLEAN, PROP_NONE);
283 RNA_def_property_boolean_sdna(prop, NULL, "pulse", SENS_NEG_PULSE_MODE);
284 RNA_def_property_ui_text(prop, "Pulse False Level", "Activate FALSE level triggering (pulse mode)");
285 RNA_def_property_update(prop, NC_LOGIC, NULL);
287 prop= RNA_def_property(srna, "frequency", PROP_INT, PROP_NONE);
288 RNA_def_property_int_sdna(prop, NULL, "freq");
289 RNA_def_property_ui_text(prop, "Frequency", "Delay between repeated pulses(in logic tics, 0=no delay)");
290 RNA_def_property_range(prop, 0, 10000);
291 RNA_def_property_update(prop, NC_LOGIC, NULL);
293 prop= RNA_def_property(srna, "tap", PROP_BOOLEAN, PROP_NONE);
294 RNA_def_property_boolean_sdna(prop, NULL, "tap", 1);
295 RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_tap_set");
296 RNA_def_property_ui_text(prop, "Tap", "Trigger controllers only for an instant, even while the sensor remains true");
297 RNA_def_property_update(prop, NC_LOGIC, NULL);
300 static void rna_def_always_sensor(BlenderRNA *brna)
303 srna= RNA_def_struct(brna, "AlwaysSensor", "Sensor");
304 RNA_def_struct_ui_text(srna, "Always Sensor", "Sensor to generate continuous pulses");
307 static void rna_def_near_sensor(BlenderRNA *brna)
312 srna= RNA_def_struct(brna, "NearSensor", "Sensor");
313 RNA_def_struct_ui_text(srna , "Near Sensor", "Sensor to detect nearby objects");
314 RNA_def_struct_sdna_from(srna, "bNearSensor", "data");
316 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
317 RNA_def_property_string_sdna(prop, NULL, "name");
318 RNA_def_property_ui_text(prop, "Property", "Only look for objects with this property");
319 RNA_def_property_update(prop, NC_LOGIC, NULL);
321 prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
322 RNA_def_property_float_sdna(prop, NULL, "dist");
323 RNA_def_property_ui_text(prop, "Distance", "Trigger distance");
324 RNA_def_property_range(prop, 0.0f, 10000.0f);
325 RNA_def_property_update(prop, NC_LOGIC, NULL);
327 prop= RNA_def_property(srna, "reset_distance", PROP_FLOAT, PROP_NONE);
328 RNA_def_property_float_sdna(prop, NULL, "resetdist");
329 RNA_def_property_ui_text(prop, "Reset Distance", "");
330 RNA_def_property_range(prop, 0.0f, 10000.0f);
331 RNA_def_property_update(prop, NC_LOGIC, NULL);
334 static void rna_def_mouse_sensor(BlenderRNA *brna)
339 static EnumPropertyItem mouse_event_items[] ={
340 {BL_SENS_MOUSE_LEFT_BUTTON, "LEFTCLICK", 0, "Left Button", ""},
341 {BL_SENS_MOUSE_MIDDLE_BUTTON, "MIDDLECLICK", 0, "Middle Button", ""},
342 {BL_SENS_MOUSE_RIGHT_BUTTON, "RIGHTCLICK", 0, "Right Button", ""},
343 {BL_SENS_MOUSE_WHEEL_UP, "WHEELUP", 0, "Wheel Up", ""},
344 {BL_SENS_MOUSE_WHEEL_DOWN, "WHEELDOWN", 0, "Wheel Down", ""},
345 {BL_SENS_MOUSE_MOVEMENT, "MOVEMENT", 0, "Movement", ""},
346 {BL_SENS_MOUSE_MOUSEOVER, "MOUSEOVER", 0, "Mouse Over", ""},
347 {BL_SENS_MOUSE_MOUSEOVER_ANY, "MOUSEOVERANY", 0, "Mouse Over Any", ""},
348 {0, NULL, 0, NULL, NULL}};
350 srna= RNA_def_struct(brna, "MouseSensor", "Sensor");
351 RNA_def_struct_ui_text(srna, "Mouse Sensor", "Sensor to detect mouse events");
352 RNA_def_struct_sdna_from(srna, "bMouseSensor", "data");
354 prop= RNA_def_property(srna, "mouse_event", PROP_ENUM, PROP_NONE);
355 RNA_def_property_enum_sdna(prop, NULL, "type");
356 RNA_def_property_enum_items(prop, mouse_event_items);
357 RNA_def_property_ui_text(prop, "Mouse Event", "Specify the type of event this mouse sensor should trigger on");
358 RNA_def_property_update(prop, NC_LOGIC, NULL);
361 static void rna_def_touch_sensor(BlenderRNA *brna)
366 srna= RNA_def_struct(brna, "TouchSensor", "Sensor");
367 RNA_def_struct_ui_text(srna, "Touch Sensor", "Sensor to detect objects colliding with the current object");
368 RNA_def_struct_sdna_from(srna, "bTouchSensor", "data");
370 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
371 RNA_def_property_struct_type(prop, "Material");
372 RNA_def_property_pointer_sdna(prop, NULL, "ma");
373 RNA_def_property_flag(prop, PROP_EDITABLE);
374 RNA_def_property_ui_text(prop, "Material", "Only look for objects with this material");
375 RNA_def_property_update(prop, NC_LOGIC, NULL);
378 static void rna_def_keyboard_sensor(BlenderRNA *brna)
383 srna= RNA_def_struct(brna, "KeyboardSensor", "Sensor");
384 RNA_def_struct_ui_text(srna, "Keyboard Sensor", "Sensor to detect keyboard events");
385 RNA_def_struct_sdna_from(srna, "bKeyboardSensor", "data");
387 prop= RNA_def_property(srna, "key", PROP_ENUM, PROP_NONE);
388 RNA_def_property_enum_sdna(prop, NULL, "key");
389 RNA_def_property_enum_items(prop, event_type_items);
390 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_key_set", NULL);
391 RNA_def_property_ui_text(prop, "Key", "");
392 RNA_def_property_update(prop, NC_LOGIC, NULL);
394 prop= RNA_def_property(srna, "modifier_key", PROP_ENUM, PROP_NONE);
395 RNA_def_property_enum_sdna(prop, NULL, "qual");
396 RNA_def_property_enum_items(prop, event_type_items);
397 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier_set", NULL);
398 RNA_def_property_ui_text(prop, "Modifier Key", "Modifier key code");
399 RNA_def_property_update(prop, NC_LOGIC, NULL);
401 prop= RNA_def_property(srna, "second_modifier_key", PROP_ENUM, PROP_NONE);
402 RNA_def_property_enum_sdna(prop, NULL, "qual2");
403 RNA_def_property_enum_items(prop, event_type_items);
404 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier2_set", NULL);
405 RNA_def_property_ui_text(prop, "Second Modifier Key", "Modifier key code");
406 RNA_def_property_update(prop, NC_LOGIC, NULL);
408 prop= RNA_def_property(srna, "target", PROP_STRING, PROP_NONE);
409 RNA_def_property_string_sdna(prop, NULL, "targetName");
410 RNA_def_property_ui_text(prop, "Target", "Property that indicates whether to log keystrokes as a string");
411 RNA_def_property_update(prop, NC_LOGIC, NULL);
413 prop= RNA_def_property(srna, "log", PROP_STRING, PROP_NONE);
414 RNA_def_property_string_sdna(prop, NULL, "toggleName");
415 RNA_def_property_ui_text(prop, "Log Toggle", "Property that receive the keystrokes in case a string is logged");
416 RNA_def_property_update(prop, NC_LOGIC, NULL);
418 prop= RNA_def_property(srna, "all_keys", PROP_BOOLEAN, PROP_NONE);
419 RNA_def_property_boolean_sdna(prop, NULL, "type", 1);
420 RNA_def_property_ui_text(prop, "All Keys", "Trigger this sensor on any keystroke");
421 RNA_def_property_update(prop, NC_LOGIC, NULL);
424 static void rna_def_property_sensor(BlenderRNA *brna)
428 static EnumPropertyItem prop_type_items[] ={
429 {SENS_PROP_EQUAL, "PROPEQUAL", 0, "Equal", ""},
430 {SENS_PROP_NEQUAL, "PROPNEQUAL", 0, "Not Equal", ""},
431 {SENS_PROP_INTERVAL, "PROPINTERVAL", 0, "Interval", ""},
432 {SENS_PROP_CHANGED, "PROPCHANGED", 0, "Changed", ""},
433 /* {SENS_PROP_EXPRESSION, "PROPEXPRESSION", 0, "Expression", ""}, NOT_USED_IN_UI */
434 {0, NULL, 0, NULL, NULL}};
436 srna= RNA_def_struct(brna, "PropertySensor", "Sensor");
437 RNA_def_struct_ui_text(srna, "Property Sensor", "Sensor to detect values and changes in values of properties");
438 RNA_def_struct_sdna_from(srna, "bPropertySensor", "data");
440 prop= RNA_def_property(srna, "evaluation_type", PROP_ENUM, PROP_NONE);
441 RNA_def_property_enum_sdna(prop, NULL, "type");
442 RNA_def_property_enum_items(prop, prop_type_items);
443 RNA_def_property_ui_text(prop, "Evaluation Type", "Type of property evaluation");
444 RNA_def_property_update(prop, NC_LOGIC, NULL);
446 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
447 RNA_def_property_string_sdna(prop, NULL, "name");
448 RNA_def_property_ui_text(prop, "Property", "");
449 RNA_def_property_update(prop, NC_LOGIC, NULL);
451 prop= RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
452 RNA_def_property_string_sdna(prop, NULL, "value");
453 RNA_def_property_ui_text(prop, "Value", "Check for this value in types in Equal or Not Equal types");
454 RNA_def_property_update(prop, NC_LOGIC, NULL);
456 prop= RNA_def_property(srna, "min_value", PROP_STRING, PROP_NONE);
457 RNA_def_property_string_sdna(prop, NULL, "value");
458 RNA_def_property_ui_text(prop, "Minimum Value", "Specify minimum value in Interval type");
459 RNA_def_property_update(prop, NC_LOGIC, NULL);
461 prop= RNA_def_property(srna, "max_value", PROP_STRING, PROP_NONE);
462 RNA_def_property_string_sdna(prop, NULL, "maxvalue");
463 RNA_def_property_ui_text(prop, "Maximum Value", "Specify maximum value in Interval type");
464 RNA_def_property_update(prop, NC_LOGIC, NULL);
467 static void rna_def_armature_sensor(BlenderRNA *brna)
471 static EnumPropertyItem prop_type_items[] ={
472 {SENS_ARM_STATE_CHANGED, "STATECHG", 0, "State Changed", ""},
473 {SENS_ARM_LIN_ERROR_BELOW, "LINERRORBELOW", 0, "Lin error below", ""},
474 {SENS_ARM_LIN_ERROR_ABOVE, "LINERRORABOVE", 0, "Lin error above", ""},
475 {SENS_ARM_ROT_ERROR_BELOW, "ROTERRORBELOW", 0, "Rot error below", ""},
476 {SENS_ARM_ROT_ERROR_ABOVE, "ROTERRORBELOW", 0, "Rot error above", ""},
477 {0, NULL, 0, NULL, NULL}};
479 srna= RNA_def_struct(brna, "ArmatureSensor", "Sensor");
480 RNA_def_struct_ui_text(srna, "Armature Sensor", "Sensor to detect values and changes in values of IK solver");
481 RNA_def_struct_sdna_from(srna, "bArmatureSensor", "data");
483 prop= RNA_def_property(srna, "test_type", PROP_ENUM, PROP_NONE);
484 RNA_def_property_enum_sdna(prop, NULL, "type");
485 RNA_def_property_enum_items(prop, prop_type_items);
486 RNA_def_property_ui_text(prop, "Test Type", "Type of value and test");
487 RNA_def_property_update(prop, NC_LOGIC, NULL);
489 prop= RNA_def_property(srna, "bone", PROP_STRING, PROP_NONE);
490 RNA_def_property_string_sdna(prop, NULL, "posechannel");
491 RNA_def_property_ui_text(prop, "Bone name", "Identify the bone to check value from");
492 RNA_def_property_update(prop, NC_LOGIC, "rna_Sensor_Armature_update");
494 prop= RNA_def_property(srna, "constraint", PROP_STRING, PROP_NONE);
495 RNA_def_property_string_sdna(prop, NULL, "constraint");
496 RNA_def_property_ui_text(prop, "Constraint name", "Identify the bone constraint to check value from");
497 RNA_def_property_update(prop, NC_LOGIC, "rna_Sensor_Armature_update");
499 prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
500 RNA_def_property_float_sdna(prop, NULL, "value");
501 RNA_def_property_ui_text(prop, "Compare Value", "Specify value to be used in comparison");
502 RNA_def_property_update(prop, NC_LOGIC, NULL);
505 static void rna_def_actuator_sensor(BlenderRNA *brna)
510 srna= RNA_def_struct(brna, "ActuatorSensor", "Sensor");
511 RNA_def_struct_ui_text(srna, "Actuator Sensor", "Sensor to detect state modifications of actuators");
512 RNA_def_struct_sdna_from(srna, "bActuatorSensor", "data");
514 // XXX if eventually have Logics using RNA 100%, we could use the actuator datablock isntead of its name
515 prop= RNA_def_property(srna, "actuator", PROP_STRING, PROP_NONE);
516 RNA_def_property_string_sdna(prop, NULL, "name");
517 RNA_def_property_ui_text(prop, "Actuator", "Actuator name, actuator active state modifications will be detected");
518 RNA_def_property_update(prop, NC_LOGIC, NULL);
521 static void rna_def_delay_sensor(BlenderRNA *brna)
526 srna= RNA_def_struct(brna, "DelaySensor", "Sensor");
527 RNA_def_struct_ui_text(srna, "Delay Sensor", "Sensor to send delayed events");
528 RNA_def_struct_sdna_from(srna, "bDelaySensor", "data");
530 prop= RNA_def_property(srna, "delay", PROP_INT, PROP_NONE);
531 RNA_def_property_ui_text(prop, "Delay", "Delay in number of logic tics before the positive trigger (default 60 per second)");
532 RNA_def_property_range(prop, 0, 5000);
533 RNA_def_property_update(prop, NC_LOGIC, NULL);
535 prop= RNA_def_property(srna, "duration", PROP_INT, PROP_NONE);
536 RNA_def_property_ui_text(prop, "Duration", "If >0, delay in number of logic tics before the negative trigger following the positive trigger");
537 RNA_def_property_range(prop, 0, 5000);
538 RNA_def_property_update(prop, NC_LOGIC, NULL);
540 prop= RNA_def_property(srna, "repeat", PROP_BOOLEAN, PROP_NONE);
541 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_DELAY_REPEAT);
542 RNA_def_property_ui_text(prop, "Repeat", "Toggle repeat option. If selected, the sensor restarts after Delay+Dur logic tics");
543 RNA_def_property_update(prop, NC_LOGIC, NULL);
546 static void rna_def_collision_sensor(BlenderRNA *brna)
551 srna= RNA_def_struct(brna, "CollisionSensor", "Sensor");
552 RNA_def_struct_ui_text(srna, "Collision Sensor", "Sensor to detect objects colliding with the current object, with more settings than the Touch sensor");
553 RNA_def_struct_sdna_from(srna, "bCollisionSensor", "data");
555 prop= RNA_def_property(srna, "pulse", PROP_BOOLEAN, PROP_NONE);
556 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_COLLISION_PULSE);
557 RNA_def_property_ui_text(prop, "Pulse", "Changes to the set of colliding objects generates pulse");
558 RNA_def_property_update(prop, NC_LOGIC, NULL);
560 prop= RNA_def_property(srna, "collision_type", PROP_BOOLEAN, PROP_NONE);
561 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_COLLISION_MATERIAL);
562 RNA_def_property_ui_text(prop, "M/P", "Toggle collision on material or property");
563 RNA_def_property_update(prop, NC_LOGIC, NULL);
565 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
566 RNA_def_property_string_sdna(prop, NULL, "name");
567 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property");
568 RNA_def_property_update(prop, NC_LOGIC, NULL);
570 //XXX to make a setFunction to create a lookup with all materials in Blend File (not only this object mat.)
571 prop= RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
572 RNA_def_property_string_sdna(prop, NULL, "materialName");
573 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material");
574 RNA_def_property_update(prop, NC_LOGIC, NULL);
576 /*//XXX either use a datablock look up to store the string name (material)
577 // or to do a doversion and use a material pointer.
578 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
579 RNA_def_property_struct_type(prop, "Material");
580 RNA_def_property_flag(prop, PROP_EDITABLE);
581 RNA_def_property_pointer_sdna(prop, NULL, "ma");
582 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material");
586 static void rna_def_radar_sensor(BlenderRNA *brna)
590 static EnumPropertyItem axis_items[] ={
591 {SENS_RAY_X_AXIS, "XAXIS", 0, "+X axis", ""},
592 {SENS_RAY_Y_AXIS, "YAXIS", 0, "+Y axis", ""},
593 {SENS_RAY_Z_AXIS, "ZAXIS", 0, "+Z axis", ""},
594 {SENS_RAY_NEG_X_AXIS, "NEGXAXIS", 0, "-X axis", ""},
595 {SENS_RAY_NEG_Y_AXIS, "NEGYAXIS", 0, "-Y axis", ""},
596 {SENS_RAY_NEG_Z_AXIS, "NEGZAXIS", 0, "-Z axis", ""},
597 {0, NULL, 0, NULL, NULL}};
599 srna= RNA_def_struct(brna, "RadarSensor", "Sensor");
600 RNA_def_struct_ui_text(srna, "Radar Sensor", "Sensor to detect objects in a cone shaped radar emanating from the current object");
601 RNA_def_struct_sdna_from(srna, "bRadarSensor", "data");
603 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
604 RNA_def_property_string_sdna(prop, NULL, "name");
605 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property");
606 RNA_def_property_update(prop, NC_LOGIC, NULL);
608 prop= RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
609 RNA_def_property_enum_items(prop, axis_items);
610 RNA_def_property_ui_text(prop, "Axis", "Specify along which axis the radar cone is cast");
611 RNA_def_property_update(prop, NC_LOGIC, NULL);
613 prop= RNA_def_property(srna, "angle", PROP_FLOAT, PROP_NONE);
614 RNA_def_property_range(prop, 0.0, 179.9);
615 RNA_def_property_ui_text(prop, "Angle", "Opening angle of the radar cone");
616 RNA_def_property_update(prop, NC_LOGIC, NULL);
618 prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
619 RNA_def_property_float_sdna(prop, NULL, "range");
620 RNA_def_property_range(prop, 0.0, 10000.0);
621 RNA_def_property_ui_text(prop, "Distance", "Depth of the radar cone");
622 RNA_def_property_update(prop, NC_LOGIC, NULL);
625 static void rna_def_random_sensor(BlenderRNA *brna)
630 srna= RNA_def_struct(brna, "RandomSensor", "Sensor");
631 RNA_def_struct_ui_text(srna, "Random Sensor", "Sensor to send random events");
632 RNA_def_struct_sdna_from(srna, "bRandomSensor", "data");
634 prop= RNA_def_property(srna, "seed", PROP_INT, PROP_NONE);
635 RNA_def_property_range(prop, 0, 1000);
636 RNA_def_property_ui_text(prop, "Seed", "Initial seed of the generator. (Choose 0 for not random)");
637 RNA_def_property_update(prop, NC_LOGIC, NULL);
640 static void rna_def_ray_sensor(BlenderRNA *brna)
644 static EnumPropertyItem axis_items[] ={
645 {SENS_RAY_X_AXIS, "XAXIS", 0, "+X axis", ""},
646 {SENS_RAY_Y_AXIS, "YAXIS", 0, "+Y axis", ""},
647 {SENS_RAY_Z_AXIS, "ZAXIS", 0, "+Z axis", ""},
648 {SENS_RAY_NEG_X_AXIS, "NEGXAXIS", 0, "-X axis", ""},
649 {SENS_RAY_NEG_Y_AXIS, "NEGYAXIS", 0, "-Y axis", ""},
650 {SENS_RAY_NEG_Z_AXIS, "NEGZAXIS", 0, "-Z axis", ""},
651 {0, NULL, 0, NULL, NULL}};
653 static const EnumPropertyItem prop_ray_type_items[]= {
654 {SENS_COLLISION_PROPERTY, "PROPERTY", ICON_LOGIC, "Property", "Use a material for ray intersections"},
655 {SENS_COLLISION_MATERIAL, "MATERIAL", ICON_MATERIAL_DATA, "Material", "Use a property for ray intersections"},
656 {0, NULL, 0, NULL, NULL}};
658 srna= RNA_def_struct(brna, "RaySensor", "Sensor");
659 RNA_def_struct_ui_text(srna, "Ray Sensor", "Sensor to detect intersections with a ray emanating from the current object");
660 RNA_def_struct_sdna_from(srna, "bRaySensor", "data");
662 prop= RNA_def_property(srna, "ray_type", PROP_ENUM, PROP_NONE);
663 RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
664 RNA_def_property_enum_items(prop, prop_ray_type_items);
665 RNA_def_property_ui_text(prop, "Ray Type", "Toggle collision on material or property");
666 RNA_def_property_update(prop, NC_LOGIC, NULL);
668 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
669 RNA_def_property_string_sdna(prop, NULL, "propname");
670 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property");
671 RNA_def_property_update(prop, NC_LOGIC, NULL);
673 prop= RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
674 RNA_def_property_string_sdna(prop, NULL, "matname");
675 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material");
676 RNA_def_property_update(prop, NC_LOGIC, NULL);
678 /* //XXX either use a datablock look up to store the string name (material)
679 // or to do a doversion and use a material pointer.
680 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
681 RNA_def_property_struct_type(prop, "Material");
682 RNA_def_property_flag(prop, PROP_EDITABLE);
683 RNA_def_property_pointer_sdna(prop, NULL, "ma");
684 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material");
687 prop= RNA_def_property(srna, "x_ray_mode", PROP_BOOLEAN, PROP_NONE);
688 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_RAY_XRAY);
689 RNA_def_property_ui_text(prop, "X-Ray Mode", "Toggle X-Ray option (see through objects that don't have the property)");
690 RNA_def_property_update(prop, NC_LOGIC, NULL);
692 prop= RNA_def_property(srna, "range", PROP_FLOAT, PROP_NONE);
693 RNA_def_property_range(prop, 0.01, 10000.0);
694 RNA_def_property_ui_text(prop, "Range", "Sense objects no farther than this distance");
695 RNA_def_property_update(prop, NC_LOGIC, NULL);
697 prop= RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
698 RNA_def_property_enum_sdna(prop, NULL, "axisflag");
699 RNA_def_property_enum_items(prop, axis_items);
700 RNA_def_property_ui_text(prop, "Axis", "Specify along which axis the ray is cast");
701 RNA_def_property_update(prop, NC_LOGIC, NULL);
704 static void rna_def_message_sensor(BlenderRNA *brna)
709 srna= RNA_def_struct(brna, "MessageSensor", "Sensor");
710 RNA_def_struct_ui_text(srna, "Message Sensor", "Sensor to detect incoming messages");
711 RNA_def_struct_sdna_from(srna, "bMessageSensor", "data");
713 prop= RNA_def_property(srna, "subject", PROP_STRING, PROP_NONE);
714 RNA_def_property_ui_text(prop, "Subject", "Optional subject filter: only accept messages with this subject, or empty for all");
715 RNA_def_property_update(prop, NC_LOGIC, NULL);
718 static void rna_def_joystick_sensor(BlenderRNA *brna)
723 static EnumPropertyItem event_type_items[] ={
724 {SENS_JOY_BUTTON, "BUTTON", 0, "Button", ""},
725 {SENS_JOY_AXIS, "AXIS", 0, "Axis", ""},
726 {SENS_JOY_HAT, "HAT", 0, "Hat", ""},
727 {SENS_JOY_AXIS_SINGLE, "AXIS_SINGLE", 0, "Single Axis", ""},
728 {0, NULL, 0, NULL, NULL}};
730 static EnumPropertyItem axis_direction_items[] ={
731 {SENS_JOY_X_AXIS, "RIGHTAXIS", 0, "Right Axis", ""},
732 {SENS_JOY_Y_AXIS, "UPAXIS", 0, "Up Axis", ""},
733 {SENS_JOY_NEG_X_AXIS, "LEFTAXIS", 0, "Left Axis", ""},
734 {SENS_JOY_NEG_Y_AXIS, "DOWNAXIS", 0, "Down Axis", ""},
735 {0, NULL, 0, NULL, NULL}};
737 static EnumPropertyItem hat_direction_items[] ={
738 {SENS_JOY_HAT_UP, "UP", 0, "Up", ""},
739 {SENS_JOY_HAT_DOWN, "DOWN", 0, "Down", ""},
740 {SENS_JOY_HAT_LEFT, "LEFT", 0, "Left", ""},
741 {SENS_JOY_HAT_RIGHT, "RIGHT", 0, "Right", ""},
743 {SENS_JOY_HAT_UP_RIGHT, "UPRIGHT", 0, "Up/Right", ""},
744 {SENS_JOY_HAT_DOWN_LEFT, "DOWNLEFT", 0, "Down/Left", ""},
745 {SENS_JOY_HAT_UP_LEFT, "UPLEFT", 0, "Up/Left", ""},
746 {SENS_JOY_HAT_DOWN_RIGHT, "DOWNRIGHT", 0, "Down/Right", ""},
747 {0, NULL, 0, NULL, NULL}};
749 srna= RNA_def_struct(brna, "JoystickSensor", "Sensor");
750 RNA_def_struct_ui_text(srna, "Joystick Sensor", "Sensor to detect joystick events");
751 RNA_def_struct_sdna_from(srna, "bJoystickSensor", "data");
753 prop= RNA_def_property(srna, "joystick_index", PROP_INT, PROP_NONE);
754 RNA_def_property_int_sdna(prop, NULL, "joyindex");
755 RNA_def_property_ui_text(prop, "Index", "Specify which joystick to use");
756 RNA_def_property_range(prop, 0, SENS_JOY_MAXINDEX-1);
757 RNA_def_property_update(prop, NC_LOGIC, NULL);
759 prop= RNA_def_property(srna, "event_type", PROP_ENUM, PROP_NONE);
760 RNA_def_property_enum_sdna(prop, NULL, "type");
761 RNA_def_property_enum_items(prop, event_type_items);
762 RNA_def_property_ui_text(prop, "Event Type", "The type of event this joystick sensor is triggered on");
763 RNA_def_property_update(prop, NC_LOGIC, NULL);
765 prop= RNA_def_property(srna, "all_events", PROP_BOOLEAN, PROP_NONE);
766 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_JOY_ANY_EVENT);
767 RNA_def_property_ui_text(prop, "All Events", "Triggered by all events on this joysticks current type (axis/button/hat)");
768 RNA_def_property_update(prop, NC_LOGIC, NULL);
771 prop= RNA_def_property(srna, "button_number", PROP_INT, PROP_NONE);
772 RNA_def_property_int_sdna(prop, NULL, "button");
773 RNA_def_property_ui_text(prop, "Button Number", "Specify which button to use");
774 RNA_def_property_range(prop, 0, 18);
775 RNA_def_property_update(prop, NC_LOGIC, NULL);
778 prop= RNA_def_property(srna, "axis_number", PROP_INT, PROP_NONE);
779 RNA_def_property_int_sdna(prop, NULL, "axis");
780 RNA_def_property_ui_text(prop, "Axis Number", "Specify which axis pair to use, 1 is usually the main direction input");
781 RNA_def_property_range(prop, 1, 2);
782 RNA_def_property_update(prop, NC_LOGIC, NULL);
784 prop= RNA_def_property(srna, "axis_threshold", PROP_INT, PROP_NONE);
785 RNA_def_property_int_sdna(prop, NULL, "precision");
786 RNA_def_property_ui_text(prop, "Axis Threshold", "Specify the precision of the axis");
787 RNA_def_property_range(prop, 0, 32768);
788 RNA_def_property_update(prop, NC_LOGIC, NULL);
790 prop= RNA_def_property(srna, "axis_direction", PROP_ENUM, PROP_NONE);
791 RNA_def_property_enum_sdna(prop, NULL, "axisf");
792 RNA_def_property_enum_items(prop, axis_direction_items);
793 RNA_def_property_ui_text(prop, "Axis Direction", "The direction of the axis");
794 RNA_def_property_update(prop, NC_LOGIC, NULL);
797 prop= RNA_def_property(srna, "single_axis_number", PROP_INT, PROP_NONE);
798 RNA_def_property_int_sdna(prop, NULL, "axis_single");
799 RNA_def_property_ui_text(prop, "Axis Number", "Specify a single axis (verticle/horizontal/other) to detect");
800 RNA_def_property_range(prop, 1, 16);
801 RNA_def_property_update(prop, NC_LOGIC, NULL);
804 prop= RNA_def_property(srna, "hat_number", PROP_INT, PROP_NONE);
805 RNA_def_property_int_sdna(prop, NULL, "hat");
806 RNA_def_property_ui_text(prop, "Hat Number", "Specify which hat to use");
807 RNA_def_property_range(prop, 1, 2);
808 RNA_def_property_update(prop, NC_LOGIC, NULL);
810 prop= RNA_def_property(srna, "hat_direction", PROP_ENUM, PROP_NONE);
811 RNA_def_property_enum_sdna(prop, NULL, "hatf");
812 RNA_def_property_enum_items(prop, hat_direction_items);
813 RNA_def_property_ui_text(prop, "Hat Direction", "Specify hat direction");
814 RNA_def_property_update(prop, NC_LOGIC, NULL);
817 void RNA_def_sensor(BlenderRNA *brna)
819 rna_def_sensor(brna);
821 rna_def_always_sensor(brna);
822 rna_def_near_sensor(brna);
823 rna_def_mouse_sensor(brna);
824 rna_def_touch_sensor(brna);
825 rna_def_keyboard_sensor(brna);
826 rna_def_property_sensor(brna);
827 rna_def_armature_sensor(brna);
828 rna_def_actuator_sensor(brna);
829 rna_def_delay_sensor(brna);
830 rna_def_collision_sensor(brna);
831 rna_def_radar_sensor(brna);
832 rna_def_random_sensor(brna);
833 rna_def_ray_sensor(brna);
834 rna_def_message_sensor(brna);
835 rna_def_joystick_sensor(brna);