Ejemplo n.º 1
0
 public MarkerSettings(MarkerSettings copy)
 {
     drawMarker = copy.drawMarker;
     useFilter  = copy.useFilter;
     filterMin  = copy.filterMin;
     filterMax  = copy.filterMax;
 }
Ejemplo n.º 2
0
 public MarkerSettings(MarkerSettings copy)
 {
     drawMarker = copy.drawMarker;
     useFilter = copy.useFilter;
     filterMin = copy.filterMin;
     filterMax = copy.filterMax;
 }
Ejemplo n.º 3
0
        public void LoadSettings()
        {
            String curSettingsName = "Default";
            Int32 settingsNodeCount;
            UserSettings us;
            Int32 settingsVer;
            XmlNode baseNode;
            XmlNodeList settingsNodes;
            XmlNode parseNode;
            XmlNodeList parseNodeList;
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Global.ApplicationUserSettingsFile);

            baseNode = xmlDoc.DocumentElement;

            // There's no UserSettings element so we'll use the default settings.
            if (baseNode.Name != "UserSettings")
                return;

            if (baseNode.Attributes["version"] == null)
                settingsVer = 0;
            else
                settingsVer = Int32.Parse(baseNode.Attributes["version"].Value);

            switch(settingsVer)
            {
                case 0:
                    break;
                case 1:
                    parseNode = baseNode.SelectSingleNode("GlobalSettings");

                    if (parseNode == null)
                        break;

                    parseNodeList = parseNode.SelectNodes("item");

                    foreach (XmlNode node in parseNodeList)
                    {
                        parseNode = node.Attributes["name"];

                        if (parseNode == null)
                            continue;

                        switch (parseNode.Value)
                        {
                            case "UseSettings":
                                parseNode = node.Attributes["value"];

                                if (parseNode != null)
                                    curSettingsName = parseNode.Value;
                                break;
                            case "HighestVersion":
                                parseNode = node.Attributes["value"];

                                if (parseNode != null)
                                    this.HighestVersion = Int32.Parse(parseNode.Value);
                                break;
                            default:
                                break;
                        }
                    }
                    break;
                default:
                    break;
            }

            if (settingsVer > 0)
                settingsNodes = baseNode.SelectNodes("Settings");
            else
                settingsNodes = xmlDoc.SelectNodes("UserSettings");

            settingsNodeCount = 0;
            foreach (XmlNode settingsNode in settingsNodes)
            {
                String settingsName;

                parseNode = settingsNode.Attributes["name"];

                if (parseNode == null)
                    settingsName = "Default";
                else
                    settingsName = parseNode.Value;

                us = null;

                foreach (UserSettings testUs in this.settingsList)
                {
                    if (testUs.SettingsName == settingsName)
                        us = testUs;
                }

                if (us == null)
                {
                    us = new UserSettings();
                    SetDefaults(us);
                    us.SettingsName = settingsName;

                    this.settingsList.Add(us);
                }

                if (us.SettingsName == curSettingsName)
                {
                    this.settings = us;
                    curSettings = settingsNodeCount;
                }
                settingsNodeCount++;

                switch (settingsVer)
                {
                    case 0:
                        #region UserSettings version 0 Loader
                        foreach (XmlNode node in settingsNode)
                        {
                            switch (node.Name)
                            {
                                case "InputWorldDirectory":
                                    us.InputWorldDirectory = node.InnerXml;
                                    break;
                                case "OutputPreviewDirectory":
                                    us.OutputPreviewDirectory = node.InnerXml;
                                    break;
                                case "IsChestFilterEnabled":
                                    us.IsChestFilterEnabled = Boolean.Parse(node.InnerXml);
                                    break;
                                case "IsWallsDrawable":
                                    us.AreWallsDrawable = Boolean.Parse(node.InnerXml);
                                    break;
                                case "OpenImageAfterDraw":
                                    us.OpenImageAfterDraw = Boolean.Parse(node.InnerXml);
                                    break;
                                case "ScanForNewChestItems":
                                    us.ScanForNewChestItems = Boolean.Parse(node.InnerXml);
                                    break;
                                case "ShowChestTypes":
                                    us.ShowChestTypes = Boolean.Parse(node.InnerXml);
                                    break;
                                case "UseCustomMarkers":
                                    us.UseCustomMarkers = Boolean.Parse(node.InnerXml);
                                    break;
                                case "ChestListSortType":
                                    us.ChestListSortType = Int32.Parse(node.InnerXml);
                                    break;
                                case "HighestVersion":
                                    this.HighestVersion = Int32.Parse(node.InnerXml);
                                    break;
                                case "SymbolStates":
                                    parseNodeList = node.SelectNodes("item");

                                    foreach (XmlNode n in parseNodeList)
                                    {
                                        String Key;
                                        Boolean Value;
                                        MarkerSettings mi;

                                        parseNode = n.SelectSingleNode("key").SelectSingleNode("string");
                                        Key = parseNode.InnerXml;

                                        parseNode = n.SelectSingleNode("value").SelectSingleNode("boolean");
                                        Value = Boolean.Parse(parseNode.InnerXml);

                                        if (us.MarkerStates.ContainsKey(Key))
                                            us.MarkerStates[Key].Drawing = Value;
                                        else
                                        {
                                            String newKey = Global.Instance.Info.MarkerImageToName(Key);

                                            if (!us.MarkerStates.ContainsKey(newKey))
                                                newKey = String.Empty;

                                            if (newKey == String.Empty)
                                            {
                                                mi = new MarkerSettings();
                                                mi.Drawing = Value;
                                                us.MarkerStates.Add(Key, mi);
                                            }
                                            else
                                            {
                                                us.MarkerStates[newKey].Drawing = Value;
                                            }
                                        }
                                    }
                                    break;
                                case "ChestFilterItems":
                                    parseNodeList = node.SelectNodes("item");

                                    foreach (XmlNode n in parseNodeList)
                                    {
                                        String Key;
                                        Boolean Value;

                                        parseNode = n.SelectSingleNode("key").SelectSingleNode("string");
                                        Key = parseNode.InnerXml;

                                        parseNode = n.SelectSingleNode("value").SelectSingleNode("boolean");
                                        Value = Boolean.Parse(parseNode.InnerXml);

                                        if (Value == true)
                                            us.ChestFilterItems.Add(Key);
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                        #endregion
                        break;
                    case 1:
                        #region UserSettings version 1 Loader
                        foreach (XmlNode node in settingsNode)
                        {
                            parseNode = node.Attributes["name"];

                            if (parseNode == null)
                                continue;

                            switch (parseNode.Value)
                            {
                                case "InputWorldDirectory":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.InputWorldDirectory = parseNode.Value;
                                    break;
                                case "OutputPreviewDirectory":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.OutputPreviewDirectory = parseNode.Value;
                                    break;
                                case "IsChestFilterEnabled":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.IsChestFilterEnabled = Boolean.Parse(parseNode.Value);
                                    break;
                                case "AreWiresDrawable":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.AreWiresDrawable = Boolean.Parse(parseNode.Value);
                                    break;
                                case "AreWallsDrawable":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.AreWallsDrawable = Boolean.Parse(parseNode.Value);
                                    break;
                                case "OpenImageAfterDraw":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.OpenImageAfterDraw = Boolean.Parse(parseNode.Value);
                                    break;
                                case "ScanForNewChestItems":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.ScanForNewChestItems = Boolean.Parse(parseNode.Value);
                                    break;
                                case "ShowChestTypes":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.ShowChestTypes = Boolean.Parse(parseNode.Value);
                                    break;
                                case "UseCustomMarkers":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.UseCustomMarkers = Boolean.Parse(parseNode.Value);
                                    break;
                                case "ChestListSortType":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.ChestListSortType = Int32.Parse(parseNode.Value);
                                    break;
                                case "CropImageType":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.CropImageType = Int32.Parse(parseNode.Value);
                                    break;
                                case "ShowChestItems":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.ShowChestItems = Boolean.Parse(parseNode.Value);
                                    break;
                                case "ShowNormalItems":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.ShowNormalItems = Boolean.Parse(parseNode.Value);
                                    break;
                                case "ShowCustomItems":
                                    parseNode = node.Attributes["value"];

                                    if (parseNode != null)
                                        us.ShowCustomItems = Boolean.Parse(parseNode.Value);
                                    break;
                                case "MarkerStates":
                                    parseNodeList = node.SelectNodes("listitem");

                                    foreach (XmlNode n in parseNodeList)
                                    {
                                        String Name;
                                        MarkerSettings mi;

                                        parseNode = n.Attributes["name"];

                                        if (parseNode == null)
                                            break;

                                        Name = parseNode.Value;

                                        if (us.MarkerStates.TryGetValue(Name, out mi) == false)
                                            mi = new MarkerSettings();

                                        parseNode = n.Attributes["draw"];

                                        if (parseNode != null)
                                            mi.Drawing = Boolean.Parse(parseNode.Value);

                                        parseNode = n.Attributes["filter"];

                                        if (parseNode != null)
                                            mi.Filtering = Boolean.Parse(parseNode.Value);

                                        parseNode = n.Attributes["min"];

                                        if (parseNode != null)
                                            mi.Min = Int32.Parse(parseNode.Value);

                                        parseNode = n.Attributes["max"];

                                        if (parseNode != null)
                                            mi.Max = Int32.Parse(parseNode.Value);

                                        if (!us.MarkerStates.ContainsKey(Name))
                                            us.MarkerStates.Add(Name, mi);
                                    }
                                    break;
                                case "ChestFilterItems":
                                    parseNode = node.Attributes["filter"];

                                    if (parseNode == null)
                                        continue;

                                    String[] splitList = parseNode.Value.Split(';');

                                    foreach (String s in splitList)
                                    {
                                        us.ChestFilterItems.Add(s);
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                        #endregion
                        break;
                    default:
                        return;
                }
            }

            parseNode = baseNode.SelectSingleNode("CustomItems");

            if (parseNode != null)
            {
                parseNode = parseNode.Attributes["list"];

                if (parseNode != null)
                {
                    String[] itemList = parseNode.Value.Split(';');

                    foreach (String s in itemList)
                    {
                        if (!Global.Instance.Info.Items.ContainsKey(s))
                            Global.Instance.Info.AddCustomItem(s);
                    }
                }
            }

            parseNode = baseNode.SelectSingleNode("CustomColors");

            if (parseNode != null)
            {
                parseNode = parseNode.Attributes["list"];

                if (parseNode != null)
                {
                    String[] colorList = parseNode.Value.Split(';');
                    Color newColor;

                    for (Int32 sPos = 0; sPos < colorList.Length; sPos += 2)
                    {
                        if (Global.TryParseColor(colorList[sPos + 1], out newColor) == false)
                            continue;

                        if (Global.Instance.Info.Colors.ContainsKey(colorList[sPos]))
                            continue;

                        Global.Instance.Info.AddCustomColor(colorList[sPos], newColor);
                    }
                }
            }
        }