Exemplo n.º 1
0
    private void UpdateFlickGesture()
    {
        if (!IsFlickGesture)
        {
            return;
        }

        // Slowdown a little.
        dragVelocity *= FlickAcceleration;
        if ((dragVelocity.magnitude * Time.deltaTime) < FlickGestureThresholdInPixels ||
            songRouletteItems.IsNullOrEmpty() ||
            InputUtils.AnyMouseButtonPressed() ||
            (flickGestureWasNoTouchscreenPressed && InputUtils.AnyTouchscreenPressed()))
        {
            // End flick-gesture
            IsFlickGesture = false;
            dragVelocity   = Vector2.zero;
            OnEndDrag(Vector2.zero);
            return;
        }

        // Stop flick when the touchscreen was pressed again (i.e., a rising flank).
        flickGestureWasNoTouchscreenPressed = flickGestureWasNoTouchscreenPressed || !InputUtils.AnyTouchscreenPressed();

        // Simulate drag in flick direction.
        SongRouletteItem flickSongRouletteItem = songRouletteItems.FirstOrDefault(it => it.SongMeta == SelectedSongMeta);

        OnDrag(flickSongRouletteItem, dragVelocity * Time.deltaTime);
    }
Exemplo n.º 2
0
    private void UpdateSongRouletteItems()
    {
        List <SongRouletteItem> usedSongRouletteItems = new List <SongRouletteItem>();

        // Spawn roulette items for songs to be displayed (i.e. selected song and its surrounding songs)
        int activeCenterIndex = activeRouletteItemPlaceholders.IndexOf(centerItem);

        foreach (RouletteItemPlaceholder placeholder in activeRouletteItemPlaceholders)
        {
            int      index = activeRouletteItemPlaceholders.IndexOf(placeholder);
            int      activeCenterDistance = index - activeCenterIndex;
            int      songIndex            = SelectedSongIndex + activeCenterDistance;
            SongMeta songMeta             = GetSongAtIndex(songIndex);

            // Get or create SongRouletteItem for the song at the index
            SongRouletteItem songRouletteItem = songRouletteItems.Where(it => it.SongMeta == songMeta).FirstOrDefault();
            if (songRouletteItem == null)
            {
                songRouletteItem = CreateSongRouletteItem(songMeta, placeholder);
            }

            // Update target
            songRouletteItem.TargetRouletteItem = placeholder;
            usedSongRouletteItems.Add(songRouletteItem);
        }

        // Remove unused items
        foreach (SongRouletteItem songRouletteItem in new List <SongRouletteItem>(songRouletteItems))
        {
            if (!usedSongRouletteItems.Contains(songRouletteItem))
            {
                RemoveSongRouletteItem(songRouletteItem);
            }
        }
    }
Exemplo n.º 3
0
    public void OnBeginDrag(SongRouletteItem songRouletteItem)
    {
        IsDrag = true;
        DragSongRouletteItem = songRouletteItem;
        songRouletteItems.ForEach(it => it.StartAnimationTowardsTargetRouletteItem());
        songPreviewController.StopSongPreview();

        // For velocity calculation
        dragStartPosition = songRouletteItem.GetPosition();
        dragDuration      = 0;
    }
Exemplo n.º 4
0
    public void OnDrag(SongRouletteItem songRouletteItem, Vector2 dragDeltaInPixels)
    {
        dragDuration += Time.deltaTime;
        SlotListControl.OnDrag(songRouletteItem, dragDeltaInPixels);
        songRouletteItems.ForEach(it => SlotListControl.InterpolateSize(it));

        if (DragSongRouletteItem != null)
        {
            DragDistance = DragSongRouletteItem.GetPosition() - dragStartPosition;
        }
    }
Exemplo n.º 5
0
    private SongRouletteItem CreateSongRouletteItem(SongMeta songMeta, RouletteItemPlaceholder rouletteItem)
    {
        SongRouletteItem item = Instantiate(songRouletteItemPrefab);

        item.transform.SetParent(transform);
        item.SongMeta = songMeta;
        item.RectTransform.anchorMin        = rouletteItem.RectTransform.anchorMin;
        item.RectTransform.anchorMax        = rouletteItem.RectTransform.anchorMax;
        item.RectTransform.sizeDelta        = Vector2.zero;
        item.RectTransform.anchoredPosition = Vector2.zero;
        item.TargetRouletteItem             = rouletteItem;
        item.AnimTime  = 1;
        item.ScaleTime = 1;

        item.GetComponent <Button>().onClick.AddListener(() => SelectSong(songMeta));

        songRouletteItems.Add(item);
        return(item);
    }
Exemplo n.º 6
0
    private SongRouletteItem CreateSongRouletteItem(SongMeta songMeta, RouletteItemPlaceholder rouletteItem)
    {
        SongRouletteItem item = Instantiate(songRouletteItemPrefab);

        item.transform.SetParent(transform);
        item.SongMeta = songMeta;
        item.RectTransform.anchorMin        = rouletteItem.RectTransform.anchorMin;
        item.RectTransform.anchorMax        = rouletteItem.RectTransform.anchorMax;
        item.RectTransform.sizeDelta        = Vector2.zero;
        item.RectTransform.anchoredPosition = Vector2.zero;
        item.TargetRouletteItem             = rouletteItem;
        item.RectTransform.localScale       = Vector3.zero;

        Button button = item.GetComponent <Button>();

        button.onClick.AddListener(() => OnSongButtonClicked(songMeta));
        songMetaToButtonMap[songMeta] = button;

        songRouletteItems.Add(item);
        return(item);
    }
Exemplo n.º 7
0
    private SongRouletteItem CreateSongRouletteItem(SongMeta songMeta, RouletteItemPlaceholder rouletteItem)
    {
        SongRouletteItem item = Instantiate(songRouletteItemPrefab, songRouletteItemContainer);

        injector.InjectAllComponentsInChildren(item);
        item.name     = songMeta.Artist + "-" + songMeta.Title;
        item.SongMeta = songMeta;
        item.RectTransform.anchorMin        = rouletteItem.RectTransform.anchorMin;
        item.RectTransform.anchorMax        = rouletteItem.RectTransform.anchorMax;
        item.RectTransform.sizeDelta        = Vector2.zero;
        item.RectTransform.anchoredPosition = Vector2.zero;
        item.TargetRouletteItem             = rouletteItem;

        Button button = item.GetComponent <Button>();

        button.OnClickAsObservable().Subscribe(_ => OnSongButtonClicked(songMeta));
        songMetaToButtonMap[songMeta] = button;

        songRouletteItems.Add(item);
        SlotListControl.ListItems.Add(item);
        return(item);
    }
Exemplo n.º 8
0
 private void RemoveSongRouletteItem(SongRouletteItem songRouletteItem)
 {
     songRouletteItem.TargetRouletteItem = null;
     songRouletteItems.Remove(songRouletteItem);
 }
Exemplo n.º 9
0
 public void RemoveSongRouletteItem(SongRouletteItem songRouletteItem)
 {
     songRouletteItem.TargetRouletteItem = null;
     songRouletteItems.Remove(songRouletteItem);
     SlotListControl.ListItems.Remove(songRouletteItem);
 }