diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Battle3/Preinstall.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Battle3/Preinstall.json index c0b7848..2ef21ca 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Battle3/Preinstall.json +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Battle3/Preinstall.json @@ -1 +1 @@ -[{"Name":"test1","Weight":100,"Remark":"","WaveList":[[],[{"Position":{"X":222,"Y":129},"Size":{"X":173,"Y":116},"SpecialMarkType":0,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Face":"0","Weapon":"weapon0007","CurrAmmon":"60","ResidueAmmo":"60"},"Altitude":0,"VerticalSpeed":0}]},{"Position":{"X":117,"Y":411},"Size":{"X":5,"Y":0},"SpecialMarkType":0,"DelayTime":0.5,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Face":"0","Weapon":"weapon0006","CurrAmmon":"20","ResidueAmmo":"20"},"Altitude":0,"VerticalSpeed":0}]}]]}] \ No newline at end of file +[{"Name":"test12","Weight":100,"Remark":"","WaveList":[[{"Position":{"X":68,"Y":40},"Size":{"X":16,"Y":16},"SpecialMarkType":0,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Face":"0","Weapon":null},"Altitude":0,"VerticalSpeed":0}]}]]}] \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/ui/grid/IUiCell.cs b/DungeonShooting_Godot/src/framework/ui/grid/IUiCell.cs index c3c66ea..df0d812 100644 --- a/DungeonShooting_Godot/src/framework/ui/grid/IUiCell.cs +++ b/DungeonShooting_Godot/src/framework/ui/grid/IUiCell.cs @@ -15,6 +15,11 @@ int Index { get; } /// + /// 获取所在网格组件 + /// + IUiGrid GetGrid(); + + /// /// 当前 Cell 初始化时调用 /// void OnInit(); @@ -25,6 +30,11 @@ void Process(float delta); /// + /// 触发当前 Cell 的点击 + /// + void Click(); + + /// /// 当前Ui被点击时调用
/// 如果 Cell 的模板为 BaseButton 类型, 则 UiCell 会自动绑定点击事件
/// 如果需要自己绑定点击事件, 请绑定 UiCell.Click() 函数
@@ -51,7 +61,7 @@ /// 当检测当前 Cell 是否可以被选中时调用 ///
bool CanSelect(); - + /// /// 当前 Cell 选中时调用, 设置 UiGrid.SelectIndex 时触发 /// diff --git a/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs b/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs index 708609e..31b88a3 100644 --- a/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs +++ b/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs @@ -33,7 +33,12 @@ private bool _init = false; //上一次点击的时间 private long _prevClickTime = -1; - + + public IUiGrid GetGrid() + { + return Grid; + } + public virtual void OnInit() { } diff --git a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs index bdb9dfa..878db9c 100644 --- a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs +++ b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs @@ -267,16 +267,17 @@ /// /// 打开创建标记页面 /// + /// 初始坐标 /// 是否提前加载 /// 创建标记回调 /// 所属父级Ui - public static void ShowCreateMark(bool preloading, Action onCreateMarkInfo , UiBase parentUi = null) + public static void ShowCreateMark(Vector2I position, bool preloading, Action onCreateMarkInfo , UiBase parentUi = null) { var window = CreateWindowInstance(parentUi); window.SetWindowTitle("创建标记"); window.SetWindowSize(new Vector2I(1400, 900)); var body = window.OpenBody(UiManager.UiName.MapEditorCreateMark); - body.InitData(preloading); + body.InitData(position, preloading); window.SetButtonList( new EditorWindowPanel.ButtonData("确定", () => { diff --git a/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs b/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs index 2bb7b95..e44a0b6 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs @@ -67,7 +67,7 @@ /// /// 所属地图编辑器UI /// - public MapEditorPanel MapEditorPanel { get; set; } + public MapEditorPanel MapEditorPanel { get; private set; } /// /// 编辑器工具UI @@ -156,17 +156,17 @@ public void SetUiNode(IUiNode uiNode) { _editorTileMap = (MapEditor.TileMap)uiNode; - _editorTileMap.Instance.MapEditorPanel = _editorTileMap.UiPanel; - _editorTileMap.Instance.MapEditorToolsPanel = _editorTileMap.UiPanel.S_MapEditorTools.Instance; + MapEditorPanel = _editorTileMap.UiPanel; + MapEditorToolsPanel = _editorTileMap.UiPanel.S_MapEditorTools.Instance; _editorTileMap.L_Brush.Instance.Draw += DrawGuides; _eventFactory = EventManager.CreateEventFactory(); - _eventFactory.AddEventListener(EventEnum.OnSelectDragTool, _editorTileMap.Instance.OnSelectHandTool); - _eventFactory.AddEventListener(EventEnum.OnSelectPenTool, _editorTileMap.Instance.OnSelectPenTool); - _eventFactory.AddEventListener(EventEnum.OnSelectRectTool, _editorTileMap.Instance.OnSelectRectTool); - _eventFactory.AddEventListener(EventEnum.OnSelectEditTool, _editorTileMap.Instance.OnSelectEditTool); - _eventFactory.AddEventListener(EventEnum.OnClickCenterTool, _editorTileMap.Instance.OnClickCenterTool); - _eventFactory.AddEventListener(EventEnum.OnEditorDirty, _editorTileMap.Instance.OnEditorDirty); + _eventFactory.AddEventListener(EventEnum.OnSelectDragTool, OnSelectHandTool); + _eventFactory.AddEventListener(EventEnum.OnSelectPenTool, OnSelectPenTool); + _eventFactory.AddEventListener(EventEnum.OnSelectRectTool, OnSelectRectTool); + _eventFactory.AddEventListener(EventEnum.OnSelectEditTool, OnSelectEditTool); + _eventFactory.AddEventListener(EventEnum.OnClickCenterTool, OnClickCenterTool); + _eventFactory.AddEventListener(EventEnum.OnEditorDirty, OnEditorDirty); RenderingServer.FramePostDraw += OnFramePostDraw; } @@ -996,15 +996,38 @@ MapProjectManager.SaveRoomTileInfo(CurrRoomSplit); } - //保存预设数据 + /// + /// 保存预设数据 + /// public void SavePreinstallConfig() { //存入本地 MapProjectManager.SaveRoomPreinstall(CurrRoomSplit); } - //设置地图坐标 - private void SetMapPosition(Vector2 pos) + /// + /// 获取相机中心点坐标 + /// + public Vector2I GetCenterPosition() + { + var pos = ToLocal(MapEditorPanel.S_SubViewport.Instance.Size / 2); + return new Vector2I((int)pos.X, (int)pos.Y); + } + + /// + /// 设置相机看向的点 + /// + public void SetLookPosition(Vector2 pos) + { + SetMapPosition(-pos * Scale + MapEditorPanel.S_SubViewport.Instance.Size / 2); + //SetMapPosition(pos * Scale); + //SetMapPosition(pos + MapEditorPanel.S_SubViewport.Instance.Size / 2); + } + + /// + /// 设置地图坐标 + /// + public void SetMapPosition(Vector2 pos) { Position = pos; MapEditorToolsPanel.SetToolTransform(pos, Scale); diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorCreateMark/MapEditorCreateMarkPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorCreateMark/MapEditorCreateMarkPanel.cs index a249c1a..ca97690 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorCreateMark/MapEditorCreateMarkPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorCreateMark/MapEditorCreateMarkPanel.cs @@ -37,8 +37,9 @@ /// /// 初始化面板数据, 用于创建数据 /// + /// 初始坐标 /// 是否提前加载 - public void InitData(bool preloading) + public void InitData(Vector2I position, bool preloading) { _preloading = preloading; if (preloading) @@ -49,6 +50,9 @@ { S_DelayContainer.Instance.Visible = true; } + + S_PosX.Instance.Value = position.X; + S_PosY.Instance.Value = position.Y; } /// diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs index b71017e..c36e547 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs @@ -1,13 +1,18 @@ -using Config; +using System; +using Config; using UI.MapEditor; namespace UI.MapEditorMapMark; public class EditorMarkCell : UiCell { + //上一次点击的时间 + private long _prevClickTime2 = -1; + public override void OnInit() { - CellNode.L_MarkButton.Instance.Pressed += OnClick; + //这里不绑定 Click 函数, 而是绑定 OnClickHandler, 因为 Select 交给 MapEditorMapMarkPanel 处理了 + CellNode.L_MarkButton.Instance.Pressed += OnClickHandler; } public override void OnSetData(MapEditorMapMarkPanel.MarkCellData data) @@ -54,16 +59,35 @@ CellNode.L_MarkButton.Instance.Text = text; } - public override void OnClick() + public void OnClickHandler() { EditorManager.SetSelectWaveIndex(Data.ParentCell.Index); CellNode.UiPanel.SetSelectCell(this, CellNode.Instance, MapEditorMapMarkPanel.SelectToolType.Mark); - //需要切换回编辑工具 - if (CellNode.UiPanel.EditorTileMap.MouseType != EditorTileMap.MouseButtonType.Edit) + //选中标记 + EditorManager.SetSelectMark(Data.MarkInfo); + + //双击判定 + if (_prevClickTime2 >= 0) { - //选中标记 - EditorManager.SetSelectMark(Data.MarkInfo); + var now = DateTime.Now.Ticks / 10000; + if (now <= _prevClickTime2 + 500) + { + OnDoubleClickHandler(); + } + + _prevClickTime2 = now; } + else + { + _prevClickTime2 = DateTime.Now.Ticks / 10000; + } + } + + public void OnDoubleClickHandler() + { + //双击聚焦标记 + var position = Data.MarkInfo.Position.AsVector2(); + CellNode.UiPanel.EditorTileMap.SetLookPosition(position); } public override void OnSelect() diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs index 674ca15..85232f3 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs @@ -10,8 +10,8 @@ public override void OnInit() { - //这里不绑定 Click 函数, 而是绑定 OnClick, 因为 Select 交给 MapEditorMapMarkPanel 处理了 - CellNode.L_WaveContainer.L_WaveButton.Instance.Pressed += OnClick; + //这里不绑定 Click 函数, 而是绑定 OnClickHandler, 因为 Select 交给 MapEditorMapMarkPanel 处理了 + CellNode.L_WaveContainer.L_WaveButton.Instance.Pressed += OnClickHandler; CellNode.L_WaveContainer.L_TextureButton.Instance.Pressed += OnExpandOrClose; CellNode.L_MarginContainer.L_AddMarkButton.Instance.Pressed += OnAddMark; @@ -55,7 +55,7 @@ private void OnAddMark() { //打开添加标记页面 - EditorWindowManager.ShowCreateMark(Index == 0, OnCreateMarkInfo); + EditorWindowManager.ShowCreateMark(CellNode.UiPanel.EditorTileMap.GetCenterPosition(), Index == 0, OnCreateMarkInfo); } //创建的标记完成 @@ -103,10 +103,12 @@ return CellNode.L_MarkContainer.Instance.Visible; } - public override void OnClick() + public void OnClickHandler() { EditorManager.SetSelectWaveIndex(Index); CellNode.UiPanel.SetSelectCell(this, CellNode.L_WaveContainer.Instance, MapEditorMapMarkPanel.SelectToolType.Wave); + //清除选中的标记 + EditorManager.SetSelectMark(null); } public override void OnSelect() diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs index c44cfc0..e4906be 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs @@ -111,7 +111,7 @@ tempWaveCell.OnExpandOrClose(); } //选中物体 - tempMarkCell.OnClick(); + tempMarkCell.OnClickHandler(); return; } } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs index 12ea2dc..0e97028 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorTools/MapEditorToolsPanel.cs @@ -198,6 +198,12 @@ //选中标记 private void OnSelectMarkTool(object arg) { + //选中编辑工具 + if (_toolGrid.SelectIndex != _editToolIndex) + { + _toolGrid.Click(_editToolIndex); + } + if (arg is MarkInfo markInfo) { if (ActiveMark == null || markInfo != ActiveMark.MarkInfo) @@ -208,6 +214,10 @@ } } } + else if (arg == null && ActiveMark != null) + { + SetActiveMark(null); + } } //删除标记