public void ClearNodes() { lock (bubbleDictionary) { foreach (long oid in bubbleDictionary.Keys) { BubbleTextNode node = bubbleDictionary[oid]; window.RemoveChild(node.Widget); node.Dispose(); } bubbleDictionary.Clear(); } }
public void RemoveNode(long oid) { lock (bubbleDictionary) { if (!bubbleDictionary.ContainsKey(oid)) { return; } BubbleTextNode node = bubbleDictionary[oid]; window.RemoveChild(node.Widget); bubbleDictionary.Remove(oid); node.Dispose(); } }
public void SetBubbleText(long oid, string text, long now) { lock (bubbleDictionary) { if (bubbleDictionary.ContainsKey(oid)) { BubbleTextNode node = bubbleDictionary[oid]; // expire in 5 seconds, plus one second for each 5 chars long expire = now + 5000 + (1000 * text.Length) / 5; node.SetText(text, expire); UpdateNode(node, now); } } }
/// <summary> /// Lock on the bubble dictionary is held already /// </summary> /// <param name="widgetNode"></param> /// <param name="now"></param> private void UpdateNode(AttachedWidget widgetNode, long now) { const float MaxFadeRange = 40 * Client.OneMeter; const float MinFadeRange = 20 * Client.OneMeter; const float MaxFadeRangeSquared = MaxFadeRange * MaxFadeRange; const float MinFadeRangeSquared = MinFadeRange * MinFadeRange; Axiom.MathLib.Vector3 ray = widgetNode.Node.DerivedPosition - client.Camera.DerivedPosition; // Don't show if they are too far away if (ray.LengthSquared > MaxFadeRangeSquared) { widgetNode.Visible = false; return; } BubbleTextNode bubbleNode = (BubbleTextNode)widgetNode; if (bubbleNode.IsExpired(now)) { widgetNode.Visible = false; return; } Vector3 widgetOffset = new Vector3(0, 0.3f * Client.OneMeter, 0); Point pixelOffset = new Point(0, -50); // if (!SetWidgetPosition(widgetNode, widgetOffset, pixelOffset)) if (!SetWidgetPosition(widgetNode, Vector3.Zero, pixelOffset)) { return; } if (ray.LengthSquared < MinFadeRangeSquared) { widgetNode.Widget.Alpha = 1.0f; } else { widgetNode.Widget.Alpha = 1.0f - (ray.Length - MinFadeRange) / (MaxFadeRange - MinFadeRange); } if (this.Visible) { widgetNode.Visible = true; } }
// FIXME: Thread safety public void AddNode(long oid, ObjectNode objNode) { BubbleTextNode widgetNode = new BubbleTextNode(oid); Node attachNode = null; WidgetSceneObject attachObj = new WidgetSceneObject(); attachObj.WidgetNode = widgetNode; AttachmentPoint ap = objNode.GetAttachmentPoint("bubble-disabled"); if (ap == null) { // Default to a bit larger than the height of the bounding box float objectHeight = objNode.Entity.BoundingBox.Size.y * 1.02f; ap = new AttachmentPoint("bubble-disabled", null, Quaternion.Identity, Vector3.UnitY * objectHeight); } attachNode = objNode.AttachLocalObject(ap, attachObj); if (attachNode == null) { widgetNode.NodeVisible = true; widgetNode.Node = objNode.SceneNode; } else { // The node visible will be set by the attachObj widgetNode.Node = attachNode; } // FIXME // widgetNode.Widget.Font = font; window.AddChild(widgetNode.Widget); widgetNode.Widget.Initialize(); widgetNode.SetFont(font); lock (bubbleDictionary) { bubbleDictionary[oid] = widgetNode; } }