/// <summary> /// Update relative drawings. Calculates new position for each scene drawing based on its origin point. /// </summary> private void UpdateRelativeDrawings() { var keysToRemove = new List <string>(); foreach (var drawing in Drawings.Relative) { if (drawing.Value.WorldId != AdvDia.CurrentWorldDynamicId) { keysToRemove.Add(drawing.Key); continue; } DrawingUtilities.RelativeMove(drawing.Value.Drawing, drawing.Value.Origin.WorldVector); } RelativeDrawing removedItem; foreach (var key in keysToRemove) { Drawings.Relative.TryRemove(key, out removedItem); } if (Drawings.Relative.Count > RelativeGeometryStorageLimit) { var firstKey = Drawings.Relative.Keys.First(); Drawings.Relative.TryRemove(firstKey, out removedItem); } }
private void DrawPointsOfInterest(DrawingContext dc, CanvasData canvas) { try { foreach (var marker in AdvDia.CurrentWorldMarkers.Where(m => m.Id >= 0 && m.Id < 200)) { dc.DrawEllipse(Brushes.Yellow, RadarResources.GridPen, marker.Position.ToCanvasPoint(), 5, 5); var textPoint = marker.Position.ToCanvasPoint(); textPoint.Y = textPoint.Y + 32; var glyphRun = DrawingUtilities.CreateGlyphRun(marker.NameHash.ToString(), 8, textPoint); dc.DrawGlyphRun(Brushes.Yellow, glyphRun); var toObjectivePen = new Pen(Brushes.Yellow, 0.2); dc.DrawLine(toObjectivePen, canvas.Center, marker.Position.ToCanvasPoint()); } } catch (Exception ex) { Logger.Debug("Exception in RadarUI.DrawPointsOfInterest(). {0} {1} {2}", ex.Message, ex.InnerException, ex); } }
private static void DrawActorLabel(DrawingContext dc, CanvasData canvas, RadarObject radarObject, Brush brush) { var text = radarObject.CachedActorName; if (text == null) { return; } const int textSize = 12; const int charLimit = 20; if (text.Length > charLimit) { text = text.Substring(0, charLimit); } // FormattedText is very slow, so instead create text manually with glyphs var glyphRun = DrawingUtilities.CreateGlyphRun(text, textSize, radarObject.Point); dc.DrawGlyphRun(brush, glyphRun); }
//private void DrawNavNode(DrawingContext dc, CanvasData canvas, GridNode node) //{ // SolidColorBrush nodeBrush; // if (node.Flags.HasFlag(NavCellFlags.RoundedCorner0) || node.Flags.HasFlag(NavCellFlags.RoundedCorner1) || node.Flags.HasFlag(NavCellFlags.RoundedCorner2) || node.Flags.HasFlag(NavCellFlags.RoundedCorner3)) // { // nodeBrush = Brushes.SaddleBrown; // } // else if (node.Flags.HasFlag(NavCellFlags.AllowWalk)) // { // nodeBrush = Brushes.Green; // } // else if (node.Flags.HasFlag(NavCellFlags.AllowProjectile)) // { // nodeBrush = Brushes.DarkGray; // } // else // { // nodeBrush = Brushes.Black; // } // dc.DrawEllipse(nodeBrush, RadarResources.GridPen, node.NavigableCenter.ToCanvasPoint(), GridSize, GridSize); //} //private void DrawNodesInRadius(DrawingContext dc, CanvasData canvas) //{ // try // { // var nearestNode = MainGrid.Instance.GetNearestNodeToPosition(AdvDia.MyPosition); // if (nearestNode == null) return; // var nodes = MainGrid.Instance.GetNeighbors(nearestNode, 5); // foreach (var node in nodes) // { // DrawNavNode(dc, canvas, node); // } // } // catch (Exception ex) // { // Logger.Debug("Exception in RadarUI.DrawNodesInRadius(). {0} {1} {2}", ex.Message, ex.InnerException, ex); // } //} /// <summary> /// Draw a Scene /// </summary> private void DrawScenes(DrawingContext dc, CanvasData canvas) { try { if (Math.Abs(CenterActor.Point.X) < 0.01f && Math.Abs(CenterActor.Point.Y) < 0.01f) { return; } var worldId = AdvDia.CurrentWorldDynamicId; foreach (var adventurerScene in ScenesStorage.CurrentWorldScenes.Where(s => s.DynamicWorldId == worldId).ToList()) { //var scene = adventurerScene.TrinityScene; // Combine navcells into one drawing and store it; because they don't change relative to each other // And because translating geometry for every navcell on every frame is waaaaay too slow. if (Drawings.Relative.ContainsKey(adventurerScene.HashName)) { continue; } var drawing = new DrawingGroup(); using (var groupdc = drawing.Open()) { #region Terrain if (adventurerScene.Cells != null) { var figures = new List <PathFigure>(); foreach (var navCell in adventurerScene.Cells.Where(nc => nc.IsWalkable)) { var topLeft = new Vector3(navCell.MinX, navCell.MinY, 0); var topRight = new Vector3(navCell.MaxX, navCell.MinY, 0); var bottomLeft = new Vector3(navCell.MinX, navCell.MaxY, 0); var bottomRight = new Vector3(navCell.MaxX, navCell.MaxY, 0); var segments = new[] { new LineSegment(topLeft.ToCanvasPoint(), true), new LineSegment(topRight.ToCanvasPoint(), true), new LineSegment(bottomRight.ToCanvasPoint(), true) }; figures.Add(new PathFigure(bottomLeft.ToCanvasPoint(), segments, true)); } var geo = new PathGeometry(figures, FillRule.Nonzero, null); geo.GetOutlinedPathGeometry(); groupdc.DrawGeometry(RadarResources.WalkableTerrain, null, geo); } #endregion #region Scene Borders var sceneTopLeft = new Vector3(adventurerScene.Min.X, adventurerScene.Min.Y, 0); var sceneTopRight = new Vector3(adventurerScene.Max.X, adventurerScene.Min.Y, 0); var sceneBottomLeft = new Vector3(adventurerScene.Min.X, adventurerScene.Max.Y, 0); var sceneBottomRight = new Vector3(adventurerScene.Max.X, adventurerScene.Max.Y, 0); groupdc.DrawGeometry(null, RadarResources.WalkableTerrainBorder, new LineGeometry(sceneTopLeft.ToCanvasPoint(), sceneTopRight.ToCanvasPoint())); groupdc.DrawGeometry(null, RadarResources.WalkableTerrainBorder, new LineGeometry(sceneBottomLeft.ToCanvasPoint(), sceneBottomRight.ToCanvasPoint())); groupdc.DrawGeometry(null, RadarResources.WalkableTerrainBorder, new LineGeometry(sceneTopLeft.ToCanvasPoint(), sceneBottomLeft.ToCanvasPoint())); groupdc.DrawGeometry(null, RadarResources.WalkableTerrainBorder, new LineGeometry(sceneTopRight.ToCanvasPoint(), sceneBottomRight.ToCanvasPoint())); #endregion #region Scene Title var textPoint = adventurerScene.Center.ToVector3().ToCanvasPoint(); var glyphRun = DrawingUtilities.CreateGlyphRun(adventurerScene.Name, 10, textPoint); groupdc.DrawGlyphRun(Brushes.Wheat, glyphRun); textPoint = adventurerScene.Center.ToVector3().ToCanvasPoint(); textPoint.Y = textPoint.Y + 20; glyphRun = DrawingUtilities.CreateGlyphRun((adventurerScene.Max - adventurerScene.Min) + " " + (adventurerScene.HasChild ? "HasSubScene" : string.Empty) + " " + (adventurerScene.SubScene != null ? " (Loaded)" : string.Empty), 8, textPoint); groupdc.DrawGlyphRun(Brushes.Wheat, glyphRun); #endregion #region Nodes var sceneNodePen = new Pen { Brush = Brushes.Black, Thickness = 0.1f }; foreach (var node in adventurerScene.Nodes) { if (node.HasEnoughNavigableCells) { groupdc.DrawGeometry(null, sceneNodePen, new LineGeometry(node.TopLeft.ToVector3().ToCanvasPoint(), node.TopRight.ToVector3().ToCanvasPoint())); groupdc.DrawGeometry(null, sceneNodePen, new LineGeometry(node.TopLeft.ToVector3().ToCanvasPoint(), node.BottomLeft.ToVector3().ToCanvasPoint())); groupdc.DrawGeometry(null, sceneNodePen, new LineGeometry(node.BottomLeft.ToVector3().ToCanvasPoint(), node.BottomRight.ToVector3().ToCanvasPoint())); groupdc.DrawGeometry(null, sceneNodePen, new LineGeometry(node.TopRight.ToVector3().ToCanvasPoint(), node.BottomRight.ToVector3().ToCanvasPoint())); //var textPoint1 = node.Center.ToVector3().ToCanvasPoint(); //// var glyphRun1 = DrawingUtilities.CreateGlyphRun(string.Format("{2} {0} ({1:P0})", node.NavigableCellCount, node.FillPercentage, node.LevelAreaId), 8, textPoint1); //var glyphRun1 = DrawingUtilities.CreateGlyphRun(node.LevelAreaId.ToString(), 8, textPoint1); //groupdc.DrawGlyphRun(Brushes.Wheat, glyphRun1); } //foreach (var navPoint in node.Nodes.Where(n=>n.NodeFlags.HasFlag(NodeFlags.NearWall))) //{ // DrawNavNode(groupdc, canvas, navPoint); // //groupdc.DrawEllipse(Brushes.LightSlateGray, sceneNodePen, navPoint.Center.ToVector3().ToCanvasPoint(), (float)GridSize / 2, (float)GridSize / 2); //} } #endregion } // Have to use SceneHash as key because scenes can appear multiple times with the same name Drawings.Relative.TryAdd(adventurerScene.HashName, new RelativeDrawing { Drawing = drawing, Origin = CenterActor.Morph, Center = adventurerScene.Center.ToVector3(), WorldId = adventurerScene.DynamicWorldId, //Image = new DrawingImage(drawing), //ImageRect = drawing.Bounds }); } foreach (var pair in Drawings.Relative) { //if (pair.Value.WorldId != AdvDia.CurrentWorldDynamicId) // continue; if (!pair.Value.Drawing.Bounds.IntersectsWith(CanvasData.ClipRegion.Rect)) { continue; } dc.DrawDrawing(pair.Value.Drawing); //if (!pair.Value.ImageRect.IntersectsWith(CanvasData.ClipRegion.Rect)) // continue; //dc.DrawImage(pair.Value.Image, pair.Value.ImageRect); } } catch (Exception ex) { Logger.Debug("Exception in RadarUI.DrawScenes(). {0} {1} {2}", ex.Message, ex.InnerException, ex); } }