Quantcast How do I prevent a frame from showing during combat - WoWInterface
Thread Tools Display Modes
10-21-19, 04:51 AM   #1
LBXZero
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 54
How do I prevent a frame from showing during combat

Currently, I have an addon that directly modifies the behavior of Blizzard's Spellbook to filter what spells are shown. Due to nature of operation, I can't avoid tainting it.

I have gotten around most problems trying to match the normal Spellbook's operation while providing a filtered spell list. The only problem left is if the spellbook is open during combat. After some trial and error, the simplest solution is to close the spellbook at the start of combat (done) and keep it from opening during combat.

Right now, I don't know how to keep SpellBookFrame from showing during combat if requested to show.
  Reply With Quote
10-21-19, 05:22 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,345
Edit: Although, I just noticed that you had got to the preventative measure but now need to control blizzards button.. best guess is to disbale the button before combat starts and restore it afterwards, similar to how I use my frames minimize button. Hopefully doing that minor change to blizzards button won't cause an issue.


I use the events that monitor regen ability and lock windows in place at that point that I don;t want being interacted with.


frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")


When regen is enabled, combat is finished and normal interaction is allowed, the opposite with disabled status.

When disabled I disable interactive buttons and enable them when regen is enabled again.

I also have an auto minimize/hide and maximize/show functionality that will change the frame to a more combat friendly shape and visibility and restore it back to its original status .. handy if you were in the middle of something and you were attacked.

This is an example from my MagePortals addon.
Lua Code:
  1. frame:SetScript("OnEvent",function(self,event,...)
  2.             local args = { ... }
  3.             if event == "PLAYER_ENTERING_WORLD" then
  4.                 frame:RegisterEvent("PLAYER_REGEN_ENABLED")
  5.                 frame:RegisterEvent("PLAYER_REGEN_DISABLED")
  6.             elseif event == "PLAYER_REGEN_DISABLED" then
  7.                 XMP_MinimizeButton_OnClick(frame.MinimizeButton,true)
  8.                 XMP_Header.MinimizeButton:Disable()
  9.                 XMP_Header.CloseButton:Disable()
  10.             elseif event == "PLAYER_REGEN_ENABLED" then
  11.                 XMP_MinimizeButton_OnClick(frame.MinimizeButton,true)
  12.                 XMP_Header.MinimizeButton:Enable()
  13.                 XMP_Header.CloseButton:Enable()
  14.             end
  15.         end)

And this is the minimizebutton_onclick function showing how the auto command works.
Lua Code:
  1. function XMP_MinimizeButton_OnClick(frame, auto)
  2.     -- Grab a local copy of the frame as we are using it alot here
  3.     local h = XMP_Header
  4.     -- If we are auto collapsing/expanding due to combat then check which action to do
  5.     if auto then                    
  6.         autoExecuted = false
  7.         -- If we are back after auto minimizing then maximize the frames
  8.         if h.autoMinimized then
  9.             XMP_Maximize(frame)
  10.             autoExecuted = true
  11.         -- Otherwise we are auto minimizing if it is maximized
  12.         elseif not h.isMinimized then
  13.             XMP_Minimize(frame)
  14.             autoExecuted = true
  15.         end        
  16.     else            
  17.         -- Handle manual collapse/expand
  18.         PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  19.         if h.isMinimized then
  20.             XMP_Maximize(frame)
  21.         else
  22.             XMP_Minimize(frame)
  23.         end
  24.     end
  25.     h.autoMinimized = (auto and autoExecuted and h.isMinimized and true) or false            
  26. end
__________________

Last edited by Xrystal : 10-21-19 at 05:26 AM.
  Reply With Quote
10-21-19, 11:35 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,845
Originally Posted by LBXZero View Post
Right now, I don't know how to keep SpellBookFrame from showing during combat if requested to show.
You can use InCombatLockdown() to determine if protected frames are locked due to being in combat.
Code:
SpellBookFrame:HookScript("OnShow",function(self)
	if InCombatLockdown() then self:Hide(); end
end);
Alternatively, you can temporarily replace the frame:Show() and frame:SetShown() methods to nop() to catch and disable any attempt to show the spellbook and set them to nil afterward to restore functions. This works because the original functions are in the frame's metatable and are only accessed if the corresponding entry in the frame's own table doesn't exist.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-21-19, 05:16 PM   #4
LBXZero
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 54
I will try the "nop()" method first. I prefer simple solutions. If that doesn't stop the spellbook from opening during combat, then I will have to disable keybindings and the Blizzard button.

I already tried having "self:Hide()" in the "OnShow" script. The spellbook still shows after the script is ran.
  Reply With Quote
10-22-19, 02:54 AM   #5
LBXZero
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 54
I found a method that works, after a little epiphany...

First, I can't reassign the function for Show() for the specific frame. It became a script error, probably due to the nature of the function.
Trying to Hook a Script or modify the OnShow script to hide the frame, the OnShow Script and the HookScript() attachment run prior to setting the frame to show, so the frame will show.
I didn't try disabling the WoW UI button to open the Spellbook. The reason is that I will also have to disable the key binding, which involves a protected function that I doubt works in a restricted environment.

What I forgot, if the parent frame is hidden, the child frames are hidden regardless if shown. Therefore, I have a blank frame that will always stay hidden set to be SpellBookFrame's parent when PLAYER_REGEN_DISABLED and then restore SpellBookFrame's parent to UIParent when PLAYER_REGEN_ENABLED. This works.

Last edited by LBXZero : 10-22-19 at 03:00 AM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » How do I prevent a frame from showing during combat

Thread Tools
Display Modes

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