diff --git a/DungeonShooting_Godot/resource/map/tileMaps/GroupConfig.json b/DungeonShooting_Godot/resource/map/tileMaps/GroupConfig.json index cab1a6a..390cc67 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/GroupConfig.json +++ b/DungeonShooting_Godot/resource/map/tileMaps/GroupConfig.json @@ -6,9 +6,25 @@ "Ready": false, "RoomPath": "resource/map/tileMaps/TestGroup1/battle/Room1/Room1_roomInfo.json", "TilePath": "resource/map/tileMaps/TestGroup1/battle/Room1/Room1_tileInfo.json" + }, + { + "Ready": false, + "RoomPath": "resource/map/tileMaps/TestGroup1/battle/Room2/Room2_roomInfo.json", + "TilePath": "resource/map/tileMaps/TestGroup1/battle/Room2/Room2_tileInfo.json" + }, + { + "Ready": false, + "RoomPath": "resource/map/tileMaps/TestGroup1/battle/Room3/Room3_roomInfo.json", + "TilePath": "resource/map/tileMaps/TestGroup1/battle/Room3/Room3_tileInfo.json" } ], - "InletList": [], + "InletList": [ + { + "Ready": false, + "RoomPath": "resource/map/tileMaps/TestGroup1/inlet/Room1/Room1_roomInfo.json", + "TilePath": "resource/map/tileMaps/TestGroup1/inlet/Room1/Room1_tileInfo.json" + } + ], "OutletList": [], "BossList": [], "RewardList": [], diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room2/Room2_roomInfo.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room2/Room2_roomInfo.json new file mode 100644 index 0000000..5408140 --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room2/Room2_roomInfo.json @@ -0,0 +1 @@ +{"Position":{"X":-2,"Y":-2},"Size":{"X":4,"Y":4},"DoorAreaInfos":[{"Direction":3,"Start":16,"End":-16},{"Direction":2,"Start":16,"End":-16},{"Direction":1,"Start":16,"End":-16},{"Direction":0,"Start":16,"End":-16}],"GroupName":"TestGroup1","RoomType":0,"RoomName":"Room2","Weight":100,"Remark":""} \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room2/Room2_tileInfo.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room2/Room2_tileInfo.json new file mode 100644 index 0000000..6f69930 --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room2/Room2_tileInfo.json @@ -0,0 +1 @@ +{"NavigationList":[{"Type":0,"Points":[-24,-24,24,-24,24,32,-24,32]}],"Floor":[-2,1,0,0,8,-2,0,0,0,8,-2,-1,0,0,8,-2,-2,0,0,8,1,1,0,0,8,1,0,0,0,8,1,-1,0,0,8,1,-2,0,0,8,0,1,0,0,8,0,0,0,0,8,0,-1,0,0,8,0,-2,0,0,8,-1,1,0,0,8,-1,0,0,0,8,-1,-1,0,0,8,-1,-2,0,0,8,-2,-3,0,2,7,-1,-3,0,2,7,0,-3,0,2,7,0,2,0,2,2,-1,2,0,2,2,-2,2,0,2,2,1,-3,0,2,7,1,2,0,2,2,2,-2,0,1,3,2,-1,0,1,3,2,-3,0,1,4,2,0,0,1,3,2,1,0,1,3,2,2,0,13,2,-3,-1,0,3,3,-3,-2,0,3,3,-3,-3,0,3,4,-3,0,0,3,3,-3,1,0,3,3,-3,2,0,11,2],"Middle":[],"Top":[]} \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room3/Room3_roomInfo.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room3/Room3_roomInfo.json new file mode 100644 index 0000000..f8892b2 --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room3/Room3_roomInfo.json @@ -0,0 +1 @@ +{"Position":{"X":-3,"Y":-3},"Size":{"X":6,"Y":6},"DoorAreaInfos":[{"Direction":3,"Start":16,"End":144},{"Direction":2,"Start":16,"End":144},{"Direction":1,"Start":16,"End":192},{"Direction":0,"Start":16,"End":192}],"GroupName":"TestGroup1","RoomType":0,"RoomName":"Room3","Weight":100,"Remark":""} \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room3/Room3_tileInfo.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room3/Room3_tileInfo.json new file mode 100644 index 0000000..7ddad26 --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room3/Room3_tileInfo.json @@ -0,0 +1 @@ +{"NavigationList":[{"Type":0,"Points":[-40,-40,40,-40,40,48,-40,48]}],"Floor":[-3,2,0,0,8,-3,1,0,0,8,-3,0,0,0,8,-3,-1,0,0,8,-3,-2,0,0,8,-3,-3,0,0,8,0,2,0,0,8,0,1,0,0,8,0,0,0,0,8,0,-1,0,0,8,0,-2,0,0,8,0,-3,0,0,8,-1,2,0,0,8,-1,1,0,0,8,-1,0,0,0,8,-1,-1,0,0,8,-1,-2,0,0,8,-1,-3,0,0,8,2,2,0,0,8,2,1,0,0,8,2,0,0,0,8,2,-1,0,0,8,2,-2,0,0,8,2,-3,0,0,8,1,2,0,0,8,1,1,0,0,8,1,0,0,0,8,1,-1,0,0,8,1,-2,0,0,8,1,-3,0,0,8,-2,2,0,0,8,-2,1,0,0,8,-2,0,0,0,8,-2,-1,0,0,8,-2,-2,0,0,8,-2,-3,0,0,8,-3,-4,0,2,7,-2,-4,0,2,7,-1,-4,0,2,7,-1,3,0,2,2,-2,3,0,2,2,-3,3,0,2,2,0,-4,0,2,7,1,-4,0,2,7,2,-4,0,2,7,2,3,0,2,2,1,3,0,2,2,0,3,0,2,2,3,-3,0,1,3,3,-2,0,1,3,3,-4,0,1,4,3,-1,0,1,3,3,0,0,1,3,3,1,0,1,3,3,2,0,1,3,3,3,0,13,2,-4,-2,0,3,3,-4,-3,0,3,3,-4,-4,0,3,4,-4,-1,0,3,3,-4,0,0,3,3,-4,1,0,3,3,-4,2,0,3,3,-4,3,0,11,2],"Middle":[],"Top":[]} \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Room1/Room1_roomInfo.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Room1/Room1_roomInfo.json new file mode 100644 index 0000000..b9987cf --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Room1/Room1_roomInfo.json @@ -0,0 +1 @@ +{"Position":{"X":0,"Y":0},"Size":{"X":0,"Y":0},"DoorAreaInfos":[],"GroupName":"TestGroup1","RoomType":1,"RoomName":"Room1","Weight":100,"Remark":""} \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Room1/Room1_tileInfo.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Room1/Room1_tileInfo.json new file mode 100644 index 0000000..6949537 --- /dev/null +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Room1/Room1_tileInfo.json @@ -0,0 +1 @@ +{"NavigationList":[],"Floor":[],"Middle":[],"Top":[]} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs b/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs index 8694d21..c3097ad 100644 --- a/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs +++ b/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs @@ -33,28 +33,42 @@ /// /// 当前cell初始化时调用 /// - protected virtual void OnInit() + public virtual void OnInit() { } /// /// 当前cell被分配值时调用 /// - protected virtual void OnSetData(T data) + public virtual void OnSetData(T data) { } /// + /// 当启用当前 Cell 时调用 + /// + public virtual void OnEnable() + { + } + + /// + /// 当禁用当前 Cell 时调用 + /// + public virtual void OnDisable() + { + } + + /// /// 当前 Cell 选中时调用, 设置 UiGrid.SelectIndex 时触发 /// - protected virtual void OnSelect() + public virtual void OnSelect() { } /// /// 当前 Cell 取消选中时调用, 设置 UiGrid.SelectIndex 时触发 /// - protected virtual void OnUnSelect() + public virtual void OnUnSelect() { } @@ -62,14 +76,14 @@ /// 当 Cell 索引发生改变时调用, 在 UiGrid 中调用 Insert(), Remove() 等函数时被动触发当前 Cell 索引值改变, Cell 业务逻辑需要用到索引值时, 那么就可以重写该函数
/// 注意: 该函数第一次调用会在 OnSetData() 之前调用 /// - protected virtual void OnRefreshIndex() + public virtual void OnRefreshIndex() { } /// /// 销毁当前cell时调用 /// - protected virtual void OnDestroy() + public virtual void OnDestroy() { } @@ -100,22 +114,6 @@ } /// - /// 选中当前 Cell, 这个函数由 UiGrid 调用 - /// - public void Select() - { - OnSelect(); - } - - /// - /// 取消选中当前 Cell , 这个函数由 UiGrid 调用 - /// - public void UnSelect() - { - OnUnSelect(); - } - - /// /// 设置当前 Cell 的索引 /// public void SetIndex(int index) diff --git a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs index bf49d56..fe3dac2 100644 --- a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs +++ b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs @@ -31,14 +31,14 @@ if (prevIndex >= 0 && prevIndex < _cellList.Count) { var uiCell = _cellList[prevIndex]; - uiCell.UnSelect(); + uiCell.OnUnSelect(); } //选中新的 if (newIndex >= 0) { var uiCell = _cellList[newIndex]; - uiCell.Select(); + uiCell.OnSelect(); } } } @@ -267,6 +267,8 @@ /// public void Add(TData data) { + //取消选中 + SelectIndex = -1; var cell = GetCellInstance(); _gridContainer.AddChild(cell.CellNode.GetUiInstance()); cell.SetData(data); @@ -283,6 +285,18 @@ uiCell.SetData(data); } } + + /// + /// 移除所有 Cell + /// + public void RemoveAll() + { + var uiCells = _cellList.ToArray(); + foreach (var uiCell in uiCells) + { + ReclaimCellInstance(uiCell); + } + } /// /// 销毁当前网格组件 @@ -320,13 +334,15 @@ _gridContainer.Position = control.Position; } } - + + //获取 cell 实例 private UiCell GetCellInstance() { if (_cellPool.Count > 0) { var cell = _cellPool.Pop(); cell.SetIndex(_cellList.Count); + cell.OnEnable(); _cellList.Add(cell); return cell; } @@ -336,13 +352,16 @@ { throw new Exception($"cellType 无法转为'{typeof(UiCell).FullName}'类型!"); } - uiCell.Init(this, (TUiCellNode)_template.CloneUiCell(), _cellList.Count); _cellList.Add(uiCell); + uiCell.Init(this, (TUiCellNode)_template.CloneUiCell(), _cellList.Count); + uiCell.OnEnable(); return uiCell; } + //回收 cell private void ReclaimCellInstance(UiCell cell) { + cell.OnDisable(); _gridContainer.RemoveChild(cell.CellNode.GetUiInstance()); _cellPool.Push(cell); } diff --git a/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs b/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs index 408c14f..568e3df 100644 --- a/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs +++ b/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs @@ -167,7 +167,7 @@ var jsonText3 = JsonSerializer.Serialize(roomSplit.TileInfo); File.WriteAllText(roomSplit.TilePath, jsonText3); //创建完成事件 - EventManager.EmitEvent(EventEnum.OnCreateGroupFinish, roomSplit); + EventManager.EmitEvent(EventEnum.OnCreateRoomFinish, roomSplit); } else { diff --git a/DungeonShooting_Godot/src/game/ui/editorWindow/CustomButtonCell.cs b/DungeonShooting_Godot/src/game/ui/editorWindow/CustomButtonCell.cs index 2117f90..557d2e6 100644 --- a/DungeonShooting_Godot/src/game/ui/editorWindow/CustomButtonCell.cs +++ b/DungeonShooting_Godot/src/game/ui/editorWindow/CustomButtonCell.cs @@ -2,17 +2,17 @@ public class CustomButtonCell : UiCell { - protected override void OnInit() + public override void OnInit() { CellNode.L_Button.Instance.Pressed += OnClick; } - protected override void OnSetData(EditorWindowPanel.ButtonData data) + public override void OnSetData(EditorWindowPanel.ButtonData data) { CellNode.L_Button.Instance.Text = data.Text; } - protected override void OnDestroy() + public override void OnDestroy() { CellNode.L_Button.Instance.Pressed -= OnClick; } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMap.cs b/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMap.cs index 144c56b..77e7b2e 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMap.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditor/TileView/EditorTileMap.cs @@ -287,7 +287,7 @@ { if (eventKey.Pressed && eventKey.Keycode == Key.M) { - GD.Print("测试保存地牢房间数据..."); + GD.Print("保存地牢房间数据..."); TriggerSave(); } } @@ -726,12 +726,13 @@ { Directory.CreateDirectory(path); } - - var tileInfo = new DungeonTileInfo(); - tileInfo.NavigationList = _dungeonTileMap.GetPolygonData().ToList(); - tileInfo.Floor = new List(); - tileInfo.Middle = new List(); - tileInfo.Top = new List(); + + var tileInfo = _roomSplit.TileInfo; + tileInfo.NavigationList.Clear(); + tileInfo.NavigationList.AddRange(_dungeonTileMap.GetPolygonData()); + tileInfo.Floor.Clear(); + tileInfo.Middle.Clear(); + tileInfo.Top.Clear(); PushLayerDataToList(AutoFloorLayer, _sourceId, tileInfo.Floor); PushLayerDataToList(AutoMiddleLayer, _sourceId, tileInfo.Middle); diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorCreateRoom/MapEditorCreateRoomPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorCreateRoom/MapEditorCreateRoomPanel.cs index 03857a8..55a5b36 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorCreateRoom/MapEditorCreateRoomPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorCreateRoom/MapEditorCreateRoomPanel.cs @@ -86,8 +86,7 @@ return null; } - var typeIndex = S_TypeSelect.Instance.Selected; - roomInfo.RoomType = (DungeonRoomType)typeIndex; + roomInfo.RoomType = (DungeonRoomType)S_TypeSelect.Instance.GetSelectedId(); //检测是否有同名房间 var temp = roomInfo.GroupName + "/" + DungeonManager.DungeonRoomTypeToString(roomInfo.RoomType) + "/" + roomInfo.RoomName; diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorProject/GroupButtonCell.cs b/DungeonShooting_Godot/src/game/ui/mapEditorProject/GroupButtonCell.cs index 23e00d5..37fdd1b 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorProject/GroupButtonCell.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorProject/GroupButtonCell.cs @@ -4,18 +4,18 @@ public class GroupButtonCell : UiCell { - protected override void OnInit() + public override void OnInit() { CellNode.Instance.Pressed += OnClick; } - protected override void OnSetData(DungeonRoomGroup info) + public override void OnSetData(DungeonRoomGroup info) { CellNode.Instance.Text = info.GroupName; CellNode.Instance.TooltipText = "路径: " + MapProjectManager.CustomMapPath + "/" + info.GroupName; } - protected override void OnRefreshIndex() + public override void OnRefreshIndex() { GD.Print("刷新索引: " + Index); } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorProject/MapEditorProjectPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorProject/MapEditorProjectPanel.cs index 2fdd88b..6328920 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorProject/MapEditorProjectPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorProject/MapEditorProjectPanel.cs @@ -45,7 +45,8 @@ public override void OnShowUi() { - S_GroupSearchButton.Instance.Pressed += OnSearchButtonClick; + S_GroupSearchButton.Instance.Pressed += OnSearchGroupButtonClick; + S_RoomSearchButton.Instance.Pressed += OnSearchRoomButtonClick; S_RoomAddButton.Instance.Pressed += OnCreateRoomClick; S_GroupAddButton.Instance.Pressed += OnCreateGroupClick; RefreshGroup(); @@ -56,7 +57,8 @@ public override void OnHideUi() { - S_GroupSearchButton.Instance.Pressed -= OnSearchButtonClick; + S_GroupSearchButton.Instance.Pressed -= OnSearchGroupButtonClick; + S_RoomSearchButton.Instance.Pressed -= OnSearchRoomButtonClick; S_RoomAddButton.Instance.Pressed -= OnCreateRoomClick; S_GroupAddButton.Instance.Pressed -= OnCreateGroupClick; _eventFactory.RemoveAllEventListener(); @@ -77,13 +79,16 @@ public void RefreshGroup() { MapProjectManager.RefreshMapGroup(); - OnSearchButtonClick(); + OnSearchGroupButtonClick(); } + /// + /// 选中地牢组 + /// public void SelectGroup(DungeonRoomGroup group) { SelectGroupInfo = group; - _roomGrid.SetDataList(group.GetAllRoomList().ToArray()); + OnSearchRoomButtonClick(); } /// @@ -100,7 +105,7 @@ } //搜索组按钮点击 - private void OnSearchButtonClick() + private void OnSearchGroupButtonClick() { //输入文本 var text = S_GroupSearchInput.Instance.Text; @@ -123,6 +128,43 @@ } } + //搜索房间按钮点击 + private void OnSearchRoomButtonClick() + { + if (SelectGroupInfo != null) + { + //输入文本 + var text = S_RoomSearchInput.Instance.Text; + //房间类型 + var roomType = S_RoomTypeButton.Instance.GetSelectedId(); + + IEnumerable result = SelectGroupInfo.GetAllRoomList(); + + //名称搜索 + if (!string.IsNullOrEmpty(text)) + { + var queryText = text.Trim().ToLower(); + result = result.Where(split => + { + return split.RoomInfo.RoomName.Trim().ToLower().Contains(queryText); + }); + } + + //类型搜索 + if (roomType > 0) + { + var type = (DungeonRoomType)roomType; + result = result.Where(split => split.RoomInfo.RoomType == type); + } + + _roomGrid.SetDataList(result.ToArray()); + } + else + { + _roomGrid.RemoveAll(); + } + } + //创建组按钮点击 private void OnCreateGroupClick() { @@ -159,7 +201,7 @@ { body.SetSelectGroup(SelectGroupInfo.GroupName); } - body.SetSelectType(S_RoomTypeButton.Instance.Selected); + body.SetSelectType(Mathf.Max(S_RoomTypeButton.Instance.Selected - 1, 0)); window.SetButtonList( new EditorWindowPanel.ButtonData("确定", () => @@ -194,12 +236,12 @@ //创建地牢组完成 private void OnCreateGroupFinish(object group) { - OnSearchButtonClick(); + OnSearchGroupButtonClick(); } //创建地牢房间完成 private void OnCreateRoomFinish(object roomSplit) { - + OnSearchRoomButtonClick(); } } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorProject/RoomButtonCell.cs b/DungeonShooting_Godot/src/game/ui/mapEditorProject/RoomButtonCell.cs index ed10445..4700cad 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorProject/RoomButtonCell.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorProject/RoomButtonCell.cs @@ -5,14 +5,14 @@ public class RoomButtonCell : UiCell { private bool _focus = false; - - protected override void OnInit() + + public override void OnInit() { CellNode.Instance.Pressed += OnClick; CellNode.Instance.FocusExited += OnFocusExited; } - protected override void OnSetData(DungeonRoomSplit data) + public override void OnSetData(DungeonRoomSplit data) { _focus = false; CellNode.L_RoomName.Instance.Text = data.RoomInfo.RoomName; @@ -21,7 +21,7 @@ CellNode.Instance.ReleaseFocus(); } - protected override void OnDestroy() + public override void OnDestroy() { CellNode.Instance.Pressed -= OnClick; CellNode.Instance.FocusExited -= OnFocusExited; diff --git a/DungeonShooting_Godot/src/game/ui/roomUI/LifeCell.cs b/DungeonShooting_Godot/src/game/ui/roomUI/LifeCell.cs index 93b5465..6076f4e 100644 --- a/DungeonShooting_Godot/src/game/ui/roomUI/LifeCell.cs +++ b/DungeonShooting_Godot/src/game/ui/roomUI/LifeCell.cs @@ -6,7 +6,7 @@ { private int _type = -1; - protected override void OnSetData(LifeIconEnum data) + public override void OnSetData(LifeIconEnum data) { if (_type == (int)data) {