2
0
Эх сурвалжийг харах

added tag as a string for easy editing

svifylabs 10 жил өмнө
parent
commit
997906d55e

+ 2 - 1
Source/Urho3D/AngelScript/APITemplates.h

@@ -761,7 +761,8 @@ template <class T> void RegisterNode(asIScriptEngine* engine, const char* classN
 	engine->RegisterObjectMethod(className, "bool HasTag(const StringHash&in)", asMETHOD(T, HasTag), asCALL_THISCALL);
 	engine->RegisterObjectMethod(className, "StringHash get_tag()", asMETHOD(T, GetTag), asCALL_THISCALL);
 	engine->RegisterObjectMethod(className, "void set_tag(const StringHash&in)", asMETHOD(T, SetTag), asCALL_THISCALL);
-
+	engine->RegisterObjectMethod(className, "const String& get_tagString()", asMETHOD(T, GetTagString), asCALL_THISCALL);
+	engine->RegisterObjectMethod(className, "void set_tagName(const String&in)", asMETHOD(T, SetTagString), asCALL_THISCALL);
 }
 
 static bool ResourceLoad(File* file, XMLFile* ptr)

+ 16 - 1
Source/Urho3D/Scene/Node.cpp

@@ -79,7 +79,8 @@ void Node::RegisterObject(Context* context)
 
     URHO3D_ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("Name", GetName, SetName, String, String::EMPTY, AM_DEFAULT);
-	URHO3D_ACCESSOR_ATTRIBUTE("Tag", GetTag, SetTag, StringHash, StringHash::ZERO, AM_DEFAULT);
+	URHO3D_ACCESSOR_ATTRIBUTE("Tag", GetTag, SetTag, StringHash, StringHash::ZERO, AM_DEFAULT | AM_NOEDIT);
+	URHO3D_ACCESSOR_ATTRIBUTE("TagString", GetTagString, SetTagString, String, String::EMPTY, AM_FILE | AM_EDIT);
 	URHO3D_ACCESSOR_ATTRIBUTE("Position", GetPosition, SetPosition, Vector3, Vector3::ZERO, AM_FILE);
     URHO3D_ACCESSOR_ATTRIBUTE("Rotation", GetRotation, SetRotation, Quaternion, Quaternion::IDENTITY, AM_FILE);
     URHO3D_ACCESSOR_ATTRIBUTE("Scale", GetScale, SetScale, Vector3, Vector3::ONE, AM_DEFAULT);
@@ -368,6 +369,13 @@ void Node::SetTag(const StringHash& tag)
 	}
 }
 
+void Node::SetTagString(const String & tag)
+{
+	StringHash id(tag);
+	tagString_ = tag;
+	SetTag(id);
+}
+
 void Node::SetPosition(const Vector3& position)
 {
     position_ = position;
@@ -1237,6 +1245,13 @@ const StringHash& Node::GetTag() const
 	return tag_;
 }
 
+const String & Node::GetTagString() const
+{
+	if (tagString_.Empty() && scene_)
+		return scene_->GetTagName(tag_);
+	return tagString_;
+}
+
 const Variant& Node::GetVar(StringHash key) const
 {
     VariantMap::ConstIterator i = vars_.Find(key);

+ 6 - 1
Source/Urho3D/Scene/Node.h

@@ -97,6 +97,8 @@ public:
     void SetName(const String& name);
 	/// Set tag for the scene node. 
 	void SetTag(const StringHash& tag);
+	/// Set tag string for the scene node. 
+	void SetTagString(const String& tag);
 	/// Set position in parent space. If the scene node is on the root level (is child of the scene itself), this is same as world space.
     void SetPosition(const Vector3& position);
 
@@ -309,7 +311,8 @@ public:
 
 	/// Return the tag.
 	const StringHash& GetTag() const;
-
+	/// Return the tag as a string.
+	const String& GetTagString() const;
     /// Return parent scene node.
     Node* GetParent() const { return parent_; }
 
@@ -651,6 +654,8 @@ private:
     String name_;
 	/// Tag.
 	StringHash tag_;
+	/// Tag String.
+	String tagString_;
     /// Name hash.
     StringHash nameHash_;
     /// Attribute buffer for network updates.