Beispiel #1
0
        private void ok_Click(object sender, EventArgs e)
        {
            stationSystemMap map = new stationSystemMap();
            FileStream fileStream = File.Open(edaFilename.Text, FileMode.Open);
            XmlSerializer serializer = new XmlSerializer(typeof(GameData));
            // get star system data to match stations
            for (int ii = 0; ii < data.stations.Count; ii++)
            {
                string systemName = map.checkIfStationPresent(data.stations[ii].CompleteName);
                if (systemName.Length == 0)
                    systemName = data.stations[ii].SystemName;
                string stationName = data.stations[ii].Name;
                if (systemName.Length == 0)
                {
                    // Last Option, because name not found: Ask.
                    starSystemNames_Input names = new starSystemNames_Input(data.stations[ii].CompleteName);
                    if (names.ShowDialog(this) == DialogResult.OK)
                        systemName = names.starSystemName.Text;
                    data.stations[ii].SystemName = systemName;
                    map.addSystemStation(outputData.StarSystems[ii].Name, data.stations[ii].CompleteName);
                    names.Dispose();
                }
                // Ready to add/update the data.
                Routines.AddOrUpdateStation(data, ii, outputData);

                /*
                // if the system the station is in has alread been defind use that...
                if (systemName.Length > 0)
                {
                    outputData.StarSystems.Add(new StarSystem());
                    outputData.StarSystems[ii].Name = systemName;
                    outputData.StarSystems[ii].Stations.Add(new Station(data.stations[ii]));
                }
                // ...otherwise ask
                else
                {
                    // Extract Station/System Name if possible
                    if (data.stations[ii].Name.IndexOf("(") != -1 &&
                        data.stations[ii].Name.IndexOf(")") != -1 &&
                        data.stations[ii].Name.IndexOf("(") < data.stations[ii].Name.IndexOf(")"))
                    {
                        outputData.StarSystems.Add(new StarSystem());
                        // Extract System name
                        outputData.StarSystems[ii].Name = data.stations[ii].Name.Substring(0, data.stations[ii].Name.IndexOf('(')).Trim();
                        // Extract Station name
                        data.stations[ii].Name = data.stations[ii].Name.Substring(
                                data.stations[ii].Name.IndexOf('('),
                                data.stations[ii].Name.IndexOf(')') - data.stations[ii].Name.IndexOf('(')
                            ).Trim();
                        outputData.StarSystems[ii].Stations.Add(new Station(data.stations[ii]));
                        map.addSystemStation(outputData.StarSystems[ii].Name, data.stations[ii].Name);
                    }
                    else
                    {
                        // Last Option, because name not found: Ask.
                        starSystemNames_Input names = new starSystemNames_Input(data.stations[ii].Name);
                        if (names.ShowDialog(this) == DialogResult.OK)
                        {
                            outputData.StarSystems.Add(new StarSystem());
                            outputData.StarSystems[ii].Name = names.starSystemName.Text;
                            outputData.StarSystems[ii].Stations.Add(new Station(data.stations[ii]));
                        }
                        // ...then add the system to the list
                        map.addSystemStation(outputData.StarSystems[ii].Name, data.stations[ii].Name);
                        names.Dispose();
                    }
                }
                */
            }

            // write game data to xml file
            serializer.Serialize(fileStream, outputData);

            // write station data to dat file
            map.writeMapFile();

            // close file
            fileStream.Close();

            // close dialogue
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Beispiel #2
0
        private void ok_Click(object sender, EventArgs e)
        {
            stationSystemMap map        = new stationSystemMap();
            FileStream       fileStream = File.Open(edaFilename.Text, FileMode.Open);
            XmlSerializer    serializer = new XmlSerializer(typeof(GameData));

            // get star system data to match stations
            for (int ii = 0; ii < data.stations.Count; ii++)
            {
                string systemName = map.checkIfStationPresent(data.stations[ii].CompleteName);
                if (systemName.Length == 0)
                {
                    systemName = data.stations[ii].SystemName;
                }
                string stationName = data.stations[ii].Name;
                if (systemName.Length == 0)
                {
                    // Last Option, because name not found: Ask.
                    starSystemNames_Input names = new starSystemNames_Input(data.stations[ii].CompleteName);
                    if (names.ShowDialog(this) == DialogResult.OK)
                    {
                        systemName = names.starSystemName.Text;
                    }
                    data.stations[ii].SystemName = systemName;
                    map.addSystemStation(outputData.StarSystems[ii].Name, data.stations[ii].CompleteName);
                    names.Dispose();
                }
                // Ready to add/update the data.
                Routines.AddOrUpdateStation(data, ii, outputData);

                /*
                 * // if the system the station is in has alread been defind use that...
                 * if (systemName.Length > 0)
                 * {
                 *  outputData.StarSystems.Add(new StarSystem());
                 *  outputData.StarSystems[ii].Name = systemName;
                 *  outputData.StarSystems[ii].Stations.Add(new Station(data.stations[ii]));
                 * }
                 * // ...otherwise ask
                 * else
                 * {
                 *  // Extract Station/System Name if possible
                 *  if (data.stations[ii].Name.IndexOf("(") != -1 &&
                 *      data.stations[ii].Name.IndexOf(")") != -1 &&
                 *      data.stations[ii].Name.IndexOf("(") < data.stations[ii].Name.IndexOf(")"))
                 *  {
                 *      outputData.StarSystems.Add(new StarSystem());
                 *      // Extract System name
                 *      outputData.StarSystems[ii].Name = data.stations[ii].Name.Substring(0, data.stations[ii].Name.IndexOf('(')).Trim();
                 *      // Extract Station name
                 *      data.stations[ii].Name = data.stations[ii].Name.Substring(
                 *              data.stations[ii].Name.IndexOf('('),
                 *              data.stations[ii].Name.IndexOf(')') - data.stations[ii].Name.IndexOf('(')
                 *          ).Trim();
                 *      outputData.StarSystems[ii].Stations.Add(new Station(data.stations[ii]));
                 *      map.addSystemStation(outputData.StarSystems[ii].Name, data.stations[ii].Name);
                 *  }
                 *  else
                 *  {
                 *      // Last Option, because name not found: Ask.
                 *      starSystemNames_Input names = new starSystemNames_Input(data.stations[ii].Name);
                 *      if (names.ShowDialog(this) == DialogResult.OK)
                 *      {
                 *          outputData.StarSystems.Add(new StarSystem());
                 *          outputData.StarSystems[ii].Name = names.starSystemName.Text;
                 *          outputData.StarSystems[ii].Stations.Add(new Station(data.stations[ii]));
                 *      }
                 *      // ...then add the system to the list
                 *      map.addSystemStation(outputData.StarSystems[ii].Name, data.stations[ii].Name);
                 *      names.Dispose();
                 *  }
                 * }
                 */
            }

            // write game data to xml file
            serializer.Serialize(fileStream, outputData);

            // write station data to dat file
            map.writeMapFile();

            // close file
            fileStream.Close();

            // close dialogue
            this.DialogResult = DialogResult.OK;
            this.Close();
        }