コード例 #1
0
        private void btnGenerateAxe_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _viewport.Children.RemoveAll(_visuals);

                string selectedItem = cboAxeType.SelectedItem as string;

                WeaponAxeType axeType;
                if (selectedItem == null || !Enum.TryParse(selectedItem, out axeType))
                {
                    MessageBox.Show("Unrecognized axe type", "CharacterStatsPanel", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                WeaponAxeSides sides;
                if (chkAxeDouble.IsChecked.Value)
                {
                    sides = WeaponAxeSides.Double;
                }
                else if (StaticRandom.NextBool())
                {
                    sides = WeaponAxeSides.Single_BackSpike;
                }
                else
                {
                    sides = WeaponAxeSides.Single_BackFlat;
                }

                WeaponAxeDNA dna = new WeaponAxeDNA()
                {
                    SizeSingle = 1d,
                    AxeType    = axeType,
                    Sides      = sides,
                    Style      = WeaponAxeStye.Basic
                };

                ModelVisual3D visual = new ModelVisual3D();
                visual.Content = new WeaponAxe(new WeaponMaterialCache(), dna, true).Model;

                _visuals.Add(visual);
                _viewport.Children.Add(visual);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "CharacterStatsPanel", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #2
0
        private string GetImageURL(bool?isColor = null)
        {
            // This gets a grayscale image 400x200
            //http://lorempixel.com/g/400/200

            // Using the image's width and height doesn't work.  Somewhere it went to zero
            //return string.Format("http://lorempixel.com/g/{0}/{1}", Convert.ToInt32(originalImage.ActualWidth).ToString(), Convert.ToInt32(originalImage.ActualHeight).ToString());

            if (isColor ?? StaticRandom.NextBool())
            {
                return("http://lorempixel.com/300/300");
            }
            else
            {
                return("http://lorempixel.com/g/300/300");
            }
        }
コード例 #3
0
        private void AddRandomKernels(int count, bool isNegPos, bool?isSquare = null)
        {
            for (int cntr = 0; cntr < count; cntr++)
            {
                bool isSquareActual = isSquare ?? StaticRandom.NextBool();

                // Create kernel
                Convolution2D kernel;
                if (isNegPos)
                {
                    kernel = GetRandomFilter_PosNeg(isSquareActual);
                }
                else
                {
                    kernel = GetRandomFilter_Positive(isSquareActual);
                }

                AddKernel(kernel);
            }
        }
コード例 #4
0
        private void DrawAsteroidsMinerals(Transform transform, bool shouldPopulateCanvas)
        {
            const double MINERALMULT  = 100d;
            const double ASTEROIDMULT = .25d;

            MapOctree snapshot = _map.LatestSnapshot;

            if (snapshot == null)
            {
                return;
            }

            if (snapshot.X0_Y0_Z0 == null && snapshot.X0_Y0_Z1 == null && snapshot.X0_Y1_Z0 == null && snapshot.X0_Y1_Z1 == null && snapshot.X1_Y0_Z0 == null && snapshot.X1_Y0_Z1 == null && snapshot.X1_Y1_Z0 == null && snapshot.X1_Y1_Z1 == null)
            {
                // This was happening because build snapshot wasn't throwing out disposed objects
                return;
            }

            #region GetValue delegates

            // These get the value of the items in that node.  The value will be divided by the area of the node to figure out opacity.
            // So the value/area should be 1 when the node is rich in that resource

            Func <MapOctree, double> getMineralValue = new Func <MapOctree, double>((node) =>
            {
                Mineral[] minerals = node.Items.
                                     Where(o => o.MapObject is Mineral).
                                     Select(o => (Mineral)o.MapObject).
                                     ToArray();

                if (minerals.Length == 0)
                {
                    return(0d);
                }
                else
                {
                    return(minerals.Sum(o => Convert.ToDouble(o.Credits) * MINERALMULT));
                }
            });

            Func <MapOctree, double> getAsteroidValue = new Func <MapOctree, double>((node) =>
            {
                Asteroid[] asteroids = node.Items.
                                       Where(o => o.MapObject is Asteroid).
                                       Select(o => (Asteroid)o.MapObject).
                                       ToArray();

                if (asteroids.Length == 0)
                {
                    return(0d);
                }
                else
                {
                    return(asteroids.Sum(o => o.PhysicsBody.Mass * ASTEROIDMULT));
                }
            });

            #endregion

            // Create the visuals
            _mineralVisual  = new ResourcesVisual(snapshot, getMineralValue, Colors.Lime, transform);
            _asteroidVisual = new ResourcesVisual(snapshot, getAsteroidValue, Colors.LightGray, transform);

            // Show a random one (the timer will swap them every tick)
            if (shouldPopulateCanvas)
            {
                _isShowingMineral = StaticRandom.NextBool();
                canvasMap.Children.Insert(0, _isShowingMineral ? _mineralVisual : _asteroidVisual);
            }

            #region Get Stats

            //double width = snapshot.MaxRange.X - snapshot.MinRange.X;
            //double height = snapshot.MaxRange.Y - snapshot.MinRange.Y;
            //double diagonal = Math3D.Avg(width, height) * Math.Sqrt(2);
            //double area = width * height;
            //double mineralValue = snapshot.Descendants(o => o.Children).Where(o => o.Items != null).Sum(o => getMineralValue(o));
            //double asteroidValue = snapshot.Descendants(o => o.Children).Where(o => o.Items != null).Sum(o => getAsteroidValue(o));

            //string stats = "";
            //stats += string.Format("width\t{0}\r\n", width);
            //stats += string.Format("height\t{0}\r\n", height);
            //stats += string.Format("diagonal\t{0}\r\n", diagonal);
            //stats += string.Format("area\t{0}\r\n", area);
            //stats += string.Format("minerals\t{0}\r\n", mineralValue);
            //stats += string.Format("asteroids\t{0}\r\n", asteroidValue);
            //stats += "\r\n";
            //stats += string.Format("min/diag\t{0}\r\n", mineralValue / diagonal);
            //stats += string.Format("ast/diag\t{0}\r\n", asteroidValue / diagonal);
            //stats += string.Format("min/area\t{0}\r\n", mineralValue / area);
            //stats += string.Format("ast/area\t{0}\r\n", asteroidValue / area);

            //Clipboard.SetText(stats);

            #endregion
        }