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);
133 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_COLLISION);
134 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_DELAY);
135 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_JOYSTICK);
136 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_KEYBOARD);
137 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MESSAGE);
138 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MOUSE);
139 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_NEAR);
140 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_PROPERTY);
141 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RADAR);
142 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RANDOM);
143 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RAY);
144 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_TOUCH);
146 RNA_enum_item_end(&item, &totitem);
152 static void rna_Sensor_keyboard_key_set(struct PointerRNA *ptr, int value)
154 bSensor *sens= (bSensor *)ptr->data;
155 bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
157 if (ISKEYBOARD(value))
163 static void rna_Sensor_keyboard_modifier_set(struct PointerRNA *ptr, int value)
165 bSensor *sens= (bSensor *)ptr->data;
166 bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
168 if (ISKEYBOARD(value))
174 static void rna_Sensor_keyboard_modifier2_set(struct PointerRNA *ptr, int value)
176 bSensor *sens= (bSensor *)ptr->data;
177 bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
179 if (ISKEYBOARD(value))
185 static void rna_Sensor_tap_set(struct PointerRNA *ptr, int value)
187 bSensor *sens= (bSensor*)ptr->data;
194 static void rna_Sensor_level_set(struct PointerRNA *ptr, int value)
196 bSensor *sens= (bSensor*)ptr->data;
203 static void rna_Sensor_Armature_update(Main *bmain, Scene *scene, PointerRNA *ptr)
205 bSensor *sens= (bSensor *)ptr->data;
206 bArmatureSensor *as = sens->data;
207 Object *ob = (Object *)ptr->id.data;
209 char *posechannel= as->posechannel;
210 char *constraint= as->constraint;
212 /* check that bone exist in the active object */
213 if (ob->type == OB_ARMATURE && ob->pose) {
215 bPose *pose = ob->pose;
216 for (pchan=pose->chanbase.first; pchan; pchan=pchan->next) {
217 if (!strcmp(pchan->name, posechannel)) {
218 /* found it, now look for constraint channel */
220 for (con=pchan->constraints.first; con; con=con->next) {
221 if (!strcmp(con->name, constraint)) {
222 /* found it, all ok */
226 /* didn't find constraint, make empty */
232 /* didn't find any */
237 /* note: the following set functions exists only to avoid id refcounting */
238 static void rna_Sensor_touch_material_set(PointerRNA *ptr, PointerRNA value)
240 bSensor *sens = (bSensor *)ptr->data;
241 bTouchSensor *ts = (bTouchSensor *) sens->data;
247 static void rna_def_sensor(BlenderRNA *brna)
252 srna= RNA_def_struct(brna, "Sensor", NULL);
253 RNA_def_struct_ui_text(srna, "Sensor", "Game engine logic brick to detect events");
254 RNA_def_struct_sdna(srna, "bSensor");
255 RNA_def_struct_refine_func(srna, "rna_Sensor_refine");
257 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
258 RNA_def_property_ui_text(prop, "Name", "Sensor name");
259 RNA_def_struct_name_property(srna, prop);
260 RNA_def_property_update(prop, NC_LOGIC, NULL);
262 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
263 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
264 RNA_def_property_enum_items(prop, sensor_type_items);
265 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_type_set", "rna_Sensor_type_itemf");
266 RNA_def_property_ui_text(prop, "Type", "");
267 RNA_def_property_update(prop, NC_LOGIC, NULL);
269 prop= RNA_def_property(srna, "pin", PROP_BOOLEAN, PROP_NONE);
270 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_PIN);
271 RNA_def_property_ui_text(prop, "Pinned", "Display when not linked to a visible states controller");
272 RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
273 RNA_def_property_update(prop, NC_LOGIC, NULL);
275 prop= RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
276 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_SHOW);
277 RNA_def_property_ui_text(prop, "Expanded", "Set sensor expanded in the user interface");
278 RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
279 RNA_def_property_update(prop, NC_LOGIC, NULL);
281 prop= RNA_def_property(srna, "invert", PROP_BOOLEAN, PROP_NONE);
282 RNA_def_property_ui_text(prop, "Invert Output", "Invert the level(output) of this sensor");
283 RNA_def_property_update(prop, NC_LOGIC, NULL);
285 prop= RNA_def_property(srna, "use_level", PROP_BOOLEAN, PROP_NONE);
286 RNA_def_property_boolean_sdna(prop, NULL, "level", 1);
287 RNA_def_property_ui_text(prop, "Level", "Level detector, trigger controllers of new states(only applicable upon logic state transition)");
288 RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_level_set");
289 RNA_def_property_update(prop, NC_LOGIC, NULL);
291 prop= RNA_def_property(srna, "use_pulse_true_level", PROP_BOOLEAN, PROP_NONE);
292 RNA_def_property_boolean_sdna(prop, NULL, "pulse", SENS_PULSE_REPEAT);
293 RNA_def_property_ui_text(prop, "Pulse True Level", "Activate TRUE level triggering (pulse mode)");
294 RNA_def_property_update(prop, NC_LOGIC, NULL);
296 prop= RNA_def_property(srna, "use_pulse_false_level", PROP_BOOLEAN, PROP_NONE);
297 RNA_def_property_boolean_sdna(prop, NULL, "pulse", SENS_NEG_PULSE_MODE);
298 RNA_def_property_ui_text(prop, "Pulse False Level", "Activate FALSE level triggering (pulse mode)");
299 RNA_def_property_update(prop, NC_LOGIC, NULL);
301 prop= RNA_def_property(srna, "frequency", PROP_INT, PROP_NONE);
302 RNA_def_property_int_sdna(prop, NULL, "freq");
303 RNA_def_property_ui_text(prop, "Frequency", "Delay between repeated pulses(in logic tics, 0=no delay)");
304 RNA_def_property_range(prop, 0, 10000);
305 RNA_def_property_update(prop, NC_LOGIC, NULL);
307 prop= RNA_def_property(srna, "use_tap", PROP_BOOLEAN, PROP_NONE);
308 RNA_def_property_boolean_sdna(prop, NULL, "tap", 1);
309 RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_tap_set");
310 RNA_def_property_ui_text(prop, "Tap", "Trigger controllers only for an instant, even while the sensor remains true");
311 RNA_def_property_update(prop, NC_LOGIC, NULL);
313 RNA_api_sensor(srna);
316 static void rna_def_always_sensor(BlenderRNA *brna)
319 srna= RNA_def_struct(brna, "AlwaysSensor", "Sensor");
320 RNA_def_struct_ui_text(srna, "Always Sensor", "Sensor to generate continuous pulses");
323 static void rna_def_near_sensor(BlenderRNA *brna)
328 srna= RNA_def_struct(brna, "NearSensor", "Sensor");
329 RNA_def_struct_ui_text(srna , "Near Sensor", "Sensor to detect nearby objects");
330 RNA_def_struct_sdna_from(srna, "bNearSensor", "data");
332 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
333 RNA_def_property_string_sdna(prop, NULL, "name");
334 RNA_def_property_ui_text(prop, "Property", "Only look for objects with this property");
335 RNA_def_property_update(prop, NC_LOGIC, NULL);
337 prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
338 RNA_def_property_float_sdna(prop, NULL, "dist");
339 RNA_def_property_ui_text(prop, "Distance", "Trigger distance");
340 RNA_def_property_range(prop, 0.0f, 10000.0f);
341 RNA_def_property_update(prop, NC_LOGIC, NULL);
343 prop= RNA_def_property(srna, "reset_distance", PROP_FLOAT, PROP_NONE);
344 RNA_def_property_float_sdna(prop, NULL, "resetdist");
345 RNA_def_property_ui_text(prop, "Reset Distance", "");
346 RNA_def_property_range(prop, 0.0f, 10000.0f);
347 RNA_def_property_update(prop, NC_LOGIC, NULL);
350 static void rna_def_mouse_sensor(BlenderRNA *brna)
355 static EnumPropertyItem mouse_event_items[] ={
356 {BL_SENS_MOUSE_LEFT_BUTTON, "LEFTCLICK", 0, "Left Button", ""},
357 {BL_SENS_MOUSE_MIDDLE_BUTTON, "MIDDLECLICK", 0, "Middle Button", ""},
358 {BL_SENS_MOUSE_RIGHT_BUTTON, "RIGHTCLICK", 0, "Right Button", ""},
359 {BL_SENS_MOUSE_WHEEL_UP, "WHEELUP", 0, "Wheel Up", ""},
360 {BL_SENS_MOUSE_WHEEL_DOWN, "WHEELDOWN", 0, "Wheel Down", ""},
361 {BL_SENS_MOUSE_MOVEMENT, "MOVEMENT", 0, "Movement", ""},
362 {BL_SENS_MOUSE_MOUSEOVER, "MOUSEOVER", 0, "Mouse Over", ""},
363 {BL_SENS_MOUSE_MOUSEOVER_ANY, "MOUSEOVERANY", 0, "Mouse Over Any", ""},
364 {0, NULL, 0, NULL, NULL}};
366 srna= RNA_def_struct(brna, "MouseSensor", "Sensor");
367 RNA_def_struct_ui_text(srna, "Mouse Sensor", "Sensor to detect mouse events");
368 RNA_def_struct_sdna_from(srna, "bMouseSensor", "data");
370 prop= RNA_def_property(srna, "mouse_event", PROP_ENUM, PROP_NONE);
371 RNA_def_property_enum_sdna(prop, NULL, "type");
372 RNA_def_property_enum_items(prop, mouse_event_items);
373 RNA_def_property_ui_text(prop, "Mouse Event", "Specify the type of event this mouse sensor should trigger on");
374 RNA_def_property_update(prop, NC_LOGIC, NULL);
377 static void rna_def_touch_sensor(BlenderRNA *brna)
382 srna= RNA_def_struct(brna, "TouchSensor", "Sensor");
383 RNA_def_struct_ui_text(srna, "Touch Sensor", "Sensor to detect objects colliding with the current object");
384 RNA_def_struct_sdna_from(srna, "bTouchSensor", "data");
386 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
387 RNA_def_property_struct_type(prop, "Material");
388 RNA_def_property_pointer_sdna(prop, NULL, "ma");
389 RNA_def_property_flag(prop, PROP_EDITABLE);
390 RNA_def_property_ui_text(prop, "Material", "Only look for objects with this material");
391 /* note: custom set function is ONLY to avoid rna setting a user for this. */
392 RNA_def_property_pointer_funcs(prop, NULL, "rna_Sensor_touch_material_set", NULL, NULL);
393 RNA_def_property_update(prop, NC_LOGIC, NULL);
396 static void rna_def_keyboard_sensor(BlenderRNA *brna)
401 srna= RNA_def_struct(brna, "KeyboardSensor", "Sensor");
402 RNA_def_struct_ui_text(srna, "Keyboard Sensor", "Sensor to detect keyboard events");
403 RNA_def_struct_sdna_from(srna, "bKeyboardSensor", "data");
405 prop= RNA_def_property(srna, "key", PROP_ENUM, PROP_NONE);
406 RNA_def_property_enum_sdna(prop, NULL, "key");
407 RNA_def_property_enum_items(prop, event_type_items);
408 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_key_set", NULL);
409 RNA_def_property_ui_text(prop, "Key", "");
410 RNA_def_property_update(prop, NC_LOGIC, NULL);
412 prop= RNA_def_property(srna, "modifier_key_1", PROP_ENUM, PROP_NONE);
413 RNA_def_property_enum_sdna(prop, NULL, "qual");
414 RNA_def_property_enum_items(prop, event_type_items);
415 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier_set", NULL);
416 RNA_def_property_ui_text(prop, "Modifier Key", "Modifier key code");
417 RNA_def_property_update(prop, NC_LOGIC, NULL);
419 prop= RNA_def_property(srna, "modifier_key_2", PROP_ENUM, PROP_NONE);
420 RNA_def_property_enum_sdna(prop, NULL, "qual2");
421 RNA_def_property_enum_items(prop, event_type_items);
422 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier2_set", NULL);
423 RNA_def_property_ui_text(prop, "Second Modifier Key", "Modifier key code");
424 RNA_def_property_update(prop, NC_LOGIC, NULL);
426 prop= RNA_def_property(srna, "target", PROP_STRING, PROP_NONE);
427 RNA_def_property_string_sdna(prop, NULL, "targetName");
428 RNA_def_property_ui_text(prop, "Target", "Property that indicates whether to log keystrokes as a string");
429 RNA_def_property_update(prop, NC_LOGIC, NULL);
431 prop= RNA_def_property(srna, "log", PROP_STRING, PROP_NONE);
432 RNA_def_property_string_sdna(prop, NULL, "toggleName");
433 RNA_def_property_ui_text(prop, "Log Toggle", "Property that receive the keystrokes in case a string is logged");
434 RNA_def_property_update(prop, NC_LOGIC, NULL);
436 prop= RNA_def_property(srna, "use_all_keys", PROP_BOOLEAN, PROP_NONE);
437 RNA_def_property_boolean_sdna(prop, NULL, "type", 1);
438 RNA_def_property_ui_text(prop, "All Keys", "Trigger this sensor on any keystroke");
439 RNA_def_property_update(prop, NC_LOGIC, NULL);
442 static void rna_def_property_sensor(BlenderRNA *brna)
446 static EnumPropertyItem prop_type_items[] ={
447 {SENS_PROP_EQUAL, "PROPEQUAL", 0, "Equal", ""},
448 {SENS_PROP_NEQUAL, "PROPNEQUAL", 0, "Not Equal", ""},
449 {SENS_PROP_INTERVAL, "PROPINTERVAL", 0, "Interval", ""},
450 {SENS_PROP_CHANGED, "PROPCHANGED", 0, "Changed", ""},
451 /* {SENS_PROP_EXPRESSION, "PROPEXPRESSION", 0, "Expression", ""}, NOT_USED_IN_UI */
452 {0, NULL, 0, NULL, NULL}};
454 srna= RNA_def_struct(brna, "PropertySensor", "Sensor");
455 RNA_def_struct_ui_text(srna, "Property Sensor", "Sensor to detect values and changes in values of properties");
456 RNA_def_struct_sdna_from(srna, "bPropertySensor", "data");
458 prop= RNA_def_property(srna, "evaluation_type", PROP_ENUM, PROP_NONE);
459 RNA_def_property_enum_sdna(prop, NULL, "type");
460 RNA_def_property_enum_items(prop, prop_type_items);
461 RNA_def_property_ui_text(prop, "Evaluation Type", "Type of property evaluation");
462 RNA_def_property_update(prop, NC_LOGIC, NULL);
464 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
465 RNA_def_property_string_sdna(prop, NULL, "name");
466 RNA_def_property_ui_text(prop, "Property", "");
467 RNA_def_property_update(prop, NC_LOGIC, NULL);
469 prop= RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
470 RNA_def_property_string_sdna(prop, NULL, "value");
471 RNA_def_property_ui_text(prop, "Value", "Check for this value in types in Equal or Not Equal types");
472 RNA_def_property_update(prop, NC_LOGIC, NULL);
474 prop= RNA_def_property(srna, "value_min", PROP_STRING, PROP_NONE);
475 RNA_def_property_string_sdna(prop, NULL, "value");
476 RNA_def_property_ui_text(prop, "Minimum Value", "Specify minimum value in Interval type");
477 RNA_def_property_update(prop, NC_LOGIC, NULL);
479 prop= RNA_def_property(srna, "value_max", PROP_STRING, PROP_NONE);
480 RNA_def_property_string_sdna(prop, NULL, "maxvalue");
481 RNA_def_property_ui_text(prop, "Maximum Value", "Specify maximum value in Interval type");
482 RNA_def_property_update(prop, NC_LOGIC, NULL);
485 static void rna_def_armature_sensor(BlenderRNA *brna)
489 static EnumPropertyItem prop_type_items[] ={
490 {SENS_ARM_STATE_CHANGED, "STATECHG", 0, "State Changed", ""},
491 {SENS_ARM_LIN_ERROR_BELOW, "LINERRORBELOW", 0, "Lin error below", ""},
492 {SENS_ARM_LIN_ERROR_ABOVE, "LINERRORABOVE", 0, "Lin error above", ""},
493 {SENS_ARM_ROT_ERROR_BELOW, "ROTERRORBELOW", 0, "Rot error below", ""},
494 {SENS_ARM_ROT_ERROR_ABOVE, "ROTERRORBELOW", 0, "Rot error above", ""},
495 {0, NULL, 0, NULL, NULL}};
497 srna= RNA_def_struct(brna, "ArmatureSensor", "Sensor");
498 RNA_def_struct_ui_text(srna, "Armature Sensor", "Sensor to detect values and changes in values of IK solver");
499 RNA_def_struct_sdna_from(srna, "bArmatureSensor", "data");
501 prop= RNA_def_property(srna, "test_type", PROP_ENUM, PROP_NONE);
502 RNA_def_property_enum_sdna(prop, NULL, "type");
503 RNA_def_property_enum_items(prop, prop_type_items);
504 RNA_def_property_ui_text(prop, "Test Type", "Type of value and test");
505 RNA_def_property_update(prop, NC_LOGIC, NULL);
507 prop= RNA_def_property(srna, "bone", PROP_STRING, PROP_NONE);
508 RNA_def_property_string_sdna(prop, NULL, "posechannel");
509 RNA_def_property_ui_text(prop, "Bone name", "Identify the bone to check value from");
510 RNA_def_property_update(prop, NC_LOGIC, "rna_Sensor_Armature_update");
512 prop= RNA_def_property(srna, "constraint", PROP_STRING, PROP_NONE);
513 RNA_def_property_string_sdna(prop, NULL, "constraint");
514 RNA_def_property_ui_text(prop, "Constraint name", "Identify the bone constraint to check value from");
515 RNA_def_property_update(prop, NC_LOGIC, "rna_Sensor_Armature_update");
517 prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
518 RNA_def_property_float_sdna(prop, NULL, "value");
519 RNA_def_property_ui_text(prop, "Compare Value", "Specify value to be used in comparison");
520 RNA_def_property_update(prop, NC_LOGIC, NULL);
523 static void rna_def_actuator_sensor(BlenderRNA *brna)
528 srna= RNA_def_struct(brna, "ActuatorSensor", "Sensor");
529 RNA_def_struct_ui_text(srna, "Actuator Sensor", "Sensor to detect state modifications of actuators");
530 RNA_def_struct_sdna_from(srna, "bActuatorSensor", "data");
532 // XXX if eventually have Logics using RNA 100%, we could use the actuator datablock isntead of its name
533 prop= RNA_def_property(srna, "actuator", PROP_STRING, PROP_NONE);
534 RNA_def_property_string_sdna(prop, NULL, "name");
535 RNA_def_property_ui_text(prop, "Actuator", "Actuator name, actuator active state modifications will be detected");
536 RNA_def_property_update(prop, NC_LOGIC, NULL);
539 static void rna_def_delay_sensor(BlenderRNA *brna)
544 srna= RNA_def_struct(brna, "DelaySensor", "Sensor");
545 RNA_def_struct_ui_text(srna, "Delay Sensor", "Sensor to send delayed events");
546 RNA_def_struct_sdna_from(srna, "bDelaySensor", "data");
548 prop= RNA_def_property(srna, "delay", PROP_INT, PROP_NONE);
549 RNA_def_property_ui_text(prop, "Delay", "Delay in number of logic tics before the positive trigger (default 60 per second)");
550 RNA_def_property_range(prop, 0, 5000);
551 RNA_def_property_update(prop, NC_LOGIC, NULL);
553 prop= RNA_def_property(srna, "duration", PROP_INT, PROP_NONE);
554 RNA_def_property_ui_text(prop, "Duration", "If >0, delay in number of logic tics before the negative trigger following the positive trigger");
555 RNA_def_property_range(prop, 0, 5000);
556 RNA_def_property_update(prop, NC_LOGIC, NULL);
558 prop= RNA_def_property(srna, "use_repeat", PROP_BOOLEAN, PROP_NONE);
559 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_DELAY_REPEAT);
560 RNA_def_property_ui_text(prop, "Repeat", "Toggle repeat option. If selected, the sensor restarts after Delay+Dur logic tics");
561 RNA_def_property_update(prop, NC_LOGIC, NULL);
564 static void rna_def_collision_sensor(BlenderRNA *brna)
569 srna= RNA_def_struct(brna, "CollisionSensor", "Sensor");
570 RNA_def_struct_ui_text(srna, "Collision Sensor", "Sensor to detect objects colliding with the current object, with more settings than the Touch sensor");
571 RNA_def_struct_sdna_from(srna, "bCollisionSensor", "data");
573 prop= RNA_def_property(srna, "use_pulse", PROP_BOOLEAN, PROP_NONE);
574 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_COLLISION_PULSE);
575 RNA_def_property_ui_text(prop, "Pulse", "Changes to the set of colliding objects generates pulse");
576 RNA_def_property_update(prop, NC_LOGIC, NULL);
578 prop= RNA_def_property(srna, "use_material", PROP_BOOLEAN, PROP_NONE);
579 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_COLLISION_MATERIAL);
580 RNA_def_property_ui_text(prop, "M/P", "Toggle collision on material or property");
581 RNA_def_property_update(prop, NC_LOGIC, NULL);
583 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
584 RNA_def_property_string_sdna(prop, NULL, "name");
585 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property");
586 RNA_def_property_update(prop, NC_LOGIC, NULL);
588 //XXX to make a setFunction to create a lookup with all materials in Blend File (not only this object mat.)
589 prop= RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
590 RNA_def_property_string_sdna(prop, NULL, "materialName");
591 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material");
592 RNA_def_property_update(prop, NC_LOGIC, NULL);
594 /*//XXX either use a datablock look up to store the string name (material)
595 // or to do a doversion and use a material pointer.
596 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
597 RNA_def_property_struct_type(prop, "Material");
598 RNA_def_property_flag(prop, PROP_EDITABLE);
599 RNA_def_property_pointer_sdna(prop, NULL, "ma");
600 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material");
604 static void rna_def_radar_sensor(BlenderRNA *brna)
608 static EnumPropertyItem axis_items[] ={
609 {SENS_RAY_X_AXIS, "XAXIS", 0, "+X axis", ""},
610 {SENS_RAY_Y_AXIS, "YAXIS", 0, "+Y axis", ""},
611 {SENS_RAY_Z_AXIS, "ZAXIS", 0, "+Z axis", ""},
612 {SENS_RAY_NEG_X_AXIS, "NEGXAXIS", 0, "-X axis", ""},
613 {SENS_RAY_NEG_Y_AXIS, "NEGYAXIS", 0, "-Y axis", ""},
614 {SENS_RAY_NEG_Z_AXIS, "NEGZAXIS", 0, "-Z axis", ""},
615 {0, NULL, 0, NULL, NULL}};
617 srna= RNA_def_struct(brna, "RadarSensor", "Sensor");
618 RNA_def_struct_ui_text(srna, "Radar Sensor", "Sensor to detect objects in a cone shaped radar emanating from the current object");
619 RNA_def_struct_sdna_from(srna, "bRadarSensor", "data");
621 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
622 RNA_def_property_string_sdna(prop, NULL, "name");
623 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property");
624 RNA_def_property_update(prop, NC_LOGIC, NULL);
626 prop= RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
627 RNA_def_property_enum_items(prop, axis_items);
628 RNA_def_property_ui_text(prop, "Axis", "Specify along which axis the radar cone is cast");
629 RNA_def_property_update(prop, NC_LOGIC, NULL);
631 prop= RNA_def_property(srna, "angle", PROP_FLOAT, PROP_NONE);
632 RNA_def_property_range(prop, 0.0, 179.9);
633 RNA_def_property_ui_text(prop, "Angle", "Opening angle of the radar cone");
634 RNA_def_property_update(prop, NC_LOGIC, NULL);
636 prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
637 RNA_def_property_float_sdna(prop, NULL, "range");
638 RNA_def_property_range(prop, 0.0, 10000.0);
639 RNA_def_property_ui_text(prop, "Distance", "Depth of the radar cone");
640 RNA_def_property_update(prop, NC_LOGIC, NULL);
643 static void rna_def_random_sensor(BlenderRNA *brna)
648 srna= RNA_def_struct(brna, "RandomSensor", "Sensor");
649 RNA_def_struct_ui_text(srna, "Random Sensor", "Sensor to send random events");
650 RNA_def_struct_sdna_from(srna, "bRandomSensor", "data");
652 prop= RNA_def_property(srna, "seed", PROP_INT, PROP_NONE);
653 RNA_def_property_range(prop, 0, 1000);
654 RNA_def_property_ui_text(prop, "Seed", "Initial seed of the generator. (Choose 0 for not random)");
655 RNA_def_property_update(prop, NC_LOGIC, NULL);
658 static void rna_def_ray_sensor(BlenderRNA *brna)
662 static EnumPropertyItem axis_items[] ={
663 {SENS_RAY_X_AXIS, "XAXIS", 0, "+X axis", ""},
664 {SENS_RAY_Y_AXIS, "YAXIS", 0, "+Y axis", ""},
665 {SENS_RAY_Z_AXIS, "ZAXIS", 0, "+Z axis", ""},
666 {SENS_RAY_NEG_X_AXIS, "NEGXAXIS", 0, "-X axis", ""},
667 {SENS_RAY_NEG_Y_AXIS, "NEGYAXIS", 0, "-Y axis", ""},
668 {SENS_RAY_NEG_Z_AXIS, "NEGZAXIS", 0, "-Z axis", ""},
669 {0, NULL, 0, NULL, NULL}};
671 static const EnumPropertyItem prop_ray_type_items[]= {
672 {SENS_COLLISION_PROPERTY, "PROPERTY", ICON_LOGIC, "Property", "Use a material for ray intersections"},
673 {SENS_COLLISION_MATERIAL, "MATERIAL", ICON_MATERIAL_DATA, "Material", "Use a property for ray intersections"},
674 {0, NULL, 0, NULL, NULL}};
676 srna= RNA_def_struct(brna, "RaySensor", "Sensor");
677 RNA_def_struct_ui_text(srna, "Ray Sensor", "Sensor to detect intersections with a ray emanating from the current object");
678 RNA_def_struct_sdna_from(srna, "bRaySensor", "data");
680 prop= RNA_def_property(srna, "ray_type", PROP_ENUM, PROP_NONE);
681 RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
682 RNA_def_property_enum_items(prop, prop_ray_type_items);
683 RNA_def_property_ui_text(prop, "Ray Type", "Toggle collision on material or property");
684 RNA_def_property_update(prop, NC_LOGIC, NULL);
686 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
687 RNA_def_property_string_sdna(prop, NULL, "propname");
688 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property");
689 RNA_def_property_update(prop, NC_LOGIC, NULL);
691 prop= RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
692 RNA_def_property_string_sdna(prop, NULL, "matname");
693 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material");
694 RNA_def_property_update(prop, NC_LOGIC, NULL);
696 /* //XXX either use a datablock look up to store the string name (material)
697 // or to do a doversion and use a material pointer.
698 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
699 RNA_def_property_struct_type(prop, "Material");
700 RNA_def_property_flag(prop, PROP_EDITABLE);
701 RNA_def_property_pointer_sdna(prop, NULL, "ma");
702 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material");
705 prop= RNA_def_property(srna, "use_x_ray", PROP_BOOLEAN, PROP_NONE);
706 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_RAY_XRAY);
707 RNA_def_property_ui_text(prop, "X-Ray Mode", "Toggle X-Ray option (see through objects that don't have the property)");
708 RNA_def_property_update(prop, NC_LOGIC, NULL);
710 prop= RNA_def_property(srna, "range", PROP_FLOAT, PROP_NONE);
711 RNA_def_property_range(prop, 0.01, 10000.0);
712 RNA_def_property_ui_text(prop, "Range", "Sense objects no farther than this distance");
713 RNA_def_property_update(prop, NC_LOGIC, NULL);
715 prop= RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
716 RNA_def_property_enum_sdna(prop, NULL, "axisflag");
717 RNA_def_property_enum_items(prop, axis_items);
718 RNA_def_property_ui_text(prop, "Axis", "Specify along which axis the ray is cast");
719 RNA_def_property_update(prop, NC_LOGIC, NULL);
722 static void rna_def_message_sensor(BlenderRNA *brna)
727 srna= RNA_def_struct(brna, "MessageSensor", "Sensor");
728 RNA_def_struct_ui_text(srna, "Message Sensor", "Sensor to detect incoming messages");
729 RNA_def_struct_sdna_from(srna, "bMessageSensor", "data");
731 prop= RNA_def_property(srna, "subject", PROP_STRING, PROP_NONE);
732 RNA_def_property_ui_text(prop, "Subject", "Optional subject filter: only accept messages with this subject, or empty for all");
733 RNA_def_property_update(prop, NC_LOGIC, NULL);
736 static void rna_def_joystick_sensor(BlenderRNA *brna)
741 static EnumPropertyItem event_type_items[] ={
742 {SENS_JOY_BUTTON, "BUTTON", 0, "Button", ""},
743 {SENS_JOY_AXIS, "AXIS", 0, "Axis", ""},
744 {SENS_JOY_HAT, "HAT", 0, "Hat", ""},
745 {SENS_JOY_AXIS_SINGLE, "AXIS_SINGLE", 0, "Single Axis", ""},
746 {0, NULL, 0, NULL, NULL}};
748 static EnumPropertyItem axis_direction_items[] ={
749 {SENS_JOY_X_AXIS, "RIGHTAXIS", 0, "Right Axis", ""},
750 {SENS_JOY_Y_AXIS, "UPAXIS", 0, "Up Axis", ""},
751 {SENS_JOY_NEG_X_AXIS, "LEFTAXIS", 0, "Left Axis", ""},
752 {SENS_JOY_NEG_Y_AXIS, "DOWNAXIS", 0, "Down Axis", ""},
753 {0, NULL, 0, NULL, NULL}};
755 static EnumPropertyItem hat_direction_items[] ={
756 {SENS_JOY_HAT_UP, "UP", 0, "Up", ""},
757 {SENS_JOY_HAT_DOWN, "DOWN", 0, "Down", ""},
758 {SENS_JOY_HAT_LEFT, "LEFT", 0, "Left", ""},
759 {SENS_JOY_HAT_RIGHT, "RIGHT", 0, "Right", ""},
761 {SENS_JOY_HAT_UP_RIGHT, "UPRIGHT", 0, "Up/Right", ""},
762 {SENS_JOY_HAT_DOWN_LEFT, "DOWNLEFT", 0, "Down/Left", ""},
763 {SENS_JOY_HAT_UP_LEFT, "UPLEFT", 0, "Up/Left", ""},
764 {SENS_JOY_HAT_DOWN_RIGHT, "DOWNRIGHT", 0, "Down/Right", ""},
765 {0, NULL, 0, NULL, NULL}};
767 srna= RNA_def_struct(brna, "JoystickSensor", "Sensor");
768 RNA_def_struct_ui_text(srna, "Joystick Sensor", "Sensor to detect joystick events");
769 RNA_def_struct_sdna_from(srna, "bJoystickSensor", "data");
771 prop= RNA_def_property(srna, "joystick_index", PROP_INT, PROP_NONE);
772 RNA_def_property_int_sdna(prop, NULL, "joyindex");
773 RNA_def_property_ui_text(prop, "Index", "Specify which joystick to use");
774 RNA_def_property_range(prop, 0, SENS_JOY_MAXINDEX-1);
775 RNA_def_property_update(prop, NC_LOGIC, NULL);
777 prop= RNA_def_property(srna, "event_type", PROP_ENUM, PROP_NONE);
778 RNA_def_property_enum_sdna(prop, NULL, "type");
779 RNA_def_property_enum_items(prop, event_type_items);
780 RNA_def_property_ui_text(prop, "Event Type", "The type of event this joystick sensor is triggered on");
781 RNA_def_property_update(prop, NC_LOGIC, NULL);
783 prop= RNA_def_property(srna, "use_all_events", PROP_BOOLEAN, PROP_NONE);
784 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_JOY_ANY_EVENT);
785 RNA_def_property_ui_text(prop, "All Events", "Triggered by all events on this joysticks current type (axis/button/hat)");
786 RNA_def_property_update(prop, NC_LOGIC, NULL);
789 prop= RNA_def_property(srna, "button_number", PROP_INT, PROP_NONE);
790 RNA_def_property_int_sdna(prop, NULL, "button");
791 RNA_def_property_ui_text(prop, "Button Number", "Specify which button to use");
792 RNA_def_property_range(prop, 0, 18);
793 RNA_def_property_update(prop, NC_LOGIC, NULL);
796 prop= RNA_def_property(srna, "axis_number", PROP_INT, PROP_NONE);
797 RNA_def_property_int_sdna(prop, NULL, "axis");
798 RNA_def_property_ui_text(prop, "Axis Number", "Specify which axis pair to use, 1 is usually the main direction input");
799 RNA_def_property_range(prop, 1, 2);
800 RNA_def_property_update(prop, NC_LOGIC, NULL);
802 prop= RNA_def_property(srna, "axis_threshold", PROP_INT, PROP_NONE);
803 RNA_def_property_int_sdna(prop, NULL, "precision");
804 RNA_def_property_ui_text(prop, "Axis Threshold", "Specify the precision of the axis");
805 RNA_def_property_range(prop, 0, 32768);
806 RNA_def_property_update(prop, NC_LOGIC, NULL);
808 prop= RNA_def_property(srna, "axis_direction", PROP_ENUM, PROP_NONE);
809 RNA_def_property_enum_sdna(prop, NULL, "axisf");
810 RNA_def_property_enum_items(prop, axis_direction_items);
811 RNA_def_property_ui_text(prop, "Axis Direction", "The direction of the axis");
812 RNA_def_property_update(prop, NC_LOGIC, NULL);
815 prop= RNA_def_property(srna, "single_axis_number", PROP_INT, PROP_NONE);
816 RNA_def_property_int_sdna(prop, NULL, "axis_single");
817 RNA_def_property_ui_text(prop, "Axis Number", "Specify a single axis (verticle/horizontal/other) to detect");
818 RNA_def_property_range(prop, 1, 16);
819 RNA_def_property_update(prop, NC_LOGIC, NULL);
822 prop= RNA_def_property(srna, "hat_number", PROP_INT, PROP_NONE);
823 RNA_def_property_int_sdna(prop, NULL, "hat");
824 RNA_def_property_ui_text(prop, "Hat Number", "Specify which hat to use");
825 RNA_def_property_range(prop, 1, 2);
826 RNA_def_property_update(prop, NC_LOGIC, NULL);
828 prop= RNA_def_property(srna, "hat_direction", PROP_ENUM, PROP_NONE);
829 RNA_def_property_enum_sdna(prop, NULL, "hatf");
830 RNA_def_property_enum_items(prop, hat_direction_items);
831 RNA_def_property_ui_text(prop, "Hat Direction", "Specify hat direction");
832 RNA_def_property_update(prop, NC_LOGIC, NULL);
835 void RNA_def_sensor(BlenderRNA *brna)
837 rna_def_sensor(brna);
839 rna_def_always_sensor(brna);
840 rna_def_near_sensor(brna);
841 rna_def_mouse_sensor(brna);
842 rna_def_touch_sensor(brna);
843 rna_def_keyboard_sensor(brna);
844 rna_def_property_sensor(brna);
845 rna_def_armature_sensor(brna);
846 rna_def_actuator_sensor(brna);
847 rna_def_delay_sensor(brna);
848 rna_def_collision_sensor(brna);
849 rna_def_radar_sensor(brna);
850 rna_def_random_sensor(brna);
851 rna_def_ray_sensor(brna);
852 rna_def_message_sensor(brna);
853 rna_def_joystick_sensor(brna);