Add Show Aggro Bar option.

This commit is contained in:
Xinhuan
2008-10-31 05:35:23 +08:00
parent be80f5d513
commit 5390a4623d
7 changed files with 109 additions and 23 deletions
+79 -23
View File
@@ -129,6 +129,8 @@ local defaults = {
UseTankBarColor = true,
TankBarColor = {r = 1, g = 0, b = 0, a = 1,},
AlwaysShowSelf = true,
ShowAggroBar = true,
AggroBarColor = {r = 1, g = 0, b = 0, a = 1,},
},
ShowWith = {
Pet = true,
@@ -1100,6 +1102,8 @@ function Omen:UpdatePartyGUIDs()
end
end
end
guidNameLookup["AGGRO"] = L["> Pull Aggro <"]
guidClassLookup["AGGRO"] = "AGGRO"
end
@@ -1144,6 +1148,7 @@ Returns the colors used in the UI to represent each major threat state.
local threatTable -- Format: threatTable[guid] = threatValue
local sortTable = {} -- Format: threatTable[i] = guid -- used for sorting by sortfunction()
local tankGUID -- Used to store which unit is tanking and hence has 100% threat by definition
local topthreat -- Used to store the top threat value
local lastWarn = { -- Used to store information for threat warnings
threatpercent = 0,
}
@@ -1159,6 +1164,7 @@ local function updatethreat(unitid, mobunitid)
if guid and not threatTable[guid] then
local isTanking, state, scaledPercent, rawPercent, threatValue = UnitDetailedThreatSituation(unitid, mobunitid)
threatTable[guid] = threatValue or -1
if threatValue and threatValue > topthreat then topthreat = threatValue end
if isTanking then tankGUID = guid end
end
end
@@ -1187,12 +1193,15 @@ function Omen:FindThreatMob()
self.unitID = nil
end
local queried = false
function Omen:UpdateBars()
if not self.Anchor:IsShown() and not db.CollapseHide then return end
-- TODO: Put a update throtle on this function
local mobGUID, mobTargetGUID
local dbBar = db.Bar
local mob, mobGUID, mobTargetGUID
topthreat = -1
if testMode then
threatTable = newTable()
@@ -1200,9 +1209,11 @@ function Omen:UpdateBars()
threatTable[i] = i*5000
end
tankGUID = 25
topthreat = 25*5000
mob = ""
self.TitleText:SetText(L["Test Mode"])
else
local mob = self:FindThreatMob()
mob = self:FindThreatMob()
if not mob then
self:ClearAll()
return
@@ -1260,6 +1271,18 @@ function Omen:UpdateBars()
updatethreat("mouseover", mob)
updatethreat("mouseovertarget", mob)
end
local tankThreat = tankGUID and threatTable[tankGUID] or mobTargetGUID and threatTable[mobTargetGUID] or topthreat
if dbBar.ShowAggroBar and tankThreat > 0 then
if GetItemInfo(37727) then -- 5 yards (Ruby Acorn - http://www.wowhead.com/?item=37727)
threatTable["AGGRO"] = tankThreat * (IsItemInRange(37727, mob) == 1 and 1.1 or 1.3)
else -- 9 yards compromise
threatTable["AGGRO"] = tankThreat * (CheckInteractDistance(mob, 3) and 1.1 or 1.3)
if not queried and not ItemRefTooltip:IsVisible() then
ItemRefTooltip:SetHyperlink("item:37727")
queried = true -- Only query once per session
end
end
end
-- Sort the threatTable
local i = 1
@@ -1283,12 +1306,10 @@ function Omen:UpdateBars()
local inset = db.Background.BarInset * 2
local w = self.BarList:GetWidth() - inset
local h = self.BarList:GetHeight() - inset
local topthreat = threatTable[sortTable[1]]
if topthreat == 0 then topthreat = 1 end
local tankThreat = threatTable[tankGUID or mobTargetGUID or sortTable[1]]
local dbBar = db.Bar
topthreat = threatTable[sortTable[1]]
if topthreat == 0 then topthreat = 1 end -- To avoid 0/0 division
local showSelfYet = true
myGUID = UnitGUID("player")
local myGUID = UnitGUID("player")
if dbBar.AlwaysShowSelf then
-- Check if we're one of the bars to be displayed
@@ -1317,7 +1338,7 @@ function Omen:UpdateBars()
if i > numBars then break end
local guid = sortTable[j]
local class = guidClassLookup[guid]
local show = class == nil and dbBar.Classes["*NOTINPARTY*"] or dbBar.Classes[class]
local show = class == nil and dbBar.Classes["*NOTINPARTY*"] or class == "AGGRO" and dbBar.ShowAggroBar or dbBar.Classes[class]
if dbBar.AlwaysShowSelf and i == numBars and not showSelfYet and guid ~= myGUID then
show = false
end
@@ -1350,6 +1371,7 @@ function Omen:UpdateBars()
-- Update the color of the bar
local c = (guid == myGUID and dbBar.UseMyBarColor and dbBar.MyBarColor) or
(guid == tankGUID and dbBar.UseTankBarColor and dbBar.TankBarColor) or
(guid == "AGGRO" and dbBar.AggroBarColor) or
(dbBar.UseClassColors and (RAID_CLASS_COLORS[class] or (class == "PET" and pet_color))) or
dbBar.BarColor
bar.texture:SetVertexColor(c.r, c.g, c.b, c.a or 1)
@@ -1434,8 +1456,15 @@ end
function Omen:UpdateTPS()
local numBars = #bars
if testMode then
for i = 1, numBars do
bars[i].Text3:SetText(1300 - 50*i)
if db.Bar.ShowAggroBar then
bars[1].Text3:SetText("--")
for i = 2, numBars do
bars[i].Text3:SetText(1300 - 50*(i-1))
end
else
for i = 1, numBars do
bars[i].Text3:SetText(1300 - 50*i)
end
end
return
end
@@ -1468,17 +1497,21 @@ function Omen:UpdateTPS()
local bar = bars[i]
if not bar:IsShown() then return end
local guid = bar.guid
local baseThreat = threatStore[1][guid]
local secondThreat = threatStore[2][guid]
local finalThreat = threatStore[dataSize][guid]
if baseThreat and secondThreat and finalThreat then
-- Calculate TPS
local ratio = (startTime - threatStoreTime[1]) / (threatStoreTime[2] - threatStoreTime[1])
local startThreat = (secondThreat - baseThreat) * ratio + baseThreat
bar.Text3:SetFormattedText("%d", (finalThreat - startThreat) / TPSWindow / 100)
if guid == "AGGRO" then
bar.Text3:SetText("--")
else
-- We don't have enough data for this unit
bar.Text3:SetText("??")
local baseThreat = threatStore[1][guid]
local secondThreat = threatStore[2][guid]
local finalThreat = threatStore[dataSize][guid]
if baseThreat and secondThreat and finalThreat then
-- Calculate TPS
local ratio = (startTime - threatStoreTime[1]) / (threatStoreTime[2] - threatStoreTime[1])
local startThreat = (secondThreat - baseThreat) * ratio + baseThreat
bar.Text3:SetFormattedText("%d", (finalThreat - startThreat) / TPSWindow / 100)
else
-- We don't have enough data for this unit
bar.Text3:SetText("??")
end
end
end
end
@@ -2174,15 +2207,38 @@ local options = {
end,
disabled = function() return not db.Bar.UseTankBarColor end,
},
UseClassColors = {
ShowAggroBar = {
type = "toggle",
order = 17,
name = L["Show Pull Aggro Bar"],
desc = L["Show a bar for the amount of threat you will need to reach in order to pull aggro."],
},
AggroBarColor = {
type = "color",
order = 18,
name = L["Pull Aggro Bar Color"],
desc = L["The background color for your Pull Aggro bar"],
hasAlpha = true,
get = function(info)
local t = db.Bar.AggroBarColor
return t.r, t.g, t.b, t.a
end,
set = function(info, r, g, b, a)
local t = db.Bar.AggroBarColor
t.r, t.g, t.b, t.a = r, g, b, a
Omen:UpdateBars()
end,
disabled = function() return not db.Bar.ShowAggroBar end,
},
UseClassColors = {
type = "toggle",
order = 20,
name = L["Use Class Colors"],
desc = L["Use standard class colors for the background color of threat bars"],
},
BarColor = {
type = "color",
order = 18,
order = 21,
name = L["Bar BG Color"],
desc = L["The background color for all threat bars"],
hasAlpha = true,
@@ -2199,7 +2255,7 @@ local options = {
},
AlwaysShowSelf = {
type = "toggle",
order = 19,
order = 24,
name = L["Always Show Self"],
desc = L["Always show your threat bar on Omen (ignores class filter settings), showing your bar on the last row if necessary"],
},