private void cbContinent_SelectionChanged(object sender, SelectionChangedEventArgs e) { Continent continent = (Continent)cbContinent.SelectedItem; if (continent.Regions.Count == 0) { cbRegion.Items.Clear(); cbRegion.Items.Add(Regions.GetRegion("100")); foreach (Region region in Regions.GetRegions().FindAll(r => Airlines.GetAirlines(r).Count > 0).OrderBy(r => r.Name)) { cbRegion.Items.Add(region); } } else { cbRegion.Items.Clear(); if (continent.Regions.Count > 1) { cbRegion.Items.Add(Regions.GetRegion("100")); } foreach (Region region in continent.Regions.FindAll(r => Airlines.GetAirlines(r).Count > 0).OrderBy(r => r.Name)) { cbRegion.Items.Add(region); } } }
//calculates AI airline average on-time % public static Dictionary <Airline, Double> GetAIonTime() { Dictionary <Airline, Double> aiOnTime = new Dictionary <Airline, double>(); foreach (Airline airline in Airlines.GetAirlines(a => !a.IsHuman)) { double otp = airline.Statistics.getStatisticsValue(StatisticsTypes.GetStatisticsType("On-Time%")); aiOnTime.Add(airline, otp); } return(aiOnTime); }
//returns dictionary of AI average fill degrees public static Dictionary <Airline, Double> GetAIFillDegree() { Dictionary <Airline, Double> AIafd = new Dictionary <Airline, double>(); foreach (Airline airline in Airlines.GetAirlines(a => !a.IsHuman)) { List <Double> AIFillDegree = (from r in airline.Routes select r.getFillingDegree()).ToList(); AIafd.Add(airline, AIFillDegree.DefaultIfEmpty(0).Average()); } return(AIafd); }
public PageAirlineData(StartDataObject startData) { this.AllTimeZones = TimeZones.GetTimeZones(); this.AllAirports = new ObservableCollection <Airport>(); this.StartData = startData; InitializeComponent(); var airlines = Airlines.GetAirlines(airline => (airline.Profile.Country.Region == this.StartData.Region || (this.StartData.Region.Uid == "100" && this.StartData.Continent.Uid == "100") || (this.StartData.Region.Uid == "100" && this.StartData.Continent.hasRegion(airline.Profile.Country.Region))) && airline.Profile.Founded <= this.StartData.Year && airline.Profile.Folded > this.StartData.Year).OrderBy(a => a.Profile.Name).ToList(); cbAirline.ItemsSource = airlines; }
public PageSelectOpponents(StartDataObject sdo) { this.StartData = sdo; this.SelectedAirlines = new ObservableCollection <Airline>(); this.Opponents = new ObservableCollection <Airline>(); foreach (Airline airline in Airlines.GetAirlines(a => a.Profile.Founded <= this.StartData.Year && a.Profile.Folded > this.StartData.Year && a != this.StartData.Airline && (a.Profile.Country.Region == this.StartData.Region || (this.StartData.Continent != null && (this.StartData.Continent.Uid == "100" || this.StartData.Continent.hasRegion(a.Profile.Country.Region)))))) { this.Opponents.Add(airline); } InitializeComponent(); }
private void btnLoadAirline_Click(object sender, RoutedEventArgs e) { string directory = AppSettings.getCommonApplicationDataPath() + "\\custom airlines"; Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".xml"; dlg.Filter = "Airline XMLs (.xml)|*.xml"; dlg.InitialDirectory = System.IO.Path.GetFullPath(directory); dlg.Multiselect = false; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { string path = dlg.FileName; Airline airline = Setup.LoadAirline(path); string imagePath = string.Format("{0}\\{1}.png", directory, airline.Profile.IATACode); if (File.Exists(imagePath)) { airline.Profile.addLogo(new AirlineLogo(imagePath)); } else { airline.Profile.addLogo(new AirlineLogo(AppSettings.getDataPath() + "\\graphics\\airlinelogos\\default.png")); } if (Airlines.GetAirline(airline.Profile.IATACode) != null) { Airlines.RemoveAirlines(a => a.Profile.IATACode == airline.Profile.IATACode); } Airlines.AddAirline(airline); var airlines = Airlines.GetAirlines(a => (a.Profile.Country.Region == this.StartData.Region || (this.StartData.Region.Uid == "100" && this.StartData.Continent.Uid == "100") || (this.StartData.Region.Uid == "100" && this.StartData.Continent.hasRegion(a.Profile.Country.Region))) && a.Profile.Founded <= this.StartData.Year && a.Profile.Folded > this.StartData.Year).OrderBy(a => a.Profile.Name).ToList(); cbAirline.ItemsSource = airlines; WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2409"), Translator.GetInstance().GetString("MessageBox", "2409", "message"), WPFMessageBoxButtons.Ok); if (cbAirline.Items.Contains(airline)) { cbAirline.SelectedItem = airline; } } }
//sets the number of opponents private void setNumberOfOpponents() { if (cbYear.SelectedItem != null && cbRegion.SelectedItem != null && cbContinent.SelectedItem != null) { int year = (int)cbYear.SelectedItem; Region region = (Region)cbRegion.SelectedItem; Continent continent = (Continent)cbContinent.SelectedItem; var airlines = Airlines.GetAirlines(airline => (airline.Profile.Country.Region == region || (region.Uid == "100" && continent.Uid == "100") || (region.Uid == "100" && continent.hasRegion(airline.Profile.Country.Region))) && airline.Profile.Founded <= year && airline.Profile.Folded > year); cbOpponents.Items.Clear(); for (int i = 0; i < airlines.Count; i++) { cbOpponents.Items.Add(i); } cbOpponents.SelectedIndex = Math.Min(cbOpponents.Items.Count - 1, 3); } }
//calculates average AI ticket price public static double GetAIAvgTicketPPD() { List <Double> AIPrices = new List <Double>(); List <Double> priceDiff = new List <Double>(); foreach (Airline airline in Airlines.GetAirlines(a => !a.IsHuman)) { List <Double> aiEconPrices = (from r in airline.Routes where r.Type == Route.RouteType.Passenger || r.Type == Route.RouteType.Mixed select((PassengerRoute)r).getFarePrice(AirlinerModel.AirlinerClass.ClassType.Economy_Class)).ToList(); List <Double> aiBusPrices = (from r in airline.Routes where r.Type == Route.RouteType.Passenger || r.Type == Route.RouteType.Mixed select((PassengerRoute)r).getFarePrice(AirlinerModel.AirlinerClass.ClassType.Business_Class)).ToList(); List <Double> aiFirstPrices = (from r in airline.Routes where r.Type == Route.RouteType.Passenger || r.Type == Route.RouteType.Mixed select((PassengerRoute)r).getFarePrice(AirlinerModel.AirlinerClass.ClassType.First_Class)).ToList(); double distance = (from r in airline.Routes select MathHelpers.GetDistance(r.Destination1, r.Destination2)).DefaultIfEmpty(0).Average(); double avgEP = aiEconPrices.DefaultIfEmpty(0).Average(); double avgBP = aiBusPrices.DefaultIfEmpty(0).Average(); double avgFP = aiFirstPrices.DefaultIfEmpty(0).Average(); double avgPrice = ((avgEP * 0.7) + (avgBP * 0.2) + (avgFP * 0.1)) / 3; double avgDistPrice = avgPrice / distance; AIPrices.Add(avgDistPrice); } return(AIPrices.DefaultIfEmpty(0).Average()); }
//creates the stats panel private void createStats() { lbToUpdate = new List <ListBox>(); panelStats.Children.Clear(); panelStats.Children.Add(createStatisticsPanel(StatisticsTypes.GetStatisticsType("Arrivals"), false)); panelStats.Children.Add(createStatisticsPanel(StatisticsTypes.GetStatisticsType("Passengers"), false)); panelStats.Children.Add(createStatisticsPanel(StatisticsTypes.GetStatisticsType("Passengers%"), false)); Boolean hasCargoAirline = Airlines.GetAirlines(a => a.AirlineRouteFocus == Model.AirlinerModel.RouteModel.Route.RouteType.Cargo).Count > 0; if (hasCargoAirline) { panelStats.Children.Add(createStatisticsPanel(StatisticsTypes.GetStatisticsType("Cargo"), false)); panelStats.Children.Add(createStatisticsPanel(StatisticsTypes.GetStatisticsType("Cargo%"), false)); } panelStats.Children.Add(createStatisticsPanel(StatisticsTypes.GetStatisticsType("On-Time%"), true)); panelStats.Children.Add(createStatisticsPanel(StatisticsTypes.GetStatisticsType("Cancellation%"), true)); }
//creates a new game private void createNewGame() { if (txtName.Text.Trim().Length > 2) { object o = null; int startYear = (int)cbStartYear.SelectedItem; int opponents = (int)cbOpponents.SelectedItem; Airline airline = (Airline)cbAirline.SelectedItem; Continent continent = (Continent)cbContinent.SelectedItem; Region region = (Region)cbRegion.SelectedItem; if (this.OpponentType == OpponentSelect.User) { if (cbSameRegion.IsChecked.Value) { o = PopUpSelectOpponents.ShowPopUp(airline, opponents, startYear, airline.Profile.Country.Region); } else { o = PopUpSelectOpponents.ShowPopUp(airline, opponents, startYear, region, continent); } } // popUpSplash.IsOpen = true; DoEvents(); GameTimeZone gtz = (GameTimeZone)cbTimeZone.SelectedItem; GameObject.GetInstance().DayRoundEnabled = cbDayTurnEnabled.IsChecked.Value; GameObject.GetInstance().TimeZone = gtz; GameObject.GetInstance().Difficulty = (DifficultyLevel)cbDifficulty.SelectedItem; GameObject.GetInstance().GameTime = new DateTime(startYear, 1, 1); GameObject.GetInstance().StartDate = GameObject.GetInstance().GameTime; //sets the fuel price GameObject.GetInstance().FuelPrice = Inflations.GetInflation(GameObject.GetInstance().GameTime.Year).FuelPrice; airline.Profile.Country = (Country)cbCountry.SelectedItem; airline.Profile.CEO = txtName.Text.Trim(); GameObject.GetInstance().setHumanAirline(airline); GameObject.GetInstance().MainAirline = GameObject.GetInstance().HumanAirline; if (cbLocalCurrency.IsChecked.Value) { GameObject.GetInstance().CurrencyCountry = airline.Profile.Country; } // AppSettings.GetInstance().resetCurrencyFormat(); Airport airport = (Airport)cbAirport.SelectedItem; AirportHelpers.RentGates(airport, airline, 2); AirportFacility checkinFacility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.CheckIn).Find(f => f.TypeLevel == 1); AirportFacility facility = AirportFacilities.GetFacilities(AirportFacility.FacilityType.Service).Find((delegate(AirportFacility f) { return(f.TypeLevel == 1); })); airport.addAirportFacility(GameObject.GetInstance().HumanAirline, facility, GameObject.GetInstance().GameTime); airport.addAirportFacility(GameObject.GetInstance().HumanAirline, checkinFacility, GameObject.GetInstance().GameTime); if (continent.Uid != "100" || region.Uid != "100") { var airlines = Airlines.GetAirlines(a => a.Profile.Country.Region == region || (region.Uid == "100" && continent.hasRegion(a.Profile.Country.Region)) && a.Profile.Founded <= startYear && a.Profile.Folded > startYear); var airports = Airports.GetAirports(a => a.Profile.Country.Region == region || (region.Uid == "100" && continent.hasRegion(a.Profile.Country.Region)) && a.Profile.Period.From.Year <= startYear && a.Profile.Period.To.Year > startYear); //Airports.RemoveAirports(a => (a.Profile.Country.Region != region && !continent.hasRegion(a.Profile.Country.Region)) || (a.Profile.Town.State != null && a.Profile.Town.State.IsOverseas)); Airports.Clear(); foreach (Airport a in airports) { Airports.AddAirport(a); } Airlines.Clear(); foreach (Airline a in airlines) { Airlines.AddAirline(a); } } PassengerHelpers.CreateAirlineDestinationDemand(); AirlinerHelpers.CreateStartUpAirliners(); if (this.OpponentType == OpponentSelect.Random || o == null) { Setup.SetupMainGame(opponents, cbSameRegion.IsChecked.Value); } else { Setup.SetupMainGame((List <Airline>)o); } airline.MarketFocus = (Airline.AirlineFocus)cbFocus.SelectedItem; GeneralHelpers.CreateHolidays(GameObject.GetInstance().GameTime.Year); //PassengerHelpers.CreateDestinationPassengers(); GameObjectWorker.GetInstance().start(); // AIWorker.GetInstance().start(); PageNavigator.NavigateTo(new PageAirline(GameObject.GetInstance().HumanAirline)); PageNavigator.ClearNavigator(); //GameObject.GetInstance().HumanAirline.Money = 10000000000000; GameObject.GetInstance().NewsBox.addNews(new News(News.NewsType.Standard_News, GameObject.GetInstance().GameTime, Translator.GetInstance().GetString("News", "1001"), string.Format(Translator.GetInstance().GetString("News", "1001", "message"), GameObject.GetInstance().HumanAirline.Profile.CEO, GameObject.GetInstance().HumanAirline.Profile.IATACode))); popUpSplash.IsOpen = false; Action action = () => { Stopwatch swPax = new Stopwatch(); swPax.Start(); PassengerHelpers.CreateDestinationDemand(); Console.WriteLine("Demand have been created in {0} ms.", swPax.ElapsedMilliseconds); swPax.Stop(); }; Task.Factory.StartNew(action); //Task.Run(action); //Task t2 = Task.Factory.StartNew(action, "passengers"); } else { WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2403"), Translator.GetInstance().GetString("MessageBox", "2403"), WPFMessageBoxButtons.Ok); } }
public PageNewGame() { OpponentType = OpponentSelect.Random; InitializeComponent(); popUpSplash = new Popup(); popUpSplash.Child = UICreator.CreateSplashWindow(); popUpSplash.Placement = PlacementMode.Center; popUpSplash.PlacementTarget = PageNavigator.MainWindow; popUpSplash.IsOpen = false; StackPanel panelContent = new StackPanel(); panelContent.Margin = new Thickness(10, 0, 10, 0); panelContent.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; Panel panelLogo = UICreator.CreateGameLogo(); panelLogo.Margin = new Thickness(0, 0, 0, 20); panelContent.Children.Add(panelLogo); TextBlock txtHeader = new TextBlock(); txtHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtHeader.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush2"); txtHeader.FontWeight = FontWeights.Bold; txtHeader.Uid = "1001"; txtHeader.Text = Translator.GetInstance().GetString("PageNewGame", txtHeader.Uid); panelContent.Children.Add(txtHeader); lbContentBasics = new ListBox(); lbContentBasics.ItemContainerStyleSelector = new ListBoxItemStyleSelector(); lbContentBasics.SetResourceReference(ListBox.ItemTemplateProperty, "QuickInfoItem"); lbContentBasics.MaxHeight = GraphicsHelpers.GetContentHeight() / 2; txtNarrative = new TextBox(); txtNarrative.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; txtNarrative.VerticalAlignment = System.Windows.VerticalAlignment.Center; txtNarrative.Background = Brushes.Transparent; txtNarrative.TextWrapping = TextWrapping.Wrap; txtNarrative.FontStyle = FontStyles.Italic; txtNarrative.Width = 500; txtNarrative.Height = 100; txtNarrative.Uid = "1015"; txtNarrative.IsReadOnly = true; txtNarrative.Text = Translator.GetInstance().GetString("PageNewGame", txtNarrative.Uid); txtNarrative.Visibility = System.Windows.Visibility.Collapsed; panelContent.Children.Add(txtNarrative); panelContent.Children.Add(lbContentBasics); lbContentHuman = new ListBox(); lbContentHuman.Visibility = System.Windows.Visibility.Collapsed; lbContentHuman.SetResourceReference(ListBox.ItemTemplateProperty, "QuickInfoItem"); lbContentHuman.MaxHeight = GraphicsHelpers.GetContentHeight() / 2; lbContentHuman.Visibility = System.Windows.Visibility.Collapsed; panelContent.Children.Add(lbContentHuman); cbContinent = new ComboBox(); cbContinent.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbContinent.Width = 200; cbContinent.DisplayMemberPath = "Name"; cbContinent.SelectedValuePath = "Name"; cbContinent.Items.Add(new Continent("100", "All continents")); foreach (Continent continent in Continents.GetContinents().OrderBy(c => c.Name)) { cbContinent.Items.Add(continent); } cbContinent.SelectionChanged += cbContinent_SelectionChanged; lbContentBasics.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1022"), cbContinent)); cbRegion = new ComboBox(); cbRegion.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbRegion.Width = 200; cbRegion.DisplayMemberPath = "Name"; cbRegion.SelectedValuePath = "Name"; cbRegion.Items.Add(Regions.GetRegion("100")); foreach (Region region in Regions.GetRegions().FindAll(r => Airlines.GetAirlines(r).Count > 0).OrderBy(r => r.Name)) { cbRegion.Items.Add(region); } cbRegion.SelectionChanged += new SelectionChangedEventHandler(cbRegion_SelectionChanged); lbContentBasics.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1012"), cbRegion)); // chs, 2011-19-10 added for the possibility of creating a new airline WrapPanel panelAirline = new WrapPanel(); cbAirline = new ComboBox(); cbAirline.SetResourceReference(ComboBox.ItemTemplateProperty, "AirlineLogoItem"); cbAirline.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbAirline.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; cbAirline.SelectionChanged += new SelectionChangedEventHandler(cbAirline_SelectionChanged); cbAirline.Width = 200; List <Airline> airlines = Airlines.GetAllAirlines(); airlines.Sort((delegate(Airline a1, Airline a2) { return(a1.Profile.Name.CompareTo(a2.Profile.Name)); })); cbAirline.ItemsSource = airlines; panelAirline.Children.Add(cbAirline); Button btnAddAirline = new Button(); btnAddAirline.Margin = new Thickness(5, 0, 0, 0); btnAddAirline.Background = Brushes.Transparent; btnAddAirline.Click += new RoutedEventHandler(btnAddAirline_Click); Image imgAddAirline = new Image(); imgAddAirline.Source = new BitmapImage(new Uri(@"/Data/images/add.png", UriKind.RelativeOrAbsolute)); imgAddAirline.Height = 16; RenderOptions.SetBitmapScalingMode(imgAddAirline, BitmapScalingMode.HighQuality); btnAddAirline.Content = imgAddAirline; panelAirline.Children.Add(btnAddAirline); lbContentHuman.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1002"), panelAirline)); txtIATA = UICreator.CreateTextBlock(""); lbContentHuman.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1003"), txtIATA)); txtAirlineType = UICreator.CreateTextBlock(""); lbContentHuman.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1021"), txtAirlineType)); StackPanel panelCountry = new StackPanel(); cbCountry = new ComboBox(); cbCountry.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbCountry.SetResourceReference(ComboBox.ItemTemplateProperty, "CountryFlagLongItem"); cbCountry.Width = 150; cbCountry.SelectionChanged += cbCountry_SelectionChanged; panelCountry.Children.Add(cbCountry); cbLocalCurrency = new CheckBox(); cbLocalCurrency.FlowDirection = System.Windows.FlowDirection.RightToLeft; cbLocalCurrency.Content = Translator.GetInstance().GetString("PageNewGame", "1014"); cbLocalCurrency.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; cbLocalCurrency.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; panelCountry.Children.Add(cbLocalCurrency); lbContentHuman.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1004"), panelCountry)); txtName = new TextBox(); txtName.Background = Brushes.Transparent; txtName.BorderBrush = Brushes.Black; txtName.Width = 200; lbContentHuman.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1005"), txtName)); // chs, 2011-19-10 added to show the airline color airlineColorRect = new Rectangle(); airlineColorRect.Width = 40; airlineColorRect.Height = 20; airlineColorRect.StrokeThickness = 1; airlineColorRect.Stroke = Brushes.Black; airlineColorRect.Fill = new AirlineBrushConverter().Convert(Airlines.GetAirline("ZA")) as Brush; airlineColorRect.Margin = new Thickness(0, 2, 0, 2); lbContentHuman.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1006"), airlineColorRect)); cbAirport = new ComboBox(); cbAirport.SetResourceReference(ComboBox.ItemTemplateProperty, "AirportCountryItem"); cbAirport.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbAirport.IsSynchronizedWithCurrentItem = true; cbAirport.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; cbAirport.SelectionChanged += new SelectionChangedEventHandler(cbAirports_SelectionChanged); List <Airport> airportsList = Airports.GetAllAirports(); airportsView = CollectionViewSource.GetDefaultView(airportsList); airportsView.SortDescriptions.Add(new SortDescription("Profile.Name", ListSortDirection.Ascending)); cbAirport.ItemsSource = airportsView; lbContentHuman.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1007"), cbAirport)); cbStartYear = new ComboBox(); cbStartYear.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbStartYear.Width = 60; for (int i = GameObject.StartYear; i < DateTime.Now.Year + 2; i++) { cbStartYear.Items.Add(i); } cbStartYear.SelectionChanged += new SelectionChangedEventHandler(cbStartYear_SelectionChanged); lbContentBasics.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1008"), cbStartYear)); cbTimeZone = new ComboBox(); cbTimeZone.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbTimeZone.Width = 300; cbTimeZone.DisplayMemberPath = "DisplayName"; cbTimeZone.SelectedValuePath = "DisplayName"; foreach (GameTimeZone gtz in TimeZones.GetTimeZones()) { cbTimeZone.Items.Add(gtz); } cbTimeZone.SelectedItem = TimeZones.GetTimeZones().Find(delegate(GameTimeZone gtz) { return(gtz.UTCOffset == new TimeSpan(0, 0, 0)); }); lbContentHuman.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1009"), cbTimeZone)); cbFocus = new ComboBox(); cbFocus.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbFocus.Width = 100; foreach (Airline.AirlineFocus focus in Enum.GetValues(typeof(Airline.AirlineFocus))) { cbFocus.Items.Add(focus); } cbFocus.SelectedIndex = 0; lbContentBasics.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1013"), cbFocus)); WrapPanel panelDifficulty = new WrapPanel(); cbDifficulty = new ComboBox(); cbDifficulty.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbDifficulty.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; cbDifficulty.Width = 100; cbDifficulty.DisplayMemberPath = "Name"; cbDifficulty.SelectedValuePath = "Name"; foreach (DifficultyLevel difficulty in DifficultyLevels.GetDifficultyLevels()) { cbDifficulty.Items.Add(difficulty); } cbDifficulty.SelectedIndex = 0; panelDifficulty.Children.Add(cbDifficulty); Button btnAddDifficulty = new Button(); btnAddDifficulty.Margin = new Thickness(5, 0, 0, 0); btnAddDifficulty.Background = Brushes.Transparent; btnAddDifficulty.Click += new RoutedEventHandler(btnAddDifficulty_Click); Image imgAddDifficulty = new Image(); imgAddDifficulty.Source = new BitmapImage(new Uri(@"/Data/images/add.png", UriKind.RelativeOrAbsolute)); imgAddDifficulty.Height = 16; RenderOptions.SetBitmapScalingMode(imgAddDifficulty, BitmapScalingMode.HighQuality); btnAddDifficulty.Content = imgAddDifficulty; panelDifficulty.Children.Add(btnAddDifficulty); lbContentBasics.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1011"), panelDifficulty)); WrapPanel panelOpponents = new WrapPanel(); cbOpponents = new ComboBox(); cbOpponents.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbOpponents.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; cbOpponents.Width = 50; cbOpponents.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right; for (int i = 0; i < Airlines.GetAllAirlines().Count; i++) { cbOpponents.Items.Add(i); } cbOpponents.SelectedIndex = 3; panelOpponents.Children.Add(cbOpponents); cbSameRegion = new CheckBox(); cbSameRegion.FlowDirection = System.Windows.FlowDirection.RightToLeft; cbSameRegion.Content = Translator.GetInstance().GetString("PageNewGame", "1017"); cbSameRegion.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; cbSameRegion.Margin = new Thickness(5, 0, 0, 0); panelOpponents.Children.Add(cbSameRegion); lbContentBasics.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1010"), panelOpponents)); WrapPanel panelOpponentSelect = new WrapPanel(); RadioButton rbRandomOpponents = new RadioButton(); rbRandomOpponents.IsChecked = true; rbRandomOpponents.GroupName = "Opponent"; rbRandomOpponents.Content = Translator.GetInstance().GetString("PageNewGame", "1018"); rbRandomOpponents.Checked += rbRandomOpponents_Checked; panelOpponentSelect.Children.Add(rbRandomOpponents); RadioButton rbSelectOpponents = new RadioButton(); rbSelectOpponents.GroupName = "Opponent"; rbSelectOpponents.Content = Translator.GetInstance().GetString("PageNewGame", "1019"); rbSelectOpponents.Checked += rbSelectOpponents_Checked; rbSelectOpponents.Margin = new Thickness(5, 0, 0, 0); panelOpponentSelect.Children.Add(rbSelectOpponents); lbContentBasics.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1020"), panelOpponentSelect)); cbDayTurnEnabled = new CheckBox(); cbDayTurnEnabled.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; cbDayTurnEnabled.IsChecked = true; lbContentBasics.Items.Add(new QuickInfoValue(Translator.GetInstance().GetString("PageNewGame", "1016"), cbDayTurnEnabled)); WrapPanel panelButtons = new WrapPanel(); panelButtons.Margin = new Thickness(0, 5, 0, 0); panelContent.Children.Add(panelButtons); btnCreate = new Button(); btnCreate.SetResourceReference(Button.StyleProperty, "RoundedButton"); btnCreate.Click += new RoutedEventHandler(btnCreate_Click); btnCreate.Height = Double.NaN; btnCreate.Width = Double.NaN; btnCreate.Uid = "203"; btnCreate.Content = Translator.GetInstance().GetString("PageNewGame", btnCreate.Uid); btnCreate.SetResourceReference(Button.BackgroundProperty, "ButtonBrush"); panelButtons.Children.Add(btnCreate); btnBack = new Button(); btnBack.SetResourceReference(Button.StyleProperty, "RoundedButton"); btnBack.Height = Double.NaN; btnBack.Width = Double.NaN; btnBack.Uid = "119"; btnBack.Content = Translator.GetInstance().GetString("General", btnBack.Uid); btnBack.SetResourceReference(Button.BackgroundProperty, "ButtonBrush"); btnBack.Margin = new Thickness(5, 0, 0, 0); btnBack.Click += btnBack_Click; btnBack.Visibility = System.Windows.Visibility.Collapsed; panelButtons.Children.Add(btnBack); Button btnExit = new Button(); btnExit.SetResourceReference(Button.StyleProperty, "RoundedButton"); btnExit.Height = double.NaN; btnExit.Width = double.NaN; btnExit.Uid = "202"; btnExit.Content = Translator.GetInstance().GetString("PageNewGame", btnExit.Uid); btnExit.Margin = new Thickness(5, 0, 0, 0); btnExit.Click += new RoutedEventHandler(btnCancel_Click); btnExit.SetResourceReference(Button.BackgroundProperty, "ButtonBrush"); panelButtons.Children.Add(btnExit); base.setTopMenu(new PageTopMenu()); base.hideNavigator(); base.hideBottomMenu(); base.setContent(panelContent); base.setHeaderContent(Translator.GetInstance().GetString("PageNewGame", "200")); cbStartYear.SelectedItem = DateTime.Now.Year; showPage(this); }
public PopUpSelectOpponents(Airline human, int opponents, int startyear, Region region, Continent continent) { this.Human = human; this.Opponents = opponents; this.StartYear = startyear; InitializeComponent(); this.Uid = "1000"; this.Title = Translator.GetInstance().GetString("PopUpSelectOpponents", this.Uid); this.Width = 500; this.Height = 500; this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; StackPanel panelMain = new StackPanel(); Grid grdMain = UICreator.CreateGrid(2); panelMain.Children.Add(grdMain); StackPanel panelSelectAirlines = new StackPanel(); panelSelectAirlines.Margin = new Thickness(5, 0, 5, 0); TextBlock txtSelectedHeader = new TextBlock(); txtSelectedHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtSelectedHeader.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush"); txtSelectedHeader.FontWeight = FontWeights.Bold; txtSelectedHeader.Uid = "1001"; txtSelectedHeader.Text = string.Format(Translator.GetInstance().GetString("PopUpSelectOpponents", txtSelectedHeader.Uid), this.Opponents); panelSelectAirlines.Children.Add(txtSelectedHeader); lbSelectedAirlines = new ListBox(); lbSelectedAirlines.ItemContainerStyleSelector = new ListBoxItemStyleSelector(); lbSelectedAirlines.SetResourceReference(ListBox.ItemTemplateProperty, "AirlineLogoItem"); lbSelectedAirlines.MaxHeight = 400; lbSelectedAirlines.SelectionChanged += lbSelectedAirlines_SelectionChanged; panelSelectAirlines.Children.Add(lbSelectedAirlines); Grid.SetColumn(panelSelectAirlines, 0); grdMain.Children.Add(panelSelectAirlines); StackPanel panelOpponents = new StackPanel(); panelOpponents.Margin = new Thickness(5, 0, 5, 0); TextBlock txtOpponentsHeader = new TextBlock(); txtOpponentsHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; txtOpponentsHeader.SetResourceReference(TextBlock.BackgroundProperty, "HeaderBackgroundBrush"); txtOpponentsHeader.FontWeight = FontWeights.Bold; txtOpponentsHeader.Uid = "1002"; txtOpponentsHeader.Text = Translator.GetInstance().GetString("PopUpSelectOpponents", txtOpponentsHeader.Uid); panelOpponents.Children.Add(txtOpponentsHeader); lbOpponentAirlines = new ListBox(); lbOpponentAirlines.ItemContainerStyleSelector = new ListBoxItemStyleSelector(); lbOpponentAirlines.SetResourceReference(ListBox.ItemTemplateProperty, "AirlineLogoItem"); lbOpponentAirlines.MaxHeight = 400; lbOpponentAirlines.SelectionChanged += lbOpponentAirlines_SelectionChanged; panelOpponents.Children.Add(lbOpponentAirlines); foreach (Airline airline in Airlines.GetAirlines(a => a.Profile.Founded <= startyear && a.Profile.Folded > startyear && a != this.Human && (a.Profile.Country.Region == region || (continent != null && (continent.Uid == "100" || continent.hasRegion(a.Profile.Country.Region)))))) { lbOpponentAirlines.Items.Add(airline); } Grid.SetColumn(panelOpponents, 1); grdMain.Children.Add(panelOpponents); Button btnOk = new Button(); btnOk.Uid = "100"; btnOk.SetResourceReference(Button.StyleProperty, "RoundedButton"); btnOk.Height = Double.NaN; btnOk.Width = Double.NaN; btnOk.Content = Translator.GetInstance().GetString("General", btnOk.Uid); btnOk.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; btnOk.Margin = new Thickness(5, 5, 0, 0); btnOk.Click += btnOk_Click; btnOk.SetResourceReference(Button.BackgroundProperty, "ButtonBrush"); panelMain.Children.Add(btnOk); this.Content = panelMain; }