using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Dominion.NET_WPF.Controls;
namespace Dominion.NET_WPF
{
///
/// Interaction logic for wSettings.xaml
///
public partial class wSettings : Window
{
private Settings _MasterSettings = null;
private Settings _LocalSettings = null;
public Settings Settings { get { return _LocalSettings; } private set { _LocalSettings = value; } }
public DominionBase.Cards.CardCollection Cards = new DominionBase.Cards.CardCollection();
public Dictionary Groups = new Dictionary();
public Dictionary Costs = new Dictionary();
public wSettings(ref Settings settings)
{
this._MasterSettings = settings;
this.Settings = new NET_WPF.Settings(settings);
this.DataContext = this.Settings;
#region Card & Group generation
this.Cards = DominionBase.Cards.CardCollection.GetAllCards(c => c.Location == DominionBase.Cards.Location.Kingdom);
this.Cards.Sort(delegate(DominionBase.Cards.Card c1, DominionBase.Cards.Card c2) { return c1.Name.CompareTo(c2.Name); });
foreach (DominionBase.Cards.Card card in this.Cards)
{
if (!this.Costs.ContainsKey(card.BaseCost))
this.Costs[card.BaseCost] = 0;
this.Costs[card.BaseCost]++;
foreach (DominionBase.Cards.Group group in Enum.GetValues(typeof(DominionBase.Cards.Group)))
{
if (group == DominionBase.Cards.Group.Basic || group == DominionBase.Cards.Group.None)
continue;
if ((card.GroupMembership & group) == group)
{
if (!Groups.ContainsKey(group))
Groups[group] = 0;
Groups[group]++;
}
}
}
#endregion
InitializeComponent();
#region Tab #1 -- Players
slidNumPlayers.Value = this.Settings.NumberOfPlayers;
slidHumanPlayers.Value = this.Settings.NumberOfHumanPlayers;
IEnumerable aiTypes = DominionBase.Players.PlayerCollection.GetAllAIs();
IEnumerable playerSettings = spPlayers.Children.OfType();
for (int count = 0; count < this.Settings.PlayerSettings.Count; count++)
{
playerSettings.ElementAt(count).AITypes = aiTypes;
playerSettings.ElementAt(count).PlayerSettings = this.Settings.PlayerSettings[count];
}
// For now, limit the number of human players to 1
slidHumanPlayers.Maximum = 1;
slidNumPlayers_ValueChanged(slidNumPlayers, null);
slidHumanPlayers_ValueChanged(slidHumanPlayers, null);
#endregion
#region Tab #2 -- Automation
if (this.Settings.AutoPlayTreasures_LoanFirst)
rbChooser_AutomaticallyPlayTreasuresLoanBeforeVenture.IsChecked = true;
else
rbChooser_AutomaticallyPlayTreasuresVentureBeforeLoan.IsChecked = true;
if (this.Settings.AutoPlayTreasures_HornOfPlentyFirst)
rbChooser_AutomaticallyPlayTreasuresHornOfPlentyBeforeBank.IsChecked = true;
else
rbChooser_AutomaticallyPlayTreasuresBankBeforeHornOfPlenty.IsChecked = true;
#endregion
#region Tab #3 -- Interface
cbLayoutStyle.SelectedValue = this.Settings.LayoutStyle;
slidToolTipDuration_ValueChanged(slidToolTipDuration, null);
#endregion
#region Tab #4 -- Kingdom Card Setup
cbUsePreset.IsChecked = this.Settings.UsePreset;
cbShowPresetCards.IsChecked = this.Settings.Settings_ShowPresetCards;
cbUsePreset_Checked(cbUsePreset, null);
cbShowPresetCards_Checked(cbShowPresetCards, null);
ucccConstraints.ConstraintCollection = this.Settings.Constraints;
cbPresets.ItemsSource = this.Settings.Presets;
cbPresets.SelectedItem = this.Settings.Presets.SingleOrDefault(p => p.Name == this.Settings.PresetName);
#endregion
#region Tab #5 -- Card Settings
foreach (DominionBase.Cards.CardsSettings cardsSettings in this.Settings.CardSettings)
icCardSettings.Items.Add(new ucCardSettings { CardsSettings = cardsSettings });
#endregion
#region Tab #6 -- Set & Group Information
IEnumerable sets = Enum.GetValues(typeof(DominionBase.Cards.Source)).Cast();
cbSet.ItemsSource = sets.Where(s => s != DominionBase.Cards.Source.All);
IEnumerable categories = Enum.GetValues(typeof(DominionBase.Cards.Category)).Cast();
cbCategory.ItemsSource = categories.Where(c => c != DominionBase.Cards.Category.Unknown && c != DominionBase.Cards.Category.Prize);
cbGroup.ItemsSource = this.Groups.OrderBy(kvp => (int)kvp.Key);
#endregion
}
private void slidNumPlayers_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
Slider slider = sender as Slider;
if (tbPlayersNum != null)
tbPlayersNum.Text = slider.Value.ToString();
if (this.Settings != null)
{
if (slidHumanPlayers != null)
{
this.Settings.NumberOfPlayers = (int)slider.Value;
if (textBox1 != null)
{
if (slider.Value == 1 && textBox1.Text.EndsWith("s"))
textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
if (slider.Value != 1 && !textBox1.Text.EndsWith("s"))
textBox1.Text += "s";
}
slidHumanPlayers.Value = this.Settings.NumberOfHumanPlayers;
slidHumanPlayers.Maximum = this.Settings.NumberOfPlayers;
// For now, limit the number of human players to 1
slidHumanPlayers.Maximum = 1;
}
}
}
private void slidHumanPlayers_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
Slider slider = sender as Slider;
if (tbPlayersHuman != null)
tbPlayersHuman.Text = slider.Value.ToString();
if (this.Settings != null)
{
if (textBox2 != null)
{
this.Settings.NumberOfHumanPlayers = (int)slider.Value;
if (slider.Value == 1 && textBox2.Text.EndsWith("s"))
textBox2.Text = textBox2.Text.Remove(textBox2.Text.Length - 1);
if (slider.Value != 1 && !textBox2.Text.EndsWith("s"))
textBox2.Text += "s";
}
if (spPlayers != null)
{
for (int count = 0; count < this.Settings.PlayerSettings.Count; count++)
{
DominionBase.Players.PlayerType pt = DominionBase.Players.PlayerType.Computer;
if (this.Settings.NumberOfHumanPlayers > count)
pt = DominionBase.Players.PlayerType.Human;
spPlayers.Children.OfType().ElementAt(count).PlayerType = pt;
}
}
}
}
private void bOk_Click(object sender, RoutedEventArgs e)
{
IEnumerable ucPSs = spPlayers.Children.OfType();
for (int count = 0; count < this.Settings.PlayerSettings.Count; count++)
{
this.Settings.PlayerSettings[count] = ucPSs.ElementAt(count).PlayerSettings;
}
this.Settings.LayoutStyle = (LayoutStyle)cbLayoutStyle.SelectedValue;
this._MasterSettings.CopyFrom(this.Settings);
this.DialogResult = true;
this.Close();
}
private void cbUsePreset_Checked(object sender, RoutedEventArgs e)
{
this.Settings.UsePreset = (cbUsePreset.IsChecked == true);
if (this.Settings.UsePreset)
{
gbCardConstraints.IsEnabled = false;
gbCardConstraints.ToolTip = "This section is disabled if you're using a preset";
}
else
{
gbCardConstraints.IsEnabled = true;
gbCardConstraints.ToolTip = null;
}
}
private void cbShowPresetCards_Checked(object sender, RoutedEventArgs e)
{
this.Settings.Settings_ShowPresetCards = (cbShowPresetCards.IsChecked == true);
cbPresets_SelectionChanged(cbPresets, null);
}
private void slidToolTipDuration_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
Slider slider = sender as Slider;
if (tbToolTipDuration != null)
{
tbToolTipDuration.Text = ((int)this.Settings.ToolTipShowDuration / 1000).ToString();
if (this.Settings.ToolTipShowDuration == ToolTipShowDuration.Off)
tbToolTipExtra.Text = "(Off)";
else
tbToolTipExtra.Text = String.Empty;
}
}
private void cbToolTipClick_Checked(object sender, RoutedEventArgs e)
{
if ((sender as CheckBox).IsChecked == true)
slidToolTipDuration.Value = 1;
}
private void cbPresets_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
DominionBase.Cards.Preset selectedPreset = (sender as ComboBox).SelectedItem as DominionBase.Cards.Preset;
if (selectedPreset != null)
this.Settings.PresetName = selectedPreset.Name;
if (selectedPreset == null || !this.Settings.Settings_ShowPresetCards)
{
olCardsUsed.Objects = null;
olCardsUsed.Visibility = System.Windows.Visibility.Collapsed;
}
else
{
List