diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_logic/logic_ops.c | 32 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 16 |
3 files changed, 48 insertions, 1 deletions
diff --git a/source/blender/editors/space_logic/logic_ops.c b/source/blender/editors/space_logic/logic_ops.c index 3b4915692dd..e7abf49e95b 100644 --- a/source/blender/editors/space_logic/logic_ops.c +++ b/source/blender/editors/space_logic/logic_ops.c @@ -259,10 +259,20 @@ static int sensor_add_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_active_context(C); bSensor *sens; + PointerRNA sens_ptr; + PropertyRNA *prop; + const char *sens_name; int type= RNA_enum_get(op->ptr, "type"); sens= new_sensor(type); BLI_addtail(&(ob->sensors), sens); + + /* set the sensor name based on rna type enum */ + RNA_pointer_create((ID *)ob, &RNA_Sensor, sens, &sens_ptr); + prop = RNA_struct_find_property(&sens_ptr, "type"); + RNA_property_enum_name(C, &sens_ptr, prop, RNA_property_enum_get(&sens_ptr, prop), &sens_name); + BLI_strncpy(sens->name, sens_name, sizeof(sens->name)); + make_unique_prop_names(C, sens->name); ob->scaflag |= OB_SHOWSENS; @@ -345,11 +355,21 @@ static int controller_add_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_active_context(C); bController *cont; + PointerRNA cont_ptr; + PropertyRNA *prop; + const char *cont_name; int type= RNA_enum_get(op->ptr, "type"); int bit; cont= new_controller(type); BLI_addtail(&(ob->controllers), cont); + + /* set the controller name based on rna type enum */ + RNA_pointer_create((ID *)ob, &RNA_Controller, cont, &cont_ptr); + prop = RNA_struct_find_property(&cont_ptr, "type"); + RNA_property_enum_name(C, &cont_ptr, prop, RNA_property_enum_get(&cont_ptr, prop), &cont_name); + BLI_strncpy(cont->name, cont_name, sizeof(cont->name)); + make_unique_prop_names(C, cont->name); /* set the controller state mask from the current object state. @@ -445,13 +465,23 @@ static int actuator_add_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_active_context(C); bActuator *act; + PointerRNA act_ptr; + PropertyRNA *prop; + const char *act_name; int type= RNA_enum_get(op->ptr, "type"); act= new_actuator(type); BLI_addtail(&(ob->actuators), act); + + /* set the actuator name based on rna type enum */ + RNA_pointer_create((ID *)ob, &RNA_Actuator, act, &act_ptr); + prop = RNA_struct_find_property(&act_ptr, "type"); + RNA_property_enum_name(C, &act_ptr, prop, RNA_property_enum_get(&act_ptr, prop), &act_name); + BLI_strncpy(act->name, act_name, sizeof(act->name)); + make_unique_prop_names(C, act->name); ob->scaflag |= OB_SHOWACT; - + WM_event_add_notifier(C, NC_LOGIC, NULL); return OPERATOR_FINISHED; diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index c37c3bc65d7..f9802e558bb 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -664,6 +664,7 @@ int RNA_enum_name(EnumPropertyItem *item, const int value, const char **name); void RNA_property_enum_items(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item, int *totitem, int *free); int RNA_property_enum_value(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value); int RNA_property_enum_identifier(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier); +int RNA_property_enum_name(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name); int RNA_property_enum_bitflag_identifiers(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier); StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 078b4d995ee..452d8d80dbc 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1101,6 +1101,22 @@ int RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop return 0; } +int RNA_property_enum_name(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name) +{ + EnumPropertyItem *item= NULL; + int result, free; + + RNA_property_enum_items(C, ptr, prop, &item, NULL, &free); + if(item) { + result= RNA_enum_name(item, value, name); + if(free) + MEM_freeN(item); + + return result; + } + return 0; +} + int RNA_property_enum_bitflag_identifiers(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier) { EnumPropertyItem *item= NULL; |