WoWInterface SVN oUF_Pazrael

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 46 to Rev 47
    Reverse comparison

Rev 46 → Rev 47

branches/oUF_Experience/oUF_Experience.lua New file
0,0 → 1,146
local function CreatePlayerTooltip(self)
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
if(self == oUF.units.player.Experience) then
if(GetWatchedFactionInfo()) then
local name, standing, min, max, value = GetWatchedFactionInfo()
local repLevel = _G['FACTION_STANDING_LABEL' .. standing]
GameTooltip:AddLine(format('|cffffffffWatched Reputation: |r %s', name))
GameTooltip:AddLine(format('|cffffffffRemaining Reputation to go:|r %s', floor(max - value)))
GameTooltip:AddLine(format('|cffffffffPercentage to go:|r %s%%', floor((max - value) / (max-min) * 100)))
GameTooltip:AddLine(format('|cffffffffCurrent Standing|r %s', repLevel))
GameTooltip:Show()
else
local min, max = UnitXP('player'), UnitXPMax('player')
if(GetXPExhaustion()) then
GameTooltip:AddLine(format('|cffffffffRested XP remaining:|r %s', GetXPExhaustion()))
GameTooltip:AddLine(' ')
end
GameTooltip:AddLine(format('|cffffffffRemaining XP to go:|r %s', floor(max - min)))
GameTooltip:AddLine(format('|cffffffffPercentage through:|r %s%%', floor(min / max * 100)))
GameTooltip:AddLine(format('|cffffffffPercentage to go:|r %s%%', floor((max - min) / max * 100)))
GameTooltip:AddLine(format('|cffffffffBars through:|r %s', floor(min / max * 20)))
GameTooltip:AddLine(format('|cffffffffBars to go:|r %s', floor((max - min) / max * 20)))
GameTooltip:Show()
end
elseif(self == oUF.units.pet.Experience) then
local petmin, petmax = GetPetExperience();
GameTooltip:AddLine(format('|cffffffffRemaining XP to go:|r %s', floor(petmax - petmin)))
GameTooltip:AddLine(format('|cffffffffPercentage through:|r %s%%', floor(petmin / petmax * 100)))
GameTooltip:AddLine(format('|cffffffffPercentage to go:|r %s%%', floor((petmax - petmin) / petmax * 100)))
GameTooltip:AddLine(format('|cffffffffBars through:|r %s', floor(petmin / petmax * 20)))
GameTooltip:AddLine(format('|cffffffffBars to go:|r %s', floor((petmax - petmin) / petmax * 20)))
GameTooltip:Show()
end
end
 
local function UpdateElement(self, event, unit)
bar = oUF.units.player.Experience
if(unit == 'player') then
if(GetWatchedFactionInfo()) then
local name, standing, min, max, value = GetWatchedFactionInfo()
bar:SetMinMaxValues(min, max)
bar:SetValue(value)
 
if(bar.rested) then
bar.rested:Hide()
end
 
if(bar.text) then
bar.text:SetFormattedText('%s / %s : %d', value, max, name)
end
self.Experience:Show()
else
local min, max = UnitXP('player'), UnitXPMax('player')
bar:SetMinMaxValues(0, max)
bar:SetValue(min)
 
if(bar.rested) then
local rested = GetXPExhaustion() or 0
bar.rested:SetMinMaxValues(0, max)
bar.rested:SetValue(rested + min)
bar.rested:SetFrameLevel(2)
bar:SetFrameLevel(3)
bar.rested:Show()
end
 
if(bar.text) then
bar.text:SetFormattedText('%s / %s', min, max)
end
if(UnitLevel('player') == MAX_PLAYER_LEVEL) then
self.Experience:Hide()
if(self.Experience.rested) then
self.Experience.rested:Hide()
end
end
end
end
 
if(bar.tooltip) then
bar:EnableMouse()
bar:SetScript('OnEnter', CreatePlayerTooltip)
bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
end
if(self.PostUpdateExperience) then self:PostUpdateExperience(event, unit, bar, min, max) end
end
 
local function UpdatePetElement(self, event, unit)
local _, class = UnitClass('player')
bar = oUF.units.pet.Experience
local petmin, petmax = GetPetExperience();
bar:SetMinMaxValues(0, petmax)
bar:SetValue(petmin)
 
if(bar.rested) then
bar.rested:Hide()
end
 
if(bar.text) then
bar.text:SetFormattedText('%s / %s', petmin, petmax)
end
if(UnitLevel('pet') == MAX_PLAYER_LEVEL) then
self.Experience:Hide()
if(self.Experience.rested) then
self.Experience.rested:Hide()
end
end
if(bar.tooltip) then
bar:EnableMouse()
bar:SetScript('OnEnter', CreatePlayerTooltip)
bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
end
if(UnitLevel('pet') == MAX_PLAYER_LEVEL or not(class == 'HUNTER')) then
bar:Hide()
else
bar:Show()
end
end
 
function oUF:PLAYER_XP_UPDATE(event, unit)
if(self.Experience) then
if(unit == 'pet') then
UpdatePetElement(self, event, unit)
end
if(unit == 'player') then
UpdateElement(self, event, unit)
end
end
end
 
oUF:RegisterSubTypeMapping('PLAYER_XP_UPDATE')
oUF:RegisterInitCallback(function(self)
if(self.Experience) then
self:RegisterEvent('PLAYER_XP_UPDATE')
self:RegisterEvent('UPDATE_FACTION')
self.UPDATE_FACTION = self.PLAYER_XP_UPDATE -- we use XP_Update since it updated on load
if not(UnitLevel('pet') == MAX_PLAYER_LEVEL) then
self:RegisterEvent('UNIT_PET_EXPERIENCE')
self.UNIT_PET_EXPERIENCE = self.PLAYER_XP_UPDATE -- we use XP_Update since it updated on load.
end
if not(UnitLevel('player') == MAX_PLAYER_LEVEL) then
self:RegisterEvent('PLAYER_LEVEL_UP')
self:RegisterEvent('UPDATE_EXHAUSTION')
self.PLAYER_LEVEL_UP = self.PLAYER_XP_UPDATE
self.UPDATE_EXHAUSTION = self.PLAYER_XP_UPDATE
end
end
end)
\ No newline at end of file