diff options
-rw-r--r-- | release/scripts/startup/bl_ui/space_logic.py | 25 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 17 | ||||
-rw-r--r-- | source/blender/editors/object/object_edit.c | 14 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_enum_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_property.c | 17 | ||||
-rw-r--r-- | source/gameengine/Converter/KX_ConvertProperties.cpp | 94 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_FontObject.cpp | 14 |
7 files changed, 172 insertions, 11 deletions
diff --git a/release/scripts/startup/bl_ui/space_logic.py b/release/scripts/startup/bl_ui/space_logic.py index 1fc58475ace..79a3f72ff48 100644 --- a/release/scripts/startup/bl_ui/space_logic.py +++ b/release/scripts/startup/bl_ui/space_logic.py @@ -20,6 +20,12 @@ import bpy from bpy.types import Header, Menu, Panel +def get_id_by_name(properties, name): + """returns ID""" + for i, prop in enumerate(properties): + if prop.name == name: + return i + return -1 class LOGIC_PT_properties(Panel): bl_space_type = 'LOGIC_EDITOR' @@ -37,10 +43,29 @@ class LOGIC_PT_properties(Panel): ob = context.active_object game = ob.game + if ob.type == 'FONT': + prop = game.properties.get("Text") + if prop: + layout.operator("object.game_property_remove", text="Text Game Property", icon='X').index = get_id_by_name(game.properties, "Text") + row = layout.row() + sub=row.row() + sub.enabled=0 + sub.prop(prop, "name", text="") + row.prop(prop, "type", text="") + # get the property from the body, not the game property + row.prop(ob.data, "body", text="") + else: + props=layout.operator("object.game_property_new", text="Text Game Property", icon='ZOOMIN') + props.name='Text' + props.type='STRING' + layout.operator("object.game_property_new", text="Add Game Property", icon='ZOOMIN') for i, prop in enumerate(game.properties): + if ob.type == 'FONT' and prop.name == "Text": + continue + box = layout.box() row = box.row() row.prop(prop, "name", text="") diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 59a34a706ee..6a15ec139c8 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -12833,6 +12833,23 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } } + { + /* Warn the user if he is using ["Text"] properties for Font objects */ + Object *ob; + bProperty *prop; + + for (ob= main->object.first; ob; ob= ob->id.next) { + if (ob->type == OB_FONT) { + for (prop=ob->prop.first;prop;prop=prop->next) { + if (strcmp(prop->name, "Text") == 0) { + BKE_reportf(fd->reports, RPT_WARNING, "Game property name conflict in object: \"%s\".\nText objects reserve the [\"Text\"] game property to change their content through Logic Bricks.\n", ob->id.name+2); + if(G.background==0) printf("Game property conflict in object: \"%s\". Texts reserve the [\"Text\"] game property to change their content through Logic Bricks.\n", ob->id.name+2); + break; + } + } + } + } + } } /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 658f4acf940..6e1a4ba6cf2 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -1936,16 +1936,23 @@ void ED_object_toggle_modes(bContext *C, int mode) /************************ Game Properties ***********************/ -static int game_property_new(bContext *C, wmOperator *UNUSED(op)) +static int game_property_new(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); bProperty *prop; + char name[32]; + int type= RNA_enum_get(op->ptr, "type"); if(!ob) return OPERATOR_CANCELLED; - prop= new_property(PROP_FLOAT); + prop= new_property(type); BLI_addtail(&ob->prop, prop); + + RNA_string_get(op->ptr, "name", name); + if(BLI_strnlen(name, 32) > 0) + BLI_strncpy(prop->name, name, sizeof(prop->name)); + unique_property(NULL, prop, 0); // make_unique_prop_names(prop->name); WM_event_add_notifier(C, NC_LOGIC, NULL); @@ -1966,6 +1973,9 @@ void OBJECT_OT_game_property_new(wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + RNA_def_enum(ot->srna, "type", gameproperty_type_items, 2, "Type", "Type of game property to add"); + RNA_def_string(ot->srna, "name", "", 32, "Name", "Name of the game property to add"); } static int game_property_remove(bContext *C, wmOperator *op) diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index 91e5d06fe5e..72917600d05 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -104,6 +104,8 @@ extern EnumPropertyItem property_type_items[]; extern EnumPropertyItem property_subtype_items[]; extern EnumPropertyItem property_unit_items[]; +extern EnumPropertyItem gameproperty_type_items[]; + extern EnumPropertyItem viewport_shade_items[]; extern EnumPropertyItem nodetree_type_items[]; diff --git a/source/blender/makesrna/intern/rna_property.c b/source/blender/makesrna/intern/rna_property.c index e8ef61b6d74..dfdc175d18b 100644 --- a/source/blender/makesrna/intern/rna_property.c +++ b/source/blender/makesrna/intern/rna_property.c @@ -35,6 +35,15 @@ #include "WM_types.h" +EnumPropertyItem gameproperty_type_items[] ={ + {GPROP_BOOL, "BOOL", 0, "Boolean", "Boolean Property"}, + {GPROP_INT, "INT", 0, "Integer", "Integer Property"}, + {GPROP_FLOAT, "FLOAT", 0, "Float", "Floating-Point Property"}, + {GPROP_STRING, "STRING", 0, "String", "String Property"}, + {GPROP_TIME, "TIMER", 0, "Timer", "Timer Property"}, + {0, NULL, 0, NULL, NULL}}; + + #ifdef RNA_RUNTIME #include "BKE_property.h" @@ -98,14 +107,6 @@ void RNA_def_gameproperty(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; - static EnumPropertyItem gameproperty_type_items[] ={ - {GPROP_BOOL, "BOOL", 0, "Boolean", "Boolean Property"}, - {GPROP_INT, "INT", 0, "Integer", "Integer Property"}, - {GPROP_FLOAT, "FLOAT", 0, "Float", "Floating-Point Property"}, - {GPROP_STRING, "STRING", 0, "String", "String Property"}, - {GPROP_TIME, "TIMER", 0, "Timer", "Timer Property"}, - {0, NULL, 0, NULL, NULL}}; - /* Base Struct for GameProperty */ srna= RNA_def_struct(brna, "GameProperty", NULL); RNA_def_struct_ui_text(srna , "Game Property", "Game engine user defined object property"); diff --git a/source/gameengine/Converter/KX_ConvertProperties.cpp b/source/gameengine/Converter/KX_ConvertProperties.cpp index 7a574276eb4..03d9be0d909 100644 --- a/source/gameengine/Converter/KX_ConvertProperties.cpp +++ b/source/gameengine/Converter/KX_ConvertProperties.cpp @@ -48,11 +48,18 @@ #include "SCA_TimeEventManager.h" #include "SCA_IScene.h" +#include "KX_FontObject.h" +#include "DNA_curve_types.h" + /* This little block needed for linking to Blender... */ #ifdef WIN32 #include "BLI_winstuff.h" #endif + +/* prototype */ +void BL_ConvertTextProperty(Object* object, KX_FontObject* fontobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer); + void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer) { @@ -155,4 +162,91 @@ void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventMan // reserve name for object state scene->AddDebugProperty(gameobj,STR_String("__state__")); } + + /* Font Objects need to 'copy' the Font Object data body to ["Text"] */ + if (object->type == OB_FONT) + { + BL_ConvertTextProperty(object, (KX_FontObject *)gameobj, timemgr, scene, isInActiveLayer); + } } + +void BL_ConvertTextProperty(Object* object, KX_FontObject* fontobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer) +{ + CValue* tprop = fontobj->GetProperty("Text"); + if(!tprop) return; + + Curve *curve = static_cast<Curve *>(object->data); + STR_String str = curve->str; + + bProperty* prop = (bProperty*)object->prop.first; + CValue* propval; + + while(prop) + { + if (strcmp(prop->name, "Text")!=0) { + prop = prop->next; + continue; + } + + propval = NULL; + + switch(prop->type) { + case GPROP_BOOL: + { + int value = atoi(str); + propval = new CBoolValue((bool)(value != 0)); + tprop->SetValue(propval); + break; + } + case GPROP_INT: + { + int value = atoi(str); + propval = new CIntValue(value); + tprop->SetValue(propval); + break; + } + case GPROP_FLOAT: + { + float floatprop = atof(str); + propval = new CFloatValue(floatprop); + tprop->SetValue(propval); + break; + } + case GPROP_STRING: + { + propval = new CStringValue(str, ""); + tprop->SetValue(propval); + break; + } + case GPROP_TIME: + { + float floatprop = atof(str); + + CValue* timeval = new CFloatValue(floatprop); + // set a subproperty called 'timer' so that + // we can register the replica of this property + // at the time a game object is replicated (AddObjectActuator triggers this) + CValue *bval = new CBoolValue(true); + timeval->SetProperty("timer",bval); + bval->Release(); + if (isInActiveLayer) + { + timemgr->AddTimeProperty(timeval); + } + + propval = timeval; + tprop->SetValue(timeval); + } + default: + { + // todo make an assert etc. + } + } + + if (propval) + propval->Release(); + + prop = prop->next; + } +} + diff --git a/source/gameengine/Ketsji/KX_FontObject.cpp b/source/gameengine/Ketsji/KX_FontObject.cpp index 5a4d9065605..c20015945aa 100644 --- a/source/gameengine/Ketsji/KX_FontObject.cpp +++ b/source/gameengine/Ketsji/KX_FontObject.cpp @@ -34,6 +34,7 @@ #include "KX_Scene.h" #include "KX_PythonInit.h" #include "BLI_math.h" +#include "StringValue.h" extern "C" { #include "BLF_api.h" @@ -224,7 +225,18 @@ int KX_FontObject::pyattr_set_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrd if(!PyUnicode_Check(value)) return PY_SET_ATTR_FAIL; char* chars = _PyUnicode_AsString(value); - self->m_text = split_string(STR_String(chars)); + + /* Allow for some logic brick control */ + CValue* tprop = self->GetProperty("Text"); + if(tprop) { + CValue *newstringprop = new CStringValue(STR_String(chars), "Text"); + self->SetProperty("Text", newstringprop); + newstringprop->Release(); + } + else { + self->m_text = split_string(STR_String(chars)); + } + return PY_SET_ATTR_SUCCESS; } |