Skip to content

Commit 3f706bb

Browse files
committed
feat: added copy and pas
1 parent cd006ee commit 3f706bb

File tree

5 files changed

+4864
-214
lines changed

5 files changed

+4864
-214
lines changed

Assets/Code/LevelEditor/BlockPopupWindow.cs

Lines changed: 105 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine;
44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67

78
namespace Code.LevelEditor
89
{
@@ -22,12 +23,15 @@ public class BlockPopupWindow : EditorWindow
2223

2324
private bool _isDragging = false;
2425
private Vector2 _dragOffset;
25-
26+
2627
private bool _showSelectionList = true;
2728
private string _searchFilter = "";
28-
29+
2930
private string _searchBlockFilter = "";
30-
31+
32+
private static Dictionary<Vector2Int, LevelCell> _copiedCells = new();
33+
private static Vector2Int _copiedSize;
34+
3135
public static void ShowPopup(
3236
Rect activatorRect,
3337
BlockLibrary library,
@@ -36,42 +40,46 @@ public static void ShowPopup(
3640
Action onClear,
3741
List<Vector2Int> currentSelection)
3842
{
39-
4043
if (Current != null)
4144
Current.Close();
42-
45+
4346
Current = CreateInstance<BlockPopupWindow>();
4447
Current._library = library;
4548
Current._onBlockSelected = onBlockSelected;
4649
Current._onRotationSelected = onRotationSelected;
4750
Current._onClear = onClear;
4851
Current._currentSelection = currentSelection;
49-
52+
5053
Current.ShowUtility();
5154
Current.position = activatorRect;
5255
}
5356

5457
private void OnGUI()
5558
{
5659
HandleWindowDrag();
57-
60+
5861
EditorGUILayout.BeginVertical("box");
59-
DrawTitle("🧱 Select Block");
62+
DrawTitle("\U0001f9f1 Select Block");
6063
DrawBlockList();
6164
EditorGUILayout.EndVertical();
62-
65+
6366
GUILayout.Space(10);
6467
EditorGUILayout.BeginVertical("box");
65-
DrawTitle("📦 Selected Cells");
68+
DrawTitle("\U0001f4e6 Selected Cells");
6669
DrawSelectedCellsList();
6770
EditorGUILayout.EndVertical();
68-
71+
6972
GUILayout.Space(10);
7073
EditorGUILayout.BeginVertical("box");
7174
DrawTitle("↻ Rotation");
7275
DrawRotationButtons();
7376
EditorGUILayout.EndVertical();
74-
77+
78+
GUILayout.Space(10);
79+
EditorGUILayout.BeginVertical("box");
80+
DrawCopyPasteButtons();
81+
EditorGUILayout.EndVertical();
82+
7583
GUILayout.Space(10);
7684
DrawClearButton();
7785
}
@@ -92,20 +100,16 @@ private void HandleWindowDrag()
92100
_isDragging = false;
93101
break;
94102
case EventType.MouseDrag when _isDragging:
95-
{
96103
var mousePos = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
97-
position = new Rect(mousePos.x - _dragOffset.x, mousePos.y - _dragOffset.y, position.width, position.height);
104+
position = new Rect(mousePos.x - _dragOffset.x, mousePos.y - _dragOffset.y, position.width,
105+
position.height);
98106
Event.current.Use();
99107
break;
100-
}
101108
}
102109
}
103-
104-
private void OnLostFocus()
105-
{
106-
Close();
107-
}
108-
110+
111+
private void OnLostFocus() => Close();
112+
109113
private void DrawTitle(string title)
110114
{
111115
GUIStyle style = new GUIStyle(EditorStyles.boldLabel)
@@ -153,10 +157,9 @@ private void DrawBlockList()
153157
GUILayout.EndVertical();
154158
}
155159

156-
157160
private void DrawSelectedCellsList()
158161
{
159-
_showSelectionList = EditorGUILayout.Foldout(_showSelectionList, "🟩 Selected Cells Details", true);
162+
_showSelectionList = EditorGUILayout.Foldout(_showSelectionList, "\U0001f7e9 Selected Cells Details", true);
160163
if (!_showSelectionList) return;
161164

162165
_searchFilter = EditorGUILayout.TextField("Search", _searchFilter);
@@ -192,7 +195,7 @@ private void DrawSelectedCellsList()
192195
EditorGUILayout.EndVertical();
193196
EditorGUILayout.EndScrollView();
194197
}
195-
198+
196199
private void DrawRotationButtons()
197200
{
198201
GUILayout.BeginHorizontal();
@@ -203,21 +206,96 @@ private void DrawRotationButtons()
203206
GUILayout.EndHorizontal();
204207
}
205208

209+
private void DrawCopyPasteButtons()
210+
{
211+
GUILayout.BeginHorizontal();
212+
213+
// КНОПКА КОПИРОВАНИЯ
214+
GUI.backgroundColor = new Color(0.8f, 0.8f, 1f);
215+
if (GUILayout.Button("📋 Copy", GUILayout.Height(25)))
216+
{
217+
_copiedCells.Clear();
218+
219+
if (_currentSelection != null && _currentSelection.Count > 0)
220+
{
221+
foreach (var pos in _currentSelection)
222+
{
223+
var cell = LevelEditorHelpers.TryGetCell(pos);
224+
if (cell != null)
225+
{
226+
_copiedCells[pos] = new LevelCell
227+
{
228+
Block = cell.Block,
229+
Rotation = cell.Rotation
230+
};
231+
}
232+
}
233+
234+
Debug.Log($"📋 Copied {_copiedCells.Count} cells");
235+
}
236+
else
237+
{
238+
Debug.LogWarning("❌ No cells selected to copy.");
239+
}
240+
}
241+
242+
// КНОПКА ВСТАВКИ
243+
GUI.backgroundColor = new Color(0.7f, 1f, 0.7f);
244+
if (GUILayout.Button("📌 Paste", GUILayout.Height(25)))
245+
{
246+
if (_copiedCells == null || _copiedCells.Count == 0)
247+
{
248+
Debug.LogWarning("❌ Nothing copied to paste.");
249+
}
250+
else if (_currentSelection == null || _currentSelection.Count == 0)
251+
{
252+
Debug.LogWarning("❌ No cells selected to paste into.");
253+
}
254+
else
255+
{
256+
var firstTarget = _currentSelection[0];
257+
var firstSource = _copiedCells.Keys.First();
258+
259+
int pasteCount = 0;
260+
261+
foreach (var sourcePair in _copiedCells)
262+
{
263+
var offset = sourcePair.Key - firstSource;
264+
var targetPos = firstTarget + offset;
265+
266+
var targetCell = LevelEditorHelpers.TryGetCell(targetPos);
267+
if (targetCell != null)
268+
{
269+
targetCell.Block = sourcePair.Value.Block;
270+
targetCell.Rotation = sourcePair.Value.Rotation;
271+
pasteCount++;
272+
}
273+
}
274+
275+
Debug.Log($"📌 Pasted {pasteCount} cells starting from [{firstTarget.x},{firstTarget.y}]");
276+
}
277+
}
278+
279+
GUI.backgroundColor = Color.white;
280+
GUILayout.EndHorizontal();
281+
}
282+
206283
private void DrawClearButton()
207284
{
208-
GUI.backgroundColor = new Color(1f, 0.3f, 0.3f);
285+
GUI.backgroundColor = new Color(1f, 0.3f, 0.3f);
209286
if (GUILayout.Button("🗑 Clear Block(s)", GUILayout.Height(30)))
210287
{
211288
_onClear?.Invoke();
212289
}
290+
213291
GUI.backgroundColor = Color.white;
214292
}
215293

216294
public static class LevelEditorHelpers
217295
{
218296
public static Func<Vector2Int, LevelCell> TryGetCell = _ => null;
219297
}
220-
298+
221299
private void OnDestroy()
222300
{
223301
_currentSelection?.Clear();
@@ -226,7 +304,7 @@ private void OnDestroy()
226304
LevelEditorHelpers.TryGetCell = _ => null;
227305

228306
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
229-
307+
230308
if (Current == this)
231309
Current = null;
232310
}

Assets/Resources/StaticData/LevelsData/LevelData_1.asset

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3416,8 +3416,8 @@ MonoBehaviour:
34163416
Entry: 7
34173417
Data: 126|Code.LevelEditor.LevelCell, Game
34183418
- Name: Block
3419-
Entry: 6
3420-
Data:
3419+
Entry: 10
3420+
Data: 3
34213421
- Name: Rotation
34223422
Entry: 7
34233423
Data: UnityEngine.Quaternion, UnityEngine.CoreModule
@@ -3443,8 +3443,8 @@ MonoBehaviour:
34433443
Entry: 7
34443444
Data: 127|Code.LevelEditor.LevelCell, Game
34453445
- Name: Block
3446-
Entry: 6
3447-
Data:
3446+
Entry: 10
3447+
Data: 3
34483448
- Name: Rotation
34493449
Entry: 7
34503450
Data: UnityEngine.Quaternion, UnityEngine.CoreModule

0 commit comments

Comments
 (0)