/// <summary>
        /// Orb Picker. Changes the entire background of a world.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OrbsRadioButton_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mi = sender as MenuItem;
            if (mi != null)
            {
                if (mi.Icon is RadioButton rb)
                {
                    rb.IsChecked = true;
                }
            }

            BackgroundData.BackgroundType bt;
            switch (mi.Name)
            {
                case "Forest":
                    bt = BackgroundData.BackgroundType.Forest;
                    break;
                case "Night":
                    bt = BackgroundData.BackgroundType.Night;
                    break;
                case "Star":
                    bt = BackgroundData.BackgroundType.Star;
                    break;
                case "Candy":
                    bt = BackgroundData.BackgroundType.Candy;
                    break;
                case "Winter":
                    bt = BackgroundData.BackgroundType.Winter;
                    break;
                case "Alien":
                    bt = BackgroundData.BackgroundType.Alien;
                    break;
                case "Desert":
                    bt = BackgroundData.BackgroundType.Desert;
                    break;

                default:
                    bt = BackgroundData.BackgroundType.Forest;
                    break;
            }

            MainCanvas.Background = BackgroundData.GetBackground(bt);
            TileDB.hasMainBackground = true;
            TileDB.MainBackground = bt;

        }
 /// <summary>
 /// Creates a new world.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void NewWorld_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Are you sure to create a new world? You may lose all your unsaved progress!", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
     {
         MainCanvas.Children.Clear();
         TileDB = new TileData(80, 60);
         DrawGrid(TileDB.Height, TileDB.Width);
         DrawBedrock();
         MainCanvas.Background = BackgroundData.GetBackground(TileDB.MainBackground);
         defaultMatrix = MainCanvas.LayoutTransform.Value;
         _selectedTile.Type = TileType.Background;
         ComboTypes.SelectedIndex = 0;
         firstPlaced = false;
         SaveButton.IsEnabled = false;
         SavedPath = String.Empty;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Creates a new world.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void NewWorld_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Are you sure to create a new world? You may lose all your unsaved progress!", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
     {
         MainCanvas.Children.Clear();
         DB = new PlannerSettings(80, 60);
         DrawGrid(DB.WorldWidth, DB.WorldHeight);
         DrawBedrock();
         MainCanvas.Background = BackgroundData.GetBackground(DB.MainBackground);
         defaultMatrix         = MainCanvas.LayoutTransform.Value;
         //_selectedTile.TileName
         ComboTypes.SelectedIndex = 1;
         firstPlaced          = false;
         FirstSelected        = false;
         SaveButton.IsEnabled = false;
         PreviousTiles.Items.Clear();
         PreviousTiles.SelectedItem = null;
         SavedPath = String.Empty;
         _selectedTile.Reset();
     }
 }
        public MainWindow()
        {

            InitializeComponent();
            //Draw Grid by default.
            DrawGrid(TileDB.Height, TileDB.Width);

            //Set Background to forest.
            MainCanvas.Background = BackgroundData.GetBackground(BackgroundData.BackgroundType.Forest);
            TileDB.MainBackground = BackgroundData.BackgroundType.Forest;
            TileDB.hasMainBackground = true;

            defaultMatrix = MainCanvas.LayoutTransform.Value;
            _selectedTile.Type = TileType.Background;

            //Load Images, searching and tile selection box.
            GenerateSelector();

            //Draw Bedrock by default.
            DrawBedrock();
            ComboTypes.SelectedIndex = 0;

            this.Title = $"{this.Title} ({UpdateChecker.current})";
        }
Beispiel #5
0
        //World Load
        private void LoadWorld_Click(object sender, RoutedEventArgs e)
        {
            if (firstPlaced && MessageBox.Show("Are you sure to load a new world? You may lose all your unsaved progress!", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
            {
                return;
            }

            isLoading = true;

            OpenFileDialog dialog = new OpenFileDialog()
            {
                Filter           = "Pixel Worlds World (*.pww)|*.pww",
                DefaultExt       = "pww",
                RestoreDirectory = true
            };
            Nullable <bool> Selected = dialog.ShowDialog();
            string          path     = dialog.FileName;

            if (Selected == true)
            {
                PlannerSettings        newWorldDB;
                DataHandler.LoadStatus status = DataHandler.TryLoadWorld(path, out newWorldDB);

                if (status == DataHandler.LoadStatus.VersionMismatch)
                {
                    MessageBox.Show("This world is not compatible with this planner version.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else if (status == DataHandler.LoadStatus.InvalidMagic)
                {
                    MessageBox.Show("This is not a world file.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else //Load-able
                {
                    MainCanvas.Children.Clear();
                    DB = new PlannerSettings(newWorldDB);
                    DrawGrid(DB.WorldWidth, DB.WorldHeight);

                    if (status == DataHandler.LoadStatus.TileNotFound)
                    {
                        if (newWorldDB.InvalidTiles.Count > 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine($"Could not load {newWorldDB.InvalidTiles.Count} tiles (Using an older version?)");
                            foreach (KeyValuePair <string, int> entry in newWorldDB.InvalidTiles)
                            {
                                sb.AppendLine($"-{entry.Key} [x{entry.Value}]");
                            }
                            MessageBox.Show(sb.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }

                    for (int y = 0; y < DB.WorldHeight; y++)
                    {
                        for (int x = 0; x < DB.WorldWidth; x++)
                        {
                            if (!AnyTileAt(newWorldDB, x, y))
                            {
                                continue;
                            }

                            foreach (Tile t in newWorldDB.TileMap[x, y].Tiles.ToList())
                            {
                                Image image = new Image()
                                {
                                    Source = t.Image.Source
                                };
                                Canvas.SetTop(image, y * 32);
                                Canvas.SetLeft(image, x * 32);
                                image.SetValue(Canvas.ZIndexProperty, t.ZIndex);
                                MainCanvas.Children.Add(image);
                                if (DB.TileMap[x, y] == null)
                                {
                                    DB.TileMap[x, y] = new TileData();
                                }


                                if (t is Foreground)
                                {
                                    DB.TileMap[x, y].Tiles.Add(new Foreground(image)
                                    {
                                        TileName = t.TileName
                                    });
                                }
                                else if (t is Background)
                                {
                                    DB.TileMap[x, y].Tiles.Add(new Background(image)
                                    {
                                        TileName = t.TileName
                                    });
                                }
                                else
                                {
                                    DB.TileMap[x, y].Tiles.Add(new Special(image)
                                    {
                                        TileName = t.TileName
                                    });
                                }
                            }
                        }
                    }

                    if (!DB.hasMainBackground)
                    {
                        MainCanvas.Background = new SolidColorBrush(Utils.IntToARGBColor(DB.ARGBBackgroundColor));
                    }
                    else
                    {
                        MainCanvas.Background = BackgroundData.GetBackground(DB.MainBackground);
                    }

                    ColorSelector.SelectedColor = Utils.IntToARGBColor(DB.ARGBBackgroundColor);
                    firstPlaced          = false;
                    FirstSelected        = false;
                    SaveButton.IsEnabled = false;
                    SavedPath            = String.Empty;
                    PreviousTiles.Items.Clear();
                    PreviousTiles.SelectedItem = null;
                    _selectedTile.Reset();
                }
            }
            isLoading = false;
        }
Beispiel #6
0
        //World Load
        private void LoadWorld_Click(object sender, RoutedEventArgs e)
        {
            if (firstPlaced && MessageBox.Show("Are you sure to load a new world? You may lose all your unsaved progress!", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
            {
                return;
            }

            isLoading = true;

            OpenFileDialog dialog = new OpenFileDialog()
            {
                Filter           = "Pixel Worlds World (*.pww)|*.pww",
                DefaultExt       = "pww",
                RestoreDirectory = true
            };
            Nullable <bool> Selected = dialog.ShowDialog();
            string          path     = dialog.FileName;

            if (Selected == true)
            {
                MainCanvas.Children.Clear();
                TileDB = (TileData)DataHandler.LoadWorld(path);
                DrawGrid(TileDB.Height, TileDB.Width);

                if (!TileDB.hasMainBackground)
                {
                    MainCanvas.Background = new SolidColorBrush(Utils.IntToARGBColor(TileDB.ARGBBackgroundColor));
                }
                else
                {
                    MainCanvas.Background = BackgroundData.GetBackground(TileDB.MainBackground);
                }

                SortedList <string, int> invalids = new SortedList <string, int>();
                for (int i = 0; i < TileDB.Tiles.GetLength(0); i++)
                {
                    for (int j = 0; j < TileDB.Tiles.GetLength(1); j++)
                    {
                        if (TileDB.Tiles[i, j] != null)
                        {
                            if (TileDB.Tiles[i, j].Type == TileType.Background || TileDB.Tiles[i, j].Type == TileType.Both)
                            {
                                Image image = new Image()
                                {
                                    Height = 32,
                                    Width  = 32
                                };
                                string         dataName = TileDB.Tiles[i, j].bgName;
                                BackgroundName name     = SelectableTile.GetBackgroundNameByString(TileDB.Tiles[i, j].bgName);

                                //If the sprite does not exist.
                                bool exists = backgroundMap.TryGetValue(name, out BitmapImage src);
                                if (!exists && dataName != null)
                                {
                                    if (invalids.ContainsKey(dataName))
                                    {
                                        invalids[dataName]++;
                                    }
                                    else
                                    {
                                        invalids.Add(dataName, 0);
                                    }
                                    TileDB.Tiles[i, j] = null;
                                }
                                else
                                {
                                    image.Source = src;

                                    Canvas.SetTop(image, TileDB.Tiles[i, j].Positions.BackgroundY.Value * 32);
                                    Canvas.SetLeft(image, TileDB.Tiles[i, j].Positions.BackgroundX.Value * 32);
                                    image.SetValue(Canvas.ZIndexProperty, 10);
                                    MainCanvas.Children.Add(image);
                                    TileDB.Tiles[i, j].Background = image;
                                }
                            }

                            if (TileDB.Tiles[i, j].Type == TileType.Foreground || TileDB.Tiles[i, j].Type == TileType.Both)
                            {
                                Image image = new Image()
                                {
                                    Height = 32,
                                    Width  = 32
                                };
                                string    dataName = TileDB.Tiles[i, j].blName;
                                BlockName name     = SelectableTile.GetBlockNameByString(TileDB.Tiles[i, j].blName);

                                bool exists = blockMap.TryGetValue(name, out BitmapImage src);
                                if (!exists && dataName != null)
                                {
                                    if (invalids.ContainsKey(dataName))
                                    {
                                        invalids[dataName]++;
                                    }
                                    else
                                    {
                                        invalids.Add(dataName, 0);
                                    }
                                    TileDB.Tiles[i, j] = null;
                                }
                                else
                                {
                                    image.Source = src;

                                    Canvas.SetTop(image, TileDB.Tiles[i, j].Positions.ForegroundY.Value * 32);
                                    Canvas.SetLeft(image, TileDB.Tiles[i, j].Positions.ForegroundX.Value * 32);
                                    image.SetValue(Canvas.ZIndexProperty, 20);
                                    MainCanvas.Children.Add(image);
                                    TileDB.Tiles[i, j].Foreground = image;
                                }
                            }
                        }
                    }
                    ColorSelector.SelectedColor = Utils.IntToARGBColor(TileDB.ARGBBackgroundColor);
                    firstPlaced          = false;
                    SaveButton.IsEnabled = false;
                    SavedPath            = String.Empty;
                }
                if (invalids.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine($"Could not load {invalids.Count} tiles (Using an older version?)");
                    foreach (KeyValuePair <string, int> entry in invalids)
                    {
                        sb.AppendLine($"-{entry.Key} [x{entry.Value}]");
                    }
                    MessageBox.Show(sb.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            isLoading = false;
        }