private void OfflineRateComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.OfflineRateComboBox.SelectedIndex >= 0) { CurrencyAcquireRateTypeEnum acquireRate = EnumHelper.GetEnumValueFromString <CurrencyAcquireRateTypeEnum>((string)this.OfflineRateComboBox.SelectedItem); this.OfflineAmountRateTextBox.IsEnabled = (acquireRate == CurrencyAcquireRateTypeEnum.Custom); this.OfflineTimeRateTextBox.IsEnabled = (acquireRate == CurrencyAcquireRateTypeEnum.Custom); if (acquireRate == CurrencyAcquireRateTypeEnum.Minutes || acquireRate == CurrencyAcquireRateTypeEnum.Hours) { this.OfflineAmountRateTextBox.Text = "1"; if (acquireRate == CurrencyAcquireRateTypeEnum.Minutes) { this.OfflineTimeRateTextBox.Text = "1"; } else if (acquireRate == CurrencyAcquireRateTypeEnum.Hours) { this.OfflineTimeRateTextBox.Text = "60"; } } else { this.OfflineAmountRateTextBox.Text = "0"; this.OfflineTimeRateTextBox.Text = "0"; } } }
private void OfflineCurrencyAcquireRateComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.OfflineCurrencyAcquireRateComboBox.SelectedIndex >= 0) { CurrencyAcquireRateTypeEnum acquireRate = EnumHelper.GetEnumValueFromString <CurrencyAcquireRateTypeEnum>((string)this.OfflineCurrencyAcquireRateComboBox.SelectedItem); this.OfflineCustomRateGrid.Visibility = (acquireRate == CurrencyAcquireRateTypeEnum.Custom) ? Visibility.Visible : Visibility.Collapsed; } }
private void OnlineRateComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.OnlineRateComboBox.SelectedIndex >= 0) { CurrencyAcquireRateTypeEnum acquireRate = EnumHelper.GetEnumValueFromString <CurrencyAcquireRateTypeEnum>((string)this.OnlineRateComboBox.SelectedItem); this.OnlineAmountRateTextBox.IsEnabled = (acquireRate == CurrencyAcquireRateTypeEnum.Custom); this.OnlineTimeRateTextBox.IsEnabled = (acquireRate == CurrencyAcquireRateTypeEnum.Custom); this.OfflineRateGroupBox.IsEnabled = true; this.BonusesGrid.IsEnabled = true; this.MinimumActivityRateTextBox.IsEnabled = true; if (acquireRate == CurrencyAcquireRateTypeEnum.Minutes || acquireRate == CurrencyAcquireRateTypeEnum.Hours) { this.OnlineAmountRateTextBox.Text = "1"; if (acquireRate == CurrencyAcquireRateTypeEnum.Minutes) { this.OnlineTimeRateTextBox.Text = "1"; } else if (acquireRate == CurrencyAcquireRateTypeEnum.Hours) { this.OnlineTimeRateTextBox.Text = "60"; } } else if (acquireRate == CurrencyAcquireRateTypeEnum.Sparks || acquireRate == CurrencyAcquireRateTypeEnum.Embers) { this.OnlineAmountRateTextBox.Text = "1"; this.OnlineTimeRateTextBox.Text = "1"; this.OfflineRateComboBox.SelectedItem = EnumHelper.GetEnumName(CurrencyAcquireRateTypeEnum.Disabled); this.OfflineRateGroupBox.IsEnabled = false; this.BonusesGrid.IsEnabled = false; this.SubscriberBonusTextBox.Text = "0"; this.ModeratorBonusTextBox.Text = "0"; this.OnFollowBonusTextBox.Text = "0"; this.OnHostBonusTextBox.Text = "0"; this.OnSubscribeBonusTextBox.Text = "0"; this.MinimumActivityRateTextBox.IsEnabled = false; this.MinimumActivityRateTextBox.Text = "0"; } else { this.OnlineAmountRateTextBox.Text = "0"; this.OnlineTimeRateTextBox.Text = "0"; } } }
private async void SaveButton_Click(object sender, System.Windows.RoutedEventArgs e) { await this.RunAsyncOperation(async() => { if (string.IsNullOrEmpty(this.NameTextBox.Text)) { await MessageBoxHelper.ShowMessageDialog(string.Format("A {0} name must be specified", this.CurrencyRankIdentifierString)); return; } if (this.NameTextBox.Text.Any(c => char.IsDigit(c))) { await MessageBoxHelper.ShowMessageDialog("The name can not contain any number digits in it"); return; } UserCurrencyViewModel dupeCurrency = ChannelSession.Settings.Currencies.Values.FirstOrDefault(c => c.Name.Equals(this.NameTextBox.Text)); if (dupeCurrency != null && (this.currency == null || !this.currency.ID.Equals(dupeCurrency.ID))) { await MessageBoxHelper.ShowMessageDialog("There already exists a currency or rank system with this name"); return; } UserInventoryViewModel dupeInventory = ChannelSession.Settings.Inventories.Values.FirstOrDefault(c => c.Name.Equals(this.NameTextBox.Text)); if (dupeInventory != null) { await MessageBoxHelper.ShowMessageDialog("There already exists an inventory with this name"); return; } string siName = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(this.NameTextBox.Text); if (siName.Equals("time") || siName.Equals("hours") || siName.Equals("mins") || siName.Equals("sparks") || siName.Equals("embers")) { await MessageBoxHelper.ShowMessageDialog("This name is reserved and can not be used"); return; } int maxAmount = int.MaxValue; if (!string.IsNullOrEmpty(this.MaxAmountTextBox.Text)) { if (!int.TryParse(this.MaxAmountTextBox.Text, out maxAmount) || maxAmount <= 0) { await MessageBoxHelper.ShowMessageDialog("The max amount must be greater than 0 or can be left empty for no max amount"); return; } } if (string.IsNullOrEmpty(this.OnlineAmountRateTextBox.Text) || !int.TryParse(this.OnlineAmountRateTextBox.Text, out int onlineAmount) || onlineAmount < 0) { await MessageBoxHelper.ShowMessageDialog("The online amount must be 0 or greater"); return; } if (string.IsNullOrEmpty(this.OnlineTimeRateTextBox.Text) || !int.TryParse(this.OnlineTimeRateTextBox.Text, out int onlineTime) || onlineTime < 0) { await MessageBoxHelper.ShowMessageDialog("The online minutes must be 0 or greater"); return; } if (string.IsNullOrEmpty(this.OfflineAmountRateTextBox.Text) || !int.TryParse(this.OfflineAmountRateTextBox.Text, out int offlineAmount) || offlineAmount < 0) { await MessageBoxHelper.ShowMessageDialog("The offline amount must be 0 or greater"); return; } if (string.IsNullOrEmpty(this.OfflineTimeRateTextBox.Text) || !int.TryParse(this.OfflineTimeRateTextBox.Text, out int offlineTime) || offlineTime < 0) { await MessageBoxHelper.ShowMessageDialog("The offline minutes must be 0 or greater"); return; } if (onlineAmount > 0 && onlineTime == 0) { await MessageBoxHelper.ShowMessageDialog("The online time can not be 0 if the online amount is greater than 0"); return; } if (offlineAmount > 0 && offlineTime == 0) { await MessageBoxHelper.ShowMessageDialog("The offline time can not be 0 if the offline amount is greater than 0"); return; } int subscriberBonus = 0; if (string.IsNullOrEmpty(this.SubscriberBonusTextBox.Text) || !int.TryParse(this.SubscriberBonusTextBox.Text, out subscriberBonus) || subscriberBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The Subscriber bonus must be 0 or greater"); return; } int modBonus = 0; if (string.IsNullOrEmpty(this.ModeratorBonusTextBox.Text) || !int.TryParse(this.ModeratorBonusTextBox.Text, out modBonus) || modBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The Moderator bonus must be 0 or greater"); return; } int onFollowBonus = 0; if (string.IsNullOrEmpty(this.OnFollowBonusTextBox.Text) || !int.TryParse(this.OnFollowBonusTextBox.Text, out onFollowBonus) || onFollowBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Follow bonus must be 0 or greater"); return; } int onHostBonus = 0; if (string.IsNullOrEmpty(this.OnHostBonusTextBox.Text) || !int.TryParse(this.OnHostBonusTextBox.Text, out onHostBonus) || onHostBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Host bonus must be 0 or greater"); return; } int onSubscribeBonus = 0; if (string.IsNullOrEmpty(this.OnSubscribeBonusTextBox.Text) || !int.TryParse(this.OnSubscribeBonusTextBox.Text, out onSubscribeBonus) || onSubscribeBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Subscribe bonus must be 0 or greater"); return; } if (this.IsRankToggleButton.IsChecked.GetValueOrDefault()) { if (this.ranks.Count() < 1) { await MessageBoxHelper.ShowMessageDialog("At least one rank must be created"); return; } } int minActivityRate = 0; if (string.IsNullOrEmpty(this.MinimumActivityRateTextBox.Text) || !int.TryParse(this.MinimumActivityRateTextBox.Text, out minActivityRate) || minActivityRate < 0) { await MessageBoxHelper.ShowMessageDialog("The Minimum Activity Rate must be 0 or greater"); return; } bool isNew = false; if (this.currency == null) { isNew = true; this.currency = new UserCurrencyViewModel(); ChannelSession.Settings.Currencies[this.currency.ID] = this.currency; } CurrencyAcquireRateTypeEnum acquireRate = CurrencyAcquireRateTypeEnum.Custom; if (this.OnlineRateComboBox.SelectedIndex >= 0) { acquireRate = EnumHelper.GetEnumValueFromString <CurrencyAcquireRateTypeEnum>((string)this.OnlineRateComboBox.SelectedItem); } this.currency.IsTrackingSparks = false; this.currency.IsTrackingEmbers = false; if (acquireRate == CurrencyAcquireRateTypeEnum.Sparks) { this.currency.IsTrackingSparks = true; } else if (acquireRate == CurrencyAcquireRateTypeEnum.Embers) { this.currency.IsTrackingEmbers = true; } this.currency.Name = this.NameTextBox.Text; this.currency.MaxAmount = maxAmount; this.currency.AcquireAmount = onlineAmount; this.currency.AcquireInterval = onlineTime; this.currency.OfflineAcquireAmount = offlineAmount; this.currency.OfflineAcquireInterval = offlineTime; this.currency.SubscriberBonus = subscriberBonus; this.currency.ModeratorBonus = modBonus; this.currency.OnFollowBonus = onFollowBonus; this.currency.OnHostBonus = onHostBonus; this.currency.OnSubscribeBonus = onSubscribeBonus; this.currency.MinimumActiveRate = minActivityRate; this.currency.ResetInterval = EnumHelper.GetEnumValueFromString <CurrencyResetRateEnum>((string)this.AutomaticResetComboBox.SelectedItem); this.currency.SpecialIdentifier = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(this.currency.Name); if (this.IsRankToggleButton.IsChecked.GetValueOrDefault()) { this.currency.Ranks = ranks.ToList(); this.currency.RankChangedCommand = this.rankChangedCommand; } else { this.currency.Ranks = new List <UserRankViewModel>(); this.currency.RankChangedCommand = null; } foreach (var otherCurrencies in ChannelSession.Settings.Currencies) { if (otherCurrencies.Value.IsRank == this.currency.IsRank) { // Turn off primary for all other currencies/ranks of the same kind otherCurrencies.Value.IsPrimary = false; } } this.currency.IsPrimary = this.IsPrimaryToggleButton.IsChecked.GetValueOrDefault(); await ChannelSession.SaveSettings(); if (isNew) { List <NewCurrencyRankCommand> commandsToAdd = new List <NewCurrencyRankCommand>(); ChatCommand statusCommand = new ChatCommand("User " + this.currency.Name, this.currency.SpecialIdentifier, new RequirementViewModel(MixerRoleEnum.User, 5)); string statusChatText = string.Empty; if (this.currency.IsRank) { statusChatText = string.Format("@$username is a ${0} with ${1} {2}!", this.currency.UserRankNameSpecialIdentifier, this.currency.UserAmountSpecialIdentifier, this.currency.Name); } else { statusChatText = string.Format("@$username has ${0} {1}!", this.currency.UserAmountSpecialIdentifier, this.currency.Name); } statusCommand.Actions.Add(new ChatAction(statusChatText)); commandsToAdd.Add(new NewCurrencyRankCommand(string.Format("!{0} - {1}", statusCommand.Commands.First(), "Shows User's Amount"), statusCommand)); if (!this.currency.IsTrackingSparks && !this.currency.IsTrackingEmbers) { ChatCommand addCommand = new ChatCommand("Add " + this.currency.Name, "add" + this.currency.SpecialIdentifier, new RequirementViewModel(MixerRoleEnum.Mod, 5)); addCommand.Actions.Add(new CurrencyAction(this.currency, CurrencyActionTypeEnum.AddToSpecificUser, "$arg2text", username: "******")); addCommand.Actions.Add(new ChatAction(string.Format("@$targetusername received $arg2text {0}!", this.currency.Name))); commandsToAdd.Add(new NewCurrencyRankCommand(string.Format("!{0} - {1}", addCommand.Commands.First(), "Adds Amount To Specified User"), addCommand)); ChatCommand addAllCommand = new ChatCommand("Add All " + this.currency.Name, "addall" + this.currency.SpecialIdentifier, new RequirementViewModel(MixerRoleEnum.Mod, 5)); addAllCommand.Actions.Add(new CurrencyAction(this.currency, CurrencyActionTypeEnum.AddToAllChatUsers, "$arg1text")); addAllCommand.Actions.Add(new ChatAction(string.Format("Everyone got $arg1text {0}!", this.currency.Name))); commandsToAdd.Add(new NewCurrencyRankCommand(string.Format("!{0} - {1}", addAllCommand.Commands.First(), "Adds Amount To All Chat Users"), addAllCommand)); if (!this.currency.IsRank) { ChatCommand giveCommand = new ChatCommand("Give " + this.currency.Name, "give" + this.currency.SpecialIdentifier, new RequirementViewModel(MixerRoleEnum.User, 5)); giveCommand.Actions.Add(new CurrencyAction(this.currency, CurrencyActionTypeEnum.AddToSpecificUser, "$arg2text", username: "******", deductFromUser: true)); giveCommand.Actions.Add(new ChatAction(string.Format("@$username gave @$targetusername $arg2text {0}!", this.currency.Name))); commandsToAdd.Add(new NewCurrencyRankCommand(string.Format("!{0} - {1}", giveCommand.Commands.First(), "Gives Amount To Specified User"), giveCommand)); } } NewCurrencyRankCommandsDialogControl dControl = new NewCurrencyRankCommandsDialogControl(this.currency, commandsToAdd); string result = await MessageBoxHelper.ShowCustomDialog(dControl); if (!string.IsNullOrEmpty(result) && result.Equals("True")) { foreach (NewCurrencyRankCommand command in dControl.commands) { if (command.AddCommand) { ChannelSession.Settings.ChatCommands.Add(command.Command); } } } } this.Close(); }); }
private async void SaveButton_Click(object sender, System.Windows.RoutedEventArgs e) { await this.RunAsyncOperation(async() => { if (string.IsNullOrEmpty(this.CurrencyNameTextBox.Text)) { await MessageBoxHelper.ShowMessageDialog("A currency name must be specified"); return; } UserCurrencyViewModel dupeCurrency = ChannelSession.Settings.Currencies.Values.FirstOrDefault(c => c.Name.Equals(this.CurrencyNameTextBox.Text)); if (dupeCurrency != null && (this.currency == null || !this.currency.ID.Equals(dupeCurrency.ID))) { await MessageBoxHelper.ShowMessageDialog("There already exists a currency or rank system with this name"); return; } if (this.CurrencyAcquireRateComboBox.SelectedIndex < 0) { await MessageBoxHelper.ShowMessageDialog("The currency rate must be selected"); return; } CurrencyAcquireRateTypeEnum acquireRate = EnumHelper.GetEnumValueFromString <CurrencyAcquireRateTypeEnum>((string)this.CurrencyAcquireRateComboBox.SelectedItem); int currencyAmount = 1; int currencyTime = 1; if (acquireRate == CurrencyAcquireRateTypeEnum.Hours) { currencyTime = 60; } else if (acquireRate == CurrencyAcquireRateTypeEnum.Custom) { if (string.IsNullOrEmpty(this.CurrencyAmountTextBox.Text) || !int.TryParse(this.CurrencyAmountTextBox.Text, out currencyAmount) || currencyAmount < 0) { await MessageBoxHelper.ShowMessageDialog("The currency rate must be 0 or greater"); return; } if (string.IsNullOrEmpty(this.CurrencyTimeTextBox.Text) || !int.TryParse(this.CurrencyTimeTextBox.Text, out currencyTime) || currencyTime < 0) { await MessageBoxHelper.ShowMessageDialog("The currency interval must be 0 or greater"); return; } if ((currencyAmount == 0 && currencyTime != 0) || (currencyAmount != 0 && currencyTime == 0)) { await MessageBoxHelper.ShowMessageDialog("The currency rate and interval must be both greater than 0 or both equal to 0"); return; } } int maxAmount = int.MaxValue; if (!string.IsNullOrEmpty(this.CurrencyMaxAmountTextBox.Text) && (!int.TryParse(this.CurrencyMaxAmountTextBox.Text, out maxAmount) || maxAmount <= 0)) { await MessageBoxHelper.ShowMessageDialog("The max amount must be greater than 0 or can be left empty for no max amount"); return; } int subscriberBonus = 0; if (string.IsNullOrEmpty(this.CurrencySubscriberBonusTextBox.Text) || !int.TryParse(this.CurrencySubscriberBonusTextBox.Text, out subscriberBonus) || subscriberBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The Subscriber bonus must be 0 or greater"); return; } int onFollowBonus = 0; if (string.IsNullOrEmpty(this.CurrencyOnFollowBonusTextBox.Text) || !int.TryParse(this.CurrencyOnFollowBonusTextBox.Text, out onFollowBonus) || onFollowBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Follow bonus must be 0 or greater"); return; } int onHostBonus = 0; if (string.IsNullOrEmpty(this.CurrencyOnHostBonusTextBox.Text) || !int.TryParse(this.CurrencyOnHostBonusTextBox.Text, out onHostBonus) || onHostBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Host bonus must be 0 or greater"); return; } int onSubscribeBonus = 0; if (string.IsNullOrEmpty(this.CurrencyOnSubscribeBonusTextBox.Text) || !int.TryParse(this.CurrencyOnSubscribeBonusTextBox.Text, out onSubscribeBonus) || onSubscribeBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Subscribe bonus must be 0 or greater"); return; } if (this.OfflineCurrencyAcquireRateComboBox.SelectedIndex < 0) { await MessageBoxHelper.ShowMessageDialog("The offline currency rate must be selected"); return; } CurrencyAcquireRateTypeEnum offlineAcquireRate = EnumHelper.GetEnumValueFromString <CurrencyAcquireRateTypeEnum>((string)this.OfflineCurrencyAcquireRateComboBox.SelectedItem); int offlineCurrencyAmount = 1; int offlineCurrencyTime = 1; if (offlineAcquireRate == CurrencyAcquireRateTypeEnum.Hours) { offlineCurrencyTime = 60; } else if (offlineAcquireRate == CurrencyAcquireRateTypeEnum.Custom) { if (string.IsNullOrEmpty(this.OfflineCurrencyAmountTextBox.Text) || !int.TryParse(this.OfflineCurrencyAmountTextBox.Text, out offlineCurrencyAmount) || offlineCurrencyAmount < 0) { await MessageBoxHelper.ShowMessageDialog("The offline currency rate must be 0 or greater"); return; } if (string.IsNullOrEmpty(this.OfflineCurrencyTimeTextBox.Text) || !int.TryParse(this.OfflineCurrencyTimeTextBox.Text, out offlineCurrencyTime) || offlineCurrencyTime < 0) { await MessageBoxHelper.ShowMessageDialog("The offline currency interval must be 0 or greater"); return; } if ((offlineCurrencyAmount == 0 && offlineCurrencyTime != 0) || (offlineCurrencyAmount != 0 && offlineCurrencyTime == 0)) { await MessageBoxHelper.ShowMessageDialog("The offline currency rate and interval must be both greater than 0 or both equal to 0"); return; } } if (this.ResetCurrencyComboBox.SelectedIndex < 0) { await MessageBoxHelper.ShowMessageDialog("A reset frequency must be selected"); return; } if (string.IsNullOrEmpty(this.specialIdentifier)) { await MessageBoxHelper.ShowMessageDialog("A currency special identifier must exist. Please ensure your currency name contains letters or numbers."); return; } if (this.isRank) { if (this.ranks.Count() < 1) { await MessageBoxHelper.ShowMessageDialog("At least one rank must be created"); return; } } bool newCurrencyRank = false; if (this.currency == null) { newCurrencyRank = true; this.currency = new UserCurrencyViewModel(); } this.currency.Name = this.CurrencyNameTextBox.Text; this.currency.AcquireAmount = currencyAmount; this.currency.AcquireInterval = currencyTime; this.currency.MaxAmount = maxAmount; this.currency.SubscriberBonus = subscriberBonus; this.currency.OnFollowBonus = onFollowBonus; this.currency.OnHostBonus = onHostBonus; this.currency.OnSubscribeBonus = onSubscribeBonus; this.currency.OfflineAcquireAmount = offlineCurrencyAmount; this.currency.OfflineAcquireInterval = offlineCurrencyTime; this.currency.ResetInterval = EnumHelper.GetEnumValueFromString <CurrencyResetRateEnum>((string)this.ResetCurrencyComboBox.SelectedItem); this.currency.SpecialIdentifier = this.specialIdentifier; if (this.isRank) { this.currency.Ranks = ranks.ToList(); this.currency.RankChangedCommand = this.rankChangedCommand; } if (!ChannelSession.Settings.Currencies.ContainsKey(this.currency.ID)) { ChannelSession.Settings.Currencies[this.currency.ID] = this.currency; } foreach (var kvp in this.userImportData) { kvp.Key.SetCurrencyAmount(this.currency, kvp.Value); } await ChannelSession.SaveSettings(); if (newCurrencyRank) { string type = (this.currency.IsRank) ? "rank" : "currency"; if (await MessageBoxHelper.ShowConfirmationDialog("Since you just created a new " + type + ", would you like to create a chat command to show a user's " + type + "?")) { ChatCommand currencyRankCommand = new ChatCommand(this.currency.Name, this.currency.SpecialIdentifier, new RequirementViewModel(MixerRoleEnum.User, 5)); string chatText = string.Empty; if (this.currency.IsRank) { chatText = string.Format("@$username is a ${0} with ${1} {2}!", this.currency.UserRankNameSpecialIdentifier, this.currency.UserAmountSpecialIdentifier, this.currency.Name); } else { chatText = string.Format("@$username has ${0} {1}!", this.currency.UserAmountSpecialIdentifier, this.currency.Name); } ChatAction chatAction = new ChatAction(chatText); currencyRankCommand.Actions.Add(chatAction); CommandWindow window = new CommandWindow(new ChatCommandDetailsControl(currencyRankCommand)); window.Closed += Window_Closed; window.Show(); window.Focus(); } } this.Close(); }); }
private async void SaveButton_Click(object sender, System.Windows.RoutedEventArgs e) { await this.RunAsyncOperation(async() => { if (string.IsNullOrEmpty(this.CurrencyNameTextBox.Text)) { await MessageBoxHelper.ShowMessageDialog("A currency name must be specified"); return; } UserCurrencyViewModel dupeCurrency = ChannelSession.Settings.Currencies.Values.FirstOrDefault(c => c.Name.Equals(this.CurrencyNameTextBox.Text)); if (dupeCurrency != null && (this.currency == null || !this.currency.ID.Equals(dupeCurrency.ID))) { await MessageBoxHelper.ShowMessageDialog("There already exists a currency or rank system with this name"); return; } if (this.CurrencyAcquireRateComboBox.SelectedIndex < 0) { await MessageBoxHelper.ShowMessageDialog("The currency rate must be selected"); return; } CurrencyAcquireRateTypeEnum acquireRate = EnumHelper.GetEnumValueFromString <CurrencyAcquireRateTypeEnum>((string)this.CurrencyAcquireRateComboBox.SelectedItem); int currencyAmount = 1; int currencyTime = 1; if (acquireRate == CurrencyAcquireRateTypeEnum.Hours) { currencyTime = 60; } else if (acquireRate == CurrencyAcquireRateTypeEnum.Custom) { if (string.IsNullOrEmpty(this.CurrencyAmountTextBox.Text) || !int.TryParse(this.CurrencyAmountTextBox.Text, out currencyAmount) || currencyAmount < 0) { await MessageBoxHelper.ShowMessageDialog("The currency rate must be 0 or greater"); return; } if (string.IsNullOrEmpty(this.CurrencyTimeTextBox.Text) || !int.TryParse(this.CurrencyTimeTextBox.Text, out currencyTime) || currencyTime < 0) { await MessageBoxHelper.ShowMessageDialog("The currency interval must be 0 or greater"); return; } if ((currencyAmount == 0 && currencyTime != 0) || (currencyAmount != 0 && currencyTime == 0)) { await MessageBoxHelper.ShowMessageDialog("The currency rate and interval must be both greater than 0 or both equal to 0"); return; } } int maxAmount = int.MaxValue; if (!string.IsNullOrEmpty(this.CurrencyMaxAmountTextBox.Text) && (!int.TryParse(this.CurrencyMaxAmountTextBox.Text, out maxAmount) || maxAmount <= 0)) { await MessageBoxHelper.ShowMessageDialog("The max amount must be greater than 0 or can be left empty for no max amount"); return; } int subscriberBonus = 0; if (string.IsNullOrEmpty(this.CurrencySubscriberBonusTextBox.Text) || !int.TryParse(this.CurrencySubscriberBonusTextBox.Text, out subscriberBonus) || subscriberBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The Subscriber bonus must be 0 or greater"); return; } int onFollowBonus = 0; if (string.IsNullOrEmpty(this.CurrencyOnFollowBonusTextBox.Text) || !int.TryParse(this.CurrencyOnFollowBonusTextBox.Text, out onFollowBonus) || onFollowBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Follow bonus must be 0 or greater"); return; } int onHostBonus = 0; if (string.IsNullOrEmpty(this.CurrencyOnHostBonusTextBox.Text) || !int.TryParse(this.CurrencyOnHostBonusTextBox.Text, out onHostBonus) || onHostBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Host bonus must be 0 or greater"); return; } int onSubscribeBonus = 0; if (string.IsNullOrEmpty(this.CurrencyOnSubscribeBonusTextBox.Text) || !int.TryParse(this.CurrencyOnSubscribeBonusTextBox.Text, out onSubscribeBonus) || onSubscribeBonus < 0) { await MessageBoxHelper.ShowMessageDialog("The On Subscribe bonus must be 0 or greater"); return; } if (this.ResetCurrencyComboBox.SelectedIndex < 0) { await MessageBoxHelper.ShowMessageDialog("A reset frequency must be selected"); return; } if (string.IsNullOrEmpty(this.specialIdentifier)) { await MessageBoxHelper.ShowMessageDialog("A currency special identifier must exist. Please ensure your currency name contains letters or numbers."); return; } if (this.isRank) { if (this.ranks.Count() < 1) { await MessageBoxHelper.ShowMessageDialog("At least one rank must be created"); return; } } if (this.currency == null) { this.currency = new UserCurrencyViewModel(); } this.currency.Name = this.CurrencyNameTextBox.Text; this.currency.AcquireAmount = currencyAmount; this.currency.AcquireInterval = currencyTime; this.currency.MaxAmount = maxAmount; this.currency.SubscriberBonus = subscriberBonus; this.currency.OnFollowBonus = onFollowBonus; this.currency.OnHostBonus = onHostBonus; this.currency.OnSubscribeBonus = onSubscribeBonus; this.currency.ResetInterval = EnumHelper.GetEnumValueFromString <CurrencyResetRateEnum>((string)this.ResetCurrencyComboBox.SelectedItem); this.currency.SpecialIdentifier = this.specialIdentifier; if (this.isRank) { this.currency.Ranks = ranks.ToList(); } if (!ChannelSession.Settings.Currencies.ContainsKey(this.currency.ID)) { ChannelSession.Settings.Currencies[this.currency.ID] = this.currency; } foreach (var kvp in this.userImportData) { if (ChannelSession.Settings.UserData.ContainsKey(kvp.Key)) { ChannelSession.Settings.UserData[kvp.Key].SetCurrencyAmount(this.currency, kvp.Value); } } await ChannelSession.SaveSettings(); this.Close(); }); }