//--------------------------------------------------------------------------- public void EraseTile(ELayerMode mode, int sourceX, int sourceY) { if (m_Layers.ContainsKey(mode)) { m_Layers[mode].EraseTile(sourceX, sourceY); } }
//--------------------------------------------------------------------------- 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)); } }
//--------------------------------------------------------------------------- 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); } }
//--------------------------------------------------------------------------- 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++; } } } }
//--------------------------------------------------------------------------- public Layer this[ELayerMode mode, int x, int y] { get { Cell cell = this[x, y]; return(cell != null ? cell[mode] : null); } }
//--------------------------------------------------------------------------- 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); }
//--------------------------------------------------------------------------- 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)); }
//--------------------------------------------------------------------------- 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); } } }
//--------------------------------------------------------------------------- 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); }
//--------------------------------------------------------------------------- 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()); }
//--------------------------------------------------------------------------- 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); } } } } }
//--------------------------------------------------------------------------- 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; } }
//--------------------------------------------------------------------------- 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); }
//--------------------------------------------------------------------------- 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"); }
//--------------------------------------------------------------------------- public void Init(ELayerMode mode, int width, int height) { m_Mode = mode; Reset(width, height); OnModeChanged(mode); }
//--------------------------------------------------------------------------- public Layer this[ELayerMode mode] { get { return(Layers.ContainsKey(mode) ? Layers[mode] : null); } }
//--------------------------------------------------------------------------- public UndoAction(ELayerMode layer) { Layer = layer; Before = new List <UndoState>(); After = new List <UndoState>(); }
//--------------------------------------------------------------------------- public void SetTile(ELayerMode mode, int sourceX, int sourceY, int destinationX, int destinationY, bool isBlocked) { //m_Canvas?.SetTile(mode, sourceX, sourceY, destinationX, destinationY, isBlocked); }
//--------------------------------------------------------------------------- public void StartUndo(ELayerMode mode) { m_CurrentUndo = new UndoAction(mode); }