diff options
author | Matt Ebb <matt@mke3.net> | 2010-05-25 10:24:45 +0400 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2010-05-25 10:24:45 +0400 |
commit | e26cc71bd0a4976c8adf8f6586a71de7ce1003d4 (patch) | |
tree | a96ed224505e4ee0e11b65fe1432e3f7a3d21717 /source/blender | |
parent | c9ac1cc9862730f6e20563fc034d825c9a6aff04 (diff) |
Tweaks to copy game properties operator for Dalai
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/object/object_edit.c | 96 |
1 files changed, 28 insertions, 68 deletions
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 4ab23f71e56..28b9fa241ca 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -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; |