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"
29 #include "RNA_access.h"
31 #include "rna_internal.h"
33 #include "DNA_constraint_types.h"
34 #include "DNA_object_types.h"
35 #include "DNA_sensor_types.h"
39 /* Always keep in alphabetical order */
40 EnumPropertyItem sensor_type_items[] ={
41 {SENS_ACTUATOR, "ACTUATOR", 0, "Actuator", ""},
42 {SENS_ALWAYS, "ALWAYS", 0, "Always", ""},
43 {SENS_ARMATURE, "ARMATURE", 0, "Armature", ""},
44 {SENS_COLLISION, "COLLISION", 0, "Collision", ""},
45 {SENS_DELAY, "DELAY", 0, "Delay", ""},
46 {SENS_JOYSTICK, "JOYSTICK", 0, "Joystick", ""},
47 {SENS_KEYBOARD, "KEYBOARD", 0, "Keyboard", ""},
48 {SENS_MESSAGE, "MESSAGE", 0, "Message", ""},
49 {SENS_MOUSE, "MOUSE", 0, "Mouse", ""},
50 {SENS_NEAR, "NEAR", 0, "Near", ""},
51 {SENS_PROPERTY, "PROPERTY", 0, "Property", ""},
52 {SENS_RADAR, "RADAR", 0, "Radar", ""},
53 {SENS_RANDOM, "RANDOM", 0, "Random", ""},
54 {SENS_RAY, "RAY", 0, "Ray", ""},
55 {SENS_TOUCH, "TOUCH", 0, "Touch", ""},
56 {0, NULL, 0, NULL, NULL}};
62 static StructRNA* rna_Sensor_refine(struct PointerRNA *ptr)
64 bSensor *sensor= (bSensor*)ptr->data;
66 switch(sensor->type) {
68 return &RNA_AlwaysSensor;
70 return &RNA_TouchSensor;
72 return &RNA_NearSensor;
74 return &RNA_KeyboardSensor;
76 return &RNA_PropertySensor;
78 return &RNA_ArmatureSensor;
80 return &RNA_MouseSensor;
82 return &RNA_CollisionSensor;
84 return &RNA_RadarSensor;
86 return &RNA_RandomSensor;
88 return &RNA_RaySensor;
90 return &RNA_MessageSensor;
92 return &RNA_JoystickSensor;
94 return &RNA_ActuatorSensor;
96 return &RNA_DelaySensor;
102 static void rna_Sensor_type_set(struct PointerRNA *ptr, int value)
104 bSensor *sens= (bSensor *)ptr->data;
105 if (value != sens->type)
112 /* Always keep in alphabetical order */
113 EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, int *free)
115 EnumPropertyItem *item= NULL;
119 if (ptr->type == &RNA_Sensor || RNA_struct_is_a(ptr->type, &RNA_Sensor)) {
120 ob = (Object *)ptr->id.data;
122 /* can't use ob from ptr->id.data because that enum is also used by operators */
123 ob = CTX_data_active_object(C);
126 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ACTUATOR);
127 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ALWAYS);
130 if (ob->type==OB_ARMATURE) {
131 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ARMATURE);
134 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_COLLISION);
135 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_DELAY);
136 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_JOYSTICK);
137 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_KEYBOARD);
138 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MESSAGE);
139 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MOUSE);
140 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_NEAR);
141 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_PROPERTY);
142 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RADAR);
143 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RANDOM);
144 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RAY);
145 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_TOUCH);
147 RNA_enum_item_end(&item, &totitem);
153 static void rna_Sensor_keyboard_key_set(struct PointerRNA *ptr, int value)
155 bSensor *sens= (bSensor *)ptr->data;
156 bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
158 if (ISKEYBOARD(value))
164 static void rna_Sensor_keyboard_modifier_set(struct PointerRNA *ptr, int value)
166 bSensor *sens= (bSensor *)ptr->data;
167 bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
169 if (ISKEYBOARD(value))
175 static void rna_Sensor_keyboard_modifier2_set(struct PointerRNA *ptr, int value)
177 bSensor *sens= (bSensor *)ptr->data;
178 bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
180 if (ISKEYBOARD(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 */
238 /* note: the following set functions exists only to avoid id refcounting */
239 static void rna_Sensor_touch_material_set(PointerRNA *ptr, PointerRNA value)
241 bSensor *sens = (bSensor *)ptr->data;
242 bTouchSensor *ts = (bTouchSensor *) sens->data;
248 static void rna_def_sensor(BlenderRNA *brna)
253 srna= RNA_def_struct(brna, "Sensor", NULL);
254 RNA_def_struct_ui_text(srna, "Sensor", "Game engine logic brick to detect events");
255 RNA_def_struct_sdna(srna, "bSensor");
256 RNA_def_struct_refine_func(srna, "rna_Sensor_refine");
258 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
259 RNA_def_property_ui_text(prop, "Name", "Sensor name");
260 RNA_def_struct_name_property(srna, prop);
261 RNA_def_property_update(prop, NC_LOGIC, NULL);
263 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
264 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
265 RNA_def_property_enum_items(prop, sensor_type_items);
266 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_type_set", "rna_Sensor_type_itemf");
267 RNA_def_property_ui_text(prop, "Type", "");
268 RNA_def_property_update(prop, NC_LOGIC, NULL);
270 prop= RNA_def_property(srna, "pin", PROP_BOOLEAN, PROP_NONE);
271 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_PIN);
272 RNA_def_property_ui_text(prop, "Pinned", "Display when not linked to a visible states controller");
273 RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
274 RNA_def_property_update(prop, NC_LOGIC, NULL);
276 prop= RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
277 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_SHOW);
278 RNA_def_property_ui_text(prop, "Expanded", "Set sensor expanded in the user interface");
279 RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
280 RNA_def_property_update(prop, NC_LOGIC, NULL);
282 prop= RNA_def_property(srna, "invert", PROP_BOOLEAN, PROP_NONE);
283 RNA_def_property_ui_text(prop, "Invert Output", "Invert the level(output) of this sensor");
284 RNA_def_property_update(prop, NC_LOGIC, NULL);
286 prop= RNA_def_property(srna, "use_level", PROP_BOOLEAN, PROP_NONE);
287 RNA_def_property_boolean_sdna(prop, NULL, "level", 1);
288 RNA_def_property_ui_text(prop, "Level", "Level detector, trigger controllers of new states(only applicable upon logic state transition)");
289 RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_level_set");
290 RNA_def_property_update(prop, NC_LOGIC, NULL);
292 prop= RNA_def_property(srna, "use_pulse_true_level", PROP_BOOLEAN, PROP_NONE);
293 RNA_def_property_boolean_sdna(prop, NULL, "pulse", SENS_PULSE_REPEAT);
294 RNA_def_property_ui_text(prop, "Pulse True Level", "Activate TRUE level triggering (pulse mode)");
295 RNA_def_property_update(prop, NC_LOGIC, NULL);
297 prop= RNA_def_property(srna, "use_pulse_false_level", PROP_BOOLEAN, PROP_NONE);
298 RNA_def_property_boolean_sdna(prop, NULL, "pulse", SENS_NEG_PULSE_MODE);
299 RNA_def_property_ui_text(prop, "Pulse False Level", "Activate FALSE level triggering (pulse mode)");
300 RNA_def_property_update(prop, NC_LOGIC, NULL);
302 prop= RNA_def_property(srna, "frequency", PROP_INT, PROP_NONE);
303 RNA_def_property_int_sdna(prop, NULL, "freq");
304 RNA_def_property_ui_text(prop, "Frequency", "Delay between repeated pulses(in logic tics, 0=no delay)");
305 RNA_def_property_range(prop, 0, 10000);
306 RNA_def_property_update(prop, NC_LOGIC, NULL);
308 prop= RNA_def_property(srna, "use_tap", PROP_BOOLEAN, PROP_NONE);
309 RNA_def_property_boolean_sdna(prop, NULL, "tap", 1);
310 RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_tap_set");
311 RNA_def_property_ui_text(prop, "Tap", "Trigger controllers only for an instant, even while the sensor remains true");
312 RNA_def_property_update(prop, NC_LOGIC, NULL);
314 RNA_api_sensor(srna);
317 static void rna_def_always_sensor(BlenderRNA *brna)
320 srna= RNA_def_struct(brna, "AlwaysSensor", "Sensor");
321 RNA_def_struct_ui_text(srna, "Always Sensor", "Sensor to generate continuous pulses");
324 static void rna_def_near_sensor(BlenderRNA *brna)
329 srna= RNA_def_struct(brna, "NearSensor", "Sensor");
330 RNA_def_struct_ui_text(srna , "Near Sensor", "Sensor to detect nearby objects");
331 RNA_def_struct_sdna_from(srna, "bNearSensor", "data");
333 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
334 RNA_def_property_string_sdna(prop, NULL, "name");
335 RNA_def_property_ui_text(prop, "Property", "Only look for objects with this property (blank = all objects)");
336 RNA_def_property_update(prop, NC_LOGIC, NULL);
338 prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
339 RNA_def_property_float_sdna(prop, NULL, "dist");
340 RNA_def_property_ui_text(prop, "Distance", "Trigger distance");
341 RNA_def_property_range(prop, 0.0f, 10000.0f);
342 RNA_def_property_update(prop, NC_LOGIC, NULL);
344 prop= RNA_def_property(srna, "reset_distance", PROP_FLOAT, PROP_NONE);
345 RNA_def_property_float_sdna(prop, NULL, "resetdist");
346 RNA_def_property_ui_text(prop, "Reset Distance", "The distance where the sensor forgets the actor");
347 RNA_def_property_range(prop, 0.0f, 10000.0f);
348 RNA_def_property_update(prop, NC_LOGIC, NULL);
351 static void rna_def_mouse_sensor(BlenderRNA *brna)
356 static EnumPropertyItem mouse_event_items[] ={
357 {BL_SENS_MOUSE_LEFT_BUTTON, "LEFTCLICK", 0, "Left Button", ""},
358 {BL_SENS_MOUSE_MIDDLE_BUTTON, "MIDDLECLICK", 0, "Middle Button", ""},
359 {BL_SENS_MOUSE_RIGHT_BUTTON, "RIGHTCLICK", 0, "Right Button", ""},
360 {BL_SENS_MOUSE_WHEEL_UP, "WHEELUP", 0, "Wheel Up", ""},
361 {BL_SENS_MOUSE_WHEEL_DOWN, "WHEELDOWN", 0, "Wheel Down", ""},
362 {BL_SENS_MOUSE_MOVEMENT, "MOVEMENT", 0, "Movement", ""},
363 {BL_SENS_MOUSE_MOUSEOVER, "MOUSEOVER", 0, "Mouse Over", ""},
364 {BL_SENS_MOUSE_MOUSEOVER_ANY, "MOUSEOVERANY", 0, "Mouse Over Any", ""},
365 {0, NULL, 0, NULL, NULL}};
367 srna= RNA_def_struct(brna, "MouseSensor", "Sensor");
368 RNA_def_struct_ui_text(srna, "Mouse Sensor", "Sensor to detect mouse events");
369 RNA_def_struct_sdna_from(srna, "bMouseSensor", "data");
371 prop= RNA_def_property(srna, "mouse_event", PROP_ENUM, PROP_NONE);
372 RNA_def_property_enum_sdna(prop, NULL, "type");
373 RNA_def_property_enum_items(prop, mouse_event_items);
374 RNA_def_property_ui_text(prop, "Mouse Event", "Specify the type of event this mouse sensor should trigger on");
375 RNA_def_property_update(prop, NC_LOGIC, NULL);
378 static void rna_def_touch_sensor(BlenderRNA *brna)
383 srna= RNA_def_struct(brna, "TouchSensor", "Sensor");
384 RNA_def_struct_ui_text(srna, "Touch Sensor", "Sensor to detect objects colliding with the current object");
385 RNA_def_struct_sdna_from(srna, "bTouchSensor", "data");
387 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
388 RNA_def_property_struct_type(prop, "Material");
389 RNA_def_property_pointer_sdna(prop, NULL, "ma");
390 RNA_def_property_flag(prop, PROP_EDITABLE);
391 RNA_def_property_ui_text(prop, "Material", "Only look for objects with this material (blank = all objects)");
392 /* note: custom set function is ONLY to avoid rna setting a user for this. */
393 RNA_def_property_pointer_funcs(prop, NULL, "rna_Sensor_touch_material_set", NULL, NULL);
394 RNA_def_property_update(prop, NC_LOGIC, NULL);
397 static void rna_def_keyboard_sensor(BlenderRNA *brna)
402 srna= RNA_def_struct(brna, "KeyboardSensor", "Sensor");
403 RNA_def_struct_ui_text(srna, "Keyboard Sensor", "Sensor to detect keyboard events");
404 RNA_def_struct_sdna_from(srna, "bKeyboardSensor", "data");
406 prop= RNA_def_property(srna, "key", PROP_ENUM, PROP_NONE);
407 RNA_def_property_enum_sdna(prop, NULL, "key");
408 RNA_def_property_enum_items(prop, event_type_items);
409 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_key_set", NULL);
410 RNA_def_property_ui_text(prop, "Key", "");
411 RNA_def_property_update(prop, NC_LOGIC, NULL);
413 prop= RNA_def_property(srna, "modifier_key_1", PROP_ENUM, PROP_NONE);
414 RNA_def_property_enum_sdna(prop, NULL, "qual");
415 RNA_def_property_enum_items(prop, event_type_items);
416 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier_set", NULL);
417 RNA_def_property_ui_text(prop, "Modifier Key", "Modifier key code");
418 RNA_def_property_update(prop, NC_LOGIC, NULL);
420 prop= RNA_def_property(srna, "modifier_key_2", PROP_ENUM, PROP_NONE);
421 RNA_def_property_enum_sdna(prop, NULL, "qual2");
422 RNA_def_property_enum_items(prop, event_type_items);
423 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier2_set", NULL);
424 RNA_def_property_ui_text(prop, "Second Modifier Key", "Modifier key code");
425 RNA_def_property_update(prop, NC_LOGIC, NULL);
427 prop= RNA_def_property(srna, "target", PROP_STRING, PROP_NONE);
428 RNA_def_property_string_sdna(prop, NULL, "targetName");
429 RNA_def_property_ui_text(prop, "Target", "Property that receive the keystrokes in case a string is logged");
430 RNA_def_property_update(prop, NC_LOGIC, NULL);
432 prop= RNA_def_property(srna, "log", PROP_STRING, PROP_NONE);
433 RNA_def_property_string_sdna(prop, NULL, "toggleName");
434 RNA_def_property_ui_text(prop, "Log Toggle", "Property that indicates whether to log keystrokes as a string");
435 RNA_def_property_update(prop, NC_LOGIC, NULL);
437 prop= RNA_def_property(srna, "use_all_keys", PROP_BOOLEAN, PROP_NONE);
438 RNA_def_property_boolean_sdna(prop, NULL, "type", 1);
439 RNA_def_property_ui_text(prop, "All Keys", "Trigger this sensor on any keystroke");
440 RNA_def_property_update(prop, NC_LOGIC, NULL);
443 static void rna_def_property_sensor(BlenderRNA *brna)
447 static EnumPropertyItem prop_type_items[] ={
448 {SENS_PROP_EQUAL, "PROPEQUAL", 0, "Equal", ""},
449 {SENS_PROP_NEQUAL, "PROPNEQUAL", 0, "Not Equal", ""},
450 {SENS_PROP_INTERVAL, "PROPINTERVAL", 0, "Interval", ""},
451 {SENS_PROP_CHANGED, "PROPCHANGED", 0, "Changed", ""},
452 /* {SENS_PROP_EXPRESSION, "PROPEXPRESSION", 0, "Expression", ""}, NOT_USED_IN_UI */
453 {0, NULL, 0, NULL, NULL}};
455 srna= RNA_def_struct(brna, "PropertySensor", "Sensor");
456 RNA_def_struct_ui_text(srna, "Property Sensor", "Sensor to detect values and changes in values of properties");
457 RNA_def_struct_sdna_from(srna, "bPropertySensor", "data");
459 prop= RNA_def_property(srna, "evaluation_type", PROP_ENUM, PROP_NONE);
460 RNA_def_property_enum_sdna(prop, NULL, "type");
461 RNA_def_property_enum_items(prop, prop_type_items);
462 RNA_def_property_ui_text(prop, "Evaluation Type", "Type of property evaluation");
463 RNA_def_property_update(prop, NC_LOGIC, NULL);
465 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
466 RNA_def_property_string_sdna(prop, NULL, "name");
467 RNA_def_property_ui_text(prop, "Property", "");
468 RNA_def_property_update(prop, NC_LOGIC, NULL);
470 prop= RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
471 RNA_def_property_string_sdna(prop, NULL, "value");
472 RNA_def_property_ui_text(prop, "Value", "Check for this value in types in Equal or Not Equal types");
473 RNA_def_property_update(prop, NC_LOGIC, NULL);
475 prop= RNA_def_property(srna, "value_min", PROP_STRING, PROP_NONE);
476 RNA_def_property_string_sdna(prop, NULL, "value");
477 RNA_def_property_ui_text(prop, "Minimum Value", "Specify minimum value in Interval type");
478 RNA_def_property_update(prop, NC_LOGIC, NULL);
480 prop= RNA_def_property(srna, "value_max", PROP_STRING, PROP_NONE);
481 RNA_def_property_string_sdna(prop, NULL, "maxvalue");
482 RNA_def_property_ui_text(prop, "Maximum Value", "Specify maximum value in Interval type");
483 RNA_def_property_update(prop, NC_LOGIC, NULL);
486 static void rna_def_armature_sensor(BlenderRNA *brna)
490 static EnumPropertyItem prop_type_items[] ={
491 {SENS_ARM_STATE_CHANGED, "STATECHG", 0, "State Changed", ""},
492 {SENS_ARM_LIN_ERROR_BELOW, "LINERRORBELOW", 0, "Lin error below", ""},
493 {SENS_ARM_LIN_ERROR_ABOVE, "LINERRORABOVE", 0, "Lin error above", ""},
494 {SENS_ARM_ROT_ERROR_BELOW, "ROTERRORBELOW", 0, "Rot error below", ""},
495 {SENS_ARM_ROT_ERROR_ABOVE, "ROTERRORABOVE", 0, "Rot error above", ""},
496 {0, NULL, 0, NULL, NULL}};
498 srna= RNA_def_struct(brna, "ArmatureSensor", "Sensor");
499 RNA_def_struct_ui_text(srna, "Armature Sensor", "Sensor to detect values and changes in values of IK solver");
500 RNA_def_struct_sdna_from(srna, "bArmatureSensor", "data");
502 prop= RNA_def_property(srna, "test_type", PROP_ENUM, PROP_NONE);
503 RNA_def_property_enum_sdna(prop, NULL, "type");
504 RNA_def_property_enum_items(prop, prop_type_items);
505 RNA_def_property_ui_text(prop, "Test", "Type of value and test");
506 RNA_def_property_update(prop, NC_LOGIC, NULL);
508 prop= RNA_def_property(srna, "bone", PROP_STRING, PROP_NONE);
509 RNA_def_property_string_sdna(prop, NULL, "posechannel");
510 RNA_def_property_ui_text(prop, "Bone Name", "Identify the bone to check value from");
511 RNA_def_property_update(prop, NC_LOGIC, "rna_Sensor_Armature_update");
513 prop= RNA_def_property(srna, "constraint", PROP_STRING, PROP_NONE);
514 RNA_def_property_string_sdna(prop, NULL, "constraint");
515 RNA_def_property_ui_text(prop, "Constraint Name", "Identify the bone constraint to check value from");
516 RNA_def_property_update(prop, NC_LOGIC, "rna_Sensor_Armature_update");
518 prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
519 RNA_def_property_float_sdna(prop, NULL, "value");
520 RNA_def_property_ui_text(prop, "Compare Value", "Specify value to be used in comparison");
521 RNA_def_property_update(prop, NC_LOGIC, NULL);
524 static void rna_def_actuator_sensor(BlenderRNA *brna)
529 srna= RNA_def_struct(brna, "ActuatorSensor", "Sensor");
530 RNA_def_struct_ui_text(srna, "Actuator Sensor", "Sensor to detect state modifications of actuators");
531 RNA_def_struct_sdna_from(srna, "bActuatorSensor", "data");
533 // XXX if eventually have Logics using RNA 100%, we could use the actuator datablock isntead of its name
534 prop= RNA_def_property(srna, "actuator", PROP_STRING, PROP_NONE);
535 RNA_def_property_string_sdna(prop, NULL, "name");
536 RNA_def_property_ui_text(prop, "Actuator", "Actuator name, actuator active state modifications will be detected");
537 RNA_def_property_update(prop, NC_LOGIC, NULL);
540 static void rna_def_delay_sensor(BlenderRNA *brna)
545 srna= RNA_def_struct(brna, "DelaySensor", "Sensor");
546 RNA_def_struct_ui_text(srna, "Delay Sensor", "Sensor to send delayed events");
547 RNA_def_struct_sdna_from(srna, "bDelaySensor", "data");
549 prop= RNA_def_property(srna, "delay", PROP_INT, PROP_NONE);
550 RNA_def_property_ui_text(prop, "Delay", "Delay in number of logic tics before the positive trigger (default 60 per second)");
551 RNA_def_property_range(prop, 0, 5000);
552 RNA_def_property_update(prop, NC_LOGIC, NULL);
554 prop= RNA_def_property(srna, "duration", PROP_INT, PROP_NONE);
555 RNA_def_property_ui_text(prop, "Duration", "If >0, delay in number of logic tics before the negative trigger following the positive trigger");
556 RNA_def_property_range(prop, 0, 5000);
557 RNA_def_property_update(prop, NC_LOGIC, NULL);
559 prop= RNA_def_property(srna, "use_repeat", PROP_BOOLEAN, PROP_NONE);
560 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_DELAY_REPEAT);
561 RNA_def_property_ui_text(prop, "Repeat", "Toggle repeat option. If selected, the sensor restarts after Delay+Dur logic tics");
562 RNA_def_property_update(prop, NC_LOGIC, NULL);
565 static void rna_def_collision_sensor(BlenderRNA *brna)
570 srna= RNA_def_struct(brna, "CollisionSensor", "Sensor");
571 RNA_def_struct_ui_text(srna, "Collision Sensor", "Sensor to detect objects colliding with the current object, with more settings than the Touch sensor");
572 RNA_def_struct_sdna_from(srna, "bCollisionSensor", "data");
574 prop= RNA_def_property(srna, "use_pulse", PROP_BOOLEAN, PROP_NONE);
575 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_COLLISION_PULSE);
576 RNA_def_property_ui_text(prop, "Pulse", "Changes to the set of colliding objects generates pulse");
577 RNA_def_property_update(prop, NC_LOGIC, NULL);
579 prop= RNA_def_property(srna, "use_material", PROP_BOOLEAN, PROP_NONE);
580 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_COLLISION_MATERIAL);
581 RNA_def_property_ui_text(prop, "M/P", "Toggle collision on material or property");
582 RNA_def_property_update(prop, NC_LOGIC, NULL);
584 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
585 RNA_def_property_string_sdna(prop, NULL, "name");
586 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property (blank = all objects)");
587 RNA_def_property_update(prop, NC_LOGIC, NULL);
589 //XXX to make a setFunction to create a lookup with all materials in Blend File (not only this object mat.)
590 prop= RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
591 RNA_def_property_string_sdna(prop, NULL, "materialName");
592 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material (blank = all objects)");
593 RNA_def_property_update(prop, NC_LOGIC, NULL);
595 /*//XXX either use a datablock look up to store the string name (material)
596 // or to do a doversion and use a material pointer.
597 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
598 RNA_def_property_struct_type(prop, "Material");
599 RNA_def_property_flag(prop, PROP_EDITABLE);
600 RNA_def_property_pointer_sdna(prop, NULL, "ma");
601 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material (blank = all objects)");
605 static void rna_def_radar_sensor(BlenderRNA *brna)
609 static EnumPropertyItem axis_items[] ={
610 {SENS_RADAR_X_AXIS, "XAXIS", 0, "+X axis", ""},
611 {SENS_RADAR_Y_AXIS, "YAXIS", 0, "+Y axis", ""},
612 {SENS_RADAR_Z_AXIS, "ZAXIS", 0, "+Z axis", ""},
613 {SENS_RADAR_NEG_X_AXIS, "NEGXAXIS", 0, "-X axis", ""},
614 {SENS_RADAR_NEG_Y_AXIS, "NEGYAXIS", 0, "-Y axis", ""},
615 {SENS_RADAR_NEG_Z_AXIS, "NEGZAXIS", 0, "-Z axis", ""},
616 {0, NULL, 0, NULL, NULL}};
618 srna= RNA_def_struct(brna, "RadarSensor", "Sensor");
619 RNA_def_struct_ui_text(srna, "Radar Sensor", "Sensor to detect objects in a cone shaped radar emanating from the current object");
620 RNA_def_struct_sdna_from(srna, "bRadarSensor", "data");
622 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
623 RNA_def_property_string_sdna(prop, NULL, "name");
624 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property (blank = all objects)");
625 RNA_def_property_update(prop, NC_LOGIC, NULL);
627 prop= RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
628 RNA_def_property_enum_items(prop, axis_items);
629 RNA_def_property_ui_text(prop, "Axis", "Specify along which axis the radar cone is cast");
630 RNA_def_property_update(prop, NC_LOGIC, NULL);
632 prop= RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE);
633 RNA_def_property_range(prop, 0.0, 179.9);
634 RNA_def_property_ui_text(prop, "Angle", "Opening angle of the radar cone");
635 RNA_def_property_update(prop, NC_LOGIC, NULL);
637 prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
638 RNA_def_property_float_sdna(prop, NULL, "range");
639 RNA_def_property_range(prop, 0.0, 10000.0);
640 RNA_def_property_ui_text(prop, "Distance", "Depth of the radar cone");
641 RNA_def_property_update(prop, NC_LOGIC, NULL);
644 static void rna_def_random_sensor(BlenderRNA *brna)
649 srna= RNA_def_struct(brna, "RandomSensor", "Sensor");
650 RNA_def_struct_ui_text(srna, "Random Sensor", "Sensor to send random events");
651 RNA_def_struct_sdna_from(srna, "bRandomSensor", "data");
653 prop= RNA_def_property(srna, "seed", PROP_INT, PROP_NONE);
654 RNA_def_property_range(prop, 0, 1000);
655 RNA_def_property_ui_text(prop, "Seed", "Initial seed of the generator. (Choose 0 for not random)");
656 RNA_def_property_update(prop, NC_LOGIC, NULL);
659 static void rna_def_ray_sensor(BlenderRNA *brna)
663 static EnumPropertyItem axis_items[] ={
664 {SENS_RAY_X_AXIS, "XAXIS", 0, "+X axis", ""},
665 {SENS_RAY_Y_AXIS, "YAXIS", 0, "+Y axis", ""},
666 {SENS_RAY_Z_AXIS, "ZAXIS", 0, "+Z axis", ""},
667 {SENS_RAY_NEG_X_AXIS, "NEGXAXIS", 0, "-X axis", ""},
668 {SENS_RAY_NEG_Y_AXIS, "NEGYAXIS", 0, "-Y axis", ""},
669 {SENS_RAY_NEG_Z_AXIS, "NEGZAXIS", 0, "-Z axis", ""},
670 {0, NULL, 0, NULL, NULL}};
672 static const EnumPropertyItem prop_ray_type_items[]= {
673 {SENS_COLLISION_PROPERTY, "PROPERTY", ICON_LOGIC, "Property", "Use a material for ray intersections"},
674 {SENS_COLLISION_MATERIAL, "MATERIAL", ICON_MATERIAL_DATA, "Material", "Use a property for ray intersections"},
675 {0, NULL, 0, NULL, NULL}};
677 srna= RNA_def_struct(brna, "RaySensor", "Sensor");
678 RNA_def_struct_ui_text(srna, "Ray Sensor", "Sensor to detect intersections with a ray emanating from the current object");
679 RNA_def_struct_sdna_from(srna, "bRaySensor", "data");
681 prop= RNA_def_property(srna, "ray_type", PROP_ENUM, PROP_NONE);
682 RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
683 RNA_def_property_enum_items(prop, prop_ray_type_items);
684 RNA_def_property_ui_text(prop, "Ray Type", "Toggle collision on material or property");
685 RNA_def_property_update(prop, NC_LOGIC, NULL);
687 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
688 RNA_def_property_string_sdna(prop, NULL, "propname");
689 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property (blank = all objects)");
690 RNA_def_property_update(prop, NC_LOGIC, NULL);
692 prop= RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
693 RNA_def_property_string_sdna(prop, NULL, "matname");
694 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material (blank = all objects)");
695 RNA_def_property_update(prop, NC_LOGIC, NULL);
697 /* //XXX either use a datablock look up to store the string name (material)
698 // or to do a doversion and use a material pointer.
699 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
700 RNA_def_property_struct_type(prop, "Material");
701 RNA_def_property_flag(prop, PROP_EDITABLE);
702 RNA_def_property_pointer_sdna(prop, NULL, "ma");
703 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material (blank = all objects)");
706 prop= RNA_def_property(srna, "use_x_ray", PROP_BOOLEAN, PROP_NONE);
707 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_RAY_XRAY);
708 RNA_def_property_ui_text(prop, "X-Ray Mode", "Toggle X-Ray option (see through objects that don't have the property)");
709 RNA_def_property_update(prop, NC_LOGIC, NULL);
711 prop= RNA_def_property(srna, "range", PROP_FLOAT, PROP_NONE);
712 RNA_def_property_range(prop, 0.01, 10000.0);
713 RNA_def_property_ui_text(prop, "Range", "Sense objects no farther than this distance");
714 RNA_def_property_update(prop, NC_LOGIC, NULL);
716 prop= RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
717 RNA_def_property_enum_sdna(prop, NULL, "axisflag");
718 RNA_def_property_enum_items(prop, axis_items);
719 RNA_def_property_ui_text(prop, "Axis", "Specify along which axis the ray is cast");
720 RNA_def_property_update(prop, NC_LOGIC, NULL);
723 static void rna_def_message_sensor(BlenderRNA *brna)
728 srna= RNA_def_struct(brna, "MessageSensor", "Sensor");
729 RNA_def_struct_ui_text(srna, "Message Sensor", "Sensor to detect incoming messages");
730 RNA_def_struct_sdna_from(srna, "bMessageSensor", "data");
732 prop= RNA_def_property(srna, "subject", PROP_STRING, PROP_NONE);
733 RNA_def_property_ui_text(prop, "Subject", "Optional subject filter: only accept messages with this subject, or empty for all");
734 RNA_def_property_update(prop, NC_LOGIC, NULL);
737 static void rna_def_joystick_sensor(BlenderRNA *brna)
742 static EnumPropertyItem event_type_items[] ={
743 {SENS_JOY_BUTTON, "BUTTON", 0, "Button", ""},
744 {SENS_JOY_AXIS, "AXIS", 0, "Axis", ""},
745 {SENS_JOY_HAT, "HAT", 0, "Hat", ""},
746 {SENS_JOY_AXIS_SINGLE, "AXIS_SINGLE", 0, "Single Axis", ""},
747 {0, NULL, 0, NULL, NULL}};
749 static EnumPropertyItem axis_direction_items[] ={
750 {SENS_JOY_X_AXIS, "RIGHTAXIS", 0, "Right Axis", ""},
751 {SENS_JOY_Y_AXIS, "UPAXIS", 0, "Up Axis", ""},
752 {SENS_JOY_NEG_X_AXIS, "LEFTAXIS", 0, "Left Axis", ""},
753 {SENS_JOY_NEG_Y_AXIS, "DOWNAXIS", 0, "Down Axis", ""},
754 {0, NULL, 0, NULL, NULL}};
756 static EnumPropertyItem hat_direction_items[] ={
757 {SENS_JOY_HAT_UP, "UP", 0, "Up", ""},
758 {SENS_JOY_HAT_DOWN, "DOWN", 0, "Down", ""},
759 {SENS_JOY_HAT_LEFT, "LEFT", 0, "Left", ""},
760 {SENS_JOY_HAT_RIGHT, "RIGHT", 0, "Right", ""},
762 {SENS_JOY_HAT_UP_RIGHT, "UPRIGHT", 0, "Up/Right", ""},
763 {SENS_JOY_HAT_DOWN_LEFT, "DOWNLEFT", 0, "Down/Left", ""},
764 {SENS_JOY_HAT_UP_LEFT, "UPLEFT", 0, "Up/Left", ""},
765 {SENS_JOY_HAT_DOWN_RIGHT, "DOWNRIGHT", 0, "Down/Right", ""},
766 {0, NULL, 0, NULL, NULL}};
768 srna= RNA_def_struct(brna, "JoystickSensor", "Sensor");
769 RNA_def_struct_ui_text(srna, "Joystick Sensor", "Sensor to detect joystick events");
770 RNA_def_struct_sdna_from(srna, "bJoystickSensor", "data");
772 prop= RNA_def_property(srna, "joystick_index", PROP_INT, PROP_NONE);
773 RNA_def_property_int_sdna(prop, NULL, "joyindex");
774 RNA_def_property_ui_text(prop, "Index", "Specify which joystick to use");
775 RNA_def_property_range(prop, 0, SENS_JOY_MAXINDEX-1);
776 RNA_def_property_update(prop, NC_LOGIC, NULL);
778 prop= RNA_def_property(srna, "event_type", PROP_ENUM, PROP_NONE);
779 RNA_def_property_enum_sdna(prop, NULL, "type");
780 RNA_def_property_enum_items(prop, event_type_items);
781 RNA_def_property_ui_text(prop, "Event Type", "The type of event this joystick sensor is triggered on");
782 RNA_def_property_update(prop, NC_LOGIC, NULL);
784 prop= RNA_def_property(srna, "use_all_events", PROP_BOOLEAN, PROP_NONE);
785 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_JOY_ANY_EVENT);
786 RNA_def_property_ui_text(prop, "All Events", "Triggered by all events on this joysticks current type (axis/button/hat)");
787 RNA_def_property_update(prop, NC_LOGIC, NULL);
790 prop= RNA_def_property(srna, "button_number", PROP_INT, PROP_NONE);
791 RNA_def_property_int_sdna(prop, NULL, "button");
792 RNA_def_property_ui_text(prop, "Button Number", "Specify which button to use");
793 RNA_def_property_range(prop, 0, 18);
794 RNA_def_property_update(prop, NC_LOGIC, NULL);
797 prop= RNA_def_property(srna, "axis_number", PROP_INT, PROP_NONE);
798 RNA_def_property_int_sdna(prop, NULL, "axis");
799 RNA_def_property_ui_text(prop, "Axis Number", "Specify which axis pair to use, 1 is usually the main direction input");
800 RNA_def_property_range(prop, 1, 2);
801 RNA_def_property_update(prop, NC_LOGIC, NULL);
803 prop= RNA_def_property(srna, "axis_threshold", PROP_INT, PROP_NONE);
804 RNA_def_property_int_sdna(prop, NULL, "precision");
805 RNA_def_property_ui_text(prop, "Axis Threshold", "Specify the precision of the axis");
806 RNA_def_property_range(prop, 0, 32768);
807 RNA_def_property_update(prop, NC_LOGIC, NULL);
809 prop= RNA_def_property(srna, "axis_direction", PROP_ENUM, PROP_NONE);
810 RNA_def_property_enum_sdna(prop, NULL, "axisf");
811 RNA_def_property_enum_items(prop, axis_direction_items);
812 RNA_def_property_ui_text(prop, "Axis Direction", "The direction of the axis");
813 RNA_def_property_update(prop, NC_LOGIC, NULL);
816 prop= RNA_def_property(srna, "single_axis_number", PROP_INT, PROP_NONE);
817 RNA_def_property_int_sdna(prop, NULL, "axis_single");
818 RNA_def_property_ui_text(prop, "Axis Number", "Specify a single axis (verticle/horizontal/other) to detect");
819 RNA_def_property_range(prop, 1, 16);
820 RNA_def_property_update(prop, NC_LOGIC, NULL);
823 prop= RNA_def_property(srna, "hat_number", PROP_INT, PROP_NONE);
824 RNA_def_property_int_sdna(prop, NULL, "hat");
825 RNA_def_property_ui_text(prop, "Hat Number", "Specify which hat to use");
826 RNA_def_property_range(prop, 1, 2);
827 RNA_def_property_update(prop, NC_LOGIC, NULL);
829 prop= RNA_def_property(srna, "hat_direction", PROP_ENUM, PROP_NONE);
830 RNA_def_property_enum_sdna(prop, NULL, "hatf");
831 RNA_def_property_enum_items(prop, hat_direction_items);
832 RNA_def_property_ui_text(prop, "Hat Direction", "Specify hat direction");
833 RNA_def_property_update(prop, NC_LOGIC, NULL);
836 void RNA_def_sensor(BlenderRNA *brna)
838 rna_def_sensor(brna);
840 rna_def_always_sensor(brna);
841 rna_def_near_sensor(brna);
842 rna_def_mouse_sensor(brna);
843 rna_def_touch_sensor(brna);
844 rna_def_keyboard_sensor(brna);
845 rna_def_property_sensor(brna);
846 rna_def_armature_sensor(brna);
847 rna_def_actuator_sensor(brna);
848 rna_def_delay_sensor(brna);
849 rna_def_collision_sensor(brna);
850 rna_def_radar_sensor(brna);
851 rna_def_random_sensor(brna);
852 rna_def_ray_sensor(brna);
853 rna_def_message_sensor(brna);
854 rna_def_joystick_sensor(brna);