Skip to content

Commit 684a2d9

Browse files
committed
Cut/Copy/Paste of cells in music block
1 parent dc6367a commit 684a2d9

2 files changed

Lines changed: 202 additions & 35 deletions

File tree

Assets/Dev/Music/MusicEditor.cs

Lines changed: 112 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public class MusicEditor : MonoBehaviour {
7171
public GameObject CreateNewBlockInList;
7272
public GameObject CreateNewWaveInList;
7373

74+
public Text SelInfo;
75+
int selectionYStart = -1;
76+
int selectionYEnd = -1;
77+
int selectionYDir = 0;
78+
7479
MusicData music;
7580
float timeForNextBeat = 0;
7681
float autoRepeat = 0;
@@ -275,7 +280,6 @@ void PlayBlock() {
275280
PlayNote(block);
276281
}
277282

278-
279283
private void Update() {
280284
bool update = false;
281285
autoRepeat -= Time.deltaTime;
@@ -314,7 +318,7 @@ private void Update() {
314318
if (!recording) {
315319
if (status == MusicEditorStatus.BlockEdit) {
316320
if (Input.GetKey(KeyCode.UpArrow) && blines != null && row > 0 && autoRepeat < 0) { row--; update = true; autoRepeat = .1f; }
317-
if (Input.GetKey(KeyCode.DownArrow) && blines != null && row < blines.Count - 1 && autoRepeat < 0) { row++; update = true; autoRepeat = .1f; }
321+
if (Input.GetKey(KeyCode.DownArrow) && blines != null && row < currentBlock.len - 1 && autoRepeat < 0) { row++; update = true; autoRepeat = .1f; }
318322
}
319323
else if (status == MusicEditorStatus.Music) {
320324
if (Input.GetKey(KeyCode.UpArrow) && mlines != null && row > 0 && autoRepeat < 0) { row--; update = true; autoRepeat = .1f; }
@@ -441,54 +445,132 @@ private void Update() {
441445
}
442446

443447
// Ctrl+C, Ctrl+V, Ctrl+X, ShiftUp, ShiftDown
444-
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { // FIXME all the times?
445-
if (Input.GetKeyDown(KeyCode.DownArrow)) {
448+
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) {
446449

450+
if (Input.GetKeyDown(KeyCode.DownArrow)) {
451+
if (selectionYStart == -1 || row > selectionYEnd + 1 || row < selectionYStart - 1) { // No selection
452+
selectionYStart = row - 1;
453+
selectionYEnd = row;
454+
selectionYDir = 1;
455+
}
456+
else {
457+
if (selectionYDir == 1) selectionYEnd++;
458+
else if (selectionYDir == -1) selectionYStart++;
459+
if (selectionYEnd > currentBlock.len - 1) selectionYEnd = currentBlock.len - 1;
460+
if (selectionYEnd < selectionYStart) {
461+
selectionYStart = -1;
462+
selectionYEnd = -1;
463+
}
464+
}
465+
ShowSelection();
447466
}
448-
if (Input.GetKeyDown(KeyCode.UpArrow)) {
449467

468+
if (Input.GetKeyDown(KeyCode.UpArrow)) {
469+
if (selectionYStart == -1 || row > selectionYEnd + 1 || row < selectionYStart - 1) { // No selection
470+
selectionYStart = row;
471+
selectionYEnd = row + 1;
472+
selectionYDir = -1;
473+
}
474+
else {
475+
if (selectionYDir == 1) selectionYEnd--;
476+
else if (selectionYDir == -1) selectionYStart--;
477+
if (selectionYStart < 0) selectionYStart = 0;
478+
if (selectionYEnd < selectionYStart) {
479+
selectionYStart = -1;
480+
selectionYEnd = -1;
481+
}
482+
}
483+
ShowSelection();
450484
}
451485
}
452486
if (Input.GetKeyDown(KeyCode.C) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) { // Ctrl+C
453-
Selection.SetParent(blines[row].transform);
454-
Vector2 pos = Vector2.zero;
455-
pos.x = - (8 - col) * 148;
456-
pos.y = 1;
457-
SelectionBox.anchoredPosition = pos;
458-
SelectionBox.sizeDelta = new Vector2(142, 34);
459-
Selection.gameObject.SetActive(true);
460487
CopiedNotes.Clear();
461-
CopiedNotes.Add(currentBlock.chs[col][row]);
462-
Debug.Log(col);
488+
for (int i = selectionYStart; i <= selectionYEnd; i++) {
489+
CopiedNotes.Add(currentBlock.chs[col][i].Duplicate());
490+
}
491+
HideSelection();
492+
if (CopiedNotes.Count == 0)
493+
SelInfo.text = "";
494+
else if (CopiedNotes.Count == 1)
495+
SelInfo.text = CopiedNotes.Count + " cell copied";
496+
else
497+
SelInfo.text = CopiedNotes.Count + " cells copied";
498+
}
499+
if (Input.GetKeyDown(KeyCode.X) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) { // Ctrl+X
500+
CopiedNotes.Clear();
501+
for (int i = selectionYStart; i <= selectionYEnd; i++) {
502+
CopiedNotes.Add(currentBlock.chs[col][i].Duplicate());
503+
currentBlock.chs[col][i].Zero();
504+
blines[i].note[col].SetZeroValues(NoteTypeSprites);
505+
}
506+
HideSelection();
507+
if (CopiedNotes.Count == 0)
508+
SelInfo.text = "";
509+
else if (CopiedNotes.Count == 1)
510+
SelInfo.text = CopiedNotes.Count + " cell copied";
511+
else
512+
SelInfo.text = CopiedNotes.Count + " cells copied";
513+
}
514+
if (Input.GetKeyDown(KeyCode.V) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && CopiedNotes.Count > 0) { // Ctrl+V
515+
// If we have something, paste starting from the current position
516+
for (int i = 0; i < CopiedNotes.Count && row + i < currentBlock.len; i++) {
517+
currentBlock.chs[col][row + i].Set(CopiedNotes[i]);
518+
blines[row + i].note[col].SetValues(CopiedNotes[i], NoteTypeSprites, freqs, noteNames, waves);
519+
}
520+
HideSelection();
463521
}
464-
465522

466523
if (update) {
467-
// Scroll if needed
468-
ScrollViews(row);
524+
ScrollViews(row); // Scroll if needed
469525
SelectedCol.anchoredPosition = new Vector3(48 + col * 142, 30, 0);
470526
SelectRow(row);
471527
}
472528
}
473529

530+
void ShowSelection() {
531+
Selection.SetParent(ContentsBlock);
532+
Selection.SetAsLastSibling();
533+
Selection.gameObject.SetActive(true);
534+
if (selectionYStart == -1) {
535+
selectionYStart = row;
536+
selectionYEnd = row;
537+
}
538+
Vector2 pos = Vector2.zero;
539+
pos.x = 48 + col * 142;
540+
pos.y = -blines[currentBlock.len - 1].GetComponent<RectTransform>().anchoredPosition.y + 32.5f - 32 * selectionYStart;
541+
SelectionBox.anchoredPosition = pos;
542+
SelectionBox.sizeDelta = new Vector2(142, 34 * (selectionYEnd - selectionYStart + 1) * .95f);
543+
}
544+
545+
void HideSelection() {
546+
selectionYStart = -1;
547+
selectionYEnd = -1;
548+
Selection.gameObject.SetActive(false);
549+
}
550+
474551
void ScrollViews(int where) {
475552
Scrollbar bar;
553+
int len;
476554
if (status == MusicEditorStatus.Music) {
477555
bar = scrollMusic;
556+
len = mlines.Count - 14;
478557
}
479558
else if (status == MusicEditorStatus.BlockList) {
480559
bar = scrollBlocks;
560+
len = bllines.Count - 14;
481561
}
482562
else if (status == MusicEditorStatus.BlockEdit) {
483563
bar = scrollBlock;
564+
len = currentBlock.len - 14;
484565
}
485-
else if (status == MusicEditorStatus.Music) {
486-
bar = scrollBlock;
566+
else if (status == MusicEditorStatus.Waveforms) {
567+
bar = scrollWaves;
568+
len = wlines.Count - 14;
487569
}
488570
else return;
489571

490572
if (where < 13) bar.value = 1;
491-
else if (where > 48) bar.value = 0;
573+
else if (where > len) bar.value = 0;
492574
else bar.value = -0.0276f * where + 1.333333333333333f;
493575
}
494576

@@ -2191,6 +2273,16 @@ public class NoteData {
21912273
public int val;
21922274
public int len;
21932275

2276+
internal NoteData Duplicate() {
2277+
return new NoteData { type = this.type, val = this.val, len = this.len };
2278+
}
2279+
2280+
internal void Set(NoteData src) {
2281+
type = src.type;
2282+
val = src.val;
2283+
len = src.len;
2284+
}
2285+
21942286
internal void Set(NoteLine note) {
21952287
type = note.type;
21962288
val = note.val;
@@ -2237,17 +2329,11 @@ public Swipe() {
22372329

22382330
/*
22392331
2240-
Find a way to keep the selection highlight in the right place.
2241-
We cannot attach it to the line
2242-
2243-
add multiple selection of rows to enalbe cleanup and copy/paste
2244-
22452332
Define better the way the cells are done. So we can save meory and have cells with multiple infos.
22462333
22472334
[type] if 0 then next cell, used also as terminator (len=0 can be a terminator and in this case len will be set as 1)
22482335
[type=note] [freq] [len]
22492336
2250-
22512337
*/
22522338

22532339

Assets/Scenes/Developer.unity

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14635,7 +14635,7 @@ RectTransform:
1463514635
m_Children:
1463614636
- {fileID: 2029024915}
1463714637
m_Father: {fileID: 1090031088}
14638-
m_RootOrder: 23
14638+
m_RootOrder: 24
1463914639
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1464014640
m_AnchorMin: {x: 0, y: 1}
1464114641
m_AnchorMax: {x: 0, y: 1}
@@ -234748,7 +234748,7 @@ RectTransform:
234748234748
m_Children:
234749234749
- {fileID: 901957375}
234750234750
m_Father: {fileID: 1090031088}
234751-
m_RootOrder: 26
234751+
m_RootOrder: 27
234752234752
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
234753234753
m_AnchorMin: {x: 0, y: 0}
234754234754
m_AnchorMax: {x: 0, y: 0}
@@ -317663,6 +317663,85 @@ RectTransform:
317663317663
m_AnchoredPosition: {x: 72, y: -16}
317664317664
m_SizeDelta: {x: 64, y: 32}
317665317665
m_Pivot: {x: 0.5, y: 0.5}
317666+
--- !u!1 &676757394
317667+
GameObject:
317668+
m_ObjectHideFlags: 0
317669+
m_CorrespondingSourceObject: {fileID: 0}
317670+
m_PrefabInstance: {fileID: 0}
317671+
m_PrefabAsset: {fileID: 0}
317672+
serializedVersion: 6
317673+
m_Component:
317674+
- component: {fileID: 676757395}
317675+
- component: {fileID: 676757397}
317676+
- component: {fileID: 676757396}
317677+
m_Layer: 5
317678+
m_Name: SelInfo
317679+
m_TagString: Untagged
317680+
m_Icon: {fileID: 0}
317681+
m_NavMeshLayer: 0
317682+
m_StaticEditorFlags: 0
317683+
m_IsActive: 1
317684+
--- !u!224 &676757395
317685+
RectTransform:
317686+
m_ObjectHideFlags: 0
317687+
m_CorrespondingSourceObject: {fileID: 0}
317688+
m_PrefabInstance: {fileID: 0}
317689+
m_PrefabAsset: {fileID: 0}
317690+
m_GameObject: {fileID: 676757394}
317691+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
317692+
m_LocalPosition: {x: 0, y: 0, z: 0}
317693+
m_LocalScale: {x: 1.00008, y: 1.00008, z: 1.00008}
317694+
m_Children: []
317695+
m_Father: {fileID: 1090031088}
317696+
m_RootOrder: 22
317697+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
317698+
m_AnchorMin: {x: 0, y: 1}
317699+
m_AnchorMax: {x: 0, y: 1}
317700+
m_AnchoredPosition: {x: 1380, y: -668.7}
317701+
m_SizeDelta: {x: 256, y: 32}
317702+
m_Pivot: {x: 0.5, y: 0.5}
317703+
--- !u!114 &676757396
317704+
MonoBehaviour:
317705+
m_ObjectHideFlags: 0
317706+
m_CorrespondingSourceObject: {fileID: 0}
317707+
m_PrefabInstance: {fileID: 0}
317708+
m_PrefabAsset: {fileID: 0}
317709+
m_GameObject: {fileID: 676757394}
317710+
m_Enabled: 1
317711+
m_EditorHideFlags: 0
317712+
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
317713+
m_Name:
317714+
m_EditorClassIdentifier:
317715+
m_Material: {fileID: 0}
317716+
m_Color: {r: 0.9339623, g: 0.8904455, b: 0.47138664, a: 1}
317717+
m_RaycastTarget: 1
317718+
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
317719+
m_Maskable: 1
317720+
m_OnCullStateChanged:
317721+
m_PersistentCalls:
317722+
m_Calls: []
317723+
m_FontData:
317724+
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
317725+
m_FontSize: 28
317726+
m_FontStyle: 0
317727+
m_BestFit: 0
317728+
m_MinSize: 2
317729+
m_MaxSize: 72
317730+
m_Alignment: 0
317731+
m_AlignByGeometry: 0
317732+
m_RichText: 1
317733+
m_HorizontalOverflow: 0
317734+
m_VerticalOverflow: 0
317735+
m_LineSpacing: 1
317736+
m_Text:
317737+
--- !u!222 &676757397
317738+
CanvasRenderer:
317739+
m_ObjectHideFlags: 0
317740+
m_CorrespondingSourceObject: {fileID: 0}
317741+
m_PrefabInstance: {fileID: 0}
317742+
m_PrefabAsset: {fileID: 0}
317743+
m_GameObject: {fileID: 676757394}
317744+
m_CullTransparentMesh: 0
317666317745
--- !u!1 &676820720
317667317746
GameObject:
317668317747
m_ObjectHideFlags: 0
@@ -488090,7 +488169,7 @@ RectTransform:
488090488169
m_AnchorMin: {x: 0, y: 1}
488091488170
m_AnchorMax: {x: 0, y: 1}
488092488171
m_AnchoredPosition: {x: 0, y: 0}
488093-
m_SizeDelta: {x: 148, y: 34}
488172+
m_SizeDelta: {x: 0, y: 0}
488094488173
m_Pivot: {x: 0, y: 1}
488095488174
--- !u!222 &1042080748
488096488175
CanvasRenderer:
@@ -492657,7 +492736,7 @@ RectTransform:
492657492736
m_Children:
492658492737
- {fileID: 334493598}
492659492738
m_Father: {fileID: 1090031088}
492660-
m_RootOrder: 27
492739+
m_RootOrder: 28
492661492740
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
492662492741
m_AnchorMin: {x: 0, y: 0}
492663492742
m_AnchorMax: {x: 0, y: 0}
@@ -500108,15 +500187,15 @@ RectTransform:
500108500187
m_GameObject: {fileID: 1069424899}
500109500188
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
500110500189
m_LocalPosition: {x: 0, y: 0, z: 0}
500111-
m_LocalScale: {x: 1.00008, y: 1.00008, z: 1.00008}
500190+
m_LocalScale: {x: 1, y: 1, z: 1}
500112500191
m_Children: []
500113500192
m_Father: {fileID: 1042080746}
500114500193
m_RootOrder: 0
500115500194
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
500116500195
m_AnchorMin: {x: 0, y: 1}
500117500196
m_AnchorMax: {x: 0, y: 1}
500118500197
m_AnchoredPosition: {x: 0, y: 0}
500119-
m_SizeDelta: {x: 148, y: 34}
500198+
m_SizeDelta: {x: 148, y: 35}
500120500199
m_Pivot: {x: 0, y: 1}
500121500200
--- !u!114 &1069424901
500122500201
MonoBehaviour:
@@ -509478,6 +509557,7 @@ MonoBehaviour:
509478509557
CreateNewBlockInMusic: {fileID: 1506825376}
509479509558
CreateNewBlockInList: {fileID: 461643763}
509480509559
CreateNewWaveInList: {fileID: 1822673399}
509560+
SelInfo: {fileID: 676757396}
509481509561
BlockPickContainer: {fileID: 43615554}
509482509562
SelectBlockButton: {fileID: 1287057350}
509483509563
CellTypeImg: {fileID: 929350536}
@@ -509529,6 +509609,7 @@ RectTransform:
509529509609
- {fileID: 370415379}
509530509610
- {fileID: 873863369}
509531509611
- {fileID: 1044717777}
509612+
- {fileID: 676757395}
509532509613
- {fileID: 1114915730}
509533509614
- {fileID: 28515856}
509534509615
- {fileID: 1663554200}
@@ -520982,7 +521063,7 @@ RectTransform:
520982521063
- {fileID: 1607150919}
520983521064
- {fileID: 1000276489}
520984521065
m_Father: {fileID: 1090031088}
520985-
m_RootOrder: 22
521066+
m_RootOrder: 23
520986521067
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
520987521068
m_AnchorMin: {x: 0.5, y: 0.5}
520988521069
m_AnchorMax: {x: 0.5, y: 0.5}
@@ -617417,7 +617498,7 @@ RectTransform:
617417617498
m_Children:
617418617499
- {fileID: 521545384}
617419617500
m_Father: {fileID: 1090031088}
617420-
m_RootOrder: 25
617501+
m_RootOrder: 26
617421617502
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
617422617503
m_AnchorMin: {x: 1, y: 0}
617423617504
m_AnchorMax: {x: 1, y: 0}
@@ -776148,7 +776229,7 @@ RectTransform:
776148776229
m_Children:
776149776230
- {fileID: 43615554}
776150776231
m_Father: {fileID: 1090031088}
776151-
m_RootOrder: 24
776232+
m_RootOrder: 25
776152776233
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
776153776234
m_AnchorMin: {x: 1, y: 0}
776154776235
m_AnchorMax: {x: 1, y: 0}

0 commit comments

Comments
 (0)