Stanzilla / WoWUIBugs

World of Warcraft UI Bug Tracker
166 stars 7 forks source link

Pings: Allow configuring ping units via an attribute #476

Closed Meorawr closed 10 months ago

Meorawr commented 1 year ago

Currently the ping system allows defining a frame to be a "ping receiver" that - if the ping hotkey is pressed while mouseovered - can trigger a contextual ping that can be redirected to a specific unit. This integration requires that a frame include PingableType_UnitFrameMixin, which will communicate the desired unit via a unit field on the frame table itself.

This however isn't too convenient for use with secure group headers that display party and raid frames; the secure header system creates frames on-demand as units come into existence and stores the unit token in a "unit" attribute, rather than as a field. Additionally, there's some more boilerplate required to apply this mixin to newly-created unit frames on-demand.

It'd be convenient for the following changes to be made:

  1. For PingableType_UnitFrameMixin:GetTargetPingGUID to query both the "unit" attribute and field.
  2. For a new template to be added that includes PingableType_UnitFrameMixin.

Essentially these changes could just look like this:

diff --git a/Interface/SharedXML/PingAttributes.xml b/Interface/SharedXML/PingAttributes.xml
index 8e08df40..a13f5095 100644
--- a/Interface/SharedXML/PingAttributes.xml
+++ b/Interface/SharedXML/PingAttributes.xml
@@ -12,4 +12,6 @@
            <Attribute name="ping-top-level-pass-through" type="boolean" value="true"/>
        </Attributes>
    </Frame>
+
+   <Frame name="PingableUnitFrameTemplate" mixin="PingableType_UnitFrameMixin" inherits="PingReceiverAttributeTemplate" virtual="true"/>
 </Ui>
\ No newline at end of file
diff --git a/Interface/SharedXML/PingableType.lua b/Interface/SharedXML/PingableType.lua
index a0c7faed..29ad122d 100644
--- a/Interface/SharedXML/PingableType.lua
+++ b/Interface/SharedXML/PingableType.lua
@@ -19,5 +19,5 @@ function PingableType_UnitFrameMixin:GetContextualPingType()
 end

 function PingableType_UnitFrameMixin:GetTargetPingGUID()
-    return UnitGUID(self.unit);
+    return UnitGUID(self:GetAttribute("unit") or self.unit);
 end
\ No newline at end of file

With these changes addons that use secure headers won't need to manually synchronize changes made to the "unit" attribute to a field of the same name on the frame table itself, and can opt-in to being ping receivers by adding a single space-separated template name to the "template" attribute on the group header without needing to add any additional logic to apply the mixin manually.

Meorawr commented 10 months ago

Implemented in 10.2.5.52206.