Tweaks to copy game properties operator for Dalai
authorMatt Ebb <matt@mke3.net>
Tue, 25 May 2010 06:24:45 +0000 (06:24 +0000)
committerMatt Ebb <matt@mke3.net>
Tue, 25 May 2010 06:24:45 +0000 (06:24 +0000)
release/scripts/ui/space_view3d.py
source/blender/editors/object/object_edit.c

index 538a13536bcdac0771312e3eaeda7b6a979537a3..8f44d00581faa0c47df0cf91b520415a4d4cf95e 100644 (file)
@@ -675,6 +675,7 @@ class VIEW3D_MT_object(bpy.types.Menu):
         layout.menu("VIEW3D_MT_object_track")
         layout.menu("VIEW3D_MT_object_group")
         layout.menu("VIEW3D_MT_object_constraints")
+        layout.menu("VIEW3D_MT_object_game_properties")
 
         layout.separator()
 
@@ -843,6 +844,17 @@ class VIEW3D_MT_make_links(bpy.types.Menu):
         layout.operator_enums("object.make_links_data", "type") # inline
 
 
+class VIEW3D_MT_object_game_properties(bpy.types.Menu):
+    bl_label = "Game Properties"
+
+    def draw(self, context):
+        layout = self.layout
+
+        layout.operator("object.game_property_copy", text="Replace").operation="REPLACE"
+        layout.operator("object.game_property_copy", text="Merge").operation="MERGE"
+        # layout.operator("object.game_property_copy").operation="CLEAR" doesn't really belong as part of copy...
+        layout.operator_menu_enum("object.game_property_copy", "property", text="Copy...")
+
 # ********** Vertex paint menu **********
 
 
@@ -2208,6 +2220,7 @@ classes = [
     VIEW3D_MT_object_track,
     VIEW3D_MT_object_group,
     VIEW3D_MT_object_constraints,
+    VIEW3D_MT_object_game_properties,
     VIEW3D_MT_object_showhide,
     VIEW3D_MT_make_single_user,
     VIEW3D_MT_make_links,
index 4ab23f71e565e0dbef65eb89797be0b70ea80314..28b9fa241cacc9f45f35cf068ed02292f0aaa087 100644 (file)
@@ -2173,13 +2173,11 @@ static int game_property_remove(bContext *C, wmOperator *op)
 {
        Object *ob= CTX_data_active_object(C);
        bProperty *prop;
-       int index;
+       int index= RNA_int_get(op->ptr, "index");
 
        if(!ob)
                return OPERATOR_CANCELLED;
 
-       index = RNA_int_get(op->ptr, "index");
-
        prop= BLI_findlink(&ob->prop, index);
 
        if(prop) {
@@ -2207,52 +2205,25 @@ void OBJECT_OT_game_property_remove(wmOperatorType *ot)
 
        RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to remove ", 0, INT_MAX);
 }
-static EnumPropertyItem game_properties_copy_types[] ={
-       {1, "REPLACE", 0, "Replace Properties", ""},
-       {2, "MERGE", 0, "Merge Properties", ""},
-       {3, "CLEAR", 0, "Clear All", ""},
-       {4, "COPY", 0, "Copy a Property", ""},
-       {0, NULL, 0, NULL, NULL}};
-
-static int game_property_copy_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       Object *ob= CTX_data_active_object(C);
-       bProperty *prop;        
-       int tot=0;
-       uiPopupMenu *pup;
-       uiLayout *menu;
-
-       /* count number of available properties */      
-       prop= ob->prop.first;
-       while(prop) {
-               tot++;
-               prop= prop->next;
-       }
 
-       /* start building */
-       pup= uiPupMenuBegin(C, op->type->name, 0);
-       menu= uiPupMenuLayout(pup);
-       uiLayoutSetOperatorContext(menu, WM_OP_EXEC_DEFAULT);
+#define COPY_PROPERTIES_REPLACE        1
+#define COPY_PROPERTIES_MERGE  2
+#define COPY_PROPERTIES_CLEAR  3
+#define COPY_PROPERTIES_COPY   4
 
-       if(!tot)
-               uiItemEnumO(menu, "OBJECT_OT_game_property_copy", NULL, 0, "type", 3);//CLEAR);
-       else {
-               uiItemEnumO(menu, "OBJECT_OT_game_property_copy", NULL, 0, "type", 1);//REPLACE);
-               uiItemEnumO(menu, "OBJECT_OT_game_property_copy", NULL, 0, "type", 2);//MERGE);
-               uiItemMenuEnumO(menu, "OBJECT_OT_game_property_copy", "property", "Copy Property", 0);//COPY
-       }
-       uiPupMenuEnd(C, pup);
-
-       /* this operator is only for a menu, not used further */
-       return OPERATOR_CANCELLED;
-}
+static EnumPropertyItem game_properties_copy_operations[] ={
+       {COPY_PROPERTIES_REPLACE, "REPLACE", 0, "Replace Properties", ""},
+       {COPY_PROPERTIES_MERGE, "MERGE", 0, "Merge Properties", ""},
+       {COPY_PROPERTIES_CLEAR, "CLEAR", 0, "Clear All", ""},
+       {COPY_PROPERTIES_COPY, "COPY", 0, "Copy a Property", ""},
+       {0, NULL, 0, NULL, NULL}};
 
 static EnumPropertyItem gameprops_items[]= {
        {0, NULL, 0, NULL, NULL}};
 
 static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *ptr, int *free)
 {      
-       Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       Object *ob= ED_object_active_context(C);
        EnumPropertyItem tmp = {0, "", 0, "", ""};
        EnumPropertyItem *item= NULL;
        bProperty *prop;
@@ -2278,21 +2249,22 @@ static int game_property_copy_exec(bContext *C, wmOperator *op)
 {
        Object *ob=ED_object_active_context(C);
        bProperty *prop;
-
-       int tmp_int; //need an int pointer to pass for the RNA_enum_name
-       EnumPropertyItem *dyn_props= NULL;
-       const char *prop_name= NULL;
-
-       int type = RNA_enum_get(op->ptr, "type");
+       int type = RNA_enum_get(op->ptr, "operation");
        int propid= RNA_enum_get(op->ptr, "property");
 
-       // recreate the dynamic enum with the properties        
-       dyn_props = gameprops_itemf(C, NULL, &tmp_int);
-
-       if (propid > 0)
-               RNA_enum_name(dyn_props, propid, &prop_name);
-
-       if ( type == 1 || type == 2 || type == 3) {
+       if(propid > 0) { /* copy */
+               prop = BLI_findlink(&ob->prop, propid-1);
+               
+               if(prop) {
+                       CTX_DATA_BEGIN(C, Object*, ob_iter, selected_editable_objects) {
+                               if (ob != ob_iter) {
+                                       if (ob->data != ob_iter->data)
+                                               set_ob_property(ob_iter, prop);
+                               }
+                       } CTX_DATA_END;
+               }
+       }
+       else if (ELEM3(type, COPY_PROPERTIES_REPLACE, COPY_PROPERTIES_MERGE, COPY_PROPERTIES_CLEAR)) {
                CTX_DATA_BEGIN(C, Object*, ob_iter, selected_editable_objects) {
                        if (ob != ob_iter) {
                                if (ob->data != ob_iter->data){
@@ -2307,18 +2279,7 @@ static int game_property_copy_exec(bContext *C, wmOperator *op)
                }
                CTX_DATA_END;
        }
-       else if(prop_name) { /* copy */
-               prop = (bProperty *) BLI_findstring(&ob->prop, prop_name, offsetof(bProperty, name));
-               
-               if(prop) {
-                       CTX_DATA_BEGIN(C, Object*, ob_iter, selected_editable_objects) {
-                               if (ob != ob_iter) {
-                                       if (ob->data != ob_iter->data)
-                                               set_ob_property(ob_iter, prop);
-                               }
-                       } CTX_DATA_END;
-               }
-       }
+
        return OPERATOR_FINISHED;
 }
 
@@ -2330,14 +2291,13 @@ void OBJECT_OT_game_property_copy(wmOperatorType *ot)
        ot->idname= "OBJECT_OT_game_property_copy";
 
        /* api callbacks */
-       ot->invoke= game_property_copy_invoke;
        ot->exec= game_property_copy_exec;
        ot->poll= ED_operator_object_active_editable;
 
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
-       RNA_def_enum(ot->srna, "type", game_properties_copy_types, 4, "Operation", "");
+       RNA_def_enum(ot->srna, "operation", game_properties_copy_operations, 4, "Operation", "");
        prop=RNA_def_enum(ot->srna, "property", gameprops_items, 0, "Property", "Properties to copy");
        RNA_def_enum_funcs(prop, gameprops_itemf);
        ot->prop=prop;