public override void ApplyPropertyMeta(SerializedProperty property, MetaAttribute metaAttribute)
        {
            SectionAttribute sectionAttribute = (SectionAttribute)metaAttribute;

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(sectionAttribute.SectionLabel, EditorStyles.boldLabel);
        }
Example #2
0
 public SectionHeaderEntry(uint name, SectionType type, SectionAttribute flags, int link, int info)
 {
     Name  = name;
     Type  = type;
     Flags = flags;
     Link  = link;
     Info  = info;
 }
 public SectionHeaderEntry32(uint name, SectionType type, SectionAttribute flags, uint address, uint offset, uint size, int link, int info, uint addressAlignment, uint entrySize)
     : base(name, type, flags, link, info)
 {
     Address          = address;
     Offset           = offset;
     Size             = size;
     AddressAlignment = addressAlignment;
     EntrySize        = entrySize;
 }
Example #4
0
 /// <summary>
 /// Reads the specified writer.
 /// </summary>
 /// <param name="reader">The reader.</param>
 public void Read(BinaryReader reader)
 {
     Address          = reader.ReadUInt16();
     Name             = reader.ReadUInt32();
     Type             = (SectionType)reader.ReadUInt16();
     Flags            = (SectionAttribute)reader.ReadUInt16();
     Address          = reader.ReadUInt32();
     Offset           = reader.ReadUInt32();
     Size             = reader.ReadUInt32();
     Link             = reader.ReadUInt32();
     Info             = reader.ReadUInt32();
     AddressAlignment = reader.ReadUInt32();
     EntrySize        = reader.ReadUInt32();
 }
        /// <summary>
        /// 按照未转码的byte数组对T的各属性进行赋值
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="originBytes">未进行GBK转码的密文解析结果</param>
        /// <returns>T的实例</returns>
        private static T ParseFromBytes <T>(byte[] originBytes, ref int offset) where T : class
        {
            T instance = Activator.CreateInstance <T>();

            PropertyInfo[] sortedProperties = SortPropertyInfo(typeof(T).GetProperties());

            for (int index = 0; index < sortedProperties.Length; index++)
            {
                PropertyInfo property = sortedProperties[index];
                if (property == null)
                {
                    continue;
                }

                SectionAttribute sectionAttribute = (SectionAttribute)property.GetCustomAttribute(typeof(SectionAttribute));

                byte[] sectionBytes = originBytes.Skip(offset).Take(sectionAttribute.Length).ToArray();
                string section      = Encoding.GetEncoding(ENCODING_GBK).GetString(sectionBytes);

                //Property赋值
                if (property.PropertyType.Equals(typeof(string)))
                {
                    //去除左右空格
                    property.SetValue(instance, section.Trim());
                }

                if (property.PropertyType.Equals(typeof(int)))
                {
                    int temp = 0;
                    Int32.TryParse(section, out temp);
                    property.SetValue(instance, temp);
                }

                if (property.PropertyType.Equals(typeof(decimal)))
                {
                    decimal temp = 0;
                    Decimal.TryParse(section, out temp);
                    property.SetValue(instance, temp);
                }

                offset += sectionAttribute.Length;
            }

            return(instance);
        }
Example #6
0
        FileSection(PropertyInfo property, SectionAttribute attribute, int level)
        {
            Property  = property;
            Attribute = attribute;
            Level     = level;

            if (IsTable && !IsList)
            {
                throw new FormatException($"{Name} table section requires collection property type.");
            }

            if (IsText && !IsString)
            {
                throw new FormatException($"{Name} text section requires string property type.");
            }

            Schema = new FileSchema(Type, level + 1);
        }
Example #7
0
        /// <summary>
        /// 按照字符串对T进行赋值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="originText"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        private static T ParseFromBytes <T>(string originText, PropertyInfo[] properties, ref int offset) where T : class
        {
            T instance = Activator.CreateInstance <T>();

            for (int index = 0; index < properties.Length; index++)
            {
                PropertyInfo property = properties[index];
                if (property == null)
                {
                    continue;
                }

                SectionAttribute sectionAttribute = (SectionAttribute)property.GetCustomAttribute(typeof(SectionAttribute));

                string section = originText.Substring(offset, sectionAttribute.Length).Trim();

                //Property赋值
                if (property.PropertyType.Equals(typeof(string)))
                {
                    property.SetValue(instance, section);
                }

                if (property.PropertyType.Equals(typeof(int)))
                {
                    int temp = 0;
                    Int32.TryParse(section, out temp);
                    property.SetValue(instance, temp);
                }

                if (property.PropertyType.Equals(typeof(decimal)))
                {
                    decimal temp = 0;
                    Decimal.TryParse(section, out temp);
                    property.SetValue(instance, temp);
                }

                offset += sectionAttribute.Length;
            }

            //\r\n换行符和回车占两个字符
            offset += 2;

            return(instance);
        }
        /// <summary>
        /// 按照Section特性的index对各属性排序
        /// </summary>
        /// <param name="defaultPropertyInfos">默认的属性数组</param>
        /// <returns></returns>
        private static PropertyInfo[] SortPropertyInfo(PropertyInfo[] defaultPropertyInfos)
        {
            PropertyInfo[] sortedProperties = new PropertyInfo[defaultPropertyInfos.Length];

            for (int index = 0; index < defaultPropertyInfos.Length; index++)
            {
                PropertyInfo property  = defaultPropertyInfos[index];
                Attribute    attribute = property.GetCustomAttribute(typeof(SectionAttribute));
                if (attribute == null)
                {
                    continue;
                }

                SectionAttribute sectionAttribute = (SectionAttribute)attribute;

                sortedProperties[sectionAttribute.Index - 1] = property;
            }

            return(sortedProperties);
        }
Example #9
0
        private static void ProcessSectionFields(DataEntrySection sectionContract, SectionAttribute sectionAttribute, Type sectionType)
        {
            // Get the Section Properties
            foreach (var property in sectionType.GetProperties())
            {
                var fieldAttribute      = GetFieldAttribute(property);
                var fieldGroupAttribute = GetFieldGroupAttribute(property.PropertyType);
                if (fieldAttribute != null && fieldGroupAttribute == null) // Regular Field
                {
                    ProcessField(sectionContract, property, fieldAttribute);
                    continue;
                }

                if (fieldGroupAttribute != null)
                {
                    ProcessFieldGroup(sectionContract, property, fieldGroupAttribute, property.Name.ToPascalCase());
                    continue;
                }
            }
        }
        // Make your own GUI for the decorator
        public override void OnGUI(Rect _position)
        {
            SectionAttribute _attribute = (SectionAttribute)attribute;

            // Get label size, plus line and section width
            Vector2 _labelSize    = LabelStyle.CalcSize(new GUIContent(_attribute.Label));
            float   _sectionWidth = Mathf.Min(_position.width, _labelSize.x + (SpaceAroundLabel * 2) + (_attribute.LineWidth * 2));
            float   _lineWidth    = ((_sectionWidth - _labelSize.x) / 2f) - SpaceAroundLabel;

            // Set position at the middle of the area and line height
            _position.y += (EditorGUIUtility.singleLineHeight / 2f) + _attribute.HeightSpace - 1;

            // Draw horizontal line if enough space
            if (_lineWidth > 0)
            {
                Rect _lineRect = new Rect()
                {
                    x      = _position.x + ((_position.width - _sectionWidth) / 2f),
                    y      = _position.y + _labelSize.y / 2f,
                    height = 2f,
                    width  = _lineWidth
                };

                // Set label x position
                _position.x = _lineRect.x + _lineWidth + SpaceAroundLabel;

                // Draw lines around label
                EditorGUI.DrawRect(_lineRect, LabelStyle.normal.textColor);
                _lineRect.x += _lineWidth + _labelSize.x + (SpaceAroundLabel * 2);
                EditorGUI.DrawRect(_lineRect, LabelStyle.normal.textColor);
            }
            // Set maximum available space surrounding the label
            else if (_position.width > _labelSize.x)
            {
                _position.x += (_position.width - _labelSize.x) / 2f;
            }

            // Draw label
            EditorGUI.LabelField(_position, _attribute.Label, LabelStyle);
        }
Example #11
0
 public void SectionAttribute_ConstructorForEventSectionType()
 {
     sectionAttribute = new SectionAttribute(SectionType.Event);
     Assert.AreEqual(SectionType.Event, sectionAttribute.SectionType);
 }
Example #12
0
 public void SectionAttribute_ConstructorForDrugSectionType()
 {
     sectionAttribute = new SectionAttribute(SectionType.Drug);
     Assert.AreEqual(SectionType.Drug, sectionAttribute.SectionType);
 }
Example #13
0
 /// <summary>
 /// Reads the specified writer.
 /// </summary>
 /// <param name="reader">The reader.</param>
 public void Read(BinaryReader reader)
 {
     Address = reader.ReadUInt16();
     Name = reader.ReadUInt32();
     Type = (SectionType)reader.ReadUInt16();
     Flags = (SectionAttribute)reader.ReadUInt16();
     Address = reader.ReadUInt32();
     Offset = reader.ReadUInt32();
     Size = reader.ReadUInt32();
     Link = reader.ReadUInt32();
     Info = reader.ReadUInt32();
     AddressAlignment = reader.ReadUInt32();
     EntrySize = reader.ReadUInt32();
 }
        // Make your own GUI for the decorator
        public override void OnGUI(Rect _position)
        {
            SectionAttribute _attribute = (SectionAttribute)attribute;

            EditorGUIEnhanced.Section(_position, _attribute.Label, _attribute.LineWidth);
        }
Example #15
0
 public void SectionAttribute_ConstructorForVehicleSectionType()
 {
     sectionAttribute = new SectionAttribute(SectionType.Vehicle);
     Assert.AreEqual(SectionType.Vehicle, sectionAttribute.SectionType);
 }
Example #16
0
 public void SectionAttribute_ConstructorForPersonSectionType()
 {
     sectionAttribute = new SectionAttribute(SectionType.Person);
     Assert.AreEqual(SectionType.Person, sectionAttribute.SectionType);
 }
Example #17
0
 public void SectionAttribute_ConstructorForOffenseSectionType()
 {
     _sectionAttribute = new SectionAttribute(SectionType.Offense);
     Assert.AreEqual(SectionType.Offense, _sectionAttribute.SectionType);
 }
Example #18
0
        private static void ProcessSectionProperty(DataEntryContract contract, PropertyInfo property, Type sectionType, SectionAttribute sectionAttribute)
        {
            // Create the Section Metadata
            var sectionContract = new DataEntrySection()
            {
                OrderBy       = contract.Sections.Count,
                Name          = property.Name,
                Path          = property.Name.ToPascalCase(),
                Label         = GetLabel(property) ?? MakeEnglish(property.Name),
                Description   = GetDescription(sectionType),
                AllowMultiple = IsCollection(property.PropertyType),
                PropertyName  = property.Name,
                SectionType   = sectionAttribute.SectionType,
                TypeName      = sectionType.FullName
            };

            // Process the Field Metadata
            ProcessSectionFields(sectionContract, sectionAttribute, sectionType);
            contract.Sections.Add(sectionContract);
        }
Example #19
0
 public void SectionAttribute_ConstructorForOrganizationSectionType()
 {
     _sectionAttribute = new SectionAttribute(SectionType.Organization);
     Assert.AreEqual(SectionType.Organization, _sectionAttribute.SectionType);
 }
Example #20
0
 public void SectionAttribute_ConstructorForNarrativeSectionType()
 {
     sectionAttribute = new SectionAttribute(SectionType.Narrative);
     Assert.AreEqual(SectionType.Narrative, sectionAttribute.SectionType);
 }
Example #21
0
 public void SectionAttribute_ConstructorForGunSectionType()
 {
     _sectionAttribute = new SectionAttribute(SectionType.Gun);
     Assert.AreEqual(SectionType.Gun, _sectionAttribute.SectionType);
 }
Example #22
0
 public void SectionAttribute_ConstructorForOfficerSectionType()
 {
     sectionAttribute = new SectionAttribute(SectionType.Officer);
     Assert.AreEqual(SectionType.Officer, sectionAttribute.SectionType);
 }
Example #23
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        SectionAttribute section = attribute as SectionAttribute;

        Color fadedText = GUI.color;

        fadedText.a = 0.75f;

        GUIStyle headerStyle = new GUIStyle(EditorStyles.whiteLargeLabel)
        {
            richText = true
        };
        GUIStyle messageStyle = new GUIStyle(EditorStyles.whiteMiniLabel)
        {
            richText = true,
            normal   = { textColor = fadedText }
        };

        // Calculate title Rect
        Rect titleRect = position;

        titleRect.x     -= 2;
        titleRect.y     += 13;
        titleRect.height = 18;

        // Check if an icon is included and draw it with the title
        if (!string.IsNullOrEmpty(section.IconPath))
        {
            Texture icon = AssetDatabase.LoadAssetAtPath <Texture>(section.IconPath);
            if (icon == null)
            {
                Debug.LogWarning(Tag + "The icon for this section cannot be found. Check the path.");
                EditorGUI.LabelField(titleRect, section.Title, headerStyle);
            }
            else
            {
                EditorGUI.LabelField(titleRect, new GUIContent(section.Title, icon), headerStyle);
            }
        }
        else
        {
            EditorGUI.LabelField(titleRect, section.Title, headerStyle);
        }

        // Check if a description is included and draw it
        if (!string.IsNullOrEmpty(section.Description))
        {
            Rect descRect = titleRect;
            descRect.y += 15;
            EditorGUI.LabelField(descRect, section.Description, messageStyle);
        }

        // Calculate separator Rect
        Rect separatorRect = position;

        separatorRect.y     += string.IsNullOrEmpty(section.Description) ? 30 : 42;
        separatorRect.height = 1.5f;

        // Check if separator is enabled and draw it
        if (section.Separator)
        {
            GUI.Box(separatorRect, "");
        }

        // Calculate PropertyField Rect
        Rect propertyPos = separatorRect;

        propertyPos.y     += 10;
        propertyPos.height = 16;

        // Draw property
        EditorGUI.PropertyField(propertyPos, property);

//		Use Handles instead of a GUI.Box (Keeps flashing on scroll as of 2017.3, don't use)
//		Handles.BeginGUI();
//		Handles.color = Color.grey;
//		Handles.DrawLine(new Vector2(posLine.x, posLine.y), new Vector2(EditorGUIUtility.currentViewWidth - 21, posLine.y));
//		Handles.EndGUI();
    }
Example #24
0
 public void SectionAttribute_ConstructorForPropertySectionType()
 {
     sectionAttribute = new SectionAttribute(SectionType.Property);
     Assert.AreEqual(SectionType.Property, sectionAttribute.SectionType);
 }
Example #25
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        SectionAttribute section = attribute as SectionAttribute;

        return(string.IsNullOrEmpty(section.Description) ? 56 : 68);
    }
        /***************************
        *******   METHODS   *******
        ***************************/

        // Specify how tall the GUI for this decorator is in pixels
        public override float GetHeight()
        {
            SectionAttribute _attribute = (SectionAttribute)attribute;

            return(LabelStyle.CalcSize(new GUIContent(_attribute.Label)).y + EditorGUIUtility.singleLineHeight + (_attribute.HeightSpace * 2));
        }
Example #27
0
        public void ConstructorWithParameterTest()
        {
            var item = new SectionAttribute("MyTestString");

            Assert.AreEqual("MyTestString", item.Section);
        }
Example #28
0
        public async Task Help()
        {
            var embeds = new List <LocalEmbed>();

            // normal proper commands
            var commands = new Dictionary <string, List <Tuple <Command, Dictionary <Type, Attribute> > > >();
            // section splits
            var sections = new Dictionary <string, SectionAttribute>();
            // extremely simple commands which will not display a description
            // and share a single row for display
            var simpleCommands = new Dictionary <SectionAttribute, List <Command> >();

            // what we'll be collecting from commands
            var searchAttributes = new List <Type>()
            {
                typeof(SectionAttribute),
                typeof(SimpleCommandAttribute)
            };

            // categorize commands by section first
            foreach (var command in _commands.GetAllCommands())
            {
                var attrs = new Dictionary <Type, Attribute>();
                var copy  = new List <Type>(searchAttributes);

                var attrLists = new List <List <Attribute> >()
                {
                    command.Attributes.ToList(),
                    command.Module.Attributes.ToList()
                };

                var hideCommand = false;
                foreach (var list in attrLists)
                {
                    foreach (var attr in list)
                    {
                        if (attr.GetType() == typeof(HiddenCommandAttribute))
                        {
                            hideCommand = true;
                            break;
                        }

                        for (int i = copy.Count - 1; i > -1; i--)
                        {
                            var item = copy[i];
                            if (attr.GetType() == item)
                            {
                                attrs.Add(item, attr);
                                copy.RemoveAt(i);
                            }
                        }
                    }

                    if (hideCommand)
                    {
                        break;
                    }
                }

                if (hideCommand || !attrs.TryGetValue(typeof(SectionAttribute), out var temp))
                {
                    continue; // invalid or hidden command?
                }

                // re-cast
                SectionAttribute section = (SectionAttribute)temp;
                if (!commands.ContainsKey(section.Name))
                {
                    commands.Add(section.Name, new List <Tuple <Command, Dictionary <Type, Attribute> > >());
                    sections.Add(section.Name, section);
                }

                if (!attrs.ContainsKey(typeof(SimpleCommandAttribute)))
                {
                    commands[section.Name].Add(new Tuple <Command, Dictionary <Type, Attribute> >(command, attrs));
                }
                else
                {
                    if (!simpleCommands.ContainsKey(section))
                    {
                        simpleCommands.Add(section, new List <Command>());
                    }

                    simpleCommands[section].Add(command);
                }
            }

            var last = sections.Last();

            foreach (var attributePair in sections)
            {
                var embed = GetEmbed()
                            .WithTitle(attributePair.Value.Name);

                var description = "\n";
                if (attributePair.Value.Description != null)
                {
                    description = attributePair.Value.Description + "\n\n=======================\n\n";
                }

                // normal commands
                if (commands[attributePair.Value.Name].Count > 0)
                {
                    foreach (var tuple in commands[attributePair.Value.Name])
                    {
                        var name = "**" + tuple.Item1.FullAliases[0] + "**";

                        description += name + " " + string.Join(' ',
                                                                tuple.Item1.Parameters.Select <Parameter, string>(FormatParameter)
                                                                ) + "\n" + (string.IsNullOrEmpty(tuple.Item1.Description) ? "" : "> " + tuple.Item1.Description + "\n\n");
                    }
                }

                // simple commands
                if (simpleCommands.TryGetValue(attributePair.Value, out var simpleList))
                {
                    // show 7 commands in each line
                    foreach (var batch in simpleList.Batch(7))
                    {
                        description += "> " + string.Join(" ", batch.Select(x => x.FullAliases[0])) + "\n\n";
                    }
                }

                if (attributePair.Equals(last))
                {
                    embed.WithFooter("Made by Ly#3449, original concept by zappin#1312, version " + Program.Version);
                }
                else
                {
                    // remove last newlines
                    description = description.Substring(0, description.Length - 1);
                }

                embeds.Add(embed.WithDescription(description));
            }

            var builder       = new LocalMessage();
            var lastEmbed     = embeds.Last();
            var addedReaction = false;

            foreach (var embed in embeds)
            {
                try
                {
                    await Context.Author.SendMessageAsync(builder.WithEmbed(embed));

                    if (!embed.Equals(lastEmbed))
                    {
                        await Task.Delay(500);
                    }

                    if (!addedReaction)
                    {
                        await Context.Message.AddReactionAsync(new LocalEmoji("✅"));
                    }
                }
                catch (Exception) // in case someone has blocked dms
                {
                    await EmbedReply("You seem to have dms disabled or other error occurred!");

                    return;
                }
            }
        /***************************
        *******   METHODS   *******
        ***************************/

        // Specify how tall the GUI for this decorator is in pixels
        public override float GetHeight()
        {
            SectionAttribute _attribute = (SectionAttribute)attribute;

            return((EditorGUIUtility.singleLineHeight + _attribute.HeightSpace) * 2);
        }