public override bool DoesInputMatchCommand(InteractiveGiveInputModel input) { string inputEvent = input?.input?.eventType; if (!string.IsNullOrEmpty(inputEvent)) { if (this.ButtonCommand.Trigger == InteractiveButtonCommandTriggerType.MouseKeyDown) { return(inputEvent.Equals("mousedown") || inputEvent.Equals("keydown")); } else if (this.ButtonCommand.Trigger == InteractiveButtonCommandTriggerType.MouseKeyUp) { return(inputEvent.Equals("mouseup") || inputEvent.Equals("keyup")); } else if (this.ButtonCommand.Trigger == InteractiveButtonCommandTriggerType.MouseKeyHeld) { if (inputEvent.Equals("mousedown") || inputEvent.Equals("keydown")) { this.ButtonCommand.IsBeingHeld = true; return(true); } else if (inputEvent.Equals("mouseup") || inputEvent.Equals("keyup")) { this.ButtonCommand.IsBeingHeld = false; } } } return(false); }
private void Interactive_OnGiveInput(object sender, InteractiveGiveInputModel e) { if (e.input != null) { this.interactiveTracker.OnStatisticEventOccurred(e.input.controlID, 1); } }
private static void InteractiveClient_OnGiveInput(object sender, InteractiveGiveInputModel e) { System.Console.WriteLine("Input Received: " + e.participantID + " - " + e.input.eventType + " - " + e.input.controlID); if (e.input.eventType.Equals("mousedown") && e.transactionID != null) { InteractiveConnectedButtonControlModel button = Program.buttons.FirstOrDefault(b => b.controlID.Equals(e.input.controlID)); if (button != null) { InteractiveConnectedSceneModel scene = Program.scenes.FirstOrDefault(s => s.buttons.Contains(button)); if (scene != null) { button.cooldown = DateTimeHelper.DateTimeOffsetToUnixTimestamp(DateTimeOffset.Now.AddSeconds(10)); Program.interactiveClient.UpdateControls(scene, new List <InteractiveConnectedButtonControlModel>() { button }).Wait(); System.Console.WriteLine("Sent 10 second cooldown to button: " + e.input.controlID); } } Program.interactiveClient.CaptureSparkTransaction(e.transactionID).Wait(); System.Console.WriteLine("Spark Transaction Captured: " + e.participantID + " - " + e.input.eventType + " - " + e.input.controlID); } }
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); } }
private static void InteractiveClient_OnGiveInput(object sender, InteractiveGiveInputModel e) { try { System.Console.WriteLine("Input Received: " + e.participantID + " - " + e.input.controlID); if (e.input != null && e.input.controlID != null && e.input.controlID.Equals("gameEnd") && e.input.meta.TryGetValue("total", out JToken totalToken)) { int total = totalToken.ToObject <int>(); if (Program.participants.TryGetValue(e.participantID, out InteractiveParticipantModel participant)) { userTotals[participant.sessionID] = total; } } } catch (Exception ex) { System.Console.WriteLine(ex.ToString()); } }
protected override async Task OnInteractiveControlUsed(UserViewModel user, InteractiveGiveInputModel input, InteractiveConnectedControlCommand command) { if (user != null && !user.IsAnonymous && input.input.meta.ContainsKey("image")) { if (this.userDrawings.ContainsKey(user)) { await this.Dispatcher.InvokeAsync(() => { this.userSubmittedImages.Remove(this.userDrawings[user]); return(Task.FromResult(0)); }); } this.userDrawings[user] = new UserSubmittedImage(user, input.input.meta["image"].ToString()); await this.Dispatcher.InvokeAsync(() => { this.userSubmittedImages.Add(this.userDrawings[user]); return(Task.FromResult(0)); }); } }
protected override async Task OnInteractiveControlUsed(UserViewModel user, InteractiveGiveInputModel input, InteractiveConnectedControlCommand command) { if (user != null && !user.IsAnonymous && (input.input.controlID.Equals("gameEnd") || input.input.controlID.Equals("flyHit")) && input.input.meta.TryGetValue("total", out JToken totalToken)) { int total = totalToken.ToObject <int>(); await this.inputLock.WaitAndRelease(async() => { if (!userTotals.ContainsKey(user)) { userTotals[user] = new PlayerData(user, total); await this.Dispatcher.InvokeAsync(() => { this.userCollection.Add(userTotals[user]); }); } }); userTotals[user].Total = total; } }
private async void ProcessVote(object sender, InteractiveGiveInputModel e) { var existingUser = users.FirstOrDefault(u => u.Sessions.Contains(e.participantID)); if (existingUser == null) // added to support users who not recorded by Joined event { var allParticipants = await((InteractiveClient)sender).GetAllParticipants(null); var participant = allParticipants.participants.Single(p => p.sessionID.Equals(e.participantID)); existingUser = new User(participant.username, participant.sessionID); this.users.Add(existingUser); this.InteractiveDataTextBlock.Text += $"[Info]: Registered player: session id {e.participantID}, user {participant.username}" + Environment.NewLine; } if (!usersVotes.ContainsKey(existingUser)) { usersVotes[existingUser] = string.Empty; } if (!usersVotes[existingUser].Equals(e.input.controlID)) { if (!usersVotes[existingUser].Equals(string.Empty)) // very first vote of the session ID for current question { this.votesCounters[usersVotes[existingUser]]--; } this.votesCounters[e.input.controlID]++; usersVotes[existingUser] = e.input.controlID; await this.chatClient.SendMessage($"{existingUser.Name} votes {e.input.controlID}"); } var statusMessage = $"A:{votesCounters[AnswerA]}, B:{votesCounters[AnswerB]}, C:{votesCounters[AnswerC]}, D:{votesCounters[AnswerD]}"; await this.chatClient.SendMessage(statusMessage); this.InteractiveDataTextBlock.Text += statusMessage + Environment.NewLine; }
private async void InteractiveClient_OnGiveInput(object sender, InteractiveGiveInputModel e) { this.InteractiveDataTextBlock.Text += "Input Received: " + e.participantID + " - " + e.input.eventType + " - " + e.input.controlID + Environment.NewLine; if (e.input.eventType.Equals("mousedown")) { this.ProcessVote(sender, e); if (e.transactionID != null) { InteractiveConnectedButtonControlModel button = this.buttons.FirstOrDefault(b => b.controlID.Equals(e.input.controlID)); if (button != null) { InteractiveConnectedSceneModel scene = this.scenes.FirstOrDefault(s => s.buttons.Contains(button)); if (scene != null) { button.cooldown = DateTimeHelper.DateTimeOffsetToUnixTimestamp(DateTimeOffset.Now.AddSeconds(10)); await this.interactiveClient.UpdateControls(scene, new List <InteractiveConnectedButtonControlModel>() { button }); this.InteractiveDataTextBlock.Text += "Sent 10 second cooldown to button: " + e.input.controlID + Environment.NewLine; } } await this.interactiveClient.CaptureSparkTransaction(e.transactionID); this.InteractiveDataTextBlock.Text += "Spark Transaction Captured: " + e.participantID + " - " + e.input.eventType + " - " + e.input.controlID + Environment.NewLine; } } }
private async void Client_OnGiveInput(object sender, InteractiveGiveInputModel e) { if (e != null && e.input != null) { if (this.Controls.ContainsKey(e.input.controlID)) { InteractiveConnectedControlCommand connectedControl = this.Controls[e.input.controlID]; if (!connectedControl.Command.IsEnabled) { return; } if (connectedControl.Button != null && !connectedControl.TriggerTransactionString.Equals(e.input.eventType)) { return; } if (connectedControl.Button != null) { connectedControl.Button.cooldown = connectedControl.Command.GetCooldownTimestamp(); List <InteractiveConnectedButtonControlModel> buttons = new List <InteractiveConnectedButtonControlModel>(); if (!string.IsNullOrEmpty(connectedControl.Command.CooldownGroup)) { var otherItems = this.Controls.Values.Where(c => c.Button != null && connectedControl.Command.CooldownGroup.Equals(c.Command.CooldownGroup)); foreach (var otherItem in otherItems) { otherItem.Button.cooldown = connectedControl.Button.cooldown; } buttons.AddRange(otherItems.Select(i => i.Button)); } else { buttons.Add(connectedControl.Button); } await this.UpdateControls(connectedControl.Scene, buttons); } else if (connectedControl.Joystick != null) { } if (!string.IsNullOrEmpty(e.transactionID)) { await this.CaptureSparkTransaction(e.transactionID); } UserViewModel user = ChannelSession.GetCurrentUser(); if (this.InteractiveUsers.ContainsKey(e.participantID)) { InteractiveParticipantModel participant = this.InteractiveUsers[e.participantID]; if (ChannelSession.Chat.ChatUsers.ContainsKey(participant.userID)) { user = ChannelSession.Chat.ChatUsers[participant.userID]; } else { user = new UserViewModel(participant.userID, participant.username); } } await connectedControl.Command.Perform(user); return; } } this.OnGiveInput(this, e); }
public virtual bool DoesInputMatchCommand(InteractiveGiveInputModel input) { return(this.EventTypeString.Equals(input.input.eventType)); }
public InteractiveInputEvent(UserViewModel user, InteractiveGiveInputModel input) { this.User = user; this.Input = input; }
public InteractiveInputEvent(UserViewModel user, InteractiveGiveInputModel input, InteractiveConnectedControlCommand command) : this(user, input) { this.Command = command; }
protected virtual Task OnInteractiveControlUsed(UserViewModel user, InteractiveGiveInputModel input, InteractiveConnectedControlCommand command) { return(Task.FromResult(0)); }
private async void Client_OnGiveInput(object sender, InteractiveGiveInputModel e) { try { if (e != null && e.input != null) { InteractiveControlModel control = this.Controls[e.input.controlID]; InteractiveConnectedControlCommand connectedControl = null; if (this.ControlCommands.ContainsKey(e.input.controlID)) { connectedControl = this.ControlCommands[e.input.controlID]; if (!connectedControl.DoesInputMatchCommand(e)) { return; } if (!connectedControl.Command.IsEnabled) { return; } } UserViewModel user = null; if (!string.IsNullOrEmpty(e.participantID)) { user = await ChannelSession.ActiveUsers.GetUserByParticipantID(e.participantID); if (user == null) { InteractiveParticipantModel participant = null; if (this.Participants.TryGetValue(e.participantID, out participant)) { user = new UserViewModel(participant); } else { IEnumerable <InteractiveParticipantModel> recentParticipants = await this.GetRecentParticipants(); participant = recentParticipants.FirstOrDefault(p => p.sessionID.Equals(e.participantID)); if (participant != null) { user = await ChannelSession.ActiveUsers.AddOrUpdateUser(participant); } } } } if (user == null) { user = new UserViewModel(0, "Unknown User"); user.InteractiveIDs[e.participantID] = new InteractiveParticipantModel() { sessionID = e.participantID, anonymous = true }; } else { await user.RefreshDetails(); } user.UpdateLastActivity(); if (ChannelSession.Settings.PreventUnknownInteractiveUsers && user.IsAnonymous) { return; } if (user.IsInInteractiveTimeout) { return; } if (!ModerationHelper.MeetsChatInteractiveParticipationRequirement(user)) { await ModerationHelper.SendChatInteractiveParticipationWhisper(user, isInteractive : true); return; } if (!this.Controls.ContainsKey(e.input.controlID)) { return; } if (connectedControl != null) { int sparkCost = 0; await this.giveInputLock.WaitAndRelease(async() => { if (await connectedControl.CheckAllRequirements(user)) { if (!string.IsNullOrEmpty(e.transactionID) && !user.Data.IsSparkExempt) { Util.Logger.LogDiagnostic("Sending Spark Transaction Capture - " + e.transactionID); await this.CaptureSparkTransaction(e.transactionID); if (control is InteractiveButtonControlModel) { sparkCost = ((InteractiveButtonControlModel)control).cost.GetValueOrDefault(); } else if (control is InteractiveTextBoxControlModel) { sparkCost = ((InteractiveTextBoxControlModel)control).cost.GetValueOrDefault(); } } List <string> arguments = new List <string>(); if (connectedControl is InteractiveConnectedJoystickCommand) { arguments.Add(e.input.x.ToString()); arguments.Add(e.input.y.ToString()); } else if (connectedControl is InteractiveConnectedTextBoxCommand) { arguments.Add(e.input.value); } await connectedControl.Perform(user, arguments); } }); if (sparkCost > 0) { GlobalEvents.SparkUseOccurred(new Tuple <UserViewModel, int>(user, sparkCost)); } } this.OnGiveInput(this, e); this.OnInteractiveControlUsed(this, new InteractiveInputEvent(user, e, connectedControl)); } } catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); } }
private static void InteractiveClient_OnGiveInput(object sender, InteractiveGiveInputModel e) { var allow = Users.TryGetValue(e.participantID, out var participant); if (!allow) { return; } System.Console.WriteLine("Input Received: " + participant.username + " - " + e.input.eventType + " - " + e.input.controlID); var i = e.input; var c = controller.controller; if (i.eventType == "mousedown" && i.controlID == "join") { //interactiveClient.UpdateControls(scene, scene.allControls).Wait(); //new InteractiveButtonControlModel //{ // controlID= "join", // disabled = true, //} /* * {"type":"method","method":"onControlUpdate","params":{"sceneID":"default","controls":[{"controlID":"join","kind":"button","etag":"","disabled":true,"cooldown":0,"cost":0,"hidden":false,"position":[{"size":"large","width":20,"height":4,"x":58,"y":4},{"size":"medium","width":32,"height":4,"x":10,"y":7},{"size":"small","width":32,"height":4,"x":0,"y":13}],"text":"locStrJoin","meta":{}}]},"id":0,"seq":4,"discard":true} * * */ } if (i.eventType == "mousedown" || i.eventType == "mouseup") { var pressed = i.eventType == "mousedown"; if (Enum.TryParse <X360Buttons>(i.controlID, out var button)) { c.SetButton(button, pressed); } } else if (e.input.eventType == "move") { var x = (short)(short.MaxValue * e.input.x); var y = (short)(short.MaxValue * -e.input.y); if (i.controlID == "LeftStick") { c.LeftStickX = x; c.LeftStickY = y; } if (i.controlID == "RightStick") { c.RightStickX = x; c.RightStickY = y; } System.Console.WriteLine($"move {i.controlID} {x} {y}"); } else { System.Console.WriteLine(e.input.eventType); } }
private async void Client_OnGiveInput(object sender, InteractiveGiveInputModel e) { try { if (e != null && e.input != null) { if (this.Controls.ContainsKey(e.input.controlID)) { InteractiveConnectedControlCommand connectedControl = this.Controls[e.input.controlID]; if (!connectedControl.Command.IsEnabled) { return; } if (!connectedControl.DoesInputMatchCommand(e)) { return; } UserViewModel user = null; if (!string.IsNullOrEmpty(e.participantID)) { user = await ChannelSession.ActiveUsers.GetUser(e.participantID); if (user == null) { IEnumerable <InteractiveParticipantModel> recentParticipants = await this.GetRecentParticipants(); InteractiveParticipantModel participant = recentParticipants.FirstOrDefault(p => p.sessionID.Equals(e.participantID)); if (participant != null) { user = await ChannelSession.ActiveUsers.AddOrUpdateUser(participant); } } } if (user == null) { user = InteractiveClientWrapper.defaultInteractiveUser; } if (!string.IsNullOrEmpty(e.transactionID) && !user.Data.IsSparkExempt) { await this.CaptureSparkTransaction(e.transactionID); } List <string> arguments = new List <string>(); if (connectedControl is InteractiveConnectedJoystickCommand) { arguments.Add(e.input.x.ToString()); arguments.Add(e.input.y.ToString()); } else if (connectedControl is InteractiveConnectedTextBoxCommand) { arguments.Add(e.input.value); } await connectedControl.Perform(user, arguments); if (this.OnInteractiveControlUsed != null) { this.OnInteractiveControlUsed(this, new Tuple <UserViewModel, InteractiveConnectedControlCommand>(user, connectedControl)); } } } this.OnGiveInput(this, e); } catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); } }