//spawn no longer exists public void Delete(Spawn s, ResizeValHolder rvh) { for (int i = 0; i < children.Count; i++) { DrawingVisualSpawn visual = (DrawingVisualSpawn)children[i]; if (visual.spawn.id == s.id) { children.RemoveAt(i); break; } } }
private void GameAnalyzer_OnZone(object sender, StringEventArgs e) { this.zoneMap = MapReader.ReadMap(e.value); mapVisuals.Clear(); spawnVisuals.Clear(); //ResizeCanvasToZone(e.value); this.rvh = GetResizeValHolder(e.value); DrawMap(this.rvh); if (followSelf) { centerView(); } lblZone.Content = this.zoneMap.zone; }
//existing spawn changed public void Update(Spawn s, ResizeValHolder rvh) { //might want to make a hash table for this so i dont have to loop int oldSpawnIndex = GetChildIndexFromSpawnID(s.id); DrawingVisualSpawn visual = (DrawingVisualSpawn)GetVisualChild(oldSpawnIndex); double oldX = (double)-visual.spawn.xLoc; double oldY = (double)-visual.spawn.yLoc; oldX = oldX - rvh.minX; oldY = oldY - rvh.minY; oldX = oldX * rvh.resizeRatio; oldY = oldY * rvh.resizeRatio; oldX = oldX + rvh.centerDistanceX; oldY = oldY + rvh.centerDistanceY; double newX = (double)-s.xLoc; double newY = (double)-s.yLoc; newX = newX - rvh.minX; newY = newY - rvh.minY; newX = newX * rvh.resizeRatio; newY = newY * rvh.resizeRatio; newX = newX + rvh.centerDistanceX; newY = newY + rvh.centerDistanceY; double offsetX = newX - oldX; double offsetY = newY - oldY; TransformGroup transformGrp = new TransformGroup(); //add to transform group and apply to visual if (visual.spawn.isSelf) { //rotate int oldHeading = Convert.ToInt32(visual.spawn.heading); int oldAngle = ((oldHeading * 360) >> 9); int newHeading = Convert.ToInt32(s.heading); int newAngle = ((newHeading * 360) >> 9); transformGrp.Children.Add(new RotateTransform((oldAngle - newAngle), oldX, oldY)); } transformGrp.Children.Add(new TranslateTransform(offsetX, offsetY)); visual.Transform = transformGrp; }
private ResizeValHolder GetResizeValHolder(string zone) {//move most of this to zone class to built on zone initialization? ResizeValHolder rvh = new ResizeValHolder(); rvh.zone = zone; rvh.minX = zoneMap.minX; rvh.minY = zoneMap.minY; rvh.zoneRatio = zoneMap.width / zoneMap.height; rvh.formRatio = (float)(mapCanvas.ActualWidth / mapCanvas.ActualHeight);//have to convert to float or it will use integer division rvh.centerDistanceX = 0.0f; rvh.centerDistanceY = 0.0f; if (rvh.zoneRatio < rvh.formRatio) {//if map is "taller" than window, match zone height to window height rvh.resizeRatio = (float)(mapCanvas.ActualHeight / zoneMap.height); } else {//if map is "wider" shrink zone width to window width rvh.resizeRatio = (float)(mapCanvas.ActualWidth / zoneMap.width); } //center map in form rvh.resizeRatio = rvh.resizeRatio * 0.95f; rvh.centerDistanceX = (float)(mapCanvas.ActualWidth - (double)(zoneMap.width * rvh.resizeRatio)) / 2; rvh.centerDistanceY = (float)(mapCanvas.ActualHeight - (double)(zoneMap.height * rvh.resizeRatio)) / 2; return rvh; }
/*private void ResizeCanvasToZone(string zone) { if (this.zoneMap != null) { mapCanvas.Width = this.zoneMap.maxX - this.zoneMap.minX; mapCanvas.Height = this.zoneMap.maxY - this.zoneMap.minY; } }*/ private void DrawMap(ResizeValHolder rvh) { foreach (MapLine line in this.zoneMap.lineList) { List<MapLineSegment> tmpSegmentList = new List<MapLineSegment>(); foreach (MapLineSegment segment in line.segmentList) { MapLineSegment tmpSegment = new MapLineSegment(); //adjust for 0 points being in the middle of the zone float tmpaX = segment.aX - rvh.minX; float tmpaY = segment.aY - rvh.minY; float tmpbX = segment.bX - rvh.minX; float tmpbY = segment.bY - rvh.minY; //adjust for scale tmpaX = tmpaX * rvh.resizeRatio; tmpaY = tmpaY * rvh.resizeRatio; tmpbX = tmpbX * rvh.resizeRatio; tmpbY = tmpbY * rvh.resizeRatio; //center image tmpaX = tmpaX + rvh.centerDistanceX; tmpaY = tmpaY + rvh.centerDistanceY; tmpbX = tmpbX + rvh.centerDistanceX; tmpbY = tmpbY + rvh.centerDistanceY; tmpSegmentList.Add(new MapLineSegment(tmpaX, tmpaY, tmpbX, tmpbY)); } //draw line mapVisuals.AddLine(tmpSegmentList, line.colorPen); } }
public void SetTarget(Spawn s, ResizeValHolder rvh) { if (s.id != targetSpawnId) { //remove target indicator from previous target if (targetSpawnId != 0) { int childId = GetChildIndexFromSpawnID(targetSpawnId); if (childId != -1) { DrawingVisualSpawn visual = (DrawingVisualSpawn)GetVisualChild(childId); DrawVisual(ref visual, rvh, false); } } //set new target indicator if we have a target if (s.memoryAddress != 0) { int childId = GetChildIndexFromSpawnID(s.id); if (childId != -1) { DrawingVisualSpawn visual = (DrawingVisualSpawn)GetVisualChild(childId); DrawVisual(ref visual, rvh, true); } } targetSpawnId = s.id; } }
private void DrawNPCCorpseVisual(ref DrawingVisualSpawn corpse, ResizeValHolder rvh, bool isTarget) { //X and Y location are inverted from how we display on window, so multiply by -1 to get inverse double x = (double)-corpse.spawn.xLoc; double y = (double)-corpse.spawn.yLoc; x = x - rvh.minX; y = y - rvh.minY; x = x * rvh.resizeRatio; y = y * rvh.resizeRatio; x = x + rvh.centerDistanceX; y = y + rvh.centerDistanceY; using(DrawingContext dc = corpse.RenderOpen()) { Brush targetBrush; if(isTarget) { targetBrush = Brushes.Fuchsia; } else { targetBrush = Brushes.LightBlue; } Pen colorPen = new Pen(targetBrush, 2.0); dc.DrawLine(colorPen, new Point(x, y - 3), new Point(x, y + 3)); dc.DrawLine(colorPen, new Point(x - 3, y), new Point(x + 3, y)); } }
/*private void GameAnalyzer_OnPlayerChangeLevel(object sender, IntEventArgs e) { this.playerLevel = e.value; //this doesnt fix the problem. f**k. //this.Clear(); }*/ //something spawned public void Add(Spawn s, ResizeValHolder rvh) { DrawingVisualSpawn visual = new DrawingVisualSpawn(s); DrawVisual(ref visual, rvh, false); children.Add(visual); }
private void DrawPCCorpseVisual(ref DrawingVisualSpawn corpse, ResizeValHolder rvh, bool isTarget) { //X and Y location are inverted from how we display on window, so multiply by -1 to get inverse double x = (double)-corpse.spawn.xLoc; double y = (double)-corpse.spawn.yLoc; x = x - rvh.minX; y = y - rvh.minY; x = x * rvh.resizeRatio; y = y * rvh.resizeRatio; x = x + rvh.centerDistanceX; y = y + rvh.centerDistanceY; using (DrawingContext dc = corpse.RenderOpen()) { Brush targetBrush; if (isTarget) { targetBrush = Brushes.Fuchsia; } else { targetBrush = Brushes.LightPink; } Pen colorPen = new Pen(targetBrush,2.0); dc.DrawLine(colorPen, new Point(x, y-3), new Point(x, y+3)); dc.DrawLine(colorPen, new Point(x-3, y), new Point(x+3, y)); //Rect rect = new Rect(new Point(x - 3, y - 3), new Size(6, 6)); //dc.DrawRectangle(null, new Pen(targetBrush, 1), rect); /* text FormattedText ft = new FormattedText( corpse.spawn.name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal), 9, Brushes.Black); // Draw the text at a location dc.DrawText(ft, new Point(x + 5.0, y + 5.0)); */ } //draw vert and horiz lines like this /*DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext dc = drawingVisual.RenderOpen()) { bool a = colorPen.IsFrozen; foreach (MapLineSegment segment in segmentList) { dc.DrawLine(colorPen, new Point(segment.aX, segment.aY), new Point(segment.bX, segment.bY)); } } this.children.Add(drawingVisual); * */ }
private void DrawPCVisual(ref DrawingVisualSpawn pc, ResizeValHolder rvh, bool isTarget) { //X and Y location are inverted from how we display on window, so multiply by -1 to get inverse double x = (double)-pc.spawn.xLoc; double y = (double)-pc.spawn.yLoc; x = x - rvh.minX; y = y - rvh.minY; x = x * rvh.resizeRatio; y = y * rvh.resizeRatio; x = x + rvh.centerDistanceX; y = y + rvh.centerDistanceY; using (DrawingContext dc = pc.RenderOpen()) { if (pc.spawn.isSelf) { /*if(this.playerLevel == 0) { this.playerLevel = (int)pc.spawn.level; }*/ Brush targetBrush; if (isTarget) { targetBrush = Brushes.Fuchsia; } else { targetBrush = Brushes.RoyalBlue; } double magnitude = 6.0; //describes how big the triangle is int heading = Convert.ToInt32(pc.spawn.heading); int angleA = 270 - ((heading * 360) >> 9); double radiansA = Math.PI * angleA / 180; double xOffsetA = Math.Cos(radiansA); double yOffsetA = Math.Sin(radiansA); int angleB = angleA + 120; double radiansB = Math.PI * angleB / 180; double xOffsetB = Math.Cos(radiansB); double yOffsetB = Math.Sin(radiansB); int angleC = angleA + 180; double radiansC = Math.PI * angleC / 180; double xOffsetC = Math.Cos(radiansC); double yOffsetC = Math.Sin(radiansC); int angleD = angleA - 120; double radiansD = Math.PI * angleD / 180; double xOffsetD = Math.Cos(radiansD); double yOffsetD = Math.Sin(radiansD); Point pointA = new Point(x + xOffsetA * magnitude * 2, y + yOffsetA * magnitude * 2); Point pointB = new Point(x + xOffsetB * magnitude, y + yOffsetB * magnitude); Point pointC = new Point(x, y); Point pointD = new Point(x + xOffsetD * magnitude, y + yOffsetD * magnitude); LineSegment[] segments = new LineSegment[] { new LineSegment(pointB, true), new LineSegment(pointC, true), new LineSegment(pointD, true) }; PathFigure figure = new PathFigure(pointA, segments, true); PathGeometry geo = new PathGeometry(new PathFigure[] { figure }); dc.DrawGeometry(Brushes.RoyalBlue, new Pen(targetBrush, 1), geo); } else { Brush targetBrush; Brush conBrush; if(playerLevel + 4 < pc.spawn.level) { conBrush = Brushes.Red; } else if(playerLevel - 4 > pc.spawn.level) { conBrush = Brushes.Green; } else { conBrush = Brushes.White; } if(isTarget) { targetBrush = Brushes.Fuchsia; } else { targetBrush = conBrush; } Rect rect = new Rect(new Point(x - 4, y - 4), new Size(8, 8)); dc.DrawRectangle(conBrush, new Pen(targetBrush, 1), rect); FormattedText ft = new FormattedText( "[" + pc.spawn.level.ToString() + " " + (SpawnClassShort)pc.spawn.eqClass + "] " + pc.spawn.name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal), 9, targetBrush); // Draw the text at a location dc.DrawText(ft, new Point(x + 5.0, y + 5.0)); } } }
private void DrawNPCVisual(ref DrawingVisualSpawn npc, ResizeValHolder rvh, bool isTarget) { //X and Y location are inverted from how we display on window, so multiply by -1 to get inverse double x = (double)-npc.spawn.xLoc; double y = (double)-npc.spawn.yLoc; x = x - rvh.minX; y = y - rvh.minY; x = x * rvh.resizeRatio; y = y * rvh.resizeRatio; x = x + rvh.centerDistanceX; y = y + rvh.centerDistanceY; using (DrawingContext dc = npc.RenderOpen()) { SolidColorBrush conBrush = GetConsiderBrush(this.playerLevel, npc.spawn.level); if (isTarget) { FormattedText ft = new FormattedText( npc.spawn.name + "\n" + npc.spawn.level.ToString() + " " + Spawn.GetRace(npc.spawn.race) + " / " + (SpawnClass)npc.spawn.eqClass, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.ExtraLight, FontStretches.Normal), 10, Brushes.Fuchsia); // Draw text dc.DrawText(ft, new Point(x + 3.0, y + 3.0)); dc.DrawEllipse(conBrush, new Pen(Brushes.Fuchsia, 1), new Point(x, y), 3, 3); } else if(isDragon(npc.spawn.name)) { conBrush = Brushes.BlueViolet; BitmapImage image = new BitmapImage(new Uri("..//..//images//dragon.png", UriKind.Relative)); Rect rect = new Rect(x - 5.0, y - 5.0, 10.0, 10.0); dc.DrawImage(image, rect); } else if(isNamed(npc.spawn.name)) { //add logic to check for any nameds here and show as "!" or something better than circle conBrush = Brushes.BlueViolet; dc.DrawEllipse(conBrush, new Pen(conBrush, 1), new Point(x, y), 3, 3); } else { dc.DrawEllipse(conBrush, new Pen(conBrush, 1), new Point(x, y), 3, 3); } } }
private void DrawVisual(ref DrawingVisualSpawn visual, ResizeValHolder rvh, bool isTarget) { switch ((SpawnType)visual.spawn.type) { case SpawnType.PC: DrawPCVisual(ref visual, rvh, isTarget); break; case SpawnType.NPC: DrawNPCVisual(ref visual, rvh, isTarget); break; case SpawnType.NPC_CORPSE: DrawNPCCorpseVisual(ref visual, rvh, isTarget); break; case SpawnType.PC_CORPSE: DrawPCCorpseVisual(ref visual, rvh, isTarget); break; } }
public void UpdateConsiderColor(ResizeValHolder rvh) { for(int i = 0; i < children.Count; i++) { DrawingVisualSpawn visual = (DrawingVisualSpawn)children[i]; int target = GetChildIndexFromSpawnID(targetSpawnId); if(i == target) { DrawVisual(ref visual, rvh, true); } else { DrawVisual(ref visual, rvh, false); } } }
public void ResizeCanvas(ResizeValHolder rvh) { //foreach (DrawingVisualSpawn visual in children) for (int i = 0; i < children.Count; i++) { DrawingVisualSpawn visual = (DrawingVisualSpawn)children[i]; int target = GetChildIndexFromSpawnID(targetSpawnId); if (i == target) { DrawVisual(ref visual, rvh, true); } else { DrawVisual(ref visual, rvh, false); } } }