WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   frame replacing (https://www.wowinterface.com/forums/showthread.php?t=50002)

Danielps1 10-02-14 04:56 PM

frame replacing
 
Hi,

There is a simple boolean variable which determines if some "all" debuffs are shown or only own debuffs(of the target).

So when = true then it will only show own debuffs
when = false it will show all debuffs

I want to make a modifier with the shift key to show all debuffs when the shiftkey is pressed and hide them again when shift is realeased.

Lua Code:
  1. if IsShiftKeyDown() then
  2.  cfg.aura.onlyShowPlayer = false
  3.  else
  4.  cfg.aura.onlyShowPlayer = true
  5.  end


This is my very simple solution for it which works. The problem here is though it only works on starting of the script. That is not very efficent because I would send my user into a loadingscreen.

OnUpdate should fix my problem here which will run this specific code everytime a frame gets rendered which is pretty handy and is what I want to accomplish.

So this is what I made

Lua Code:
  1. local function onUpdate(self,elapsed)
  2.  if IsShiftKeyDown() then
  3.  cfg.aura.onlyShowPlayer = false
  4.  else
  5.  cfg.aura.onlyShowPlayer = true
  6.  end
  7.  end
  8.  
  9.  local shiftdebuffs = CreateFrame("frame")
  10.  shiftdebuffs:SetScript("OnUpdate", onUpdate)


My problem is now that it doesn't work. I new to the onUpdate stuff and only copy pasted it from another addon I did which worked fine.
Right it goes straight to = false, which is only happening I think because it is the default.

thanks for the help

weird title, can't change it.

Danielps1 10-05-14 09:56 AM

bump

~ 10 characters ~

Duugu 10-05-14 10:32 AM

You OnUpdate code is ok and does work as expected.

There must be something wrong within other parts of your code.

Danielps1 10-05-14 11:04 AM

Quote:

Originally Posted by Duugu (Post 297435)
You OnUpdate code is ok and does work as expected.

There must be something wrong within other parts of your code.

Hm, thanks atleast I'm good there. Sadly the rest of the code is from ouF_Skaarj and I don't really understand all of that.
This is what I found in Skarj's code

Lua Code:
  1. if cfg.aura.target_debuffs then
  2.             local d = CreateFrame('Frame', nil, self)
  3.             d.size = 23
  4.             d.spacing = 5
  5.             d.num = cfg.aura.target_debuffs_num
  6.             d:SetPoint('BOTTOMLEFT', self, 'TOPLEFT', 0, 8)
  7.             d:SetSize(cfg.player.width, d.size)
  8.             d.initialAnchor = 'TOPLEFT'
  9.             d.onlyShowPlayer = cfg.aura.onlyShowPlayer
  10.             d.PostCreateIcon = auraIcon
  11.             d.PostUpdateIcon = PostUpdateIcon
  12.             d.CustomFilter = CustomFilter
  13.             self.Debuffs = d      
  14.         end

Duugu 10-05-14 11:12 AM

So you're using an unmodified version of ouF_Skaarj and just would like to add a way to show your own auras on shift key?

Danielps1 10-05-14 11:13 AM

Quote:

Originally Posted by Duugu (Post 297437)
So you're using an unmodified version of ouF_Skaarj and just would like to add a way to show your own auras on shift key?

Well I changed a lot ouf things in terms of style, but yeah basically I want to do that. Skarj is sadly not aroun d or so, not sure.

Duugu 10-05-14 12:16 PM

I'm not that motivated to dig into the code of ouF_Skaarj to be honest. :) But this you be a quick and dirty solution.

Try to replace

Lua Code:
  1. local customFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster)
  2.     if((icons.onlyShowPlayer and icon.isPlayer) or (not icons.onlyShowPlayer and name)) then
  3.         return true
  4.     end
  5. end

in aura.lua with

Lua Code:
  1. local customFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster)
  2.     if(((icons.onlyShowPlayer or IsShiftKeyDown()) and icon.isPlayer) or (not icons.onlyShowPlayer and name)) then
  3.         return true
  4.     end
  5. end

Didn't test this though. :)

Danielps1 10-05-14 12:30 PM

Hmm, I know where you are going with this but it doesn't work. I'm not sure why

Phanx 10-05-14 07:05 PM

1. Never use an OnUpdate script if there's an event you can respond to instead. OnUpdate scripts run every time a new video output frame is drawn -- if you're running at 60 FPS, every OnUpdate script is getting run 60 times per second. In this case, there is an event that tells you when modifier keys are pressed or released -- MODIFIER_STATE_CHANGED.

2. Simply checking for the modifier state in the aura filter won't really work, because modifier state changes don't trigger an aura display update -- only aura changes do that.

3. I already do this in my layout; here's a standalone adaptation that will work with any oUF layout to show all auras while Shift is pressed, and restore whatever filter you normally have when it's released:

Code:

local f = CreateFrame("Frame")
f:RegisterEvent("MODIFIER_STATE_CHANGED")
f:SetScript("OnEvent", function(f, event, key, state)
        if key ~= "LSHIFT" and key ~= "RSHIFT" then
                return
        end
        local a, b
        if state == 1 then
                a, b = "CustomFilter", "__CustomFilter"
        else
                a, b = "__CustomFilter", "CustomFilter"
        end
        for i = 1, #oUF.objects do
                local object = oUF.objects[i]
                local buffs = object.Auras or object.Buffs
                if buffs and buffs[a] then
                        buffs[b] = buffs[a]
                        buffs[a] = nil
                        buffs:ForceUpdate()
                end
                local debuffs = object.Debuffs
                if debuffs and debuffs[a] then
                        debuffs[b] = debuffs[a]
                        debuffs[a] = nil
                        debuffs:ForceUpdate()
                end
        end
end)


Danielps1 10-05-14 11:46 PM

Okay, Thank you

But doesn't the filter from the ouF Layout apply after this one which would make the de/buffs visible/not visible again?

I just tried it and it doesn't seem to work. No Error code but as long as the debuffs are still turned on in skaarj config nothing changes.

Phanx 10-06-14 01:42 AM

What the code I posted does:

When you press the Shift key, it removes the CustomFilter from all Auras, Buffs, and Debuffs elements on all oUF frames, and forces them all to update. This will cause all buffs and debuffs to be displayed, since there is no filtering in place.

When you release the Shift key, it replaces whatever CustomFilter was on each Auras, Buffs, and Debuffs element on each oUF frame, and forces them all to update. This will cause buffs and debuffs to be filtered according to your CustomFilter function again.

If you use the code I posted, your CustomFilter function should apply normal (non-Shift key) filtering all the time, because it will never be run while the Shift key is pressed. If it has any checks to apply special filtering, get rid of them.

If you want something other than the functionality I just described, please be more specific about what you're looking for. Based on the description in your original post, it sounded like this is what you wanted -- show all auras on Shift, otherwise apply your filter.

Danielps1 10-06-14 04:12 AM

No the functionality is exactly want I want.

But for I don't get it working. I there is no special filtering in place by Skarj as far as I have seen, so your Code should work, but it just doesn't.

Phanx 10-06-14 04:17 AM

Yes, there is:
Code:

local CustomFilter = function(icons, ...)
    local _, icon, name, _, _, _, _, _, _, caster = ...
    local isPlayer
    if (caster == 'player' or caster == 'vechicle') then
        isPlayer = true
    end
    if((icons.onlyShowPlayer and isPlayer) or (not icons.onlyShowPlayer and name)) then
        icon.isPlayer = isPlayer
        icon.owner = caster
        return true
    end
end

Have you made any changes to that part of the code?

Danielps1 10-06-14 04:53 AM

Quote:

Originally Posted by Phanx (Post 297453)
Yes, there is:
Have you made any changes to that part of the code?

I removed it earlier to try if your code works, but it doesn't :( forgot to mention, I tried. I just tried again without and with the code but it doesn't seem to do anything.

Also tried leaving the aurafilter in the cfg of ouf_skaarj on/off but that didn't make any change aswell, except that it still works so you can still Hide debuffs on the target with the cfg.aura.ShowOnlyPlayer

Phanx 10-06-14 11:11 AM

Where did you put the code I gave you? Are you sure it's even running? Add some print statements to make sure:

Code:

        if state == 1 then
                print("Shift pressed, removing aura filters")
                a, b = "CustomFilter", "__CustomFilter"
        else
                print("Shift released, restoring aura filters")
                a, b = "__CustomFilter", "CustomFilter"
        end


Danielps1 10-06-14 12:33 PM

I tried aura.lua and layout.lua

both same result "Shift released, restoring aura filters"

Phanx 10-06-14 12:51 PM

Are you on live or beta? If you're on beta, they may have changed the "state" argument passed into the event to a boolean or something else that isn't a numeric 1 for "the key is pressed".

Code:

        print("Shift changed:", type(state), state)
        if state == 1 then


Danielps1 10-06-14 01:01 PM

Quote:

Originally Posted by Phanx (Post 297467)
Are you on live or beta? If you're on beta, they may have changed the "state" argument passed into the event to a boolean or something else that isn't a numeric 1 for "the key is pressed".

Code:

        print("Shift changed:", type(state), state)
        if state == 1 then


No, live servers

Phanx 10-06-14 02:37 PM

Are you sure you don't have some third-party software messing with your keyboard? There's no way that releasing a key should indicate it's pressed. I just tested in-game and it's still passing 1/0, which I fully expected since the code was copied and pasted from my own oUF layout where it's working just fine.

Type "/etrace" in-game, press Shift, and release Shift. The mouseover the MODIFIER_STATE_CHANGED events in the window and look at arg2. It should be a numeric 1 on press, 0 on release. If it's something else please post what it is.

Danielps1 10-06-14 03:04 PM

No works perfectly.


Lombra 10-06-14 04:39 PM

Quote:

Originally Posted by Phanx (Post 297467)
Code:

        print("Shift changed:", type(state), state)
        if state == 1 then


Do this anyway. You must've gotten the arguments mixed up somehow?

Danielps1 10-07-14 04:12 AM

Hmm,

This is what my chat looks like now.



It does the exact same thing when pressing shift/or not

Lombra 10-07-14 05:16 AM

Can you post your whole OnEvent function?

Danielps1 10-07-14 06:04 AM

Quote:

Originally Posted by Lombra (Post 297482)
Can you post your whole OnEvent function?

Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterEvent("MODIFIER_STATE_CHANGED")
  3. f:SetScript("OnEvent", function(f, event, key, state)
  4.     if key ~= "LSHIFT" and key ~= "RSHIFT" then
  5.         return
  6.     end
  7.     local a, b
  8.     if state == 1 then
  9.         a, b = "CustomFilter", "__CustomFilter"
  10.     else
  11.         a, b = "__CustomFilter", "CustomFilter"
  12.     end
  13.     for i = 1, #oUF.objects do
  14.         local object = oUF.objects[i]
  15.         local buffs = object.Auras or object.Buffs
  16.         if buffs and buffs[a] then
  17.             buffs[b] = buffs[a]
  18.             buffs[a] = nil
  19.             buffs:ForceUpdate()
  20.         end
  21.         local debuffs = object.Debuffs
  22.         if debuffs and debuffs[a] then
  23.             debuffs[b] = debuffs[a]
  24.             debuffs[a] = nil
  25.             debuffs:ForceUpdate()
  26.         end
  27.     end
  28. end)
  29.  
  30. print("Shift changed:", type(state), state)
  31.     if state == 1 then
  32.         print("Shift pressed, removing aura filters")
  33.         a, b = "CustomFilter", "__CustomFilter"
  34.     else
  35.         print("Shift released, restoring aura filters")
  36.         a, b = "__CustomFilter", "CustomFilter"
  37.     end

Lombra 10-07-14 07:16 AM

Ok, you should've placed the bottom snippet inside the event handler, so that's probably working, after all. The problem will be in the oUF bit, but I have no idea what's going on there, nor how oUF works.

Danielps1 10-07-14 07:32 AM

Quote:

Originally Posted by Lombra (Post 297485)
Ok, you should've placed the bottom snippet inside the event handler, so that's probably working, after all. The problem will be in the oUF bit, but I have no idea what's going on there, nor how oUF works.

Ugh, I'm stupid. Yeah works fine now, but sadly that doesn't help with finding the solution to the Aura filter problem :D


Duugu 10-07-14 07:42 AM

Well, then try to find out whats wrong. Just add a print(key, state) to you OnEvent handler. :) What does it print?

Danielps1 10-07-14 08:05 AM

Quote:

Originally Posted by Duugu (Post 297487)
Well, then try to find out whats wrong. Just add a print(key, state) to you OnEvent handler. :) What does it print?

I don't get what i would accomplish that way. the state is fine, it knows when shift is pressed and released. The Problem is the filter doesn't get removed

Duugu 10-07-14 08:07 AM

Quote:

Originally Posted by Danielps1 (Post 297489)
I don't get what i would accomplish that way. the state is fine, it knows when shift is pressed and released. The Problem is the filter doesn't get removed

Ah. Sorry. Then I've mixed up something. :) Thought "if state == 1 then" still does not trigger.

Phanx 10-07-14 07:53 PM

Post your entire addon.

Danielps1 10-07-14 11:16 PM

Quote:

Originally Posted by Phanx (Post 297513)
Post your entire addon.

That's a lot of code, I zipped it since there are over 40 files or so in that Addon.

I really appreciate the help. I know that's a lot of work.

oUF_Skaarj: https://www.mediafire.com/?ust166y91ht5k2h


If you actually need to run the Addon and you probably need my other folder too which includes the media for oUF_Skaarj

https://www.mediafire.com/?cscjvjvdbp6jo7b

Phanx 10-09-14 03:41 AM

Well, as written, your player frame only has a Debuffs element, which is not filtered, and your target frame's Buffs and Debuffs elements are not filtered either, so while the code I posted works just fine and does what it should do, there's no visible result because there are no filters to remove and restore. What exactly are you hoping to do?

Danielps1 10-09-14 04:57 AM

Quote:

Originally Posted by Phanx (Post 297556)
Well, as written, your player frame only has a Debuffs element, which is not filtered, and your target frame's Buffs and Debuffs elements are not filtered either, so while the code I posted works just fine and does what it should do, there's no visible result because there are no filters to remove and restore. What exactly are you hoping to do?

But the Target frame has a filter for only showing personal debuffs. Normally it shows them in color and shows the other Debuff in b/w.

But there is also an option to ONLY show my own debuffs, which is exactly what I am looking for.

Phanx 10-09-14 07:32 PM

Quote:

Originally Posted by Danielps1 (Post 297558)
But the Target frame has a filter for only showing personal debuffs. Normally it shows them in color and shows the other Debuff in b/w.

No, it doesn't. If there ever was such code, it's commented out. You can verify in-game that the target frame debuffs are not filtered; put the mouse over the target frame and type:

/dump GetMouseFocus().Debuffs.CustomFilter
"empty result"

Danielps1 10-10-14 02:12 AM

Quote:

Originally Posted by Phanx (Post 297566)
No, it doesn't. If there ever was such code, it's commented out. You can verify in-game that the target frame debuffs are not filtered; put the mouse over the target frame and type:

/dump GetMouseFocus().Debuffs.CustomFilter
"empty result"

Yeah I get empty result aswell. But some filter is going on, since not all enemy Debuffs are beeing displayed. I tested it in raid and on training dummy's, only my own Debuffs are shown. I don't know where that filter is coming from.

Lombra 10-10-14 02:28 AM

That's an option in the default UI.

Phanx 10-10-14 02:58 AM

Filter options for the default UI do not affect oUF.

However, on further investigation, oUF itself applies a filter if you don't supply one, and if you set certain properties on the Debuffs element:

Code:

local customFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster)
        if((icons.onlyShowPlayer and icon.isPlayer) or (not icons.onlyShowPlayer and name)) then
                return true
        end
end

If you want to use this default filter instead of supplying your own, then I'd suggest that rather than removing the filter, you replace it with a dummy one that lets everything through:

Code:

local showall = function() return true end

local f = CreateFrame("Frame")
f:RegisterEvent("MODIFIER_STATE_CHANGED")
f:SetScript("OnEvent", function(f, event, key, state)
        if key ~= "LSHIFT" and key ~= "RSHIFT" then
                return
        end
        local a, b
        if state == 1 then
                a, b = "CustomFilter", "__CustomFilter"
        else
                a, b = "__CustomFilter", "CustomFilter"
        end
        for i = 1, #oUF.objects do
                local object = oUF.objects[i]
                local buffs = object.Auras or object.Buffs
                if buffs and buffs[a] then
                        buffs[b] = buffs[a]
                        buffs[a] = showall
                        buffs:ForceUpdate()
                end
                local debuffs = object.Debuffs
                if debuffs and debuffs[a] then
                        debuffs[b] = debuffs[a]
                        debuffs[a] = showall
                        debuffs:ForceUpdate()
                end
        end
end)



All times are GMT -6. The time now is 03:19 AM.

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