Exemple #1
0
 public override void SetMetaData(Dictionary <FName, string> metadata)
 {
     if (Flags.HasFlag(PropFlags.Instanced))
     {
         metadata[UMeta.GetKeyName(MDProp.EditInline)] = "true";
     }
 }
Exemple #2
0
        private static void SetAllMetaData(IntPtr obj, ManagedUnrealReflectionBase field, UMeta.Target target)
        {
            if (!FBuild.WithEditor || !metaDataEnabled || field == null || string.IsNullOrEmpty(field.Path))
            {
                return;
            }

            IntPtr outermost = Native_UObjectBaseUtility.GetOutermost(obj);
            IntPtr metadata  = outermost == IntPtr.Zero ? IntPtr.Zero : Native_UPackage.GetMetaData(outermost);

            if (metadata == IntPtr.Zero)
            {
                return;
            }

            Dictionary <FName, string> values = null;

            if (!metaDataMap.TryGetValue(field.Path.ToLower(), out values))
            {
                values = new Dictionary <FName, string>();
            }

            switch (target)
            {
            // Class / interface
            case UMeta.Target.Class:
            case UMeta.Target.Interface:
                // See GetMetadataKeyword (Engine\Source\Programs\UnrealHeaderTool\Private\BaseParser.cpp)
                // "NotBlueprintable" removes "NotBlueprintable" and adds "IsBlueprintBase=false"
                // "Blueprintable" and adds "IsBlueprintBase=true"
                // "BlueprintInternalUseOnly" adds "BlueprintType"

                if (!values.ContainsKey(UMeta.GetKeyName(MDClass.IsBlueprintBase)))
                {
                    if (values.ContainsKey(UMeta.GetKeyName(MDClass.Blueprintable)))
                    {
                        values[UMeta.GetKeyName(MDClass.IsBlueprintBase)] = "true";
                    }
                    else if (values.ContainsKey(UMeta.GetKeyName(MDClass.NotBlueprintable)))
                    {
                        values[UMeta.GetKeyName(MDClass.IsBlueprintBase)] = "false";
                    }
                }

                MetaDataMergeClassCategories(metadata, obj, values);
                break;
            }
            SetMetaDataBlueprintability(values, target, field as ManagedUnrealTypeInfo);

            using (TArrayUnsafe <FName> keysUnsafe = new TArrayUnsafe <FName>())
                using (TArrayUnsafe <string> valuesUnsafe = new TArrayUnsafe <string>())
                {
                    keysUnsafe.AddRange(values.Keys.ToArray());
                    valuesUnsafe.AddRange(values.Values.ToArray());
                    Native_UMetaData.SetObjectValues(metadata, obj, keysUnsafe.Address, valuesUnsafe.Address);
                }
        }
Exemple #3
0
 private static void SetOrClearMetaDataClassCollection(MDClass key, Dictionary <FName, string> values, HashSet <string> collection)
 {
     if (collection.Count > 0)
     {
         values[UMeta.GetKeyName(key)] = string.Join(" ", collection);
     }
     else
     {
         values.Remove(UMeta.GetKeyName(key));
     }
 }
        public static void SetMetaData <TEnum, T>(this UField field, TEnum key, T value) where TEnum : struct
        {
            string valueStr    = null;
            UClass unrealClass = value as UClass;

            if (unrealClass != null)
            {
                valueStr = unrealClass.GetPathName();
            }
            else
            {
                valueStr = value.ToString();
            }

            field.SetMetaData(UMeta.GetKey(key), valueStr);
        }
 public override void SetMetaData(Dictionary <FName, string> metadata)
 {
     // HeaderParser.cpp just adds an empty string for tagged functions so this should be fine
     metadata[UMeta.GetKeyName(MDFunc.BlueprintSetter)] = FunctionName;
 }
 public UMetaAttribute(MDFunc key, int value)
     : this(UMeta.GetKey(key), value.ToString())
 {
 }
 public static bool GetBoolMetaData <TEnum>(this UField field, TEnum key) where TEnum : struct
 {
     return(field.GetBoolMetaData(UMeta.GetKey(key)));
 }
Exemple #8
0
        private void AppendAttribute(CSharpTextBuilder builder, UField field, UnrealModuleInfo module, bool isCollapsedMember)
        {
            UnrealModuleType moduleType;
            UnrealModuleType moduleAssetType;
            string           moduleName = GetModuleName(field, out moduleType, out moduleAssetType);

            if (string.IsNullOrEmpty(moduleName))
            {
                moduleName = module.Name;
            }

            List <string> attributes = new List <string>();

            // TODO: Combine all of this into EPropertyType (add some TypeCode into UField?)
            bool          isInterface  = false;
            UEnum         unrealEnum   = field as UEnum;
            UClass        unrealClass  = field as UClass;
            UScriptStruct unrealStruct = field as UScriptStruct;

            UFunction unrealFunction = field as UFunction;

            if (unrealFunction != null)
            {
                if (unrealFunction.HasAnyFunctionFlags(EFunctionFlags.Delegate))
                {
                    attributes.Add("UDelegate");
                }
                else
                {
                    if (isCollapsedMember)
                    {
                        // The Flags here might not contain too useful information if there is both a get/set function.
                        // Maybe include a second flags var?
                        attributes.Add("UFunctionAsProp(Flags=0x" + ((uint)unrealFunction.FunctionFlags).ToString("X8") + ")");
                    }
                    else
                    {
                        attributes.Add("UFunction(Flags=0x" + ((uint)unrealFunction.FunctionFlags).ToString("X8") + ")");
                    }
                }
            }

            UProperty unrealProperty = field as UProperty;

            if (unrealProperty != null)
            {
                attributes.Add("UProperty(Flags=(PropFlags)0x" + ((ulong)unrealProperty.PropertyFlags).ToString("X16") + ")");
            }

            if (unrealStruct != null)
            {
                attributes.Add("UStruct(Flags=0x" + ((uint)unrealStruct.StructFlags).ToString("X8") + ")");
            }
            else if (unrealClass != null)
            {
                // Abstract isn't really required but might help with code browsing to know what is abstract
                // and what isn't. Therefore put it at the start of the attributes list.
                if (unrealClass.HasAnyClassFlags(EClassFlags.Abstract))
                {
                    attributes.Add("Abstract");
                }

                isInterface = unrealClass.IsChildOf <UInterface>();
                if (isInterface)
                {
                    attributes.Add("UInterface(Flags=0x" + ((uint)unrealClass.ClassFlags).ToString("X8") + ")");
                }
                else
                {
                    // Should we skip "inherit" config name?
                    string configNameStr = string.Empty;
                    if (unrealClass.ClassConfigName != FName.None &&
                        !unrealClass.ClassConfigName.ToString().Equals("inherit", StringComparison.InvariantCultureIgnoreCase))
                    {
                        configNameStr = ", Config=\"" + unrealClass.ClassConfigName + "\"";
                    }

                    attributes.Add("UClass(Flags=(ClassFlags)0x" + ((uint)unrealClass.ClassFlags).ToString("X8") +
                                   configNameStr + ")");
                }
            }

            if (unrealEnum != null)
            {
                attributes.Add("UEnum");
            }

            if (unrealEnum != null || unrealClass != null || unrealStruct != null)
            {
                bool blueprintType = false;
                bool blueprintable = false;
                if (unrealEnum != null)
                {
                    blueprintType = field.GetBoolMetaData(MDClass.BlueprintType);
                }
                else
                {
                    GetBlueprintability(field as UStruct, out blueprintType, out blueprintable);
                }
                if (blueprintType)
                {
                    attributes.Add(UMeta.GetKey(MDClass.BlueprintType));
                }
                if (unrealClass != null && blueprintable)
                {
                    attributes.Add(UMeta.GetKey(MDClass.Blueprintable));
                }

                if (isInterface)
                {
                }

                attributes.Add("UMetaPath(\"" + field.GetPathName() + "\", \"" + moduleName +
                               "\", UnrealModuleType." + GetUnrealModuleTypeString(moduleType, moduleAssetType) +
                               (isInterface ? ", InterfaceImpl=typeof(" + GetTypeName(unrealClass, null) + "Impl" + ")" : string.Empty) + ")");
            }
            else
            {
                attributes.Add("UMetaPath(\"" + field.GetPathName() + "\")");
            }

            if (attributes.Count > 0)
            {
                builder.AppendLine("[" + string.Join(", ", attributes) + "]");
            }
        }
 public UMetaAttribute(MDInterface key, int value)
     : this(UMeta.GetKey(key), value.ToString())
 {
 }
        //////////////////////////////////////////////////////
        // MDInterface
        //////////////////////////////////////////////////////

        public UMetaAttribute(MDInterface key, string value)
            : this(UMeta.GetKey(key), value)
        {
        }
 public UMetaAttribute(MDEnum key, bool value)
     : this(UMeta.GetKey(key), value.ToString())
 {
 }
 public static bool GeStringMetaDataHierarchical <TEnum>(this UStruct unrealStruct, TEnum key) where TEnum : struct
 {
     return(unrealStruct.GeStringMetaDataHierarchical(new FName(UMeta.GetKey(key))));
 }
 public static UClass GetClassMetaData <TEnum>(this UField field, TEnum key) where TEnum : struct
 {
     return(field.GetClassMetaData(UMeta.GetKey(key)));
 }
 public static float GetFloatMetaData <TEnum>(this UField field, TEnum key) where TEnum : struct
 {
     return(field.GetFloatMetaData(UMeta.GetKey(key)));
 }
Exemple #15
0
 public override void SetMetaData(Dictionary <FName, string> metadata)
 {
     metadata[UMeta.GetKeyName(MDProp.ExposeOnSpawn)] = "true";
 }
Exemple #16
0
        private static void MetaDataMergeClassCategories(IntPtr metadata, IntPtr obj, Dictionary <FName, string> values)
        {
            // Copying the logic in FClassDeclarationMetaData::MergeClassCategories
            // Engine\Source\Programs\UnrealHeaderTool\Private\ClassDeclarationMetaData.cpp
            // ShowFunctions HideFunctions
            // HideCategories ShowCategories ShowSubCatgories
            // AutoExpandCategories AutoCollapseCategories

            // - How is ShowFunctions / HideFunctions used? Hiding a function doesn't seem to hide it from being
            //   visible in the actions list in Blueprint. If it isn't super important we could skip it.
            // - ShowCategories / HideCategories is important

            // Maybe cache these lists and clear them for each type
            HashSet <string> showCategories             = new HashSet <string>();
            HashSet <string> hideCategories             = new HashSet <string>();
            HashSet <string> showSubCategories          = new HashSet <string>();
            HashSet <string> showFunctions              = new HashSet <string>();
            HashSet <string> hideFunctions              = new HashSet <string>();
            HashSet <string> autoExpandCategories       = new HashSet <string>();
            HashSet <string> autoCollapseCategories     = new HashSet <string>();
            HashSet <string> dontAutoCollapseCategories = new HashSet <string>();
            HashSet <string> classGroupNames            = new HashSet <string>();

            GetMetaDataItems(UMeta.GetKeyName(MDClass.ShowCategories), values, showCategories);
            GetMetaDataItems(UMeta.GetKeyName(MDClass.HideCategories), values, hideCategories);
            GetMetaDataItems(UMeta.GetKeyName(MDClass.ShowFunctions), values, showFunctions);
            GetMetaDataItems(UMeta.GetKeyName(MDClass.HideFunctions), values, hideFunctions);
            GetMetaDataItems(UMeta.GetKeyName(MDClass.AutoExpandCategories), values, autoExpandCategories);
            GetMetaDataItems(UMeta.GetKeyName(MDClass.AutoCollapseCategories), values, autoCollapseCategories);
            GetMetaDataItems(UMeta.GetKeyName(MDClass.DontAutoCollapseCategories), values, dontAutoCollapseCategories);
            GetMetaDataItems(UMeta.GetKeyName(MDClass.ClassGroupNames), values, classGroupNames);

            IntPtr           parentClass                  = Native_UClass.GetSuperClass(obj);
            HashSet <string> parentHideCategories         = new HashSet <string>();
            HashSet <string> parentShowSubCatgories       = new HashSet <string>();
            HashSet <string> parentHideFunctions          = new HashSet <string>();
            HashSet <string> parentAutoExpandCategories   = new HashSet <string>();
            HashSet <string> parentAutoCollapseCategories = new HashSet <string>();

            GetParentMetaDataItems(metadata, parentClass, UMeta.GetKeyName(MDClass.HideCategories), parentHideCategories);
            GetParentMetaDataItems(metadata, parentClass, UMeta.GetKeyName(MDClass.ShowCategories), parentShowSubCatgories);
            GetParentMetaDataItems(metadata, parentClass, UMeta.GetKeyName(MDClass.HideFunctions), parentHideFunctions);
            GetParentMetaDataItems(metadata, parentClass, UMeta.GetKeyName(MDClass.AutoExpandCategories), parentAutoExpandCategories);
            GetParentMetaDataItems(metadata, parentClass, UMeta.GetKeyName(MDClass.AutoCollapseCategories), parentAutoCollapseCategories);

            // Add parent categories. We store the opposite of HideCategories and HideFunctions in a separate array anyway.
            MetaDataMergeCollection(hideCategories, parentHideCategories);
            MetaDataMergeCollection(showSubCategories, parentShowSubCatgories);
            MetaDataMergeCollection(hideFunctions, parentHideFunctions);

            MetaDataMergeShowCategories(showCategories, hideCategories, showSubCategories);

            // Merge ShowFunctions and HideFunctions
            foreach (string value in showFunctions)
            {
                hideFunctions.Remove(value);
            }
            //showFunctions.Clear();

            // Merge DontAutoCollapseCategories and AutoCollapseCategories
            foreach (string value in dontAutoCollapseCategories)
            {
                autoCollapseCategories.Remove(value);
            }
            //dontAutoCollapseCategories.Clear();

            // The original function then merges ShowFunctions / HideFunctions again? (ShowFunctions will now be empty)

            // Merge AutoExpandCategories and AutoCollapseCategories (we still want to keep AutoExpandCategories though!)
            foreach (string value in autoExpandCategories)
            {
                autoCollapseCategories.Remove(value);
                parentAutoCollapseCategories.Remove(value);
            }

            // Do the same as above but the other way around
            foreach (string value in autoCollapseCategories)
            {
                autoExpandCategories.Remove(value);
                parentAutoExpandCategories.Remove(value);
            }

            // Once AutoExpandCategories and AutoCollapseCategories for THIS class have been parsed, add the parent inherited categories
            MetaDataMergeCollection(autoCollapseCategories, parentAutoCollapseCategories);
            MetaDataMergeCollection(autoExpandCategories, parentAutoExpandCategories);

            SetOrClearMetaDataClassCollection(MDClass.ClassGroupNames, values, classGroupNames);
            SetOrClearMetaDataClassCollection(MDClass.AutoCollapseCategories, values, autoCollapseCategories);
            SetOrClearMetaDataClassCollection(MDClass.HideCategories, values, hideCategories);
            SetOrClearMetaDataClassCollection(MDClass.ShowCategories, values, showSubCategories);
            SetOrClearMetaDataClassCollection(MDClass.HideFunctions, values, hideFunctions);
            SetOrClearMetaDataClassCollection(MDClass.AutoExpandCategories, values, autoExpandCategories);
        }
 public UMetaAttribute(MD key, float value)
     : this(UMeta.GetKey(key), value.ToString())
 {
 }
Exemple #18
0
        private static void SetMetaDataBlueprintability(Dictionary <FName, string> values, UMeta.Target target,
                                                        ManagedUnrealTypeInfo typeInfo)
        {
            ManagedUnrealVisibility.Type defaultTypeVisibility = ManagedUnrealVisibility.Type.None;
            switch (target)
            {
            case UMeta.Target.Class:
                defaultTypeVisibility = ManagedUnrealVisibility.Class;
                break;

            case UMeta.Target.Interface:
                defaultTypeVisibility = ManagedUnrealVisibility.Interface;
                break;

            case UMeta.Target.Struct:
                defaultTypeVisibility = ManagedUnrealVisibility.Struct;
                break;

            case UMeta.Target.Enum:
                defaultTypeVisibility = ManagedUnrealVisibility.Enum;
                break;

            default:
                return;
            }
            if (defaultTypeVisibility == ManagedUnrealVisibility.Type.None)
            {
                return;
            }

            // Use whatever state is in typeInfo if default state is enabled. It should have been resolved
            // properly for our managed type (if the state was defined on a native type the default state config
            // should have overridden it)

            if (defaultTypeVisibility.HasFlag(ManagedUnrealVisibility.Type.BlueprintType))
            {
                if (typeInfo.AdditionalFlags.HasFlag(ManagedUnrealTypeInfoFlags.BlueprintTypeHierarchical))
                {
                    values[UMeta.GetKeyName(MDClass.BlueprintType)] = "true";
                    values.Remove(UMeta.GetKeyName(MDClass.NotBlueprintType));
                }
                else
                {
                    values[UMeta.GetKeyName(MDClass.NotBlueprintType)] = "true";
                    values.Remove(UMeta.GetKeyName(MDClass.BlueprintType));
                }
            }

            if (defaultTypeVisibility.HasFlag(ManagedUnrealVisibility.Type.Blueprintable))
            {
                if (typeInfo.AdditionalFlags.HasFlag(ManagedUnrealTypeInfoFlags.BlueprintableHierarchical))
                {
                    values[UMeta.GetKeyName(MDClass.Blueprintable)]   = "true";
                    values[UMeta.GetKeyName(MDClass.IsBlueprintBase)] = "true";
                    values.Remove(UMeta.GetKeyName(MDClass.NotBlueprintable));
                }
                else
                {
                    values[UMeta.GetKeyName(MDClass.NotBlueprintType)] = "true";
                    values[UMeta.GetKeyName(MDClass.IsBlueprintBase)]  = "false";
                    values.Remove(UMeta.GetKeyName(MDClass.Blueprintable));
                }
            }
        }
 public UMetaAttribute(MD key, UClass value)
     : this(UMeta.GetKey(key), value == null ? string.Empty : value.GetPathName())
 {
 }
        private void AppendAttribute(CSharpTextBuilder builder, UField field, UnrealModuleInfo module, bool isCollapsedMember)
        {
            UnrealModuleType moduleType;
            UnrealModuleType moduleAssetType;
            string           moduleName = GetModuleName(field, out moduleType, out moduleAssetType);

            if (string.IsNullOrEmpty(moduleName))
            {
                moduleName = module.Name;
            }

            List <string> attributes = new List <string>();

            // TODO: Combine all of this into EPropertyType (add some TypeCode into UField?)
            bool          isInterface  = false;
            UEnum         unrealEnum   = field as UEnum;
            UClass        unrealClass  = field as UClass;
            UScriptStruct unrealStruct = field as UScriptStruct;

            UFunction unrealFunction = field as UFunction;

            if (unrealFunction != null)
            {
                if (unrealFunction.HasAnyFunctionFlags(EFunctionFlags.Delegate))
                {
                    attributes.Add("UDelegate");
                }
                else
                {
                    string additionalFunctionInfo = string.Empty;

                    // TODO: Only get the script name for virtual functions / interface functions as we currently only need
                    //       this for finding the base function for hooking things up to the native base types.
                    string scriptFunctionName;
                    if (unrealFunction.GetScriptName(out scriptFunctionName))
                    {
                        additionalFunctionInfo += ", OriginalName=\"" + unrealFunction.GetName() + "\"";
                    }

                    if (isCollapsedMember)
                    {
                        // The Flags here might not contain too useful information if there is both a get/set function.
                        // Maybe include a second flags var?
                        attributes.Add("UFunctionAsProp(Flags=0x" + ((uint)unrealFunction.FunctionFlags).ToString("X8") + additionalFunctionInfo + ")");
                    }
                    else
                    {
                        attributes.Add("UFunction(Flags=0x" + ((uint)unrealFunction.FunctionFlags).ToString("X8") + additionalFunctionInfo + ")");
                    }
                }
            }

            UProperty unrealProperty = field as UProperty;

            if (unrealProperty != null)
            {
                attributes.Add("UProperty(Flags=(PropFlags)0x" + ((ulong)unrealProperty.PropertyFlags).ToString("X16") + ")");
            }

            if (unrealStruct != null)
            {
                attributes.Add("UStruct(Flags=0x" + ((uint)unrealStruct.StructFlags).ToString("X8") + ")");
            }
            else if (unrealClass != null)
            {
                // Abstract isn't really required but might help with code browsing to know what is abstract
                // and what isn't. Therefore put it at the start of the attributes list.
                if (unrealClass.HasAnyClassFlags(EClassFlags.Abstract))
                {
                    attributes.Add("Abstract");
                }

                isInterface = unrealClass.IsChildOf <UInterface>();
                if (isInterface)
                {
                    attributes.Add("UInterface(Flags=0x" + ((uint)unrealClass.ClassFlags).ToString("X8") + ")");
                }
                else
                {
                    attributes.Add("UClass(Flags=(ClassFlags)0x" + ((uint)unrealClass.ClassFlags).ToString("X8") + ")");
                }
            }

            if (unrealEnum != null)
            {
                attributes.Add("UEnum");
            }

            if (unrealEnum != null || unrealClass != null || unrealStruct != null)
            {
                bool blueprintType = false;
                bool blueprintable = false;
                if (unrealEnum != null)
                {
                    blueprintType = field.GetBoolMetaData(MDClass.BlueprintType);
                }
                else
                {
                    GetBlueprintability(field as UStruct, out blueprintType, out blueprintable);
                }
                if (blueprintType)
                {
                    attributes.Add(UMeta.GetKey(MDClass.BlueprintType));
                }
                if (unrealClass != null && blueprintable)
                {
                    attributes.Add(UMeta.GetKey(MDClass.Blueprintable));
                }

                attributes.Add("UMetaPath(\"" + field.GetPathName() + "\"" +
                               (isInterface ? ", InterfaceImpl=typeof(" + GetTypeName(unrealClass, null) + "Impl" + ")" : string.Empty) + ")");
            }
            else
            {
                attributes.Add("UMetaPath(\"" + field.GetPathName() + "\")");
            }

            if (attributes.Count > 0)
            {
                builder.AppendLine("[" + string.Join(", ", attributes) + "]");
            }
        }
        //////////////////////////////////////////////////////
        // MDFunc
        //////////////////////////////////////////////////////

        public UMetaAttribute(MDFunc key, string value)
            : this(UMeta.GetKey(key), value)
        {
        }