WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Hiding elements based on player state (https://www.wowinterface.com/forums/showthread.php?t=21999)

Sangull 04-11-09 10:06 PM

Hiding elements based on player state
 
I'm currently working on some additions/changes to the oUF_Neav layout and I've run into a snag. I'm trying to hide the Level text when I am resting or in combat, and display those icons instead. I'm able to get the icons to display correctly, however I'm having issues with hiding the Level text. This is the code I'm currently running:

Code:

              -- level
        if (unit == "player" or unit == "target" or unit == "focus") then
                self.Level = CreateFont(self.Health, "Interface\\AddOns\\oUF_Neav\\media\\fontNumber.ttf", 17, "OUTLINE", 0, 0)
                self.Level:SetPoint("CENTER", self.f, (unit == "player" and -63) or 63.5, -15)
                self.Level:SetText("[level]")
                self:Tag(self.Level, "[level]")
        end

                --combaticon
        if (unit == "player") then
                self.Combat = self.Health:CreateTexture(nil, 'OVERLAY', self)
                self.Combat:SetHeight(20)
                self.Combat:SetWidth(20)
                self.Combat:SetPoint('CENTER', self.f, -63, -15)
                self.Combat:SetTexture('Interface\\CharacterFrame\\UI-StateIcon')
                self.Combat:SetTexCoord(0.58, 0.90, 0.08, 0.41)
        end
       
                --resticon
        if (unit == "player") then
                self.Resting = self.Health:CreateTexture(nil, 'OVERLAY', self)
                self.Resting:SetHeight(28)
                self.Resting:SetWidth(28)
                self.Resting:SetPoint('CENTER', self.f, -63, -15)
                self.Resting:SetTexture('Interface\\CharacterFrame\\UI-StateIcon')
                self.Resting:SetTexCoord(0,0.5,0,0.421875)
        end

I then have this set to the player frame specifically:

Code:

if self.Resting then
    self.Level:Hide()
elseif self.Combat then
    self.Level:Hide()
else
    self.Level:Show()
end

I've also tried
Code:

if (not self.Resting or self.Combat) then
      self.Level:Show()
else
      self.Level:Hide()
end

The first hides the level text all the time, while the second doesn't hide it at all. I'm not sure where to go from here. Any help would be appreciated.

Edit: Actually, after beating on a target dummy my request has become slightly more complicated. I'd like to prioritize Resting icon > Combat icon > Level text. I still haven't found a way to do this though.

zork 04-12-09 05:10 AM

I think thats rather easy. Create yourself a assistant frame and anchor 4 Events on that frame. (Resting started, Resting ended, Combat started, Combat ended and Player Entering World)

http://www.wowwiki.com/Events/P

PLAYER_UPDATE_RESTING
PLAYER_REGEN_ENABLED
PLAYER_REGEN_DISABLED
PLAYER_ENTERING_WORLD

This is how you could implement. Create the assistant frame, register Events to that frame and call a function upcon event. Use conditions to do specific thing upon specific events.
Code:

 
  -- Hello world function
  local function am(text,event)
    DEFAULT_CHAT_FRAME:AddMessage(text)
  end
 
  -- Create a local variable of the type Frame
  local a = CreateFrame("Frame")
 
  -- Register a Event on that Frame
  a:RegisterEvent("PLAYER_UPDATE_RESTING")
  a:RegisterEvent("PLAYER_REGEN_ENABLED")
  a:RegisterEvent("PLAYER_REGEN_DISABLED")
  a:RegisterEvent("PLAYER_ENTERING_WORLD")
 
  -- Set a script that will be run on a given Event
  a:SetScript("OnEvent", function(self,event)
   
    -- Call the Hello World function
    if event == "PLAYER_UPDATE_RESTING" then
      am("Hello World!",event)
    elseif event == "PLAYER_REGEN_ENABLED" then
      am("OUCH!")
    else
      am("DOH!")
    end
  end)


Sangull 04-12-09 01:59 PM

So I added your code into my layout like this:

Code:

                -- Hello world function
                local function am(text,event)
                        DEFAULT_CHAT_FRAME:AddMessage(text)
                end

               
                local a = CreateFrame("Frame")
 
                -- Register a Event on that Frame
                a:RegisterEvent("PLAYER_UPDATE_RESTING")
                a:RegisterEvent("PLAYER_REGEN_ENABLED")
                a:RegisterEvent("PLAYER_REGEN_DISABLED")
                a:RegisterEvent("PLAYER_ENTERING_WORLD")
 
                -- Set a script that will be run on a given Event
                a:SetScript("OnEvent", function(self,event)
   
                        -- Call the Hello World function
                if event == "PLAYER_UPDATE_RESTING" then
                        am("Hello World!",event)
                        oUF.units.player.Level:Hide()
                        oUF.units.player.Combat:Hide()
                elseif event == "PLAYER_REGEN_DISABLED" then
                        am("OUCH!")
                        oUF.units.player.Level:Hide()
                else
                        am("DOH!")
                        oUF.units.player.Level:Show()
                end
        end)

It works perfectly for showing/hiding in combat. However any time my resting state changes it hides everything until I enter and leave combat to reset it. I'm sure this is because PLAYER_UPDATE_RESTING is simply saying whether the resting state changed, rather than firing a true/false.

I found http://www.wowwiki.com/API_IsResting which looks closer to what I am looking for but I'm not sure how to use it since it isn't an event. Any other ideas? :D

Edit: Updated description of what the code actually does.

Edit2: An idea I had, though I'm too much of a coding noob to be sure if it would work. Could I make my own event to fire resting = true or resting = false using the IsResting() API?


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

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI