示例#1
0
        public void Show(Window parent, Point p)
        {
            Console.WriteLine("show");
            if (instance == null)
            {
                instance = Create(parent);
            }

            if (instance != null)
            {
                instance.Left = p.X;
                instance.Top  = p.Y + instance.Height / 2;
                instance.Show();
                instance.Focus();
            }
        }
        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();
            });
        }