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 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 } }
private void OnMarkerOnPropertyChangedTiled(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(ActiveMarker.text)) { this["Label"] = marker.text; } else if (e.PropertyName == nameof(ActiveMarker.pos)) { TiledBitmapStyle iconStyle = (TiledBitmapStyle)Styles.First(x => x is TiledBitmapStyle); //#TODO make interface for both styles with setters for pos/dir/color/stuff if (iconStyle == null) { return; } CultureInfo ci = (CultureInfo)CultureInfo.CurrentCulture.Clone(); ci.NumberFormat.NumberDecimalSeparator = "."; var markerSize = marker.size.Split(',').Select(xy => float.Parse(xy, NumberStyles.Any, ci)).ToArray(); var center = new Point(marker.pos[0], marker.pos[1]); Geometry = new BoundBox(center.Offset(-markerSize[0], -markerSize[1]), center.Offset(markerSize[0], markerSize[1])); iconStyle.rect = new SkiaSharp.SKRect(-markerSize[0], -markerSize[1], markerSize[0], markerSize[1]); DataHasChanged(); } else if (e.PropertyName == nameof(ActiveMarker.dir)) { foreach (var sym in Styles.Where(x => x is TiledBitmapStyle)) //#TODO just store the style in a variable { (sym as TiledBitmapStyle).rotation = marker.dir; } DataHasChanged(); } else if (e.PropertyName == nameof(ActiveMarker.brush)) { TiledBitmapStyle iconStyle = (TiledBitmapStyle)Styles.First(x => x is TiledBitmapStyle); if (iconStyle == null) { return; } if (!GameState.Instance.marker.markerBrushes.ContainsKey(marker.brush)) { return; } var markerBrush = GameState.Instance.marker.markerBrushes[marker.brush]; if (marker.color == "Default") { markerColor = new MarkerColor { color = marker.color, name = markerBrush.name } } ; iconStyle.color = markerColor.ToSKColor(); //set rect MarkerCache.Instance.GetImage(markerBrush, null).ContinueWith( (image) => { iconStyle.image = image.Result; }); DataHasChanged(); } else if (e.PropertyName == nameof(ActiveMarker.color)) { TiledBitmapStyle iconStyle = (TiledBitmapStyle)Styles.First(x => x is TiledBitmapStyle); 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(); } }