public Rect2D(Vector2D min, Vector2D max) { Min = new Vector2D(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y)); Max = new Vector2D(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y)); _Min = Min; _Max = Max; }
public SkillNode FindNodeInRange(Vector2D mousePointer, int range = 50) { var nodes = FindNodesInRange(mousePointer, range); var nodeList = nodes as IList<KeyValuePair<ushort, SkillNode>> ?? nodes.ToList(); if (!nodeList.Any()) return null; if (DrawAscendancy) { var dnode = nodeList.First(); return nodeList.Where(x => x.Value.ascendancyName == AscClasses.GetClassName(Chartype, AscType)) .DefaultIfEmpty(dnode) .First() .Value; } return nodeList.First().Value; }
public IEnumerable<KeyValuePair<ushort, SkillNode>> FindNodesInRange(Vector2D mousePointer, int range = 50) { var nodes = Skillnodes.Where(n => ((n.Value.Position - mousePointer).Length < range)).ToList(); if (!DrawAscendancy || AscType <= 0) return nodes; var asn = GetAscNode(); var bitmap = Assets["Classes" + asn.ascendancyName]; nodes = Skillnodes.Where(n => (n.Value.ascendancyName != null || (Math.Pow(n.Value.Position.X - asn.Position.X, 2) + Math.Pow(n.Value.Position.Y - asn.Position.Y, 2)) > Math.Pow((bitmap.Height * 1.25 + bitmap.Width * 1.25) / 2, 2)) && ((n.Value.Position - mousePointer).Length < range)).ToList(); return nodes; }
private void zbSkillTreeBackground_MouseMove(object sender, MouseEventArgs e) { Point p = e.GetPosition(zbSkillTreeBackground.Child); var v = new Vector2D(p.X, p.Y); v = v * _multransform + _addtransform; SkillNode node = null; IEnumerable<KeyValuePair<ushort, SkillNode>> nodes = SkillTree.Skillnodes.Where(n => ((n.Value.Position - v).Length < 50)).ToList(); if (nodes.Count() != 0) node = nodes.First().Value; if (node != null && node.Attributes.Count != 0) { if (node.IsJewelSocket) { Tree.DrawJewelHighlight(node); } if (Tree.SkilledNodes.Contains(node.Id)) { _toRemove = Tree.ForceRefundNodePreview(node.Id); if (_toRemove != null) Tree.DrawRefundPreview(_toRemove); } else { _prePath = Tree.GetShortestPathTo(node.Id, Tree.SkilledNodes); Tree.DrawPath(_prePath); } var tooltip = node.Name + "\n" + node.attributes.Aggregate((s1, s2) => s1 + "\n" + s2); if (!(_sToolTip.IsOpen && _lasttooltip == tooltip)) { var sp = new StackPanel(); sp.Children.Add(new TextBlock { Text = tooltip }); if (_prePath != null) { sp.Children.Add(new Separator()); sp.Children.Add(new TextBlock { Text = "Points to skill node: " + _prePath.Count }); } _sToolTip.Content = sp; _sToolTip.IsOpen = true; _lasttooltip = tooltip; } } else { _sToolTip.Tag = false; _sToolTip.IsOpen = false; _prePath = null; _toRemove = null; if (Tree != null) { Tree.ClearPath(); Tree.ClearJewelHighlight(); } } }
private void zbSkillTreeBackground_Click(object sender, RoutedEventArgs e) { Point p = ((MouseEventArgs)e.OriginalSource).GetPosition(zbSkillTreeBackground.Child); Size size = zbSkillTreeBackground.Child.DesiredSize; var v = new Vector2D(p.X, p.Y); v = v * _multransform + _addtransform; IEnumerable<KeyValuePair<ushort, SkillNode>> nodes = SkillTree.Skillnodes.Where(n => ((n.Value.Position - v).Length < 50)).ToList(); if (nodes.Count() != 0) { var node = nodes.First().Value; // Ignore clicks on character portraits and masteries if (node.Spc == null && !node.IsMastery) { if (_lastMouseButton == MouseButton.Right) { // Can't use using because Control is also in System.Windows and that is used elsewhere. if (System.Windows.Forms.Control.ModifierKeys.HasFlag(System.Windows.Forms.Keys.Shift)) { // Backward on shift+RMB Tree.CycleNodeTagBackward(node); } else { // Forward on RMB Tree.CycleNodeTagForward(node); } e.Handled = true; } else { // Toggle whether the node is included in the tree if (Tree.SkilledNodes.Contains(node.Id)) { Tree.ForceRefundNode(node.Id); UpdateUI(); _prePath = Tree.GetShortestPathTo(node.Id, Tree.SkilledNodes); Tree.DrawPath(_prePath); } else if (_prePath != null) { foreach (ushort i in _prePath) { Tree.SkilledNodes.Add(i); } UpdateUI(); Tree.UpdateAvailNodes(); _toRemove = Tree.ForceRefundNodePreview(node.Id); if (_toRemove != null) Tree.DrawRefundPreview(_toRemove); } } } } else { if (p.X < 0 || p.Y < 0 || p.X > size.Width || p.Y > size.Height) { if (_lastMouseButton == MouseButton.Right) { zbSkillTreeBackground.Reset(); } } } tbSkillURL.Text = Tree.SaveToURL(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { ItemDB.Load("Items.xml"); ItemDB.Merge("ItemsLocal.xml"); ItemDB.Index(); _attibuteCollection = new ListCollectionView(_attiblist); listBox1.ItemsSource = _attibuteCollection; _attibuteCollection.GroupDescriptions.Add(new PropertyGroupDescription("Text") { Converter = new GroupStringConverter() }); _allAttributeCollection = new ListCollectionView(_allAttributesList); _allAttributeCollection.GroupDescriptions.Add(new PropertyGroupDescription("Text") { Converter = new GroupStringConverter() }); lbAllAttr.ItemsSource = _allAttributeCollection; _defenceCollection = new ListCollectionView(_defenceList); _defenceCollection.GroupDescriptions.Add(new PropertyGroupDescription("Group")); listBoxDefence.ItemsSource = _defenceCollection; _offenceCollection = new ListCollectionView(_offenceList); _offenceCollection.GroupDescriptions.Add(new PropertyGroupDescription("Group")); listBoxOffence.ItemsSource = _offenceCollection; if (_persistentData.StashBookmarks != null) Stash.Bookmarks = new System.Collections.ObjectModel.ObservableCollection<StashBookmark>(_persistentData.StashBookmarks); // Set theme & accent. SetTheme(_persistentData.Options.Theme); SetAccent(_persistentData.Options.Accent); Tree = SkillTree.CreateSkillTree(StartLoadingWindow, UpdateLoadingWindow, CloseLoadingWindow); Tree.MainWindow = this; recSkillTree.Width = SkillTree.TRect.Width / SkillTree.TRect.Height * recSkillTree.Height; recSkillTree.UpdateLayout(); recSkillTree.Fill = new VisualBrush(Tree.SkillTreeVisual); Tree.Chartype = SkillTree.CharName.IndexOf(((string)((ComboBoxItem)cbCharType.SelectedItem).Name).ToUpper()); Tree.UpdateAvailNodes(); UpdateUI(); _multransform = SkillTree.TRect.Size / new Vector2D(recSkillTree.RenderSize.Width, recSkillTree.RenderSize.Height); _addtransform = SkillTree.TRect.TopLeft; // loading last build if (_persistentData.CurrentBuild != null) SetCurrentBuild(_persistentData.CurrentBuild); btnLoadBuild_Click(this, new RoutedEventArgs()); _justLoaded = false; // loading saved build lvSavedBuilds.Items.Clear(); foreach (var build in _persistentData.Builds) { lvSavedBuilds.Items.Add(build); } ImportLegacySavedBuilds(); }
// public Vector2D RandomPoint( Random r ) { return new Vector2D( r.NextBetween( Left, Right ), r.NextBetween( Top, Bottom ) ); } public Rect2D(Vector2D v) { Min = Max = v; _Min = _Max = v; }
public Rect2D Assimilate(Vector2D v) { /*if ( v.X < Min.X ) Min.X = v.X; if ( v.Y < Min.Y ) Min.Y = v.Y; if ( v.X > Max.X ) Max.X = v.X; if ( v.Y > Max.Y ) Max.Y = v.Y;*/ return new Rect2D( new Vector2D( Math.Min(Left, v.X), Math.Min(Top, v.Y)), new Vector2D( Math.Max(Right, v.X), Math.Max(Bottom, v.Y)) ); }
public bool Contains(Vector2D v) { return v.X >= Min.X && v.Y >= Min.Y && v.Y <= Max.Y && v.X <= Max.X; }
public double Dot(Vector2D p) { return p.X*X + p.Y*Y; }
/// <summary> /// /// </summary> /// <param name="type">"Normal", "Highlight", and "Pressed"</param> public void DrawAscendancyButton(string type = "Normal") { using (var dc = _ascButtons.RenderOpen()) { if (AscType == 0 || _persistentData.Options.ShowAllAscendancyClasses) return; foreach (var i in RootNodeList) { if (!SkilledNodes.Contains(Skillnodes[(ushort)i])) continue; var node = Skillnodes[(ushort)i]; string imageName; switch (type) { case "Highlight": imageName = "PassiveSkillScreenAscendancyButtonHighlight"; break; case "Pressed": imageName = "PassiveSkillScreenAscendancyButtonPressed"; break; default: imageName = "PassiveSkillScreenAscendancyButton"; break; } var b = Assets[imageName]; var brush = new ImageBrush(Assets[imageName]); var worldPos = node.Position; const int distanceFromStartNodeCenter = 325; var dirX = 0.0; var dirY = 1.0; var distToCentre = Math.Sqrt(worldPos.X * worldPos.X + worldPos.Y * worldPos.Y); var isCentered = Math.Abs(worldPos.X) < 10.0 && Math.Abs(worldPos.Y) < 10.0; if (!isCentered) { dirX = worldPos.X / distToCentre; dirY = -worldPos.Y / distToCentre; } var ascButtonRot = Math.Atan2(dirX, dirY); var buttonCx = worldPos.X + distanceFromStartNodeCenter * Math.Cos(ascButtonRot + Math.PI / 2); var buttonCy = worldPos.Y + distanceFromStartNodeCenter * Math.Sin(ascButtonRot + Math.PI / 2); var buttonPoint = new Vector2D(buttonCx, buttonCy); var rect = new Rect(buttonCx - b.Height * 1.75, buttonCy - b.Width * 1.75, b.Width * 2.5, b.Height * 2.5); dc.PushTransform(new RotateTransform(ascButtonRot * (180 / Math.PI), buttonCx, buttonCy)); dc.DrawRectangle(brush, null, rect); AscButtonPosition = buttonPoint; } } }
public static Vector2D? IntersectLineLine(Vector2D s1, Vector2D e1, Vector2D s2, Vector2D e2) { var aabb1 = new Rect2D(s1, e1); var aabb2 = new Rect2D(s2, e2); if (!aabb1.IntersectsWith(aabb2)) return null; double x1 = s1.X; double x2 = e1.X; double x3 = s2.X; double x4 = e2.X; double y1 = s1.Y; double y2 = e1.Y; double y3 = s2.Y; double y4 = e2.Y; double denom = (x1 - x2)*(y3 - y4) - (y1 - y2)*(x3 - x4); if (Math.Abs(denom) < 1e-4) return null; double px = ((x1*y2 - y1*x2)*(x3 - x4) - (x1 - x2)*(x3*y4 - y3*x4))/denom; double py = ((x1*y2 - y1*x2)*(y3 - y4) - (y1 - y2)*(x3*y4 - y3*x4))/denom; var p = new Vector2D(px, py); double l1 = (p - s1).Length; double l2 = (p - e1).Length; if (l1 + l2 > (s1 - e1).Length + 1e-3) return null; return p; }
//public Vector2D RandomRotate( double minAngle, double maxAngle, Random r ) //{ // double angle = r.NextBetween( minAngle, maxAngle ); // return Rotate( angle ); //} public static bool EpsilonEquals(Vector2D v1, Vector2D v2, double epsilon = 1e-5) { return (v1 - v2).Length < epsilon; }
public static double DistanceLinePoint(Vector2D start, Vector2D end, Vector2D v, out Vector2D nearest) { Vector2D dir = v - start; Vector2D borderDir = (end - start).Normalized(); double dot = borderDir.Dot(dir); if (dot < 0) { nearest = start; return (v - start).Length; } if (dot > (end - start).Length) { nearest = end; return (v - end).Length; } Vector2D tangent = borderDir*dot; nearest = start + tangent; Vector2D normal = dir - tangent; return normal.Length; }
public static double DistanceLinePoint(Vector2D start, Vector2D end, Vector2D v) { Vector2D n; return DistanceLinePoint(start, end, v, out n); }
internal void DrawNodeBaseSurroundHighlight() { float factor = 1.2f; using (DrawingContext dc = picSkillSurroundHighlight.RenderOpen()) { if (HighlightedNodes != null) { foreach (ushort skillNode in HighlightedNodes) { Vector2D pos = (Skillnodes[skillNode].Position); if (Skillnodes[skillNode].IsNotable) { dc.DrawRectangle(NodeSurroundHighlightBrush[3].Value, null, new Rect((int)pos.X - NodeSurroundBrush[3].Key.Width * factor, (int)pos.Y - NodeSurroundBrush[3].Key.Height * factor, NodeSurroundBrush[3].Key.Width * 2 * factor, NodeSurroundBrush[3].Key.Height * 2 * factor)); } else if (Skillnodes[skillNode].IsKeyStone) { dc.DrawRectangle(NodeSurroundHighlightBrush[2].Value, null, new Rect((int)pos.X - NodeSurroundBrush[2].Key.Width * factor, (int)pos.Y - NodeSurroundBrush[2].Key.Height * factor, NodeSurroundBrush[2].Key.Width * 2 * factor, NodeSurroundBrush[2].Key.Height * 2 * factor)); } else if (Skillnodes[skillNode].IsMastery) { //Needs to be here so that "Masteries" (Middle images of nodes) don't get anything drawn around them. } else { dc.DrawRectangle(NodeSurroundHighlightBrush[0].Value, null, new Rect((int)pos.X - NodeSurroundBrush[0].Key.Width * factor, (int)pos.Y - NodeSurroundBrush[0].Key.Height * factor, NodeSurroundBrush[0].Key.Width * 2 * factor, NodeSurroundBrush[0].Key.Height * 2 * factor)); } } } } var pen2 = new Pen(new SolidColorBrush(_treeComparisonColor), 25 * factor); using (DrawingContext dc = picPathHighlight.RenderOpen()) { if (HighlightedNodes != null) { foreach (ushort n1 in HighlightedNodes) { foreach (SkillNode n2 in Skillnodes[n1].Neighbor) { if (HighlightedNodes.Contains(n2.Id)) { DrawConnection(dc, pen2, n2, Skillnodes[n1]); } } } } } }