Esempio n. 1
0
        private void PositionUserPointOnCanvas(UserViewModel user, Point point)
        {
            UserProfileAvatarControl avatarControl = this.userAvatars[user.ID];

            double canvasX = ((point.X / 100.0) * this.image.ActualWidth);
            double canvasY = ((point.Y / 100.0) * this.image.ActualHeight);

            Canvas.SetLeft(avatarControl, canvasX - 10);
            Canvas.SetTop(avatarControl, canvasY - 10);
        }
        protected override async Task OnInteractiveControlUsed(UserViewModel user, InteractiveGiveInputModel input, InteractiveConnectedControlCommand command)
        {
            try
            {
                if (input.input.controlID.Equals("position") && user != null && input.input.meta.ContainsKey("x") && input.input.meta.ContainsKey("y"))
                {
                    if (this.scene != null && this.positionButton != null && input.input.meta["x"] != null && input.input.meta["y"] != null)
                    {
                        Point point = new Point()
                        {
                            X = (double)input.input.meta["x"], Y = (double)input.input.meta["y"]
                        };

                        this.userPoints[user.ID] = point;

                        InteractiveConnectedButtonControlModel control = new InteractiveConnectedButtonControlModel()
                        {
                            controlID = this.positionButton.controlID
                        };
                        control.meta["userID"] = user.ID;
                        control.meta["x"]      = point.X;
                        control.meta["y"]      = point.Y;
                        await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control });

                        await this.Dispatcher.InvokeAsync(async() =>
                        {
                            UserProfileAvatarControl avatarControl = null;

                            if (!this.userAvatars.ContainsKey(user.ID))
                            {
                                avatarControl = new UserProfileAvatarControl();
                                await avatarControl.SetUserAvatarUrl(user);
                                avatarControl.SetSize(20);

                                this.canvas.Children.Add(avatarControl);
                                this.userAvatars[user.ID] = avatarControl;
                            }

                            avatarControl = this.userAvatars[user.ID];

                            double canvasX = ((point.X / 100.0) * this.canvas.Width);
                            double canvasY = ((point.Y / 100.0) * this.canvas.Height);

                            Canvas.SetLeft(avatarControl, canvasX - 10);
                            Canvas.SetTop(avatarControl, canvasY - 10);
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Esempio n. 3
0
        protected override async Task <bool> GameConnectedInternal()
        {
            this.Dispatcher.Invoke(() =>
            {
                this.MapComboBox.IsEnabled      = false;
                this.MaxTimeTextBox.IsEnabled   = false;
                this.SparkCostTextBox.IsEnabled = false;

                this.TimerStackPanel.Visibility        = Visibility.Hidden;
                this.DropLocationStackPanel.Visibility = Visibility.Hidden;
                this.WinnerStackPanel.Visibility       = Visibility.Hidden;

                this.TimerTextBlock.Text        = string.Empty;
                this.DropLocationTextBlock.Text = string.Empty;
                this.WinnerAvatar.SetSize(80);
                this.WinnerTextBlock.Text = string.Empty;
            });

            this.SaveSettings();

            InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes();

            if (sceneGroups != null)
            {
                this.scene = sceneGroups.scenes.FirstOrDefault();
                if (this.scene != null)
                {
                    this.positionButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("position"));
                    this.winnerButton   = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("winner"));
                }
            }

            if (this.positionButton == null || this.winnerButton == null)
            {
                Logger.Log("Could not get position or winner buttons");
                return(false);
            }

            if (this.sparkCost > 0)
            {
                this.positionButton.cost = this.sparkCost;
                await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { this.positionButton });

                await ChannelSession.Interactive.RefreshCachedControls();
            }

            if (this.dropMapType == DropMapTypeEnum.PUBG)
            {
                JObject settings = this.GetCustomSettings();
                settings[MapSelectionSettingProperty] = this.MapComboBox.SelectedIndex;
                this.SaveCustomSettings(settings);

                PUBGMap map = (PUBGMap)this.MapComboBox.SelectedItem;

                InteractiveConnectedButtonControlModel control = new InteractiveConnectedButtonControlModel()
                {
                    controlID = this.positionButton.controlID
                };
                control.meta["map"] = map.Map;
                await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control });
            }

            this.userAvatars.Clear();
            this.userPoints.Clear();
            if (this.canvas != null)
            {
                this.canvas.Children.Clear();
            }

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Task.Run(async() =>
            {
                if (this.scene != null && this.winnerButton != null)
                {
                    InteractiveConnectedButtonControlModel control = null;

                    for (int i = 0; i < (maxTime + 1); i++)
                    {
                        await Task.Delay(1000);

                        int timeLeft = maxTime - i;

                        this.Dispatcher.Invoke(() =>
                        {
                            this.UpdateTimerUI(timeLeft);
                        });

                        control = new InteractiveConnectedButtonControlModel()
                        {
                            controlID = this.winnerButton.controlID
                        };
                        control.meta["timeleft"] = timeLeft;
                        await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>()
                        {
                            control
                        });
                    }

                    if (this.userPoints.Count > 0)
                    {
                        var users   = this.userPoints.Keys.ToList();
                        int index   = RandomHelper.GenerateRandomNumber(users.Count);
                        uint winner = users[index];
                        Point point = this.userPoints[winner];
                        UserProfileAvatarControl avatar = this.userAvatars[winner];

                        UserModel user = await ChannelSession.Connection.GetUser(winner);

                        string username = (user != null) ? user.username : "******";
                        string location = this.ComputeLocation(point);

                        this.Dispatcher.InvokeAsync(async() =>
                        {
                            await this.UpdateWinnerUI(winner, username, location);
                            this.canvas.Children.Clear();
                            this.canvas.Children.Add(avatar);
                        });

                        control = new InteractiveConnectedButtonControlModel()
                        {
                            controlID = this.winnerButton.controlID
                        };
                        control.meta["userID"]   = winner;
                        control.meta["username"] = username;
                        control.meta["location"] = location;
                        await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>()
                        {
                            control
                        });

                        await ChannelSession.Chat.SendMessage(string.Format("Winner: @{0}, Drop Location: {1}", username, location));
                    }
                }
            });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            return(await base.GameConnectedInternal());
        }
        protected override async Task GameConnectedInternal()
        {
            this.SaveDropMapSettings();

            InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes();

            if (sceneGroups != null)
            {
                this.scene = sceneGroups.scenes.FirstOrDefault();
                if (this.scene != null)
                {
                    this.positionButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("position"));
                    this.winnerButton   = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("winner"));
                }
            }

            if (this.positionButton == null || this.winnerButton == null)
            {
                throw new InvalidOperationException("Could not get position or winner buttons");
            }

            if (this.sparkCost > 0)
            {
                this.positionButton.cost = this.sparkCost;
                await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { this.positionButton });

                await ChannelSession.Interactive.RefreshCachedControls();
            }

            this.userAvatars.Clear();
            this.userPoints.Clear();
            this.canvas.Children.Clear();

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Task.Run(async() =>
            {
                if (this.scene != null && this.winnerButton != null)
                {
                    InteractiveConnectedButtonControlModel control = null;

                    for (int i = 0; i < (maxTime + 1); i++)
                    {
                        await Task.Delay(1000);

                        int timeLeft = maxTime - i;

                        this.Dispatcher.Invoke(() =>
                        {
                            this.UpdateTimerUI(timeLeft);
                        });

                        control = new InteractiveConnectedButtonControlModel()
                        {
                            controlID = this.winnerButton.controlID
                        };
                        control.meta["timeleft"] = timeLeft;
                        await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>()
                        {
                            control
                        });
                    }

                    if (this.userPoints.Count > 0)
                    {
                        var users   = this.userPoints.Keys.ToList();
                        int index   = RandomHelper.GenerateRandomNumber(users.Count);
                        uint winner = users[index];
                        Point point = this.userPoints[winner];
                        UserProfileAvatarControl avatar = this.userAvatars[winner];

                        UserModel user = await ChannelSession.Connection.GetUser(winner);

                        string username = (user != null) ? user.username : "******";
                        string location = this.ComputeLocation(point);

                        this.Dispatcher.InvokeAsync(async() =>
                        {
                            await this.UpdateWinnerUI(winner, username, location);
                            this.canvas.Children.Clear();
                            this.canvas.Children.Add(avatar);
                        });

                        control = new InteractiveConnectedButtonControlModel()
                        {
                            controlID = this.winnerButton.controlID
                        };
                        control.meta["userID"]   = winner;
                        control.meta["username"] = username;
                        control.meta["location"] = location;
                        await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>()
                        {
                            control
                        });

                        await ChannelSession.Chat.SendMessage(string.Format("Winner: @{0}, Drop Location: {1}", username, location));
                    }
                }
            });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }