public override void AddingAtPosition(int x, int y, TileMaskCollection selection)
        {
            if (selection == null)
            {
                return;
            }

            selection.MoveTo(x, y);

            int drx = selection.Left;
            int dry = selection.Top;
            int drr = drx + selection.Width;
            int drb = dry + selection.Height;
            int cz  = CellSize;

            drx /= cz;
            drx *= cz;
            dry /= cz;
            dry *= cz;
            drr += (drr % cz);
            drb += (drb % cz);
            int w = drr - drx;
            int h = drb - dry;

            layer1.DrawRectangle(drx, dry, w, h, BackgroundColor);
            layers[SelectedLayer].AddTiles(selection);

            ITileCollection col = layers[SelectedLayer].TilesOnArea(drx, dry, w, h);

            drawTileMaskCollection(col);
            UpdateLayer2();
            updateOffsetAndCopyLenght(drx, dry, drr, drb);
        }
Beispiel #2
0
        /// <summary>
        /// Adds the tiles.
        /// </summary>
        /// <param name="tls">The tls.</param>
        public void AddTiles(ITileCollection tls)
        {
            if (tls == null)
            {
                throw new ArgumentNullException(nameof(tls));
            }
            List <TileMask> ts = (List <TileMask>)tls.GetEnumerable();
            int             px;
            int             py;
            PositionKey     pk;

            foreach (TileMask t in ts)
            {
                px = t.X / CellSize;
                py = t.Y / CellSize;
                if (px >= 0 && py >= 0 && px < Width && py < Height)
                {
                    pk = new PositionKey((uint)px, (uint)py);
                    if (!tiles.ContainsKey(pk))
                    {
                        tiles.Add(pk, new List <TileMask>());
                    }
                    tiles[pk].Add(t);
                }
            }
        }
Beispiel #3
0
        public static ITileCollection Create()
        {
            //Fire the hook to allow a consumer to specify a custom implementation
            ITileCollection collection = Hooks.Tile.CreateCollection?.Invoke();

            //Either return the custom provider, or use the default one.
            return(collection ?? new DefaultTileCollection());
        }
Beispiel #4
0
        public bool SetProvider(ITileCollection provider)
        {
            //if (!AcceptedWarning)
            //{
            //	Console.Write("This is an experimental command and is only intended for evaluation. Proceed? [Y/n]: ");

            //	var accepted = Console.ReadKey().Key == ConsoleKey.Y;
            //	if (accepted)
            //	{

            //	}

            //	return false;
            //}

            ////todo transfer + unload if during game
            //if (Netplay.IsListening)
            //{
            //    if (Terraria.Main.tile != null)
            //    {
            //        int x = 0;
            //        int y = 0;
            //        try
            //        {
            //            // trigger our internals to generate the data store
            //            provider[0, 0]?.ClearTile();

            //            x = 0;
            //            for (x = 0; x < Terraria.Main.maxTilesX; x++)
            //            {
            //                y = 0;
            //                for (y = 0; y < Terraria.Main.maxTilesY; y++)
            //                {
            //                    provider[x, y] = Terraria.Main.tile[x, y];
            //                }
            //            }
            //        }
            //        catch (Exception ex)
            //        {
            //            Console.WriteLine($"Error @{x}x{y}\n{ex}");
            //            return false;
            //        }
            //    }
            //}

            var previous = Terraria.Main.tile as IDisposable;

            Terraria.Main.tile = provider;
            if (previous != null)
            {
                previous.Dispose();
            }

            GC.Collect();

            return(true);
        }
Beispiel #5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="World" /> class wrapping the specified Terraria tiles, chests, and
        ///     signs.
        /// </summary>
        /// <param name="tiles">The tiles, which must not be <c>null</c>.</param>
        /// <param name="chests">The chests, which must not be <c>null</c>.</param>
        /// <param name="signs">The signs, which must not be <c>null</c>.</param>
        /// <exception cref="ArgumentNullException">
        ///     Either <paramref name="tiles" />, <paramref name="chests" />, or <paramref name="signs" /> is <c>null</c>.
        /// </exception>
        public OTAPIWorld([NotNull] ITileCollection tiles, [NotNull] TerrariaChest[] chests,
                          [NotNull] TerrariaSign[] signs)
        {
            _terrariaTiles  = tiles ?? throw new ArgumentNullException(nameof(tiles));
            _terrariaChests = chests ?? throw new ArgumentNullException(nameof(chests));
            _terrariaSigns  = signs ?? throw new ArgumentNullException(nameof(signs));

            _sectionTimer.Elapsed += NotifySections;
            _sectionTimer.Start();
        }
Beispiel #6
0
        public static ITileCollection Create(int maxX, int maxY)
        {
            global::Terraria.Main.maxTilesX = maxX;
            global::Terraria.Main.maxTilesY = maxY;

            //Fire the hook to allow a consumer to specify a custom implementation
            ITileCollection collection = Hooks.Tile.CreateCollection?.Invoke();

            //Either return the custom provider, or use the default one.
            return(collection ?? new DefaultTileCollection());
        }
Beispiel #7
0
            public T(GraphicsDevice d, ContentManager c)
            {
                c.RootDirectory  = "./Content";
                this.Background  = c.Load <Texture2D>("Background.png");
                this.Overlay     = c.Load <Texture2D>("Overlay.png");
                this.tileTexture = c.Load <Texture2D>("Resources.png");
                this.Red         = Texture2dHelper.CreateTexture(d, 10, 10, (_) => Color.Red);
                this.White       = Texture2dHelper.CreateTexture(d, 10, 10, (_) => Color.White);

                this.Tiles = new TileCollection();
                this.Tiles.Load(texture: this.tileTexture, tileSize: 16);
            }
 public FakeTileRectangle Add(object Key, int X, int Y,
                              int Width, int Height, ITileCollection CopyFrom = null)
 {
     lock (Locker)
     {
         if (Data.ContainsKey(Key))
         {
             throw new ArgumentException($"Key '{Key}' is already in use.");
         }
         FakeTileRectangle fake = new FakeTileRectangle(this, Key, X, Y, Width, Height, CopyFrom);
         Data.Add(Key, fake);
         Order.Add(Key);
         return(fake);
     }
 }
        protected override void OnMinesweeperChanged()
        {
            this.targetSpaceCount = (this.Minesweeper.Tiles.Width * this.Minesweeper.Tiles.Height) -
                                    this.Minesweeper.MineCount;
            this.boardTiles            = this.Minesweeper.Tiles;
            this.boardInitialized      = false;
            this.revealedSpaces        = 0;
            this.leftAndRightMouseDown = false;

            this.SetRevealTileMethod();
            this.IsGameOver     = false;
            this.IsVictory      = false;
            this.SelectionBrush = TileBoardViewModelBase.DefaultSelectionBrush;
            this.HoverBrush     = TileBoardViewModelBase.DefaultHoverBrush;
            this.IsTilePressed  = false;
        }
        protected override void OnMinesweeperChanged()
        {
            this.targetSpaceCount = (this.Minesweeper.Tiles.Width * this.Minesweeper.Tiles.Height) -
                                    this.Minesweeper.MineCount;
            this.boardTiles = this.Minesweeper.Tiles;
            this.boardInitialized = false;
            this.revealedSpaces = 0;
            this.leftAndRightMouseDown = false;

            this.SetRevealTileMethod();
            this.IsGameOver = false;
            this.IsVictory = false;
            this.SelectionBrush = TileBoardViewModelBase.DefaultSelectionBrush;
            this.HoverBrush = TileBoardViewModelBase.DefaultHoverBrush;
            this.IsTilePressed = false;
        }
        private void InitBoard()
        {
            var minesweeper = this.Minesweeper;

            if (minesweeper == null)
            {
                return;
            }

            double time1 = 0, time2 = 0;
            var    sw = Stopwatch.StartNew();

            this.boardTiles = minesweeper.Tiles;
            double newWidth  = this.boardTiles.Width * this.TileSize.Width;
            double newHeight = this.boardTiles.Height * this.TileSize.Height;

            bool resizeControl = this.Width != newWidth || this.Height != newHeight;

            if (resizeControl)
            {
                this.Width  = this.boardTiles.Width * this.TileSize.Width;
                this.Height = this.boardTiles.Height * this.TileSize.Height;
            }

            if (this.boardBitmap == null || resizeControl)
            {
                this.boardBitmap = new WriteableBitmap((int)this.Width, (int)this.Height, 96d, 96d, PixelFormats.Bgra32, null);
                this.proxy       = new WriteableBitmapProxy(this.boardBitmap);
            }

            this.Visuals.ForEach(this.RemoveVisualChild);
            this.Visuals.Clear();

            time1 = sw.Elapsed.TotalMilliseconds;
            this.DrawBoard();

            time2 = sw.Elapsed.TotalMilliseconds;
            this.AddVisuals();

            sw.Stop();

            Console.WriteLine("1) Resizing/Clearing Visuals: " + time1.ToString("0.0000"));
            Console.WriteLine("2) Drawing Board: " + (time2 - time1).ToString("0.0000"));
            Console.WriteLine("3) Adding Visuals: " + (sw.Elapsed.TotalMilliseconds - time2).ToString("0.0000"));
        }
 public FakeTileRectangle(FakeCollection Collection, object Key,
                          int X, int Y, int Width, int Height, ITileCollection CopyFrom)
     : this(Collection, Key, X, Y, Width, Height)
 {
     if (CopyFrom != null)
     {
         for (int i = X; i < X + Width; i++)
         {
             for (int j = Y; j < Y + Height; j++)
             {
                 ITile t = CopyFrom[i, j];
                 if (t != null)
                 {
                     this.Tile[i - X, j - Y].CopyFrom(t);
                 }
             }
         }
     }
 }
Beispiel #13
0
        internal void Initialize(string Name, int X, int Y, int Width, int Height, ITileCollection CopyFrom, int Layer = 0)
        {
            this.Name   = Name;
            this.Data   = new StructTile[Width, Height];
            this.X      = X;
            this.Y      = Y;
            this.Width  = Width;
            this.Height = Height;
            this.Layer  = Layer;

            for (int i = X; i < X + Width; i++)
            {
                for (int j = Y; j < Y + Height; j++)
                {
                    ITile t = CopyFrom[i, j];
                    if (t != null)
                    {
                        this[i, j].CopyFrom(t);
                    }
                }
            }
        }
 /// <summary>
 /// Adds the tiles.
 /// </summary>
 /// <param name="tiles">The tiles.</param>
 public void AddTiles(ITileCollection tiles)
 {
     AddCollection((TileMaskCollection)tiles);
 }
        private void InitBoard()
        {
            var minesweeper = this.Minesweeper;
            if (minesweeper == null)
            {
                return;
            }

            double time1 = 0, time2 = 0;
            var sw = Stopwatch.StartNew();

            this.boardTiles = minesweeper.Tiles;
            double newWidth = this.boardTiles.Width * this.TileSize.Width;
            double newHeight = this.boardTiles.Height * this.TileSize.Height;

            bool resizeControl = this.Width != newWidth || this.Height != newHeight;
            if (resizeControl)
            {
                this.Width = this.boardTiles.Width * this.TileSize.Width;
                this.Height = this.boardTiles.Height * this.TileSize.Height;
            }

            if (this.boardBitmap == null || resizeControl)
            {
                this.boardBitmap = new WriteableBitmap((int)this.Width, (int)this.Height, 96d, 96d, PixelFormats.Bgra32, null);
                this.proxy = new WriteableBitmapProxy(this.boardBitmap);
            }

            this.Visuals.ForEach(this.RemoveVisualChild);
            this.Visuals.Clear();

            time1 = sw.Elapsed.TotalMilliseconds;
            this.DrawBoard();

            time2 = sw.Elapsed.TotalMilliseconds;
            this.AddVisuals();

            sw.Stop();

            Console.WriteLine("1) Resizing/Clearing Visuals: " + time1.ToString("0.0000"));
            Console.WriteLine("2) Drawing Board: " + (time2 - time1).ToString("0.0000"));
            Console.WriteLine("3) Adding Visuals: " + (sw.Elapsed.TotalMilliseconds - time2).ToString("0.0000"));
        }
        public static INamedTileCollection CreateTileProvider(string Name, int X, int Y, int Width, int Height, ITileCollection CopyFrom, int Layer = 0)
        {
            Type newType                = Helper.CreateType();
            Type tileProviderType       = typeof(TileProvider <>).MakeGenericType(newType);
            INamedTileCollection result = (INamedTileCollection)Activator.CreateInstance(tileProviderType, true);

            ((dynamic)result).Initialize(Name, X, Y, Width, Height, CopyFrom, Layer);
            typeof(TileReference <>)
            .MakeGenericType(newType)
            .GetField("_Provider", BindingFlags.NonPublic | BindingFlags.Static)
            .SetValue(null, result);
            lock (FakeProviderPlugin.ProvidersToAdd)
            {
                if (FakeProviderPlugin.ProvidersLoaded)
                {
                    Tile.Add(result);
                }
                else
                {
                    FakeProviderPlugin.ProvidersToAdd.Add(result);
                }
            }
            return(result);
        }
Beispiel #17
0
 /// <summary>
 /// Adds the tiles.
 /// </summary>
 /// <param name="tiles">The tiles.</param>
 public void AddTiles(ITileCollection tiles)
 {
     GetCollection().AddCollection((TileMaskCollection)tiles);
     X = Section.Left;
     Y = Section.Top;
 }