WoWInterface SVN oUF_Experience

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 20 to Rev 21
    Reverse comparison

Rev 20 → Rev 21

trunk/oUF_Experience/oUF_Experience.lua
2,153 → 2,77
 
Elements handled:
.Experience [statusbar]
.Experience.Text [fontstring]
.Experience.Text [fontstring] (optional)
 
Shared:
- colorReputation [table] - will use blizzard colors if not set
- colorExperience [table] - will use a green color if not set
- Color [table] - will use oUF.colors.health if not set
- Tooltip [boolean]
- MouseOver [boolean]
- XPOnly [boolean]
- RepOnly [boolean]
 
--]]
local localized, english = UnitClass('player')
local _format = string.format
 
local function PlayerXPTip(self, min, max)
local rested = GetXPExhaustion()
local function Tooltip(self, unit, min, max)
GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT', 5, -5)
GameTooltip:AddLine(_format('XP: %d/%d (%.1f%%)', min, max, min/max*100))
GameTooltip:AddLine(_format('%d needed (%.1f%% - %.1f bars)', max-min, (max-min)/max*100,(max-min)/max*20))
if(rested) then
GameTooltip:AddLine(_format('|cff0090ffRested: +%d (%.1f%%)', rested, rested/max*100))
GameTooltip:AddLine(string.format('XP: %d/%d (%.1f%%)', min, max, min/max*100))
GameTooltip:AddLine(string.format('%d needed (%.1f%% - %.1f bars)', max-min, (max-min)/max*100,(max-min)/max*20))
 
if(unit == 'player' and GetXPExhaustion()) then
GameTooltip:AddLine(string.format('|cff0090ffRested: +%d (%.1f%%)', GetXPExhaustion(), GetXPExhaustion()/max*100))
end
GameTooltip:Show()
end
 
local function PlayerRepTip(self, name, id, min, max)
GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT', 5, -5)
GameTooltip:AddLine(_format('%s (%s)', name, _G['FACTION_STANDING_LABEL'..id]))
GameTooltip:AddLine(_format('%d/%d (%.1f%%)', min, max, min/max*100))
GameTooltip:Show()
end
 
local function PetTip(self, min, max)
GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT', 5, -5)
GameTooltip:AddLine(_format('XP: %d/%d (%.1f%%)', min, max, min/max*100))
GameTooltip:AddLine(_format('%d needed (%.1f%% - %.1f bars)', max-min, (max-min)/max*100,(max-min)/max*20))
GameTooltip:Show()
end
local function Update(self, event, unit)
local bar = self.Experience
 
if(event == 'UNIT_PET' and self.unit ~= 'player') then
return
elseif(self.unit == 'player' and UnitLevel('player') == MAX_PLAYER_LEVEL) then
bar:SetAlpha(0)
elseif(self.unit == 'pet' and (UnitLevel('pet') == UnitLevel('player') and english ~= 'HUNTER')) then
bar:SetAlpha(0)
else
local min, max
if(self.unit == 'pet' and not bar.RepOnly) then
min, max = GetPetExperience()
elseif(self.unit == 'player' and not bar.RepOnly) then
min, max = UnitXP(self.unit), UnitXPMax(self.unit)
end
 
function oUF:PLAYER_XP_UPDATE(event, unit)
if(self.unit == 'player') then
local bar = self.Experience
 
if(GetWatchedFactionInfo() and not self.Experience.XPOnly) then
local name, id, min, max, value = GetWatchedFactionInfo()
bar:SetMinMaxValues(min, max)
bar:SetValue(value)
bar:EnableMouse()
bar:SetStatusBarColor(unpack(self.colorReputation or {FACTION_BAR_COLORS[id].r, FACTION_BAR_COLORS[id].g, FACTION_BAR_COLORS[id].b}))
bar:SetMinMaxValues(0, max)
bar:SetValue(min)
bar:EnableMouse()
bar:SetStatusBarColor(unpack(self.Color or self.colors.health))
 
if(not bar.MouseOver) then
bar:SetAlpha(1)
end
if(not bar.MouseOver) then
bar:SetAlpha(1)
end
 
if(bar.Text) then
bar.Text:SetFormattedText('%d / %d - %s', value - min, max - min, name)
end
 
if(bar.Tooltip and bar.MouseOver) then
bar:SetScript('OnEnter', function() bar:SetAlpha(1); PlayerRepTip(bar, name, id, value - min, max - min) end)
bar:SetScript('OnLeave', function() bar:SetAlpha(0); GameTooltip:Hide() end)
elseif(bar.Tooltip and not bar.MouseOver) then
bar:SetScript('OnEnter', function() PlayerRepTip(bar, name, id, value - min, max - min) end)
bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
elseif(bar.MouseOver and not bar.Tooltip) then
bar:SetScript('OnEnter', function() bar:SetAlpha(1) end)
bar:SetScript('OnLeave', function() bar:SetAlpha(0) end)
end
elseif(UnitLevel('player') ~= MAX_PLAYER_LEVEL and not self.Experience.RepOnly) then
local min, max = UnitXP('player'), UnitXPMax('player')
bar:SetMinMaxValues(0, max)
bar:SetValue(min)
bar:EnableMouse()
bar:SetStatusBarColor(unpack(self.colorExperience or self.colors.health))
 
if(not bar.MouseOver) then
bar:SetAlpha(1)
end
 
if(bar.Text) then
bar.Text:SetFormattedText('%d / %d', min, max)
end
 
if(bar.Tooltip and bar.MouseOver) then
bar:SetScript('OnEnter', function() bar:SetAlpha(1); PlayerXPTip(bar, min, max) end)
bar:SetScript('OnLeave', function() bar:SetAlpha(0); GameTooltip:Hide() end)
elseif(bar.Tooltip and not bar.MouseOver) then
bar:SetScript('OnEnter', function() PlayerXPTip(bar, min, max) end)
bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
elseif(bar.MouseOver and not bar.Tooltip) then
bar:SetScript('OnEnter', function() bar:SetAlpha(1) end)
bar:SetScript('OnLeave', function() bar:SetAlpha(0) end)
end
else
bar:SetAlpha(0)
if(bar.Text) then
bar.Text:SetFormattedText('%d / %d', min, max)
end
end
end
 
function oUF:UNIT_PET_EXPERIENCE(event, unit)
if(self.unit == 'pet') then
local bar = self.Experience
if(UnitLevel('pet') ~= UnitLevel('player') and english == 'HUNTER' and not self.Experience.RepOnly) then
local min, max = GetPetExperience()
bar:SetMinMaxValues(0, max)
bar:SetValue(min)
bar:EnableMouse()
bar:SetStatusBarColor(unpack(self.colorExperience or self.colors.health))
 
if(not bar.MouseOver) then
bar:SetAlpha(1)
end
 
if(bar.Text) then
bar.Text:SetFormattedText('%d / %d', min, max)
end
 
if(bar.Tooltip and bar.MouseOver) then
bar:SetScript('OnEnter', function() bar:SetAlpha(1); PetTip(bar, min, max) end)
bar:SetScript('OnLeave', function() bar:SetAlpha(0); GameTooltip:Hide() end)
elseif(bar.Tooltip and not bar.MouseOver) then
bar:SetScript('OnEnter', function() PetTip(bar, min, max) end)
bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
elseif(bar.MouseOver and not bar.Tooltip) then
bar:SetScript('OnEnter', function() bar:SetAlpha(1) end)
bar:SetScript('OnLeave', function() bar:SetAlpha(0) end)
end
else
bar:SetAlpha(0)
if(bar.Tooltip and bar.MouseOver) then
bar:SetScript('OnEnter', function() bar:SetAlpha(1); Tooltip(bar, unit, min, max) end)
bar:SetScript('OnLeave', function() bar:SetAlpha(0); GameTooltip:Hide() end)
elseif(bar.Tooltip and not bar.MouseOver) then
bar:SetScript('OnEnter', function() Tooltip(bar, unit, min, max) end)
bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
elseif(bar.MouseOver and not bar.Tooltip) then
bar:SetScript('OnEnter', function() bar:SetAlpha(1) end)
bar:SetScript('OnLeave', function() bar:SetAlpha(0) end)
end
end
end
 
function oUF:UNIT_PET(event, unit)
if(unit == 'player') then
self.UNIT_PET_EXPERIENCE(self, event, unit)
end
end
 
oUF:RegisterInitCallback(function(self)
local function Enable(self)
local experience = self.Experience
if(experience) then
self:RegisterEvent('PLAYER_XP_UPDATE')
self:RegisterEvent('UNIT_PET_EXPERIENCE')
self:RegisterEvent('UPDATE_FACTION')
self:RegisterEvent('UNIT_PET')
self.UPDATE_FACTION = self.PLAYER_XP_UPDATE
self:RegisterEvent('PLAYER_XP_UPDATE', Update)
self:RegisterEvent('UNIT_PET_EXPERIENCE', Update)
self:RegisterEvent('UNIT_PET', Update)
 
if(not experience:GetStatusBarTexture()) then
experience:SetStatusBarTexture([=[Interface\TargetingFrame\UI-StatusBar]=])
157,9 → 81,18
if(experience.MouseOver) then
experience:SetAlpha(0)
end
 
return true
end
end)
end
 
oUF:RegisterSubTypeMapping('PLAYER_XP_UPDATE')
oUF:RegisterSubTypeMapping('UNIT_PET_EXPERIENCE')
oUF:RegisterSubTypeMapping('UPDATE_FACTION')
\ No newline at end of file +local function Disable(self) + local experience = self.Experience + if(experience) then + self:UnregisterEvent('PLAYER_XP_UPDATE', Update) + self:UnregisterEvent('UNIT_PET_EXPERIENCE', Update) + self:UnregisterEvent('UNIT_PET', Update) + end +end + +oUF:AddElement('Experience', Update, Enable, Disable) \ No newline at end of file
trunk/oUF_Experience/oUF_Experience.toc
2,7 → 2,7
## Author: p3lim
## Version: 30000.wowi:revision
## Title: oUF Experience
## Notes: Experience/Reputation Bar support for oUF layouts.
## Notes: Experience Bar support for oUF layouts.
## RequiredDeps: oUF
 
oUF_Experience.lua