Example #1
0
        /// <summary>
        /// Refreshes the load prompt based on the given mode.
        /// </summary>
        public void Refresh(Mode mode)
        {
            // Clear old buttons
            foreach (GameObject fileButton in _fileButtons)
            {
                Destroy(fileButton);
            }

            _fileButtons.Clear();

            _loadMode = mode;

            // Get list of files in save location
            List <string> files = new List <string>();

            switch (mode)
            {
            case LoadPrompt.Mode.Project:
                files.AddRange(Directory.GetFiles(GameManager.Instance.ProjectSavePath, "*" + SaveLoad.PROJECT_SAVE_EXT).ToList <string>());
                break;

            case LoadPrompt.Mode.Song:
                files.AddRange(Directory.GetFiles(GameManager.Instance.SongSavePath, "*" + SaveLoad.SONG_SAVE_EXT).ToList <string>());
                break;
            }
            for (int i = 0; i < files.Count; i++)
            {
                string path     = files[i];
                string filename = Path.GetFileNameWithoutExtension(files[i]);

                GameObject button = UIHelpers.MakeButton(filename);

                RectTransform button_tr = button.GetComponent <RectTransform>();
                button_tr.SetParent(_fileList);
                float width = ((RectTransform)button_tr.parent.parent).rect.width;
                button_tr.sizeDelta = new Vector2(width, _ButtonSize.y);
                button_tr.AnchorAtPoint(0f, 1f);
                button_tr.anchoredPosition3D = new Vector3(
                    HORIZONTAL_PADDING + button_tr.sizeDelta.x / 2f,
                    ((i == 0 ? 0f : VERTICAL_PADDING) + button_tr.sizeDelta.y) * -(float)(i + 1),
                    0f
                    );
                button_tr.ResetScaleRot();

                Image button_img = button.GetComponent <Image>();
                button_img.sprite = UIManager.Instance.FillSprite;
                button_img.color  = new Color(1f, 1f, 1f, 0f);

                GameObject    text    = UIHelpers.MakeText(filename + "_Text");
                RectTransform text_tr = text.GetComponent <RectTransform>();
                text_tr.SetParent(button.transform);
                text_tr.sizeDelta = ((RectTransform)text_tr.parent).sizeDelta;
                text_tr.AnchorAtPoint(0.5f, 0.5f);
                text_tr.anchoredPosition3D = Vector3.zero;
                text_tr.ResetScaleRot();

                Text text_text = text.GetComponent <Text>();
                text_text.text      = filename;
                text_text.fontSize  = 36;
                text_text.color     = Color.white;
                text_text.font      = UIManager.Instance.Font;
                text_text.alignment = TextAnchor.MiddleLeft;

                Fadeable text_fade = text.AddComponent <Fadeable>();
                text_fade.StartFaded = false;

                button.GetComponent <Button>().onClick.AddListener(() => {
                    UIManager.Instance.PlayMenuClickSound();
                    ResetButtons();
                    _selectedPath = path;
                    _loadButton.GetComponent <Button>().interactable = true;
                    _loadButtonText.color = _loadButton.GetComponent <Button>().colors.normalColor;
                    button.GetComponent <Image>().color = new Color(1f, 1f, 1f, 0.5f);
                });

                _fileButtons.Add(button);

                /*GameObject highlight = UIHelpers.MakeImage(filename + "_Highlight");
                 * RectTransform highlight_tr = highlight.GetComponent<RectTransform>();
                 * highlight_tr.SetParent(button_tr);
                 * highlight_tr.sizeDelta = ((RectTransform)text_tr.parent).sizeDelta;
                 * highlight_tr.AnchorAtPoint(0.5f, 0.5f);
                 * highlight_tr.anchoredPosition3D = Vector3.zero;
                 * highlight_tr.ResetScaleRot();
                 * highlight.GetComponent<Image>().color = new Color(1f, 1f, 1f, 0.5f);
                 *
                 * ShowHide sh = button.ShowHide();
                 * sh.objects = new List<GameObject>();
                 * sh.objects.Add(highlight);
                 *
                 * fileButtons.Add(highlight);
                 * highlight.SetActive(false);*/
            }

            // Update size of panel to fit all files
            _fileList.sizeDelta = new Vector2(_FileListSize.x, (float)(_fileButtons.Count + 1) * (VERTICAL_PADDING + _ButtonSize.y));

            // Update header
            _header.text = mode == Mode.Project ? "Load Project" : "Load Song";
        }
Example #2
0
        /// <summary>
        /// Refreshes the entire playlist menu.
        /// </summary>
        public void Refresh()
        {
            // Clear all listings and buttons
            foreach (GameObject listing in _listings)
            {
                Destroy(listing);
            }
            _listings.Clear();


            // Resize browser panel
            int numSongs = MusicManager.Instance.CurrentProject.Songs.Count;

            _playlistTR.sizeDelta = new Vector2(
                _playlistTR.sizeDelta.x,
                _verticalPadding * (numSongs + 2) + _buttonHeight * (numSongs + 1)
                );

            // Create song listings
            for (int i = 0; i < numSongs; i++)
            {
                int  num  = i;
                Song song = MusicManager.Instance.CurrentProject.Songs[num];

                // Create listing for song
                GameObject listing = UIHelpers.MakeButton(song.Name);
                _listings.Add(listing);

                RectTransform listing_tr = listing.GetComponent <RectTransform>();
                listing_tr.SetParent(_playlistTR);
                listing_tr.sizeDelta = new Vector2(_playlistTR.rect.width, _buttonHeight);
                listing_tr.AnchorAtPoint(0f, 1f);
                listing_tr.anchoredPosition3D = new Vector3(
                    _horizontalPadding + listing_tr.sizeDelta.x / 2f,
                    -_verticalPadding - listing_tr.sizeDelta.y / 2f - (_verticalPadding + listing_tr.sizeDelta.y) * (float)i,
                    0f
                    );
                listing_tr.ResetScaleRot();

                Image listing_img = listing.GetComponent <Image>();
                listing_img.sprite = UIManager.Instance.FillSprite;
                listing_img.color  = new Color(0f, 0f, 1f, 0f);

                // Create background for listing
                GameObject    listing_bg    = UIHelpers.MakeImage(song.Name + "_bg");
                RectTransform listing_bg_tr = listing_bg.GetComponent <RectTransform>();
                listing_bg_tr.SetParent(_playlistTR);
                listing_bg_tr.sizeDelta = new Vector2(listing_tr.sizeDelta.x - 2f * _horizontalPadding, listing_tr.sizeDelta.y);
                listing_bg_tr.AnchorAtPoint(0f, 1f);
                listing_bg_tr.anchoredPosition3D = new Vector3(
                    _horizontalPadding + listing_tr.sizeDelta.x / 2f,
                    listing_tr.anchoredPosition3D.y,
                    0f
                    );
                listing_bg_tr.SetSiblingIndex(-1);
                listing_bg_tr.ResetScaleRot();

                Image listing_bg_img = listing_bg.GetComponent <Image>();
                listing_bg_img.raycastTarget = false;
                listing_bg_img.sprite        = UIManager.Instance.FillSprite;
                listing_bg_img.color         = new Color(1f, 1f, 1f, 0.0f);

                Fadeable listing_bg_fade = listing_bg.AddComponent <Fadeable>();
                listing_bg_fade.BlockRaycastsWhileFaded = false;
                listing_bg_fade.StartFaded = true;

                Highlighted listing_highlight = listing.AddComponent <Highlighted>();
                listing_highlight.HighlightObject = listing_bg_fade;

                _listings.Add(listing_bg);

                // Create song text
                GameObject listing_text = UIHelpers.MakeText(song.Name + "_text");

                RectTransform listing_text_tr = listing_text.GetComponent <RectTransform>();
                listing_text_tr.SetParent(listing_tr);
                listing_text_tr.sizeDelta = listing_tr.sizeDelta;
                listing_text_tr.AnchorAtPoint(0.5f, 0.5f);
                listing_text_tr.anchoredPosition3D = new Vector3(_horizontalPadding * 1.5f + listing_tr.sizeDelta.y, 0f, 0f);
                listing_text_tr.ResetScaleRot();

                Text listing_text_txt = listing_text.GetComponent <Text>();
                listing_text_txt.text      = (i + 1).ToString() + ". " + song.Name;
                listing_text_txt.fontSize  = _fontSize;
                listing_text_txt.color     = Color.black;
                listing_text_txt.font      = UIManager.Instance.HandwrittenFont;
                listing_text_txt.alignment = TextAnchor.MiddleLeft;


                // Create remove song button
                GameObject listing_remove = UIHelpers.MakeButton(song.Name + "_remove");

                RectTransform listing_remove_tr = listing_remove.GetComponent <RectTransform>();
                listing_remove_tr.SetParent(listing_tr);
                listing_remove_tr.sizeDelta = new Vector2(_iconScale * listing_tr.sizeDelta.y, _iconScale * listing_tr.sizeDelta.y);
                listing_remove_tr.AnchorAtPoint(1f, 0.5f);
                listing_remove_tr.anchoredPosition3D = new Vector3(-_horizontalPadding - listing_remove_tr.sizeDelta.x, 0f, 0f);
                listing_remove_tr.ResetScaleRot();

                Image listing_remove_img = listing_remove.GetComponent <Image>();
                listing_remove_img.color  = Color.black;
                listing_remove_img.sprite = UIManager.Instance.RemoveIcon;

                Button listing_remove_button = listing_remove.GetComponent <Button>();
                listing_remove_button.onClick.AddListener(() => {
                    UIManager.Instance.PlayMenuClickSound();
                    MusicManager.Instance.RemoveSong(num);
                    Refresh();
                });

                listing_remove.AddComponent <Tooltippable>().Message = "Remove \"" + song.Name + "\".";

                // Create edit song button
                GameObject listing_edit = UIHelpers.MakeButton(song.Name + "_edit");

                RectTransform listing_edit_tr = listing_edit.GetComponent <RectTransform>();
                listing_edit_tr.SetParent(listing_tr);
                listing_edit_tr.sizeDelta = new Vector2(_iconScale * listing_tr.sizeDelta.y, _iconScale * listing_tr.sizeDelta.y);
                listing_edit_tr.AnchorAtPoint(1f, 0.5f);
                listing_edit_tr.anchoredPosition3D = new Vector3(
                    listing_remove_tr.anchoredPosition3D.x - _horizontalPadding - listing_edit_tr.sizeDelta.x,
                    0f,
                    0f
                    );
                listing_edit_tr.ResetScaleRot();

                Image listing_edit_img = listing_edit.GetComponent <Image>();
                listing_edit_img.color  = Color.black;
                listing_edit_img.sprite = UIManager.Instance.EditIcon;

                Button listing_edit_button = listing_edit.GetComponent <Button>();
                listing_edit_button.onClick.AddListener(() => {
                    UIManager.Instance.PlayMenuClickSound();
                    MusicManager.Instance.CurrentSong = song;
                    if (song.Key == Key.None || song.Scale == -1)
                    {
                        UIManager.Instance.GoToKeySelectMenu();
                    }
                    else
                    {
                        UIManager.Instance.GoToSongArrangeMenu();
                    }
                });

                listing_edit.AddComponent <Tooltippable>().Message = "Edit \"" + song.Name + "\".";

                // Create move song up button if not at top
                if (num > 0)
                {
                    Song       prevSong   = MusicManager.Instance.CurrentProject.Songs[i - 1];
                    GameObject listing_up = UIHelpers.MakeButton(song.Name + "_up");

                    RectTransform listing_up_tr = listing_up.GetComponent <RectTransform>();
                    listing_up_tr.SetParent(listing_tr);
                    listing_up_tr.sizeDelta = new Vector2(listing_tr.sizeDelta.y * _iconScale / 2f, listing_tr.sizeDelta.y * _iconScale / 2f);
                    listing_up_tr.ResetScaleRot();
                    listing_up_tr.localRotation = Quaternion.Euler(0f, 0f, 90f);
                    listing_up_tr.AnchorAtPoint(0f, 0.5f);
                    listing_up_tr.anchoredPosition3D = new Vector3(
                        _horizontalPadding + listing_up_tr.sizeDelta.x / 2f,
                        listing_up_tr.sizeDelta.y / 2f + _verticalPadding / 2f,
                        0f
                        );

                    Image listing_up_img = listing_up.GetComponent <Image>();
                    listing_up_img.color  = Color.black;
                    listing_up_img.sprite = UIManager.Instance.ArrowIcon;

                    Button listing_up_button = listing_up.GetComponent <Button>();
                    listing_up_button.onClick.AddListener(() => {
                        UIManager.Instance.PlayMenuClickSound();
                        Song temp = song;
                        MusicManager.Instance.CurrentProject.Songs[num]     = prevSong;
                        MusicManager.Instance.CurrentProject.Songs[num - 1] = temp;
                        Refresh();
                    });
                }

                // Create move song down button if not at bottom
                if (num < MusicManager.Instance.CurrentProject.Songs.Count - 1)
                {
                    Song       nextSong     = MusicManager.Instance.CurrentProject.Songs[i + 1];
                    GameObject listing_down = UIHelpers.MakeButton(song.Name + "_down");

                    RectTransform listing_down_tr = listing_down.GetComponent <RectTransform>();
                    listing_down_tr.SetParent(listing_tr);
                    listing_down_tr.sizeDelta = new Vector2(listing_tr.sizeDelta.y * _iconScale / 2f, listing_tr.sizeDelta.y * _iconScale / 2f);
                    listing_down_tr.ResetScaleRot();
                    listing_down_tr.localRotation = Quaternion.Euler(0f, 0f, -90f);
                    listing_down_tr.AnchorAtPoint(0f, 0.5f);
                    listing_down_tr.anchoredPosition3D = new Vector3(
                        _horizontalPadding + listing_down_tr.sizeDelta.x / 2f,
                        -listing_down_tr.sizeDelta.y / 2f - _verticalPadding / 2f,
                        0f
                        );

                    Image listing_down_img = listing_down.GetComponent <Image>();
                    listing_down_img.color  = Color.black;
                    listing_down_img.sprite = UIManager.Instance.ArrowIcon;

                    Button listing_down_button = listing_down.GetComponent <Button>();
                    listing_down_button.onClick.AddListener(() => {
                        UIManager.Instance.PlayMenuClickSound();
                        Song temp = song;
                        MusicManager.Instance.CurrentProject.Songs[num]     = nextSong;
                        MusicManager.Instance.CurrentProject.Songs[num + 1] = temp;
                        Refresh();
                    });
                }
            }

            // Create new song button
            GameObject newSongButton = UIHelpers.MakeButton("New Song");

            _listings.Add(newSongButton);

            RectTransform newSongButton_tr = newSongButton.GetComponent <RectTransform>();

            newSongButton_tr.SetParent(_playlistTR);
            newSongButton_tr.AnchorAtPoint(0.15f, 1f);
            newSongButton_tr.sizeDelta = new Vector2(_buttonHeight * _iconScale, _buttonHeight * _iconScale);


            newSongButton_tr.anchoredPosition3D = new Vector3(
                //horizontalPadding + newSongButton_tr.sizeDelta.x/2f,
                0f,
                -_verticalPadding - 0.5f * _buttonHeight - (_verticalPadding + _buttonHeight) * (float)(numSongs),
                0f
                );
            newSongButton_tr.ResetScaleRot();

            Image newSong_img = newSongButton.GetComponent <Image>();

            newSong_img.sprite = UIManager.Instance.AddIcon;
            newSong_img.color  = Color.black;

            newSongButton.GetComponent <Button>().onClick.AddListener(delegate {
                UIManager.Instance.PlayMenuClickSound();
                MusicManager.Instance.NewSong();
                UIManager.Instance.GoToKeySelectMenu();
            });

            GameObject newSong_text = UIHelpers.MakeText("New Song_text");

            RectTransform newSong_text_tr = newSong_text.GetComponent <RectTransform>();

            newSong_text_tr.SetParent(newSongButton_tr);
            newSong_text_tr.sizeDelta = new Vector2(_playlistTR.rect.width / 2f - 2f * _horizontalPadding, newSongButton_tr.sizeDelta.y);
            newSong_text_tr.AnchorAtPoint(0f, 0.5f);
            newSong_text_tr.anchoredPosition3D = new Vector3(
                newSong_text_tr.sizeDelta.x / 2f + _horizontalPadding + newSongButton_tr.sizeDelta.x,
                0f,
                0f
                );
            newSong_text_tr.ResetScaleRot();

            Text newSong_text_txt = newSong_text.GetComponent <Text>();

            newSong_text_txt.text      = "New Song...";
            newSong_text_txt.fontSize  = (int)(_fontSize * _iconScale);
            newSong_text_txt.color     = Color.black;
            newSong_text_txt.font      = UIManager.Instance.HandwrittenFont;
            newSong_text_txt.alignment = TextAnchor.MiddleLeft;

            GameObject newSongButton_highlight = UIHelpers.MakeImage("Highlight (New Song Button)");

            _listings.Add(newSongButton_highlight);

            RectTransform newSongButton_highlight_tr = newSongButton_highlight.GetComponent <RectTransform>();

            newSongButton_highlight_tr.SetParent(newSongButton_tr);
            newSongButton_highlight_tr.sizeDelta = new Vector2(_playlistTR.rect.width * 0.5f - 2f * _horizontalPadding, newSongButton_tr.sizeDelta.y * 1.5f);
            newSongButton_highlight_tr.AnchorAtPoint(0f, 0.5f);
            newSongButton_highlight_tr.anchoredPosition3D = new Vector3(newSongButton_highlight_tr.sizeDelta.x / 3f, 0f, 0f);
            newSongButton_highlight_tr.ResetScaleRot();

            newSongButton_highlight_tr.SetSiblingIndex(-1);

            Image newSongButton_highlight_img = newSongButton_highlight.GetComponent <Image>();

            newSongButton_highlight_img.raycastTarget = false;
            newSongButton_highlight_img.sprite        = UIManager.Instance.ScribbleIcon;
            newSongButton_highlight_img.color         = new Color(1f, 1f, 1f, 1f);

            Fadeable newSongButton_highlight_fade = newSongButton_highlight.AddComponent <Fadeable>();

            newSongButton_highlight_fade.StartFaded = true;
            newSongButton_highlight_fade.BlockRaycastsWhileFaded = false;
            newSongButton_highlight_fade.FadeSpeed = 0.1f;

            Highlighted newSongButton_highlighted = newSongButton.AddComponent <Highlighted>();

            newSongButton_highlighted.HighlightObject = newSongButton_highlight_fade;

            // Create load song button
            GameObject loadSongButton = UIHelpers.MakeButton("Load Song Button (Playlist Browser)");

            _listings.Add(loadSongButton);

            RectTransform loadSongButton_tr = loadSongButton.GetComponent <RectTransform>();

            loadSongButton_tr.SetParent(_playlistTR);
            loadSongButton_tr.sizeDelta = new Vector2(_buttonHeight * _iconScale, _buttonHeight * _iconScale);
            loadSongButton_tr.AnchorAtPoint(0.6f, 1f);
            loadSongButton_tr.anchoredPosition3D = new Vector3(
                //horizontalPadding + loadSongButton_tr.sizeDelta.x / 2f,
                0f,
                -_verticalPadding - 0.5f * _buttonHeight - (_verticalPadding + _buttonHeight) * (float)(numSongs),
                0f
                );
            loadSongButton_tr.ResetScaleRot();

            Image loadSongButton_img = loadSongButton.GetComponent <Image>();

            loadSongButton_img.sprite = UIManager.Instance.LoadIcon;
            loadSongButton_img.color  = Color.black;

            loadSongButton.GetComponent <Button>().onClick.AddListener(delegate {
                UIManager.Instance.PlayMenuClickSound();
                GameManager.Instance.ShowLoadPromptForSongs();
            });

            GameObject loadSongButton_text = UIHelpers.MakeText("Load New Song_text");

            RectTransform loadSongButton_text_tr = loadSongButton_text.GetComponent <RectTransform>();

            loadSongButton_text_tr.SetParent(loadSongButton_tr);
            loadSongButton_text_tr.sizeDelta = new Vector2(_playlistTR.rect.width / 2f - 2f * _horizontalPadding, loadSongButton_tr.sizeDelta.y);
            loadSongButton_text_tr.AnchorAtPoint(0f, 0.5f);
            loadSongButton_text_tr.anchoredPosition3D = new Vector3(
                loadSongButton_text_tr.sizeDelta.x / 2f + _horizontalPadding + loadSongButton_tr.sizeDelta.x,
                0f,
                0f
                );
            loadSongButton_text_tr.ResetScaleRot();

            Text loadSongButton_text_txt = loadSongButton_text.GetComponent <Text>();

            loadSongButton_text_txt.text      = "Load Song...";
            loadSongButton_text_txt.fontSize  = (int)(_fontSize * _iconScale);
            loadSongButton_text_txt.color     = Color.black;
            loadSongButton_text_txt.font      = UIManager.Instance.HandwrittenFont;
            loadSongButton_text_txt.alignment = TextAnchor.MiddleLeft;

            GameObject loadSongButton_highlight = UIHelpers.MakeImage("Load New Song Highlight");

            _listings.Add(loadSongButton_highlight);

            RectTransform loadSongButton_highlight_tr = loadSongButton_highlight.GetComponent <RectTransform>();

            loadSongButton_highlight_tr.SetParent(loadSongButton_tr);
            loadSongButton_highlight_tr.sizeDelta = new Vector2(_playlistTR.rect.width * 0.5f, loadSongButton_tr.sizeDelta.y * 1.5f);
            loadSongButton_highlight_tr.AnchorAtPoint(0f, 0.5f);
            loadSongButton_highlight_tr.anchoredPosition3D = new Vector3(loadSongButton_highlight_tr.sizeDelta.x / 3f, 0f, 0f);
            loadSongButton_highlight_tr.ResetScaleRot();

            loadSongButton_highlight_tr.SetSiblingIndex(-1);

            Image loadSongButton_highlight_img = loadSongButton_highlight.GetComponent <Image>();

            loadSongButton_highlight_img.raycastTarget = false;
            loadSongButton_highlight_img.sprite        = UIManager.Instance.ScribbleIcon;
            loadSongButton_highlight_img.color         = new Color(1f, 1f, 1f, 1f);

            Fadeable loadSongButton_highlight_fade = loadSongButton_highlight.AddComponent <Fadeable>();

            loadSongButton_highlight_fade.StartFaded = true;
            loadSongButton_highlight_fade.BlockRaycastsWhileFaded = false;
            loadSongButton_highlight_fade.FadeSpeed = 0.1f;

            Highlighted loadSongButton_highlighted = loadSongButton.AddComponent <Highlighted>();

            loadSongButton_highlighted.HighlightObject = loadSongButton_highlight_fade;
        }
Example #3
0
        /// <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);
            }
        }
Example #4
0
        /// <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);
            }
        }
Example #5
0
        /// <summary>
        /// Refreshes the radial key menu.
        /// </summary>
        public void Refresh()
        {
            // Clear old buttons
            foreach (GameObject obj in _objects)
            {
                Destroy(obj);
            }
            _objects.Clear();

            // Init radius and scale
            _radius = (_tr.rect.width - _baseScale / 2f) / 2f;
            _scale  = _baseScale;

            // Layer one -- keys
            for (int i = 1; i < _numKeys; i++)   // i=1 so that it skips Key.None
            {
                Key   key   = (Key)i;
                float angle = (float)i / (float)(_numKeys - 1) * _TWOPI;

                // Create button
                GameObject    button = UIHelpers.MakeTextButton(key.ToString());
                RectTransform tr     = button.GetComponent <RectTransform>();
                tr.SetParent(gameObject.GetComponent <RectTransform>());
                tr.SetSideWidth(_scale);
                tr.AnchorAtPoint(0.5f, 0.5f);
                tr.anchoredPosition3D = new Vector3(
                    _radius * Mathf.Cos(angle),
                    _radius * Mathf.Sin(angle),
                    0f);
                tr.ResetScaleRot();

                // Set button text
                Text text = button.GetComponentInChildren <Text>();
                if (key.ToString().Contains("Sharp"))
                {
                    text.text = key.ToString()[0] + "#";
                }
                text.font     = UIManager.Instance.Font;
                text.fontSize = (int)(_scale / 2.5f);
                text.color    = _GRAY;

                // Set button image
                Image img = button.GetComponent <Image>();
                img.sprite = UIManager.Instance.PercussionVolumeIcon;
                img.color  = _GRAY;

                // Highlight if selected key
                if (key == MusicManager.Instance.CurrentSong.Key)
                {
                    text.color = Color.white;
                    img.color  = Color.white;

                    GameObject hl = UIHelpers.MakeImage(
                        key.ToString() + "_SelectedHighlight");
                    tr = hl.GetComponent <RectTransform>();
                    tr.SetParent(button.GetComponent <RectTransform>());
                    tr.sizeDelta = ((RectTransform)(tr.parent)).sizeDelta;
                    tr.AnchorAtPoint(0.5f, 0.5f);
                    tr.anchoredPosition3D = Vector3.zero;
                    tr.ResetScaleRot();

                    img        = hl.GetComponent <Image>();
                    img.sprite = UIManager.Instance.CircleIcon;
                    img.color  = Color.white;
                }

                // Set button functionality
                button.GetComponent <Button>().onClick.AddListener(delegate {
                    UIManager.Instance.PlayMenuClickSound();
                    MusicManager.Instance.CurrentSong.Key = key;
                    Refresh();
                });

                // Set button show/hide
                Highlighted buttonHighlighted = button.AddComponent <Highlighted>();
                GameObject  highlight         = UIHelpers.MakeImage(
                    key.ToString() + "_Highlight");
                tr = highlight.GetComponent <RectTransform>();
                tr.SetParent(button.GetComponent <RectTransform>());
                tr.sizeDelta = ((RectTransform)(tr.parent)).sizeDelta;
                tr.AnchorAtPoint(0.5f, 0.5f);
                tr.ResetScaleRot();
                tr.anchoredPosition3D = Vector3.zero;
                highlight.GetComponent <Image>().sprite =
                    UIManager.Instance.PercussionVolumeIcon;
                highlight.GetComponent <Image>().color = Color.white;

                Fadeable highlightFade = highlight.AddComponent <Fadeable>();
                highlightFade.StartFaded = true;
                highlightFade.BlockRaycastsWhileFaded = false;
                highlightFade.FadeSpeed = 0.1f;

                buttonHighlighted.HighlightObject = highlightFade;

                _objects.Add(button);
            }

            // Layer two -- scales
            _radius *= _scaleFactor;
            _scale  *= _scaleFactor;
            for (int i = 0; i < _numScales; i++)
            {
                ScaleInfo scalei = ScaleInfo.AllScales[i];
                float     angle  = (float)i / (float)_numScales * _TWOPI;

                // Make scale button
                GameObject    button = UIHelpers.MakeTextButton(scalei.Name);
                RectTransform tr     = button.GetComponent <RectTransform>();
                tr.SetParent(gameObject.GetComponent <RectTransform>());
                tr.SetSideWidth(_scale);
                tr.AnchorAtPoint(0.5f, 0.5f);
                tr.ResetScaleRot();
                tr.anchoredPosition3D = new Vector3(
                    _radius * Mathf.Cos(angle),
                    _radius * Mathf.Sin(angle),
                    0f);

                // Set button text
                Text text = button.GetComponentInChildren <Text>();
                text.font     = UIManager.Instance.Font;
                text.fontSize = (int)(_baseScale / 8f);
                text.color    = _GRAY;

                // Set button image
                Image img = button.GetComponent <Image>();
                img.sprite = UIManager.Instance.PercussionVolumeIcon;
                img.color  = _GRAY;

                // Set highlighted button
                if (i == MusicManager.Instance.CurrentSong.Scale)
                {
                    text.color = Color.white;
                    img.color  = Color.white;
                }

                // Set button functionality
                button.GetComponent <Button>().onClick.AddListener(delegate {
                    UIManager.Instance.PlayMenuClickSound();
                    MusicManager.Instance.CurrentSong.Scale = scalei.ScaleIndex;
                    Refresh();
                });

                // Set show/hide
                Highlighted buttonHighlight = button.AddComponent <Highlighted>();
                GameObject  highlight       = UIHelpers.MakeImage(
                    scalei.Name + "_Highlight");
                tr = highlight.GetComponent <RectTransform>();
                tr.SetParent(button.GetComponent <RectTransform>());
                tr.sizeDelta = ((RectTransform)(tr.parent)).sizeDelta;
                tr.AnchorAtPoint(0.5f, 0.5f);
                tr.ResetScaleRot();
                tr.anchoredPosition3D = Vector3.zero;
                highlight.GetComponent <Image>().sprite =
                    UIManager.Instance.PercussionVolumeIcon;
                highlight.GetComponent <Image>().color = Color.white;

                Fadeable highlightFade = highlight.AddComponent <Fadeable>();
                highlightFade.StartFaded = true;
                highlightFade.BlockRaycastsWhileFaded = false;
                highlightFade.FadeSpeed = 0.1f;

                buttonHighlight.HighlightObject = highlightFade;

                _objects.Add(button);
            }

            GameObject confirmButton =
                KeySelectConfirmButton.Instance.gameObject;

            // Confirm button
            if (MusicManager.Instance.CurrentSong.Key != Key.None &&
                MusicManager.Instance.CurrentSong.Scale != -1)
            {
                PlayKeySound();
                KeySelectConfirmButton.Instance.Show();
                confirmButton.GetComponent <Button>().interactable = true;
            }
        }