Beispiel #1
0
        public BlockControl(CacheForm form, HaloOnlineCacheContext cacheContext, Type type, FieldInfo field) :
            this()
        {
            CacheContext = cacheContext;
            Field        = field;

            groupBox.Text = field.Name.ToSpaced().Replace("_", "");
            new ToolTip().SetToolTip(groupBox, $"{groupBox.Text} Block {CacheForm.GetDocumentation(field)}");

            Struct = new StructControl(form, CacheContext, type.GenericTypeArguments[0], null);
            groupBox.Controls.Add(Struct);
            Struct.Dock = DockStyle.Fill;
            Struct.BringToFront();

            Height = groupBox.Height;
        }
Beispiel #2
0
        private Dictionary <string, IFieldControl> CreateFieldControls(CacheForm form, Control parent, FieldInfo field, Type type, bool toplevel)
        {
            Enabled = false;

            var result     = new Dictionary <string, IFieldControl>();
            var enumerator = TagStructure.GetTagFieldEnumerable(new TagStructureInfo(type, Cache.Version));

            var currentLocation = new Point(parent is GroupBox ? 3 : 0, parent is GroupBox ? 16 : 0);

            foreach (var fieldInfo in enumerator)
            {
                if (fieldInfo.Attribute.Flags.HasFlag(TagFieldFlags.Padding))
                {
                    continue;
                }

                var fieldType   = fieldInfo.FieldInfo.FieldType;
                var isFlagsEnum = (fieldType.GetCustomAttributes(typeof(FlagsAttribute), false).FirstOrDefault() as FlagsAttribute ?? null) != null;
                var isTagBlock  = (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List <>));
                var isStruct    = (fieldType.GetCustomAttributes(typeof(TagStructureAttribute), false).FirstOrDefault() as TagStructureAttribute ?? null) != null;
                var isBounds    = (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Bounds <>));

                if (toplevel && (isStruct || isTagBlock))
                {
                    continue;
                }

                if (field != null && field != fieldInfo.FieldInfo)
                {
                    continue;
                }

                Control control = null;

                if (fieldType == typeof(StringId))
                {
                    control = new StringIdControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType.IsEnum)
                {
                    if (isFlagsEnum)
                    {
                        control = new FlagsControl(fieldInfo.FieldInfo);
                    }
                    else
                    {
                        control = new EnumControl(fieldInfo.FieldInfo);
                    }
                }
                else if (fieldType == typeof(Point2d))
                {
                    control = new Point2dControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(Rectangle2d))
                {
                    control = new Rectangle2dControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(ArgbColor))
                {
                    control = new ArgbColorControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealPoint2d))
                {
                    control = new RealPoint2dControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealPoint3d))
                {
                    control = new RealPoint3dControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealVector2d))
                {
                    control = new RealVector2dControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealVector3d))
                {
                    control = new RealVector3dControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealQuaternion))
                {
                    control = new RealQuaternionControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealRgbColor))
                {
                    control = new RealRgbColorControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealArgbColor))
                {
                    control = new RealArgbColorControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealEulerAngles2d))
                {
                    control = new RealEulerAngles2dControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealEulerAngles3d))
                {
                    control = new RealEulerAngles3dControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealPlane2d))
                {
                    control = new RealPlane2dControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(RealPlane3d))
                {
                    control = new RealPlane3dControl(Cache, fieldInfo.FieldInfo);
                }
                else if (fieldType == typeof(CachedTag))
                {
                    control = new TagReferenceControl(form, Cache, fieldInfo.FieldInfo);
                }
                else if (isTagBlock)
                {
                    control = new BlockControl(form, Cache, fieldType, fieldInfo.FieldInfo);

                    if (((BlockControl)control).Struct.FieldControls.Count == 0)
                    {
                        continue;
                    }
                }
                else if (isStruct)
                {
                    control = new StructControl(form, Cache, fieldType, fieldInfo.FieldInfo);

                    if (((StructControl)control).FieldControls.Count == 0)
                    {
                        continue;
                    }
                }
                else if (isBounds)
                {
                    control = new BoundsControl(Cache, fieldInfo.FieldInfo);
                }
                else
                {
                    control = new ValueControl(Cache, fieldInfo.FieldInfo);
                }

                control.Location = new Point(currentLocation.X, currentLocation.Y);
                parent.Controls.Add(control);

                currentLocation.Y = control.Bottom;

                if (parent is GroupBox gb && gb.AutoSize == false)
                {
                    parent.Width  = control.Right + 8;
                    parent.Height = control.Bottom + 6;
                }

                if (isStruct || isTagBlock)
                {
                    control.BringToFront();
                }

                result[fieldInfo.FieldInfo.Name] = (IFieldControl)control;

                Application.DoEvents();
            }

            Enabled = true;

            return(result);
        }