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 index 8348749..bcf14cb 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room3/Room3_roomInfo.json +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room3/Room3_roomInfo.json @@ -1 +1 @@ -{"Position":{"X":-10,"Y":-13},"Size":{"X":23,"Y":24},"DoorAreaInfos":[{"Direction":3,"Start":0,"End":336},{"Direction":0,"Start":0,"End":128},{"Direction":0,"Start":208,"End":288},{"Direction":2,"Start":0,"End":112},{"Direction":1,"Start":0,"End":352}],"GroupName":"TestGroup1","RoomType":0,"RoomName":"Room3","Weight":100,"Remark":""} \ No newline at end of file +{"Position":{"X":-10,"Y":-13},"Size":{"X":23,"Y":24},"DoorAreaInfos":[{"Direction":3,"Start":0,"End":336},{"Direction":0,"Start":0,"End":128},{"Direction":0,"Start":208,"End":288},{"Direction":2,"Start":0,"End":112},{"Direction":1,"Start":0,"End":352}],"GroupName":"TestGroup1","RoomType":0,"RoomName":"Room3","Weight":200,"Remark":""} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/map/serialize/RoomPreinstallInfo.cs b/DungeonShooting_Godot/src/framework/map/serialize/RoomPreinstallInfo.cs index ad68616..73713c6 100644 --- a/DungeonShooting_Godot/src/framework/map/serialize/RoomPreinstallInfo.cs +++ b/DungeonShooting_Godot/src/framework/map/serialize/RoomPreinstallInfo.cs @@ -32,17 +32,6 @@ public List> WaveList; /// - /// 从指定对象浅拷贝数据 - /// - public void CloneFrom(RoomPreinstallInfo preinstallInfo) - { - Name = preinstallInfo.Name; - Weight = preinstallInfo.Weight; - Remark = preinstallInfo.Remark; - WaveList = preinstallInfo.WaveList; - } - - /// /// 初始化波数据 /// public void InitWaveList() diff --git a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs index 7d6f655..bdb9dfa 100644 --- a/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs +++ b/DungeonShooting_Godot/src/game/manager/EditorWindowManager.cs @@ -173,6 +173,37 @@ } /// + /// 编辑地牢房间 + /// + /// 原数据 + /// 保存时回调 + public static void ShowEditRoom(DungeonRoomSplit roomSplit, Action onSave) + { + var window = UiManager.Open_EditorWindow(); + window.SetWindowTitle("编辑地牢房间"); + window.SetWindowSize(new Vector2I(700, 600)); + var body = window.OpenBody(UiManager.UiName.MapEditorCreateRoom); + body.InitEditData(roomSplit); + + window.SetButtonList( + new EditorWindowPanel.ButtonData("确定", () => + { + //获取填写的数据, 并创建ui + var saveData = body.GetRoomInfo(); + if (saveData != null) + { + window.CloseWindow(); + onSave(saveData); + } + }), + new EditorWindowPanel.ButtonData("取消", () => + { + window.CloseWindow(); + }) + ); + } + + /// /// 打开创建房间预设弹窗 /// /// 当前房间的类型 diff --git a/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs b/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs index efd6583..4aa6e63 100644 --- a/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs +++ b/DungeonShooting_Godot/src/game/manager/MapProjectManager.cs @@ -174,14 +174,11 @@ var jsonText = JsonSerializer.Serialize(GroupMap, options); File.WriteAllText(configFile, jsonText); //将房间数据保存为json - var jsonText2 = JsonSerializer.Serialize(roomSplit.RoomInfo); - File.WriteAllText(roomSplit.RoomPath, jsonText2); + SaveRoomInfo(roomSplit); //将房间地块保存为json - var jsonText3 = JsonSerializer.Serialize(roomSplit.TileInfo); - File.WriteAllText(roomSplit.TilePath, jsonText3); + SaveRoomTileInfo(roomSplit); //将预设保存为json - var jsonText4 = JsonSerializer.Serialize(roomSplit.Preinstall); - File.WriteAllText(roomSplit.PreinstallPath, jsonText4); + SaveRoomPreinstall(roomSplit); //创建完成事件 EventManager.EmitEvent(EventEnum.OnCreateRoomFinish, roomSplit); } @@ -212,6 +209,51 @@ } /// + /// 保存房间数据 + /// + public static void SaveRoomInfo(DungeonRoomSplit roomSplit) + { + var roomInfo = roomSplit.RoomInfo; + var path = GetConfigPath(roomInfo.GroupName,roomInfo.RoomType, roomInfo.RoomName); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + var jsonText = JsonSerializer.Serialize(roomInfo); + File.WriteAllText(roomSplit.RoomPath, jsonText); + } + + /// + /// 保存房间地块数据 + /// + public static void SaveRoomTileInfo(DungeonRoomSplit roomSplit) + { + var roomInfo = roomSplit.RoomInfo; + var path = GetConfigPath(roomInfo.GroupName,roomInfo.RoomType, roomInfo.RoomName); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + var jsonText = JsonSerializer.Serialize(roomSplit.TileInfo); + File.WriteAllText(roomSplit.TilePath, jsonText); + } + + /// + /// 保存房间预设数据 + /// + public static void SaveRoomPreinstall(DungeonRoomSplit roomSplit) + { + var roomInfo = roomSplit.RoomInfo; + var path = GetConfigPath(roomInfo.GroupName,roomInfo.RoomType, roomInfo.RoomName); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + var jsonText = JsonSerializer.Serialize(roomSplit.Preinstall); + File.WriteAllText(roomSplit.PreinstallPath, jsonText); + } + + /// /// 从指定组中删除房间, 返回是否删除成功 /// public static bool DeleteRoom(DungeonRoomGroup group, DungeonRoomSplit roomSplit) diff --git a/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs b/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs index 1d6142c..6e7cf53 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditor/tileView/EditorTileMap.cs @@ -940,11 +940,6 @@ { //存入本地 var roomInfo = CurrRoomSplit.RoomInfo; - var path = MapProjectManager.GetConfigPath(roomInfo.GroupName,roomInfo.RoomType, roomInfo.RoomName); - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } if (!HasError) //没有错误 { @@ -960,23 +955,13 @@ roomInfo.DoorAreaInfos.Clear(); roomInfo.DoorAreaInfos.AddRange(CurrDoorConfigs); roomInfo.ClearCompletionDoorArea(); - - path += "/" + MapProjectManager.GetRoomInfoConfigName(roomInfo.RoomName); - var jsonStr = JsonSerializer.Serialize(roomInfo); - File.WriteAllText(path, jsonStr); + MapProjectManager.SaveRoomInfo(CurrRoomSplit); } //保存地块数据 public void SaveTileInfoConfig() { //存入本地 - var roomInfo = CurrRoomSplit.RoomInfo; - var path = MapProjectManager.GetConfigPath(roomInfo.GroupName,roomInfo.RoomType, roomInfo.RoomName); - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - var tileInfo = CurrRoomSplit.TileInfo; tileInfo.NavigationList.Clear(); tileInfo.NavigationList.AddRange(_dungeonTileMap.GetPolygonData()); @@ -987,26 +972,14 @@ PushLayerDataToList(AutoFloorLayer, _sourceId, tileInfo.Floor); PushLayerDataToList(AutoMiddleLayer, _sourceId, tileInfo.Middle); PushLayerDataToList(AutoTopLayer, _sourceId, tileInfo.Top); - - path += "/" + MapProjectManager.GetTileInfoConfigName(roomInfo.RoomName); - var jsonStr = JsonSerializer.Serialize(tileInfo); - File.WriteAllText(path, jsonStr); + MapProjectManager.SaveRoomTileInfo(CurrRoomSplit); } //保存预设数据 public void SavePreinstallConfig() { //存入本地 - var roomInfo = CurrRoomSplit.RoomInfo; - var path = MapProjectManager.GetConfigPath(roomInfo.GroupName,roomInfo.RoomType, roomInfo.RoomName); - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - - path += "/" + MapProjectManager.GetRoomPreinstallConfigName(roomInfo.RoomName); - var jsonStr = JsonSerializer.Serialize(CurrRoomSplit.Preinstall); - File.WriteAllText(path, jsonStr); + MapProjectManager.SaveRoomPreinstall(CurrRoomSplit); } //设置地图坐标 diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorCreatePreinstall/MapEditorCreatePreinstallPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorCreatePreinstall/MapEditorCreatePreinstallPanel.cs index d8ac5b8..7730e2e 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorCreatePreinstall/MapEditorCreatePreinstallPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorCreatePreinstall/MapEditorCreatePreinstallPanel.cs @@ -34,35 +34,51 @@ /// public RoomPreinstallInfo GetRoomPreinstall(List roomPreinstalls) { - var data = new RoomPreinstallInfo(); - data.Name = S_PreinstallNameInput.Instance.Text; - //检查名称是否合规 - if (string.IsNullOrEmpty(data.Name)) - { - EditorWindowManager.ShowTips("错误", "预设名称不能为空!"); - return null; - } - - var index = roomPreinstalls.FindIndex(preinstall => preinstall.Name == data.Name && preinstall != _roomPreinstallInfo); - if (index >= 0) - { - EditorWindowManager.ShowTips("错误", "当前房间已经存在预设名称'" + data.Name + "', 请使用其他名称!"); - return null; - } - - data.Remark = S_RemarkInput.Instance.Text; - data.Weight = (int)S_WeightInput.Instance.Value; + RoomPreinstallInfo data; if (_roomPreinstallInfo != null) //编辑数据 { - data.WaveList = _roomPreinstallInfo.WaveList; + data = _roomPreinstallInfo; + data.Name = S_PreinstallNameInput.Instance.Text; + //检查名称是否合规 + if (string.IsNullOrEmpty(data.Name)) + { + EditorWindowManager.ShowTips("错误", "预设名称不能为空!"); + return null; + } + var index = roomPreinstalls.FindIndex(preinstall => preinstall.Name == data.Name && preinstall != _roomPreinstallInfo); + if (index >= 0) + { + EditorWindowManager.ShowTips("错误", "当前房间已经存在预设名称'" + data.Name + "', 请使用其他名称!"); + return null; + } + + data.Remark = S_RemarkInput.Instance.Text; + data.Weight = (int)S_WeightInput.Instance.Value; } else //创建数据 { + data = new RoomPreinstallInfo(); + data.Name = S_PreinstallNameInput.Instance.Text; + //检查名称是否合规 + if (string.IsNullOrEmpty(data.Name)) + { + EditorWindowManager.ShowTips("错误", "预设名称不能为空!"); + return null; + } + + var index = roomPreinstalls.FindIndex(preinstall => preinstall.Name == data.Name); + if (index >= 0) + { + EditorWindowManager.ShowTips("错误", "当前房间已经存在预设名称'" + data.Name + "', 请使用其他名称!"); + return null; + } + + data.Remark = S_RemarkInput.Instance.Text; + data.Weight = (int)S_WeightInput.Instance.Value; //预加载波 data.InitWaveList(); CreateSpecialMark(data.WaveList); } - return data; } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorCreateRoom/MapEditorCreateRoomPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorCreateRoom/MapEditorCreateRoomPanel.cs index 04be262..9a7bb02 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorCreateRoom/MapEditorCreateRoomPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorCreateRoom/MapEditorCreateRoomPanel.cs @@ -8,6 +8,8 @@ public partial class MapEditorCreateRoomPanel : MapEditorCreateRoom { + //编辑模式下的原数据 + private DungeonRoomSplit _roomSplit; //key: 组名称, value: 选项索引 private Dictionary _groupMap = new Dictionary(); @@ -35,6 +37,28 @@ } /// + /// 初始化数据, 用于编辑房间 + /// + /// + public void InitEditData(DungeonRoomSplit roomSplit) + { + _roomSplit = roomSplit; + //房间名称 + S_RoomNameInput.Instance.Text = roomSplit.RoomInfo.RoomName; + //权重 + S_WeightInput.Instance.Value = roomSplit.RoomInfo.Weight; + //备注 + S_RemarkInput.Instance.Text = roomSplit.RoomInfo.Remark; + //所在的组 + SetSelectGroup(roomSplit.RoomInfo.GroupName); + //房间类型 + SetSelectType((int)roomSplit.RoomInfo.RoomType); + //不可编辑 + S_GroupSelect.Instance.Disabled = true; + S_TypeSelect.Instance.Disabled = true; + } + + /// /// 设置选中的组 /// public void SetSelectGroup(string groupName) @@ -61,63 +85,97 @@ /// public DungeonRoomSplit GetRoomInfo() { - var roomInfo = new DungeonRoomInfo(); - roomInfo.RoomName = S_RoomNameInput.Instance.Text; - roomInfo.Remark = S_RemarkInput.Instance.Text; - //检查名称是否合规 - if (string.IsNullOrEmpty(roomInfo.RoomName)) + if (_roomSplit != null) //修改数据 { - EditorWindowManager.ShowTips("错误", "房间名称不能为空!"); - return null; - } - - var groupIndex = S_GroupSelect.Instance.Selected; - foreach (var pair in _groupMap) - { - if (pair.Value == groupIndex) + var roomInfo = _roomSplit.RoomInfo; + roomInfo.RoomName = S_RoomNameInput.Instance.Text; + roomInfo.Remark = S_RemarkInput.Instance.Text; + roomInfo.Weight = (int)S_WeightInput.Instance.Value; + + //检查名称是否合规 + if (string.IsNullOrEmpty(roomInfo.RoomName)) { - roomInfo.GroupName = pair.Key; + EditorWindowManager.ShowTips("错误", "房间名称不能为空!"); + return null; } + //检测是否有同名房间 + if (_roomSplit.RoomInfo.RoomName != roomInfo.RoomName) + { + var temp = roomInfo.GroupName + "/" + DungeonManager.DungeonRoomTypeToString(roomInfo.RoomType) + "/" + + roomInfo.RoomName; + var dirPath = MapProjectManager.CustomMapPath + temp; + var dir = new DirectoryInfo(dirPath); + if (dir.Exists && dir.GetFiles().Length > 0) + { + EditorWindowManager.ShowTips("错误", $"已经有相同路径的房间了!\n路径: {temp}"); + return null; + } + } + return _roomSplit; } - - if (roomInfo.GroupName == null) + else { - EditorWindowManager.ShowTips("错误", "组名错误!"); - return null; + var roomInfo = new DungeonRoomInfo(); + roomInfo.RoomName = S_RoomNameInput.Instance.Text; + roomInfo.Remark = S_RemarkInput.Instance.Text; + roomInfo.RoomType = (DungeonRoomType)S_TypeSelect.Instance.GetSelectedId(); + roomInfo.Weight = (int)S_WeightInput.Instance.Value; + + //检查名称是否合规 + if (string.IsNullOrEmpty(roomInfo.RoomName)) + { + EditorWindowManager.ShowTips("错误", "房间名称不能为空!"); + return null; + } + + var groupIndex = S_GroupSelect.Instance.Selected; + foreach (var pair in _groupMap) + { + if (pair.Value == groupIndex) + { + roomInfo.GroupName = pair.Key; + } + } + + if (roomInfo.GroupName == null) + { + EditorWindowManager.ShowTips("错误", "组名错误!"); + return null; + } + + + + //检测是否有同名房间 + var temp = roomInfo.GroupName + "/" + DungeonManager.DungeonRoomTypeToString(roomInfo.RoomType) + "/" + roomInfo.RoomName; + var dirPath = MapProjectManager.CustomMapPath + temp; + var dir = new DirectoryInfo(dirPath); + if (dir.Exists && dir.GetFiles().Length > 0) + { + EditorWindowManager.ShowTips("错误", $"已经有相同路径的房间了!\n路径: {temp}"); + return null; + } + + + roomInfo.Size = new SerializeVector2(); + roomInfo.Position = new SerializeVector2(); + roomInfo.DoorAreaInfos = new List(); + + var roomSplit = new DungeonRoomSplit(); + roomSplit.RoomPath = dirPath + "/" + MapProjectManager.GetRoomInfoConfigName(roomInfo.RoomName); + roomSplit.RoomInfo = roomInfo; + + var tileInfo = new DungeonTileInfo(); + tileInfo.NavigationList = new List(); + tileInfo.Floor = new List(); + tileInfo.Middle = new List(); + tileInfo.Top = new List(); + + roomSplit.TilePath = dirPath + "/" + MapProjectManager.GetTileInfoConfigName(roomInfo.RoomName); + roomSplit.TileInfo = tileInfo; + + roomSplit.PreinstallPath = dirPath + "/" + MapProjectManager.GetRoomPreinstallConfigName(roomInfo.RoomName); + roomSplit.Preinstall = new List(); + return roomSplit; } - - roomInfo.RoomType = (DungeonRoomType)S_TypeSelect.Instance.GetSelectedId(); - - //检测是否有同名房间 - var temp = roomInfo.GroupName + "/" + DungeonManager.DungeonRoomTypeToString(roomInfo.RoomType) + "/" + roomInfo.RoomName; - var dirPath = MapProjectManager.CustomMapPath + temp; - var dir = new DirectoryInfo(dirPath); - if (dir.Exists && dir.GetFiles().Length > 0) - { - EditorWindowManager.ShowTips("错误", $"已经有相同路径的房间了!\n路径: {temp}"); - return null; - } - - roomInfo.Weight = (int)S_WeightInput.Instance.Value; - roomInfo.Size = new SerializeVector2(); - roomInfo.Position = new SerializeVector2(); - roomInfo.DoorAreaInfos = new List(); - - var roomSplit = new DungeonRoomSplit(); - roomSplit.RoomPath = dirPath + "/" + MapProjectManager.GetRoomInfoConfigName(roomInfo.RoomName); - roomSplit.RoomInfo = roomInfo; - - var tileInfo = new DungeonTileInfo(); - tileInfo.NavigationList = new List(); - tileInfo.Floor = new List(); - tileInfo.Middle = new List(); - tileInfo.Top = new List(); - - roomSplit.TilePath = dirPath + "/" + MapProjectManager.GetTileInfoConfigName(roomInfo.RoomName); - roomSplit.TileInfo = tileInfo; - - roomSplit.PreinstallPath = dirPath + "/" + MapProjectManager.GetRoomPreinstallConfigName(roomInfo.RoomName); - roomSplit.Preinstall = new List(); - return roomSplit; } } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs index 2dd3ff2..95fc118 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs @@ -287,8 +287,6 @@ var selectPreinstall = GetSelectPreinstall(); EditorWindowManager.ShowEditPreinstall(roomInfoRoomType, roomSplitPreinstall, selectPreinstall, preinstall => { - //修改逻辑 - selectPreinstall.CloneFrom(preinstall); //修改下拉菜单数据 var optionButton = S_PreinstallOption.Instance; optionButton.SetItemText(optionButton.Selected, $"{preinstall.Name} ({preinstall.Weight})"); diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorProject/MapEditorProjectPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorProject/MapEditorProjectPanel.cs index ad7abf4..b5f29a3 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorProject/MapEditorProjectPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorProject/MapEditorProjectPanel.cs @@ -188,7 +188,20 @@ //编辑房间 private void OnEditRoom() { - + var selectRoom = _roomGrid.SelectData; + if (selectRoom == null) + { + EditorWindowManager.ShowTips("提示", "请选择需要编辑的房间!"); + } + else + { + EditorWindowManager.ShowEditRoom(selectRoom, (room) => + { + //保存房间数据 + MapProjectManager.SaveRoomInfo(room); + OnSearchRoomButtonClick(); + }); + } } //删除房间