private void Command_ChangeRows(object sliderValues)
        {
            Tuple <int, int> delta = (Tuple <int, int>)sliderValues;
            TileViewModel    newTile;

            // Adding new items
            if (delta.Item2 > delta.Item1)
            {
                for (int j = 0; j < (delta.Item2 - delta.Item1); j++)
                {
                    for (int i = 0; i < Columns; i++)
                    {
                        newTile = new TileViewModel(map.Atlas, new Tile(0, 0));
                        Tiles.Add(newTile);
                    }
                }
            }
            // Removing old items
            else if (delta.Item1 > delta.Item2)
            {
                for (int y = delta.Item1 - 1; y >= delta.Item2; y--)
                {
                    for (int x = Columns - 1; x >= 0; x--)
                    {
                        map.Atlas.UnRegisterTile(Tiles[Tiles.Count - 1]);
                        Tiles.RemoveAt(Tiles.Count - 1);
                    }
                }
            }
        }
        public MapSettingsViewModel(MapViewModel map)
        {
            this.map = map;

            MapName   = map.Name;
            MapWidth  = map.Width;
            MapHeight = map.Height;

            ApplyChanges    = new RelayCommand(Command_ApplyChanges);
            SelectAtlasFile = new ParameterCommand(Command_SelectAtlasFile);

            Atlas    = new AtlasViewModel(new Atlas(map.Atlas.TileSheet, map.Atlas.TileWidth, map.Atlas.TileHeight));
            FillTile = new TileViewModel(Atlas, new Tile(0, 0));
        }
        public BrushViewModel(MapViewModel parentMap)
        {
            // Fields
            map     = parentMap;
            Rows    = 1;
            Columns = 1;

            // Tile Maps
            Tiles = new ObservableCollection <TileViewModel>();
            // Map has one tile by default
            TileViewModel newTile = new TileViewModel(map.Atlas, new Tile(0, 0));

            Tiles.Add(newTile);
            newTile.IsSelected = true;

            // Commands
            ChangeRows    = new ParameterCommand(Command_ChangeRows);
            ChangeColumns = new ParameterCommand(Command_ChangeColumns);
            SelectTile    = new ParameterCommand(Command_SelectTile);
        }
Esempio n. 4
0
 private void TileViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName.Equals("TileID"))
     {
         if (sender.GetType() != typeof(TileViewModel))
         {
             throw new ArgumentException("Tile Type: " + sender.GetType() + " is not valid. Expected TileViewModel");
         }
         // Update the Tiles bitmap image.
         TileViewModel tile = sender as TileViewModel;
         if (tile.TileID >= Atlas.Tiles.Count)
         {
             // Set a null tile?
         }
         else
         {
             tile.TileImage = Atlas.Tiles[tile.TileID];
         }
     }
 }
        private void Command_ChangeColumns(object sliderValues)
        {
            Tuple <int, int> delta = (Tuple <int, int>)sliderValues;
            TileViewModel    newTile;

            // Adding new items
            if (delta.Item2 > delta.Item1)
            {
                for (int j = 0; j < (delta.Item2 - delta.Item1); j++)
                {
                    int col_offset = delta.Item1 + j; // column to add the tile in
                    for (int i = Rows - 1; i >= 0; i--)
                    {
                        int starting_row = i * (col_offset);
                        newTile = new TileViewModel(map.Atlas, new Tile(0, 0));
                        Tiles.Insert(starting_row + col_offset, newTile);
                    }
                }
            }
            // Removing old items
            else if (delta.Item1 > delta.Item2)
            {
                // Iterate over rows starting at bottom
                for (int y = Rows - 1; y >= 0; y--)
                {
                    // Iterate over columns starting at right
                    for (int x = delta.Item1 - 1; x >= 0; x--)
                    {
                        int index = y * delta.Item1 + x;

                        // If the current item is one of the last tiles in the row, then we remove it
                        if (x >= delta.Item2)
                        {
                            map.Atlas.UnRegisterTile(Tiles[index]);
                            Tiles.RemoveAt(index);
                        }
                    }
                }
            }
        }
 public TilePickerViewModel(AtlasViewModel atlas, TileViewModel tile)
 {
     Atlas = atlas;
     Tile  = tile;
 }
Esempio n. 7
0
 public void UnRegisterTile(TileViewModel tile)
 {
     registeredTiles.Remove(tile);
 }
Esempio n. 8
0
 public void RegisterTile(TileViewModel tile)
 {
     registeredTiles.Add(tile);
 }