diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs index 39a52f2..4df02b3 100644 --- a/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs +++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorTerrain/down/MaskCell.cs @@ -4,23 +4,77 @@ public class MaskCell : UiCell { + private TextureRect _textureRect; + private Texture2D _texture; + private TileSetEditorTerrainPanel _panel; + private bool _dragMoveFlag = false; + public override void OnInit() { - CellNode.Instance.Init(this); + _panel = CellNode.UiPanel; + _textureRect = _panel.S_BottomBg.L_TileTexture.Instance; + _texture = _textureRect.Texture; + CellNode.Instance.Draw += Draw; + CellNode.Instance.AddDragListener(OnDrag); } - public override void OnSetData(Rect2I data) + public override void Process(float delta) { - CellNode.Instance.SetRect(data); + CellNode.Instance.QueueRedraw(); } - public override void OnSelect() + //拖拽操作 + private void OnDrag(DragState state, Vector2 delta) { - CellNode.Instance.DragOutline = true; + var sprite = _panel.S_DragSprite.Instance; + if (state == DragState.DragStart) //拖拽开始 + { + //这里要判断一下是否在BottomBg区域内 + if (CellNode.UiPanel.S_BottomBg.Instance.IsMouseInRect()) + { + _panel.DraggingCell = this; + Grid.SelectIndex = Index; + _dragMoveFlag = false; + } + } + else if (state == DragState.DragEnd) //拖拽结束 + { + if (_panel.DraggingCell == this) + { + _panel.DraggingCell = null; + sprite.Visible = false; + _dragMoveFlag = false; + + if (_panel.S_TopBg.Instance.IsMouseInRect()) //找到放置的Cell + { + _panel.OnDropCell(this); + } + } + } + else if (_panel.DraggingCell == this) //拖拽移动 + { + if (!_dragMoveFlag) + { + _dragMoveFlag = true; + sprite.Texture = _texture; + sprite.RegionRect = Data; + sprite.Scale = _panel.S_TopBg.L_TerrainRoot.Instance.Scale; + sprite.Visible = true; + sprite.GlobalPosition = sprite.GetGlobalMousePosition(); + } + sprite.GlobalPosition = sprite.GetGlobalMousePosition(); + } } - public override void OnUnSelect() + private void Draw() { - CellNode.Instance.DragOutline = false; + if (Grid.SelectIndex == Index) + { + //选中时绘制轮廓 + CellNode.Instance.DrawRect( + new Rect2(Vector2.Zero, CellNode.Instance.Size), + new Color(0, 1, 1), false, 2f / _textureRect.Scale.X + ); + } } } \ No newline at end of file