UnityGameProjectsCode / Rise2Point0Game / MusicEntryInfo.cs
MusicEntryInfo.cs
Raw
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class MusicEntryInfo : MonoBehaviour
{
    public TextMeshProUGUI entryID;
    public TextMeshProUGUI songName;
    public Image favoriteIcon;

    [SerializeField] private Color32 backgroundDefaultColor, backgroundDisabledColor;

    private Image entryBackground;

    [SerializeField] private Image currentlyPlayingIcon;
    private MouseOverFade mouseFadeEffect;
    private PlaySongOnPress playOnPress;
    // public Button upButton;
    // public Button downButton;
    private bool isFavorite;
    private bool isLocked;
    private SoundManager soundMgr;

    //Set explicit movements for the up, down, and favorite buttons to allow for controller movement.

    void Awake()
    {
        entryBackground = GetComponent<Image>();
        mouseFadeEffect = GetComponent<MouseOverFade>();
        playOnPress = GetComponent<PlaySongOnPress>();
    }

    private void Start()
    {
        soundMgr = ObjectManager.GetObject(4).GetComponent<SoundManager>();
    }

    public void SetEntryPosition(int changeValue)
    {
        //given a value that represents up or down, change the music entries position within the list via the sound manager
        soundMgr.ChangeMusicEntryPosition(this, changeValue);
    }

    // public void SetUpExplicitTargets(GameObject upTarget, GameObject downTarget, GameObject rightTarget)
    // {
    //     var navigation = upButton.navigation;

    //     if (upTarget != null)
    //     {
    //         navigation.selectOnUp = upTarget.GetComponent<Button>();
    //     }

    //     if (rightTarget != null)
    //     {
    //         navigation.selectOnRight = rightTarget.GetComponent<Scrollbar>();
    //     }


    //     if (downTarget != null)
    //     {
    //         navigation.selectOnDown = downTarget.GetComponent<Button>();
    //     }

    //     upButton.navigation = navigation;
    // }

    // public void SetDownExplicitTargets(GameObject upTarget, GameObject downTarget, GameObject rightTarget)
    // {
    //     var navigation = downButton.navigation;

    //     if (upTarget != null)
    //     {
    //         navigation.selectOnUp = upTarget.GetComponent<Button>();
    //     }

    //     if (rightTarget != null)
    //     {
    //         navigation.selectOnRight = rightTarget.GetComponent<Scrollbar>();
    //     }


    //     if (downTarget != null)
    //     {
    //         navigation.selectOnDown = downTarget.GetComponent<Button>();
    //     }

    //     downButton.navigation = navigation;
    // }

    public void SetEntryID(int newID)
    {
        entryID.text = newID.ToString();
    }

    public void SetSongName(string newName)
    {
        songName.text = newName;
    }

    public void SetIsFavorite(bool state)
    {
        isFavorite = state;

        if (isFavorite)
            favoriteIcon.color = Color.red;
        else
            favoriteIcon.color = Color.white;
    }

    public void SetCurrentlyPlaying(bool state)
    {
        //show or hide the image that shows that the song is playing
        if(state)
            currentlyPlayingIcon.enabled = true;
        else
            currentlyPlayingIcon.enabled = false;
    }

    public void SetIsLocked(bool state)
    {
        isLocked = state;

        if(isLocked)
        {
            //change to default color and enable interaction
            entryBackground.color = backgroundDisabledColor;
            favoriteIcon.GetComponent<Button>().interactable = false;
            mouseFadeEffect.enabled = false;
            playOnPress.enabled = false;
        }
        else
        {
            //opposite
            entryBackground.color = backgroundDefaultColor;
            favoriteIcon.GetComponent<Button>().interactable = true;
            mouseFadeEffect.enabled = true;
            playOnPress.enabled = true;
        }
    }

    public void ReverseFavoriteState()
    {
        isFavorite = !isFavorite;

        SetIsFavorite(isFavorite);

        soundMgr.ChangeMusicEntryFavoriteState(this);
    }

    public int GetEntryID()
    {
        return int.Parse(entryID.text);
    }

    public string GetSongName()
    {
        return songName.text;
    }

    public bool GetIsFavorite()
    {
        return isFavorite;
    }

    public bool GetIsLocked()
    {
        return isLocked;
    }

    // public Button GetUpButton()
    // {
    //     return upButton;
    // }

    // public Button GetDownButton()
    // {
    //     return downButton;
    // }
}