Example #1
0
        // Display grid to work
        private void DisplayGrid()
        {
            int size = 32;
            int x    = 0;
            int y    = 0;

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Is_Map    map  = new Is_Map();
                    Is_Map    map2 = new Is_Map();
                    Is_Map    map3 = new Is_Map();
                    Rectangle rect = new Rectangle();
                    rect.Width  = size;
                    rect.Height = size;
                    rect.Fill   = Brushes.White;
                    rect.Stroke = Brushes.Black;

                    Canvas.SetTop(rect, x);
                    Canvas.SetLeft(rect, y);
                    Map.Children.Add(rect);
                    myGrid[i, j] = Array_index;
                    y           += (size + 1);
                    New_Map1.Add(map);
                    New_Map1[Array_index].GetTileNumber = Tile_Type.Empty;
                    New_Map1[Array_index].Columns       = j + 1;
                    New_Map1[Array_index].Rows          = i + 1;

                    New_Map2.Add(map2);
                    New_Map2[Array_index].GetTileNumber = Tile_Type.Empty;
                    New_Map2[Array_index].Columns       = j + 1;
                    New_Map2[Array_index].Rows          = i + 1;

                    New_Map3.Add(map3);
                    New_Map3[Array_index].GetTileNumber = Tile_Type.Empty;
                    New_Map3[Array_index].Columns       = j + 1;
                    New_Map3[Array_index].Rows          = i + 1;

                    Array_index++;
                }
                y  = 0;
                x += (size + 1);
            }
            Array_index = 0;
        }
Example #2
0
        // Basically, it has been ultilized sprite generator's functions
        // When you fill all list, Combine generator will help to merge three images into a single image
        // Then the app would save a map to Json file
        private void Combine(object sender, RoutedEventArgs e)
        {
            List <Is_Map> All_Map            = new List <Is_Map>(300);
            int           Array_index2       = 0;
            int           Array_index_First  = 0;
            int           Array_index_Second = 0;
            int           Array_index_Third  = 0;

            if (direction == Direction.Horizontal)
            {
                for (int r = 0; r < 10; r++)
                {
                    for (int c = 0; c < 30; c++)
                    {
                        Is_Map is_Map = new Is_Map();
                        All_Map.Add(is_Map);
                        newGrid[r, c] = Array_index2;
                        All_Map[Array_index2].Columns = c + 1;
                        All_Map[Array_index2].Rows    = r + 1;
                        if (c >= 0 && c < 10)
                        {
                            All_Map[Array_index2].GetTileNumber = New_Map1[Array_index_First].GetTileNumber;
                            All_Map[Array_index2].TileName      = New_Map1[Array_index_First].TileName;
                            if (Array_index_First == 99)
                            {
                                Array_index_First = 0;
                            }
                            else
                            {
                                Array_index_First++;
                            }
                        }
                        else if (c >= 10 && c < 20)
                        {
                            All_Map[Array_index2].GetTileNumber = New_Map2[Array_index_Second].GetTileNumber;
                            All_Map[Array_index2].TileName      = New_Map2[Array_index_Second].TileName;

                            if (Array_index_Second == 99)
                            {
                                Array_index_Second = 0;
                            }
                            else
                            {
                                Array_index_Second++;
                            }
                        }
                        else
                        {
                            All_Map[Array_index2].GetTileNumber = New_Map3[Array_index_Third].GetTileNumber;
                            All_Map[Array_index2].TileName      = New_Map3[Array_index_Third].TileName;
                            if (Array_index_Third == 99)
                            {
                                Array_index_Third = 0;
                            }
                            else
                            {
                                Array_index_Third++;
                            }
                        }

                        Array_index2++;
                    }
                }

                SaveFileDialog saveFile = new SaveFileDialog();
                saveFile.Filter = "png files (*.png)|*.png|All files (*.*)|*.*";
                if (saveFile.ShowDialog() == true)
                {
                    string[] Files = { Info.ImagePath1, Info.ImagePath2, Info.ImagePath3 };
                    if (Info.ImagePath1 == string.Empty && Info.ImagePath2 == string.Empty && Info.ImagePath3 == string.Empty)
                    {
                        MessageBox.Show("An image is empty, since Images have been conflicted. Should choose different name of the file, not same");
                    }
                    else
                    {
                        int MaxWidth  = 0;
                        int MaxHeight = 0;
                        int Columns   = 3;
                        foreach (string Image in Files)
                        {
                            System.Drawing.Image image = System.Drawing.Image.FromFile(Image);
                            MaxWidth  = Math.Max(MaxWidth, image.Width);
                            MaxHeight = Math.Max(MaxHeight, image.Height);
                            image.Dispose();
                        }

                        int Width  = Columns * MaxWidth;
                        int Height = MaxHeight;

                        System.Drawing.Bitmap Sheet = new System.Drawing.Bitmap(Width, Height);

                        using (System.Drawing.Graphics GFX = System.Drawing.Graphics.FromImage(Sheet))
                        {
                            int Col = 0;
                            int Row = 0;
                            foreach (string F in Files)
                            {
                                System.Drawing.Image img = System.Drawing.Image.FromFile(F);
                                int x = (Col * MaxWidth) + (MaxWidth / 2 - img.Width / 2);
                                int y = (Row * MaxHeight) + (MaxHeight / 2 - img.Height / 2);

                                System.Drawing.Rectangle SrcRect  = new System.Drawing.Rectangle(0, 0, img.Width, img.Height);
                                System.Drawing.Rectangle DestRect = new System.Drawing.Rectangle(x, y, img.Width, img.Height);
                                GFX.DrawImage(img, DestRect, SrcRect, System.Drawing.GraphicsUnit.Pixel);
                                img.Dispose();

                                Col++;
                                if (Col == Columns)
                                {
                                    Col = 0;
                                    Row++;
                                }
                            }
                        }
                        Sheet.Save(saveFile.FileName); // The image will save new file into output path
                        string CompleteName = "Map.json";
                        if (File.Exists(CompleteName))
                        {
                            File.Delete(CompleteName);
                        }
                        var JsonSerilzation = JsonConvert.SerializeObject(All_Map, Formatting.Indented);
                        System.IO.File.WriteAllText(CompleteName, JsonSerilzation);
                        All_Map = null;
                        this.Box.SelectedItem = First_List;
                    }
                }
            }
            else if (direction == Direction.Vertical)
            {
                for (int r = 0; r < 30; r++)
                {
                    for (int c = 0; c < 10; c++)
                    {
                        Is_Map is_Map = new Is_Map();
                        All_Map.Add(is_Map);
                        newGrid[r, c] = Array_index2;
                        All_Map[Array_index2].Columns = c + 1;
                        All_Map[Array_index2].Rows    = r + 1;
                        if (r >= 0 && r < 10)
                        {
                            All_Map[Array_index2].GetTileNumber = New_Map1[Array_index_First].GetTileNumber;
                            All_Map[Array_index2].TileName      = New_Map1[Array_index_First].TileName;
                            if (Array_index_First == 99)
                            {
                                Array_index_First = 0;
                            }
                            else
                            {
                                Array_index_First++;
                            }
                        }
                        else if (r >= 10 && r < 20)
                        {
                            All_Map[Array_index2].GetTileNumber = New_Map2[Array_index_Second].GetTileNumber;
                            All_Map[Array_index2].TileName      = New_Map2[Array_index_Second].TileName;

                            if (Array_index_Second == 99)
                            {
                                Array_index_Second = 0;
                            }
                            else
                            {
                                Array_index_Second++;
                            }
                        }
                        else
                        {
                            All_Map[Array_index2].GetTileNumber = New_Map3[Array_index_Third].GetTileNumber;
                            All_Map[Array_index2].TileName      = New_Map3[Array_index_Third].TileName;
                            if (Array_index_Third == 99)
                            {
                                Array_index_Third = 0;
                            }
                            else
                            {
                                Array_index_Third++;
                            }
                        }

                        Array_index2++;
                    }
                }

                SaveFileDialog saveFile2 = new SaveFileDialog();
                saveFile2.Filter = "png files (*.png)|*.png|All files (*.*)|*.*";
                if (saveFile2.ShowDialog() == true)
                {
                    string[] Files = { Info.ImagePath1, Info.ImagePath2, Info.ImagePath3 };
                    if (Info.ImagePath1 == string.Empty && Info.ImagePath2 == string.Empty && Info.ImagePath3 == string.Empty)
                    {
                        MessageBox.Show("An image is empty, since Images have been conflicted. Should choose different name of the file, not same");
                    }
                    else
                    {
                        int MaxWidth  = 0;
                        int MaxHeight = 0;
                        int Columns   = 1;
                        int Rows      = 3;
                        foreach (string Image in Files)
                        {
                            System.Drawing.Image image = System.Drawing.Image.FromFile(Image);
                            MaxWidth  = Math.Max(MaxWidth, image.Width);
                            MaxHeight = Math.Max(MaxHeight, image.Height);
                            image.Dispose();
                        }

                        int Width  = MaxWidth;
                        int Height = Rows * MaxHeight;

                        System.Drawing.Bitmap Sheet = new System.Drawing.Bitmap(Width, Height);

                        using (System.Drawing.Graphics GFX = System.Drawing.Graphics.FromImage(Sheet))
                        {
                            int Col = 0;
                            int Row = 0;
                            foreach (string F in Files)
                            {
                                System.Drawing.Image img = System.Drawing.Image.FromFile(F);
                                int x = (Col * MaxWidth) + (MaxWidth / 2 - img.Width / 2);
                                int y = (Row * MaxHeight) + (MaxHeight / 2 - img.Height / 2);

                                System.Drawing.Rectangle SrcRect  = new System.Drawing.Rectangle(0, 0, img.Width, img.Height);
                                System.Drawing.Rectangle DestRect = new System.Drawing.Rectangle(x, y, img.Width, img.Height);
                                GFX.DrawImage(img, DestRect, SrcRect, System.Drawing.GraphicsUnit.Pixel);
                                img.Dispose();

                                Col++;
                                if (Col == Columns)
                                {
                                    Col = 0;
                                    Row++;
                                }
                            }
                        }
                        Sheet.Save(saveFile2.FileName); // The image will save new file into output path
                        string CompleteName = "Map.json";
                        if (File.Exists(CompleteName))
                        {
                            File.Delete(CompleteName);
                        }
                        var JsonSerilzation = JsonConvert.SerializeObject(All_Map, Formatting.Indented);
                        System.IO.File.WriteAllText(CompleteName, JsonSerilzation);
                        All_Map = null;
                        this.Box.SelectedItem = First_List;
                    }
                }
            }
        }
Example #3
0
        private void Reset_Map(object sender, RoutedEventArgs e)
        {
            Array_index = 0;
            if (Map_Number == 0)
            {
                New_Map1.Clear();
                First_Check.IsChecked    = false;
                Combine_Button.IsEnabled = false;

                foreach (var t in Map.Children.OfType <Rectangle>())
                {
                    t.Fill = Brushes.White;
                }

                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        Is_Map map1 = new Is_Map();
                        New_Map1.Add(map1);
                        New_Map1[Array_index].GetTileNumber = Tile_Type.Empty;
                        New_Map1[Array_index].Columns       = j + 1;
                        New_Map1[Array_index].Rows          = i + 1;
                    }
                }
                Array_index = 0;
            }
            else if (Map_Number == 1)
            {
                New_Map2.Clear();
                Second_Check.IsChecked   = false;
                Combine_Button.IsEnabled = false;
                foreach (var t in Map.Children.OfType <Rectangle>())
                {
                    t.Fill = Brushes.White;
                }

                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        Is_Map map2 = new Is_Map();
                        New_Map2.Add(map2);
                        New_Map2[Array_index].GetTileNumber = Tile_Type.Empty;
                        New_Map2[Array_index].Columns       = j + 1;
                        New_Map2[Array_index].Rows          = i + 1;
                    }
                }
                Array_index = 0;
            }
            else if (Map_Number == 2)
            {
                New_Map3.Clear();
                Third_Check.IsChecked    = false;
                Combine_Button.IsEnabled = false;
                foreach (var t in Map.Children.OfType <Rectangle>())
                {
                    t.Fill = Brushes.White;
                }

                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        Is_Map map3 = new Is_Map();
                        New_Map3.Add(map3);
                        New_Map3[Array_index].GetTileNumber = Tile_Type.Empty;
                        New_Map3[Array_index].Columns       = j + 1;
                        New_Map3[Array_index].Rows          = i + 1;
                    }
                }
                Array_index = 0;
            }
        }