Exemplo n.º 1
0
        /// <summary>
        /// Load beatmaps from the database, or by parsing the directory structure in fallback cases.
        /// </summary>
        private void InitializeBeatmaps()
        {
            string udid = GameBase.Instance.DeviceIdentifier; //cache the udid before possibly writing the database out.

            BeatmapDatabase.Initialize();

#if !DIST
            if (GameBase.Mapper)
            {
                //desktop/mapper builds.
                recursiveBeatmaps(BeatmapPath);
            }
            else
#endif
            if (BeatmapDatabase.BeatmapInfo.Count > 0 && !ForceBeatmapRefresh && BeatmapDatabase.Version == BeatmapDatabase.DATABASE_VERSION)
            {
                bool hasMissingMaps = false;
                foreach (BeatmapInfo bmi in BeatmapDatabase.BeatmapInfo)
                {
                    Beatmap b = bmi.GetBeatmap();
                    if (!File.Exists(b.ContainerFilename))
                    {
                        hasMissingMaps = true;
                        continue;
                    }

                    maps.AddInPlace(b);
                }
            }
            else
            {
#if !DIST
                Console.WriteLine("Regenerating database!");
#endif

                ForceBeatmapRefresh = false;

#if iOS
                //bundled maps
                foreach (string s in Directory.GetFiles("Beatmaps/"))
                {
                    Beatmap b = new Beatmap(s);

                    BeatmapDatabase.PopulateBeatmap(b);
                    maps.AddInPlace(b);
                }
#endif

                foreach (string s in Directory.GetFiles(BeatmapPath, "*.os*"))
                {
                    Beatmap b = new Beatmap(s);

                    if (b.Package == null)
                    {
                        continue;
                    }

                    BeatmapDatabase.PopulateBeatmap(b);
                    maps.AddInPlace(b);
                }

                BeatmapDatabase.Write();
            }

            int index = 0;

            string lastPackId = null;
            foreach (Beatmap b in maps)
            {
                if (b.Package == null)
                {
                    continue;
                }

                BeatmapPanel panel = new BeatmapPanel(b, panelSelected, index++);
                if (b.PackId != lastPackId)
                {
                    panel.NewSection = true;
                    lastPackId       = b.PackId;
                }

                topmostSpriteManager.Add(panel);
                panels.Add(panel);
            }

            panelDownloadMore = new BeatmapPanel(null, delegate
            {
                AudioEngine.PlaySample(OsuSamples.MenuHit);
                State = SelectState.Exiting;
                Director.ChangeMode(OsuMode.Store);
            }, index++)
            {
                NewSection = true
            };

            panelDownloadMore.s_Text.Text      = LocalisationManager.GetString(OsuString.DownloadMoreSongs);
            panelDownloadMore.s_Text.Colour    = Color4.White;
            panelDownloadMore.s_Text.Offset.Y += 16;
            panels.Add(panelDownloadMore);
            topmostSpriteManager.Add(panelDownloadMore);
        }
Exemplo n.º 2
0
        public override void Update()
        {
            base.Update();

            spriteManagerDifficultySelect.Update();
            if (songInfoSpriteManager != null)
            {
                songInfoSpriteManager.Update();
            }
            if (rankingSpriteManager != null)
            {
                rankingSpriteManager.Update();
            }
            topmostSpriteManager.Update();

            inputStolen = InputManager.PrimaryTrackingPoint != null && InputManager.PrimaryTrackingPoint.HoveringObject == s_ButtonBack;

            //handle touch scrolling
            switch (State)
            {
            case SelectState.DifficultySelect:
                if (!AudioEngine.Music.IsElapsing)
                {
                    playFromPreview();
                }

                if (InputManager.IsPressed && !inputStolen)
                {
                    pendingModeChange = true;
                }
                else if (pendingModeChange)
                {
                    difficultySelectOffset += velocity;

                    if (difficultySelectOffset > mode_button_width / 2)
                    {
                        SetDifficulty(Difficulty.Easy);
                    }
                    else if (difficultySelectOffset < -mode_button_width / 2)
                    {
                        SetDifficulty(Difficulty.Expert);
                    }
                    else
                    {
                        SetDifficulty(Difficulty.Normal);
                    }

                    pendingModeChange = false;
                }

                if (Director.PendingOsuMode == OsuMode.Unknown)
                {
                    Vector2 pos = new Vector2(difficultySelectOffset, 0);
                    if (Math.Abs(pos.X - s_ModeButtonEasy.Position.X) > 10)
                    {
                        s_ModeButtonEasy.MoveTo(pos, 200, EasingTypes.In);
                        s_ModeButtonStream.MoveTo(pos, 200, EasingTypes.In);
                        s_ModeButtonExpert.MoveTo(pos, 200, EasingTypes.In);
                    }

                    s_ModeButtonEasy.ScaleScalar   = (float)Math.Sqrt(1 - 0.002f * Math.Abs(s_ModeButtonEasy.Offset.X + s_ModeButtonEasy.Position.X));
                    s_ModeButtonStream.ScaleScalar = (float)Math.Sqrt(1 - 0.002f * Math.Abs(s_ModeButtonStream.Offset.X + s_ModeButtonStream.Position.X));
                    s_ModeButtonExpert.ScaleScalar = (float)Math.Sqrt(1 - 0.002f * Math.Abs(s_ModeButtonExpert.Offset.X + s_ModeButtonExpert.Position.X));

                    s_ModeButtonEasy.Update();
                    s_ModeButtonStream.Update();
                    s_ModeButtonExpert.Update();
                }

                break;

            case SelectState.SongSelect:

                float bound    = offsetBound;
                bool  wasBound = isBound;
                isBound = songSelectOffset == bound;

                if (!InputManager.IsPressed)
                {
                    float lastOffset = songSelectOffset;
                    songSelectOffset = songSelectOffset * (1 - 0.2f * Clock.ElapsedRatioToSixty) + bound * 0.2f * Clock.ElapsedRatioToSixty + velocity * Clock.ElapsedRatioToSixty;

                    if (songSelectOffset != bound)
                    {
                        velocity *= (1 - 0.3f * Clock.ElapsedRatioToSixty);
                    }
                    else
                    {
                        velocity *= (1 - 0.06f * Clock.ElapsedRatioToSixty);
                    }
                }

                float panelHeightPadded = BeatmapPanel.PANEL_HEIGHT + 10;

                float newIntOffset = isBound ? (int)Math.Round(songSelectOffset / panelHeightPadded) : songSelectOffset / panelHeightPadded;

                if (Director.PendingOsuMode == OsuMode.Unknown)
                {
                    if (InputManager.PrimaryTrackingPoint != null && InputManager.IsPressed)
                    {
                        if (InputManager.PrimaryTrackingPoint.HoveringObject is pSprite sprite)
                        {
                            //check for beatmap present; the store link doesn't have one.
                            if (sprite.Tag is BeatmapPanel panel && panel.Beatmap != null)
                            {
                                if (SelectedPanel != panel && PreviewingPanel != panel)
                                {
                                    cancelHoverPreview();

                                    SelectedPanel  = panel;
                                    Player.Beatmap = panel.Beatmap;

                                    SelectedPanelHoverGlow = panel.s_BackingPlate2.AdditiveFlash(0, 1, true);
                                    SelectedPanelHoverGlow.FadeIn(time_to_hover);

                                    //cancel any previously scheduled preview that was not activated yet.
                                    GameBase.Scheduler.Cancel(previewDelegate);

                                    previewDelegate = GameBase.Scheduler.Add(delegate
                                    {
                                        if (panel != SelectedPanel || panel == PreviewingPanel || State != SelectState.SongSelect)
                                        {
                                            return;
                                        }

                                        cancelLockedHoverPreview();

                                        if (AudioEngine.Music != null && (AudioEngine.Music.lastLoaded != panel.Beatmap.PackageIdentifier))
                                        {
                                            AudioEngine.Music.Load(panel.Beatmap.GetFileBytes(panel.Beatmap.AudioFilename), false, panel.Beatmap.PackageIdentifier);
                                            if (!AudioEngine.Music.IsElapsing)
                                            {
                                                playFromPreview();
                                            }

                                            SelectedPanelHoverGlow.Alpha  = 1;
                                            SelectedPanelHoverGlow.Colour = Color4.White;
                                            SelectedPanelHoverGlow.FadeOut(500, 0.8f);
                                            SelectedPanelHoverGlow.Transformations[0].Looping = true;
                                            SelectedPanelHoverGlowLockedIn = SelectedPanelHoverGlow;
                                            SelectedPanelHoverGlow         = null;
                                            PreviewingPanel = panel;
                                            PreviewingPanel.Add(SelectedPanelHoverGlowLockedIn);
                                        }
                                    }, time_to_hover);
                                }
                                else
                                {
                                    if (SelectedPanelHoverGlow != null && Math.Abs(SelectedPanelHoverGlow.Position.Y - panel.s_BackingPlate2.Position.Y) > 3)
                                    {
                                        cancelHoverPreview();
                                    }
                                }
                            }
                            else
                            {
                                cancelHoverPreview();
                            }
                        }
                    }
                    else
                    {
                        cancelHoverPreview();
                        if (!AudioEngine.Music.IsElapsing)
                        {
                            InitializeBgm();
                        }
                    }

                    if (newIntOffset != lastIntOffset)
                    {
                        if (isBound && wasBound)
                        {
                            AudioEngine.PlaySample(OsuSamples.MenuClick);
                            background.FlashColour(new Color4(140, 140, 140, 255), 400);
                        }

                        lastIntOffset = newIntOffset;
                    }

                    if (SelectedPanelHoverGlow != null)
                    {
                        AudioEngine.Music.DimmableVolume = 1 - SelectedPanelHoverGlow.Alpha;
                    }

                    Vector2 pos = new Vector2(0, 60 + (newIntOffset * panelHeightPadded) * 0.5f + songSelectOffset * 0.5f);

                    foreach (BeatmapPanel p in panels)
                    {
                        if (p.NewSection)
                        {
                            pos.Y += 20;
                        }

                        if (Math.Abs(p.s_BackingPlate.Position.Y - pos.Y) > 1 || Math.Abs(p.s_BackingPlate.Position.X - pos.X) > 1)
                        {
                            //todo: change this to use a draggable spritemanager instead. better performance and will move smoother on lower fps.
                            p.MoveTo(pos, touchingBegun ? 50 : 300);
                        }
                        pos.Y += 63;
                    }
                }

                break;
            }
        private void showDifficultySelection(BeatmapPanel panel, bool instant = false)
        {
            if (!instant && State != SelectState.SongSelect && State != SelectState.SongInfo)
            {
                return;
            }

            if (Clock.ModeTime - lastDownTime > time_to_hover)
            {
                return;
            }

            cancelHoverPreview();
            cancelLockedHoverPreview();

            SelectedPanel  = panel;
            Player.Beatmap = panel.Beatmap;

            panel.s_BackingPlate2.Alpha = 1;
            panel.s_BackingPlate2.AdditiveFlash(400, 1, true);
            panel.s_BackingPlate2.FadeColour(Color4.White, 0);

            foreach (BeatmapPanel p in panels)
            {
                p.s_BackingPlate.HandleInput = false;

                if (p == panel)
                {
                    continue;
                }

                foreach (pDrawable s in p.Sprites)
                {
                    s.FadeOut(instant ? 0 : 400);
                    s.MoveTo(new Vector2(200, s.Position.Y), instant ? 0 : 500, EasingTypes.In);
                }
            }

            if (instant)
            {
                if (AudioEngine.Music != null && (AudioEngine.Music.lastLoaded != panel.Beatmap.PackageIdentifier))
                {
                    AudioEngine.Music.Load(panel.Beatmap.GetFileBytes(panel.Beatmap.AudioFilename), false, panel.Beatmap.PackageIdentifier);
                }
                showDifficultySelection2(true);
            }
            else
            {
                AudioEngine.PlaySample(OsuSamples.MenuHit);

                State = SelectState.LoadingPreview;

                GameBase.Scheduler.Add(delegate
                {
                    if (State != SelectState.LoadingPreview)
                    {
                        return;
                    }

                    if (AudioEngine.Music != null && (AudioEngine.Music.lastLoaded != panel.Beatmap.PackageIdentifier))
                    {
                        AudioEngine.Music.Load(panel.Beatmap.GetFileBytes(panel.Beatmap.AudioFilename), false, panel.Beatmap.PackageIdentifier);
                    }

                    GameBase.Scheduler.Add(delegate { showDifficultySelection2(); }, true);
                }, 400);
            }
        }