Esempio n. 1
0
        public static void OnSaveState()
        {
            int         startIndex = 1;
            XmlDocument doc        = new XmlDocument();
            XmlElement  root       = doc.CreateElement("maps");

            doc.AppendChild(root);
            XmlElement mapXmlElem;

            foreach (GCMap map in Maps)
            {
                mapXmlElem = doc.CreateElement("maprec");
                root.AppendChild(mapXmlElem);

                mapXmlElem.SetAttribute("guid", map.Id.ToString());
                if (!File.Exists(map.ImageFilePath))
                {
                    map.ImageFilePath = GetNewFileName(ref startIndex, ".png");
                    map.ImageChanged  = true;
                }
                if (map.ImageChanged)
                {
                    map.Image.Save(map.ImageFilePath, ImageFormat.Png);
                    map.ImageChanged = false;
                }
                mapXmlElem.SetAttribute("filePath", map.ImageFilePath);
                mapXmlElem.SetAttribute("title", map.Title);
                mapXmlElem.SetAttribute("sizex", map.ImageSize.Width.ToString());
                mapXmlElem.SetAttribute("sizey", map.ImageSize.Height.ToString());
                mapXmlElem.SetAttribute("latend", map.LatitudeEnd.ToString());
                mapXmlElem.SetAttribute("latstart", map.LatitudeStart.ToString());
                mapXmlElem.SetAttribute("longend", map.LongitudeEnd.ToString());
                mapXmlElem.SetAttribute("longstart", map.LongitudeStart.ToString());
                mapXmlElem.SetAttribute("usable", map.MapUsable ? "1" : "0");
                foreach (GCMapAnchor mapAnchor in map.AnchorPoints)
                {
                    XmlElement mae = doc.CreateElement("anchor");
                    mapXmlElem.AppendChild(mae);

                    mae.SetAttribute("relX", mapAnchor.relX.ToString());
                    mae.SetAttribute("relY", mapAnchor.relY.ToString());
                    mae.SetAttribute("title", mapAnchor.Location);
                    mae.SetAttribute("latitude", mapAnchor.Latitude.ToString());
                    mae.SetAttribute("longitude", mapAnchor.Longitude.ToString());
                }
            }

            string rootFile = GCGlobal.GetFileName(GCGlobal.MapsFolderPath, "root.xml");

            doc.Save(rootFile);
        }
Esempio n. 2
0
        public static void OnStart()
        {
            string rootFile = GCGlobal.GetFileName(GCGlobal.MapsFolderPath, "root.xml");

            if (File.Exists(rootFile))
            {
                Maps.Clear();
                XmlDocument doc = new XmlDocument();
                doc.Load(rootFile);
                foreach (XmlNode mapXmlNode in doc.GetElementsByTagName("maprec"))
                {
                    if (mapXmlNode is XmlElement mapXmlElement)
                    {
                        GCMap map = new GCMap();
                        map.Id             = new Guid(mapXmlElement.GetAttribute("guid"));
                        map.ImageFilePath  = mapXmlElement.GetAttribute("filePath");
                        map.Title          = mapXmlElement.GetAttribute("title");
                        map.ImageSize      = new Size(int.Parse(mapXmlElement.GetAttribute("sizex")), int.Parse(mapXmlElement.GetAttribute("sizey")));
                        map.LatitudeEnd    = double.Parse(mapXmlElement.GetAttribute("latend"));
                        map.LatitudeStart  = double.Parse(mapXmlElement.GetAttribute("latstart"));
                        map.LongitudeEnd   = double.Parse(mapXmlElement.GetAttribute("longend"));
                        map.LongitudeStart = double.Parse(mapXmlElement.GetAttribute("longstart"));
                        map.MapUsable      = (int.Parse(mapXmlElement.GetAttribute("usable")) == 1);
                        foreach (XmlElement anchorXmlNode in mapXmlElement.GetElementsByTagName("anchor"))
                        {
                            GCMapAnchor anchorPoint = new GCMapAnchor();
                            anchorPoint.relX      = double.Parse(anchorXmlNode.GetAttribute("relX"));
                            anchorPoint.relY      = double.Parse(anchorXmlNode.GetAttribute("relY"));
                            anchorPoint.Location  = anchorXmlNode.GetAttribute("title");
                            anchorPoint.Latitude  = double.Parse(anchorXmlNode.GetAttribute("latitude"));
                            anchorPoint.Longitude = double.Parse(anchorXmlNode.GetAttribute("longitude"));
                            map.AnchorPoints.Add(anchorPoint);
                        }

                        map.RecalculateDimensions();
                        Maps.Add(map);
                    }
                }
            }
        }