Skip to content

Commit 92cc093

Browse files
committed
feat: added box in DrawExistingBlocks
1 parent d602451 commit 92cc093

File tree

1 file changed

+40
-22
lines changed

1 file changed

+40
-22
lines changed

Assets/Code/LevelEditor/BlockLibraryWindow.cs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ namespace Code.LevelEditor.Editor
1010
{
1111
public class BlockLibraryWindow : OdinEditorWindow
1212
{
13-
private enum SortMode { ByID, ByPrefabName, ByIconName }
13+
private enum SortMode
14+
{
15+
ByID,
16+
ByPrefabName,
17+
ByIconName
18+
}
1419

1520
[MenuItem("Tools/Block Library 🧱")]
1621
public static void ShowWindow()
@@ -19,29 +24,24 @@ public static void ShowWindow()
1924
window.minSize = new Vector2(400, 500);
2025
}
2126

22-
[BoxGroup("📦 Block Library", centerLabel: true)]
23-
[ReadOnly, ShowInInspector, HideLabel]
27+
[BoxGroup("📦 Block Library", centerLabel: true)] [ReadOnly, ShowInInspector, HideLabel]
2428
private BlockLibrary _blockLibrary;
2529

26-
[BoxGroup("🧱 Create Block", centerLabel: true)]
27-
[ShowInInspector, LabelText("Block ID")]
30+
[BoxGroup("🧱 Create Block", centerLabel: true)] [ShowInInspector, LabelText("Block ID")]
2831
private string _newBlockId = "";
29-
[BoxGroup("🧱 Create Block")]
30-
[ShowInInspector, LabelText("Icon")]
32+
[BoxGroup("🧱 Create Block")] [ShowInInspector, LabelText("Icon")]
3133
private Sprite _newBlockSprite;
32-
[BoxGroup("🧱 Create Block")]
33-
[ShowInInspector, LabelText("Prefab")]
34+
[BoxGroup("🧱 Create Block")] [ShowInInspector, LabelText("Prefab")]
3435
private GameObject _newBlockPrefab;
35-
36-
[BoxGroup("🔍 Search & Sort", centerLabel: true)]
37-
[ShowInInspector, LabelText("Filter")]
36+
37+
[BoxGroup("🔍 Search & Sort", centerLabel: true)] [ShowInInspector, LabelText("Filter")]
3838
private string _searchFilter = "";
3939
[BoxGroup("🔍 Search & Sort")]
4040
[HorizontalGroup("🔍 Search & Sort/SortRow")]
4141
[EnumToggleButtons, HideLabel, PropertyOrder(0)]
4242
[SerializeField]
4343
private SortMode _sortMode = SortMode.ByID;
44-
44+
4545
private BlockDataEditor _selectedBlock;
4646
private BlockEditorDTO _blockDraft = new BlockEditorDTO();
4747
private bool _sortAscending = true;
@@ -64,6 +64,7 @@ protected override void DrawEditor(int index)
6464
{
6565
CreateLibrary();
6666
}
67+
6768
return;
6869
}
6970

@@ -72,7 +73,7 @@ protected override void DrawEditor(int index)
7273
DrawExistingBlocks();
7374
GUILayout.FlexibleSpace();
7475
EditorGUILayout.EndScrollView();
75-
76+
7677
GUILayout.Space(10);
7778
DrawSelectedBlockSection();
7879
}
@@ -121,7 +122,8 @@ private void DrawSelectedBlockSection()
121122
else
122123
{
123124
EditorGUILayout.BeginHorizontal();
124-
GUILayout.Label(_selectedBlock.Icon != null ? _selectedBlock.Icon.texture : Texture2D.grayTexture, GUILayout.Width(32), GUILayout.Height(32));
125+
GUILayout.Label(_selectedBlock.Icon != null ? _selectedBlock.Icon.texture : Texture2D.grayTexture,
126+
GUILayout.Width(32), GUILayout.Height(32));
125127
GUILayout.Label(_selectedBlock.ID, SirenixGUIStyles.BoldLabel);
126128
GUILayout.FlexibleSpace();
127129
EditorGUILayout.EndHorizontal();
@@ -131,7 +133,8 @@ private void DrawSelectedBlockSection()
131133
// Поля редактирования DTO
132134
_blockDraft.Id = EditorGUILayout.TextField("ID", _blockDraft.Id);
133135
_blockDraft.Icon = (Sprite)EditorGUILayout.ObjectField("Icon", _blockDraft.Icon, typeof(Sprite), false);
134-
_blockDraft.Prefab = (GameObject)EditorGUILayout.ObjectField("Prefab", _blockDraft.Prefab, typeof(GameObject), false);
136+
_blockDraft.Prefab =
137+
(GameObject)EditorGUILayout.ObjectField("Prefab", _blockDraft.Prefab, typeof(GameObject), false);
135138

136139
GUILayout.Space(4);
137140

@@ -148,12 +151,18 @@ private void DrawSelectedBlockSection()
148151
[Button("@_sortAscending ? \"\" : \"\"", ButtonSizes.Medium)]
149152
[PropertyOrder(1)]
150153
private void ToggleSortDirection() => _sortAscending = !_sortAscending;
151-
154+
152155
private void DrawExistingBlocks()
153156
{
157+
SirenixEditorGUI.BeginBox();
158+
SirenixEditorGUI.BeginBoxHeader();
159+
SirenixEditorGUI.Title("📦 Existing Blocks", null, TextAlignment.Center, true);
160+
SirenixEditorGUI.EndBoxHeader();
161+
154162
if (_blockLibrary.AllBlocks == null || _blockLibrary.AllBlocks.Count == 0)
155163
{
156164
SirenixEditorGUI.InfoMessageBox("No blocks found.");
165+
SirenixEditorGUI.EndBox(); // не забываем закрыть
157166
return;
158167
}
159168

@@ -169,7 +178,8 @@ private void DrawExistingBlocks()
169178
return _sortMode switch
170179
{
171180
SortMode.ByID => string.Compare(a.ID, b.ID, StringComparison.OrdinalIgnoreCase),
172-
SortMode.ByIconName => string.Compare(a.Icon?.name ?? "", b.Icon?.name ?? "", StringComparison.OrdinalIgnoreCase),
181+
SortMode.ByIconName => string.Compare(a.Icon?.name ?? "", b.Icon?.name ?? "",
182+
StringComparison.OrdinalIgnoreCase),
173183
SortMode.ByPrefabName => SafeCompare(a.Prefab, b.Prefab),
174184
_ => 0
175185
};
@@ -189,15 +199,20 @@ private void DrawExistingBlocks()
189199

190200
GUILayout.BeginHorizontal();
191201

192-
GUILayout.Label(block.Icon != null ? block.Icon.texture : Texture2D.grayTexture, GUILayout.Width(32), GUILayout.Height(32));
202+
GUILayout.Label(block.Icon != null ? block.Icon.texture : Texture2D.grayTexture, GUILayout.Width(32),
203+
GUILayout.Height(32));
193204
GUILayout.FlexibleSpace();
194205

195206
if (GUILayout.Button("Select", GUILayout.Width(60)))
207+
{
196208
_selectedBlock = block;
209+
_blockDraft.LoadFrom(block);
210+
}
197211

198212
if (GUILayout.Button("X", GUILayout.Width(20)))
199213
{
200-
if (EditorUtility.DisplayDialog("Delete Block", $"Are you sure you want to delete '{block.ID}'?", "Yes", "No"))
214+
if (EditorUtility.DisplayDialog("Delete Block", $"Are you sure you want to delete '{block.ID}'?",
215+
"Yes", "No"))
201216
{
202217
var path = AssetDatabase.GetAssetPath(block);
203218
_blockLibrary.AllBlocks.Remove(block);
@@ -212,6 +227,8 @@ private void DrawExistingBlocks()
212227
GUILayout.EndHorizontal();
213228
SirenixEditorGUI.EndBox();
214229
}
230+
231+
SirenixEditorGUI.EndBox();
215232
}
216233

217234
[BoxGroup("🧱 Create Block")]
@@ -246,15 +263,16 @@ private int SafeCompare(UnityEngine.Object a, UnityEngine.Object b)
246263
{
247264
try
248265
{
249-
return string.Compare(a?.name ?? string.Empty, b?.name ?? string.Empty, StringComparison.OrdinalIgnoreCase);
266+
return string.Compare(a?.name ?? string.Empty, b?.name ?? string.Empty,
267+
StringComparison.OrdinalIgnoreCase);
250268
}
251269
catch
252270
{
253271
return 0;
254272
}
255273
}
256274
}
257-
275+
258276
[Serializable]
259277
public class BlockEditorDTO
260278
{

0 commit comments

Comments
 (0)