Example #1
0
 internal virtual void AddAttributes()
 {
     Attributes["id"]   = Id;
     Attributes["name"] = Name;
     if (!Enable)
     {
         Attributes["disabled"] = "disabled";
     }
     if (!CssClass.IsNullOrEmpty())
     {
         Attributes["class"] = CssClass;
     }
     if (!Validator.IsNullOrEmpty())
     {
         Attributes["validator"] = Validator;
     }
     if (!AttributeString.IsNullOrEmpty())
     {
         string[] kvs = AttributeString.Split(new char[] { ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
         foreach (var kv in kvs)
         {
             string[] keyValue = kv.Split(':');
             Attributes[keyValue[0]] = keyValue[1];
         }
     }
     if (ChangeTiggerSearch)
     {
         Attributes["data-autotigger"] = "true";
     }
 }
Example #2
0
 protected void SetDefaultStyle(object sender, WriterCommandEventArgs args)
 {
     if (args.Mode == WriterCommandEventMode.QueryState)
     {
         args.Enabled = false;
         if (args.Document != null && args.EditorControl.Readonly == false)
         {
             args.Enabled = true;
         }
     }
     else if (args.Mode == WriterCommandEventMode.Invoke)
     {
         DocumentContentStyle style = null;
         if (args.Parameter is string)
         {
             style = new DocumentContentStyle();
             style.DisableDefaultValue = true;
             string          values  = (string)args.Parameter;
             AttributeString attrs   = new AttributeString(values);
             bool            setFlag = false;
             foreach (AttributeStringItem item in attrs)
             {
                 XDependencyProperty p = XDependencyProperty.GetProperty(
                     typeof(DocumentContentStyle),
                     item.Name);
                 if (p != null)
                 {
                     Type pt = p.PropertyType;
                     try
                     {
                         if (pt.Equals(typeof(string)))
                         {
                             style.SetValue(p, item.Value);
                         }
                         else
                         {
                             TypeConverter tc = TypeDescriptor.GetConverter(pt);
                             if (tc != null && tc.CanConvertFrom(typeof(string)))
                             {
                                 object v = tc.ConvertFrom(item.Value);
                                 style.SetValue(p, v);
                             }
                             else
                             {
                                 object v = Convert.ChangeType(item.Value, pt);
                                 style.SetValue(p, v);
                             }
                         }
                         setFlag = true;
                     }
                     catch { }
                 } //p
             }     //foreach
             if (setFlag == false)
             {
                 // 输入的数据不对,退出处理
                 style = null;
             }
         }//if
         else if (args.Parameter is DocumentContentStyle)
         {
             style = (DocumentContentStyle)args.Parameter;
         }
         if (style != null)
         {
             args.Document.EditorSetDefaultStyle(style, true);
             args.RefreshLevel = UIStateRefreshLevel.All;
         }
     }//else
 }
Example #3
0
        static void WalkElement(XElement e, Dictionary <XamlElementLineInfo, XamlElementLineInfo> mappingOldNewLineInfo)
        {
            var info        = (IXmlLineInfo)e;
            var newLineInfo = new XamlElementLineInfo(lineNumber, currentColumn);

            mappingOldNewLineInfo.Add(new XamlElementLineInfo(info.LineNumber, info.LinePosition), newLineInfo);

            Console.WriteLine(info.LinePosition);
            NewLine();
            string prefix1 = e.GetPrefixOfNamespace(e.Name.Namespace);
            string name1   = prefix1 == null ? e.Name.LocalName : prefix1 + ":" + e.Name.LocalName;

            newLineInfo.Position = sb.Length;
            Append("<" + name1);

            List <AttributeString> list = new List <AttributeString>();
            int length = name1.Length;

            foreach (var a in e.Attributes())
            {
                string prefix2 = e.GetPrefixOfNamespace(a.Name.Namespace);
                var    g       = new AttributeString()
                {
                    Name = a.Name, Prefix = prefix2, Value = a.Value
                };
                list.Add(g);
                length += g.FinalString.Length;
            }

            list.Sort(AttributeComparrer.Instance);

            if (length > LengthBeforeNewLine)
            {
                nextColumn = currentColumn + 1;
                for (int i = 0; i < list.Count; i++)
                {
                    if (i > 0)
                    {
                        NewLine();
                    }
                    else
                    {
                        Append(" ");
                    }
                    Append(list[i].FinalString);
                }
                nextColumn -= name1.Length + 2;
            }
            else
            {
                foreach (var a in list)
                {
                    Append(" " + a.FinalString);
                }
            }

            if (e.Nodes().Count() > 0)
            {
                Append(">");
                nextColumn += Indenation;

                WalkContainer(e, mappingOldNewLineInfo);

                nextColumn -= Indenation;
                NewLine();
                Append("</" + name1 + ">");
            }
            else
            {
                Append(" />");
            }

            newLineInfo.Length = sb.Length - newLineInfo.Position;
        }
        static void WalkElement(XElement e)
        {
            NewLine();
            string prefix1 = e.GetPrefixOfNamespace(e.Name.Namespace);
            string name1   = prefix1 == null ? e.Name.LocalName : prefix1 + ":" + e.Name.LocalName;

            Append("<" + name1);

            List <AttributeString> list = new List <AttributeString>();
            int length = name1.Length;

            foreach (var a in e.Attributes())
            {
                string prefix2 = e.GetPrefixOfNamespace(a.Name.Namespace);
                var    g       = new AttributeString()
                {
                    Name = a.Name, Prefix = prefix2, Value = a.Value
                };
                list.Add(g);
                length += g.FinalString.Length;
            }

            list.Sort(AttributeComparrer.Instance);

            if (length > LengthBeforeNewLine)
            {
                nextColumn = currentColumn + 1;
                for (int i = 0; i < list.Count; i++)
                {
                    if (i > 0)
                    {
                        NewLine();
                    }
                    else
                    {
                        Append(" ");
                    }
                    Append(list[i].FinalString);
                }
                nextColumn -= name1.Length + 2;
            }
            else
            {
                foreach (var a in list)
                {
                    Append(" " + a.FinalString);
                }
            }

            if (e.Nodes().Count() > 0)
            {
                Append(">");
                nextColumn += Indenation;

                WalkContainer(e);

                nextColumn -= Indenation;
                NewLine();
                Append("</" + name1 + ">");
            }
            else
            {
                Append(" />");
            }
        }
Example #5
0
        public static BlockType ReadBlockType(this StreamReader reader, int id, string name, string reference)
        {
            try
            {
                BlockType blockType = new BlockType(id, name, reference);
                reader.ReadAttributes(blockType, (key, value) =>
                {
                    EcfAttribute a = null;
                    switch (key)
                    {
                    // bool
                    case "AboveTerrainCheck":
                    case "IsAccessible":
                    case "IsIgnoreLC":
                    case "IsLockable":
                    case "ShowBlockName":
                    case "TurretTargetIgnore":
                        a = new AttributeBool(value == "true");
                        break;

                    // int
                    case "BlastDamage":
                    case "BlastRadius":
                    case "CPUIn":
                    case "CPUOut":
                    case "EnergyIn":
                    case "EnergyInIdle":
                    case "EnergyOut":
                    case "FuelCapacity":
                    case "HitPoints":
                    case "MaxCount":
                    case "O2Capacity":
                    case "PanelAngle":
                    case "RotSpeed":
                    case "ShieldCapacity":
                    case "ShieldCooldown":
                    case "ShieldPerCrystal":
                    case "ShieldRecharge":
                    case "StackSize":
                    case "Temperature":
                    case "TemperatureGain":
                    case "ThrusterForce":
                    case "Torque":
                    case "UnlockCost":
                    case "UnlockLevel":
                    case "XpFactor":
                        a = new AttributeInt(int.Parse(value));
                        break;

                    // colour
                    case "BlockColor":
                        Match cm = Regex.Match(value, "(?<red>\\d+)\\s*,\\s*(?<green>\\d+)\\s*,\\s*(?<blue>\\d+)");
                        if (cm.Success)
                        {
                            byte r = byte.Parse(cm.Groups["red"].Value);
                            byte g = byte.Parse(cm.Groups["green"].Value);
                            byte b = byte.Parse(cm.Groups["blue"].Value);
                            a      = new AttributeColour(r, g, b);
                        }
                        else
                        {
                            throw new Exception("Unable to parse BlockColor attribute.");
                        }
                        break;

                    // string
                    case "Category":
                    case "Group":
                    case "Info":
                    case "IsOxygenTight":
                    case "Material":
                    case "TechTreeParent":
                    case "TemplateRoot":
                    case "WeaponItem":
                        a = new AttributeString(value);
                        break;

                    // string[]
                    case "ChildBlocks":
                    case "FuelAccept":
                    case "O2Accept":
                    case "TechTreeNames":
                        a = new AttributeStringArray(value != null ? Regex.Split(value, "\\s*,\\s*") : null);
                        break;

                    // float
                    case "HVEngineDampCoef":
                    case "HVEngineDampPow":
                    case "Mass":
                    case "MaxVolumeCapacity":
                    case "Radiation":
                    case "ReturnFactor":
                    case "SolarPanelEfficiency":
                    case "Volume":
                    case "VolumeCapacity":
                    case "Zoom":
                        a = new AttributeFloat(float.Parse(value));
                        break;

                    default:
                        Console.WriteLine($"Unknown block attribute: {key}");
                        break;
                    }

                    return(a);
                }, null);

                return(blockType);
            }
            catch (System.Exception ex)
            {
                throw new Exception("Failed reading item", ex);
            }
        }
Example #6
0
        public static ItemType ReadItemType(this StreamReader reader, int id, string name, string reference)
        {
            try
            {
                ItemType itemType = new ItemType(id, name, reference);

                reader.ReadAttributes(itemType, (key, value) =>
                {
                    EcfAttribute a = null;
                    switch (key)
                    {
                    // int
                    case "Armor":
                    case "BlastDamage":
                    case "BlastRadius":
                    case "Cold":
                    case "Durability":
                    case "FoodDecayTime":
                    case "Heat":
                    case "NrSlots":
                    case "Oxygen":
                    case "Radiation":
                    case "StackSize":
                    case "UnlockCost":
                    case "UnlockLevel":
                        a = new AttributeInt(int.Parse(value));
                        break;

                    // string[]
                    case "AllowAt":
                    case "TechTreeNames":
                        a = new AttributeStringArray(value != null ? Regex.Split(value, "\\s*,\\s*") : null);
                        break;

                    // bool
                    case "PickupToToolbar":
                    case "RadialMenu":
                        a = new AttributeBool(value.ToLower() == "true");
                        break;

                    // string
                    case "Category":
                    case "TechTreeParent":
                        a = new AttributeString(value);
                        break;

                    // float
                    case "DegradationProb":
                    case "FallDamageFac":
                    case "FoodFac":
                    case "JetpackFac":
                    case "JumpFac":
                    case "Mass":
                    case "PowerFac":
                    case "Range":
                    case "SpeedFac":
                    case "StaminaFac":
                    case "Volume":
                    case "VolumeCapacity":
                        a = new AttributeFloat(float.Parse(value));
                        break;

                    default:
                        Console.WriteLine($"Unknown item attribute: {key}");
                        break;
                    }
                    return(a);
                }, (s, o) =>
                {
                    if (ParseChildNodeHeader(s, out string childType, out string childName))
                    {
                        // TODO: Verify that childType == "" and childName == ""
                        OperationMode child = reader.ReadOperationMode(-1, childName, null);
                        ((ItemType)o).OperationModes.Add(child);
                    }
                });

                return(itemType);
            }