Ejemplo n.º 1
0
        /// <summary>
        /// Parses the tile document and loads the files into the dictionary
        /// </summary>
        public static bool Read()
        {
            if (TileDictionary == null)
                TileDictionary = "tile_dictionary.txt";
            if (ObjectDictionary == null)
                ObjectDictionary = "object_dictionary.txt";
            if (EventDictionary == null)
                EventDictionary = "event_dictionary.txt";

            bool result = false;
            try
            {
                using (StreamReader streamReader = new StreamReader(tileFile))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        //Consider all lines that are not comments.
                        if (!line.StartsWith("#") && !String.IsNullOrEmpty(line))
                        {
                            // Remove any trailing comments.
                            if (line.Contains("#"))
                            {
                                line = line.Substring(0, line.IndexOf("#"));
                            }

                            string tile = line.Substring(line.IndexOf(':') + 1);
                            tile = tile.Substring(0, tile.Length - 4);
                            int tileID = int.Parse(line.Substring(0, line.IndexOf(':')));

                            Texture2D tileTexture = ServiceManager.Resources.GetTileTexture(tile);
                            tileDictionary.Add(tileID, tileTexture);
                        }
                    }
                }

                using (StreamReader streamReader = new StreamReader(ObjectDictionary))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        //Consider all lines that are not comments.
                        if (!line.StartsWith("#"))
                        {
                            // Remove any trailing comments.
                            if (line.Contains("#"))
                            {
                                line = line.Substring(0, line.IndexOf("#"));
                            }

                            string obj = line.Substring(line.IndexOf(':') + 1);
                            obj = obj.Substring(0, obj.Length - 4);
                            int objectID = int.Parse(line.Substring(0, line.IndexOf(':')));

                            Model objectModel = ServiceManager.Resources.GetModel(
                                String.Format("objects\\{0}", obj));
                            objectDictionary.Add(objectID, objectModel);
                        }
                    }
                }

                result = true;
                Initialized = true;
            }
            catch (FileNotFoundException err)
            {
                // TODO: The user should probably know about this.
                ServiceManager.Game.Console.DebugPrint(
                    "File could not be found: " + err);
            }
            catch (IOException e)
            {
                ServiceManager.Game.Console.DebugPrint(
                    "I/O error reading the tile dictionary: " + e);
                MessageBox alert = new MessageBox(ServiceManager.Game.Manager,
                    MessageBox.MessageBoxType.ERROR,
                    string.Format("An error occured while trying to read {0}: {1}",
                        tileFile, e.Message),
                    "Error reading tile dictionary file.");
            }
            catch (Exception e)
            {
                ServiceManager.Game.Console.DebugPrint(
                    "The tile dictionary {0} is corrupted: {1}", tileFile, e);
                MessageBox alert = new MessageBox(ServiceManager.Game.Manager,
                    MessageBox.MessageBoxType.ERROR,
                    string.Format("The file {0} is corrupted.\nTry running the patcher again." +
                    "If that doesn't work, please visit the website for help.", tileFile),
                    "Error reading tile dictionary file.");
            }

            return result;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize any components required by this state.
        /// </summary>
        public override void Initialize()
        {
            serverList = ServiceManager.Echelon.GetGameServerList();
            serverInfo = new List<String[]>();

            foreach (Network.Util.GameServerInfo server in serverList)
            {
                serverInfo.Add(new String[] {
                    server.Name,
                    Toolkit.GameModeToString(server.CurrentGameMode),
                    server.CurrentMap.Substring(0, server.CurrentMap.IndexOf(".vtmap")),
                    server.NumberOfPlayers.ToString() + " / " + server.PlayerLimit.ToString(),
                    server.GetFormattedAverageLatency(),
                    server.Approved ? "Yes" : "No"
                });
            }

            ServiceManager.Game.Console.DebugPrint(
                "{0} game servers loaded.", serverList.Length);

            form = new ServerList(ServiceManager.Game.Manager, headers, serverInfo);
            ServiceManager.Game.FormManager.SwitchWindows(form.Window);

            form.Play.Enabled = false;
            form.Back.Click += new TomShane.Neoforce.Controls.EventHandler(Back_Click);
            form.Refresh.Click += new TomShane.Neoforce.Controls.EventHandler(Refresh_Click);
            form.Play.Click += new TomShane.Neoforce.Controls.EventHandler(Play_Click);
            form.SelectionChanged += new TomShane.Neoforce.Controls.EventHandler(SelectionChanged);
            if (serverList.Length > 0)
            {
                form.SelectedIndex = 0;
                form.Play.Enabled = true;
            }

            if (errorMessage != null)
            {
                MessageBox alert = new MessageBox(ServiceManager.Game.Manager,
                    MessageBox.MessageBoxType.ERROR,
                    errorMessage, "Cannot connect.");
            }
        }