Exemple #1
0
        public void SetOpacityCoef(float coef)
        {
            if (coef == opacityCoef)
            {
                return;
            }
            opacityCoef = coef;

            //#TODO store ref to the style in a var
            MarkerIconStyle iconStyle = (MarkerIconStyle)Styles.FirstOrDefault(x => x is MarkerIconStyle);

            if (iconStyle != null)
            {
                iconStyle.Opacity = marker.alpha * opacityCoef;
            }


            TiledBitmapStyle TiconStyle = (TiledBitmapStyle)Styles.FirstOrDefault(x => x is TiledBitmapStyle);

            if (TiconStyle != null)
            {
                TiconStyle.Opacity = marker.alpha * opacityCoef;
            }

            var PiconStyle = (PolylineMarkerStyle)Styles.FirstOrDefault(x => x is PolylineMarkerStyle);

            if (PiconStyle != null)
            {
                PiconStyle.Opacity = marker.alpha * opacityCoef;
            }


            DataHasChanged();
        }
        public GPSTrackerFeature(GPSTracker tracker)
        {
            Tracker       = tracker;
            this["Label"] = tracker.displayName;
            imgStyle      = new MarkerIconStyle
            {
                SymbolRotation = 0,
                Opacity        = 1,
                size           = new float[] { 32, 32 },
                typeSize       = 1,
                color          = SKColors.Black,
                shadow         = false,
                text           = tracker.displayName
            };


            Styles.Add(imgStyle);

            var markerType  = GameState.Instance.marker.markerTypes["hd_join"];
            var markerColor = GameState.Instance.marker.markerColors["ColorBlack"];

            MarkerCache.Instance.GetImage(markerType, markerColor)
            .ContinueWith(
                (image) =>
            {
                imgStyle.markerIcon = image.Result;
            });



            lblStyle = new MarkerLabelStyle(tracker.displayName, markerType, markerColor);
            Styles.Add(lblStyle);

            heightStyle        = new MarkerLabelStyle(tracker.displayName, markerType, markerColor);
            heightStyle.Offset = new Offset(0, markerType.size, false);
            Styles.Add(heightStyle);


            velStyle = new VelocityIndicatorStyle {
                velocity = new Vector3(tracker.vel[0], tracker.vel[1], 0f)
            };
            Styles.Add(velStyle);

            Geometry = new Point(tracker.pos[0], tracker.pos[1]);
        }
        public MarkerFeature(ActiveMarker marker)
        {
            this.marker = marker;

            this["Label"] = marker.text;
            Geometry      = new Point(marker.pos[0], marker.pos[1]);

            CultureInfo ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();

            ci.NumberFormat.NumberDecimalSeparator = ".";

            if (!GameState.Instance.marker.markerColors.ContainsKey(marker.color))
            {
                throw new InvalidOperationException();
            }
            markerColor = GameState.Instance.marker.markerColors[marker.color];

            if (string.IsNullOrEmpty(marker.size))
            {
                marker.size = "64,64";
            }

            if (marker.shape == "ICON")
            {
                if (string.IsNullOrEmpty(marker.type))
                {
                    return;                                    //Can happen, somehow
                }
                if (!GameState.Instance.marker.markerTypes.ContainsKey(marker.type))
                {
                    throw new InvalidOperationException();
                }
                var markerType = GameState.Instance.marker.markerTypes[marker.type];

                if (marker.color == "Default")
                {
                    markerColor = new MarkerColor
                    {
                        color = markerType.color, name = markerType.name
                    }
                }
                ;

                try
                {
                    var symStyle = new MarkerIconStyle
                    {
                        SymbolRotation = marker.dir,
                        Opacity        = marker.alpha,
                        size           = marker.size.Split(',').Select(xy => float.Parse(xy, NumberStyles.Any, ci)).ToArray(),
                        typeSize       = markerType.size,
                        color          = markerColor.ToSKColor(),
                        shadow         = markerType.shadow,
                        text           = marker.text
                    };

                    MarkerCache.Instance.GetImage(markerType, null)
                    .ContinueWith(
                        (image) =>
                    {
                        symStyle.markerIcon = image.Result;
                    });

                    Styles.Add(symStyle);
                    marker.PropertyChanged += OnMarkerOnPropertyChangedIcon;
                }
                catch (System.FormatException ex)
                {
                }
            }
            else if (marker.shape == "RECTANGLE" || marker.shape == "ELLIPSE")
            {
                if (!GameState.Instance.marker.markerBrushes.ContainsKey(marker.brush))
                {
                    throw new InvalidOperationException();
                }
                var markerBrush = GameState.Instance.marker.markerBrushes[marker.brush];

                var markerSize = marker.size.Split(',').Select(xy => float.Parse(xy, NumberStyles.Any, ci)).ToArray();


                var center = new Point(marker.pos[0], marker.pos[1]);

                //set rect
                Geometry = new BoundBox(center.Offset(-markerSize[0], -markerSize[1]), center.Offset(markerSize[0], markerSize[1]));

                var tiledBitmap = new TiledBitmapStyle
                {
                    image    = null,
                    rect     = new SkiaSharp.SKRect(-markerSize[0], -markerSize[1], markerSize[0], markerSize[1]),
                    rotation = marker.dir,
                    ellipse  = marker.shape == "ELLIPSE",
                    border   = markerBrush.drawBorder,
                    color    = markerColor.ToSKColor()
                };
                Styles.Add(tiledBitmap);


                MarkerCache.Instance.GetImage(markerBrush, null).ContinueWith(
                    (image) =>
                {
                    tiledBitmap.image = image.Result;
                });

                marker.PropertyChanged += OnMarkerOnPropertyChangedTiled;
            }
            else if (marker.shape == "POLYLINE")
            {
                if (marker.polyline.Count == 0)
                {
                    return;
                }
                Geometry = new BoundBox(marker.polyline);

                var polyMarker = new PolylineMarkerStyle(marker.polyline)
                {
                    color = markerColor.ToSKColor()
                };
                Styles.Add(polyMarker);

                //Polylines have no propertychanged as (in ACE) they cannot be edited
            }
        }
        void OnMarkerOnPropertyChangedIcon(object a, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(ActiveMarker.text))
            {
                this["Label"] = marker.text;
                //#TODO update Label style
                foreach (var label in Styles.Where(x => x is MarkerIconStyle))
                {
                    (label as MarkerIconStyle).text = marker.text;
                }

                DataHasChanged();
            }
            else if (e.PropertyName == nameof(ActiveMarker.pos))
            {
                Geometry = new Point(marker.pos[0], marker.pos[1]);
                DataHasChanged();
            }
            else if (e.PropertyName == nameof(ActiveMarker.dir))
            {
                foreach (var sym in Styles.Where(x => x is MarkerIconStyle)) //#TODO just store the style in a variable
                {
                    (sym as MarkerIconStyle).SymbolRotation = marker.dir;
                }
                DataHasChanged();
            }
            else if (e.PropertyName == nameof(ActiveMarker.type))
            {
                MarkerIconStyle iconStyle = (MarkerIconStyle)Styles.First(x => x is MarkerIconStyle);
                if (iconStyle == null)
                {
                    return;
                }

                if (!GameState.Instance.marker.markerTypes.ContainsKey(marker.type))
                {
                    return;
                }
                var markerType = GameState.Instance.marker.markerTypes[marker.type];

                if (marker.color == "Default")
                {
                    markerColor = new MarkerColor {
                        color = markerType.color, name = markerType.name
                    }
                }
                ;

                iconStyle.color    = markerColor.ToSKColor();
                iconStyle.typeSize = markerType.size;
                iconStyle.shadow   = markerType.shadow;

                MarkerCache.Instance.GetImage(markerType, null)
                .ContinueWith((image) => { iconStyle.markerIcon = image.Result; });
                DataHasChanged();
            }
            else if (e.PropertyName == nameof(ActiveMarker.color))
            {
                MarkerIconStyle iconStyle = (MarkerIconStyle)Styles.First(x => x is MarkerIconStyle);
                if (iconStyle == null)
                {
                    return;
                }


                if (!GameState.Instance.marker.markerColors.ContainsKey(marker.color))
                {
                    return;
                }
                markerColor = GameState.Instance.marker.markerColors[marker.color];



                if (marker.color == "Default")
                {
                    if (!GameState.Instance.marker.markerTypes.ContainsKey(marker.type))
                    {
                        return;
                    }
                    var markerType = GameState.Instance.marker.markerTypes[marker.type];

                    markerColor = new MarkerColor {
                        color = markerType.color, name = markerType.name
                    };
                }

                iconStyle.color = markerColor.ToSKColor();
                DataHasChanged();
            }
        }