diff --git a/DungeonShooting_Godot/prefab/ui/MapEditorCreateMark.tscn b/DungeonShooting_Godot/prefab/ui/MapEditorCreateMark.tscn index 4bb9712..fe06a81 100644 --- a/DungeonShooting_Godot/prefab/ui/MapEditorCreateMark.tscn +++ b/DungeonShooting_Godot/prefab/ui/MapEditorCreateMark.tscn @@ -115,6 +115,7 @@ custom_minimum_size = Vector2(200, 0) layout_mode = 2 max_value = 9999.0 +value = 16.0 custom_arrow_step = 1.0 [node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer3/HBoxContainer3/VBoxContainer"] @@ -129,6 +130,7 @@ custom_minimum_size = Vector2(200, 0) layout_mode = 2 max_value = 9999.0 +value = 16.0 custom_arrow_step = 1.0 [node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer3"] diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_preinstall.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_preinstall.json index 9ce9005..154b74e 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_preinstall.json +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_preinstall.json @@ -1 +1 @@ -[{"Name":"test1","Weight":100,"Remark":"","WaveList":[[{"Position":{"X":-30,"Y":-36},"Size":{"X":50,"Y":50},"Preloading":false,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Weapon":"weapon0007","CurrAmmon":"60","ResidueAmmo":"50"}}]}]]},{"Name":"test2","Weight":100,"Remark":"","WaveList":[[{"Position":{"X":5,"Y":-51},"Size":{"X":61,"Y":31},"Preloading":true,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Weapon":"weapon0001","CurrAmmon":"30","ResidueAmmo":"30"}}]}]]},{"Name":"test3","Weight":100,"Remark":"","WaveList":[[{"Position":{"X":-36,"Y":-41},"Size":{"X":30,"Y":60},"Preloading":false,"DelayTime":0,"MarkList":[{"Id":"weapon0001","Weight":100,"Attr":{"CurrAmmon":"30","ResidueAmmo":"210"}}]},{"Position":{"X":98,"Y":8},"Size":{"X":30,"Y":90},"Preloading":false,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Weapon":"weapon0001","CurrAmmon":"30","ResidueAmmo":"50"}}]}],[{"Position":{"X":35,"Y":24},"Size":{"X":54,"Y":44},"Preloading":false,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Weapon":"weapon0007","CurrAmmon":"60","ResidueAmmo":"50"}}]}]]}] \ No newline at end of file +[{"Name":"test1","Weight":100,"Remark":"","WaveList":[[{"Position":{"X":23,"Y":-92},"Size":{"X":17,"Y":69},"Preloading":false,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Weapon":"weapon0002","CurrAmmon":"7","ResidueAmmo":"7"}}]},{"Position":{"X":6,"Y":-27},"Size":{"X":44,"Y":35},"Preloading":true,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Weapon":"weapon0007","CurrAmmon":"60","ResidueAmmo":"60"}}]},{"Position":{"X":73,"Y":30},"Size":{"X":75,"Y":46},"Preloading":false,"DelayTime":1,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Weapon":"weapon0006","CurrAmmon":"20","ResidueAmmo":"20"}}]},{"Position":{"X":-18,"Y":-133},"Size":{"X":88,"Y":20},"Preloading":false,"DelayTime":2,"MarkList":[{"Id":"weapon0002","Weight":100,"Attr":{"CurrAmmon":"7","ResidueAmmo":"70"}}]}],[{"Position":{"X":-39,"Y":-27},"Size":{"X":39,"Y":27},"Preloading":false,"DelayTime":0.6,"MarkList":[{"Id":"prop0006","Weight":100,"Attr":null}]}]]},{"Name":"test2","Weight":100,"Remark":"","WaveList":[[{"Position":{"X":-13,"Y":-31},"Size":{"X":61,"Y":35},"Preloading":true,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Weapon":"weapon0001","CurrAmmon":"30","ResidueAmmo":"30"}}]}]]},{"Name":"test3","Weight":100,"Remark":"","WaveList":[[{"Position":{"X":-18,"Y":-33},"Size":{"X":90,"Y":27},"Preloading":false,"DelayTime":0,"MarkList":[{"Id":"weapon0001","Weight":100,"Attr":{"CurrAmmon":"30","ResidueAmmo":"210"}}]},{"Position":{"X":98,"Y":28},"Size":{"X":27,"Y":51},"Preloading":false,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Weapon":"weapon0001","CurrAmmon":"30","ResidueAmmo":"50"}}]}],[{"Position":{"X":44,"Y":28},"Size":{"X":54,"Y":44},"Preloading":false,"DelayTime":0,"MarkList":[{"Id":"enemy0001","Weight":100,"Attr":{"Weapon":"weapon0007","CurrAmmon":"60","ResidueAmmo":"50"}}]}]]}] \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_tileInfo.json b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_tileInfo.json index 4bea290..7a02202 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_tileInfo.json +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/battle/Room1/Room1_tileInfo.json @@ -1 +1 @@ -{"NavigationList":[{"Type":0,"Points":[-72,-152,104,-152,104,-96,56,-96,56,-80,40,-80,40,-8,104,-8,104,-56,120,-56,120,64,72,64,72,104,120,104,120,128,24,128,24,104,56,104,56,64,8,64,8,0,-56,0,-56,64,-72,64]}],"Floor":[7,3,0,0,8,7,2,0,0,8,7,1,0,0,8,7,0,0,0,8,7,-1,0,0,8,7,-2,0,0,8,7,-3,0,0,8,7,-4,0,0,8,7,6,0,0,8,7,7,0,0,8,6,-10,0,0,8,6,-9,0,0,8,6,-8,0,0,8,6,3,0,0,8,6,2,0,0,8,6,1,0,0,8,6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0,3,3,-6,1,0,3,3,-6,2,0,3,3,-6,3,0,3,3,-6,4,0,11,2,-5,4,0,2,2,-4,4,0,2,2,-3,0,0,1,2,-3,1,0,1,3,-3,2,0,1,3,-3,3,0,1,3,-3,4,0,13,2,-2,0,0,2,2,-1,0,0,3,2,-1,1,0,3,3,-1,2,0,3,3,-1,3,0,3,3,-1,4,0,11,2,0,4,0,2,2,0,5,0,3,4,0,6,0,3,3,0,7,0,3,3,0,8,0,11,2,1,4,0,2,2,1,8,0,2,2,2,4,0,3,2,2,8,0,2,2,3,-5,0,1,2,3,-4,0,1,3,3,-3,0,1,3,3,8,0,2,2,4,-6,0,1,2,4,-5,0,13,2,4,8,0,2,2,5,-6,0,2,2,5,-5,0,3,4,5,-4,0,3,3,5,-3,0,3,3,5,4,0,1,2,5,8,0,2,2,6,-6,0,2,2,6,4,0,2,2,6,8,0,2,2,7,-11,0,1,4,7,-10,0,1,3,7,-9,0,1,3,7,-8,0,1,3,7,-7,0,1,3,7,-6,0,13,2,7,4,0,2,2,7,8,0,2,2,8,-5,0,1,4,8,-4,0,1,3,8,-3,0,1,3,8,-2,0,1,3,8,-1,0,1,3,8,0,0,1,3,8,1,0,1,3,8,2,0,1,3,8,3,0,1,3,8,4,0,13,2,8,5,0,1,4,8,6,0,1,3,8,7,0,1,3,8,8,0,13,2]} \ No newline at end of file +{"NavigationList":[{"Type":0,"Points":[-72,-152,104,-152,104,-96,56,-96,56,-80,40,-80,40,-8,104,-8,104,-56,120,-56,120,64,72,64,72,104,120,104,120,128,24,128,24,104,56,104,56,64,8,64,8,0,-56,0,-56,64,-72,64]},{"Type":1,"Points":[-40,-112,8,-112,8,-56,-40,-56]}],"Floor":[-5,-5,0,0,8,-5,-4,0,0,8,-5,-3,0,0,8,-5,-2,0,0,8,-5,-1,0,0,8,-5,0,0,0,8,-5,1,0,0,8,-5,2,0,0,8,-5,3,0,0,8,-5,-6,0,0,8,-5,-7,0,0,8,-5,-8,0,0,8,-5,-9,0,0,8,-5,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3,3,-6,4,0,11,2,-5,4,0,2,2,-4,4,0,2,2,-3,0,0,1,2,-3,1,0,1,3,-3,2,0,1,3,-3,3,0,1,3,-3,4,0,13,2,-2,-7,0,1,2,-2,-6,0,1,3,-2,0,0,2,2,-1,-7,0,3,2,-1,-6,0,3,3,-1,0,0,3,2,-1,1,0,3,3,-1,2,0,3,3,-1,3,0,3,3,-1,4,0,11,2,0,4,0,2,2,0,5,0,3,4,0,6,0,3,3,0,7,0,3,3,0,8,0,11,2,1,4,0,2,2,1,8,0,2,2,2,4,0,3,2,2,8,0,2,2,3,-5,0,1,2,3,-4,0,1,3,3,-3,0,1,3,3,8,0,2,2,4,-6,0,1,2,4,-5,0,13,2,4,8,0,2,2,5,-6,0,2,2,5,-5,0,3,4,5,-4,0,3,3,5,-3,0,3,3,5,4,0,1,2,5,8,0,2,2,6,-6,0,2,2,6,4,0,2,2,6,8,0,2,2,7,-11,0,1,4,7,-10,0,1,3,7,-9,0,1,3,7,-8,0,1,3,7,-7,0,1,3,7,-6,0,13,2,7,4,0,2,2,7,8,0,2,2,8,-5,0,1,4,8,-4,0,1,3,8,-3,0,1,3,8,-2,0,1,3,8,-1,0,1,3,8,0,0,1,3,8,1,0,1,3,8,2,0,1,3,8,3,0,1,3,8,4,0,13,2,8,5,0,1,4,8,6,0,1,3,8,7,0,1,3,8,8,0,13,2]} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/common/Utils.cs b/DungeonShooting_Godot/src/framework/common/Utils.cs index 99fe1a7..6d6802c 100644 --- a/DungeonShooting_Godot/src/framework/common/Utils.cs +++ b/DungeonShooting_Godot/src/framework/common/Utils.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using Godot; /// @@ -169,4 +171,94 @@ return pos.X >= rect2.Position.X && pos.X <= rect2.Position.X + rect2.Size.X && pos.Y >= rect2.Position.Y && pos.Y <= rect2.Position.Y + rect2.Size.Y; } + + /// + /// 使用快速排序算法对 arr 进行排序操作 + /// + /// 需要进行排序的数组 + /// 自定义比较规则 + public static void QuickSort(T[] arr, Comparison comparison) + { + QuickSort(arr, 0, arr.Length - 1, comparison); + } + + /// + /// 使用快速排序算法对 arr 进行排序操作 + /// + /// 需要进行排序的数组 + /// 自定义比较规则 + public static void QuickSort(List arr, Comparison comparison) + { + QuickSort(arr, 0, arr.Count - 1, comparison); + } + + private static void QuickSort(T[] arr, int low, int high, Comparison comparison) + { + if (low < high) + { + int pivotIndex = Partition(arr, low, high, comparison); + QuickSort(arr, low, pivotIndex - 1, comparison); + QuickSort(arr, pivotIndex + 1, high, comparison); + } + } + + private static void QuickSort(List arr, int low, int high, Comparison comparison) + { + if (low < high) + { + int pivotIndex = Partition(arr, low, high, comparison); + QuickSort(arr, low, pivotIndex - 1, comparison); + QuickSort(arr, pivotIndex + 1, high, comparison); + } + } + + private static int Partition(T[] arr, int low, int high, Comparison comparison) + { + T pivot = arr[high]; + int i = low - 1; + + for (int j = low; j < high; j++) + { + if (comparison(arr[j], pivot) < 0) + { + i++; + Swap(arr, i, j); + } + } + + Swap(arr, i + 1, high); + return i + 1; + } + + private static int Partition(List arr, int low, int high, Comparison comparison) + { + T pivot = arr[high]; + int i = low - 1; + + for (int j = low; j < high; j++) + { + if (comparison(arr[j], pivot) < 0) + { + i++; + Swap(arr, i, j); + } + } + + Swap(arr, i + 1, high); + return i + 1; + } + + private static void Swap(T[] arr, int i, int j) + { + T temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + + private static void Swap(List arr, int i, int j) + { + T temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } } \ 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 4883906..708609e 100644 --- a/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs +++ b/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs @@ -88,6 +88,17 @@ } /// + /// 当 Cell 参与排序时调用, 参数 other 为需要对比的另一个 Cell 对象
+ /// 函数返回 -1 表示当前 Cell 在 other 之前
+ /// 函数返回 0 表示当前 Cell 和 other 位置相同
+ /// 函数返回 1 表示当前 Cell 和 other 之后
+ ///
+ public virtual int OnSort(UiCell other) + { + return 0; + } + + /// /// 初始化数据 /// public void Init(UiGrid grid, TUiCellNode cellNode, int index) diff --git a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs index c31c27c..2d907e0 100644 --- a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs +++ b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs @@ -334,6 +334,48 @@ _cellList[index].Click(); } + + /// + /// 对所有已经启用的 Cell 进行排序操作, 排序时会调用 Cell 的 OnSort() 函数用于处理排序逻辑
+ /// 注意: 排序会影响 Cell 的 Index + ///
+ public void Sort() + { + if (_cellList.Count <= 0) + { + return; + } + //这里记录 SelectIndex 是让排序后 SelectIndex 指向的 Cell 不变 + var selectIndex = SelectIndex; + var selectCell = GetCell(selectIndex); + //执行排序操作 + Utils.QuickSort(_cellList, (a, b) => a.OnSort(b)); + if (selectIndex >= 0) + { + selectIndex = _cellList.FindIndex(cell => cell == selectCell); + } + //先移除所有节点 + for (var i = 0; i < _cellList.Count; i++) + { + _gridContainer.RemoveChild(_cellList[i].CellNode.GetUiInstance()); + } + + if (selectIndex >= 0) + { + _selectIndex = selectIndex; + } + //以新的顺序加入GridContainer + for (var i = 0; i < _cellList.Count; i++) + { + _gridContainer.AddChild(_cellList[i].CellNode.GetUiInstance()); + } + //刷新Index + for (var i = 0; i < _cellList.Count; i++) + { + var cell = _cellList[i]; + cell.SetIndex(i); + } + } /// /// 销毁当前网格组件 diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorCreateMark/attribute/ObjectAttribute.cs b/DungeonShooting_Godot/src/game/ui/mapEditorCreateMark/attribute/ObjectAttribute.cs index 1e749a1..0190aa5 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorCreateMark/attribute/ObjectAttribute.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorCreateMark/attribute/ObjectAttribute.cs @@ -81,7 +81,9 @@ _objectBar.L_HBoxContainer.L_ObjectIcon.Instance.Texture = ResourceManager.LoadTexture2D(o.Icon); //弹药 _currAmmonAttr.L_NumInput.Instance.MaxValue = weapon.AmmoCapacity; + _currAmmonAttr.L_NumInput.Instance.Value = weapon.AmmoCapacity; _residueAmmoAttr.L_NumInput.Instance.MaxValue = weapon.MaxAmmoCapacity; + _residueAmmoAttr.L_NumInput.Instance.Value = weapon.AmmoCapacity; } } diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs index 8105012..547d7f8 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorMarkCell.cs @@ -70,4 +70,21 @@ { CellNode.L_MarkButton.L_Select.Instance.Visible = false; } + + public override int OnSort(UiCell other) + { + if (!Data.MarkInfo.Preloading && other.Data.MarkInfo.Preloading) + { + return 0; + } + else if (Data.MarkInfo.Preloading) + { + return -1; + } + else if (other.Data.MarkInfo.Preloading) + { + return 1; + } + return (int)(Data.MarkInfo.DelayTime * 1000 - other.Data.MarkInfo.DelayTime * 1000); + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs index e14d4d1..e4d0dec 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/EditorWaveCell.cs @@ -30,6 +30,8 @@ array[i] = new MapEditorMapMarkPanel.MarkCellData(this, data[i]); } MarkGrid.SetDataList(array); + //执行排序操作 + MarkGrid.Sort(); } public override void OnRefreshIndex() @@ -60,6 +62,8 @@ //选中最后一个 //MarkGrid.SelectIndex MarkGrid.Click(MarkGrid.Count - 1); + //执行排序操作 + MarkGrid.Sort(); } /// diff --git a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs index a27c5e4..4e20c3b 100644 --- a/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/mapEditorMapMark/MapEditorMapMarkPanel.cs @@ -92,23 +92,24 @@ var selectPreinstall = GetSelectPreinstall(); if (selectPreinstall != null) { - for (var i = 0; i < selectPreinstall.WaveList.Count; i++) + var waveCells = _grid.GetAllCell(); + foreach (var waveCell in waveCells) { - var wave = selectPreinstall.WaveList[i]; - for (var j = 0; j < wave.Count; j++) + var tempWaveCell = (EditorWaveCell)waveCell; + var markCells = tempWaveCell.MarkGrid.GetAllCell(); + for (var i = 0; i < markCells.Length; i++) { - var tempMark = wave[j]; - if (tempMark == markInfo) + var tempMarkCell = (EditorMarkCell)markCells[i]; + if (tempMarkCell.Data.MarkInfo == markInfo) { - var waveCell = (EditorWaveCell)_grid.GetCell(i); - var cell = (EditorMarkCell)waveCell.MarkGrid.GetCell(j); //如果没有展开, 则调用展开方法 - if (!waveCell.IsExpand()) + if (!tempWaveCell.IsExpand()) { - waveCell.OnExpandOrClose(); + tempWaveCell.OnExpandOrClose(); } //选中物体 - cell.OnClick(); + tempMarkCell.OnClick(); + return; } } } @@ -397,6 +398,8 @@ dataMarkInfo.CloneFrom(mark); //刷新 Cell markCell.SetData(markCell.Data); + //执行排序 + markCell.Grid.Sort(); EventManager.EmitEvent(EventEnum.OnEditMark, dataMarkInfo); }); }