コード例 #1
0
ファイル: Portal.cs プロジェクト: fcraft-based/GemsCraft
        public void Remove(Player requester)
        {
            NormalBrush   brush           = new NormalBrush(Block.Air, Block.Air);
            DrawOperation removeOperation = new CuboidDrawOperation(requester);

            removeOperation.AnnounceCompletion = false;
            removeOperation.Brush   = brush;
            removeOperation.Context = BlockChangeContext.Portal;

            if (this.AffectedBlocks == null)
            {
                this.AffectedBlocks    = new Vector3I[2];
                this.AffectedBlocks[0] = new Vector3I(Range.Xmin, Range.Ymin, Range.Zmin);
                this.AffectedBlocks[1] = new Vector3I(Range.Xmax, Range.Ymax, Range.Zmax);
            }

            if (!removeOperation.Prepare(this.AffectedBlocks))
            {
                throw new PortalException("Unable to remove portal.");
            }

            removeOperation.Begin();

            lock (requester.World.Portals.SyncRoot)
            {
                requester.World.Portals.Remove(this);
            }

            PortalDB.Save();
        }
コード例 #2
0
ファイル: FeedData.cs プロジェクト: enpici/800craft
        public FeedData(Block _textType, Vector3I _pos, Bitmap Image, World world, Direction direction_, Player player_)
        {
            direction = direction_;
            Blocks    = new ConcurrentDictionary <string, Vector3I>();
            Init(Image, world);
            Pos      = _pos;
            textType = ( byte )_textType;
            bgType   = ( byte )Block.Air;
            FeedData.AddMessages();
            MessageCount = 0;
            Sentence     = FeedData.Messages[MessageCount];
            Id           = System.Threading.Interlocked.Increment(ref feedCounter);
            player       = player_;
            NormalBrush   brush     = new NormalBrush(Block.Wood);
            DrawOperation Operation = new CuboidWireframeDrawOperation(player);

            Operation.AnnounceCompletion = false;
            Operation.Brush   = brush;
            Operation.Context = BlockChangeContext.Drawn;

            if (!Operation.Prepare(new[] { StartPos, FinishPos }))
            {
                throw new Exception("Unable to cubw frame.");
            }

            Operation.Begin();
            AddFeedToList(this, world);

            Start();
        }
コード例 #3
0
ファイル: ButtonStyle.cs プロジェクト: huangdonghai/titan3d
        public override async Task Initialize(CRenderContext rc, UIElement hostElement)
        {
            await NormalBrush.Initialize(rc, hostElement);

            await HoveredBrush.Initialize(rc, hostElement);

            await PressedBrush.Initialize(rc, hostElement);

            await DisabledBrush.Initialize(rc, hostElement);
        }
コード例 #4
0
    public void FillTiles(Point startPoint, NormalBrush brush)
    {
        var applyList = new HashSet <Texture2D>();

        var queue = new Queue <Point>();

        queue.Enqueue(startPoint);

        var targetTile = _tilerMap.GetTileFromWorldTile(startPoint, true);//.Properties.ID;

        if (targetTile == null)
        {
            return;
        }

        var targetProperty = targetTile.Properties;
        var replacementID  = brush.GetBrush(startPoint.X, startPoint.Y);

        // Already match, just return
        if (replacementID.Properties.Equals(targetProperty))
        {
            return;
        }

        while (queue.Count > 0)
        {
            var p    = queue.Dequeue();
            var tile = _tilerMap.GetTileFromWorldTile(p);

            if (tile != null && tile.Properties.Equals(targetProperty))
            {
                var changedTexture = ChangeTile(p, replacementID);
                applyList.Add(changedTexture);

                var left = new Point(p.X - 1, p.Y);
                queue.Enqueue(left);

                var right = new Point(p.X + 1, p.Y);
                queue.Enqueue(right);

                var bottom = new Point(p.X, p.Y - 1);
                queue.Enqueue(bottom);

                var top = new Point(p.X, p.Y + 1);
                queue.Enqueue(top);
            }
        }

        // Apply any changes
        foreach (var t in applyList)
        {
            t.Apply();
        }
    }
コード例 #5
0
        public FillTool(DrawWindow parent, NormalBrush brush)
        {
            _parent = parent;

            var map = _parent.TilerMap;
            _brush = brush;

            if (_brush == null)
                _brush = new NormalBrush(map != null ? map.TileResolution : 1, TileTexture.None);

            _brush.BrushSize = new Point(1, 1);
        }
コード例 #6
0
        public void SetBrush(IBrush brush)
        {
            // Only allow normal brushes
            var b = brush as NormalBrush;
            if (b == null)
            {
                var map = _parent.TilerMap;
                b = new NormalBrush(map != null ? map.TileResolution : 1, TileTexture.None);
            }

            _brush = b;
        }
コード例 #7
0
        public void SetBrush(IBrush brush)
        {
            // Only allow normal brushes
            var b = brush as NormalBrush;

            if (b == null)
            {
                var map = _parent.TilerMap;
                b = new NormalBrush(map != null ? map.TileResolution : 1, TileTexture.None);
            }

            _brush = b;
        }
コード例 #8
0
    private NormalBrush GetBrush(IEnumerable <Tileset> tilesets, Tile tile, int textureSize)
    {
        var c         = tile.Collision;
        var collision = new bool[c.Length];

        Array.Copy(c, collision, c.Length);

        var id    = tile.Properties.ID;
        var setID = (int)(id >> 32);

        Tileset ts = null;

        // Find matching tileset
// ReSharper disable LoopCanBeConvertedToQuery
        foreach (var t in tilesets)
// ReSharper restore LoopCanBeConvertedToQuery
        {
            if (t.TilesetID == setID)
            {
                ts = t;
                break;
            }
        }

        TileTexture tt = null;

        if (ts)
        {
            // Find matching tile
            tt = ts.Assets.Find(a => a.ID == id);
        }

        if (tt == null)
        {
            tt = TileTexture.None;
        }

        var brush = new NormalBrush(textureSize, tt);

        for (var i = 0; i < 4; i++)
        {
            if (brush.GetBrush().Properties.Rot == tile.Properties.Rot)
            {
                break;
            }

            brush.Rotate();
        }

        return(brush);
    }
コード例 #9
0
        public FillTool(DrawWindow parent, NormalBrush brush)
        {
            _parent = parent;

            var map = _parent.TilerMap;

            _brush = brush;

            if (_brush == null)
            {
                _brush = new NormalBrush(map != null ? map.TileResolution : 1, TileTexture.None);
            }

            _brush.BrushSize = new Point(1, 1);
        }
コード例 #10
0
    public void ReplaceTiles(Point startPoint, NormalBrush brush)
    {
        var applyList = new HashSet <Texture2D>();

        var targetTile = _tilerMap.GetTileFromWorldTile(startPoint, true);//.Properties.ID;

        if (targetTile == null)
        {
            return;
        }

        var targetProperty = targetTile.Properties;
        var replacementID  = brush.GetBrush(startPoint.X, startPoint.Y);

        // Already match, just return
        if (replacementID.Properties.Equals(targetProperty))
        {
            return;
        }

        foreach (var cell in _tilerMap.Cells)
        {
            for (int index = 0; index < cell.Tiles.Length; index++)
            {
                var tile = cell.Tiles[index];

                if (tile.Properties.Equals(targetProperty))
                {
                    var p = new Point
                    {
                        X = index % _tilerMap.TilesPerCell,
                        Y = index / _tilerMap.TilesPerCell
                    };

                    var changedTexture = ChangeTile(cell, p, replacementID);
                    applyList.Add(changedTexture);
                }
            }
        }

        // Apply any changes
        foreach (var t in applyList)
        {
            t.Apply();
        }
    }
コード例 #11
0
    private void Rebuild()
    {
        var tpc = _map.TilesPerCell;

        var tilesets = LoadAllTilesets();

        foreach (Cell cell in _map.Cells)
        {
            var texture = cell.GetTexture();
            if (!texture)
            {
                continue;
            }

            for (var j = 0; j < tpc; j++)
            {
                for (var i = 0; i < tpc; i++)
                {
                    var index = j * tpc + i;
                    var tile  = cell.Tiles[index];

                    NormalBrush brush = GetBrush(tilesets, tile, _map.TileResolution);

                    if (brush != null)
                    {
                        var data = brush.GetBrush();

                        texture.SetPixels(i * _map.TileResolution, j * _map.TileResolution, _map.TileResolution,
                                          _map.TileResolution, data.Colors);

                        var c         = data.Collision;
                        var collision = new bool[c.Length];
                        Array.Copy(c, collision, c.Length);

                        tile.Collision = collision;
                    }
                }
            }
            texture.Apply();
        }
    }