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 Initialize()
        {
            background =
                new pSprite(TextureManager.Load(OsuTexture.songselect_background), FieldTypes.StandardSnapCentre, OriginTypes.Centre,
                            ClockTypes.Mode, Vector2.Zero, 0, true, new Color4(56, 56, 56, 255));
            background.Scale.X = background.DrawWidth / GameBase.BaseSize.X;

            background.AlphaBlend = false;
            spriteManager.Add(background);

            rankingBackground =
                new pSprite(TextureManager.Load(OsuTexture.ranking_background), FieldTypes.StandardSnapCentreLeft, OriginTypes.CentreLeft,
                            ClockTypes.Mode, Vector2.Zero, 0.4f, true, Color4.White);
            rankingBackground.Position    = new Vector2(5, -20);
            rankingBackground.ScaleScalar = 0.85f;
            layer2.Add(rankingBackground);

            pText artist = new pText(Player.Beatmap.Artist, 30, new Vector2(10, fill_height + 5), 0.5f, true, Color4.OrangeRed)
            {
                TextShadow = true
            };

            layer1.Add(artist);
            pText title = new pText(Player.Beatmap.Title, 30, new Vector2(16 + artist.MeasureText().X / GameBase.BaseToNativeRatioAligned, fill_height + 5), 0.5f, true, Color4.White)
            {
                TextShadow = true
            };

            layer1.Add(title);

            pTexture modeTex;

            switch (Player.Difficulty)
            {
            case Difficulty.Easy:
                modeTex = TextureManager.Load(OsuTexture.songselect_mode_easy);
                break;

            case Difficulty.Expert:
                modeTex = TextureManager.Load(OsuTexture.songselect_mode_expert);
                break;

            default:
                modeTex = TextureManager.Load(OsuTexture.songselect_mode_stream);
                break;
            }

            modeGraphic = new pSprite(modeTex, FieldTypes.StandardSnapRight, OriginTypes.TopRight, ClockTypes.Mode, new Vector2(5, 7), 0.45f, true, Color4.White)
            {
                ScaleScalar = 0.5f
            };
            layer1.Add(modeGraphic);

            rankGraphic = new pSprite(RankableScore.RankingTexture, FieldTypes.StandardSnapBottomRight, OriginTypes.Centre, ClockTypes.Mode, new Vector2(120, 180), 0.46f, true, Color4.White)
            {
                Alpha = 0
            };

            layer1.Add(rankGraphic);

            initializeTransition();

            //Scoring
            {
                float v_offset = -165;

                pText heading = new pText(LocalisationManager.GetString(OsuString.Score), 28, new Vector2(240, v_offset), 0.5f, true, Color4.White)
                {
                    Origin = OriginTypes.TopLeft,
                    Field  = FieldTypes.StandardSnapCentreLeft,
                    Bold   = true
                };
                resultSprites.Add(heading);

                v_offset += 30;

                pSpriteText count = new pSpriteText("000,000", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.TopRight, ClockTypes.Mode, new Vector2(445, v_offset), 0.9f, true, new Color4(255, 166, 0, 255));
                count.TextConstantSpacing = true;
                countTotalScore           = count;

                resultSprites.Add(count);

                v_offset += 40;

                //Spin Bonus
                heading = new pText(LocalisationManager.GetString(OsuString.Hit), 20, new Vector2(240, v_offset), 0.5f, true, Color4.Gray)
                {
                    Origin = OriginTypes.TopLeft,
                    Field  = FieldTypes.StandardSnapCentreLeft,
                    Bold   = true
                };
                resultSprites.Add(heading);

                count = new pSpriteText("000000", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.TopRight, ClockTypes.Mode, new Vector2(445, v_offset), 0.9f, true, new Color4(255, 166, 0, 255));
                count.TextConstantSpacing = true;
                count.ZeroAlpha           = 0.5f;
                count.ScaleScalar         = 0.7f;
                resultSprites.Add(count);

                countScoreHit = count;

                v_offset += 25;


                heading = new pText(LocalisationManager.GetString(OsuString.Combo), 20, new Vector2(240, v_offset), 0.5f, true, Color4.Gray)
                {
                    Origin = OriginTypes.TopLeft,
                    Field  = FieldTypes.StandardSnapCentreLeft,
                    Bold   = true
                };
                resultSprites.Add(heading);

                count = new pSpriteText("000000", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.TopRight, ClockTypes.Mode, new Vector2(445, v_offset), 0.9f, true, new Color4(255, 166, 0, 255));
                count.TextConstantSpacing = true;
                count.ZeroAlpha           = 0.5f;
                count.ScaleScalar         = 0.7f;
                resultSprites.Add(count);

                countScoreCombo = count;

                v_offset += 25;

                heading = new pText(LocalisationManager.GetString(OsuString.Accuracy), 20, new Vector2(240, v_offset), 0.5f, true, Color4.Gray)
                {
                    Origin = OriginTypes.TopLeft,
                    Field  = FieldTypes.StandardSnapCentreLeft,
                    Bold   = true
                };
                resultSprites.Add(heading);

                count = new pSpriteText("000000", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.TopRight, ClockTypes.Mode, new Vector2(445, v_offset), 0.9f, true, new Color4(255, 166, 0, 255));
                count.TextConstantSpacing = true;
                count.ZeroAlpha           = 0.5f;
                count.ScaleScalar         = 0.7f;
                resultSprites.Add(count);

                countScoreAccuracy = count;

                v_offset += 25;

                heading = new pText(LocalisationManager.GetString(OsuString.Spin), 20, new Vector2(240, v_offset), 0.5f, true, Color4.Gray)
                {
                    Origin = OriginTypes.TopLeft,
                    Field  = FieldTypes.StandardSnapCentreLeft,
                    Bold   = true
                };
                resultSprites.Add(heading);

                count = new pSpriteText("000000", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.TopRight, ClockTypes.Mode, new Vector2(445, v_offset), 0.9f, true, new Color4(255, 166, 0, 255));
                count.TextConstantSpacing = true;
                count.ZeroAlpha           = 0.5f;
                count.ScaleScalar         = 0.7f;
                resultSprites.Add(count);

                countScoreSpin = count;

                v_offset += 30;

                heading = new pText(LocalisationManager.GetString(OsuString.Accuracy), 28, new Vector2(240, v_offset), 0.5f, true, Color4.White)
                {
                    Origin = OriginTypes.TopLeft,
                    Field  = FieldTypes.StandardSnapCentreLeft,
                    Bold   = true
                };
                resultSprites.Add(heading);

                v_offset += 34;

                count             = new pSpriteText((RankableScore.accuracy * 100).ToString("00.00", GameBase.nfi) + "%", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.TopRight, ClockTypes.Mode, new Vector2(445, v_offset), 0.9f, true, new Color4(0, 180, 227, 255));
                count.ScaleScalar = 0.7f;
                resultSprites.Add(count);

                v_offset += 20;

                heading = new pText(LocalisationManager.GetString(OsuString.MaxCombo), 28, new Vector2(240, v_offset), 0.5f, true, Color4.White)
                {
                    Origin = OriginTypes.TopLeft,
                    Field  = FieldTypes.StandardSnapCentreLeft,
                    Bold   = true
                };
                resultSprites.Add(heading);

                v_offset += 34;

                count             = new pSpriteText(RankableScore.maxCombo.ToString("#,0", GameBase.nfi) + "x", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.TopRight, ClockTypes.Mode, new Vector2(445, v_offset), 0.9f, true, new Color4(0, 180, 227, 255));
                count.ScaleScalar = 0.7f;
                resultSprites.Add(count);
            }

            {
                Vector2 pos        = new Vector2(60, -130);
                Vector2 textOffset = new Vector2(150, 0);

                float spacing = 65;

                pSprite hitExplosion = new pSprite(TextureManager.Load(OsuTexture.hit300), pos)
                {
                    Field = FieldTypes.StandardSnapCentreLeft, Origin = OriginTypes.Centre, ScaleScalar = 0.5f, DrawDepth = 0.9f
                };
                resultSprites.Add(hitExplosion);

                count300 = new pSpriteText("0x", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.CentreRight, ClockTypes.Mode, pos + textOffset, 0.9f, true, Color4.White)
                {
                    SpacingOverlap = 3, TextConstantSpacing = true
                };
                resultSprites.Add(count300);

                pos.Y += spacing;

                hitExplosion = new pSprite(TextureManager.Load(OsuTexture.hit100), pos)
                {
                    Field = FieldTypes.StandardSnapCentreLeft, Origin = OriginTypes.Centre, ScaleScalar = 0.5f, DrawDepth = 0.9f
                };
                resultSprites.Add(hitExplosion);

                count100 = new pSpriteText("0x", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.CentreRight, ClockTypes.Mode, pos + textOffset, 0.9f, true, Color4.White)
                {
                    SpacingOverlap = 3, TextConstantSpacing = true
                };
                resultSprites.Add(count100);

                pos.Y += spacing;

                hitExplosion = new pSprite(TextureManager.Load(OsuTexture.hit50), pos)
                {
                    Field = FieldTypes.StandardSnapCentreLeft, Origin = OriginTypes.Centre, ScaleScalar = 0.5f, DrawDepth = 0.9f
                };
                resultSprites.Add(hitExplosion);

                count50 = new pSpriteText("0x", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.CentreRight, ClockTypes.Mode, pos + textOffset, 0.9f, true, Color4.White)
                {
                    SpacingOverlap = 3, TextConstantSpacing = true
                };
                resultSprites.Add(count50);

                pos.Y += spacing;

                hitExplosion = new pSprite(TextureManager.Load(OsuTexture.hit0), pos)
                {
                    Field = FieldTypes.StandardSnapCentreLeft, Origin = OriginTypes.Centre, ScaleScalar = 0.5f, DrawDepth = 0.9f
                };
                resultSprites.Add(hitExplosion);

                count0 = new pSpriteText("0x", "score", 0, FieldTypes.StandardSnapCentreLeft, OriginTypes.CentreRight, ClockTypes.Mode, pos + textOffset, 0.9f, true, Color4.White)
                {
                    SpacingOverlap = 3, TextConstantSpacing = true
                };
                resultSprites.Add(count0);
            }

            if (Director.LastOsuMode == OsuMode.SongSelect)
            {
                cameFromSongSelect = true;
            }

            layer2.Add(resultSprites);

            s_ButtonBack       = new BackButton(returnToSelect, false);
            s_ButtonBack.Alpha = 0;
            topMostLayer.Add(s_ButtonBack);

            s_Footer          = new pSprite(TextureManager.Load(OsuTexture.ranking_footer), FieldTypes.StandardSnapBottomRight, OriginTypes.BottomRight, ClockTypes.Mode, new Vector2(0, -100), 0.98f, true, Color4.White);
            s_Footer.Alpha    = 0;
            s_Footer.OnClick += delegate
            {
                Director.ChangeMode(OsuMode.Play);
                AudioEngine.PlaySample(OsuSamples.MenuHit);
            };
            topMostLayer.Add(s_Footer);

            if (!cameFromSongSelect)
            {
                InitializeBgm();

                //this is a bit of cheating to ensure that getting 100% will always result in 1mil. there are some race conditions with multitouch that may allow
                //for ever-so-slightly lower max scores, but this would piss people off.
                if (RankableScore.accuracy == 1 && RankableScore.totalScore - RankableScore.spinnerBonusScore != Score.MAX_SCORE)
                {
                    RankableScore.comboBonusScore = Score.MAX_SCORE - RankableScore.accuracyBonusScore - RankableScore.hitScore;
                }

                DifficultyScoreInfo bmi = BeatmapDatabase.GetDifficultyInfo(Player.Beatmap, Player.Difficulty);
                if (bmi.HighScore == null || RankableScore.totalScore > bmi.HighScore.totalScore)
                {
                    if (bmi.difficulty == Difficulty.Normal && RankableScore.Ranking >= Rank.A && (bmi.HighScore == null || bmi.HighScore.Ranking < Rank.A))
                    {
                        unlockedExpert = true;
                    }

                    isPersonalBest = true;
                    bmi.HighScore  = RankableScore;
                    BeatmapDatabase.Write();
                }
                else if (bmi.HighScore != null && RankableScore.Ranking > bmi.HighScore.Ranking)
                {
                    bmi.HighScore.Ranking = RankableScore.Ranking;
                }

                //Average Timing
                avg = (float)RankableScore.hitOffsetMilliseconds / Math.Max(1, RankableScore.hitOffsetCount);
                pText heading = new pText(LocalisationManager.GetString(OsuString.AvgTiming) + Math.Round(Math.Abs(avg), 1) + (RankableScore.hitOffsetMilliseconds > 0 ? "ms late" : "ms early"), 16, new Vector2(0, 20), 0.5f, true, Color4.White)
                {
                    Field  = FieldTypes.StandardSnapBottomCentre,
                    Origin = OriginTypes.BottomCentre
                };
                layer1.Add(heading);

                doSubmission();
            }
            else
            {
                if (!string.IsNullOrEmpty(RankableScore.Username))
                {
                    pText playerName = new pText("Played by " + RankableScore.Username, 30, new Vector2(10, 10), 0.5f, true, new Color4(255, 234, 0, 255))
                    {
                        TextShadow = true,
                        Field      = FieldTypes.StandardSnapBottomRight,
                        Origin     = OriginTypes.BottomRight
                    };

                    s_Footer.Bypass = true; //don't show footer. we need this room!

                    layer1.Add(playerName);
                }

                //displaying a previous high score (or online high score)
                finishDisplaying();
            }

            Director.OnTransitionEnded += Director_OnTransitionEnded;
            InputManager.OnMove        += HandleInputManagerOnMove;
        }