Ejemplo n.º 1
0
        /// <summary>
        /// Resets values of the current contour settings
        /// </summary>
        private void RestartValues()
        {
            // if we change a type of a stone, everything will be reseted
            ContourRock contourRck = contourRocks.Where(ctr => ctr.contour_name.Equals(((ComboBoxItem)contourNameCombo.SelectedItem).Content)).First();

            contourRocks.Remove(contourRck);
            A_Rock contextRock = null;

            if (blackHoleCmbIt.IsSelected && !(contourRck.rock is BlackHole))
            {
                contextRock = new BlackHole();
            }
            if (generatorCmbIt.IsSelected && !(contourRck.rock is Generator))
            {
                contextRock = new Generator();
            }
            if (gravitonCmbIt.IsSelected && !(contourRck.rock is Graviton))
            {
                contextRock = new Graviton();
            }
            if (magnetonCmbIt.IsSelected && !(contourRck.rock is Magneton))
            {
                contextRock = new Magneton();
            }

            if (contextRock != null)
            {
                contourRck.rock = contextRock;
            }
            contourRocks.Add(contourRck);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Contour selection change will save current values and reload values
 /// </summary>
 private void contourNameCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (initialized)
     {
         SaveValues();
         RestartComponents();
         actual_contour = contourRocks.First(ctr => ctr.contour_name.Equals(((ComboBoxItem)contourNameCombo.SelectedItem).Content));
         LoadValues();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Calculates a distance between two stones
        /// </summary>
        /// <returns></returns>
        private int DistanceBetweenRocks(ContourRock rck, FoundRock fnd)
        {
            double deltaX = rck.rock.Position.X - fnd.position.X;
            double deltaY = rck.rock.Position.Y - fnd.position.Y;

            if (deltaX == 0 && deltaY == 0)
            {
                return(0);
            }
            return((int)Math.Sqrt(deltaX * deltaX + deltaY * deltaY));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets a minimal distance between a freshly inserted stone and all others
        /// </summary>
        private void SetMinimumLengthForPlacedRock(ContourRock rock, HashSet <FoundRock> founds)
        {
            rock.minLength = 100000;
            rock.foundRock = null;

            foreach (FoundRock found in founds)
            {
                int distance = DistanceBetweenRocks(rock, found);
                if (distance < rock.minLength)
                {
                    rock.minLength = distance;
                    rock.foundRock = found;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Saves values of a contour upon click on settings of another contour
        /// </summary>
        private void SaveValues()
        {
            ContourRock contourRck = actual_contour;

            if (contourRck.rock is Graviton)
            {
                ((Graviton)contourRck.rock).Settings.weigh          = GravWeighSlider.Value;
                ((Graviton)contourRck.rock).Settings.enabled        = true;
                ((Graviton)contourRck.rock).Settings.Energy_pulsing = (bool)pulsarChck.IsChecked;
                ((Graviton)contourRck.rock).Settings_Allowed        = !((bool)baseSetChck.IsChecked);
            }
            if (contourRck.rock is Magneton)
            {
                ((Magneton)contourRck.rock).Settings.force          = MagForceSlider.Value;
                ((Magneton)contourRck.rock).Settings.enabled        = true;
                ((Magneton)contourRck.rock).Settings.Energy_pulsing = (bool)pulsarChck.IsChecked;
                ((Magneton)contourRck.rock).Settings_Allowed        = !((bool)baseSetChck.IsChecked);
            }
            if (contourRck.rock is BlackHole)
            {
                ((BlackHole)contourRck.rock).Settings.weigh          = (int)BHweighSlider.Value;
                ((BlackHole)contourRck.rock).Settings.enabled        = true;
                ((BlackHole)contourRck.rock).Settings.Energy_pulsing = (bool)pulsarChck.IsChecked;
                ((BlackHole)contourRck.rock).Settings_Allowed        = !((bool)baseSetChck.IsChecked);
            }
            if (contourRck.rock is Generator)
            {
                ((Generator)contourRck.rock).Settings.particle_minimum_size  = GminPartSizeSlider.Value;
                ((Generator)contourRck.rock).Settings.particle_maximum_size  = GmaxPartSizeSlider.Value;
                ((Generator)contourRck.rock).Settings.angle_maximum          = GangleMaxSlider.Value;
                ((Generator)contourRck.rock).Settings.angle_offset           = GangleOffSlider.Value;
                ((Generator)contourRck.rock).Settings.generatingSpeed        = GgenerSpeedSlider.Value;
                ((Generator)contourRck.rock).Settings.particle_maximum_speed = GmaxPartVelocitySlider.Value;
                ((Generator)contourRck.rock).Settings.particle_minimum_speed = GminPartVelocitySlider.Value;
                ((Generator)contourRck.rock).Settings.enabled        = true;
                ((Generator)contourRck.rock).Settings.Energy_pulsing = (bool)pulsarChck.IsChecked;
                ((Generator)contourRck.rock).Settings_Allowed        = !((bool)baseSetChck.IsChecked);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads values from a contour
        /// </summary>
        private void LoadValues()
        {
            ContourRock contourRck = actual_contour;

            if (contourRck.rock is Graviton)
            {
                rockTypeCombo.SelectedItem = gravitonCmbIt;
                GravWeighSlider.Value      = ((Graviton)contourRck.rock).Settings.weigh;
                pulsarChck.IsChecked       = ((Graviton)contourRck.rock).Settings.Energy_pulsing;
                baseSetChck.IsChecked      = !((Graviton)contourRck.rock).Settings_Allowed;
            }
            if (contourRck.rock is Magneton)
            {
                rockTypeCombo.SelectedItem = magnetonCmbIt;
                MagForceSlider.Value       = ((Magneton)contourRck.rock).Settings.force;
                pulsarChck.IsChecked       = ((Magneton)contourRck.rock).Settings.Energy_pulsing;
                baseSetChck.IsChecked      = !((Magneton)contourRck.rock).Settings_Allowed;
            }
            if (contourRck.rock is BlackHole)
            {
                rockTypeCombo.SelectedItem = blackHoleCmbIt;
                BHweighSlider.Value        = ((BlackHole)contourRck.rock).Settings.weigh;
                pulsarChck.IsChecked       = ((BlackHole)contourRck.rock).Settings.Energy_pulsing;
                baseSetChck.IsChecked      = !((BlackHole)contourRck.rock).Settings_Allowed;
            }
            if (contourRck.rock is Generator)
            {
                rockTypeCombo.SelectedItem   = generatorCmbIt;
                GangleMaxSlider.Value        = ((Generator)contourRck.rock).Settings.angle_maximum;
                GangleOffSlider.Value        = ((Generator)contourRck.rock).Settings.angle_offset;
                GgenerSpeedSlider.Value      = ((Generator)contourRck.rock).Settings.generatingSpeed;
                GmaxPartVelocitySlider.Value = ((Generator)contourRck.rock).Settings.particle_maximum_speed;
                GminPartVelocitySlider.Value = ((Generator)contourRck.rock).Settings.particle_minimum_speed;
                GmaxPartSizeSlider.Value     = ((Generator)contourRck.rock).Settings.particle_minimum_size;
                GminPartSizeSlider.Value     = ((Generator)contourRck.rock).Settings.particle_maximum_size;
                pulsarChck.IsChecked         = ((Generator)contourRck.rock).Settings.Energy_pulsing;
                baseSetChck.IsChecked        = !((Generator)contourRck.rock).Settings_Allowed;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a stone entity based on the information about detected contour
        /// </summary>
        /// <param name="contureName">contour name</param>
        /// <param name="position">contour position</param>
        /// <param name="templates">list of known templates</param>
        /// <returns></returns>
        private FoundRock CreateFoundRock(String contureName, FPoint position, Templates templates, double radius, double scale, double angle)
        {
            FoundRockType type = FoundRockType.GRAVITON;
            ContourRock   rck  = (templates.rockSettings.Where(name => name.contour_name.Equals(contureName))).First();

            if (rck.rock is Generator)
            {
                type = FoundRockType.GENERATOR;
            }
            if (rck.rock is BlackHole)
            {
                type = FoundRockType.BLACKHOLE;
            }
            if (rck.rock is Graviton)
            {
                type = FoundRockType.GRAVITON;
            }
            if (rck.rock is Magneton)
            {
                type = FoundRockType.MAGNETON;
            }

            return(new FoundRock(contureName, type, position, radius, scale, angle));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes all data
        /// </summary>
        public void InitData()
        {
            contourRocks = templates.rockSettings;

            if (contourRocks == null)
            {
                contourRocks = new HashSet <ContourRock>();
            }

            if (templates != null)
            {
                // put the name of each contour into a combobox and create a ContourRock, bound with its id
                foreach (Template tmp in templates)
                {
                    if (contourRocks.Count(cnt => cnt.contour_name.Equals(tmp.name)) == 0)
                    {
                        // create a referential stone
                        A_Rock contextRock = null;
                        if (blackHoleCmbIt.IsSelected)
                        {
                            contextRock = new BlackHole();
                        }
                        if (generatorCmbIt.IsSelected)
                        {
                            contextRock = new Generator();
                        }
                        if (gravitonCmbIt.IsSelected)
                        {
                            contextRock = new Graviton();
                        }
                        if (magnetonCmbIt.IsSelected)
                        {
                            contextRock = new Magneton();
                        }

                        contourRocks.Add(new ContourRock(contextRock, tmp.name));
                    }

                    ComboBoxItem item = new ComboBoxItem();
                    item.Content    = tmp.name;
                    item.IsSelected = true;
                    contourNameCombo.Items.Add(item);
                }

                actual_contour = contourRocks.Where(cnt => cnt.contour_name.Equals(((ComboBoxItem)(contourNameCombo.SelectedItem)).Content)).First();
                if (actual_contour.rock is Graviton)
                {
                    gravitonCmbIt.IsSelected = true;
                }
                else if (actual_contour.rock is Generator)
                {
                    generatorCmbIt.IsSelected = true;
                }
                else if (actual_contour.rock is Magneton)
                {
                    magnetonCmbIt.IsSelected = true;
                }
                else if (actual_contour.rock is BlackHole)
                {
                    blackHoleCmbIt.IsSelected = true;
                }

                if (blackHoleCmbIt.IsSelected)
                {
                    blackHoleGroup.Visibility = Visibility.Visible;
                }
                if (gravitonCmbIt.IsSelected)
                {
                    gravitonGroup.Visibility = Visibility.Visible;
                }
                if (generatorCmbIt.IsSelected)
                {
                    generatorGroup.Visibility = Visibility.Visible;
                }
                if (magnetonCmbIt.IsSelected)
                {
                    magnetonGroup.Visibility = Visibility.Visible;
                }

                LoadValues();
                initialized = true;
            }
        }