예제 #1
0
        public void FetchAndShowBeatmap(int beatmapId)
        {
            beatmapSet.Value = null;
            var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId);

            req.Success += res =>
            {
                beatmapSet.Value            = res.ToBeatmapSet(rulesets);
                header.Picker.Beatmap.Value = header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId);
            };
            api.Queue(req);
            Show();
        }
예제 #2
0
        private void load(IAPIProvider api, NotificationOverlay notifications)
        {
            SpriteIcon icon;

            AddRange(new Drawable[]
            {
                icon = new SpriteIcon
                {
                    Anchor = Anchor.Centre,
                    Origin = Anchor.Centre,
                    Icon   = FontAwesome.Regular.Heart,
                    Size   = new Vector2(18),
                    Shadow = false,
                },
                loading = new LoadingLayer(true, false),
            });

            Action = () =>
            {
                // guaranteed by disabled state above.
                Debug.Assert(BeatmapSet.Value.OnlineBeatmapSetID != null);

                loading.Show();

                request?.Cancel();

                request = new PostBeatmapFavouriteRequest(BeatmapSet.Value.OnlineBeatmapSetID.Value, favourited.Value ? BeatmapFavouriteAction.UnFavourite : BeatmapFavouriteAction.Favourite);

                request.Success += () =>
                {
                    favourited.Toggle();
                    loading.Hide();
                };

                request.Failure += e =>
                {
                    notifications?.Post(new SimpleNotification
                    {
                        Text = e.Message,
                        Icon = FontAwesome.Solid.Times,
                    });

                    loading.Hide();
                };

                api.Queue(request);
            };

            favourited.ValueChanged += favourited => icon.Icon = favourited.NewValue ? FontAwesome.Solid.Heart : FontAwesome.Regular.Heart;

            localUser.BindTo(api.LocalUser);
            localUser.BindValueChanged(_ => updateEnabled());

            // must be run after setting the Action to ensure correct enabled state (setting an Action forces a button to be enabled).
            BeatmapSet.BindValueChanged(setInfo =>
            {
                updateEnabled();
                favourited.Value = setInfo.NewValue?.OnlineInfo?.HasFavourited ?? false;
            }, true);
        }
        private void load(OsuGameBase osu, IAPIProvider api, RulesetStore rulesets)
        {
            Bindable <BeatmapInfo> beatmapBindable = new Bindable <BeatmapInfo>();

            var imported = ImportBeatmapTest.LoadOszIntoOsu(osu);

            Child = backgroundSprite = new TestUpdateableBeatmapBackgroundSprite {
                RelativeSizeAxes = Axes.Both
            };

            backgroundSprite.Beatmap.BindTo(beatmapBindable);

            var req = new GetBeatmapSetRequest(1);

            api.Queue(req);

            AddStep("load null beatmap", () => beatmapBindable.Value = null);
            AddUntilStep("wait for cleanup...", () => backgroundSprite.ChildCount == 1);
            AddStep("load imported beatmap", () => beatmapBindable.Value = imported.Beatmaps.First());
            AddUntilStep("wait for cleanup...", () => backgroundSprite.ChildCount == 1);

            if (api.IsLoggedIn)
            {
                AddUntilStep("wait for api response", () => req.Result != null);
                AddStep("load online beatmap", () => beatmapBindable.Value = new BeatmapInfo
                {
                    BeatmapSet = req.Result?.ToBeatmapSet(rulesets)
                });
                AddUntilStep("wait for cleanup...", () => backgroundSprite.ChildCount == 1);
            }
            else
            {
                AddStep("online (login first)", () => { });
            }
        }
예제 #4
0
        private void load(IAPIProvider api)
        {
            GetUsersRequest req = new GetUsersRequest();

            req.Success += list => users = list.Select(e => e.User).ToList();

            api.Queue(req);
        }
예제 #5
0
        private void load(IAPIProvider api)
        {
            var req = new GetRoomScoresRequest();

            req.Success += v => { };
            req.Failure += _ => { };

            api.Queue(req);
        }
예제 #6
0
        /// <summary>
        /// Posts a message to the currently opened channel.
        /// </summary>
        /// <param name="text">The message text that is going to be posted</param>
        /// <param name="isAction">Is true if the message is an action, e.g.: user is currently eating </param>
        /// <param name="target">An optional target channel. If null, <see cref="CurrentChannel"/> will be used.</param>
        public void PostMessage(string text, bool isAction = false, Channel target = null)
        {
            if (target == null)
            {
                target = CurrentChannel.Value;
            }

            if (target == null)
            {
                return;
            }

            void dequeueAndRun()
            {
                if (postQueue.Count > 0)
                {
                    postQueue.Dequeue().Invoke();
                }
            }

            postQueue.Enqueue(() =>
            {
                if (!api.IsLoggedIn)
                {
                    target.AddNewMessages(new ErrorMessage("Please sign in to participate in chat!"));
                    return;
                }

                var message = new LocalEchoMessage
                {
                    Sender    = api.LocalUser.Value,
                    Timestamp = DateTimeOffset.Now,
                    ChannelId = target.Id,
                    IsAction  = isAction,
                    Content   = text
                };

                target.AddLocalEcho(message);

                // if this is a PM and the first message, we need to do a special request to create the PM channel
                if (target.Type == ChannelType.PM && !target.Joined)
                {
                    var createNewPrivateMessageRequest = new CreateNewPrivateMessageRequest(target.Users.First(), message);

                    createNewPrivateMessageRequest.Success += createRes =>
                    {
                        target.Id = createRes.ChannelID;
                        target.ReplaceMessage(message, createRes.Message);
                        dequeueAndRun();
                    };

                    createNewPrivateMessageRequest.Failure += exception =>
                    {
                        Logger.Error(exception, "Posting message failed.");
                        target.ReplaceMessage(message, null);
                        dequeueAndRun();
                    };

                    api.Queue(createNewPrivateMessageRequest);
                    return;
                }

                var req = new PostMessageRequest(message);

                req.Success += m =>
                {
                    target.ReplaceMessage(message, m);
                    dequeueAndRun();
                };

                req.Failure += exception =>
                {
                    Logger.Error(exception, "Posting message failed.");
                    target.ReplaceMessage(message, null);
                    dequeueAndRun();
                };

                api.Queue(req);
            });

            // always run if the queue is empty
            if (postQueue.Count == 1)
            {
                dequeueAndRun();
            }
        }