Exemple #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="routes"></param>
 private void SetupRouteNodes(RouteNodeCollection routes)
 {
     foreach (RouteNode node in routes)
     {
         var tile = this[node.Row, node.Col, node.Lev];
         if (tile != null)
         {
             ((XCMapTile)tile).Node = node;
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// cTor.
        /// </summary>
        /// <param name="descriptor"></param>
        /// <param name="parts"></param>
        /// <param name="routes"></param>
        internal MapFileChild(
            Descriptor descriptor,
            List <TilepartBase> parts,
            RouteNodeCollection routes)
            :
            base(descriptor, parts)
        {
            string dirMap = Path.Combine(Descriptor.BasePath, MapsDir);

            FullPath = Path.Combine(
                dirMap,
                Descriptor.Label + MapExt);

            Terrains = Descriptor.Terrains;

            Routes = routes;

            if (File.Exists(FullPath))
            {
                for (int i = 0; i != parts.Count; ++i)
                {
                    parts[i].TilesetId = i;
                }

                ReadMapFile(parts);
                SetupRouteNodes(routes);
                CalculateOccultations();
            }
            else
            {
                string error = String.Format(
                    System.Globalization.CultureInfo.CurrentCulture,
                    "The file does not exist{0}{0}{1}",
                    Environment.NewLine,
                    FullPath);
                MessageBox.Show(
                    error,
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    0);
            }
        }
Exemple #3
0
        public static MapFileBase LoadTileset(Descriptor descriptor)
        {
            //LogFile.WriteLine("");
            //LogFile.WriteLine("MapFileService.LoadTileset descriptor= " + descriptor);

            if (descriptor != null)
            {
                string dirMap = Path.Combine(descriptor.BasePath, MapFileChild.MapsDir);
                string pfeMap = Path.Combine(
                    dirMap,
                    descriptor.Label + MapFileChild.MapExt);
                //LogFile.WriteLine(". pfeMap= " + pfeMap);

                if (File.Exists(pfeMap))
                {
                    //LogFile.WriteLine(". . Map file exists");

                    var parts = new List <TilepartBase>();

                    foreach (string terrain in descriptor.Terrains)                     // push together the tileparts of all allocated terrains
                    {
                        var MCD = descriptor.GetTerrainRecords(terrain);
                        foreach (Tilepart part in MCD)
                        {
                            parts.Add(part);
                        }
                    }

                    if (parts.Count != 0)
                    {
                        var RMP = new RouteNodeCollection(descriptor.Label, descriptor.BasePath);
                        var MAP = new MapFileChild(
                            descriptor,
                            parts,
                            RMP);
                        return(MAP);
                    }

                    //LogFile.WriteLine(". . . descriptor has no terrains");
                    MessageBox.Show(
                        "There are no terrains allocated or they do not contain MCD records.",
                        "Warning",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning,
                        MessageBoxDefaultButton.Button1,
                        0);
                }
                else
                {
                    //LogFile.WriteLine(". . Mapfile does NOT exist");
                    MessageBox.Show(
                        "The Mapfile does not exist.",
                        "Warning",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning,
                        MessageBoxDefaultButton.Button1,
                        0);
                }
            }
            else
            {
                //LogFile.WriteLine(". descriptor NOT Valid");
                MessageBox.Show(
                    "The tileset is not valid.",
                    "Warning",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning,
                    MessageBoxDefaultButton.Button1,
                    0);
            }

            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Loads a tileset. Called by XCMainWindow.LoadSelectedMap()
        /// @note Check that 'descriptor' is not null before call.
        /// </summary>
        /// <param name="descriptor"></param>
        /// <param name="treechanged"></param>
        /// <returns></returns>
        public static MapFileBase LoadTileset(Descriptor descriptor, ref bool treechanged)
        {
            //LogFile.WriteLine("");
            //LogFile.WriteLine("MapFileService.LoadTileset descriptor= " + descriptor);

            string pfeMap = descriptor.Basepath;

            if (!String.IsNullOrEmpty(pfeMap))             // -> the BasePath can be null if resource-type is notconfigured.
            {
                pfeMap = Path.Combine(
                    Path.Combine(descriptor.Basepath, GlobalsXC.MapsDir),
                    descriptor.Label + GlobalsXC.MapExt);
            }
            //LogFile.WriteLine(". pfeMap= " + pfeMap);

            if (!File.Exists(pfeMap))             // Open a folderbrowser for user to point to a basepath ->
            {
                if (MessageBox.Show(
                        "The Mapfile does not exist."
                        + Environment.NewLine + Environment.NewLine
                        + "Do you want to browse for a different basepath to the .MAP and .RMP files?",
                        "Warning",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Warning,
                        MessageBoxDefaultButton.Button1,
                        0) == DialogResult.Yes)
                {
                    using (var fbd = new FolderBrowserDialog())
                    {
                        string basepath = descriptor.Basepath;
                        if (!String.IsNullOrEmpty(basepath) &&
                            Directory.Exists(basepath))
                        {
                            fbd.SelectedPath = basepath;
                        }
                        // TODO: Check descriptor's Palette and default to Ufo/Tftd Resource dir instead.

                        fbd.Description = String.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            "Browse to a basepath folder. A valid basepath folder"
                            + " has the subfolders MAPS and ROUTES.");

                        if (fbd.ShowDialog() == DialogResult.OK)
                        {
                            pfeMap = Path.Combine(fbd.SelectedPath, GlobalsXC.MapsDir);
                            pfeMap = Path.Combine(pfeMap, descriptor.Label + GlobalsXC.MapExt);

                            if (File.Exists(pfeMap))
                            {
                                descriptor.Basepath = fbd.SelectedPath;
                                treechanged         = true;
                            }
                            else
                            {
                                MessageBox.Show(
                                    descriptor.Label + GlobalsXC.MapExt
                                    + " was not found in that basepath.",
                                    "Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1,
                                    0);
                            }
                        }
                    }
                }
            }

            if (File.Exists(pfeMap))
            {
                //LogFile.WriteLine(". . Map file exists");

                var tileparts = new List <TilepartBase>();

                for (int i = 0; i != descriptor.Terrains.Count; ++i)                 // push together the tileparts of all allocated terrains
                {
                    //LogFile.WriteLine(". . . terrain= " + descriptor.Terrains[i].Item1 + " : " + descriptor.Terrains[i].Item2);

                    var MCD = descriptor.GetTerrainRecords(i);                     // NOTE: Calls ResourceInfo.LoadSpriteset() also.
                    foreach (Tilepart tilepart in MCD)
                    {
                        tileparts.Add(tilepart);
                    }
                }

                if (tileparts.Count != 0)
                {
                    if (tileparts.Count > MAX_MCDRECORDS)                     // issue warning ->
                    {
                        string text = String.Empty;

                        int lengthTotal = 0;
                        for (int i = 0; i != descriptor.Terrains.Count; ++i)                         // do it again ...
                        {
                            string terrain = descriptor.Terrains[i].Item1;
                            if (terrain.Length > lengthTotal)
                            {
                                lengthTotal = terrain.Length;
                            }
                        }

                        for (int i = 0; i != descriptor.Terrains.Count; ++i)                         // do it again ...
                        {
                            string terrain = descriptor.Terrains[i].Item1;
                            string st      = terrain;

                            int length = terrain.Length;
                            while (length++ != lengthTotal)
                            {
                                st += " ";
                            }

                            int records = descriptor.GetRecordCount(i);
                            text += st + " - " + records + Environment.NewLine;
                        }
                        text += Environment.NewLine + "total - " + tileparts.Count;

                        MapFileWarn.Instance.Show();
                        MapFileWarn.Instance.SetText(descriptor.Label, text);
                    }

                    var RMP = new RouteNodeCollection(descriptor.Label, descriptor.Basepath);
                    var MAP = new MapFileChild(
                        descriptor,
                        tileparts,
                        RMP);
                    return(MAP);
                }

                //LogFile.WriteLine(". . . descriptor has no terrains");
                MessageBox.Show(
                    "There are no terrains allocated or they do not contain MCD records.",
                    "Warning",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning,
                    MessageBoxDefaultButton.Button1,
                    0);
            }

            return(null);
        }