Beispiel #1
0
        //---------------------------------------------------------------------------

        public void EraseTile(ELayerMode mode, int sourceX, int sourceY)
        {
            if (m_Layers.ContainsKey(mode))
            {
                m_Layers[mode].EraseTile(sourceX, sourceY);
            }
        }
Beispiel #2
0
        //---------------------------------------------------------------------------

        public void FillTile(ELayerMode mode, int sourceX, int sourceY, int targetX, int targetY)
        {
            if (m_Map != null)
            {
                FloodFill(mode, new SelectionPoint(sourceX, sourceY), new SelectionPoint(targetX, targetY));
            }
        }
Beispiel #3
0
        //---------------------------------------------------------------------------

        public void SetTile(ELayerMode mode, int sourceX, int sourceY, int targetX, int targetY)
        {
            if (m_Layers.ContainsKey(mode))
            {
                m_Layers[mode].SetTile(sourceX, sourceY, targetX, targetY);
            }
        }
Beispiel #4
0
        //---------------------------------------------------------------------------

        private void FloodFill(ELayerMode mode, SelectionPoint center, SelectionPoint fill)
        {
            if (IsMatch(mode, center.X, center.Y, fill.X, fill.Y))
            {
                return;
            }

            Layer layer = m_Map[mode, center.X, center.Y];

            if (layer != null)
            {
                SelectionPoint         expected = new SelectionPoint(layer.TargetX, layer.TargetY);
                Queue <SelectionPoint> q        = new Queue <SelectionPoint>();
                q.Enqueue(center);
                while (q.Count > 0)
                {
                    SelectionPoint n = q.Dequeue();
                    if (!IsMatch(mode, n.X, n.Y, expected.X, expected.Y))
                    {
                        continue;
                    }
                    SelectionPoint w = n, e = new SelectionPoint(n.X + 1, n.Y);
                    while ((w.X >= 0) && IsMatch(mode, w.X, w.Y, expected.X, expected.Y))
                    {
                        if (m_Map.SetTile(mode, w.X, w.Y, fill.X, fill.Y))
                        {
                            ContainsChanges = true;
                            m_Control?.SetTile(mode, w.X, w.Y, fill.X, fill.Y);
                        }
                        if ((w.Y > 0) && IsMatch(mode, w.X, w.Y - 1, expected.X, expected.Y))
                        {
                            q.Enqueue(new SelectionPoint(w.X, w.Y - 1));
                        }
                        if ((w.Y < m_Map.Height - 1) && IsMatch(mode, w.X, w.Y + 1, expected.X, expected.Y))
                        {
                            q.Enqueue(new SelectionPoint(w.X, w.Y + 1));
                        }
                        w.X--;
                    }
                    while ((e.X <= m_Map.Width - 1) && IsMatch(mode, e.X, e.Y, expected.X, expected.Y))
                    {
                        if (m_Map.SetTile(mode, e.X, e.Y, fill.X, fill.Y))
                        {
                            ContainsChanges = true;
                            m_Control?.SetTile(mode, e.X, e.Y, fill.X, fill.Y);
                        }
                        if ((e.Y > 0) && IsMatch(mode, e.X, e.Y - 1, expected.X, expected.Y))
                        {
                            q.Enqueue(new SelectionPoint(e.X, e.Y - 1));
                        }
                        if ((e.Y < m_Map.Height - 1) && IsMatch(mode, e.X, e.Y + 1, expected.X, expected.Y))
                        {
                            q.Enqueue(new SelectionPoint(e.X, e.Y + 1));
                        }
                        e.X++;
                    }
                }
            }
        }
Beispiel #5
0
        //---------------------------------------------------------------------------

        public Layer this[ELayerMode mode, int x, int y]
        {
            get
            {
                Cell cell = this[x, y];
                return(cell != null ? cell[mode] : null);
            }
        }
Beispiel #6
0
        //---------------------------------------------------------------------------

        public void SetTextureBounds(int x, int y, ELayerMode layer, Rectangle bounds)
        {
            if (x < Left || x >= Right || y < Top || y >= Bottom)
            {
                return;
            }
            m_Chunks[x / Chunk.Width, y / Chunk.Height].SetTextureBounds(x, y, layer, bounds);
        }
Beispiel #7
0
        //---------------------------------------------------------------------------

        public Rectangle GetTextureBounds(int x, int y, ELayerMode layer)
        {
            if (x < Left || x >= Right || y < Top || y >= Bottom)
            {
                return(new Rectangle());
            }
            return(m_Chunks[x / Chunk.Width, y / Chunk.Height].GetTextureBounds(x, y, layer));
        }
Beispiel #8
0
        //---------------------------------------------------------------------------

        public void ClearTile(ELayerMode mode, int sourceX, int sourceY)
        {
            if (m_Map != null)
            {
                if (m_Map.SetTile(mode, sourceX, sourceY, -1, -1))
                {
                    ContainsChanges = true;
                    m_Control?.EraseTile(mode, sourceX, sourceY);
                }
            }
        }
Beispiel #9
0
        //---------------------------------------------------------------------------

        private bool IsMatch(ELayerMode mode, int x, int y, int expectedX, int expectedY)
        {
            if (m_Map != null)
            {
                Layer layer = m_Map[mode, x, y];
                if (layer != null)
                {
                    return(layer.TargetX == expectedX && layer.TargetY == expectedY);
                }
            }
            return(false);
        }
Beispiel #10
0
        //---------------------------------------------------------------------------

        public Rectangle GetTextureBounds(int x, int y, ELayerMode layer)
        {
            switch (layer)
            {
            case ELayerMode.First:
                return(m_Cells[x % Width, y % Height].Layer1);

            case ELayerMode.Second:
                return(m_Cells[x % Width, y % Height].Layer2);

            case ELayerMode.Third:
                return(m_Cells[x % Width, y % Height].Layer3);
            }
            return(new Rectangle());
        }
Beispiel #11
0
        //---------------------------------------------------------------------------

        public void SetTile(ELayerMode mode, int sourceX, int sourceY, int targetX, int targetY, int width, int height)
        {
            if (m_Map != null)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        if (m_Map.SetTile(mode, sourceX + x, sourceY + y, targetX + x, targetY + y))
                        {
                            ContainsChanges = true;
                            m_Control?.SetTile(mode, sourceX + x, sourceY + y, targetX + x, targetY + y);
                        }
                    }
                }
            }
        }
Beispiel #12
0
        //---------------------------------------------------------------------------

        public void SetTextureBounds(int x, int y, ELayerMode layer, Rectangle bounds)
        {
            switch (layer)
            {
            case ELayerMode.First:
                m_Cells[x % Width, y % Height].Layer1 = bounds;
                break;

            case ELayerMode.Second:
                m_Cells[x % Width, y % Height].Layer2 = bounds;
                break;

            case ELayerMode.Third:
                m_Cells[x % Width, y % Height].Layer3 = bounds;
                break;
            }
        }
Beispiel #13
0
        //---------------------------------------------------------------------------

        public bool SetTile(ELayerMode mode, int sourceX, int sourceY, int targetX, int targetY)
        {
            if (sourceX < 0 || sourceX >= Width || sourceY < 0 || sourceY >= Height)
            {
                return(false);
            }
            Layer layer = Cells[sourceX, sourceY][mode];

            if (layer != null)
            {
                if (layer.TargetX != targetX || layer.TargetY != targetY)
                {
                    layer.TargetX = targetX;
                    layer.TargetY = targetY;
                    return(true);
                }
            }
            return(false);
        }
Beispiel #14
0
        //---------------------------------------------------------------------------

        private void OnModeChanged(ELayerMode mode)
        {
            if (mode < m_Mode)
            {
                ImageOpacity = 0.3f;
                TintOpacity  = 0.0f;
            }
            else if (mode > m_Mode)
            {
                ImageOpacity = 1.0f;
                TintOpacity  = 0.5f;
            }
            else
            {
                ImageOpacity = 1.0f;
                TintOpacity  = 0.0f;
            }
            OnPropertyChanged("ImageOpacity");
            OnPropertyChanged("TintOpacity");
        }
Beispiel #15
0
        //---------------------------------------------------------------------------

        public void Init(ELayerMode mode, int width, int height)
        {
            m_Mode = mode;
            Reset(width, height);
            OnModeChanged(mode);
        }
Beispiel #16
0
        //---------------------------------------------------------------------------

        public Layer this[ELayerMode mode]
        {
            get { return(Layers.ContainsKey(mode) ? Layers[mode] : null); }
        }
Beispiel #17
0
        //---------------------------------------------------------------------------

        public UndoAction(ELayerMode layer)
        {
            Layer  = layer;
            Before = new List <UndoState>();
            After  = new List <UndoState>();
        }
Beispiel #18
0
        //---------------------------------------------------------------------------

        public void SetTile(ELayerMode mode, int sourceX, int sourceY, int destinationX, int destinationY, bool isBlocked)
        {
            //m_Canvas?.SetTile(mode, sourceX, sourceY, destinationX, destinationY, isBlocked);
        }
Beispiel #19
0
        //---------------------------------------------------------------------------

        public void StartUndo(ELayerMode mode)
        {
            m_CurrentUndo = new UndoAction(mode);
        }