コード例 #1
0
        /// <summary>
        /// Select a map
        /// </summary>
        /// <param name="map"></param>
        /// <returns>True when map selection is changed, otherwise false.</returns>
        public bool SelectMap(string map)
        {
            lock (this.AvailablePlanetMaps)
            {
                if (!this.AvailablePlanetMaps.ContainsKey(map))
                {
                    return(false);
                }
                var newMap = this.AvailablePlanetMaps[map];
                if (newMap == this.CurrentMap)
                {
                    return(false);
                }
                var oldMap = this.CurrentMap;

                this.SaveCurrentMapZoomLevel();

                this.CurrentMap = newMap;
                // Unload map textures.
                if (oldMap != null)
                {
                    oldMap.UnloadAllTextures();
                }
                SetCurrentMapZoomLevel(newMap);

                if (API.Camera != null)
                {
                    API.Camera.CenterOnPixel(this.CurrentLayer.Size.X / 2, this.CurrentLayer.Size.Y / 2);
                    API.Camera.AdjustScrollbarsToLayer();
                }

                for (int i = 0; i < API.UiElements.MapList.Items.Count; i++)
                {
                    if ((API.UiElements.MapList.Items[i] as MapSelectionItem).MapPath.Equals(map, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (i != API.UiElements.MapList.SelectedIndex)
                        {
                            API.UiElements.MapList.SelectedIndex = i;
                        }
                        break;
                    }
                }
                return(true);
            }
        }
コード例 #2
0
 public void FindAvailableMaps(MapType mapType)
 {
     lock (this.AvailablePlanetMaps)
     {
         this.AvailablePlanetMaps.Clear();
         API.UiElements.MapList.Items.Clear();
         var candidates = Directory.GetFiles(this.mapDirectory, "*.txt", SearchOption.AllDirectories);
         foreach (var candidate in candidates)
         {
             try
             {
                 var map = PlanetMap.FromFile(this.mapDirectory, candidate);
                 if (map == null)
                 {
                     continue;
                 }
                 if (String.IsNullOrEmpty(map.Name))
                 {
                     continue;
                 }
                 if (map.Layers.Length == 0)
                 {
                     continue;
                 }
                 if (map.Type != mapType)
                 {
                     continue;
                 }
                 var pathName = candidate.Remove(0, this.mapDirectory.Length + 1);
                 this.AvailablePlanetMaps.Add(pathName, map);
                 API.UiElements.MapList.Items.Add(new MapSelectionItem {
                     MapName = map.Name.Trim('"', ' '), MapPath = pathName, Type = map.Type
                 });
             }
             catch (Exception ex)
             {
                 Program.WriteLog(ex);
                 continue;
             }
         }
     }
 }
コード例 #3
0
 public void Load(string map)
 {
     this.CurrentMap = PlanetMap.FromFile(this.mapDirectory, map);
 }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mapDir">Full path to map directory (cd_image/textures/Planetmap/)</param>
        /// <param name="mapFile">Full path to map file (AoRK/AoRK.txt)</param>
        /// <returns></returns>
        public static PlanetMap FromFile(string mapDir, string mapFile)
        {
            var map    = new PlanetMap();
            var layers = new List <PlanetMapLayer>();

            PlanetMapLayer currentLayer = null;

            using (var reader = new StreamReader(mapFile))
            {
                bool readingLayer = false;
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine().Trim();
                    if (String.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    var words = line.Split(' ');
                    if (!readingLayer)
                    {
                        // Name
                        if (words[0] == "Name")
                        {
                            map.Name = line.Substring("Name".Length + 1);
                            continue;
                        }
                        if (words[0] == "Type")
                        {
                            MapType mapType;
                            Enum.TryParse <MapType>(words[1], out mapType);
                            map.Type = mapType;
                            continue;
                        }
                        if (words[0] == "CoordsFile")
                        {
                            map.CoordsFile = Xml.Deserialize <MapCoords>(new FileInfo(Path.Combine(mapDir, words[1])));
                            continue;
                        }
                    }

                    if (words[0] == "File")
                    {
                        // Starting a new layer.
                        currentLayer = new PlanetMapLayer(Path.Combine(mapDir, words[1]));
                        layers.Add(currentLayer);
                        readingLayer = true;
                        continue;
                    }
                    if (currentLayer != null)
                    {
                        if (words[0] == "TextureSize")
                        {
                            currentLayer.TextureSize = int.Parse(words[1]);
                            continue;
                        }
                        if (words[0] == "Size")
                        {
                            currentLayer.Size = new Point(
                                int.Parse(words[1]),
                                int.Parse(words[2]));
                            continue;
                        }
                        if (words[0] == "Tiles")
                        {
                            currentLayer.Tiles = new Point(
                                int.Parse(words[1]),
                                int.Parse(words[2]));
                            continue;
                        }
                        if (words[0] == "MapRect")
                        {
                            currentLayer.MapRect = new Rectangle(
                                int.Parse(words[1]),
                                int.Parse(words[2]),
                                int.Parse(words[3]),
                                int.Parse(words[4]));
                            continue;
                        }
                        if (words[0] == "FilePos")
                        {
                            currentLayer.AddFilePos(int.Parse(words[1]));
                        }
                    }
                }
            }

            if (map.CoordsFile == null)
            {
                // Try to load default map coords
                if (!Xml.TryDeserialize <MapCoords>(
                        new FileInfo(Path.Combine(mapDir, "MapCoordinates.xml")),
                        out map.CoordsFile))
                {
                    // If loading default map coords failed, load the embedded map coords.
                    using (var ms = new MemoryStream(ASCIIEncoding.UTF8.GetBytes(Properties.Resources.MapCoordinates)))
                    {
                        map.CoordsFile = Xml.Deserialize <MapCoords>(ms);
                    }
                }
            }

            map.Layers = layers.ToArray();
            return(map);
        }