diff --git a/oUF_Experience/oUF_Experience.lua b/oUF_Experience/oUF_Experience.lua index d3ffe67..a23afc2 100644 --- a/oUF_Experience/oUF_Experience.lua +++ b/oUF_Experience/oUF_Experience.lua @@ -1,7 +1,7 @@ -local function CreatePlayerTooltip(self) - local min, max = UnitXP('player'), UnitXPMax('player') +local _, class = UnitClass('player') - GameTooltip:SetOwner(self, "ANCHOR_CURSOR") +local function PlayerXPTip(self, min, max) + GameTooltip:SetOwner(self, 'ANCHOR_CURSOR') if(GetXPExhaustion()) then GameTooltip:AddLine(format('|cffffffffRested XP remaining:|r %s', GetXPExhaustion())) GameTooltip:AddLine(' ') @@ -14,55 +14,109 @@ local function CreatePlayerTooltip(self) GameTooltip:Show() end -local function UpdateElement(self, event, unit, bar) - if(unit == 'player') then - local min, max = UnitXP('player'), UnitXPMax('player') - bar:SetMinMaxValues(0, max) - bar:SetValue(min) +local function PlayerRepTip(self, name, standing, min, max, value) + GameTooltip:SetOwner(self, 'ANCHOR_CURSOR') + GameTooltip:AddLine(format('|cffffffffWatched Faction:|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', _G['FACTION_STANDING_LABEL' .. standing])) + GameTooltip:Show() +end + +local function PetTip(self, min, max) + GameTooltip:SetOwner(self, 'ANCHOR_CURSOR') + 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 - 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) +function oUF:PLAYER_XP_UPDATE(event, unit) + if(self.unit == 'player') then + local bar = self.Experience + if(GetWatchedFactionInfo()) then + local name, standing, min, max, value = GetWatchedFactionInfo() + bar:SetMinMaxValues(min, max) + bar:SetValue(value) + + if(bar.Text) then + bar.Text:SetFormattedText('%d / %d - %s', value, max, name) + end + + if(bar.Tooltip) then + bar:EnableMouse() + bar:SetScript('OnEnter', function() PlayerRepTip(bar, name, standing, min, max, value) end) + bar:SetScript('OnLeave', function() GameTooltip:Hide() end) + end + else + local min, max = UnitXP('player'), UnitXPMax('player') + bar:SetMinMaxValues(0, max) + bar:SetValue(min) + bar:Show() + + if(bar.Text) then + bar.Text:SetFormattedText('%d / %d', min, max) + end + + if(bar.Tooltip) then + bar:EnableMouse() + bar:SetScript('OnEnter', function() PlayerXPTip(bar, min, max) end) + bar:SetScript('OnLeave', function() GameTooltip:Hide() end) + end end + end +end + +function oUF:UNIT_PET_EXPERIENCE(event, unit) + if(self.unit == 'pet') then + local bar = self.Experience + local min, max = GetPetExperience() + bar:SetMinMaxValues(0, max) + bar:SetValue(min) + bar:Show() - if(bar.text) then - bar.text:SetFormattedText('%s / %s', min, max) + if(bar.Text) then + bar.Text:SetFormattedText('%d / %d', min, max) end - if(bar.tooltip) then + if(bar.Tooltip) then bar:EnableMouse() - bar:SetScript('OnEnter', CreatePlayerTooltip) + bar:SetScript('OnEnter', function() PetTip(bar, min, max) end) bar:SetScript('OnLeave', function() GameTooltip:Hide() end) end - - if(self.PostUpdateExperience) then self:PostUpdateExperience(event, unit, bar, min, max) end end end -function oUF:PLAYER_XP_UPDATE(event, unit) - if(self.Experience) then - UpdateElement(self, event, unit, self.Experience) - end -end - -oUF:RegisterSubTypeMapping('PLAYER_XP_UPDATE') oUF:RegisterInitCallback(function(self) - if(self.Experience) then - if(UnitLevel('player') == MAX_PLAYER_LEVEL) then - self.Experience:Hide() - if(self.Experience.rested) then - self.Experience.rested:Hide() - end + local experience = self.Experience + if(experience) then + if(UnitLevel('pet') ~= MAX_PLAYER_LEVEL and class == 'HUNTER') then + self:RegisterEvent('UNIT_PET_EXPERIENCE') else + experience:Hide() + end + + if(UnitLevel('player') ~= MAX_PLAYER_LEVEL) then self:RegisterEvent('PLAYER_XP_UPDATE') - self:RegisterEvent('PLAYER_LEVEL_UP') - self:RegisterEvent('UPDATE_EXHAUSTION') + -- hook more events + self:RegisterEvent('UPDATE_FACTION') + self:RegisterEvent('UPDATE_EXHAUSTION') + self:RegisterEvent('PLAYER_LEVEL_UP') + self.UPDATE_FACTION = self.PLAYER_XP_UPDATE + self.UPDATE_EXAUSTION = self.PLAYER_XP_UPDATE self.PLAYER_LEVEL_UP = self.PLAYER_XP_UPDATE - self.UPDATE_EXHAUSTION = self.PLAYER_XP_UPDATE + else + experience:Hide() + end + + if(not experience:GetStatusBarTexture()) then + experience:SetStatusBarTexture([=[Interface\TargetingFrame\UI-StatusBar]=]) end end -end) \ No newline at end of file +end) + +oUF:RegisterSubTypeMapping('PLAYER_XP_UPDATE') +oUF:RegisterSubTypeMapping('UNIT_PET_EXPERIENCE') \ No newline at end of file diff --git a/oUF_Experience/oUF_Experience.toc b/oUF_Experience/oUF_Experience.toc index cdea127..b769b94 100644 --- a/oUF_Experience/oUF_Experience.toc +++ b/oUF_Experience/oUF_Experience.toc @@ -1,8 +1,8 @@ ## Interface: 20400 ## Author: p3lim -## Version: Revision wowi:revision +## Version: 20400.wowi:revision ## Title: oUF Experience -## Notes: Experience Bar support for oUF layouts. +## Notes: Experience/Reputation Bar support for oUF layouts. ## RequiredDeps: oUF oUF_Experience.lua