Ejemplo n.º 1
0
        public override int CompareTo(object obj)
        {
            ItemSlotRow other = obj as ItemSlotRow;

            return(order.CompareTo(other.order));
        }
Ejemplo n.º 2
0
        internal void OrganizeSelection(SortBy sortBy, ProgressBy progressBy, string filterMod, bool initializing = false)
        {
            int displayMusicID = tMusicPlayer.AllMusic[DisplayBox].music;

            if (sortBy == SortBy.ID)
            {
                musicData = musicData.OrderBy(x => x.music).ToList();
            }
            if (sortBy == SortBy.Name)
            {
                musicData = musicData.OrderBy(x => x.name).ToList();
            }

            DisplayBox = tMusicPlayer.AllMusic.FindIndex(x => x.music == displayMusicID);

            SelectionList.Clear();

            if (!viewMode)
            {
                // Current view mode is GRID
                ItemSlotRow newRow = new ItemSlotRow(0, 400, 50);
                int         col    = 0;
                int         row    = 0;
                for (int i = 0; i < musicData.Count; i++)
                {
                    // Filter checks do not happen when initializing
                    // Include all music boxes if FilterMod is left empty
                    // Otherwise find music boxes with the same mod name as the selected filter mod
                    // If Availability isn't 'None' check if the box is obtained or not
                    if (!initializing)
                    {
                        MusicPlayerPlayer modplayer = Main.LocalPlayer.GetModPlayer <MusicPlayerPlayer>();
                        bool CheckFilterMod         = filterMod != "" && (musicData[i].mod != filterMod);
                        bool CheckObtained          = progressBy == ProgressBy.Obtained && modplayer.MusicBoxList.All(x => x.Type != musicData[i].musicbox);
                        bool CheckUnobtained        = progressBy == ProgressBy.Unobtained && modplayer.MusicBoxList.Any(x => x.Type == musicData[i].musicbox);

                        if (CheckFilterMod || CheckObtained || CheckUnobtained)
                        {
                            continue;
                        }
                    }

                    SelectionSlots[i]             = new MusicBoxSlot(musicData[i].musicbox, 0.85f);
                    SelectionSlots[i].Left.Pixels = 20f + (SelectionSlots[i].Width.Pixels + 10f) * col;
                    SelectionSlots[i].Top.Pixels  = (newRow.Height.Pixels / 2f) - (SelectionSlots[i].Height.Pixels / 2f);
                    SelectionSlots[i].Id          = $"SelectionSlotGrid_{i}";
                    newRow.Append(SelectionSlots[i]);
                    col++;
                    if (col == 5)
                    {
                        row++;
                        col = 0;
                        SelectionList.Add(newRow);
                        newRow = new ItemSlotRow(row, 400, 50);
                    }
                }
                if (col != 0)
                {
                    // Add the last row if we did not complete it
                    SelectionList.Add(newRow);
                }
            }
            else
            {
                // Current view mode is LIST
                ItemSlotRow newRow;
                for (int i = 0; i < musicData.Count; i++)
                {
                    // Include all music boxes if FilterMod is left empty
                    // Otherwise find music boxes with the same mod name as the selected filter mod
                    // If Availability isn't 'None' check if the box is obtained or not
                    if (!initializing)
                    {
                        MusicPlayerPlayer modplayer = Main.LocalPlayer.GetModPlayer <MusicPlayerPlayer>();
                        bool CheckFilterMod         = filterMod != "" && (musicData[i].mod != filterMod);
                        bool CheckObtained          = progressBy == ProgressBy.Obtained && modplayer.MusicBoxList.All(x => x.Type != musicData[i].musicbox);
                        bool CheckUnobtained        = progressBy == ProgressBy.Unobtained && modplayer.MusicBoxList.Any(x => x.Type == musicData[i].musicbox);

                        if (CheckFilterMod || CheckObtained || CheckUnobtained)
                        {
                            continue;
                        }
                    }

                    newRow = new ItemSlotRow(i, panelTextures[2].Bounds.Width, panelTextures[2].Bounds.Height);

                    // Item Slot
                    SelectionSlots[i]             = new MusicBoxSlot(musicData[i].musicbox, 0.85f);
                    SelectionSlots[i].Left.Pixels = 20f;
                    SelectionSlots[i].Top.Pixels  = (newRow.Height.Pixels / 2f) - (SelectionSlots[i].Height.Pixels / 2f);
                    SelectionSlots[i].Id          = $"SelectionSlotList_{i}";
                    newRow.Append(SelectionSlots[i]);

                    // Play button
                    HoverButton playSong = new HoverButton(buttonTextures, new Rectangle(24, 0, 22, 22))
                    {
                        Id = $"altplay_{musicData[i].music}",
                    };
                    playSong.Width.Pixels  = 22f;
                    playSong.Height.Pixels = 22f;
                    playSong.Left.Pixels   = SelectionSlots[i].Left.Pixels + SelectionSlots[i].Width.Pixels + 8f;
                    playSong.Top.Pixels    = (newRow.Height.Pixels / 2f) - (playSong.Height.Pixels / 2f);
                    playSong.OnClick      += (a, b) => ListViewPlaySong(playSong.Id);
                    newRow.Append(playSong);

                    // Song name and mod
                    UIText songName = new UIText(musicData[i].name, 0.85f);
                    songName.Left.Pixels = playSong.Left.Pixels + playSong.Width.Pixels + 8f;
                    songName.Top.Pixels  = (newRow.Height.Pixels / 2f) - 15f;
                    newRow.Append(songName);

                    UIText songMod = new UIText(musicData[i].mod, 0.85f);
                    songMod.Left.Pixels = playSong.Left.Pixels + playSong.Width.Pixels + 8f;
                    songMod.Top.Pixels  = (newRow.Height.Pixels / 2f) + 4f;
                    newRow.Append(songMod);

                    SelectionList.Add(newRow);
                }
            }

            SelectionList.SetScrollbar(selectionScrollBar);
        }