Quantcast help with player frames - WoWInterface
Thread Tools Display Modes
08-06-18, 12:17 PM   #1
joeyo
A Fallenroot Satyr
Join Date: Jan 2012
Posts: 25
help with player frames

for some reason im placing
PlayerFrameTexture:Hide()
and
PetFrameManaBar:Hide()
in a .lua but for some reason it does not want to work even though i can run it in game and it works as intended i cant understand how i need to write it so that it will work as if i was running it in game. i have very minimal experience in this subject.
  Reply With Quote
08-06-18, 12:45 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,542
You need to wait until these frames are setup before you can hide anything. Try this:
Lua Code:
  1. local f = CreateFrame("Frame")    --we need a frame to listen for an event
  2. f:RegisterEvent("PLAYER_ENTERING_WORLD")   --we'll listen for this event - all the UI stuff should be done loading by now
  3. f:SetScript("OnEvent", function(self, event)   --when the event fires we want this to happen
  4.      PlayerFrameTexture:Hide()
  5.      PetFrameManaBar:Hide()
  6. end)

Put the above into your Lua file, or you can use this to make your addon instead: https://addon.bool.no/
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-06-18, 01:02 PM   #3
joeyo
A Fallenroot Satyr
Join Date: Jan 2012
Posts: 25
Originally Posted by Seerah View Post
You need to wait until these frames are setup before you can hide anything. Try this:
Lua Code:
  1. local f = CreateFrame("Frame")    --we need a frame to listen for an event
  2. f:RegisterEvent("PLAYER_ENTERING_WORLD")   --we'll listen for this event - all the UI stuff should be done loading by now
  3. f:SetScript("OnEvent", function(self, event)   --when the event fires we want this to happen
  4.      PlayerFrameTexture:Hide()
  5.      PetFrameManaBar:Hide()
  6. end)

Put the above into your Lua file, or you can use this to make your addon instead: https://addon.bool.no/
that seems to work for the player frame but the pet mana bar is still there. could it be something different for register event?
iam also using the line
RegisterStateDriver(PetFrame,"visibility","[combat,@pet,exists] show;hide")
so that it hides when not in combat but when i use that line even if i type
/run PetFrameManaBar:Hide()
it does nothing unless i use it when the frame is visible so is there a way to get it to trigger after the frame is shown?

Edit:tried "PLAYER_ENTER_COMBAT" instead and nothing worked then

Last edited by joeyo : 08-06-18 at 04:56 PM.
  Reply With Quote
08-06-18, 06:53 PM   #4
joeyo
A Fallenroot Satyr
Join Date: Jan 2012
Posts: 25
so ive tried this

so i have been trying to edit a current pieced together .lua so that the pet frame shows when in combat/have a target/less than full health and hides when out of combat and full health.also set to hide the pet mana bar and frame texture.

the problem is that the frame is not hidden from entering the game also i cannot seem to get the pet mana bar to be hidden from entering the game. this is what i got so far if anyone can help out or at least let me know where i went wrong.

Lua:
Code:
-- This file is loaded from "!frame combat.toc"

local PlayerUnitFrame = CreateFrame('Frame', nil, UIParent);  
local ForceShown = false
--[[
    Hides the Pet 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 HidePet(hide)
    if (InCombatLockdown() == false) then
        if (hide and UnitHealth('pet') == UnitHealthMax('pet') and UnitExists('target') == false and (not ForceShown)) then
            PetFrame:Hide();
        else
            PetFrame: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
        HidePet(true);
    end

    if (event == 'PLAYER_REGEN_DISABLED') then
        HidePet(false);
    elseif (event == 'PLAYER_REGEN_ENABLED' or event == 'UNIT_HEALTH') then
        HidePet(true);
    end

    if (event == 'PLAYER_TARGET_CHANGED') then
        if (UnitExists('target')) then
            HidePet(false);
        else
            HidePet(true);
        end
    end

    if (event == 'UNIT_EXITED_VEHICLE' and ... == 'pet') then
        StyleFrames();
    end


end

function TogglePetFrameHide()
	ForceShown = not ForceShown
	DEFAULT_CHAT_FRAME:AddMessage(ForceShown)
	HidePet(true)
end


    local f = CreateFrame("Frame")    --we need a frame to listen for an event
    f:RegisterEvent("PLAYER_ENTERING_WORLD)   --we'll listen for this event - all the UI stuff should be done loading by now
    f:SetScript("OnEvent", function(self, event)   --when the event fires we want this to happen
           PetFrameManaBar:Hide()
    end)
PetFrameTexture:Hide()
-- 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');

Last edited by joeyo : 08-06-18 at 06:55 PM.
  Reply With Quote
08-06-18, 07:18 PM   #5
Vrul
A Frostmaul Preserver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 284
What you are requesting here is slightly different than what you requested in this thread. If you want the PetFrame visible as stated here then you don't need any special code for it since it is parented to PlayerFrame and will show and hide with it already.

If you never want to see PetFrameManaBar then just do:
Code:
PetFrameManaBar:SetScript("OnShow", PetFrameManaBar.Hide)
  Reply With Quote
08-06-18, 07:40 PM   #6
joeyo
A Fallenroot Satyr
Join Date: Jan 2012
Posts: 25
Originally Posted by Vrul View Post
What you are requesting here is slightly different than what you requested in this thread. If you want the PetFrame visible as stated here then you don't need any special code for it since it is parented to PlayerFrame and will show and hide with it already.

If you never want to see PetFrameManaBar then just do:
Code:
PetFrameManaBar:SetScript("OnShow", PetFrameManaBar.Hide)
omg!? how did i miss this well they say learn something new everyday.i truly am thankful as ive spent i think close to all day today trying to get this working right lol
unfortunately i still cannot get the pet frame to not show on login. it seems that once i start combat or even target something it will then follow the .lua and act as intended.
so all i have left with the pet frame is to set it to not show within login and to get rid of the damage numbers and threat circle around the portrait but i have yet to look into that.
  Reply With Quote
08-06-18, 10:02 PM   #7
Theroxis
A Fallenroot Satyr
Join Date: Jun 2018
Posts: 24
Originally Posted by joeyo View Post
omg!? how did i miss this well they say learn something new everyday.i truly am thankful as ive spent i think close to all day today trying to get this working right lol
unfortunately i still cannot get the pet frame to not show on login. it seems that once i start combat or even target something it will then follow the .lua and act as intended.
so all i have left with the pet frame is to set it to not show within login and to get rid of the damage numbers and threat circle around the portrait but i have yet to look into that.
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.

Last edited by Theroxis : 08-06-18 at 10:04 PM.
  Reply With Quote
08-07-18, 08:27 AM   #8
joeyo
A Fallenroot Satyr
Join Date: Jan 2012
Posts: 25
Originally Posted by Theroxis View Post
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

Last edited by joeyo : 08-07-18 at 09:01 AM.
  Reply With Quote
08-07-18, 02:01 PM   #9
joeyo
A Fallenroot Satyr
Join Date: Jan 2012
Posts: 25
anyone? this is killing me that its perfect but this tiny little thing lol
  Reply With Quote
08-07-18, 04:01 PM   #10
Theroxis
A Fallenroot Satyr
Join Date: Jun 2018
Posts: 24
Originally Posted by joeyo View Post
anyone? this is killing me that its perfect but this tiny little thing lol
You could try calling SetAlpha(0) instead of Hide(). This works around frames being hidden and shown by other elements. This won't disable mouse interaction with the frame like Hide() does but if something else calls Show() it will still be hidden because it's set to be 100% transparent (0% opacity)
  Reply With Quote
08-07-18, 04:05 PM   #11
Vrul
A Frostmaul Preserver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 284
You can try the code I posted in the other thread. It does what you stated there and could be tweaked to what you say you now want in this one.
  Reply With Quote
08-07-18, 05:52 PM   #12
joeyo
A Fallenroot Satyr
Join Date: Jan 2012
Posts: 25
Originally Posted by Vrul View Post
You can try the code I posted in the other thread. It does what you stated there and could be tweaked to what you say you now want in this one.
I’m using the lua you posted in the other thread and just replaced everything with petframe or hidepet or any word that says player and it works exactly like the player frame one just for some reason if refuses to be hidden on login but once I select a target and exit target it hides. I’ve tried everything I can think of and have been searching google for the last few days and nothing I find is working. I mean if there’s no solution I could just leave it as is but it’s just the tiniest of things that’s giving me the biggest headache. I’ll try and see if calling set alpha works without conflicting with the rest of the functions.
  Reply With Quote
08-07-18, 06:28 PM   #13
Theroxis
A Fallenroot Satyr
Join Date: Jun 2018
Posts: 24
disregard, didn't work for me.

Last edited by Theroxis : 08-07-18 at 06:48 PM.
  Reply With Quote
08-07-18, 07:02 PM   #14
Vrul
A Frostmaul Preserver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 284
Are you sure another addon or another section of your addon isn't doing it? By default PetFrame is parented to PlayerFrame so if the PlayerFrame is hidden then the PetFrame should also be hidden.

Edit:
If your PetFrame is not parented to PlayerFrame like it seems then you will need to add <frame>:RegisterUnitEvent("UNIT_PET", "player") to your event handler and add code to deal with that event.

Last edited by Vrul : 08-07-18 at 07:15 PM. Reason: Added more info
  Reply With Quote
08-07-18, 07:49 PM   #15
joeyo
A Fallenroot Satyr
Join Date: Jan 2012
Posts: 25
Originally Posted by Vrul View Post
Are you sure another addon or another section of your addon isn't doing it? By default PetFrame is parented to PlayerFrame so if the PlayerFrame is hidden then the PetFrame should also be hidden.

Edit:
If your PetFrame is not parented to PlayerFrame like it seems then you will need to add <frame>:RegisterUnitEvent("UNIT_PET", "player") to your event handler and add code to deal with that event.
EDIT:!!your a genius sir the one line that was missing is something i didnt try! all i needed to add was
Code:
PlayerUnitFrame:RegisterUnitEvent("UNIT_PET", "player");
at the end of it all and it worked!
now is there anyway to combine addons together?
this is to show player frame when in combat or with a target or not at full health.it also hides the texture of the frame and also the player level
Code:
-- This file is loaded from "!frame fade.toc"

--[[
	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();
        else
            PlayerFrame: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
	DEFAULT_CHAT_FRAME:AddMessage(ForceShown)
	HidePlayer(true)
end

    local f = CreateFrame("Frame")    --we need a frame to listen for an event
    f:RegisterEvent("PLAYER_ENTERING_WORLD")   --we'll listen for this event - all the UI stuff should be done loading by now
    f:SetScript("OnEvent", function(self, event)   --when the event fires we want this to happen
         PlayerFrameTexture:Hide();
         PlayerLevelText:Hide()
    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');
this addon does chat/minimap buttons/removes the target/pet frame textures/removes the pet mana bar and also sets the target cast bar on a different parent.
Code:
-- This file is loaded from "!chat.toc"

CHAT_TAB_SHOW_DELAY = 0
CHAT_TAB_HIDE_DELAY = 0
CHAT_FRAME_FADE_TIME = 0
CHAT_FRAME_FADE_OUT_TIME = 0
DEFAULT_CHATFRAME_ALPHA = 0
ChatFrame1:SetTimeVisible(5)
ChatFrame1:SetFadeDuration(3)
MiniMapMailFrame:SetParent(UIParent)
MiniMapMailFrame:SetAlpha(0.4)
QueueStatusMinimapButton:SetParent(UIParent)
QueueStatusMinimapButton:SetAlpha(0.4)
GameTimeFrame:SetParent(UIParent)
GameTimeFrame:SetAlpha(0.4)
GarrisonLandingPageMinimapButton:SetParent(UIParent)
GarrisonLandingPageMinimapButton:SetAlpha(0.4)
MiniMapTracking:SetParent(UIParent)
MiniMapTracking:SetAlpha(0.4)
TargetFrameSpellBar:SetParent(UiParent)
TargetFrameTextureFrameTexture:Hide()
PetFrameManaBar:SetScript("OnShow", PetFrameManaBar.Hide)
PetFrameTexture:Hide()
and this removes the target and focus frame level
Code:
local f=CreateFrame("Frame")
f:SetScript("OnEvent",function(self,event,...)
  if event=="PLAYER_TARGET_CHANGED" then
    -- do TargetFrame changes here
    TargetFrameTextureFrameLevelText:Hide()
  elseif event=="PLAYER_FOCUS_CHANGED" then
    -- do FocusFrame changes here
    FocusFrameTextureFrameLevelText:Hide()
  end
end)
f:RegisterEvent("PLAYER_TARGET_CHANGED")
f:RegisterEvent("PLAYER_FOCUS_CHANGED")
i want to combine all these with the now working pet lua
Code:
-- This file is loaded from "!frame combat.toc"

local PlayerUnitFrame = CreateFrame('Frame', nil, UIParent);  
local ForceShown = false
--[[
    Hides the Pet 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 HidePet(hide)
    if (InCombatLockdown() == false) then
        if (hide and UnitHealth('pet') == UnitHealthMax('pet') and UnitExists('target') == false and (not ForceShown)) then
            PetFrame:Hide();
        else
            PetFrame: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' or event == 'UNIT_PET') then
        HidePet(true);
    end

    if (event == 'PLAYER_REGEN_DISABLED') then
        HidePet(false);
    elseif (event == 'PLAYER_REGEN_ENABLED' or event == 'UNIT_HEALTH') then
        HidePet(true);
    end

    if (event == 'PLAYER_TARGET_CHANGED') then
        if (UnitExists('target')) then
            HidePet(false);
        else
            HidePet(true);
        end
    end

    if (event == 'UNIT_EXITED_VEHICLE' and ... == 'pet') then
        StyleFrames();
    end


end

function TogglePetFrameHide()
	ForceShown = not ForceShown
	DEFAULT_CHAT_FRAME:AddMessage(ForceShown)
	HidePet(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');
PlayerUnitFrame:RegisterUnitEvent("UNIT_PET", "player");
PlayerUnitFrame:RegisterEvent('ADDON_LOADED');
seems everytime i try to combine something it just breaks the whole thing so if the lua masters can help me minimize the amount of addons i have id reeeeeally appreciate it =) i really have learned so much from this little problem though.

Last edited by joeyo : 08-07-18 at 08:18 PM.
  Reply With Quote
08-07-18, 10:52 PM   #16
Vrul
A Frostmaul Preserver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 284
I changed the way you were hiding level text to a more permanent solution.

I commented out the line
Code:
TargetFrameSpellBar:SetParent(UIParent)
because is was causing an error for me. It also had a typo "UiParent" but maybe that is correct for your setup.

I used the code I posted in the other thread as a base and modified from there:
Code:
local frame, forceShow, inCombat, queue = CreateFrame("Frame")
local mayShowPetFrame, playerHasTarget = true

local function UpdatePetFrame()
    if not inCombat then
        local frame = PetFrame
        local unit = frame.unit
        frame:SetShown(mayShowPetFrame and UnitExists(unit) and (forceShow or playerHasTarget or (UnitHealth(unit) < UnitHealthMax(unit))))
    end
end

local function UpdatePlayerFrame()
    if not inCombat then
        local frame = PlayerFrame
        local unit = frame.unit
        frame:SetShown(forceShow or playerHasTarget or (UnitHealth(unit) < UnitHealthMax(unit)))
    end
end

local function DisableShowMode()
    frame:RegisterUnitEvent("UNIT_HEALTH", "player", "pet", "vehicle")
    frame:RegisterUnitEvent("UNIT_MAXHEALTH", "player", "pet", "vehicle")
    if inCombat then
        queue = nil
    end
end

local function EnableShowMode(override)
    frame:UnregisterEvent("UNIT_HEALTH")
    frame:UnregisterEvent("UNIT_MAXHEALTH")
    if not inCombat or override then
        PlayerFrame:Show()
        PetFrame:SetShown(mayShowPetFrame and UnitExists(PetFrame.unit))
    else
        queue = EnableShowMode
    end
end

frame:SetScript("OnEvent", function(self, event, unit)
    if event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH" then
        if unit == PlayerFrame.unit then
            UpdatePlayerFrame()
        elseif unit == PetFrame.unit then
            UpdatePetFrame()
        end
        return
    elseif event == "PLAYER_TARGET_CHANGED" then
        playerHasTarget = UnitExists("target")
    elseif event == "PLAYER_REGEN_DISABLED" then
        inCombat = true
        EnableShowMode(true)
    elseif event == "PLAYER_REGEN_ENABLED" then
        inCombat = false
        (queue or DisableShowMode)()
        queue = nil
    else
        mayShowPetFrame = UnitIsVisible(PetFrame.unit) and PetUsesPetFrame() and not PlayerFrame.vehicleHidesPet
    end
    UpdatePlayerFrame()
    UpdatePetFrame()
end)

frame:RegisterEvent("PET_UI_UPDATE")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_TARGET_CHANGED")
frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", "player")
frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", "player")
frame:RegisterEvent("UNIT_PET", "player")
DisableShowMode()

function ToggleUnitFrameForceShow()
    forceShow = not forceShow
    if forceShow then
        EnableShowMode()
    else
        DisableShowMode()
        UpdatePlayerFrame()
        UpdatePetFrame()
    end
end

--[=[---------------------------------------------------------------------------
Other tweaks
-----------------------------------------------------------------------------]=]
CHAT_TAB_SHOW_DELAY = 0
CHAT_TAB_HIDE_DELAY = 0
CHAT_FRAME_FADE_TIME = 0
CHAT_FRAME_FADE_OUT_TIME = 0
DEFAULT_CHATFRAME_ALPHA = 0

ChatFrame1:SetTimeVisible(5)
ChatFrame1:SetFadeDuration(3)

GameTimeFrame:SetParent(UIParent)
GameTimeFrame:SetAlpha(0.4)

GarrisonLandingPageMinimapButton:SetParent(UIParent)
GarrisonLandingPageMinimapButton:SetAlpha(0.4)

MiniMapMailFrame:SetParent(UIParent)
MiniMapMailFrame:SetAlpha(0.4)

MiniMapTracking:SetParent(UIParent)
MiniMapTracking:SetAlpha(0.4)

PetFrameManaBar:HookScript("OnShow", PetFrameManaBar.Hide)
PetFrameTexture:Hide()

PlayerFrameTexture:SetAlpha(0)

QueueStatusMinimapButton:SetParent(UIParent)
QueueStatusMinimapButton:SetAlpha(0.4)

--TargetFrameSpellBar:SetParent(UIParent)
TargetFrameTextureFrameTexture:Hide()

do
    local SetZeroAlpha = function(self) self:SetAlpha(0) end

    hooksecurefunc(PlayerLevelText, "SetVertexColor", SetZeroAlpha)
    hooksecurefunc(TargetFrameTextureFrameLevelText, "SetVertexColor", SetZeroAlpha)
    hooksecurefunc(FocusFrameTextureFrameLevelText, "SetVertexColor", SetZeroAlpha)
end
The macro text to force showing PlayerFrame and PetFrame (if applicable) without having a target is:
Code:
/run ToggleUnitFrameForceShow()
  Reply With Quote
08-08-18, 10:13 AM   #17
joeyo
A Fallenroot Satyr
Join Date: Jan 2012
Posts: 25
Originally Posted by Vrul View Post
I changed the way you were hiding level text to a more permanent solution.

I commented out the line
Code:
TargetFrameSpellBar:SetParent(UIParent)
because is was causing an error for me. It also had a typo "UiParent" but maybe that is correct for your setup.

I used the code I posted in the other thread as a base and modified from there:
Code:
local frame, forceShow, inCombat, queue = CreateFrame("Frame")
local mayShowPetFrame, playerHasTarget = true

local function UpdatePetFrame()
    if not inCombat then
        local frame = PetFrame
        local unit = frame.unit
        frame:SetShown(mayShowPetFrame and UnitExists(unit) and (forceShow or playerHasTarget or (UnitHealth(unit) < UnitHealthMax(unit))))
    end
end

local function UpdatePlayerFrame()
    if not inCombat then
        local frame = PlayerFrame
        local unit = frame.unit
        frame:SetShown(forceShow or playerHasTarget or (UnitHealth(unit) < UnitHealthMax(unit)))
    end
end

local function DisableShowMode()
    frame:RegisterUnitEvent("UNIT_HEALTH", "player", "pet", "vehicle")
    frame:RegisterUnitEvent("UNIT_MAXHEALTH", "player", "pet", "vehicle")
    if inCombat then
        queue = nil
    end
end

local function EnableShowMode(override)
    frame:UnregisterEvent("UNIT_HEALTH")
    frame:UnregisterEvent("UNIT_MAXHEALTH")
    if not inCombat or override then
        PlayerFrame:Show()
        PetFrame:SetShown(mayShowPetFrame and UnitExists(PetFrame.unit))
    else
        queue = EnableShowMode
    end
end

frame:SetScript("OnEvent", function(self, event, unit)
    if event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH" then
        if unit == PlayerFrame.unit then
            UpdatePlayerFrame()
        elseif unit == PetFrame.unit then
            UpdatePetFrame()
        end
        return
    elseif event == "PLAYER_TARGET_CHANGED" then
        playerHasTarget = UnitExists("target")
    elseif event == "PLAYER_REGEN_DISABLED" then
        inCombat = true
        EnableShowMode(true)
    elseif event == "PLAYER_REGEN_ENABLED" then
        inCombat = false
        (queue or DisableShowMode)()
        queue = nil
    else
        mayShowPetFrame = UnitIsVisible(PetFrame.unit) and PetUsesPetFrame() and not PlayerFrame.vehicleHidesPet
    end
    UpdatePlayerFrame()
    UpdatePetFrame()
end)

frame:RegisterEvent("PET_UI_UPDATE")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_TARGET_CHANGED")
frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", "player")
frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", "player")
frame:RegisterEvent("UNIT_PET", "player")
DisableShowMode()

function ToggleUnitFrameForceShow()
    forceShow = not forceShow
    if forceShow then
        EnableShowMode()
    else
        DisableShowMode()
        UpdatePlayerFrame()
        UpdatePetFrame()
    end
end

--[=[---------------------------------------------------------------------------
Other tweaks
-----------------------------------------------------------------------------]=]
CHAT_TAB_SHOW_DELAY = 0
CHAT_TAB_HIDE_DELAY = 0
CHAT_FRAME_FADE_TIME = 0
CHAT_FRAME_FADE_OUT_TIME = 0
DEFAULT_CHATFRAME_ALPHA = 0

ChatFrame1:SetTimeVisible(5)
ChatFrame1:SetFadeDuration(3)

GameTimeFrame:SetParent(UIParent)
GameTimeFrame:SetAlpha(0.4)

GarrisonLandingPageMinimapButton:SetParent(UIParent)
GarrisonLandingPageMinimapButton:SetAlpha(0.4)

MiniMapMailFrame:SetParent(UIParent)
MiniMapMailFrame:SetAlpha(0.4)

MiniMapTracking:SetParent(UIParent)
MiniMapTracking:SetAlpha(0.4)

PetFrameManaBar:HookScript("OnShow", PetFrameManaBar.Hide)
PetFrameTexture:Hide()

PlayerFrameTexture:SetAlpha(0)

QueueStatusMinimapButton:SetParent(UIParent)
QueueStatusMinimapButton:SetAlpha(0.4)

--TargetFrameSpellBar:SetParent(UIParent)
TargetFrameTextureFrameTexture:Hide()

do
    local SetZeroAlpha = function(self) self:SetAlpha(0) end

    hooksecurefunc(PlayerLevelText, "SetVertexColor", SetZeroAlpha)
    hooksecurefunc(TargetFrameTextureFrameLevelText, "SetVertexColor", SetZeroAlpha)
    hooksecurefunc(FocusFrameTextureFrameLevelText, "SetVertexColor", SetZeroAlpha)
end
The macro text to force showing PlayerFrame and PetFrame (if applicable) without having a target is:
Code:
/run ToggleUnitFrameForceShow()
Works perfect! your a master at your craft sir i hope to be on that level some day i especially love the organization since most my lua code is copy paste mess that i trial and error lol
so i forgot to link one more lua code that i wanted to put in that...
Code:
-- rChat: core
-- zork, 2016

-----------------------------
-- Variables
-----------------------------

local A, L = ...

local DefaultSetItemRef = SetItemRef

local cfg = {}
cfg.dropshadow = {}
cfg.dropshadow.offset = {1,-2}
cfg.dropshadow.color = {0,0,0,0.9}
cfg.editbox = {}
cfg.editbox.font = {STANDARD_TEXT_FONT, 12}
cfg.chat = {}
cfg.chat.font = {STANDARD_TEXT_FONT, 12} --{STANDARD_TEXT_FONT, 12, "OUTLINE"}

-----------------------------
-- Functions
-----------------------------

--SkinChat
local function SkinChat(self)
  if not self then return end
  local name = self:GetName()
  --chat frame resizing
  self:SetClampRectInsets(0, 0, 0, 0)
  self:SetMaxResize(UIParent:GetWidth()/2, UIParent:GetHeight()/2)
  self:SetMinResize(100, 50)
  self:SetFont(unpack(cfg.chat.font))
  self:SetShadowOffset(unpack(cfg.dropshadow.offset))
  self:SetShadowColor(unpack(cfg.dropshadow.color))
  --chat fading
  self:SetFading(true)
  --hide button frame
  local bf = _G[name.."ButtonFrame"]
  bf:HookScript("OnShow", bf.Hide)
  bf:Hide()
  --editbox
  local eb = _G[name.."EditBox"]
  eb:SetAltArrowKeyMode(false)
  --textures
  _G[name.."EditBoxLeft"]:Hide()
  _G[name.."EditBoxMid"]:Hide()
  _G[name.."EditBoxRight"]:Hide()
  --reposition
  eb:ClearAllPoints()
  if name == "ChatFrame2" then
    eb:SetPoint("BOTTOM",self,"TOP",0,22+24) --CombatLogQuickButtonFrame_Custom:GetHeight()
  else
    eb:SetPoint("BOTTOM",self,"TOP",0,22)
  end
  eb:SetPoint("LEFT",self,-5,0)
  eb:SetPoint("RIGHT",self,10,0)
end

--OpenTemporaryWindow
local function OpenTemporaryWindow()
  for _, name in next, CHAT_FRAMES do
    local frame = _G[name]
    if (frame.isTemporary) then
      SkinChat(frame)
    end
  end
end

--OnMOuseScroll
local function OnMOuseScroll(self,dir)
  if(dir > 0) then
    if(IsShiftKeyDown()) then self:ScrollToTop() else self:ScrollUp() end
  else
    if(IsShiftKeyDown()) then self:ScrollToBottom() else self:ScrollDown() end
  end
end

--we replace the default setitemref and use it to parse links for alt invite and url copy
function SetItemRef(link, ...)
  local type, value = link:match("(%a+):(.+)")
  if IsAltKeyDown() and type == "player" then
    InviteUnit(value:match("([^:]+)"))
  elseif (type == "url") then
    local eb = LAST_ACTIVE_CHAT_EDIT_BOX or ChatFrame1EditBox
    if not eb then return end
    eb:SetText(value)
    eb:SetFocus()
    eb:HighlightText()
    if not eb:IsShown() then eb:Show() end
  else
    return DefaultSetItemRef(link, ...)
  end
end

--AddMessage
local function AddMessage(self, text, ...)
  --channel replace (Trade and such)
  text = text:gsub('|h%[(%d+)%. .-%]|h', '|h%1.|h')
  --url search
  text = text:gsub('([wWhH][wWtT][wWtT][%.pP]%S+[^%p%s])', '|cffffffff|Hurl:%1|h[%1]|h|r')
  return self.DefaultAddMessage(self, text, ...)
end

-----------------------------
-- Stuff
-----------------------------

--editbox font
ChatFontNormal:SetFont(unpack(cfg.editbox.font))
ChatFontNormal:SetShadowOffset(unpack(cfg.dropshadow.offset))
ChatFontNormal:SetShadowColor(unpack(cfg.dropshadow.color))

--font size
CHAT_FONT_HEIGHTS = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}

--tabs
CHAT_TAB_HIDE_DELAY = 0
CHAT_FRAME_TAB_NORMAL_MOUSEOVER_ALPHA = 0
CHAT_FRAME_TAB_NORMAL_NOMOUSE_ALPHA = 0
CHAT_FRAME_TAB_SELECTED_MOUSEOVER_ALPHA = 1
CHAT_FRAME_TAB_SELECTED_NOMOUSE_ALPHA = 0
CHAT_FRAME_TAB_ALERTING_MOUSEOVER_ALPHA = 1
CHAT_FRAME_TAB_ALERTING_NOMOUSE_ALPHA = 1

--channels
CHAT_WHISPER_GET              = "<< %s "
CHAT_WHISPER_INFORM_GET       = ">> %s "
CHAT_BN_WHISPER_GET           = "<< %s "
CHAT_BN_WHISPER_INFORM_GET    = ">> %s "
CHAT_YELL_GET                 = "%s "
CHAT_SAY_GET                  = "%s "
CHAT_BATTLEGROUND_GET         = "|Hchannel:Battleground|hBG.|h %s: "
CHAT_BATTLEGROUND_LEADER_GET  = "|Hchannel:Battleground|hBGL.|h %s: "
CHAT_GUILD_GET                = "|Hchannel:Guild|hG.|h %s: "
CHAT_OFFICER_GET              = "|Hchannel:Officer|hGO.|h %s: "
CHAT_PARTY_GET                = "|Hchannel:Party|hP.|h %s: "
CHAT_PARTY_LEADER_GET         = "|Hchannel:Party|hPL.|h %s: "
CHAT_PARTY_GUIDE_GET          = "|Hchannel:Party|hPG.|h %s: "
CHAT_RAID_GET                 = "|Hchannel:Raid|hR.|h %s: "
CHAT_RAID_LEADER_GET          = "|Hchannel:Raid|hRL.|h %s: "
CHAT_RAID_WARNING_GET         = "|Hchannel:RaidWarning|hRW.|h %s: "
CHAT_INSTANCE_CHAT_GET        = "|Hchannel:Battleground|hI.|h %s: "
CHAT_INSTANCE_CHAT_LEADER_GET = "|Hchannel:Battleground|hIL.|h %s: "
--CHAT_MONSTER_PARTY_GET       = CHAT_PARTY_GET
--CHAT_MONSTER_SAY_GET         = CHAT_SAY_GET
--CHAT_MONSTER_WHISPER_GET     = CHAT_WHISPER_GET
--CHAT_MONSTER_YELL_GET        = CHAT_YELL_GET
CHAT_FLAG_AFK = "<AFK> "
CHAT_FLAG_DND = "<DND> "
CHAT_FLAG_GM = "<[GM]> "

--remove the annoying guild loot messages by replacing them with the original ones
YOU_LOOT_MONEY_GUILD = YOU_LOOT_MONEY
LOOT_MONEY_SPLIT_GUILD = LOOT_MONEY_SPLIT

--don't cut the toastframe
BNToastFrame:SetClampedToScreen(true)
BNToastFrame:SetClampRectInsets(-15,15,15,-15)

--hide the menu button
ChatFrameMenuButton:HookScript("OnShow", ChatFrameMenuButton.Hide)
ChatFrameMenuButton:Hide()

--hide the friend micro button
local button = QuickJoinToastButton or FriendsMicroButton
button:HookScript("OnShow", button.Hide)
button:Hide()

--skin chat
for i = 1, NUM_CHAT_WINDOWS do
  local chatframe = _G["ChatFrame"..i]
  SkinChat(chatframe)
  --adjust channel display
  if (i ~= 2) then
    chatframe.DefaultAddMessage = chatframe.AddMessage
    chatframe.AddMessage = AddMessage
  end
end

--scroll
FloatingChatFrame_OnMouseScroll = OnMOuseScroll

--temporary chat windows
hooksecurefunc("FCF_OpenTemporaryWindow", OpenTemporaryWindow)
this is a chat addon ive been using to remove all the buttons and edit box and making the chat completely gone unless mouse over,new whisper, or typing a message.

random question. is there a way to increase the target and player frames name length not the font but trying to get it to for example my toons name is crystaldemon but with the way i have it set it says something like "crystald..." instead of the full name.

Last edited by joeyo : 08-08-18 at 12:03 PM.
  Reply With Quote
08-08-18, 04:31 PM   #18
Vrul
A Frostmaul Preserver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 284
Why would you want to take a separate addon and add it's code in with the other code? Just keep them separate. If anything you should split that other code into two separate files.
  Reply With Quote
08-08-18, 08:29 PM   #19
joeyo
A Fallenroot Satyr
Join Date: Jan 2012
Posts: 25
Originally Posted by Vrul View Post
Why would you want to take a separate addon and add it's code in with the other code? Just keep them separate. If anything you should split that other code into two separate files.
ok if u recommend i keep them separate then i will keep them separate.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » help with player frames

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