Added dynamic enum itemf for add sensor/actuator operators
authorMatt Ebb <matt@mke3.net>
Fri, 7 May 2010 02:01:50 +0000 (02:01 +0000)
committerMatt Ebb <matt@mke3.net>
Fri, 7 May 2010 02:01:50 +0000 (02:01 +0000)
source/blender/editors/space_logic/logic_ops.c
source/blender/editors/space_logic/logic_window.c
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/intern/rna_actuator.c
source/blender/makesrna/intern/rna_sensor.c

index ee65068e5375a533a93038abe550dfab3b816f4f..3b4915692dd1d90bafdd07d42e7850566f683801 100644 (file)
@@ -289,7 +289,8 @@ void LOGIC_OT_sensor_add(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       prop= RNA_def_enum(ot->srna, "type", sensor_type_items, SENS_ALWAYS, "Type", "Type of sensor to add");
+       prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, SENS_ALWAYS, "Type", "Type of sensor to add");
+       RNA_def_enum_funcs(prop, rna_Sensor_type_itemf);
 }
 
 /* ************* Add/Remove Controller Operator ************* */
@@ -474,7 +475,8 @@ void LOGIC_OT_actuator_add(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       prop= RNA_def_enum(ot->srna, "type", actuator_type_items, CONT_LOGIC_AND, "Type", "Type of actuator to add");
+       prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, CONT_LOGIC_AND, "Type", "Type of actuator to add");
+       RNA_def_enum_funcs(prop, rna_Actuator_type_itemf);
 }
 
 void ED_operatortypes_logic(void)
index 91a0dd9ee4f832157153842360abc5ba72444cc8..90f60dfaad914ef729006e226411744fc4a30048 100644 (file)
@@ -4313,7 +4313,7 @@ static void logic_buttons_new(bContext *C, ARegion *ar)
        {
                PointerRNA settings_ptr;
                row = uiLayoutRow(layout, 0);
-               RNA_pointer_create(NULL, &RNA_GameObjectSettings, ob, &settings_ptr);
+               RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
                uiItemR(row, &logic_ptr, "controllers_show_initial_state", UI_ITEM_R_NO_BG, "", 0);
                uiTemplateLayers(row, &settings_ptr, "state", &settings_ptr, "used_state", 0);
                
@@ -4346,7 +4346,7 @@ static void logic_buttons_new(bContext *C, ARegion *ar)
                uiItemS(layout);
                
                for(cont= ob->controllers.first; cont; cont=cont->next) {
-                       RNA_pointer_create(&ob->id, &RNA_Controller, cont, &ptr);
+                       RNA_pointer_create((ID *)ob, &RNA_Controller, cont, &ptr);
                        
                        if (!(ob->state & cont->state_mask))
                                continue;
@@ -4421,7 +4421,7 @@ static void logic_buttons_new(bContext *C, ARegion *ar)
                uiItemS(layout);
                
                for(sens= ob->sensors.first; sens; sens=sens->next) {
-                       RNA_pointer_create(&ob->id, &RNA_Sensor, sens, &ptr);
+                       RNA_pointer_create((ID *)ob, &RNA_Sensor, sens, &ptr);
                        
                        if ((slogic->scaflag & BUTS_SENS_STATE) ||
                                (sens->totlinks == 0) ||                                                                                        /* always display sensor without links so that is can be edited */
@@ -4480,7 +4480,7 @@ static void logic_buttons_new(bContext *C, ARegion *ar)
                
                for(act= ob->actuators.first; act; act=act->next) {
                        
-                       RNA_pointer_create(&ob->id, &RNA_Actuator, act, &ptr);
+                       RNA_pointer_create((ID *)ob, &RNA_Actuator, act, &ptr);
                        
                        if ((slogic->scaflag & BUTS_ACT_STATE) ||
                                !(act->flag & ACT_LINKED) ||            /* always display actuators without links so that is can be edited */
index fd96d1d41d75bafc3cb4a8679f06dc2ee1e39f8b..bb0a1ba2c525b8805016277bfd619c8937fc0afa 100644 (file)
@@ -75,12 +75,8 @@ extern EnumPropertyItem object_type_items[];
 
 extern EnumPropertyItem object_type_curve_items[];
 
-extern EnumPropertyItem sensor_type_items[];
-
 extern EnumPropertyItem controller_type_items[];
 
-extern EnumPropertyItem actuator_type_items[];
-
 extern EnumPropertyItem space_type_items[];
 
 extern EnumPropertyItem keymap_propvalue_items[];
@@ -97,6 +93,8 @@ extern EnumPropertyItem viewport_shading_items[];
 struct bContext;
 struct PointerRNA;
 EnumPropertyItem *rna_TransformOrientation_itemf(struct bContext *C, struct PointerRNA *ptr, int *free);
+EnumPropertyItem *rna_Sensor_type_itemf(struct bContext *C, struct PointerRNA *ptr, int *free);
+EnumPropertyItem *rna_Actuator_type_itemf(struct bContext *C, struct PointerRNA *ptr, int *free);
 
 /* Generic functions, return an enum from library data, index is the position
  * in the linked list can add more for different types as needed */
index ff735d35ade88144cd5ec932741e87bcae93b613..11995264c94e69acc725c05a3c76e7826f2aa419 100644 (file)
@@ -174,19 +174,27 @@ static EnumPropertyItem *rna_EditObjectActuator_mode_itemf(bContext *C, PointerR
        return item;
 }
 
-static EnumPropertyItem *rna_Actuator_type_itemf(bContext *C, PointerRNA *ptr, int *free)
+EnumPropertyItem *rna_Actuator_type_itemf(bContext *C, PointerRNA *ptr, int *free)
 {
        EnumPropertyItem *item= NULL;
-       Object *ob = (Object *)ptr->id.data;
-
+       Object *ob= NULL;
        int totitem= 0;
-       if (ob->type==OB_ARMATURE)
-       {
-               RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_ACTION);
-               RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_ARMATURE);
+       
+       if (ptr->type == &RNA_Actuator) {
+               ob = (Object *)ptr->id.data;
+       } else {
+               /* can't use ob from ptr->id.data because that enum is also used by operators */
+               ob = CTX_data_active_object(C);
+       }
+       
+       if (ob != NULL) {
+               if (ob->type==OB_ARMATURE) {
+                       RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_ACTION);
+                       RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_ARMATURE);
+               } else {
+                       RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_SHAPEACTION);
+               }
        }
-       else
-               RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_SHAPEACTION);
 
        RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_CAMERA);
        RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_CONSTRAINT);
index 5a52a779aee845f21039f65f78d81065aff881b6..c8407dfced28fc8421fe5f8561e5a1f0f9f6af07 100644 (file)
@@ -104,23 +104,31 @@ static void rna_Sensor_type_set(struct PointerRNA *ptr, int value)
        }
 }
 
-static EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, int *free)
+EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, int *free)
 {
        EnumPropertyItem *item= NULL;
-       Object *ob = (Object *)ptr->id.data;
-
+       Object *ob=NULL;
        int totitem= 0;
 
+       if (ptr->type == &RNA_Sensor) {
+               ob = (Object *)ptr->id.data;
+       } else {
+               /* can't use ob from ptr->id.data because that enum is also used by operators */
+               ob = CTX_data_active_object(C);
+       }
+       
        RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ACTUATOR);
        RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ALWAYS);
 
-       if (ob->type==OB_ARMATURE)
-               RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ARMATURE);
-       else if(ob->type==OB_MESH){
-               RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_COLLISION);
-               RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_TOUCH);
+       if (ob != NULL) {
+               if (ob->type==OB_ARMATURE) {
+                       RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ARMATURE);
+               } else if(ob->type==OB_MESH) {
+                       RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_COLLISION);
+                       RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_TOUCH);
+               }
        }
-
+       
        RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_DELAY);
        RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_JOYSTICK);
        RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_KEYBOARD);