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 *****
25 /** \file blender/makesrna/intern/rna_sensor.c
32 #include "RNA_define.h"
33 #include "RNA_enum_types.h"
34 #include "RNA_access.h"
36 #include "rna_internal.h"
38 #include "DNA_constraint_types.h"
39 #include "DNA_object_types.h"
40 #include "DNA_sensor_types.h"
44 /* Always keep in alphabetical order */
45 EnumPropertyItem sensor_type_items[] ={
46 {SENS_ACTUATOR, "ACTUATOR", 0, "Actuator", ""},
47 {SENS_ALWAYS, "ALWAYS", 0, "Always", ""},
48 {SENS_ARMATURE, "ARMATURE", 0, "Armature", ""},
49 {SENS_COLLISION, "COLLISION", 0, "Collision", ""},
50 {SENS_DELAY, "DELAY", 0, "Delay", ""},
51 {SENS_JOYSTICK, "JOYSTICK", 0, "Joystick", ""},
52 {SENS_KEYBOARD, "KEYBOARD", 0, "Keyboard", ""},
53 {SENS_MESSAGE, "MESSAGE", 0, "Message", ""},
54 {SENS_MOUSE, "MOUSE", 0, "Mouse", ""},
55 {SENS_NEAR, "NEAR", 0, "Near", ""},
56 {SENS_PROPERTY, "PROPERTY", 0, "Property", ""},
57 {SENS_RADAR, "RADAR", 0, "Radar", ""},
58 {SENS_RANDOM, "RANDOM", 0, "Random", ""},
59 {SENS_RAY, "RAY", 0, "Ray", ""},
60 {SENS_TOUCH, "TOUCH", 0, "Touch", ""},
61 {0, NULL, 0, NULL, NULL}};
67 static StructRNA* rna_Sensor_refine(struct PointerRNA *ptr)
69 bSensor *sensor= (bSensor*)ptr->data;
71 switch(sensor->type) {
73 return &RNA_AlwaysSensor;
75 return &RNA_TouchSensor;
77 return &RNA_NearSensor;
79 return &RNA_KeyboardSensor;
81 return &RNA_PropertySensor;
83 return &RNA_ArmatureSensor;
85 return &RNA_MouseSensor;
87 return &RNA_CollisionSensor;
89 return &RNA_RadarSensor;
91 return &RNA_RandomSensor;
93 return &RNA_RaySensor;
95 return &RNA_MessageSensor;
97 return &RNA_JoystickSensor;
99 return &RNA_ActuatorSensor;
101 return &RNA_DelaySensor;
107 static void rna_Sensor_type_set(struct PointerRNA *ptr, int value)
109 bSensor *sens= (bSensor *)ptr->data;
110 if (value != sens->type)
117 /* Always keep in alphabetical order */
118 EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
120 EnumPropertyItem *item= NULL;
124 if (ptr->type == &RNA_Sensor || RNA_struct_is_a(ptr->type, &RNA_Sensor)) {
125 ob = (Object *)ptr->id.data;
127 /* can't use ob from ptr->id.data because that enum is also used by operators */
128 ob = CTX_data_active_object(C);
131 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ACTUATOR);
132 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ALWAYS);
135 if (ob->type==OB_ARMATURE) {
136 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ARMATURE);
139 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_COLLISION);
140 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_DELAY);
141 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_JOYSTICK);
142 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_KEYBOARD);
143 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MESSAGE);
144 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MOUSE);
145 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_NEAR);
146 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_PROPERTY);
147 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RADAR);
148 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RANDOM);
149 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RAY);
150 RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_TOUCH);
152 RNA_enum_item_end(&item, &totitem);
158 static void rna_Sensor_keyboard_key_set(struct PointerRNA *ptr, int value)
160 bSensor *sens= (bSensor *)ptr->data;
161 bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
163 if (ISKEYBOARD(value))
169 static void rna_Sensor_keyboard_modifier_set(struct PointerRNA *ptr, int value)
171 bSensor *sens= (bSensor *)ptr->data;
172 bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
174 if (ISKEYBOARD(value))
180 static void rna_Sensor_keyboard_modifier2_set(struct PointerRNA *ptr, int value)
182 bSensor *sens= (bSensor *)ptr->data;
183 bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
185 if (ISKEYBOARD(value))
191 static void rna_Sensor_tap_set(struct PointerRNA *ptr, int value)
193 bSensor *sens= (bSensor*)ptr->data;
200 static void rna_Sensor_level_set(struct PointerRNA *ptr, int value)
202 bSensor *sens= (bSensor*)ptr->data;
209 static void rna_Sensor_Armature_update(Main *bmain, Scene *scene, PointerRNA *ptr)
211 bSensor *sens= (bSensor *)ptr->data;
212 bArmatureSensor *as = sens->data;
213 Object *ob = (Object *)ptr->id.data;
215 char *posechannel= as->posechannel;
216 char *constraint= as->constraint;
218 /* check that bone exist in the active object */
219 if (ob->type == OB_ARMATURE && ob->pose) {
221 bPose *pose = ob->pose;
222 for (pchan=pose->chanbase.first; pchan; pchan=pchan->next) {
223 if (!strcmp(pchan->name, posechannel)) {
224 /* found it, now look for constraint channel */
226 for (con=pchan->constraints.first; con; con=con->next) {
227 if (!strcmp(con->name, constraint)) {
228 /* found it, all ok */
232 /* didn't find constraint, make empty */
238 /* didn't find any */
243 /* note: the following set functions exists only to avoid id refcounting */
244 static void rna_Sensor_touch_material_set(PointerRNA *ptr, PointerRNA value)
246 bSensor *sens = (bSensor *)ptr->data;
247 bTouchSensor *ts = (bTouchSensor *) sens->data;
253 static void rna_def_sensor(BlenderRNA *brna)
258 srna= RNA_def_struct(brna, "Sensor", NULL);
259 RNA_def_struct_ui_text(srna, "Sensor", "Game engine logic brick to detect events");
260 RNA_def_struct_sdna(srna, "bSensor");
261 RNA_def_struct_refine_func(srna, "rna_Sensor_refine");
263 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
264 RNA_def_property_ui_text(prop, "Name", "Sensor name");
265 RNA_def_struct_name_property(srna, prop);
266 RNA_def_property_update(prop, NC_LOGIC, NULL);
268 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
269 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
270 RNA_def_property_enum_items(prop, sensor_type_items);
271 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_type_set", "rna_Sensor_type_itemf");
272 RNA_def_property_ui_text(prop, "Type", "");
273 RNA_def_property_update(prop, NC_LOGIC, NULL);
275 prop= RNA_def_property(srna, "pin", PROP_BOOLEAN, PROP_NONE);
276 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_PIN);
277 RNA_def_property_ui_text(prop, "Pinned", "Display when not linked to a visible states controller");
278 RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
279 RNA_def_property_update(prop, NC_LOGIC, NULL);
281 prop= RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
282 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_SHOW);
283 RNA_def_property_ui_text(prop, "Expanded", "Set sensor expanded in the user interface");
284 RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
285 RNA_def_property_update(prop, NC_LOGIC, NULL);
287 prop= RNA_def_property(srna, "invert", PROP_BOOLEAN, PROP_NONE);
288 RNA_def_property_ui_text(prop, "Invert Output", "Invert the level(output) of this sensor");
289 RNA_def_property_update(prop, NC_LOGIC, NULL);
291 prop= RNA_def_property(srna, "use_level", PROP_BOOLEAN, PROP_NONE);
292 RNA_def_property_boolean_sdna(prop, NULL, "level", 1);
293 RNA_def_property_ui_text(prop, "Level", "Level detector, trigger controllers of new states(only applicable upon logic state transition)");
294 RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_level_set");
295 RNA_def_property_update(prop, NC_LOGIC, NULL);
297 prop= RNA_def_property(srna, "use_pulse_true_level", PROP_BOOLEAN, PROP_NONE);
298 RNA_def_property_boolean_sdna(prop, NULL, "pulse", SENS_PULSE_REPEAT);
299 RNA_def_property_ui_text(prop, "Pulse True Level", "Activate TRUE level triggering (pulse mode)");
300 RNA_def_property_update(prop, NC_LOGIC, NULL);
302 prop= RNA_def_property(srna, "use_pulse_false_level", PROP_BOOLEAN, PROP_NONE);
303 RNA_def_property_boolean_sdna(prop, NULL, "pulse", SENS_NEG_PULSE_MODE);
304 RNA_def_property_ui_text(prop, "Pulse False Level", "Activate FALSE level triggering (pulse mode)");
305 RNA_def_property_update(prop, NC_LOGIC, NULL);
307 prop= RNA_def_property(srna, "frequency", PROP_INT, PROP_NONE);
308 RNA_def_property_int_sdna(prop, NULL, "freq");
309 RNA_def_property_ui_text(prop, "Frequency", "Delay between repeated pulses(in logic tics, 0=no delay)");
310 RNA_def_property_range(prop, 0, 10000);
311 RNA_def_property_update(prop, NC_LOGIC, NULL);
313 prop= RNA_def_property(srna, "use_tap", PROP_BOOLEAN, PROP_NONE);
314 RNA_def_property_boolean_sdna(prop, NULL, "tap", 1);
315 RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_tap_set");
316 RNA_def_property_ui_text(prop, "Tap", "Trigger controllers only for an instant, even while the sensor remains true");
317 RNA_def_property_update(prop, NC_LOGIC, NULL);
319 RNA_api_sensor(srna);
322 static void rna_def_always_sensor(BlenderRNA *brna)
325 srna= RNA_def_struct(brna, "AlwaysSensor", "Sensor");
326 RNA_def_struct_ui_text(srna, "Always Sensor", "Sensor to generate continuous pulses");
329 static void rna_def_near_sensor(BlenderRNA *brna)
334 srna= RNA_def_struct(brna, "NearSensor", "Sensor");
335 RNA_def_struct_ui_text(srna , "Near Sensor", "Sensor to detect nearby objects");
336 RNA_def_struct_sdna_from(srna, "bNearSensor", "data");
338 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
339 RNA_def_property_string_sdna(prop, NULL, "name");
340 RNA_def_property_ui_text(prop, "Property", "Only look for objects with this property (blank = all objects)");
341 RNA_def_property_update(prop, NC_LOGIC, NULL);
343 prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
344 RNA_def_property_float_sdna(prop, NULL, "dist");
345 RNA_def_property_ui_text(prop, "Distance", "Trigger distance");
346 RNA_def_property_range(prop, 0.0f, 10000.0f);
347 RNA_def_property_update(prop, NC_LOGIC, NULL);
349 prop= RNA_def_property(srna, "reset_distance", PROP_FLOAT, PROP_NONE);
350 RNA_def_property_float_sdna(prop, NULL, "resetdist");
351 RNA_def_property_ui_text(prop, "Reset Distance", "The distance where the sensor forgets the actor");
352 RNA_def_property_range(prop, 0.0f, 10000.0f);
353 RNA_def_property_update(prop, NC_LOGIC, NULL);
356 static void rna_def_mouse_sensor(BlenderRNA *brna)
361 static EnumPropertyItem mouse_event_items[] ={
362 {BL_SENS_MOUSE_LEFT_BUTTON, "LEFTCLICK", 0, "Left Button", ""},
363 {BL_SENS_MOUSE_MIDDLE_BUTTON, "MIDDLECLICK", 0, "Middle Button", ""},
364 {BL_SENS_MOUSE_RIGHT_BUTTON, "RIGHTCLICK", 0, "Right Button", ""},
365 {BL_SENS_MOUSE_WHEEL_UP, "WHEELUP", 0, "Wheel Up", ""},
366 {BL_SENS_MOUSE_WHEEL_DOWN, "WHEELDOWN", 0, "Wheel Down", ""},
367 {BL_SENS_MOUSE_MOVEMENT, "MOVEMENT", 0, "Movement", ""},
368 {BL_SENS_MOUSE_MOUSEOVER, "MOUSEOVER", 0, "Mouse Over", ""},
369 {BL_SENS_MOUSE_MOUSEOVER_ANY, "MOUSEOVERANY", 0, "Mouse Over Any", ""},
370 {0, NULL, 0, NULL, NULL}};
372 srna= RNA_def_struct(brna, "MouseSensor", "Sensor");
373 RNA_def_struct_ui_text(srna, "Mouse Sensor", "Sensor to detect mouse events");
374 RNA_def_struct_sdna_from(srna, "bMouseSensor", "data");
376 prop= RNA_def_property(srna, "mouse_event", PROP_ENUM, PROP_NONE);
377 RNA_def_property_enum_sdna(prop, NULL, "type");
378 RNA_def_property_enum_items(prop, mouse_event_items);
379 RNA_def_property_ui_text(prop, "Mouse Event", "Specify the type of event this mouse sensor should trigger on");
380 RNA_def_property_update(prop, NC_LOGIC, NULL);
383 static void rna_def_touch_sensor(BlenderRNA *brna)
388 srna= RNA_def_struct(brna, "TouchSensor", "Sensor");
389 RNA_def_struct_ui_text(srna, "Touch Sensor", "Sensor to detect objects colliding with the current object");
390 RNA_def_struct_sdna_from(srna, "bTouchSensor", "data");
392 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
393 RNA_def_property_struct_type(prop, "Material");
394 RNA_def_property_pointer_sdna(prop, NULL, "ma");
395 RNA_def_property_flag(prop, PROP_EDITABLE);
396 RNA_def_property_ui_text(prop, "Material", "Only look for objects with this material (blank = all objects)");
397 /* note: custom set function is ONLY to avoid rna setting a user for this. */
398 RNA_def_property_pointer_funcs(prop, NULL, "rna_Sensor_touch_material_set", NULL, NULL);
399 RNA_def_property_update(prop, NC_LOGIC, NULL);
402 static void rna_def_keyboard_sensor(BlenderRNA *brna)
407 srna= RNA_def_struct(brna, "KeyboardSensor", "Sensor");
408 RNA_def_struct_ui_text(srna, "Keyboard Sensor", "Sensor to detect keyboard events");
409 RNA_def_struct_sdna_from(srna, "bKeyboardSensor", "data");
411 prop= RNA_def_property(srna, "key", PROP_ENUM, PROP_NONE);
412 RNA_def_property_enum_sdna(prop, NULL, "key");
413 RNA_def_property_enum_items(prop, event_type_items);
414 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_key_set", NULL);
415 RNA_def_property_ui_text(prop, "Key", "");
416 RNA_def_property_update(prop, NC_LOGIC, NULL);
418 prop= RNA_def_property(srna, "modifier_key_1", PROP_ENUM, PROP_NONE);
419 RNA_def_property_enum_sdna(prop, NULL, "qual");
420 RNA_def_property_enum_items(prop, event_type_items);
421 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier_set", NULL);
422 RNA_def_property_ui_text(prop, "Modifier Key", "Modifier key code");
423 RNA_def_property_update(prop, NC_LOGIC, NULL);
425 prop= RNA_def_property(srna, "modifier_key_2", PROP_ENUM, PROP_NONE);
426 RNA_def_property_enum_sdna(prop, NULL, "qual2");
427 RNA_def_property_enum_items(prop, event_type_items);
428 RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier2_set", NULL);
429 RNA_def_property_ui_text(prop, "Second Modifier Key", "Modifier key code");
430 RNA_def_property_update(prop, NC_LOGIC, NULL);
432 prop= RNA_def_property(srna, "target", PROP_STRING, PROP_NONE);
433 RNA_def_property_string_sdna(prop, NULL, "targetName");
434 RNA_def_property_ui_text(prop, "Target", "Property that receive the keystrokes in case a string is logged");
435 RNA_def_property_update(prop, NC_LOGIC, NULL);
437 prop= RNA_def_property(srna, "log", PROP_STRING, PROP_NONE);
438 RNA_def_property_string_sdna(prop, NULL, "toggleName");
439 RNA_def_property_ui_text(prop, "Log Toggle", "Property that indicates whether to log keystrokes as a string");
440 RNA_def_property_update(prop, NC_LOGIC, NULL);
442 prop= RNA_def_property(srna, "use_all_keys", PROP_BOOLEAN, PROP_NONE);
443 RNA_def_property_boolean_sdna(prop, NULL, "type", 1);
444 RNA_def_property_ui_text(prop, "All Keys", "Trigger this sensor on any keystroke");
445 RNA_def_property_update(prop, NC_LOGIC, NULL);
448 static void rna_def_property_sensor(BlenderRNA *brna)
452 static EnumPropertyItem prop_type_items[] ={
453 {SENS_PROP_EQUAL, "PROPEQUAL", 0, "Equal", ""},
454 {SENS_PROP_NEQUAL, "PROPNEQUAL", 0, "Not Equal", ""},
455 {SENS_PROP_INTERVAL, "PROPINTERVAL", 0, "Interval", ""},
456 {SENS_PROP_CHANGED, "PROPCHANGED", 0, "Changed", ""},
457 /* {SENS_PROP_EXPRESSION, "PROPEXPRESSION", 0, "Expression", ""}, NOT_USED_IN_UI */
458 {0, NULL, 0, NULL, NULL}};
460 srna= RNA_def_struct(brna, "PropertySensor", "Sensor");
461 RNA_def_struct_ui_text(srna, "Property Sensor", "Sensor to detect values and changes in values of properties");
462 RNA_def_struct_sdna_from(srna, "bPropertySensor", "data");
464 prop= RNA_def_property(srna, "evaluation_type", PROP_ENUM, PROP_NONE);
465 RNA_def_property_enum_sdna(prop, NULL, "type");
466 RNA_def_property_enum_items(prop, prop_type_items);
467 RNA_def_property_ui_text(prop, "Evaluation Type", "Type of property evaluation");
468 RNA_def_property_update(prop, NC_LOGIC, NULL);
470 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
471 RNA_def_property_string_sdna(prop, NULL, "name");
472 RNA_def_property_ui_text(prop, "Property", "");
473 RNA_def_property_update(prop, NC_LOGIC, NULL);
475 prop= RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
476 RNA_def_property_string_sdna(prop, NULL, "value");
477 RNA_def_property_ui_text(prop, "Value", "Check for this value in types in Equal or Not Equal types");
478 RNA_def_property_update(prop, NC_LOGIC, NULL);
480 prop= RNA_def_property(srna, "value_min", PROP_STRING, PROP_NONE);
481 RNA_def_property_string_sdna(prop, NULL, "value");
482 RNA_def_property_ui_text(prop, "Minimum Value", "Specify minimum value in Interval type");
483 RNA_def_property_update(prop, NC_LOGIC, NULL);
485 prop= RNA_def_property(srna, "value_max", PROP_STRING, PROP_NONE);
486 RNA_def_property_string_sdna(prop, NULL, "maxvalue");
487 RNA_def_property_ui_text(prop, "Maximum Value", "Specify maximum value in Interval type");
488 RNA_def_property_update(prop, NC_LOGIC, NULL);
491 static void rna_def_armature_sensor(BlenderRNA *brna)
495 static EnumPropertyItem prop_type_items[] ={
496 {SENS_ARM_STATE_CHANGED, "STATECHG", 0, "State Changed", ""},
497 {SENS_ARM_LIN_ERROR_BELOW, "LINERRORBELOW", 0, "Lin error below", ""},
498 {SENS_ARM_LIN_ERROR_ABOVE, "LINERRORABOVE", 0, "Lin error above", ""},
499 {SENS_ARM_ROT_ERROR_BELOW, "ROTERRORBELOW", 0, "Rot error below", ""},
500 {SENS_ARM_ROT_ERROR_ABOVE, "ROTERRORABOVE", 0, "Rot error above", ""},
501 {0, NULL, 0, NULL, NULL}};
503 srna= RNA_def_struct(brna, "ArmatureSensor", "Sensor");
504 RNA_def_struct_ui_text(srna, "Armature Sensor", "Sensor to detect values and changes in values of IK solver");
505 RNA_def_struct_sdna_from(srna, "bArmatureSensor", "data");
507 prop= RNA_def_property(srna, "test_type", PROP_ENUM, PROP_NONE);
508 RNA_def_property_enum_sdna(prop, NULL, "type");
509 RNA_def_property_enum_items(prop, prop_type_items);
510 RNA_def_property_ui_text(prop, "Test", "Type of value and test");
511 RNA_def_property_update(prop, NC_LOGIC, NULL);
513 prop= RNA_def_property(srna, "bone", PROP_STRING, PROP_NONE);
514 RNA_def_property_string_sdna(prop, NULL, "posechannel");
515 RNA_def_property_ui_text(prop, "Bone Name", "Identify the bone to check value from");
516 RNA_def_property_update(prop, NC_LOGIC, "rna_Sensor_Armature_update");
518 prop= RNA_def_property(srna, "constraint", PROP_STRING, PROP_NONE);
519 RNA_def_property_string_sdna(prop, NULL, "constraint");
520 RNA_def_property_ui_text(prop, "Constraint Name", "Identify the bone constraint to check value from");
521 RNA_def_property_update(prop, NC_LOGIC, "rna_Sensor_Armature_update");
523 prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
524 RNA_def_property_float_sdna(prop, NULL, "value");
525 RNA_def_property_ui_text(prop, "Compare Value", "Specify value to be used in comparison");
526 RNA_def_property_update(prop, NC_LOGIC, NULL);
529 static void rna_def_actuator_sensor(BlenderRNA *brna)
534 srna= RNA_def_struct(brna, "ActuatorSensor", "Sensor");
535 RNA_def_struct_ui_text(srna, "Actuator Sensor", "Sensor to detect state modifications of actuators");
536 RNA_def_struct_sdna_from(srna, "bActuatorSensor", "data");
538 // XXX if eventually have Logics using RNA 100%, we could use the actuator datablock isntead of its name
539 prop= RNA_def_property(srna, "actuator", PROP_STRING, PROP_NONE);
540 RNA_def_property_string_sdna(prop, NULL, "name");
541 RNA_def_property_ui_text(prop, "Actuator", "Actuator name, actuator active state modifications will be detected");
542 RNA_def_property_update(prop, NC_LOGIC, NULL);
545 static void rna_def_delay_sensor(BlenderRNA *brna)
550 srna= RNA_def_struct(brna, "DelaySensor", "Sensor");
551 RNA_def_struct_ui_text(srna, "Delay Sensor", "Sensor to send delayed events");
552 RNA_def_struct_sdna_from(srna, "bDelaySensor", "data");
554 prop= RNA_def_property(srna, "delay", PROP_INT, PROP_NONE);
555 RNA_def_property_ui_text(prop, "Delay", "Delay in number of logic tics before the positive trigger (default 60 per second)");
556 RNA_def_property_range(prop, 0, 5000);
557 RNA_def_property_update(prop, NC_LOGIC, NULL);
559 prop= RNA_def_property(srna, "duration", PROP_INT, PROP_NONE);
560 RNA_def_property_ui_text(prop, "Duration", "If >0, delay in number of logic tics before the negative trigger following the positive trigger");
561 RNA_def_property_range(prop, 0, 5000);
562 RNA_def_property_update(prop, NC_LOGIC, NULL);
564 prop= RNA_def_property(srna, "use_repeat", PROP_BOOLEAN, PROP_NONE);
565 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_DELAY_REPEAT);
566 RNA_def_property_ui_text(prop, "Repeat", "Toggle repeat option. If selected, the sensor restarts after Delay+Dur logic tics");
567 RNA_def_property_update(prop, NC_LOGIC, NULL);
570 static void rna_def_collision_sensor(BlenderRNA *brna)
575 srna= RNA_def_struct(brna, "CollisionSensor", "Sensor");
576 RNA_def_struct_ui_text(srna, "Collision Sensor", "Sensor to detect objects colliding with the current object, with more settings than the Touch sensor");
577 RNA_def_struct_sdna_from(srna, "bCollisionSensor", "data");
579 prop= RNA_def_property(srna, "use_pulse", PROP_BOOLEAN, PROP_NONE);
580 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_COLLISION_PULSE);
581 RNA_def_property_ui_text(prop, "Pulse", "Changes to the set of colliding objects generates pulse");
582 RNA_def_property_update(prop, NC_LOGIC, NULL);
584 prop= RNA_def_property(srna, "use_material", PROP_BOOLEAN, PROP_NONE);
585 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_COLLISION_MATERIAL);
586 RNA_def_property_ui_text(prop, "M/P", "Toggle collision on material or property");
587 RNA_def_property_update(prop, NC_LOGIC, NULL);
589 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
590 RNA_def_property_string_sdna(prop, NULL, "name");
591 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property (blank = all objects)");
592 RNA_def_property_update(prop, NC_LOGIC, NULL);
594 //XXX to make a setFunction to create a lookup with all materials in Blend File (not only this object mat.)
595 prop= RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
596 RNA_def_property_string_sdna(prop, NULL, "materialName");
597 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material (blank = all objects)");
598 RNA_def_property_update(prop, NC_LOGIC, NULL);
600 /*//XXX either use a datablock look up to store the string name (material)
601 // or to do a doversion and use a material pointer.
602 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
603 RNA_def_property_struct_type(prop, "Material");
604 RNA_def_property_flag(prop, PROP_EDITABLE);
605 RNA_def_property_pointer_sdna(prop, NULL, "ma");
606 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material (blank = all objects)");
610 static void rna_def_radar_sensor(BlenderRNA *brna)
614 static EnumPropertyItem axis_items[] ={
615 {SENS_RADAR_X_AXIS, "XAXIS", 0, "+X axis", ""},
616 {SENS_RADAR_Y_AXIS, "YAXIS", 0, "+Y axis", ""},
617 {SENS_RADAR_Z_AXIS, "ZAXIS", 0, "+Z axis", ""},
618 {SENS_RADAR_NEG_X_AXIS, "NEGXAXIS", 0, "-X axis", ""},
619 {SENS_RADAR_NEG_Y_AXIS, "NEGYAXIS", 0, "-Y axis", ""},
620 {SENS_RADAR_NEG_Z_AXIS, "NEGZAXIS", 0, "-Z axis", ""},
621 {0, NULL, 0, NULL, NULL}};
623 srna= RNA_def_struct(brna, "RadarSensor", "Sensor");
624 RNA_def_struct_ui_text(srna, "Radar Sensor", "Sensor to detect objects in a cone shaped radar emanating from the current object");
625 RNA_def_struct_sdna_from(srna, "bRadarSensor", "data");
627 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
628 RNA_def_property_string_sdna(prop, NULL, "name");
629 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property (blank = all objects)");
630 RNA_def_property_update(prop, NC_LOGIC, NULL);
632 prop= RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
633 RNA_def_property_enum_items(prop, axis_items);
634 RNA_def_property_ui_text(prop, "Axis", "Specify along which axis the radar cone is cast");
635 RNA_def_property_update(prop, NC_LOGIC, NULL);
637 //XXX TODO - use radians internally then change to PROP_ANGLE
638 prop= RNA_def_property(srna, "angle", PROP_FLOAT, PROP_NONE);
639 RNA_def_property_range(prop, 0.0, 179.9);
640 RNA_def_property_ui_text(prop, "Angle", "Opening angle of the radar cone (in degrees)");
641 RNA_def_property_update(prop, NC_LOGIC, NULL);
643 prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
644 RNA_def_property_float_sdna(prop, NULL, "range");
645 RNA_def_property_range(prop, 0.0, 10000.0);
646 RNA_def_property_ui_text(prop, "Distance", "Depth of the radar cone");
647 RNA_def_property_update(prop, NC_LOGIC, NULL);
650 static void rna_def_random_sensor(BlenderRNA *brna)
655 srna= RNA_def_struct(brna, "RandomSensor", "Sensor");
656 RNA_def_struct_ui_text(srna, "Random Sensor", "Sensor to send random events");
657 RNA_def_struct_sdna_from(srna, "bRandomSensor", "data");
659 prop= RNA_def_property(srna, "seed", PROP_INT, PROP_NONE);
660 RNA_def_property_range(prop, 0, 1000);
661 RNA_def_property_ui_text(prop, "Seed", "Initial seed of the generator. (Choose 0 for not random)");
662 RNA_def_property_update(prop, NC_LOGIC, NULL);
665 static void rna_def_ray_sensor(BlenderRNA *brna)
669 static EnumPropertyItem axis_items[] ={
670 {SENS_RAY_X_AXIS, "XAXIS", 0, "+X axis", ""},
671 {SENS_RAY_Y_AXIS, "YAXIS", 0, "+Y axis", ""},
672 {SENS_RAY_Z_AXIS, "ZAXIS", 0, "+Z axis", ""},
673 {SENS_RAY_NEG_X_AXIS, "NEGXAXIS", 0, "-X axis", ""},
674 {SENS_RAY_NEG_Y_AXIS, "NEGYAXIS", 0, "-Y axis", ""},
675 {SENS_RAY_NEG_Z_AXIS, "NEGZAXIS", 0, "-Z axis", ""},
676 {0, NULL, 0, NULL, NULL}};
678 static const EnumPropertyItem prop_ray_type_items[]= {
679 {SENS_COLLISION_PROPERTY, "PROPERTY", ICON_LOGIC, "Property", "Use a material for ray intersections"},
680 {SENS_COLLISION_MATERIAL, "MATERIAL", ICON_MATERIAL_DATA, "Material", "Use a property for ray intersections"},
681 {0, NULL, 0, NULL, NULL}};
683 srna= RNA_def_struct(brna, "RaySensor", "Sensor");
684 RNA_def_struct_ui_text(srna, "Ray Sensor", "Sensor to detect intersections with a ray emanating from the current object");
685 RNA_def_struct_sdna_from(srna, "bRaySensor", "data");
687 prop= RNA_def_property(srna, "ray_type", PROP_ENUM, PROP_NONE);
688 RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
689 RNA_def_property_enum_items(prop, prop_ray_type_items);
690 RNA_def_property_ui_text(prop, "Ray Type", "Toggle collision on material or property");
691 RNA_def_property_update(prop, NC_LOGIC, NULL);
693 prop= RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
694 RNA_def_property_string_sdna(prop, NULL, "propname");
695 RNA_def_property_ui_text(prop, "Property", "Only look for Objects with this property (blank = all objects)");
696 RNA_def_property_update(prop, NC_LOGIC, NULL);
698 prop= RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
699 RNA_def_property_string_sdna(prop, NULL, "matname");
700 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material (blank = all objects)");
701 RNA_def_property_update(prop, NC_LOGIC, NULL);
703 /* //XXX either use a datablock look up to store the string name (material)
704 // or to do a doversion and use a material pointer.
705 prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
706 RNA_def_property_struct_type(prop, "Material");
707 RNA_def_property_flag(prop, PROP_EDITABLE);
708 RNA_def_property_pointer_sdna(prop, NULL, "ma");
709 RNA_def_property_ui_text(prop, "Material", "Only look for Objects with this material (blank = all objects)");
712 prop= RNA_def_property(srna, "use_x_ray", PROP_BOOLEAN, PROP_NONE);
713 RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_RAY_XRAY);
714 RNA_def_property_ui_text(prop, "X-Ray Mode", "Toggle X-Ray option (see through objects that don't have the property)");
715 RNA_def_property_update(prop, NC_LOGIC, NULL);
717 prop= RNA_def_property(srna, "range", PROP_FLOAT, PROP_NONE);
718 RNA_def_property_range(prop, 0.01, 10000.0);
719 RNA_def_property_ui_text(prop, "Range", "Sense objects no farther than this distance");
720 RNA_def_property_update(prop, NC_LOGIC, NULL);
722 prop= RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
723 RNA_def_property_enum_sdna(prop, NULL, "axisflag");
724 RNA_def_property_enum_items(prop, axis_items);
725 RNA_def_property_ui_text(prop, "Axis", "Specify along which axis the ray is cast");
726 RNA_def_property_update(prop, NC_LOGIC, NULL);
729 static void rna_def_message_sensor(BlenderRNA *brna)
734 srna= RNA_def_struct(brna, "MessageSensor", "Sensor");
735 RNA_def_struct_ui_text(srna, "Message Sensor", "Sensor to detect incoming messages");
736 RNA_def_struct_sdna_from(srna, "bMessageSensor", "data");
738 prop= RNA_def_property(srna, "subject", PROP_STRING, PROP_NONE);
739 RNA_def_property_ui_text(prop, "Subject", "Optional subject filter: only accept messages with this subject, or empty for all");
740 RNA_def_property_update(prop, NC_LOGIC, NULL);
743 static void rna_def_joystick_sensor(BlenderRNA *brna)
748 static EnumPropertyItem event_type_items[] ={
749 {SENS_JOY_BUTTON, "BUTTON", 0, "Button", ""},
750 {SENS_JOY_AXIS, "AXIS", 0, "Axis", ""},
751 {SENS_JOY_HAT, "HAT", 0, "Hat", ""},
752 {SENS_JOY_AXIS_SINGLE, "AXIS_SINGLE", 0, "Single Axis", ""},
753 {0, NULL, 0, NULL, NULL}};
755 static EnumPropertyItem axis_direction_items[] ={
756 {SENS_JOY_X_AXIS, "RIGHTAXIS", 0, "Right Axis", ""},
757 {SENS_JOY_Y_AXIS, "UPAXIS", 0, "Up Axis", ""},
758 {SENS_JOY_NEG_X_AXIS, "LEFTAXIS", 0, "Left Axis", ""},
759 {SENS_JOY_NEG_Y_AXIS, "DOWNAXIS", 0, "Down Axis", ""},
760 {0, NULL, 0, NULL, NULL}};
762 static EnumPropertyItem hat_direction_items[] ={
763 {SENS_JOY_HAT_UP, "UP", 0, "Up", ""},
764 {SENS_JOY_HAT_DOWN, "DOWN", 0, "Down", ""},
765 {SENS_JOY_HAT_LEFT, "LEFT", 0, "Left", ""},
766 {SENS_JOY_HAT_RIGHT, "RIGHT", 0, "Right", ""},
768 {SENS_JOY_HAT_UP_RIGHT, "UPRIGHT", 0, "Up/Right", ""},
769 {SENS_JOY_HAT_DOWN_LEFT, "DOWNLEFT", 0, "Down/Left", ""},
770 {SENS_JOY_HAT_UP_LEFT, "UPLEFT", 0, "Up/Left", ""},
771 {SENS_JOY_HAT_DOWN_RIGHT, "DOWNRIGHT", 0, "Down/Right", ""},
772 {0, NULL, 0, NULL, NULL}};
774 srna= RNA_def_struct(brna, "JoystickSensor", "Sensor");
775 RNA_def_struct_ui_text(srna, "Joystick Sensor", "Sensor to detect joystick events");
776 RNA_def_struct_sdna_from(srna, "bJoystickSensor", "data");
778 prop= RNA_def_property(srna, "joystick_index", PROP_INT, PROP_NONE);
779 RNA_def_property_int_sdna(prop, NULL, "joyindex");
780 RNA_def_property_ui_text(prop, "Index", "Specify which joystick to use");
781 RNA_def_property_range(prop, 0, SENS_JOY_MAXINDEX-1);
782 RNA_def_property_update(prop, NC_LOGIC, NULL);
784 prop= RNA_def_property(srna, "event_type", PROP_ENUM, PROP_NONE);
785 RNA_def_property_enum_sdna(prop, NULL, "type");
786 RNA_def_property_enum_items(prop, event_type_items);
787 RNA_def_property_ui_text(prop, "Event Type", "The type of event this joystick sensor is triggered on");
788 RNA_def_property_update(prop, NC_LOGIC, NULL);
790 prop= RNA_def_property(srna, "use_all_events", PROP_BOOLEAN, PROP_NONE);
791 RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_JOY_ANY_EVENT);
792 RNA_def_property_ui_text(prop, "All Events", "Triggered by all events on this joysticks current type (axis/button/hat)");
793 RNA_def_property_update(prop, NC_LOGIC, NULL);
796 prop= RNA_def_property(srna, "button_number", PROP_INT, PROP_NONE);
797 RNA_def_property_int_sdna(prop, NULL, "button");
798 RNA_def_property_ui_text(prop, "Button Number", "Specify which button to use");
799 RNA_def_property_range(prop, 0, 18);
800 RNA_def_property_update(prop, NC_LOGIC, NULL);
803 prop= RNA_def_property(srna, "axis_number", PROP_INT, PROP_NONE);
804 RNA_def_property_int_sdna(prop, NULL, "axis");
805 RNA_def_property_ui_text(prop, "Axis Number", "Specify which axis pair to use, 1 is usually the main direction input");
806 RNA_def_property_range(prop, 1, 2);
807 RNA_def_property_update(prop, NC_LOGIC, NULL);
809 prop= RNA_def_property(srna, "axis_threshold", PROP_INT, PROP_NONE);
810 RNA_def_property_int_sdna(prop, NULL, "precision");
811 RNA_def_property_ui_text(prop, "Axis Threshold", "Specify the precision of the axis");
812 RNA_def_property_range(prop, 0, 32768);
813 RNA_def_property_update(prop, NC_LOGIC, NULL);
815 prop= RNA_def_property(srna, "axis_direction", PROP_ENUM, PROP_NONE);
816 RNA_def_property_enum_sdna(prop, NULL, "axisf");
817 RNA_def_property_enum_items(prop, axis_direction_items);
818 RNA_def_property_ui_text(prop, "Axis Direction", "The direction of the axis");
819 RNA_def_property_update(prop, NC_LOGIC, NULL);
822 prop= RNA_def_property(srna, "single_axis_number", PROP_INT, PROP_NONE);
823 RNA_def_property_int_sdna(prop, NULL, "axis_single");
824 RNA_def_property_ui_text(prop, "Axis Number", "Specify a single axis (verticle/horizontal/other) to detect");
825 RNA_def_property_range(prop, 1, 16);
826 RNA_def_property_update(prop, NC_LOGIC, NULL);
829 prop= RNA_def_property(srna, "hat_number", PROP_INT, PROP_NONE);
830 RNA_def_property_int_sdna(prop, NULL, "hat");
831 RNA_def_property_ui_text(prop, "Hat Number", "Specify which hat to use");
832 RNA_def_property_range(prop, 1, 2);
833 RNA_def_property_update(prop, NC_LOGIC, NULL);
835 prop= RNA_def_property(srna, "hat_direction", PROP_ENUM, PROP_NONE);
836 RNA_def_property_enum_sdna(prop, NULL, "hatf");
837 RNA_def_property_enum_items(prop, hat_direction_items);
838 RNA_def_property_ui_text(prop, "Hat Direction", "Specify hat direction");
839 RNA_def_property_update(prop, NC_LOGIC, NULL);
842 void RNA_def_sensor(BlenderRNA *brna)
844 rna_def_sensor(brna);
846 rna_def_always_sensor(brna);
847 rna_def_near_sensor(brna);
848 rna_def_mouse_sensor(brna);
849 rna_def_touch_sensor(brna);
850 rna_def_keyboard_sensor(brna);
851 rna_def_property_sensor(brna);
852 rna_def_armature_sensor(brna);
853 rna_def_actuator_sensor(brna);
854 rna_def_delay_sensor(brna);
855 rna_def_collision_sensor(brna);
856 rna_def_radar_sensor(brna);
857 rna_def_random_sensor(brna);
858 rna_def_ray_sensor(brna);
859 rna_def_message_sensor(brna);
860 rna_def_joystick_sensor(brna);