private void PanelButton_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                #region Get border/text

                string buttonText = "";
                Border border = null;

                // Figure out which button was pushed
                if (e.OriginalSource is TextBlock)
                {
                    TextBlock textblock = (TextBlock)e.OriginalSource;
                    buttonText = textblock.Text;
                    border = (Border)textblock.Parent;
                }
                else if (e.OriginalSource is Border)
                {
                    border = (Border)e.OriginalSource;
                    buttonText = ((TextBlock)border.Child).Text;
                }
                else
                {
                    MessageBox.Show("Unknown panel button", this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                #endregion

                pnlSettings.Children.Clear();

                switch (buttonText)
                {
                    case "File":
                        #region File

                        // This is now always done in Window_Loaded
                        //if (_panelFile == null)
                        //{
                        //    _panelFile = new PanelFile(null, _session, _options, _itemOptions);
                        //    _panelFile.SessionChanged += new EventHandler(PanelFile_SessionChanged);
                        //}

                        pnlSettings.Children.Add(_panelFile);

                        #endregion
                        break;

                    case "Bean Types":
                        #region Bean Types

                        //_panelBeanTypes = _panelBeanTypes ?? new PanelBeanTypes(_options, _world);		// this is now done in window load

                        pnlSettings.Children.Add(_panelBeanTypes);

                        #endregion
                        break;

                    case "Bean Props":
                        #region Bean Props

                        _panelBeanProps = _panelBeanProps ?? new PanelBeanProps(_options, _itemOptions);
                        pnlSettings.Children.Add(_panelBeanProps);

                        #endregion
                        break;

                    case "Mutation":
                        #region Mutation

                        _panelMutation = _panelMutation ?? new PanelMutation(_options);
                        pnlSettings.Children.Add(_panelMutation);

                        #endregion
                        break;

                    case "Tracking":
                        #region Tracking

                        if (_panelTracking == null)
                        {
                            _panelTracking = new PanelTracking(_options);
                            _panelTracking.WinnerListsRecreated += new EventHandler(PanelTracking_WinnerListsRecreated);
                            _panelTracking.NumFinalistsChanged += new EventHandler(PanelTracking_NumFinalistsChanged);
                            _panelTracking.KillLivingBeans += new EventHandler(PanelTracking_KillLivingBeans);
                        }

                        pnlSettings.Children.Add(_panelTracking);

                        #endregion
                        break;

                    case "Simulation":
                        #region Simulation

                        _panelSimulation = _panelSimulation ?? new PanelSimulation(_options);
                        pnlSettings.Children.Add(_panelSimulation);

                        #endregion
                        break;

                    default:
                        MessageBox.Show("", this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                        break;		// even though it's an error, don't return.  Flow through
                }

                _pressedButton = border;
                ColorPanelButtons();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #2
0
        private void FinishLoad(FlyingBeanSession session, FlyingBeanOptions options, ItemOptions itemOptions, ShipDNA[] winningBeans, string saveFolder, bool startEmpty)
        {
            // Manually instantiate some of the properties that didn't get serialized
            options.DefaultBeanList = _defaultBeanList;

            if (options.NewBeanList == null)            // if this was called by new, it will still be null
            {
                options.NewBeanList = new SortedList <string, ShipDNA>();

                if (!startEmpty)
                {
                    string[] beanKeys = options.DefaultBeanList.Keys.ToArray();

                    foreach (int keyIndex in UtilityCore.RandomRange(0, beanKeys.Length, Math.Min(3, beanKeys.Length)))         // only do 3 of the defaults
                    {
                        string key = beanKeys[keyIndex];
                        options.NewBeanList.Add(key, options.DefaultBeanList[key]);
                    }
                }
            }

            options.MutateArgs = PanelMutation.BuildMutateArgs(options);

            options.GravityField = new GravityFieldUniform();
            options.Gravity      = options.Gravity;     // the property set modifies the gravity field

            options.WinnersLive = new WinnerList(true, options.TrackingMaxLineagesLive, options.TrackingMaxPerLineageLive);

            if (options.WinnersFinal == null)           // if a previous save had winning ships, this will already be loaded with them
            {
                options.WinnersFinal = new WinnerList(false, options.TrackingMaxLineagesFinal, options.TrackingMaxPerLineageFinal);
            }

            options.WinnerCandidates = new CandidateWinners();
            // These are already in the final list, there's no point in putting them in the candidate list as well
            //if (winningBeans != null)
            //{
            //    foreach (ShipDNA dna in winningBeans)
            //    {
            //        options.WinnerCandidates.Add(dna);
            //    }
            //}

            // Make sure the session folder is up to date
            if (saveFolder == null)
            {
                this.SessionFolder = null;
            }
            else
            {
                string dirChar = Regex.Escape(System.IO.Path.DirectorySeparatorChar.ToString());

                string pattern = dirChar + Regex.Escape(FlyingBeansWindow.SESSIONFOLDERPREFIX) + "[^" + dirChar + "]+(?<upto>" + dirChar + ")" + Regex.Escape(FlyingBeansWindow.SAVEFOLDERPREFIX);
                Match  match   = Regex.Match(saveFolder, pattern, RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    this.SessionFolder = saveFolder.Substring(0, match.Groups["upto"].Index);           // the session folder is everything before the save subfolder
                }
                else
                {
                    // They may have chosen a folder that they unziped onto their desktop, or wherever.  Leaving this null so that if they hit save, it will be saved
                    // in the appropriate location
                    this.SessionFolder = null;
                }
            }

            // Swap out the settings
            this.Session     = session;
            this.Options     = options;
            this.ItemOptions = itemOptions;

            // Inform the world
            if (this.SessionChanged != null)
            {
                this.SessionChanged(this, new EventArgs());
            }
        }