Ejemplo n.º 1
0
        protected virtual void OpenNewRoom(Room room)
        {
            selectionLease = selectedRoom.BeginLease(false);
            Debug.Assert(selectionLease != null);
            selectionLease.Value = room;

            this.Push(CreateRoomSubScreen(room));
        }
Ejemplo n.º 2
0
        protected override void Dispose(bool isDisposing)
        {
            base.Dispose(isDisposing);

            // base call does an UnbindAllBindables().
            // clean up the leased reference here so that it doesn't get returned twice.
            leasedInProgress = null;
        }
Ejemplo n.º 3
0
        private void load(OsuConfigManager config, BeatmapManager beatmaps, Framework.Game game)
        {
            // prevent user from changing beatmap while the intro is still runnning.
            beatmap = base.Beatmap.BeginLease(false);

            menuVoice = config.GetBindable <bool>(OsuSetting.MenuVoice);
            seeya     = audio.Samples.Get(@"seeya");
        }
Ejemplo n.º 4
0
        private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game)
        {
            // prevent user from changing beatmap while the intro is still runnning.
            beatmap = Beatmap.BeginLease(false);

            MenuVoice = config.GetBindable <bool>(OsuSetting.MenuVoice);
            MenuMusic = config.GetBindable <bool>(OsuSetting.MenuMusic);
            seeya     = audio.Samples.Get(SeeyaSampleName);

            BeatmapSetInfo setInfo = null;

            // if the user has requested not to play theme music, we should attempt to find a random beatmap from their collection.
            if (!MenuMusic.Value)
            {
                var sets = beatmaps.GetAllUsableBeatmapSets(IncludedDetails.Minimal);

                if (sets.Count > 0)
                {
                    setInfo        = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
                    initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
                }
            }

            // we generally want a song to be playing on startup, so use the intro music even if a user has specified not to if no other track is available.
            if (setInfo == null)
            {
                if (!loadThemedIntro())
                {
                    // if we detect that the theme track or beatmap is unavailable this is either first startup or things are in a bad state.
                    // this could happen if a user has nuked their files store. for now, reimport to repair this.
                    var import = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).Result;

                    import.PerformWrite(b =>
                    {
                        b.Protected = true;
                        beatmaps.Update(b);
                    });

                    loadThemedIntro();
                }
            }

            bool loadThemedIntro()
            {
                setInfo = beatmaps.QueryBeatmapSets(b => b.Hash == BeatmapHash, IncludedDetails.AllButRuleset).FirstOrDefault();

                if (setInfo == null)
                {
                    return(false);
                }

                initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);

                return(UsingThemedIntro = initialBeatmap != null);
            }
        }
Ejemplo n.º 5
0
        private void endOperation()
        {
            if (leasedInProgress == null)
            {
                throw new InvalidOperationException("Cannot end operation multiple times.");
            }

            leasedInProgress.Return();
            leasedInProgress = null;
        }
        public void TestLeasedBindable()
        {
            LeasedBindable <TestEnum?> leased = null;

            AddStep("change value to test0", () => simpleTabcontrol.Current.Value = TestEnum.Test0);
            AddStep("lease bindable", () => leased = simpleTabcontrol.Current.BeginLease(true));
            AddStep("change value to test1", () => leased.Value = TestEnum.Test1);
            AddAssert("value changed", () => simpleTabcontrol.Current.Value == TestEnum.Test1);
            AddAssert("tab changed", () => simpleTabcontrol.SelectedTab.Value == TestEnum.Test1);
            AddStep("end lease", () => leased.UnbindAll());
        }
Ejemplo n.º 7
0
        public IDisposable BeginOperation()
        {
            if (leasedInProgress != null)
            {
                throw new InvalidOperationException("Cannot begin operation while another is in progress.");
            }

            leasedInProgress       = inProgress.BeginLease(true);
            leasedInProgress.Value = true;

            return(new OngoingOperation(this, leasedInProgress));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Begins tracking a new online operation.
        /// </summary>
        /// <returns>
        /// An <see cref="IDisposable"/> that will automatically mark the operation as ended on disposal.
        /// </returns>
        /// <exception cref="InvalidOperationException">An operation has already been started.</exception>
        public IDisposable BeginOperation()
        {
            if (leasedInProgress != null)
            {
                throw new InvalidOperationException("Cannot begin operation while another is in progress.");
            }

            leasedInProgress       = inProgress.BeginLease(true);
            leasedInProgress.Value = true;

            // for extra safety, marshal the end of operation back to the update thread if necessary.
            return(new InvokeOnDisposal(() => Scheduler.Add(endOperation, false)));
        }
Ejemplo n.º 9
0
        private void endOperationWithKnownLease(LeasedBindable <bool> lease)
        {
            if (lease != leasedInProgress)
            {
                return;
            }

            // for extra safety, marshal the end of operation back to the update thread if necessary.
            Scheduler.Add(() =>
            {
                leasedInProgress?.Return();
                leasedInProgress = null;
            }, false);
        }
Ejemplo n.º 10
0
        public override void OnResuming(IScreen last)
        {
            base.OnResuming(last);

            Debug.Assert(selectionLease != null);

            selectionLease.Return();
            selectionLease = null;

            if (selectedRoom.Value?.RoomID.Value == null)
            {
                selectedRoom.Value = new Room();
            }

            music?.EnsurePlayingSomething();

            onReturning();
        }
Ejemplo n.º 11
0
        private void endOperationWithKnownLease(LeasedBindable <bool> lease)
        {
            // for extra safety, marshal the end of operation back to the update thread if necessary.
            Scheduler.Add(() =>
            {
                if (lease != leasedInProgress)
                {
                    return;
                }

                // UnbindAll() is purposefully used instead of Return() - the two do roughly the same thing, with one difference:
                // the former won't throw if the lease has already been returned before.
                // this matters because framework can unbind the lease via the internal UnbindAllBindables(), which is not always detectable
                // (it is in the case of disposal, but not in the case of screen exit - at least not cleanly).
                leasedInProgress?.UnbindAll();
                leasedInProgress = null;
            }, false);
        }
Ejemplo n.º 12
0
        public override void OnResuming(ScreenTransitionEvent e)
        {
            base.OnResuming(e);

            Debug.Assert(selectionLease != null);

            selectionLease.Return();
            selectionLease = null;

            if (SelectedRoom.Value?.RoomID.Value == null)
            {
                SelectedRoom.Value = new Room();
            }

            music?.EnsurePlayingSomething();

            onReturning();
        }
Ejemplo n.º 13
0
        private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game)
        {
            // prevent user from changing beatmap while the intro is still runnning.
            beatmap = Beatmap.BeginLease(false);

            MenuVoice = config.GetBindable <bool>(OsuSetting.MenuVoice);
            MenuMusic = config.GetBindable <bool>(OsuSetting.MenuMusic);

            seeya = audio.Samples.Get(@"seeya");

            BeatmapSetInfo setInfo = null;

            if (!MenuMusic.Value)
            {
                var sets = beatmaps.GetAllUsableBeatmapSets();
                if (sets.Count > 0)
                {
                    setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
                }
            }

            if (setInfo == null)
            {
                setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == BeatmapHash);

                if (setInfo == null)
                {
                    // we need to import the default menu background beatmap
                    setInfo = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).Result;

                    setInfo.Protected = true;
                    beatmaps.Update(setInfo);
                }
            }

            introBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
            Track        = introBeatmap.Track;
        }
Ejemplo n.º 14
0
            public override void OnEntering(IScreen last)
            {
                EnteredFrom = last;
                Entered?.Invoke();

                if (shouldTakeOutLease)
                {
                    DummyBindable.BindTo(((TestScreen)last).DummyBindable);
                    LeasedCopy = DummyBindable.BeginLease(true);
                }

                base.OnEntering(last);

                if (last != null)
                {
                    //only show the pop button if we are entered form another screen.
                    popButton.Alpha = 1;
                }

                this.MoveTo(new Vector2(0, -DrawSize.Y));
                this.MoveTo(Vector2.Zero, transition_time, Easing.OutQuint);
                this.FadeIn(1000);
            }
Ejemplo n.º 15
0
 public OngoingOperation(OngoingOperationTracker tracker, LeasedBindable <bool> lease)
 {
     this.tracker = tracker;
     this.lease   = lease;
 }
Ejemplo n.º 16
0
        private void load(OsuConfigManager config, Framework.Game game, RealmAccess realm, IAPIProvider api)
        {
            // prevent user from changing beatmap while the intro is still running.
            beatmap = Beatmap.BeginLease(false);

            MenuVoice = config.GetBindable <bool>(OsuSetting.MenuVoice);
            MenuMusic = config.GetBindable <bool>(OsuSetting.MenuMusic);

            if (api.LocalUser.Value.IsSupporter)
            {
                AddInternal(skinnableSeeya = new SkinnableSound(new SampleInfo(SeeyaSampleName)));
            }
            else
            {
                seeya = audio.Samples.Get(SeeyaSampleName);
            }

            // if the user has requested not to play theme music, we should attempt to find a random beatmap from their collection.
            if (!MenuMusic.Value)
            {
                realm.Run(r =>
                {
                    var usableBeatmapSets = r.All <BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected).AsRealmCollection();

                    int setCount = usableBeatmapSets.Count;

                    if (setCount > 0)
                    {
                        var found = usableBeatmapSets[RNG.Next(0, setCount - 1)].Beatmaps.FirstOrDefault();

                        if (found != null)
                        {
                            initialBeatmap = beatmaps.GetWorkingBeatmap(found);
                        }
                    }
                });
            }

            // we generally want a song to be playing on startup, so use the intro music even if a user has specified not to if no other track is available.
            if (initialBeatmap == null)
            {
                // Intro beatmaps are generally made using the osu! ruleset.
                // It might not be present in test projects for other rulesets.
                bool osuRulesetPresent = rulesets.GetRuleset(0) != null;

                if (!loadThemedIntro() && osuRulesetPresent)
                {
                    // if we detect that the theme track or beatmap is unavailable this is either first startup or things are in a bad state.
                    // this could happen if a user has nuked their files store. for now, reimport to repair this.
                    var import = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).GetResultSafely();

                    import?.PerformWrite(b => b.Protected = true);

                    loadThemedIntro();
                }
            }

            bool loadThemedIntro()
            {
                var setInfo = beatmaps.QueryBeatmapSet(b => b.Protected && b.Hash == BeatmapHash);

                if (setInfo == null)
                {
                    return(false);
                }

                setInfo.PerformRead(s =>
                {
                    if (s.Beatmaps.Count == 0)
                    {
                        return;
                    }

                    initialBeatmap = beatmaps.GetWorkingBeatmap(s.Beatmaps.First());
                });

                return(UsingThemedIntro = initialBeatmap != null);
            }
        }