示例#1
0
        void cGenerator_SelectedIndexChanged(object sender, EventArgs e)
        {
            string genName = cGenerator.SelectedItem.ToString();

            SelectGenerator(MapGenUtil.GetGeneratorByName(genName));
            bGenerate.PerformClick();
        }
示例#2
0
        void MapGenParamsFromMap(string fileName, Map ourMap)
        {
            tStatus2.Text = "";

            string oldData;

            if (ourMap.Metadata.TryGetValue("_Origin", "GeneratorParams", out oldData))
            {
                // load legacy (pre-0.640) embedded generation parameters
                // TODO: legacy templates
                MessageBox.Show(LegacyTemplateMessage);
            }
            else
            {
                // load modern (0.640+) embedded generation parameters
                try {
                    MapGeneratorParameters genParams = MapGenUtil.LoadParamsFromMap(ourMap);
                    if (genParams == null)
                    {
                        tStatus1.Text = "No generation parameters found in " + fileName;
                        MessageBox.Show(
                            "No embedded map generation parameters found in " + fileName,
                            "No generation parameters found",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
                        return;
                    }
                    SelectGenerator(genParams.Generator);
                    SetGenParams(genParams);
                    tStatus1.Text = "Imported map generation from " + fileName;
                } catch (MapGenUtil.UnknownMapGeneratorException ex) {
                    tStatus1.Text = "No matching generator found for " + fileName;
                    MessageBox.Show("Could not find a matching map generator for \"" + ex.GeneratorName + "\"",
                                    "Missing map generator",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                } catch (Exception ex) {
                    tStatus1.Text = "Error loading parameters from " + fileName;
                    MessageBox.Show(ex.GetType().Name + Environment.NewLine + ex.Message,
                                    "Error loading parameters from " + fileName,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
        }
示例#3
0
        void LoadPresetFromFile()
        {
            if (loadPresetDialog == null)
            {
                loadPresetDialog = new OpenFileDialog {
                    Filter = "fCraft MapGen Preset|*.fmgp|" +
                             "All files|*.*",
                    InitialDirectory = Paths.MapPath
                };
            }
            if (loadPresetDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string       fullFileName       = loadPresetDialog.FileName;
            XDocument    doc                = XDocument.Load(fullFileName);
            XElement     root               = doc.Root;
            string       genName            = root.Element("Generator").Value;
            MapGenerator gen                = MapGenUtil.GetGeneratorByName(genName);
            string       versionMismatchMsg =
                String.Format("This preset was made for a different version of {0} map generator. Continue?",
                              gen.Name);

            if (gen.Version != new Version(root.Element("Version").Value) &&
                MessageBox.Show(versionMismatchMsg, "Version mismatch", MessageBoxButtons.YesNo) !=
                DialogResult.Yes)
            {
                return;
            }
            SelectGenerator(gen);
            MapGeneratorParameters genParams = gen.CreateParameters(root.Element("Parameters"));

            SetGenParams(genParams);
            SetStatus("Generation parameters loaded.");
            bGenerate.PerformClick();
        }