mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-05-09 22:41:39 +02:00
Added a type property to ModelVisualEntry, also it now hides the irrelevant properties based on it's type. Implemented handling of the attachment ModelVisuals in CharacterSkeleton3D. Also Small api change to CharacterSkeleton3D.
This commit is contained in:
parent
e93b99079d
commit
c3ac4bf02a
@ -24,6 +24,15 @@ SOFTWARE.
|
||||
|
||||
#include "../../singletons/ess.h"
|
||||
|
||||
const String ModelVisualEntry::BINDING_STRING_MODEL_VISUAL_ENTRY_TYPES = "Bone,Attachment";
|
||||
|
||||
ModelVisualEntry::ModenVisualEntryType ModelVisualEntry::get_type() const {
|
||||
return _type;
|
||||
}
|
||||
void ModelVisualEntry::set_type(const ModelVisualEntry::ModenVisualEntryType type) {
|
||||
_type = type;
|
||||
}
|
||||
|
||||
int ModelVisualEntry::get_override_layer() const {
|
||||
return _override_layer;
|
||||
}
|
||||
@ -116,6 +125,7 @@ void ModelVisualEntry::set_size(const int value) {
|
||||
}
|
||||
|
||||
ModelVisualEntry::ModelVisualEntry() {
|
||||
_type = MODEL_VISUAL_ENTRY_TYPE_BONE;
|
||||
_override_layer = 0;
|
||||
|
||||
_entity_type = 0;
|
||||
@ -209,35 +219,53 @@ bool ModelVisualEntry::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
}
|
||||
void ModelVisualEntry::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
for (int i = 0; i < _entries.size(); ++i) {
|
||||
if (_type == ModelVisualEntry::MODEL_VISUAL_ENTRY_TYPE_BONE) {
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource"));
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
|
||||
#endif
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
|
||||
p_list->push_back(PropertyInfo(Variant::COLOR, "entry_" + itos(i) + "/color"));
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/attachment", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"));
|
||||
p_list->push_back(PropertyInfo(Variant::TRANSFORM, "entry_" + itos(i) + "/transform"));
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
|
||||
p_list->push_back(PropertyInfo(Variant::COLOR, "entry_" + itos(i) + "/color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
|
||||
} else {
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/attachment", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
|
||||
}
|
||||
p_list->push_back(PropertyInfo(Variant::TRANSFORM, "entry_" + itos(i) + "/transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL));
|
||||
}
|
||||
}
|
||||
|
||||
void ModelVisualEntry::_validate_property(PropertyInfo &property) const {
|
||||
String name = property.name;
|
||||
|
||||
if (_type == ModelVisualEntry::MODEL_VISUAL_ENTRY_TYPE_BONE) {
|
||||
if (name == "entity_type") {
|
||||
property.usage = PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED;
|
||||
property.hint_string = ESS::get_singleton()->entity_types_get();
|
||||
} else if (name == "bone") {
|
||||
if (ESS::get_singleton()->skeletons_bones_count() > _entity_type) {
|
||||
property.hint_string = ESS::get_singleton()->skeletons_bones_index_get(_entity_type);
|
||||
} else {
|
||||
property.hint_string = "";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (name == "entity_type") {
|
||||
property.usage = PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED;
|
||||
} else if (name == "bone") {
|
||||
property.hint_string = EntityEnums::BINDING_STRING_COMMON_CHARCATER_SKELETON_POINTS;
|
||||
}
|
||||
}
|
||||
|
||||
if (name == "group") {
|
||||
property.hint_string = ESS::get_singleton()->model_visual_groups_get();
|
||||
} else if (name == "bone") {
|
||||
if (ESS::get_singleton()->skeletons_bones_count() > _entity_type) {
|
||||
property.hint_string = ESS::get_singleton()->skeletons_bones_index_get(_entity_type);
|
||||
} else {
|
||||
property.hint_string = "";
|
||||
}
|
||||
} else if (name == "entity_type") {
|
||||
property.hint_string = ESS::get_singleton()->entity_types_get();
|
||||
} else if (name == "override_layer") {
|
||||
property.hint_string = ESS::get_singleton()->texture_layers_get();
|
||||
}
|
||||
}
|
||||
|
||||
void ModelVisualEntry::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_type"), &ModelVisualEntry::get_type);
|
||||
ClassDB::bind_method(D_METHOD("set_type", "value"), &ModelVisualEntry::set_type);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, ModelVisualEntry::BINDING_STRING_MODEL_VISUAL_ENTRY_TYPES, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_type", "get_type");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_override_layer"), &ModelVisualEntry::get_override_layer);
|
||||
ClassDB::bind_method(D_METHOD("set_override_layer", "value"), &ModelVisualEntry::set_override_layer);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "override_layer", PROPERTY_HINT_ENUM, ""), "set_override_layer", "get_override_layer");
|
||||
@ -274,4 +302,7 @@ void ModelVisualEntry::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_size"), &ModelVisualEntry::get_size);
|
||||
ClassDB::bind_method(D_METHOD("set_size", "value"), &ModelVisualEntry::set_size);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_size", "get_size");
|
||||
|
||||
BIND_ENUM_CONSTANT(MODEL_VISUAL_ENTRY_TYPE_BONE);
|
||||
BIND_ENUM_CONSTANT(MODEL_VISUAL_ENTRY_TYPE_ATTACHMENT);
|
||||
}
|
||||
|
@ -42,6 +42,17 @@ class ModelVisualEntry : public Resource {
|
||||
GDCLASS(ModelVisualEntry, Resource);
|
||||
|
||||
public:
|
||||
enum ModenVisualEntryType {
|
||||
MODEL_VISUAL_ENTRY_TYPE_BONE = 0,
|
||||
MODEL_VISUAL_ENTRY_TYPE_ATTACHMENT
|
||||
};
|
||||
|
||||
static const String BINDING_STRING_MODEL_VISUAL_ENTRY_TYPES;
|
||||
|
||||
public:
|
||||
ModelVisualEntry::ModenVisualEntryType get_type() const;
|
||||
void set_type(const ModelVisualEntry::ModenVisualEntryType type);
|
||||
|
||||
int get_override_layer() const;
|
||||
void set_override_layer(const int layer);
|
||||
|
||||
@ -109,6 +120,7 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
ModelVisualEntry::ModenVisualEntryType _type;
|
||||
int _override_layer;
|
||||
|
||||
int _entity_type;
|
||||
@ -118,4 +130,6 @@ private:
|
||||
Vector<MVEE> _entries;
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(ModelVisualEntry::ModenVisualEntryType);
|
||||
|
||||
#endif
|
||||
|
@ -81,37 +81,37 @@ Node *CharacterSkeleton3D::common_attach_point_node_get(const EntityEnums::Commo
|
||||
|
||||
return _attach_point_nodes[common_attach_point_index_get(index)].node;
|
||||
}
|
||||
void CharacterSkeleton3D::common_attach_point_add_effect(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene) {
|
||||
void CharacterSkeleton3D::common_attach_point_add(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene) {
|
||||
int index = common_attach_point_index_get(point);
|
||||
|
||||
ERR_FAIL_INDEX(index, _attach_point_nodes.size());
|
||||
|
||||
Node *n = _attach_point_nodes[index].node;
|
||||
|
||||
if (INSTANCE_VALIDATE(n) && n->has_method("add_effect")) {
|
||||
n->call("add_effect", scene);
|
||||
if (INSTANCE_VALIDATE(n) && n->has_method("add")) {
|
||||
n->call("add", scene);
|
||||
}
|
||||
}
|
||||
void CharacterSkeleton3D::common_attach_point_add_effect_timed(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene, const float time) {
|
||||
void CharacterSkeleton3D::common_attach_point_add_timed(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene, const float time) {
|
||||
int index = common_attach_point_index_get(point);
|
||||
|
||||
ERR_FAIL_INDEX(index, _attach_point_nodes.size());
|
||||
|
||||
Node *n = _attach_point_nodes[index].node;
|
||||
|
||||
if (INSTANCE_VALIDATE(n) && n->has_method("add_effect_timed")) {
|
||||
n->call("add_effect_timed", scene, time);
|
||||
if (INSTANCE_VALIDATE(n) && n->has_method("add_timed")) {
|
||||
n->call("add_timed", scene, time);
|
||||
}
|
||||
}
|
||||
void CharacterSkeleton3D::common_attach_point_remove_effect(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene) {
|
||||
void CharacterSkeleton3D::common_attach_point_remove(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene) {
|
||||
int index = common_attach_point_index_get(point);
|
||||
|
||||
ERR_FAIL_INDEX(index, _attach_point_nodes.size());
|
||||
|
||||
Node *n = _attach_point_nodes[index].node;
|
||||
|
||||
if (INSTANCE_VALIDATE(n) && n->has_method("remove_effect")) {
|
||||
n->call("remove_effect", scene);
|
||||
if (INSTANCE_VALIDATE(n) && n->has_method("remove")) {
|
||||
n->call("remove", scene);
|
||||
}
|
||||
}
|
||||
int CharacterSkeleton3D::common_attach_point_index_get(const EntityEnums::CommonCharacterSkeletonPoints point) {
|
||||
@ -239,6 +239,20 @@ void CharacterSkeleton3D::add_model_visual_entry(Ref<ModelVisual> vis, Ref<Model
|
||||
ERR_FAIL_COND(!vis.is_valid());
|
||||
ERR_FAIL_COND(!ive.is_valid());
|
||||
|
||||
if (ive->get_type() == ModelVisualEntry::MODEL_VISUAL_ENTRY_TYPE_ATTACHMENT) {
|
||||
EntityEnums::CommonCharacterSkeletonPoints target_bone = static_cast<EntityEnums::CommonCharacterSkeletonPoints>(ive->get_bone());
|
||||
|
||||
for (int i = 0; i < ive->get_size(); ++i) {
|
||||
Ref<PackedScene> ps = ive->get_attachment(i);
|
||||
|
||||
if (ps.is_valid()) {
|
||||
common_attach_point_add(target_bone, ps);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int target_bone_idx = ive->get_bone();
|
||||
|
||||
Vector<Ref<SkeletonModelEntry> > &entries = _entries.write[target_bone_idx];
|
||||
@ -267,6 +281,20 @@ void CharacterSkeleton3D::remove_model_visual_entry(Ref<ModelVisual> vis, Ref<Mo
|
||||
ERR_FAIL_COND(!vis.is_valid());
|
||||
ERR_FAIL_COND(!ive.is_valid());
|
||||
|
||||
if (ive->get_type() == ModelVisualEntry::MODEL_VISUAL_ENTRY_TYPE_ATTACHMENT) {
|
||||
EntityEnums::CommonCharacterSkeletonPoints target_bone = static_cast<EntityEnums::CommonCharacterSkeletonPoints>(ive->get_bone());
|
||||
|
||||
for (int i = 0; i < ive->get_size(); ++i) {
|
||||
Ref<PackedScene> ps = ive->get_attachment(i);
|
||||
|
||||
if (ps.is_valid()) {
|
||||
common_attach_point_remove(target_bone, ps);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int target_bone_idx = ive->get_bone();
|
||||
|
||||
Vector<Ref<SkeletonModelEntry> > &entries = _entries.write[target_bone_idx];
|
||||
@ -555,9 +583,9 @@ void CharacterSkeleton3D::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo("_common_attach_point_index_get", PropertyInfo(Variant::INT, "point", PROPERTY_HINT_NONE, EntityEnums::BINDING_STRING_COMMON_CHARCATER_SKELETON_POINTS)));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("common_attach_point_node_get", "point"), &CharacterSkeleton3D::common_attach_point_node_get);
|
||||
ClassDB::bind_method(D_METHOD("common_attach_point_add_effect", "point", "scene"), &CharacterSkeleton3D::common_attach_point_add_effect);
|
||||
ClassDB::bind_method(D_METHOD("common_attach_point_add_effect_timed", "point", "scene", "time"), &CharacterSkeleton3D::common_attach_point_add_effect_timed);
|
||||
ClassDB::bind_method(D_METHOD("common_attach_point_remove_effect", "point", "scene"), &CharacterSkeleton3D::common_attach_point_remove_effect);
|
||||
ClassDB::bind_method(D_METHOD("common_attach_point_add", "point", "scene"), &CharacterSkeleton3D::common_attach_point_add);
|
||||
ClassDB::bind_method(D_METHOD("common_attach_point_add_timed", "point", "scene", "time"), &CharacterSkeleton3D::common_attach_point_add_timed);
|
||||
ClassDB::bind_method(D_METHOD("common_attach_point_remove", "point", "scene"), &CharacterSkeleton3D::common_attach_point_remove);
|
||||
ClassDB::bind_method(D_METHOD("common_attach_point_index_get", "point"), &CharacterSkeleton3D::common_attach_point_index_get);
|
||||
ClassDB::bind_method(D_METHOD("_common_attach_point_index_get", "point"), &CharacterSkeleton3D::_common_attach_point_index_get);
|
||||
|
||||
|
@ -69,9 +69,9 @@ public:
|
||||
int attach_point_count() const;
|
||||
|
||||
Node *common_attach_point_node_get(const EntityEnums::CommonCharacterSkeletonPoints point);
|
||||
void common_attach_point_add_effect(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene);
|
||||
void common_attach_point_add_effect_timed(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene, const float time);
|
||||
void common_attach_point_remove_effect(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene);
|
||||
void common_attach_point_add(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene);
|
||||
void common_attach_point_add_timed(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene, const float time);
|
||||
void common_attach_point_remove(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref<PackedScene> &scene);
|
||||
int common_attach_point_index_get(const EntityEnums::CommonCharacterSkeletonPoints point);
|
||||
virtual int _common_attach_point_index_get(const EntityEnums::CommonCharacterSkeletonPoints point);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user