示例#1
0
    // Update background in use and apply the changes to the play page.
    public void UpdateBackgroundInUse(BackgroundList.Background targetBackground)
    {
        backgroundInUseName = targetBackground.Name;

        foreach (Transform background in _backgroundImages.transform)
        {
            background.gameObject.GetComponent <SpriteRenderer>().sprite = targetBackground.ImageSprite;
        }
    }
示例#2
0
 public bool GetBackgroundAt(int X, int Y, out BackgroundName Background)
 {
     Background = BackgroundName.NONE;
     if (HasBackgroundAt(X, Y))
     {
         Background = SelectableTile.GetBackgroundNameByString(TileDB.Tiles[X, Y].bgName);
         return(true);
     }
     return(false);
 }
示例#3
0
        public void LoadBackground(BackgroundName imageName, float tint = 0.8f)
        {
            Color adjusted = new Color(tint, tint, tint, a: 1f);

            BackgroundImageComponent.color = adjusted;

            BackgroundImage image = new BackgroundImage(imageName); // TEMP // TODO move this to a list and draw from the list, updating when necessary.  Maybe scene manager does need to load backgrounds?

            BackgroundImageComponent.sprite = Resources.Load <Sprite>(image.FilePath);
        }
示例#4
0
        public BackgroundImage(BackgroundName imageName)
        {
            this.ImageName = imageName;
            this.FilePath  = ImagePathLookup[imageName];

            // Guard Clause: if image doesn't exist, load default instead.
            if (this.FilePath == "")
            {
                this.FilePath = ImagePathLookup[defaultBackground];
                Debug.Log("No background image file found. Reverted to default.");
            }
        }
示例#5
0
    public GameData()
    {
        coinsOwned          = InitialCoinAmount;
        carIndexToOwnership = new Ownership[TotalCarCount];
        foreach (var car in CarList.List)
        {
            carIndexToOwnership[(int)car.Name] = Ownership.NotOwned;
        }

        carIndexToOwnership[(int)CarList.CarSedan.Name] = Ownership.Owned;

        backgroundNameToOwnership = new Ownership[TotalBackgroundCount];
        foreach (var background in BackgroundList.List)
        {
            backgroundNameToOwnership[(int)background.Name] = Ownership.NotOwned;
        }

        backgroundNameToOwnership[(int)BackgroundList.BlueGrassBackground.Name] = Ownership.Owned;

        carInUseName        = CarName.Sedan;
        subscriptionType    = SubscriptionType.NoSubscription;
        backgroundInUseName = BackgroundName.BlueGrass;
    }
示例#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;
        }
 public static Background GetBackgroundByName(BackgroundName backgroundName)
 {
     return(List[(int)backgroundName]);
 }
 public Background(BackgroundName name)
 {
     Name = name;
 }
示例#9
0
 // Constructor for images e.g. backgournds
 public Command(CommandName name, BackgroundName imageName, List <string> args = null)
 {
     CommandName = name;
     ImageName   = imageName;
     Args        = args;
 }