public void NewStatistic()
        {
            var newStat = new PlayerStatistic()
            {
                Label = "New Statistic"
            };

            PlayerStatistics.Add(newStat);
            SelectedStatistic = newStat;
        }
        public static PlayerSettings FromXML(XElement xml)
        {
            PlayerSettings result = new PlayerSettings();

            if (xml.Element("Description") != null)
            {
                result.PlayerDescription = Script.FromXML(xml.Element("Description").Element("Script"), result.PlayerDescription);
            }
            if (xml.Element("MovementScript") != null)
            {
                result.MovementScript = Script.FromXML(xml.Element("MovementScript").Element("Script"), result.MovementScript);
            }
            if (xml.Element("Statistics") != null)
            {
                result.PlayerStatistics = new ObservableCollection <PlayerStatistic>((from a in xml.Element("Statistics").Elements() select PlayerStatistic.FromXML(a)).ToList());
            }
            if (xml.Element("EquipmentSlots") != null)
            {
                result.EquipmentSlots = new ObservableCollection <EquipmentSlot>((from a in xml.Element("EquipmentSlots").Elements() select EquipmentSlot.FromXML(a)).ToList());
            }
            return(result);
        }
        public static PlayerStatistic FromXML(XElement xml)
        {
            PlayerStatistic stat = new PlayerStatistic();

            if (xml.Element("Label") != null)
            {
                stat.Label = xml.Element("Label").Value;
            }
            if (xml.Element("AssociatedVariable") != null)
            {
                stat.AssociatedVariable = new VarRef(Guid.Parse(xml.Element("AssociatedVariable").Value));
            }
            if (xml.Element("Visibility") != null)
            {
                stat.DisplayCondition = Script.FromXML(xml.Element("Visibility").Element("Script"), stat.DisplayCondition);
            }
            if (xml.Element("DisplayType") != null)
            {
                string type = xml.Element("DisplayType").Value;
                if (type == "Plaintext")
                {
                    stat.IsPlaintext = true;
                }
                else if (type == "ProgressBar" || type == "BalanceBar")
                {
                    if (type == "ProgressBar")
                    {
                        stat.IsProgressBar = true;
                    }
                    else
                    {
                        stat.IsBalanceBar = true;
                    }
                    if (xml.Element("HighWarning") != null)
                    {
                        stat.HighWarning = Convert.ToBoolean(xml.Element("HighWarning").Value);
                    }
                    if (xml.Element("LowWarning") != null)
                    {
                        stat.LowWarning = Convert.ToBoolean(xml.Element("LowWarning").Value);
                    }
                    if (xml.Element("MinValue") != null)
                    {
                        var minValueXml = xml.Element("MinValue");
                        if (minValueXml.Attribute("Type") != null)
                        {
                            var minType = minValueXml.Attribute("Type").Value;
                            if (minType == "Constant")
                            {
                                stat.MinimumValueConstant      = true;
                                stat.MinimumValueConstantValue = Int32.Parse(minValueXml.Value);
                            }
                            else if (minType == "Variable")
                            {
                                stat.MinimumValueVariable      = true;
                                stat.MinimumValueVariableValue = new VarRef(Guid.Parse(minValueXml.Value));
                            }
                        }
                    }
                    if (xml.Element("MaxValue") != null)
                    {
                        var maxValueXml = xml.Element("MaxValue");
                        if (maxValueXml.Attribute("Type") != null)
                        {
                            var maxType = maxValueXml.Attribute("Type").Value;
                            if (maxType == "Constant")
                            {
                                stat.MaximumValueConstant      = true;
                                stat.MaximumValueConstantValue = Int32.Parse(maxValueXml.Value);
                            }
                            else if (maxType == "Variable")
                            {
                                stat.MaximumValueVariable      = true;
                                stat.MaximumValueVariableValue = new VarRef(Guid.Parse(maxValueXml.Value));
                            }
                        }
                    }
                    if (xml.Element("LowLabel") != null)
                    {
                        stat.BalanceBarLowLabel = xml.Element("LowLabel").Value;
                    }
                    if (xml.Element("HighLabel") != null)
                    {
                        stat.BalanceBarHighLabel = xml.Element("HighLabel").Value;
                    }
                }
            }
            return(stat);
        }