WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Tutorials & Other Helpful Info. (https://www.wowinterface.com/forums/forumdisplay.php?f=12)
-   -   How To : Right click removing buff (https://www.wowinterface.com/forums/showthread.php?t=36117)

sigg 10-22-10 03:43 AM

How To : Right click removing buff
 
Hello

I know that the new SecuredAuraheader is quite complicated to use, this is a helper to show you how RDX handle that.

Create a file AuraButtonTemplate.xml :
The secureAuraengine need a xml template to create buttons on the fly :

Code:

<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
        <Button name="RDXAB30x30Template" inherits="SecureActionButtonTemplate" virtual="true">
                <Size x="30" y="30"/>
                <Attributes>
                        <Attribute name="type" value="cancelaura"/>
                </Attributes>
                <Scripts>
                        <OnLoad>
                                self:RegisterForClicks("RightButtonUp");
                        </OnLoad>
                        <OnEnter>
                                GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT");
                                GameTooltip:SetFrameLevel(self:GetFrameLevel() + 2);
                                if self:GetAttribute("target-slot") == 16 or self:GetAttribute("target-slot") == 17 or self:GetAttribute("target-slot") == 18 then
                                        GameTooltip:SetInventoryItem("player", self:GetID());
                                else
                                        GameTooltip:SetUnitAura("player", self:GetID());
                                end
                        </OnEnter>
                        <OnLeave>
                                GameTooltip:Hide();
                        </OnLeave>
                </Scripts>
        </Button>
</Ui>

Important tags description :
Size This will define the height and width of your buff, example: <Size x="30" y="30"/>
Attribute : indicate the button is a cancelaura type.
<Attributes>
<Attribute name="type" value="cancelaura"/>
</Attributes>


Create the SecureAuraHeader handler :

Code:

local headerAura = CreateFrame("Frame", "SAH", nil, "SecureAuraHeaderTemplate");
headerAura:SetAttribute("unit", "player"); -- to activate UNITAURA event refresh
headerAura:SetAttribute("filter", "HELPFUL");
headerAura:SetAttribute("template", "RDXAB30x30Template"); -- must be the template name of your XML
headerAura:SetAttribute("minWidth", 100);
headerAura:SetAttribute("minHeight", 100);

-- the following code create a buff bar anchor to TOPLEFT and buff orientation goes to right with 10 buttons max on two rows
headerAura:SetAttribute("point", "TOPLEFT");
headerAura:SetAttribute("xOffset", 30);
headerAura:SetAttribute("yOffset", 0);
headerAura:SetAttribute("wrapAfter", 10);
headerAura:SetAttribute("wrapXOffset", 0);
headerAura:SetAttribute("wrapYOffset", -30);
headerAura:SetAttribute("maxWraps", 2);

-- sorting
headerAura:SetAttribute("sortMethod", "NAME"); -- INDEX or NAME or TIME
headerAura:SetAttribute("sortDir", "+"); -- - to reverse
headerAura:Show();

-- provide a simple iterator to the header
local function siter_active_children(header, i)
        i = i + 1;
        local child = header:GetAttribute("child" .. i);
        if child and child:IsShown() then
                return i, child, child:GetAttribute("index");
        end
end
function headerAura:ActiveChildren() return siter_active_children, self, 0; end

-- The update style function
local function updateStyle()
        for _,frame in headerAura:ActiveChildren() do
               
                -- create style texture if it doesn't exist
                if not frame.tex then
                        frame.tex = CreateTexture(frame);
                        frame.tex:SetAllPoints(frame);
                       
                        frame.cd = CreateFrame("Cooldown");
                        frame.cd:SetAllPoints(frame);
                       
                        frame.txt = CreateFontString(frame);
                        frame.txt:SetAllPoints(frame);
                        frame.txt:SetFont(GameFontNormal);
                end
               
                local name, _, icon, count, debuffType, duration, expirationTime = UnitAura("player", frame:GetID(), "HELPFUL");
                if name then
                        frame.tex:SetTexture(icon);
                        frame.cd:SetCooldown(expirationTime - duration, duration);
                        if count > 1 then frame.txt:SetText(count); else frame.txt:SetText("");end
                        frame.tex:Show();
                        frame.cd:Show();
                        frame.txt:Show();
                else
                        frame.tex:Hide();
                        frame.cd:Hide();
                        frame.txt:Hide();
                end
        end
end

create a new handler to update the style of each button

Code:

local f = CreateFrame("Frame");
f:RegisterEvent("UNIT_AURA");

-- in the OnEvent UNIT_AURA :
-- depending of the framework you are using, delay the update to the next frame. I suppose there is a similary function in ace. The example here use our VFL framework
VFLT.NextFrame(math.random(10000000), function() updateStyle() end);

I hope this will help you in your addons.

Cheers
Sigg

Sideshow 10-22-10 04:38 AM

Nice post ! I need that :)

Kurak 10-22-10 05:25 AM

Great, but you could even pray for people like me who have not much idea of it, explain in what folder is it?:confused::confused:

sigg 10-22-10 06:44 AM

this is a sample code for developer LUA.

:eek:

Luzzifus 10-22-10 07:43 AM

I'm trying to set up your example code as a standalone addon right now. I had to change some of these CreateTexture/CreateFontString calls. Also the events fire and call the updateStyle function. However I don't see any buffs ingame. Am I missing something?

Quote:

-- the following code create a buff bar anchor to TOPLEFT and buff orientation goes to right with 10 buttons max on two rows
headerAura:SetAttribute("point", "TOPLEFT");
headerAura:SetAttribute("xOffset", 30);
headerAura:SetAttribute("yOffset", 0);
headerAura:SetAttribute("wrapAfter", 10);
headerAura:SetAttribute("wrapXOffset", 0);
headerAura:SetAttribute("wrapYOffset", -30);
headerAura:SetAttribute("maxWraps", 2);

Which one of these lines would do that red thing? :confused:

Also I did a quick search for any documentation on the SecureAuraHeaderTemplate, like.. eh.. usage maybe. ^^ Came up with basically nothing, I can't even find it in the Blizz UI Source Code..

**edit: After your example and explanation it really doesn't sound so complicated anymore, thank you for that! If only I could see my buffs. :D

Maul 10-22-10 07:43 AM

Woot, thanks :)

Ailae 10-22-10 07:50 AM

Quote:

Originally Posted by Luzzifus (Post 213296)
I can't even find it in the Blizz UI Source Code..

http://github.com/tekkub/wow-ui-sour...oupHeaders.xml
http://github.com/tekkub/wow-ui-sour...oupHeaders.lua

Thanks for the code, gonna play around with it a bit. But why does the update have to happen "on next frame"?

sigg 10-22-10 07:52 AM

Hello

About the style function, you have to call it in the next frame call, because the engine auraheader also use the event "UNIT_AURA" to update itself.

What I saw, was the style function is called before the auraheader update.

Goes to right :
headerAura:SetAttribute("xOffset", 30);
headerAura:SetAttribute("yOffset", 0);

Goes to left :
headerAura:SetAttribute("xOffset", -30);
headerAura:SetAttribute("yOffset", 0);

Goes to down :
headerAura:SetAttribute("xOffset", 0);
headerAura:SetAttribute("yOffset", -30);

Goes to up:
headerAura:SetAttribute("xOffset", 0);
headerAura:SetAttribute("yOffset", 30);

You should be able to move your mouse on the button and see the gametooltip.

sigg 10-22-10 08:10 AM

the SecureAuraHeaderTemplate is located in the SecureGroupHeaders.lua

Luzzifus 10-22-10 08:28 AM

Thanks to both of you (Ailae and sigg)!

The reason why I didn't see anything was because I forgot to call :SetPoint on the header.. *cough* It's working now.

sigg 10-22-10 08:51 AM

Now let's talk about the weapon enchant.

The system is still buggy and Blizzard has not finished it.
- Rightclick on the weapon enchant is not working (bug blizzard SecureTemplates.lua:395: attempt to call global 'CancelItemTempEnchant' (a nil value)).
- The gametooltip of the second enchant always show the main hand. (file SecureGroupHeaders.lua, line 777, local slot = GetInventorySlotInfo("MainHandSlot");, replace MainHandSlot by SecondaryHandSlot)
- The third weapon enchant button is not implemented yet in the new securedauraheader

Add this in the header :

Code:

headerAura:SetAttribute("includeWeapons", 1);
headerAura:SetAttribute("weaponTemplate", "RDXAB30x30Template");

In the style function :

Code:

local tempEnchant1 = headerAura:GetAttribute("tempEnchant1");
if tempEnchant1 then
        if not tempEnchant1.tex then
                -- create your style
        end
        local hasMainHandEnchant, mainHandExpiration, mainHandCharges = GetWeaponEnchantInfo();
        if hasMainHandEnchant then
                local slotid = GetInventorySlotInfo("MainHandSlot");
                local icon = GetInventoryItemTexture("player", slotid);
                tempEnchant1.tex:SetTexture(icon);
                if mainHandCharges > 1 then tempEnchant1.txt:SetText(mainHandCharges); else tempEnchant1.txt:SetText("");end
                tempEnchant1.tex:Show();
                tempEnchant1.txt:Show();
        else
                tempEnchant1.tex:Hide();
                tempEnchant1.txt:Hide();
        end
end

:p

Dargen 10-22-10 09:06 AM

These are the issues that I've encountered so far with the current implementation of the SecureAuraHeader:

SecureTemplates.lua:
- You cannot cancel a weapon enchantment since the CancelTempEnchantment() function is spelled incorrectly.

SecureGroupHeaders.lua:
- Does not update the buttons if using a unit like "target" and the target changes, etc.
- The "consolidateDuration" attribute mentioned in comments never gets used.
- The "sortDir" attribute mentioned in the comments is spelled as "sortDirection" in the actual code.
- The comments for the xOffset attribute say the default is width, however the code sets the default to 0.
- The comments for the yOffset attribute say the default is height, however the code sets the default to 0.
- sortFactory(): If the "separateOwn" attribute is 0 it will be handled as if it were -1.
- configureAuras(): Setting the "wrapAfter" attribute to nil or 0 results in a divide by nil or 0 error.
- configureAuras(): Cannot use a string template name for the "consolidateProxy" attribute or "consolidateHeader" attribute because the code tests the return value of type() for an uppercase 'STRING'.
- configureAuras(): Assigns the slot number for the MainHandSlot to the off hand enchant button's "target-slot" attribute and :SetID(). You can work around this by comparing the child frame's value to header:GetAttribute("tempEnchant2") and supplying your own inventory slot number.
- extractTemplateInfo(): Does not properly separate a template name from a widget type when both are specified in a template name string.
- SecureAuraHeader_OnUpdate(): Does not track consolidated buffs in order to move them out of consolidation when time remaining is short.
- SecureAuraHeader_Update(): Setting the "includeWeapons" attribute to 0 will cause weapon buttons to be displayed if they have previously been created.
- SecureAuraHeader_Update(): The logic that decides which buffs to add to the consoliation frame is adding buffs with short rather than long time remaining values.
- SecureAuraHeader_Update(): Due to a bug in the loop that parses the "groupBy" attribute, only the last filter in a comma separated list will be used.

Dargen 10-22-10 10:29 AM

Blizzard updates the aura header anytime it is shown, it receives a UNIT_AURA event, or an attribute is assigned to it.

When setting a number of attributes in the header you can minimize the number of times Blizzard updates the header by setting the "_ignore" attribute first (or you can hide the header since the OnAttributeChanged script also ignores attribute updates when the header is not visible).

As long as the "_ignore" attribute is set, Blizzard will not update the header. When you're finished changing attributes, restore the original "_ignore" attribute value. To force a header update you can then set any other attribute.

Code:

local oldIgnore = header:GetAttribute("_ignore");
header:SetAttribute("_ignore", "attributeChanges");
-- Set all your header attributes here
header:SetAttribute("_ignore", oldIgnore);
header:SetAttribute("_update", header:GetAttribute("_update"));


Luzzifus 10-22-10 03:18 PM

I just uploaded a first version of a very lightweight buff frame replacement using SecureAuraHeaders:

http://www.wowinterface.com/download...-nivBuffs.html

Rightclicking buffs off works like a charm (except for weapon enchants, as already said). If something doesn't work, feel free to flame me.

(No seriously, don't. :p )

Rilgamon 10-23-10 12:53 AM

This is a great guide to help me understand what I need to learn ... BIG THANK YOU!!

For my addon ProcWatch I have one bar that shows certain buffs on more than one unit (player, target, focus). From reading your guide I guess this will no longer work when I want cancleaura to work. Am I right ?

Grimsin 10-23-10 01:39 AM

Someone make sure Elkano sees this, ElkBB! :banana:

Luzzifus 10-24-10 02:13 PM

You don't need those calls to Show() and Hide() for buttons in the updateStyle() function. The headers do that on their own and the calls cause taint errors in combat.

Btw. how would I make it work with the consolidation feature, when Blizzards code to create the consolidation button from a template is broken?

Rilgamon 10-27-10 02:17 PM

I'm playing with cancelaura ... why on earth do I have to set "unit" ?
Are there other units than player where I can cancel an aura ? ;)

v6o 10-27-10 06:31 PM

Quote:

Originally Posted by Rilgamon (Post 214665)
I'm playing with cancelaura ... why on earth do I have to set "unit" ?
Are there other units than player where I can cancel an aura ? ;)

You can cancel vehicle buffs, and possibly pet

Rilgamon 10-27-10 10:27 PM

Quote:

Originally Posted by v6o (Post 214737)
You can cancel vehicle buffs, and possibly pet

ups, never thought of that or tried it :) thanks for the tip :D

v6o 10-28-10 07:13 AM

Would hooking the header's OnEvent ensure that it's run after the default update so the vehicle updates do not happen to "early" ?

Edit: Should just had realized the problem lies in that the unit attribute is still player even when entering a vehicle and that's why it's not updating correctly. Just made it change unit on attribute whenever you enter or exit an vehicle.

When you change any attribute the header updates so there's not much else to do to it it seems :)

v6o 10-28-10 03:19 PM

Anyone got experience with the sorting blizzard implemented? Is it working? More specifically is TIME working?

When I try it I get some weird orders...

Mischback 10-30-10 05:43 PM

Quote:

Originally Posted by v6o (Post 214888)
Anyone got experience with the sorting blizzard implemented? Is it working? More specifically is TIME working?

When I try it I get some weird orders...

Same here, TIME doesn't seem to work...

Dargen 10-31-10 05:00 AM

Quote:

Originally Posted by v6o (Post 214813)
Should just had realized the problem lies in that the unit attribute is still player even when entering a vehicle and that's why it's not updating correctly. Just made it change unit on attribute whenever you enter or exit an vehicle.

When you change any attribute the header updates so there's not much else to do to it it seems :)

One thing to remember is that you can't change the unit attribute if you are in combat when you get into or out of the vehicle.

Dargen 10-31-10 05:08 AM

Quote:

Originally Posted by Mischback (Post 215255)
Same here, TIME doesn't seem to work...

I believe sorting by time is working correctly. However, there is a bug that causes it to always separate the buffs you've cast from the buffs cast by other people, so it can look like the list is not properly sorted. It would be nice if there was a way to customize if buffs with no duration got sorted to the top or bottom.

v6o 10-31-10 11:21 AM

Quote:

Originally Posted by Dargen (Post 215344)
One thing to remember is that you can't change the unit attribute if you are in combat when you get into or out of the vehicle.

Doh. Completely forgot about the secure restrictions.... Is it possible to change the unit attribute with secure code or should I just make a double and show/hide with a secure on-state handler (or whatever they're called)


Edit: Tried to test this in combat but not sure if I left as I was dismounted, any way to shorten this?

Code:

local sechan = CreateFrame("Frame", nil, nil, "SecureHandlerStateTemplate")
sechan:SetAttribute("_onstate-aurastate", [[
local buffs = self:GetFrameRef("auraframe1")
local debuffs = self:GetFrameRef("auraframe2")
if newstate == "invehicle" then
    buffs:SetAttribute("unit", "vehicle")
    debuffs:SetAttribute("unit", "vehicle")
elseif newstate == "notinvehicle" then
    buffs:SetAttribute("unit", "player")
    debuffs:SetAttribute("unit", "player")
end
]])

sechan:SetFrameRef("auraframe1", buffs)
sechan:SetFrameRef("auraframe2", debuffs)
RegisterStateDriver(sechan, "aurastate", "[vehicleui] invehicle; notinvehicle")


Taroven 11-07-10 09:25 AM

Code:

local sechan = CreateFrame("Frame", nil, nil, "SecureHandlerStateTemplate")
sechan:SetAttribute("_onstate-aurastate", [[
local buffs = self:GetFrameRef("auraframe1")
local debuffs = self:GetFrameRef("auraframe2")
local state = newstate == "invehicle" and "vehicle" or "player"
buffs:SetAttribute("unit",state)
debuffs:SetAttribute("unit",state)
]])

sechan:SetFrameRef("auraframe1", buffs)
sechan:SetFrameRef("auraframe2", debuffs)
RegisterStateDriver(sechan, "aurastate", "[vehicleui] invehicle; notinvehicle")

Not sure about the framerefs, but that at least gets rid of the if statement.

aX0rZ 11-10-10 11:36 AM

I'm currently trying to implement SecureAuraHeaderTemplates in my UnitFrame-AddOn. So I'm using it for "unit"-Attribute-Values != "player". But I'm having some problems with it. Generally my code is based on nivBuffs which is based on the code sigg posted.

1. When i have no unit in target and then target any unit, buffs are correctly shown. But when I then target another unit, the buffs of the old unit are shown. I call the "UpdateStyle"-function when targets change but it seems SecureAuraHeaderTemplates do no adjust the buff-frames (child1, ...) when switching target.
2. Sometimes new buffs are not shown on my player frame. This is true for being inside combat aswell as for not.

Did anyone implement anything like this yet. Is it a flaw in my code or in Blizzards? Or do you need to see my code to judge that?

zork 11-11-10 10:11 AM

You need that only for player buffs. You cannot cancel buffs on your target anyway so those can be just normal textures.

aX0rZ 11-11-10 10:39 AM

Well I think it simplyfies the code, for example its super easy to sort the buffs (just :SetAttribute call). Also if blizzard changes something about their buff api or how events are handeld for buffs i just have to use SecureAuraHandler witch makes it easier to maintain my code.

aX0rZ 11-11-10 11:07 AM

Quote:

Originally Posted by aX0rZ (Post 217223)
1. When i have no unit in target and then target any unit, buffs are correctly shown. But when I then target another unit, the buffs of the old unit are shown. I call the "UpdateStyle"-function when targets change but it seems SecureAuraHeaderTemplates do no adjust the buff-frames (child1, ...) when switching target.

Managed to resolve this issue. A simple "SecureAuraHeader_Update(header)" inserted at the beggining of "UpdateStyle" fixed that. But when now applying a new buff in combat I get an error, so it only works ooc.

v6o 11-11-10 12:47 PM

You will need to force an update from an secure environment whenever your target changes. I do not know how to do this.

aX0rZ 11-11-10 01:10 PM

Quote:

Originally Posted by v6o (Post 217369)
As you change target nothing happens to the auras because the unit is still "target". You will need to force an update but you need to remember that you will have to do it from secure code.

Well how do i force an update? With SecureAuraHeader_Update()? That doesn't work infight, probably because my Event-Handler is not secure code. But how do you react to events in a secure environment? I also tried force an update with "header:SetAttribute("unit", header:GetAttribute("unit"))", because SecureAuraHeader_OnAttributeChange updates the header everytime an attribute is changed, which should be secure code since it's frome blizzard, but that didn't work.

MoonWitch 11-12-10 05:53 PM

Ok, I've been constantly trying... I've tried with XML, without, with SecureAuraHeader, with SecureActionButton .. quite frankly - my "solution" worked fine for Seerah she told me, but somehow - it doesn't work for me >.<

I can only disable first most left and most right buff. So could someone be kind and help me understand a bit more?

Code is at https://github.com/moonwitch/Furbish/tree/experimental

Seerah 11-12-10 08:38 PM

I actually didn't need any solution other than to stop doing something stupid that was tainting after 4.0. I just changed my method to a better, smarter way.

I don't sort or filter my buffs, I only skin them. That's why it worked.

aX0rZ 11-13-10 02:00 AM

Quote:

Originally Posted by MoonWitch (Post 217553)
Ok, I've been constantly trying... I've tried with XML, without, with SecureAuraHeader, with SecureActionButton .. quite frankly - my "solution" worked fine for Seerah she told me, but somehow - it doesn't work for me >.<

I can only disable first most left and most right buff. So could someone be kind and help me understand a bit more?

Code is at https://github.com/moonwitch/Furbish/tree/experimental

As far as I understand SecureAuraHeaderTemplate the following is wrong:
  1. When you use :SetScript("OnEvent", ...) on "addon", you overite the SecureAuraHeader Event-Handler, so removing its functionallity. Rather use :HookScript().
  2. You don't need to register "UNIT_AURA" on "addon", since Blizzard does that for you.
  3. It's not "addon" that needs :EnableMouse() and :SetScript("OnEnter/OnLeave") you need to do this for every buff frame
  4. (I'm not sure on this) It seems like you want to use the default Blizzard Buff Frames, I don't know if thats possible, rather create your own (You already have in your .xml but you don't use them).
  5. You miss a bunch of :SetAttribute() calls. As far as i remember there are atleast 3 or so needed to display any buffs in any way. You can get all the attribute names at http://wow.go-hero.net/framexml/1311...oupHeaders.lua line 614.
  6. Once your BuffCount and DebuffCount reach BUFF_MAX_DISPLAY/DEBUFF_MAX_DISPLAY you unregister UNIT_AURA resulting in that Buffs are no longer updated

If you have any problems I recommend taking a look into nivBuffs it's very clean code and it's working.

MoonWitch 11-14-10 07:04 AM

I have taken a look at nivBuffs, still no win.

I took out :
- the positioning
- the ref to UNIT_AURA
- the enablemouse (and tooltip part in the xml)
- max display was taken out as well

As far attributes go : I don't quite see which ones I am missing that are needed. Unless all of them are needed, then Blizz created a monster :(

@Seerah : Show me?

EDIT : Apparently Show() is key :P

Ailae 11-14-10 07:40 AM

There really is no need to use the new SecureAuraHeaderTemplate if you are just moving and/or skinning the buff-buttons. It's only useful if you want to filter or sort buffs, since that would taint the original Blizzard BuffFrame.

So you seem to be mixing apples with oranges right now. Here's my local copy of Furbish, that I hacked a bit to also add a border. Maybe it'll help. To get the buffs where you want you must move both the BuffFrame and the ConsolidatedBuffs since Blizzards anchors the second row to ConsolidatedBuffs.

http://pastebin.com/axuBEh9G

Looking at your mission statement on what's different in your version of Furbish, it would be how the times are formatted, which is easily changed at the top of the paste I linked.

MoonWitch 11-14-10 07:47 AM

Well, the mission statement was slightly outdated :P

Basically here's what the my version did :
- Skin buffs, debuffs
- relocate
- add timers

And apparently those 3 made sure I got taint >.< So I set out to solve it. (I really do need that right click) Now that being said, I could only get it partially working. It seems to have a mind of its own.

Thank you, Ailae, you solved it for me, I thought I had gone through all the global blizzy stuff, but apparently I missed one.

BUFF_WARNING_TIME <- causes taint. So it works fine now, thanks!

Talyrius 01-24-11 09:38 AM

Does anyone know if the problems with temporary weapon enchants in the SecureAuraHeader have been fixed on the PTR?


All times are GMT -6. The time now is 06:35 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI