diff --git a/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs b/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs index f9746fc..a351b94 100644 --- a/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs +++ b/DungeonShooting_Godot/src/framework/ui/grid/UiCell.cs @@ -78,6 +78,7 @@ return; } + OnDestroy(); IsDestroyed = true; } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs index aee534c..ac6ed69 100644 --- a/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs +++ b/DungeonShooting_Godot/src/framework/ui/grid/UiGrid.cs @@ -19,7 +19,6 @@ private Type _cellType; private Stack> _cellPool = new Stack>(); private List> _cellList = new List>(); - private GridContainer _gridContainer; private Vector2I _cellOffset; @@ -42,6 +41,9 @@ } } + /// + /// 设置每个 Cell 之间的偏移量 + /// public void SetCellOffset(Vector2I offset) { if (_gridContainer != null) @@ -52,11 +54,17 @@ } } + /// + /// 获取每个 Cell 之间的偏移量 + /// public Vector2I GetCellOffset() { return _cellOffset; } + /// + /// 设置列数 + /// public void SetColumns(int columns) { _columns = columns; @@ -66,6 +74,9 @@ } } + /// + /// 获取列数 + /// public int GetColumns() { if (_gridContainer != null) @@ -76,6 +87,9 @@ return _columns; } + /// + /// 设置是否开启自动扩展列, 如果开启, 则组件会根据 GridContainer 组件所占用的宽度自动设置列数 + /// public void SetAutoColumns(bool flag) { if (flag != _autoColumns) @@ -97,11 +111,17 @@ } } + /// + /// 获取是否开启自动扩展列 + /// public bool GetAutoColumns() { return _autoColumns; } + /// + /// 设置当前组布局方式是否横向扩展, 如果为 true, 则 GridContainer 的宽度会撑满父物体 + /// public void SetHorizontalExpand(bool flag) { if (_gridContainer != null) @@ -116,7 +136,10 @@ } } } - + + /// + /// 获取当前组布局方式是否横向扩展 + /// public bool GetHorizontalExpand() { if (_gridContainer != null) @@ -126,9 +149,56 @@ return false; } - + /// - /// 设置当前网格组件中的所有数据 + /// 获取所有数据 + /// + public TData[] GetAllData() + { + var array = new TData[_cellList.Count]; + for (var i = 0; i < _cellList.Count; i++) + { + array[i] = _cellList[i].Data; + } + return array; + } + + /// + /// 获取所有 Cell 对象 + /// + public UiCell[] GetAllCell() + { + return _cellList.ToArray(); + } + + /// + /// 根据指定索引获取数据 + /// + public TData GetData(int index) + { + if (index < 0 || index >= _cellList.Count) + { + return default; + } + + return _cellList[index].Data; + } + + /// + /// 根据指定索引获取 Cell 对象 + /// + public UiCell GetCell(int index) + { + if (index < 0 || index >= _cellList.Count) + { + return default; + } + + return _cellList[index]; + } + + /// + /// 设置当前网格组件中的所有数据, 性能较低 /// public void SetDataList(TData[] array) { @@ -161,7 +231,6 @@ /// /// 添加单条数据 /// - /// public void Add(TData data) { var cell = GetCellInstance(); @@ -169,7 +238,22 @@ _gridContainer.AddChild(cell.CellNode.GetUiInstance()); cell.SetData(data); } + + /// + /// 修改指定索引的位置的 cell 数据 + /// + public void UpdateByIndex(int index, TData data) + { + var uiCell = GetCell(index); + if (uiCell != null) + { + uiCell.SetData(data); + } + } + /// + /// 销毁当前网格组件 + /// public void Destroy() { if (IsDestroyed) diff --git a/DungeonShooting_Godot/src/game/ui/bottomTips/BottomTipsPanel.cs b/DungeonShooting_Godot/src/game/ui/bottomTips/BottomTipsPanel.cs index 7eb02fc..d615eee 100644 --- a/DungeonShooting_Godot/src/game/ui/bottomTips/BottomTipsPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/bottomTips/BottomTipsPanel.cs @@ -49,8 +49,7 @@ /// public void SetIcon(Texture2D icon) { - L_Panel.L_MarginContainer.L_CenterContainer.L_HBoxContainer.L_AspectRatioContainer.L_TextureRect.Instance - .Texture = icon; + S_TextureRect.Instance.Texture = icon; } /// @@ -58,7 +57,7 @@ /// public void SetMessage(string message) { - L_Panel.L_MarginContainer.L_CenterContainer.L_HBoxContainer.L_Label.Instance.Text = message; + S_Label.Instance.Text = message; } private IEnumerator RunAnimation(Texture2D icon, string message) @@ -109,8 +108,7 @@ private static BottomTipsPanel _instance; public static void Init() { - _instance = UiManager.Open_BottomTips(); - _instance.HideUi(); + _instance = UiManager.CreateUi(UiManager.UiName.BottomTips); } ///