Beispiel #1
0
        private void commitButton_Click(object sender, EventArgs e)
        {
            if (gennedTypes == null)
            {
                gennedTypes = new MapStore();
            }
            //Open world_gen.txt
            openWorldgenFile.ShowDialog();

            //Save it!
            if (openWorldgenFile.FileName == "world_gen.txt") //Having the default name means you've not specified a path
            {
                MessageBox.Show("Cancelled");
            }
            else if (gennedTypes.isEmpty() == true)
            {
                MessageBox.Show("You've not imported any map data!");
            }
            else if (openWorldgenFile.FileName.Substring(openWorldgenFile.FileName.Length - 4, 4) != ".txt")
            {
                string x = openWorldgenFile.FileName.Substring(openWorldgenFile.FileName.Length - 4, 4);
                MessageBox.Show("That doesn't appear to be a text file");
            }
            else
            {
                HeightmapProcessing.CommitToFile(int.Parse(xComboBox.SelectedItem.ToString()), int.Parse(yComboBox.SelectedItem.ToString()), nameTextBox.Text, gennedTypes, openWorldgenFile.FileName);
            }
        }
Beispiel #2
0
        private void commitButton_Click(object sender, EventArgs e)
        {
            if (gennedTypes == null)
            {
                gennedTypes = new MapStore();
            }
            //Open world_gen.txt
            openWorldgenFile.ShowDialog();

            //Save it!
            if (openWorldgenFile.FileName == "world_gen.txt") //Having the default name means you've not specified a path
            {
                MessageBox.Show("Cancelled");
            }
            else if (gennedTypes.isEmpty() == true)
            {
                MessageBox.Show("You've not imported any map data!");
            }
            else if (openWorldgenFile.FileName.Substring(openWorldgenFile.FileName.Length - 4, 4) != ".txt")
            {
                string x = openWorldgenFile.FileName.Substring(openWorldgenFile.FileName.Length - 4, 4);
                MessageBox.Show("That doesn't appear to be a text file");
            }
            else
            {
                HeightmapProcessing.CommitToFile(int.Parse(xComboBox.SelectedItem.ToString()), int.Parse(yComboBox.SelectedItem.ToString()), nameTextBox.Text, gennedTypes, openWorldgenFile.FileName);
            }
        }
Beispiel #3
0
 private void clearButton_Click(object sender, EventArgs e)
 {
     gennedTypes = new MapStore(); //Flush out old gennedTypes
     TypesListBox.Items.Clear();
     commitButton.Enabled = false;
     xComboBox.Enabled = true;
     yComboBox.Enabled = true;
 }
Beispiel #4
0
 private void clearButton_Click(object sender, EventArgs e)
 {
     gennedTypes = new MapStore(); //Flush out old gennedTypes
     TypesListBox.Items.Clear();
     commitButton.Enabled = false;
     xComboBox.Enabled    = true;
     yComboBox.Enabled    = true;
 }
Beispiel #5
0
        private void goButton_Click(object sender, EventArgs e)
        {
            if (gennedTypes == null)
            {
                gennedTypes = new MapStore();
            }

            int conversionType = 0;
            switch (TypeComboBox.SelectedItem.ToString())
            {
                case "Elevation":
                    conversionType = (int)ImportType.ELEV;
                    break;
                case "Rainfall":
                    conversionType = (int)ImportType.RAIN;
                    break;
                case "Temperature":
                    conversionType = (int)ImportType.TEMP;
                    break;
                case "Drainage":
                    conversionType = (int)ImportType.DRAIN;
                    break;
                case "Savagery":
                    conversionType = (int)ImportType.SAV;
                    break;
                case "Volcanicity":
                    conversionType = (int)ImportType.VOLC;
                    break;
                default:
                    conversionType = (int)ImportType.ELEV;
                    break;
            }

            if (HeightmapProcessing.ProcessMap(heightmapFileNameTextbox.Text, int.Parse(xComboBox.SelectedItem.ToString()), int.Parse(yComboBox.SelectedItem.ToString()), int.Parse(offsetTextBox.Text), float.Parse(ratioTextBox.Text), conversionType, gennedTypes, TypesListBox) == true)
            {
                heightmapFileNameTextbox.Text = string.Empty;
                if (gennedTypes.isEmpty() != true)
                {
                    commitButton.Enabled = true;
                    xComboBox.Enabled = false;
                    yComboBox.Enabled = false;
                }
                else
                {
                    commitButton.Enabled = false;
                    xComboBox.Enabled = true;
                    yComboBox.Enabled = true;
                }
            }
            else
            {
                MessageBox.Show("Failed to process map!");
            }
        }
Beispiel #6
0
        public static bool ProcessMap(string heightMapPath, int finalXSize, int finalYSize, int heightAdjust, float colourToHeightRatio, int type, MapStore gennedTypes, System.Windows.Forms.ListBox gennedTypesWindow) //Eventually, we're going to need to pass arguments!
        {
            //Load our bitmap
            Bitmap heightmap = null;

            try
            {
                heightmap = new Bitmap(heightMapPath);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Failed to load image - are you sure it's a valid bitmap?");
                return(false);
            }
            //Resize the image
            Bitmap   heightmapResized = new Bitmap(finalXSize, finalYSize);
            Graphics resizer          = Graphics.FromImage((Image)heightmapResized);

            resizer.DrawImage(heightmap, 0, 0, finalXSize, finalYSize);

            //TODO: Change the resolution if need be

            //Store it in a legible array
            int[,] imageArray = new int[finalXSize, finalYSize];
            for (int x = 0; x < finalXSize; x++)
            {
                for (int y = 0; y < finalYSize; y++)
                {
                    float averagedPixel = ((heightmapResized.GetPixel(x, y).R) + (heightmapResized.GetPixel(x, y).G) + (heightmapResized.GetPixel(x, y).B)) / 3;
                    averagedPixel    = (averagedPixel * colourToHeightRatio) + heightAdjust;
                    imageArray[x, y] = (int)averagedPixel;
                }
            }

            if (gennedTypes.getItem(type) == null)
            {
                switch (type)
                {
                case (int)ImportType.ELEV:
                    gennedTypesWindow.Items.Add("Elevation");
                    break;

                case (int)ImportType.RAIN:
                    gennedTypesWindow.Items.Add("Rainfall");
                    break;

                case (int)ImportType.TEMP:
                    gennedTypesWindow.Items.Add("Temperature");
                    break;

                case (int)ImportType.DRAIN:
                    gennedTypesWindow.Items.Add("Drainage");
                    break;

                case (int)ImportType.SAV:
                    gennedTypesWindow.Items.Add("Savagery");
                    break;

                case (int)ImportType.VOLC:
                    gennedTypesWindow.Items.Add("Volcanicity");
                    break;
                }
            }
            //Stuff it into our storage collection
            gennedTypes.setItem(type, imageArray);


            System.Windows.Forms.MessageBox.Show("Added to the array!");
            return(true);
        }
Beispiel #7
0
        public static void CommitToFile(int finalXSize, int finalYSize, string mapname, MapStore finishedTypes, string worldGenFilePath)
        {
            StreamWriter SW;

            SW = File.AppendText(worldGenFilePath);
            SW.WriteLine();

            int squares = finalXSize * finalYSize;

            if (squares <= 289)
            {
                SW.Write(WorldGenTemplate.GetPocketSettings(mapname, finalXSize, finalYSize));
            }
            else if (squares <= 289)
            {
                SW.Write(WorldGenTemplate.GetSmallerSettings(mapname, finalXSize, finalYSize));
            }
            else if (squares <= 1089)
            {
                SW.Write(WorldGenTemplate.GetSmallSettings(mapname, finalXSize, finalYSize));
            }
            else if (squares <= 4225)
            {
                SW.Write(WorldGenTemplate.GetMediumSettings(mapname, finalXSize, finalYSize));
            }
            else
            {
                SW.Write(WorldGenTemplate.GetLargeSettings(mapname, finalXSize, finalYSize));
            }
            //SW.Write();
            //Now write the remaining types

            for (int i = 0; i < 6; i++)
            {
                int[,] heightMap = finishedTypes.getItem(i);
                if (heightMap != null)
                {
                    string dataType = string.Empty;
                    switch (i)
                    {
                    case (int)ImportType.ELEV:
                        dataType = "[PS_EL";
                        break;

                    case (int)ImportType.RAIN:
                        dataType = "[PS_RF";
                        break;

                    case (int)ImportType.TEMP:
                        dataType = "[PS_TP";
                        break;

                    case (int)ImportType.DRAIN:
                        dataType = "[PS_DR";
                        break;

                    case (int)ImportType.SAV:
                        dataType = "[PS_SV";
                        break;

                    case (int)ImportType.VOLC:
                        dataType = "[PS_VL";
                        break;
                    }

                    for (int y = 0; y < finalYSize; y++)
                    {
                        SW.WriteLine();

                        SW.Write(dataType);
                        for (int x = 0; x < finalXSize; x++)
                        {
                            SW.Write(":");
                            SW.Write(heightMap[x, y]);
                        }
                        SW.Write("]");
                    }
                }
            }
            SW.Close();
            System.Windows.Forms.MessageBox.Show("Saved!");
        }
        //Eventually, we're going to need to pass arguments!
        public static bool ProcessMap(string heightMapPath, int finalXSize, int finalYSize, int heightAdjust, float colourToHeightRatio, int type, MapStore gennedTypes, System.Windows.Forms.ListBox gennedTypesWindow)
        {
            //Load our bitmap
            Bitmap heightmap = null;
            try
            {
                heightmap = new Bitmap(heightMapPath);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Failed to load image - are you sure it's a valid bitmap?");
                return false;
            }
            //Resize the image
            Bitmap heightmapResized = new Bitmap(finalXSize, finalYSize);
            Graphics resizer = Graphics.FromImage( (Image) heightmapResized );
            resizer.DrawImage( heightmap, 0, 0, finalXSize, finalYSize );

            //TODO: Change the resolution if need be

            //Store it in a legible array
            int[,] imageArray = new int[finalXSize, finalYSize];
            for (int x = 0; x < finalXSize; x++)
            {
                for (int y = 0; y < finalYSize; y++)
                {
                    float averagedPixel = ((heightmapResized.GetPixel(x, y).R) + (heightmapResized.GetPixel(x, y).G) + (heightmapResized.GetPixel(x, y).B)) / 3;
                    averagedPixel = (averagedPixel * colourToHeightRatio) + heightAdjust;
                    imageArray[x, y] = (int)averagedPixel;
                }
            }

            if (gennedTypes.getItem(type) == null)
            {
                switch (type)
                {
                    case (int)ImportType.ELEV:
                        gennedTypesWindow.Items.Add("Elevation");
                        break;
                    case (int)ImportType.RAIN:
                        gennedTypesWindow.Items.Add("Rainfall");
                        break;
                    case (int)ImportType.TEMP:
                        gennedTypesWindow.Items.Add("Temperature");
                        break;
                    case (int)ImportType.DRAIN:
                        gennedTypesWindow.Items.Add("Drainage");
                        break;
                    case (int)ImportType.SAV:
                        gennedTypesWindow.Items.Add("Savagery");
                        break;
                    case (int)ImportType.VOLC:
                        gennedTypesWindow.Items.Add("Volcanicity");
                        break;
                }
            }
            //Stuff it into our storage collection
            gennedTypes.setItem(type, imageArray);

            System.Windows.Forms.MessageBox.Show("Added to the array!");
            return true;
        }
        public static void CommitToFile(int finalXSize, int finalYSize, string mapname, MapStore finishedTypes, string worldGenFilePath)
        {
            StreamWriter SW;
            SW = File.AppendText(worldGenFilePath);
            SW.WriteLine();

            int squares = finalXSize * finalYSize;
            if (squares <= 289)
            {
                SW.Write(WorldGenTemplate.GetPocketSettings(mapname, finalXSize, finalYSize));
            }
            else if (squares <= 289)
            {
                SW.Write(WorldGenTemplate.GetSmallerSettings(mapname, finalXSize, finalYSize));
            }
            else if (squares <= 1089)
            {
                SW.Write(WorldGenTemplate.GetSmallSettings(mapname, finalXSize, finalYSize));
            }
            else if (squares <= 4225)
            {
                SW.Write(WorldGenTemplate.GetMediumSettings(mapname, finalXSize, finalYSize));
            }
            else
            {
                SW.Write(WorldGenTemplate.GetLargeSettings(mapname, finalXSize, finalYSize));
            }
            //SW.Write();
            //Now write the remaining types

            for (int i = 0; i < 6; i++)
            {
                int[,] heightMap = finishedTypes.getItem(i);
                if (heightMap != null)
                {
                    string dataType = string.Empty;
                    switch (i)
                    {
                        case (int)ImportType.ELEV:
                            dataType = "[PS_EL";
                            break;
                        case (int)ImportType.RAIN:
                            dataType = "[PS_RF";
                            break;
                        case (int)ImportType.TEMP:
                            dataType = "[PS_TP";
                            break;
                        case (int)ImportType.DRAIN:
                            dataType = "[PS_DR";
                            break;
                        case (int)ImportType.SAV:
                            dataType = "[PS_SV";
                            break;
                        case (int)ImportType.VOLC:
                            dataType = "[PS_VL";
                            break;
                    }

                    for (int y = 0; y < finalYSize; y++)
                    {
                        SW.WriteLine();

                        SW.Write(dataType);
                        for (int x = 0; x < finalXSize; x++)
                        {
                            SW.Write(":");
                            SW.Write(heightMap[x, y]);
                        }
                        SW.Write("]");
                    }
                }
            }
            SW.Close();
            System.Windows.Forms.MessageBox.Show("Saved!");
        }
Beispiel #10
0
        private void goButton_Click(object sender, EventArgs e)
        {
            if (gennedTypes == null)
            {
                gennedTypes = new MapStore();
            }

            int conversionType = 0;

            switch (TypeComboBox.SelectedItem.ToString())
            {
            case "Elevation":
                conversionType = (int)ImportType.ELEV;
                break;

            case "Rainfall":
                conversionType = (int)ImportType.RAIN;
                break;

            case "Temperature":
                conversionType = (int)ImportType.TEMP;
                break;

            case "Drainage":
                conversionType = (int)ImportType.DRAIN;
                break;

            case "Savagery":
                conversionType = (int)ImportType.SAV;
                break;

            case "Volcanicity":
                conversionType = (int)ImportType.VOLC;
                break;

            default:
                conversionType = (int)ImportType.ELEV;
                break;
            }

            if (HeightmapProcessing.ProcessMap(heightmapFileNameTextbox.Text, int.Parse(xComboBox.SelectedItem.ToString()), int.Parse(yComboBox.SelectedItem.ToString()), int.Parse(offsetTextBox.Text), float.Parse(ratioTextBox.Text), conversionType, gennedTypes, TypesListBox) == true)
            {
                heightmapFileNameTextbox.Text = string.Empty;
                if (gennedTypes.isEmpty() != true)
                {
                    commitButton.Enabled = true;
                    xComboBox.Enabled    = false;
                    yComboBox.Enabled    = false;
                }
                else
                {
                    commitButton.Enabled = false;
                    xComboBox.Enabled    = true;
                    yComboBox.Enabled    = true;
                }
            }
            else
            {
                MessageBox.Show("Failed to process map!");
            }
        }
 public void DisplayMap(int xSize, int ySize, int type, MapStore gennedTypes)
 {
     visualisedPictureBox.Image = (Image)HeightmapProcessing.GenerateBitmapFromData(xSize, ySize, type, gennedTypes.getItem(type));
     this.Show();
 }