WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Moving a frame depending on spec (https://www.wowinterface.com/forums/showthread.php?t=56581)

10leej 08-20-18 02:35 PM

Moving a frame depending on spec
 
So trying to set the position of my raid frames depending on whether the character is a healing spec or not since I like the raid frames under my character when I heal, but not any other time.
I figured using an event would work and while it does I can only seem to watch "PLAYER_ENTERING_WORLD" and while I see the other events fire they don't set the frame position unless I reload the UI.

I can't seem to find a working example either, but that might be me being lazy.

Lua Code:
  1. frame:SetScript("OnEvent", function(self, event, unit)
  2. if event == "PLAYER_SPECIALIZATION_CHANGED" or event == "PLAYER_ENTERING_WORLD" or event == "PLAYER_SPECIALIZATION_CHANGED" then
  3.   if (playerClass == "PRIEST" and GetSpecialization() == 1) then
  4.     frame:SetPoint(unpack(cfg.group.healposition))
  5.   elseif (playerClass == "PRIEST" and GetSpecialization() == 2) then
  6.     frame:SetPoint(unpack(cfg.group.healposition))
  7.   elseif (playerClass == "PALADIN" and GetSpecialization() == 1) then
  8.     frame:SetPoint(unpack(cfg.group.healposition))
  9.   elseif (playerClass == "DRUID" and GetSpecialization() == 4) then
  10.     frame:SetPoint(unpack(cfg.group.healposition))
  11.   elseif (playerClass == "MONK" and GetSpecialization() == 2) then
  12.     frame:SetPoint(unpack(cfg.group.healposition))
  13.   elseif (playerClass == "SHAMAN" and GetSpecialization() == 3) then
  14.     frame:SetPoint(unpack(cfg.group.healposition))
  15.   else
  16.     frame:SetPoint(unpack(cfg.group.position))
  17.   end
  18. end
  19. end)
  20. frame:RegisterEvent("PLAYER_TALENT_UPDATE")
  21. frame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
  22. frame:RegisterEvent("PLAYER_ENTERING_WORLD")

Complete Source Code

It is an oUF layout I'm working on, but I figured this was more of a general problem and not an oUF problem

Fizzlemizz 08-20-18 03:59 PM

I dont' see a frame:ClearAllPoints()

Vrul 08-20-18 04:32 PM

You can make that handle future classes better:
Code:

local party = CreateFrame('Frame')
party:SetScript('OnEvent', function(self, event)
    self:UnregisterEvent(event)

    local function UpdatePosition(self)
        local _, _, _, _, role = GetSpecializationInfo(GetSpecialization())
        self:ClearAllPoints()
        self:SetPoint(unpack(cfg.group[role ~= 'HEALER' and "position" or "healposition"]))
    end
    UpdatePosition(self)

    self:SetScript('OnEvent', UpdatePosition)
    self:RegisterUnitEvent('PLAYER_SPECIALIZATION_CHANGED', 'player')
end)
party:RegisterEvent('PLAYER_ENTERING_WORLD')


10leej 08-21-18 05:21 PM

Quote:

Originally Posted by Fizzlemizz (Post 329731)
I dont' see a frame:ClearAllPoints()

/doh

Quote:

Originally Posted by Vrul (Post 329732)
You can make that handle future classes better:
Code:

local party = CreateFrame('Frame')
party:SetScript('OnEvent', function(self, event)
    self:UnregisterEvent(event)

    local function UpdatePosition(self)
        local _, _, _, _, role = GetSpecializationInfo(GetSpecialization())
        self:ClearAllPoints()
        self:SetPoint(unpack(cfg.group[role ~= 'HEALER' and "position" or "healposition"]))
    end
    UpdatePosition(self)

    self:SetScript('OnEvent', UpdatePosition)
    self:RegisterUnitEvent('PLAYER_SPECIALIZATION_CHANGED', 'player')
end)
party:RegisterEvent('PLAYER_ENTERING_WORLD')


That definately looks better


All times are GMT -6. The time now is 05:59 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI