public async Task RefreshCachedControls() { this.Scenes.Clear(); this.Controls.Clear(); this.ControlCommands.Clear(); // Initialize Scenes InteractiveConnectedSceneGroupCollectionModel scenes = await this.GetScenes(); if (scenes != null) { foreach (InteractiveConnectedSceneModel scene in scenes.scenes) { this.Scenes.Add(scene); InteractiveSceneModel dataScene = this.Version.controls.scenes.FirstOrDefault(s => s.sceneID.Equals(scene.sceneID)); foreach (InteractiveConnectedButtonControlModel button in scene.buttons) { if (dataScene != null) { InteractiveButtonControlModel dataButton = dataScene.buttons.FirstOrDefault(b => b.controlID.Equals(button.controlID)); if (dataButton != null) { button.text = dataButton.text; button.tooltip = dataButton.tooltip; } } this.Controls[button.controlID] = button; this.AddConnectedControl(scene, button); } foreach (InteractiveConnectedJoystickControlModel joystick in scene.joysticks) { this.Controls[joystick.controlID] = joystick; this.AddConnectedControl(scene, joystick); } foreach (InteractiveConnectedTextBoxControlModel textBox in scene.textBoxes) { if (dataScene != null) { InteractiveTextBoxControlModel dataTextBox = dataScene.textBoxes.FirstOrDefault(b => b.controlID.Equals(textBox.controlID)); if (dataTextBox != null) { textBox.placeholder = dataTextBox.placeholder; textBox.submitText = dataTextBox.submitText; } } this.Controls[textBox.controlID] = textBox; this.AddConnectedControl(scene, textBox); } } } }
public InteractiveTextBoxCommandDetailsControl(InteractiveTextBoxCommand command) { this.command = command; this.Control = command.TextBox; InitializeComponent(); }
public InteractiveTextBoxCommandDetailsControl(InteractiveGameListingModel game, InteractiveGameVersionModel version, InteractiveSceneModel scene, InteractiveTextBoxControlModel control) { this.Game = game; this.Version = version; this.Scene = scene; this.Control = control; InitializeComponent(); }
public InteractiveTextBoxCommandDetailsControl(InteractiveGameModel game, InteractiveGameVersionModel version, InteractiveTextBoxCommand command) { this.Game = game; this.Version = version; this.command = command; this.Control = command.TextBox; InitializeComponent(); }
public BasicInteractiveTextBoxCommandEditorControl(CommandWindow window, InteractiveGameModel game, InteractiveGameVersionModel version, InteractiveSceneModel scene, InteractiveTextBoxControlModel textBox, BasicCommandTypeEnum commandType) { this.window = window; this.game = game; this.version = version; this.scene = scene; this.textBox = textBox; this.commandType = commandType; InitializeComponent(); }
protected override async Task OnLoaded() { this.TextValueSpecialIdentifierTextBlock.Text = SpecialIdentifierStringBuilder.InteractiveTextBoxTextEntrySpecialIdentifierHelpText; if (this.command != null) { IEnumerable <InteractiveGameListingModel> games = await ChannelSession.Connection.GetOwnedInteractiveGames(ChannelSession.Channel); this.game = games.FirstOrDefault(g => g.name.Equals(this.command.GameID)); if (this.game != null) { this.version = this.game.versions.First(); this.version = await ChannelSession.Connection.GetInteractiveGameVersion(this.version); this.scene = this.version.controls.scenes.FirstOrDefault(s => s.sceneID.Equals(this.command.SceneID)); this.textBox = this.command.TextBox; } this.SparkCostTextBox.Text = this.command.TextBox.cost.ToString(); this.UseChatModerationCheckBox.IsChecked = this.command.UseChatModeration; if (this.command.Actions.First() is ChatAction) { this.actionControl = new ChatActionControl(null, (ChatAction)this.command.Actions.First()); } else if (this.command.Actions.First() is SoundAction) { this.actionControl = new SoundActionControl(null, (SoundAction)this.command.Actions.First()); } } else { this.SparkCostTextBox.Text = this.textBox.cost.ToString(); if (this.commandType == BasicCommandTypeEnum.Chat) { this.actionControl = new ChatActionControl(null); } else if (this.commandType == BasicCommandTypeEnum.Sound) { this.actionControl = new SoundActionControl(null); } } this.ActionControlControl.Content = this.actionControl; await base.OnLoaded(); }
public InteractiveControlCommandItem(InteractiveTextBoxControlModel textBox) { this.TextBox = textBox; }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { if (ChannelSession.Interactive != null) { if (this.InteractiveType == InteractiveActionTypeEnum.Connect) { if (ChannelSession.Interactive.IsConnected()) { await ChannelSession.Interactive.Disconnect(); GlobalEvents.InteractiveDisconnected(); } IEnumerable <InteractiveGameModel> games = await ChannelSession.Interactive.GetAllConnectableGames(); InteractiveGameModel game = games.FirstOrDefault(g => g.id.Equals(this.InteractiveGameID)); if (game != null) { if (await ChannelSession.Interactive.Connect(game)) { GlobalEvents.InteractiveConnected(game); } } } else if (this.InteractiveType == InteractiveActionTypeEnum.Disconnect) { if (ChannelSession.Interactive.IsConnected()) { await ChannelSession.Interactive.Disconnect(); GlobalEvents.InteractiveDisconnected(); } } else if (ChannelSession.Interactive.IsConnected()) { if (!user.HasPermissionsTo(this.RoleRequirement)) { if (ChannelSession.Chat != null) { await ChannelSession.Chat.Whisper(user.UserName, "You do not permission to perform this action."); } return; } await ChannelSession.Interactive.AddGroup(this.GroupName, (!string.IsNullOrEmpty(this.SceneID))?this.SceneID : InteractiveUserGroupViewModel.DefaultName); if (this.InteractiveType == InteractiveActionTypeEnum.MoveGroupToScene) { await ChannelSession.Interactive.UpdateGroup(this.GroupName, this.SceneID); } else if (this.InteractiveType == InteractiveActionTypeEnum.MoveUserToGroup || this.InteractiveType == InteractiveActionTypeEnum.MoveUserToScene) { if (!string.IsNullOrEmpty(this.OptionalUserName)) { string optionalUserName = await this.ReplaceStringWithSpecialModifiers(this.OptionalUserName, user, arguments); UserViewModel optionalUser = await ChannelSession.ActiveUsers.GetUserByUsername(optionalUserName); if (optionalUser != null) { await ChannelSession.Interactive.AddUserToGroup(optionalUser, this.GroupName); } } else { await ChannelSession.Interactive.AddUserToGroup(user, this.GroupName); } } if (this.InteractiveType == InteractiveActionTypeEnum.MoveAllUsersToGroup || this.InteractiveType == InteractiveActionTypeEnum.MoveAllUsersToScene) { foreach (UserViewModel chatUser in await ChannelSession.ActiveUsers.GetAllUsers()) { await ChannelSession.Interactive.AddUserToGroup(chatUser, this.GroupName); } IEnumerable <InteractiveParticipantModel> participants = ChannelSession.Interactive.Participants.Values; foreach (InteractiveParticipantModel participant in participants) { participant.groupID = this.GroupName; } await ChannelSession.Interactive.UpdateParticipants(participants); } else if (this.InteractiveType == InteractiveActionTypeEnum.CooldownButton || this.InteractiveType == InteractiveActionTypeEnum.CooldownGroup || this.InteractiveType == InteractiveActionTypeEnum.CooldownScene) { InteractiveConnectedSceneModel scene = null; List <InteractiveConnectedButtonControlModel> buttons = new List <InteractiveConnectedButtonControlModel>(); if (this.InteractiveType == InteractiveActionTypeEnum.CooldownButton) { if (ChannelSession.Interactive.ControlCommands.ContainsKey(this.CooldownID) && ChannelSession.Interactive.ControlCommands[this.CooldownID] is InteractiveConnectedButtonCommand) { InteractiveConnectedButtonCommand command = (InteractiveConnectedButtonCommand)ChannelSession.Interactive.ControlCommands[this.CooldownID]; scene = command.Scene; buttons.Add(command.Button); } } if (this.InteractiveType == InteractiveActionTypeEnum.CooldownGroup) { var allButtons = ChannelSession.Interactive.ControlCommands.Values.Where(c => c is InteractiveConnectedButtonCommand).Select(c => (InteractiveConnectedButtonCommand)c); allButtons = allButtons.Where(c => this.CooldownID.Equals(c.ButtonCommand.CooldownGroupName)); if (allButtons.Count() > 0) { scene = allButtons.FirstOrDefault().Scene; buttons.AddRange(allButtons.Select(c => c.Button)); } } if (this.InteractiveType == InteractiveActionTypeEnum.CooldownScene) { var allButtons = ChannelSession.Interactive.ControlCommands.Values.Where(c => c is InteractiveConnectedButtonCommand).Select(c => (InteractiveConnectedButtonCommand)c); allButtons = allButtons.Where(c => this.CooldownID.Equals(c.ButtonCommand.SceneID)); if (allButtons.Count() > 0) { scene = allButtons.FirstOrDefault().Scene; buttons.AddRange(allButtons.Select(c => c.Button)); } } if (buttons.Count > 0) { long timestamp = DateTimeHelper.DateTimeOffsetToUnixTimestamp(DateTimeOffset.Now.AddSeconds(this.CooldownAmount)); foreach (InteractiveConnectedButtonControlModel button in buttons) { button.SetCooldownTimestamp(timestamp); } await ChannelSession.Interactive.UpdateControls(scene, buttons); } } else if (this.InteractiveType == InteractiveActionTypeEnum.UpdateControl || this.InteractiveType == InteractiveActionTypeEnum.SetCustomMetadata || this.InteractiveType == InteractiveActionTypeEnum.EnableDisableControl) { InteractiveConnectedSceneModel scene = null; InteractiveControlModel control = null; foreach (InteractiveConnectedSceneModel s in ChannelSession.Interactive.Scenes) { foreach (InteractiveControlModel c in s.allControls) { if (c.controlID.Equals(this.ControlID)) { scene = s; control = c; break; } } if (control != null) { break; } } if (scene != null && control != null) { if (this.InteractiveType == InteractiveActionTypeEnum.UpdateControl) { string replacementValue = await this.ReplaceStringWithSpecialModifiers(this.UpdateValue, user, arguments); int.TryParse(replacementValue, out int replacementNumberValue); if (control is InteractiveButtonControlModel) { InteractiveButtonControlModel button = (InteractiveButtonControlModel)control; switch (this.UpdateControlType) { case InteractiveActionUpdateControlTypeEnum.Text: button.text = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.TextSize: button.textSize = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.TextColor: button.textColor = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.Tooltip: button.tooltip = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.SparkCost: button.cost = replacementNumberValue; break; case InteractiveActionUpdateControlTypeEnum.AccentColor: button.accentColor = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.FocusColor: button.focusColor = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.BorderColor: button.borderColor = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.BackgroundColor: button.backgroundColor = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.BackgroundImage: button.backgroundImage = replacementValue; break; } } else if (control is InteractiveLabelControlModel) { InteractiveLabelControlModel label = (InteractiveLabelControlModel)control; switch (this.UpdateControlType) { case InteractiveActionUpdateControlTypeEnum.Text: label.text = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.TextSize: label.textSize = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.TextColor: label.textColor = replacementValue; break; } } else if (control is InteractiveTextBoxControlModel) { InteractiveTextBoxControlModel textbox = (InteractiveTextBoxControlModel)control; switch (this.UpdateControlType) { case InteractiveActionUpdateControlTypeEnum.Text: textbox.submitText = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.Tooltip: textbox.placeholder = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.SparkCost: textbox.cost = replacementNumberValue; break; } } } else if (this.InteractiveType == InteractiveActionTypeEnum.SetCustomMetadata) { control.meta["userID"] = user.ID; foreach (var kvp in this.CustomMetadata) { string value = await this.ReplaceStringWithSpecialModifiers(kvp.Value, user, arguments); if (bool.TryParse(value, out bool boolValue)) { control.meta[kvp.Key] = boolValue; } else if (int.TryParse(value, out int intValue)) { control.meta[kvp.Key] = intValue; } else if (double.TryParse(value, out double doubleValue)) { control.meta[kvp.Key] = doubleValue; } else { control.meta[kvp.Key] = value; } } } else if (this.InteractiveType == InteractiveActionTypeEnum.EnableDisableControl) { control.disabled = !this.EnableDisableControl; } await ChannelSession.Interactive.UpdateControls(scene, new List <InteractiveControlModel>() { control }); } } } } }
private async Task <bool> Initialize() { this.Scenes.Clear(); this.Controls.Clear(); InteractiveGameVersionModel gameVersion = await ChannelSession.Connection.GetInteractiveGameVersion(this.Game.versions.OrderByDescending(v => v.createdAt.GetValueOrDefault()).First()); foreach (InteractiveSceneModel scene in gameVersion.controls.scenes) { await this.UpdateControls(new InteractiveConnectedSceneModel() { sceneID = scene.sceneID }, scene.allControls); } // Initialize Scenes InteractiveConnectedSceneGroupCollectionModel scenes = await ChannelSession.Interactive.GetScenes(); if (scenes == null) { return(false); } foreach (InteractiveConnectedSceneModel scene in scenes.scenes) { this.Scenes.Add(scene); InteractiveSceneModel dataScene = gameVersion.controls.scenes.FirstOrDefault(s => s.sceneID.Equals(scene.sceneID)); foreach (InteractiveConnectedButtonControlModel button in scene.buttons) { if (dataScene != null) { InteractiveButtonControlModel dataButton = dataScene.buttons.FirstOrDefault(b => b.controlID.Equals(button.controlID)); if (dataButton != null) { button.text = dataButton.text; button.tooltip = dataButton.tooltip; } } this.AddConnectedControl(scene, button); } foreach (InteractiveConnectedJoystickControlModel joystick in scene.joysticks) { this.AddConnectedControl(scene, joystick); } foreach (InteractiveConnectedTextBoxControlModel textBox in scene.textBoxes) { if (dataScene != null) { InteractiveTextBoxControlModel dataTextBox = dataScene.textBoxes.FirstOrDefault(b => b.controlID.Equals(textBox.controlID)); if (dataTextBox != null) { textBox.placeholder = dataTextBox.placeholder; textBox.submitText = dataTextBox.submitText; } } this.AddConnectedControl(scene, textBox); } } // Initialize Groups List <InteractiveGroupModel> groupsToAdd = new List <InteractiveGroupModel>(); if (ChannelSession.Settings.InteractiveUserGroups.ContainsKey(this.Client.InteractiveGame.id)) { foreach (InteractiveUserGroupViewModel userGroup in ChannelSession.Settings.InteractiveUserGroups[this.Client.InteractiveGame.id]) { if (!userGroup.DefaultScene.Equals(InteractiveUserGroupViewModel.DefaultName)) { if (!await this.AddGroup(userGroup.GroupName, userGroup.DefaultScene)) { return(false); } } } } // Initialize Participants await this.AddParticipants(await this.GetRecentParticipants()); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { await this.RefreshInteractiveUsers(); }, this.backgroundThreadCancellationTokenSource.Token); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(true); }
public InteractiveTextBoxCommand(InteractiveGameModel game, InteractiveSceneModel scene, InteractiveTextBoxControlModel control, RequirementViewModel requirements) : base(game, scene, control, string.Empty, requirements) { }