public ChatChannelSetup(ChatTypeConfiguration chatTypeConfig = null) { InitializeComponent(); foreach (var xivChatType in Enum.GetValues(typeof(XivChatType)).Cast <XivChatType>()) { var details = xivChatType.GetDetails(); if (details == null) { continue; } ChatTypeComboBox.Items.Add(new ChatTypeComboBoxWrapper { Name = details.FancyName, ChatType = xivChatType }); } if (chatTypeConfig != null) { ChatTypeComboBox.SelectedIndex = ChatTypeComboBox.Items.Cast <ChatTypeComboBoxWrapper>() .Select((v, i) => new { Index = i, Value = v }) // Pair up values and indexes .Where(p => p.Value.ChatType == chatTypeConfig.ChatType) // Do the filtering .Select(p => p.Index) .First(); ChannelTypeComboBox.SelectedIndex = (int)chatTypeConfig.Channel.Type; ChannelIdTextBox.Text = chatTypeConfig.Channel.ChannelId.ToString(); ServerIdTextBox.Text = chatTypeConfig.Channel.GuildId.ToString(); ApplyColor(chatTypeConfig.Color); } }
private void NextButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(ChannelIdTextBox.Text)) { Close(); } var comboBoxEntry = ChatTypeComboBox.SelectedItem as ChatTypeComboBoxWrapper; if (!string.IsNullOrEmpty(ChannelIdTextBox.Text) && ulong.TryParse(ChannelIdTextBox.Text, out var channelId)) { var guildId = 0UL; if (ChannelTypeComboBox.SelectedIndex == 0) { if (!string.IsNullOrEmpty(ServerIdTextBox.Text) && ulong.TryParse(ServerIdTextBox.Text, out var parsedGuildId)) { guildId = parsedGuildId; } else { goto inputProblem; } } var channelPrefix = ChannelPrefixTextBox.Text; Result = new ChatTypeConfiguration { Channel = new ChannelConfiguration { ChannelId = channelId, GuildId = guildId, ChannelPrefix = channelPrefix, Type = (ChannelType)ChannelTypeComboBox.SelectedIndex }, Color = _color }; if (comboBoxEntry != null) { Result.ChatType = comboBoxEntry.ChatType; } Close(); return; } inputProblem: MessageBox.Show(Loc.Localize("EnterValidIdsError", "Please enter valid IDs."), "XIVLauncher", MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); }