Originally Posted by Theroxis
If you want it to hide on login, you'll need to wait for the PLAYER_ENTERING_WORLD event:
Code:
function fHandler_OnEvent(self, event, addon)
if event == "PLAYER_ENTERING_WORLD" then
--Your code here
end
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", fHandler_OnEvent)
If you are using that hacked down version of the ImprovedBlizzardUI I posted in the other thread and want to add more frames, don't make a complete new addon just add additional frames:
Code:
--[[
Stripped from ImprovedBlizzardUI by Theroxis
Modified to ONLY hide/unhide the player frame.
modules\frames\player.lua
Styles, Scales and Repositions the Player Unit Frame.
Disables Player Portrait Spam
]]
local PlayerUnitFrame = CreateFrame('Frame', nil, UIParent);
local ForceShown = false
--[[
Hides the Player Frame when you are out of combat, have no target and are at full health.
@ param boolean $hide Should we hide the frame
@ return void
]]
local function HidePlayer(hide)
if (InCombatLockdown() == false) then
if (hide and UnitHealth('player') == UnitHealthMax('player') and UnitExists('target') == false and (not ForceShown)) then
PlayerFrame:Hide();
PetFrame:Hide();
PetFrameManaBar:SetScript("OnShow", PetFrameManaBar.Hide)
else
PlayerFrame:Show();
PetFrame:Show();
PetFrameManaBar:SetScript("OnShow", PetFrameManaBar.Show)
end
end
end
--[[
Handles the WoW API Events Registered Below
@ param Frame $self The Frame that is handling the event
@ param string $event The WoW API Event that has been triggered
@ param arg $... The arguments of the Event
@ return void
]]
local function HandleEvents (self, event, ...)
if (event == 'PLAYER_ENTERING_WORLD' or event == 'PLAYER_LOGIN' or event == 'ADDON_LOADED') then
HidePlayer(true);
end
if (event == 'PLAYER_REGEN_DISABLED') then
HidePlayer(false);
elseif (event == 'PLAYER_REGEN_ENABLED' or event == 'UNIT_HEALTH') then
HidePlayer(true);
end
if (event == 'PLAYER_TARGET_CHANGED') then
if (UnitExists('target')) then
HidePlayer(false);
else
HidePlayer(true);
end
end
if (event == 'UNIT_EXITED_VEHICLE' and ... == 'player') then
StyleFrames();
end
end
function TogglePlayerFrameHide()
ForceShown = not ForceShown
HidePlayer(true)
end
-- Register the Modules Events
PlayerUnitFrame:SetScript('OnEvent', HandleEvents);
PlayerUnitFrame:RegisterEvent('PLAYER_ENTERING_WORLD');
PlayerUnitFrame:RegisterEvent('PLAYER_LOGIN');
PlayerUnitFrame:RegisterEvent('UNIT_HEALTH');
PlayerUnitFrame:RegisterEvent('PLAYER_REGEN_DISABLED');
PlayerUnitFrame:RegisterEvent('PLAYER_REGEN_ENABLED');
PlayerUnitFrame:RegisterEvent('PLAYER_TARGET_CHANGED');
PlayerUnitFrame:RegisterEvent('UNIT_EXITED_VEHICLE');
PlayerUnitFrame:RegisterEvent('ADDON_LOADED');
Obviously I'm not exactly certain what you desire in this; if you want to wait until your pet's health is full then you could just wrap the PetFrame show and hide functions in a conditional, so they aren't hidden until the pet is at full health as well.
Also you can use the state driver with an OnShow hook like the example above:
Code:
RegisterStateDriver(PetFrame,"visibility","[combat,@pet,exists] show;hide")
PetFrameManaBar:SetScript("OnShow", function()
if PetFrame:IsVisible() then
PetFrameManaBar:Show()
else
PetFrameManaBar:Hide()
end
end)
Note that the last solution is probably the most elegant for working around the quirky mana bar behavior. It let's the bar show if the frame itself is visible, but hides it if not.
|
So basically I want the pet frame to do the same exact things as the player frame so show while targeting,in combat,and if the pet isn’t at full health. And hide if not. As far as the mana bar I want it hidden all the time. This code looks good to point me in the right direction so I’m going to see what I come up with and I’ll check back in. Wish me luck ��
Edit:so i gave it a try and it seems that
RegisterStateDriver(PetFrame,"visibility","[combat,@pet,exists] show;hide")
is the only thing that seem to work to not show the pet frame upon login. problem is that when the pet is not at full health the frame will blink for a second then disapear consistently meaning the command listed is conflicting with the visibility of the pet frame. feel like im so close just i know im missing like a small overlook.
Edit2: also tried
Code:
function fHandler_OnEvent(self, event, addon)
if event == "PLAYER_ENTERING_WORLD" then
PetFrame:Hide()
end
end
and still visible when i reload seems the only thing that has worked so far is the state driver