/// <summary> /// Creates melodic all note buttons for a note in a row. /// </summary> /// <param name="title">Base note button title.</param> /// <param name="row">Row index.</param> /// <param name="fileName">Note filename.</param> /// <param name="inScale">Is this note in the selected scale?</param> void MakeMelodicButtons(string title, int row, string fileName, bool inScale) { Color transparentWhite = new Color(1f, 1f, 1f, 0.5f); // Calculate y position of buttons in this row GameObject bg = _rowBackgrounds[row]; float y = bg.GetComponent <RectTransform>().anchoredPosition3D.y; // Create note text GameObject noteText = UIHelpers.MakeText(title); noteText.SetParent(_iconBar_tr); noteText.SetSideWidth(_squareSize.x); noteText.AnchorAtPoint(0.5f, 1f); noteText.SetPosition2D(0f, y); noteText.SetTextAlignment(TextAnchor.MiddleCenter); noteText.SetFontSize(30); _objects.Add(noteText); // Change text color depending on whether or not the note is in the scale if (inScale) { noteText.GetComponent <Text>().color = Color.white; bg.GetComponent <Image>().SetAlpha(bg.GetComponent <Image>().color.a * 3f); } else { noteText.GetComponent <Text>().color = transparentWhite; } // Make note buttons for (int i = 0; i < _numButtons; i++) { // Make reference copy int num = i; // Calculate x position of this button float x = _columnBackgrounds[num].GetComponent <RectTransform>().anchoredPosition3D.x; // Calculate scale float scale = ( i % 4 - 2 == 0 ? _halfNoteScale : // Half notes (i % 4 - 1 == 0 || i % 4 - 3 == 0 ? _quarterNoteScale : // Quarter notes 1f) // Whole notes ); // Check if note is already in riff bool noteExists = CurrentRiff.Lookup(fileName, num); // Get or create note Note note = noteExists ? CurrentRiff.GetNote(fileName, num) : new Note(fileName); Sprite melodicFilled = UIManager.Instance.FilledMelodicNoteIcon; Sprite melodicEmpty = UIManager.Instance.EmptyMelodicNoteIcon; // Make note button Sprite graphic = (CurrentRiff.Lookup(fileName, num) ? melodicFilled : melodicEmpty); GameObject button = UIHelpers.MakeButton(title + "_" + i, graphic); button.SetParent(_notePanel); button.SetSize2D(_buttonSize.x, _buttonSize.y); button.AnchorAtPoint(0f, 1f); button.SetPosition2D(x, y); // Add StopScrolling tag button.tag = "StopScrolling"; // Change scale based on beat RectTransform button_tr = button.GetComponent <RectTransform>(); button_tr.ResetScaleRot(); button_tr.localScale = new Vector3(scale, scale, scale); // Create volume slider GameObject volume = UIHelpers.MakeImage(title + "_volume"); RectTransform volume_tr = volume.GetComponent <RectTransform>(); volume_tr.SetParent(button_tr); volume_tr.sizeDelta = button_tr.sizeDelta; volume_tr.localScale = new Vector3( button_tr.localScale.x * _volumeScale, button_tr.localScale.y * 2f * _volumeScale, 1f ); volume_tr.AnchorAtPoint(0.5f, 0.5f); volume_tr.anchoredPosition3D = Vector3.zero; Image volume_img = volume.GetComponent <Image>(); volume_img.sprite = UIManager.Instance.MelodicVolumeIcon; volume_img.type = Image.Type.Filled; volume_img.fillAmount = note.Volume; // Setup volume slider NoteButton noteButton = button.AddComponent <NoteButton>(); noteButton.targetNote = note; noteButton.volumeImage = volume.GetComponent <Image>(); noteButton.UpdateButtonArt(); // Initially hide volume slider volume.SetActive(false); // Setup button button.GetComponent <Button>().onClick.AddListener(() => { if (!InputManager.Instance.IsDragging) { bool n = CurrentRiff.Toggle(note, num); if (n) { SuggestChords(num, row); } else { ClearSuggestions(); } //bt_sh.enabled = n; button.GetComponent <Image>().sprite = (n ? melodicFilled : melodicEmpty); } }); // Register button _objects.Add(button); _buttonGrid[num].Add(button); } }
/// <summary> /// Creates all percussio note buttons for a drum note. /// </summary> /// <param name="title">Base name of each button.</param> /// <param name="row">Row index.</param> /// <param name="soundName">Sound file to use.</param> /// <param name="iconGraphic">Icon to use.</param> void MakePercussionButtons(string title, int row, string fileName, Sprite iconGraphic) { // Calculate y position of buttons in this row float y = _rowBackgrounds[row].GetComponent <RectTransform>().anchoredPosition3D.y; // Make icon for note GameObject drumIcon = UIHelpers.MakeImage(title, iconGraphic); drumIcon.SetParent(_iconBar_tr); drumIcon.SetSideWidth(_squareSize.x); drumIcon.AnchorAtPoint(0.5f, 1.0f); drumIcon.GetComponent <RectTransform>().ResetScaleRot(); drumIcon.SetPosition2D(0f, y); drumIcon.AddComponent <Tooltippable>().Message = title; _objects.Add(drumIcon); // Make note buttons for (int i = 0; i < _numButtons; i++) { // Make a reference copy int num = i; // Calculate x position of this button float x = _columnBackgrounds[num].GetComponent <RectTransform>().anchoredPosition3D.x; // Calculate scale float scale = ( i % 4 - 2 == 0 ? _halfNoteScale : // Half notes (i % 4 - 1 == 0 || i % 4 - 3 == 0 ? _quarterNoteScale : // Quarter notes 1f) // Whole notes ); // Check if note is already in riff bool noteExists = CurrentRiff.Lookup(fileName, num); // Get or create note Note note = noteExists ? CurrentRiff.GetNote(fileName, num) : new Note(fileName); Sprite percussionEmpty = UIManager.Instance.EmptyPercussionNoteIcon; Sprite percussionFilled = UIManager.Instance.FilledPercussionNoteIcon; // Create note button Sprite graphic = (noteExists ? percussionFilled : percussionEmpty); GameObject button = UIHelpers.MakeButton(title + "_" + i, graphic); button.SetParent(_notePanel); button.SetSize2D(_buttonSize); button.AnchorAtPoint(0f, 1f); button.SetPosition2D(x, y); // Add StopScrolling tag button.tag = "StopScrolling"; // Change scale based on beat RectTransform button_tr = button.GetComponent <RectTransform>(); button_tr.ResetScaleRot(); button_tr.localScale = new Vector3(scale, scale, scale); // Create volume slider GameObject volume = UIHelpers.MakeImage(title + "_volume"); RectTransform volume_tr = volume.GetComponent <RectTransform>(); volume_tr.SetParent(button_tr); volume_tr.sizeDelta = _buttonSize; volume_tr.localScale = Vector3.one * _volumeScale; volume_tr.AnchorAtPoint(0.5f, 0.5f); volume_tr.anchoredPosition3D = Vector3.zero; Image volume_img = volume.GetComponent <Image>(); volume_img.sprite = UIManager.Instance.PercussionVolumeIcon; volume_img.type = Image.Type.Filled; volume_img.fillAmount = note.Volume; // Setup volume slider NoteButton noteButton = button.AddComponent <NoteButton>(); noteButton.targetNote = note; noteButton.volumeImage = volume.GetComponent <Image>(); noteButton.UpdateButtonArt(); // Initially hide volume slider volume.SetActive(false); // Add button functionality button.GetComponent <Button>().onClick.AddListener(() => { if (!InputManager.Instance.IsDragging) { bool n = CurrentRiff.Toggle(note, num); button.GetComponent <Image>().sprite = (n ? percussionFilled : percussionEmpty); } }); // Register button _objects.Add(button); _buttonGrid[i].Add(button); } }