Thread Tools Display Modes
05-01-15, 03:10 AM   #1
Valixx
A Deviate Faerie Dragon
 
Valixx's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2013
Posts: 12
LUA: Hide default frames OOC and show if target

Hello guys.

I need some help with the following. Here's what I need it ( the code ) to do:
  • Hide if out of combat ( this works so far )
  • show if I have a target ( this isn't )

Lua Code:
  1. local f = CreateFrame('frame', nil, nil, 'SecureHandlerStateTemplate')
  2. f:SetFrameRef('PlayerFrame', PlayerFrame)
  3. f:SetFrameRef('TargetFrame', TargetFrame)
  4. f:SetFrameRef('FocusFrame', FocusFrame)
  5. f:SetFrameRef('ComboFrame', ComboFrame)
  6. f:SetAttribute('_onstate-combat', [=[ -- Securely toggle visibility in combat
  7.     if newstate == 'show' then
  8.         self:GetFrameRef('PlayerFrame'):Show()
  9.         if UnitExists('target') then
  10.             self:GetFrameRef('TargetFrame'):Show()
  11.             self:GetFrameRef('PlayerFrame'):Show()
  12.         end
  13.         if UnitExists('focus') then
  14.             self:GetFrameRef('FocusFrame'):Show()
  15.         end
  16.     else
  17.         self:GetFrameRef('PlayerFrame'):Hide()
  18.         self:GetFrameRef('TargetFrame'):Hide()
  19.         self:GetFrameRef('FocusFrame'):Hide()
  20.         self:GetFrameRef('ComboFrame'):Hide()
  21.     end
  22. ]=])
  23. RegisterStateDriver(f, 'combat', '[combat] show; hide', '[target, exists] show')
  24.  
  25. local function HideFrame(self) -- Insecurely hide out of combat if shown
  26.     if not InCombatLockdown() or not UnitExists("target") then self:Hide() end
  27. end
  28. PlayerFrame:HookScript('OnShow', HideFrame)
  29. TargetFrame:HookScript('OnShow', HideFrame)
  30. FocusFrame:HookScript('OnShow', HideFrame)
  31. ComboFrame:HookScript('OnShow', HideFrame)
  32.  
  33. f:SetScript('OnEvent', function(self, event)
  34.     if GetComboPoints('player', 'target') > 0 then -- Show ComboFrame upon entering combat if we have points
  35.         ComboFrame:Show()
  36.     end
  37. end)
  38. f:RegisterEvent('PLAYER_REGEN_DISABLED')
__________________
I'm a Web-Designer with Love for WordPress, HTML5, CSS3, LESS and JavaScript.
You need anything? Message me!
  Reply With Quote
05-01-15, 03:21 AM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You have your target condition as a completely separate 4th argument for RegisterStateDriver, which only takes 3 arguments.
Lua Code:
  1. RegisterStateDriver(f, 'combat', '[combat] show; hide', '[target, exists] show')

You need to combine the macro conditions into one string that handles both situations.
Lua Code:
  1. RegisterStateDriver(f, 'combat', '[target,exists][combat] show; hide')

The other problem is that you're hooking all of their OnShow scripts to hide the frame 'if not InCombatLockdown() or not UnitExists("target")', which means it will always attempt to hide the frame if it's shown out of combat.

It should use "and" instead of "or" since you can't securely hide the frames in combat that way, however it should not be necessary to hide any of the frames this way if the state driver is working, so you might as well remove the hooks.

Last edited by semlar : 05-01-15 at 03:28 AM.
  Reply With Quote
05-01-15, 03:33 AM   #3
Valixx
A Deviate Faerie Dragon
 
Valixx's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2013
Posts: 12
Thanks for answering. I'll see what I can do later... need to go and cook something fine

Allright, just seen your edit. I'll try that then.

I'll report back later. Thank you.
__________________
I'm a Web-Designer with Love for WordPress, HTML5, CSS3, LESS and JavaScript.
You need anything? Message me!
  Reply With Quote
05-01-15, 03:50 AM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You might also consider reparenting all of these frames to frame f and simply hiding and showing that rather than handling them separately, that way you won't have to worry about them being shown when they're not supposed to be.

If you choose to do that you'll want to make f a child of UIParent to keep the scales consistent.
  Reply With Quote
05-01-15, 05:13 AM   #5
Valixx
A Deviate Faerie Dragon
 
Valixx's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2013
Posts: 12
The unitframes are working fine now. If there's a target and in combat, they are showing. Extactly what I wanted.

Lua Code:
  1. local f = CreateFrame('frame', nil, nil, 'SecureHandlerStateTemplate')
  2. f:SetFrameRef('PlayerFrame', PlayerFrame)
  3. f:SetFrameRef('TargetFrame', TargetFrame)
  4. f:SetFrameRef('FocusFrame', FocusFrame)
  5. f:SetFrameRef('ComboFrame', ComboFrame)
  6. f:SetAttribute('_onstate-combat', [=[ -- Securely toggle visibility in combat
  7.     if newstate == 'show' then
  8.         self:GetFrameRef('PlayerFrame'):Show()
  9.         if UnitExists('target') then
  10.             self:GetFrameRef('TargetFrame'):Show()
  11.             self:GetFrameRef('PlayerFrame'):Show()
  12.         end
  13.         if UnitExists('focus') then
  14.             self:GetFrameRef('FocusFrame'):Show()
  15.         end
  16.     else
  17.         self:GetFrameRef('PlayerFrame'):Hide()
  18.         self:GetFrameRef('TargetFrame'):Hide()
  19.         self:GetFrameRef('FocusFrame'):Hide()
  20.         self:GetFrameRef('ComboFrame'):Hide()
  21.     end
  22. ]=])
  23. RegisterStateDriver(f, 'combat', '[target,exists][combat] show; hide')
  24.  
  25. f:RegisterEvent('PLAYER_REGEN_DISABLED')

The second thing I wanted to try is to show the minimap only if in combat. This is what I got so far:

Lua Code:
  1. MinimapCluster:RegisterEvent("PLAYER_REGEN_ENABLED")
  2. MinimapCluster:RegisterEvent("PLAYER_REGEN_DISABLED")
  3. MinimapCluster:HookScript("OnEvent", function(self, event)
  4.     if event == "PLAYER_REGEN_ENABLED" then
  5.         self:Hide()
  6.     else
  7.         self:Show()
  8.     end
  9. end)

This is what happens after a /reload:

Out of combat -> Minimap is shown.
Entering combat -> Minimap is shown.
Leaving combat -> Minimap is hidden.

Any tips on how to hide it from the start ( login / reload )?
__________________
I'm a Web-Designer with Love for WordPress, HTML5, CSS3, LESS and JavaScript.
You need anything? Message me!

Last edited by Valixx : 05-01-15 at 05:18 AM.
  Reply With Quote
05-01-15, 05:33 AM   #6
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Valixx View Post
Any tips on how to hide it from the start ( login / reload )?
Register event PLAYER_LOGIN and do something like self:SetShown(event == 'PLAYER_REGEN_DISABLED')
  Reply With Quote
05-01-15, 06:11 AM   #7
Valixx
A Deviate Faerie Dragon
 
Valixx's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2013
Posts: 12
I tried so many things, it just won't work... still trying..

I even added commands and stuff, everything's working fine but the hide on login... Tried with ADDON_LOADED, PLAYER_ENTERING_WORLD and PLAYER_LOGIN.
__________________
I'm a Web-Designer with Love for WordPress, HTML5, CSS3, LESS and JavaScript.
You need anything? Message me!

Last edited by Valixx : 05-01-15 at 06:30 AM.
  Reply With Quote
05-01-15, 06:33 AM   #8
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
I don't know what you tried, but this works fine for me, at least as far as I understand what you're asking.
Lua Code:
  1. MinimapCluster:RegisterEvent("PLAYER_REGEN_ENABLED")
  2. MinimapCluster:RegisterEvent("PLAYER_REGEN_DISABLED")
  3. MinimapCluster:RegisterEvent("PLAYER_LOGIN")
  4. MinimapCluster:HookScript("OnEvent", function(self, event)
  5.     self:SetShown(event == "PLAYER_REGEN_DISABLED")
  6. end)
  Reply With Quote
05-01-15, 07:22 AM   #9
Valixx
A Deviate Faerie Dragon
 
Valixx's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2013
Posts: 12
Got everything working now. I did the same thing to hide the BuffFrame and it works too.

Thanks for your help, I appreaciate it.
__________________
I'm a Web-Designer with Love for WordPress, HTML5, CSS3, LESS and JavaScript.
You need anything? Message me!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » LUA: Hide default frames OOC and show if target


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off