Add configurable TPS display based on a real time sliding window of the last X seconds.

This commit is contained in:
Xinhuan
2008-10-14 00:23:55 +08:00
parent 30d5b7cdaa
commit 61a6dc0872
2 changed files with 122 additions and 22 deletions
+4
View File
@@ -100,6 +100,10 @@ L["Bar Height"] = true
L["Height of each bar"] = true
L["Bar Spacing"] = true
L["Spacing between each bar"] = true
L["Show TPS"] = true
L["Show threat per second values"] = true
L["TPS Window"] = true
L["TPS_WINDOW_DESC"] = "The threat per second calculation is based on a real time sliding window of the last X seconds."
L["Bar Label Options"] = true
L["Font"] = true
L["The font that the labels will use"] = true
+118 -22
View File
@@ -41,7 +41,6 @@ LSM:Register("sound", "Short Circuit", [[Sound\Spells\SimonGame_Visual_BadPress.
LSM:Register("sound", "Fel Portal", [[Sound\Spells\Sunwell_Fel_PortalStand.wav]])
LSM:Register("sound", "Fel Nova", [[Sound\Spells\SeepingGaseous_Fel_Nova.wav]])
LSM:Register("sound", "You Will Die!", [[Sound\Creature\CThun\CThunYouWillDIe.wav]])
LSM:Register("background", "Blizzard Parchment", [[Interface\AchievementFrame\UI-Achievement-Parchment-Horizontal]])
LSM:Register("background", "Blizzard Parchment 2", [[Interface\AchievementFrame\UI-Achievement-Parchment]])
@@ -71,7 +70,8 @@ local defaults = {
Locked = false,
PositionW = 200,
PositionH = 82,
VGrip1 = 115,
VGrip1 = 85,
VGrip2 = 115,
Background = {
Texture = "Blizzard Parchment",
BorderTexture = "Blizzard Dialog",
@@ -113,6 +113,8 @@ local defaults = {
WARRIOR = true,
["*NOTINPARTY*"] = true,
},
ShowTPS = true,
TPSWindow = 10,
},
ShowWith = {
Pet = true,
@@ -251,8 +253,19 @@ end
local function sizing(self)
local w = Omen.Anchor:GetWidth()
db.VGrip1 = w * Omen.Anchor.VGrip1Ratio
db.VGrip2 = w * Omen.Anchor.VGrip2Ratio
if db.VGrip1 < 10 then db.VGrip1 = 10 end
if db.VGrip1 > w - 10 then db.VGrip1 = w - 10 end
if db.Bar.ShowTPS then
if db.VGrip2 < db.VGrip1 + 10 then db.VGrip2 = db.VGrip1 + 10 end
if db.VGrip1 > w - 20 then
db.VGrip1 = w - 20
db.VGrip2 = w - 10
end
Omen.VGrip2:ClearAllPoints()
Omen.VGrip2:SetPoint("TOPLEFT", Omen.BarList, "TOPLEFT", db.VGrip2, 0)
Omen.VGrip2:SetPoint("BOTTOMLEFT", Omen.BarList, "BOTTOMLEFT", db.VGrip2, 0)
end
Omen.VGrip1:ClearAllPoints()
Omen.VGrip1:SetPoint("TOPLEFT", Omen.BarList, "TOPLEFT", db.VGrip1, 0)
Omen.VGrip1:SetPoint("BOTTOMLEFT", Omen.BarList, "BOTTOMLEFT", db.VGrip1, 0)
@@ -260,10 +273,10 @@ local function sizing(self)
Omen:ReAnchorLabels()
Omen:UpdateBars()
end
local function movegrip(self)
local function movegrip1(self)
local x = GetCursorPosition() / UIParent:GetEffectiveScale()
local x1 = Omen.Anchor:GetLeft() + 10
local x2 = Omen.Anchor:GetRight() - 10
local x2 = db.Bar.ShowTPS and Omen.Anchor:GetLeft() + db.VGrip2 - 10 or Omen.Anchor:GetRight() - 10
if x > x1 and x < x2 then
db.VGrip1 = x - x1 + 10
Omen.VGrip1:ClearAllPoints()
@@ -272,6 +285,18 @@ local function movegrip(self)
end
Omen:ReAnchorLabels()
end
local function movegrip2(self)
local x = GetCursorPosition() / UIParent:GetEffectiveScale()
local x1 = Omen.Anchor:GetLeft() + db.VGrip1 + 10
local x2 = Omen.Anchor:GetRight() - 10
if x > x1 and x < x2 then
db.VGrip2 = x - x1 + db.VGrip1 + 10
Omen.VGrip2:ClearAllPoints()
Omen.VGrip2:SetPoint("TOPLEFT", Omen.BarList, "TOPLEFT", db.VGrip2, 0)
Omen.VGrip2:SetPoint("BOTTOMLEFT", Omen.BarList, "BOTTOMLEFT", db.VGrip2, 0)
end
Omen:ReAnchorLabels()
end
function Omen:CreateFrames()
-- Create anchor
@@ -331,6 +356,7 @@ function Omen:CreateFrames()
if not db.Locked then
Omen.Anchor.IsMovingOrSizing = 2
Omen.Anchor.VGrip1Ratio = db.VGrip1 / Omen.Anchor:GetWidth()
Omen.Anchor.VGrip2Ratio = db.VGrip2 / Omen.Anchor:GetWidth()
Omen.Anchor:SetScript("OnSizeChanged", sizing)
Omen.Anchor:StartSizing()
end
@@ -347,7 +373,7 @@ function Omen:CreateFrames()
end)
self.Grip:SetScript("OnHide", self.Grip:GetScript("OnMouseUp"))
-- Create label resizing vertical grip
-- Create label resizing vertical grip 1
self.VGrip1 = CreateFrame("Button", "OmenVResizeGrip1", self.BarList)
self.VGrip1:SetWidth(1)
self.VGrip1:SetPoint("TOPLEFT", self.BarList, "TOPLEFT", db.VGrip1, 0)
@@ -357,15 +383,27 @@ function Omen:CreateFrames()
self.VGrip1:GetNormalTexture():SetVertexColor(1, 1, 1, 0.5)
self.VGrip1:GetHighlightTexture():SetVertexColor(1, 1, 1, 0.5)
self.VGrip1:SetScript("OnMouseDown", function(self)
if not db.Locked then
self:SetScript("OnUpdate", movegrip)
end
if not db.Locked then self:SetScript("OnUpdate", movegrip1) end
end)
self.VGrip1:SetScript("OnMouseUp", function(self)
self:SetScript("OnUpdate", nil)
end)
self.VGrip1:SetScript("OnHide", self.Grip:GetScript("OnMouseUp"))
self.VGrip1:SetScript("OnMouseUp", function(self) self:SetScript("OnUpdate", nil) end)
self.VGrip1:SetScript("OnHide", self.VGrip1:GetScript("OnMouseUp"))
self.VGrip1:SetFrameLevel(self.BarList:GetFrameLevel() + 2)
-- Create label resizing vertical grip 2
self.VGrip2 = CreateFrame("Button", "OmenVResizeGrip2", self.BarList)
self.VGrip2:SetWidth(1)
self.VGrip2:SetPoint("TOPLEFT", self.BarList, "TOPLEFT", db.VGrip2, 0)
self.VGrip2:SetPoint("BOTTOMLEFT", self.BarList, "BOTTOMLEFT", db.VGrip2, 0)
self.VGrip2:SetNormalTexture("Interface\\Tooltips\\UI-Tooltip-Background")
self.VGrip2:SetHighlightTexture("Interface\\Tooltips\\UI-Tooltip-Background")
self.VGrip2:GetNormalTexture():SetVertexColor(1, 1, 1, 0.5)
self.VGrip2:GetHighlightTexture():SetVertexColor(1, 1, 1, 0.5)
self.VGrip2:SetScript("OnMouseDown", function(self)
if not db.Locked then self:SetScript("OnUpdate", movegrip2) end
end)
self.VGrip2:SetScript("OnMouseUp", self.VGrip1:GetScript("OnMouseUp"))
self.VGrip2:SetScript("OnHide", self.VGrip1:GetScript("OnMouseUp"))
self.VGrip2:SetFrameLevel(self.BarList:GetFrameLevel() + 2)
end
function Omen:OnInitialize()
@@ -617,12 +655,21 @@ function Omen:UpdateGrips()
self.VGrip1:ClearAllPoints()
self.VGrip1:SetPoint("TOPLEFT", self.BarList, "TOPLEFT", db.VGrip1, 0)
self.VGrip1:SetPoint("BOTTOMLEFT", self.BarList, "BOTTOMLEFT", db.VGrip1, 0)
self.VGrip2:ClearAllPoints()
self.VGrip2:SetPoint("TOPLEFT", self.BarList, "TOPLEFT", db.VGrip2, 0)
self.VGrip2:SetPoint("BOTTOMLEFT", self.BarList, "BOTTOMLEFT", db.VGrip2, 0)
if db.Locked then
self.Grip:Hide()
self.VGrip1:Hide()
self.VGrip2:Hide()
else
self.Grip:Show()
self.VGrip1:Show()
if db.Bar.ShowTPS then
self.VGrip2:Show()
else
self.VGrip2:Hide()
end
end
end
@@ -785,19 +832,23 @@ do
bar.Text2:SetJustifyH("RIGHT")
bar.Text2:SetFont(LSM:Fetch("font", db.Bar.Font), db.Bar.FontSize, db.Bar.FontOutline)
bar.Text2:SetTextColor(color.r, color.g, color.b, color.a)
bar.Text2:SetWidth(Omen.BarList:GetWidth() - db.VGrip1 - 5)
if db.Bar.ShowTPS then
bar.Text2:SetWidth(Omen.BarList:GetWidth() - db.VGrip2 - 5)
else
bar.Text2:SetWidth(Omen.BarList:GetWidth() - db.VGrip1 - 5)
end
bar.Text2:SetHeight(db.Bar.FontSize)
bar.Text2:SetNonSpaceWrap(false)
bar.Text3 = bar:CreateFontString(nil, nil, "GameFontNormalSmall")
bar.Text3:SetPoint("RIGHT", bar, "RIGHT", -5, 1)
bar.Text3:SetPoint("LEFT", bar.Text1, "RIGHT", 0, 1)
bar.Text3:SetJustifyH("RIGHT")
bar.Text3:SetFont(LSM:Fetch("font", db.Bar.Font), db.Bar.FontSize, db.Bar.FontOutline)
bar.Text3:SetTextColor(color.r, color.g, color.b, color.a)
bar.Text3:SetWidth(Omen.BarList:GetWidth() - db.VGrip1 - 5)
bar.Text3:SetWidth(db.VGrip2 - db.VGrip1 - 5)
bar.Text3:SetHeight(db.Bar.FontSize)
bar.Text3:SetNonSpaceWrap(false)
bar.Text3:Hide()
if not db.Bar.ShowTPS then bar.Text3:Hide() end
bar.texture = bar:CreateTexture()
bar.texture:SetTexture(LSM:Fetch("statusbar", db.Bar.Texture))
@@ -816,8 +867,9 @@ do
elseif barID == 1 then
-- Parent our TPS update frame to the first bar, so that TPS updates
-- updates happen when at least 1 bar (the first bar) is shown.
Omen.TPSUpdateFrame = CreateFrame("Frame", bar)
Omen.TPSUpdateFrame = CreateFrame("Frame", nil, bar)
Omen.TPSUpdateFrame:SetScript("OnUpdate", function(self, elapsed) Omen:UpdateTPS() end)
if not db.Bar.ShowTPS then Omen.TPSUpdateFrame:Hide() end
end
return bar
@@ -848,19 +900,29 @@ function Omen:UpdateBarLabelSettings()
for i = 1, #bars do
bars[i].Text1:SetFont(font, size, flags)
bars[i].Text2:SetFont(font, size, flags)
bars[i].Text3:SetFont(font, size, flags)
bars[i].Text1:SetTextColor(color.r, color.g, color.b, color.a)
bars[i].Text2:SetTextColor(color.r, color.g, color.b, color.a)
bars[i].Text3:SetTextColor(color.r, color.g, color.b, color.a)
bars[i].Text1:SetHeight(size)
bars[i].Text2:SetHeight(size)
bars[i].Text3:SetHeight(size)
end
end
function Omen:ReAnchorLabels()
local w = db.VGrip1
local w2 = Omen.BarList:GetWidth() - w
local w2 = db.Bar.ShowTPS and Omen.BarList:GetWidth() - db.VGrip2 or Omen.BarList:GetWidth() - w
local w3 = db.VGrip2 - db.VGrip1
for i = 1, #bars do
bars[i].Text1:SetWidth(w - 5)
bars[i].Text2:SetWidth(w2 - 5)
if db.Bar.ShowTPS then
bars[i].Text3:SetWidth(w3 - 5)
bars[i].Text3:Show()
else
bars[i].Text3:Hide()
end
end
end
@@ -1223,8 +1285,15 @@ function Omen:ClearAll()
end
function Omen:UpdateTPS()
if testMode then
for i = 1, #bars do
bars[i].Text3:SetText(1300 - 50*i)
end
return
end
-- Remove data that is too old
local startTime = GetTime() - 10
local TPSWindow = db.Bar.TPSWindow
local startTime = GetTime() - TPSWindow
while threatStoreTime[2] and startTime > threatStoreTime[2] do
delTable(tremove(threatStore, 1))
tremove(threatStoreTime, 1)
@@ -1232,13 +1301,13 @@ function Omen:UpdateTPS()
-- Now check that we still have enough data
local dataSize = #threatStoreTime
if dataSize == 0 or startTime <= threatStoreTime[1] then
-- We do not have enough data, 10 seconds has not passed
-- We do not have enough data, TPSWindow seconds has not passed
for i = 1, #bars do
bars[i].Text3:SetText("??")
end
return
end
-- Check for special case with just 1 data point past 10 seconds
-- Check for special case with just 1 data point past TPSWindow seconds
if dataSize == 1 then
-- Threat generated is 0
for i = 1, #bars do
@@ -1257,7 +1326,7 @@ function Omen:UpdateTPS()
-- Calculate TPS
local ratio = (startTime - threatStoreTime[1]) / (threatStoreTime[2] - threatStoreTime[1])
local startThreat = (secondThreat - baseThreat) * ratio + baseThreat
bars[i].Text3:SetFormattedText("%d", (finalThreat - startThreat) / 1000)
bars[i].Text3:SetFormattedText("%d", (finalThreat - startThreat) / TPSWindow / 100)
else
-- We don't have enough data for this unit
bars[i].Text3:SetText("??")
@@ -1702,6 +1771,33 @@ local options = {
Omen:UpdateBars()
end,
},
ShowTPS = {
type = "toggle",
order = 6,
name = L["Show TPS"],
desc = L["Show threat per second values"],
set = function(info, value)
db.Bar.ShowTPS = value
if db.VGrip1 > db.VGrip2 then
db.VGrip1, db.VGrip2 = db.VGrip2, db.VGrip1
end
movegrip1()
movegrip2()
Omen:UpdateGrips()
local f = Omen.TPSUpdateFrame
if f then
if value then f:Show() else f:Hide() end
end
end,
},
TPSWindow = {
type = "range",
order = 7,
name = L["TPS Window"],
desc = L["TPS_WINDOW_DESC"],
min = 5, max = 15, step = 0.1,
disabled = function() return not db.Bar.ShowTPS end,
},
Texture = {
type = "select", dialogControl = 'LSM30_Statusbar',
order = 10,