Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2012-01-05 01:40:00 +0400
committerDalai Felinto <dfelinto@gmail.com>2012-01-05 01:40:00 +0400
commitbe025ea31985f7614106b47a519d6e678a19fb95 (patch)
tree369a126b807ff727a7faf624314e0389e5a9e5c5 /source/gameengine/Converter/KX_ConvertProperties.cpp
parent049ab984697aa277c476833670275624c4385257 (diff)
This patch creates an interface for ["Text"] properties in Font objects.
Interface: http://www.pasteall.org/pic/show.php?id=23785 Simple test file: http://www.pasteall.org/blend/10616 (I'll commit this to the text suite later) Code Explanation: --------------- (1) it adds a toggle to add/remove a "Text" gameproperty. - internally this property is just another game property (so we can find it within the game.properties lookup). - the property itself has no 'value', the interface shows the content of ob.data.body instead (why? because gameproperties are per object, while the text is per data). (2) at BGE converter time it sets the current value of the object.data.body to the ["Text"] property. (3) if you change object.text (bge text property) it automatically convert ["Text"] to a CStringValue. *** that means if the original property was a CIntegerValue, it will be converted to CStringValue forever *** * the only to do I can think of is to add a warning at doversion time if user has ["Text"] property for a Font object * * when that happens we print a warning in console/popup.*
Diffstat (limited to 'source/gameengine/Converter/KX_ConvertProperties.cpp')
-rw-r--r--source/gameengine/Converter/KX_ConvertProperties.cpp94
1 files changed, 94 insertions, 0 deletions
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;
+ }
+}
+