Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 3.3.3-6
Fetching contributors…

Cannot retrieve contributors at this time

file 588 lines (479 sloc) 12.561 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
local fiend = _G.Fiend

local ADDON_NAME, Fiend = ...
Fiend.L = Fiend.L or { }
local L = setmetatable(Fiend.L, { __index = function(t, s) t[s] = s return s end })

local Display = {
}

local View = {
texture = [[Interface\addons\Fiend\media\HalV.tga]],
max = 0,
isActive = false,
total = 0,
bg = { 0.3, 0.3, 0.3 },
}

local floor = math.floor

local tip = GameTooltip
function Display.OnEnter(self)
if self:IsShown() and self.pos > 0 then
tip:SetOwner(self, "ANCHOR_LEFT")
tip:AddDoubleLine(self.pos .. ". " .. self.name, "lal", self.col.r, self.col.g, self.col.b, self.col.r, self.col.g, self.col.b)
tip:AddDoubleLine(self.total, "(" .. math.floor(self.total / self.parent.total * 100) .. "%)", 1, 1, 1, 1, 1, 1)

tip:Show()
self.parent.tip = true
end
end

local pool = setmetatable({}, {
__mode = "k",
__newindex = function(self, index, bar)
bar.name = nil
bar.guid = nil
bar.class = nil
bar.col = nil
bar.total = 0
bar.parent = nil

rawset(self, index, bar)
end
})

function View:Update(guid, ammount, name)
local bar = self.guids[guid]
bar.name = string.match(name, "(.*)\-?")

bar.total = bar.total + ammount
self.total = self.total + ammount

-- bar.per = math.floor(bar.total / self.total * 100)

if bar.total > 1e3 then
bar.right:SetText(math.floor((bar.total * 10) / 100) / 100 .. "k")
else
bar.right:SetText(bar.total)
end

self.dirty = true
end

function View:UpdateDisplay()
if not self.isActive or #self.bars == 0 or not self.display.frame:IsShown() then return end

table.sort(self.bars, function(a, b) return b.total < a.total end)

local total = math.floor((self.display.frame:GetHeight() - 32) / self.size)
local width = self.display.frame:GetWidth()

local size = self.size

local max = self.bars[1].total

local bar
for i = 1, #self.bars do
bar = self.bars[i]
if i > total then
bar.pos = 0
bar:Hide()
else
bar:SetValue(100 * (bar.total / max))

if bar.pos ~= i then
bar:SetPoint("TOP", self.display.frame, "TOP", 0, ((i - 1) * -size) - 32)

bar.left:SetText(i .. ". " .. bar.name)

bar.pos = i
end

bar:Show()
end
end

self.dirty = false
end

function View:RemoveAllBars()
local bar
for i = 1, #self.bars do
bar = table.remove(self.bars, 1)

bar:Hide()

self.guids[bar.guid] = nil

table.insert(pool, bar)
end

self.total = 0
end

function View:Resizing(width, height)
local total = math.floor((height or self.display.frame:GetHeight() - 32) / self.size)

local bar
for i = 1, #self.bars do
bar = self.bars[i]
if i > total then
bar:Hide()
else
bar:Show()
end
end

self.dirty = true
end

function View:Activate()
if self.isActive then return end

if self.display.currentView then
self.display.currentView:Deactivate()
end

self.display.frame.title:SetText(self.title)
self.display.frame:SetBackdropBorderColor(unpack(self.bg))

self.display.currentView = self

if self.display.dropDown:IsShown() then
UIDropDownMenu_Refresh(self.display.dropDown)
end

self.isActive = true
-- Update faster
self:UpdateDisplay()
end

function View:Deactivate(clean)
if not self.isActive then return end

self.isActive = false

if clean then
self:ResetAllBars()
else
local bar
for i = 1, #self.bars do
bar = self.bars[i]
bar:Hide()
bar.pos = 0 -- Force update next dirty cycle
end
end

self.display.currentView = nil
end

function View:Output(count, where, player)
if #self.bars == 0 then return end

local output

if not where then
output = print
else
output = function(str)
SendChatMessage(str, where, nil, where == "WHISPER" and player)
end
end

output("Fiend - " .. self.title .. ":")

-- Need to do a double pass
local bar
for i = 1, count or #self.bars do
if not self.bars[i] then break end
bar = self.bars[i]
output(string.format("%d. %s - %d %d%%", i, bar.name, bar.total, (math.floor(bar.total * 10000 / self.total) / 100)))
end
end

function Display:OnUpdate(elapsed)
if self.currentView and self.currentView.dirty then
self.currentView:UpdateDisplay()
end
end

function Display:CreateFrame(title)
local frame = CreateFrame("Frame", "FiendDamage" .. title, UIParent)
frame:SetHeight(250)
frame:SetWidth(300)
frame:SetPoint("CENTER")
frame:EnableMouse(true)
frame:SetMinResize(50, 50)
frame:SetMovable(true)
frame:SetResizable(true)
frame:SetUserPlaced(true)
frame:SetClampedToScreen(true)
--frame:SetHitRectInsets(

frame:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
self:StopMovingOrSizing()
end
end)

frame:SetScript("OnMouseDown", function(s, button)
if IsModifiedClick("ALT") and button == "LeftButton" then
s:StartMoving()
elseif button == "RightButton" then
if IsModifiedClick("SHIFT") then
self.currentView:RemoveAllBars()
else
ToggleDropDownMenu(1, nil, self.dropDown, "cursor")
end
end
end)

frame:SetScript("OnSizeChanged", function(s, width, height)
if self.currentView then
self.currentView.dirty = true
end
end)

frame:SetBackdrop({
bgFile = [[Interface\Tooltips\UI-Tooltip-Background.tga]], tile = true, tileSize = 16,
edgeFile = [[Interface\addons\Fiend\media\otravi-semi-full-border.tga]], edgeSize = 32,
insets = {left = 0, right = 0, top = 20, bottom = 0},
})

frame:SetBackdropColor(0, 0, 0, 0.8)

local title = frame:CreateFontString(nil, "OVERLAY")
title:SetFont(STANDARD_TEXT_FONT, 16)
title:SetText("Fiend")
title:SetJustifyH("CENTER")
title:SetPoint("CENTER")
title:SetPoint("TOP", 0, - 12)

frame.title = title

local drag = CreateFrame("Frame", nil, frame)
drag:SetHeight(16)
drag:SetWidth(16)
drag:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", - 1, 1)
drag:EnableMouse(true)
drag:SetFrameLevel(20)

drag:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
frame:StopMovingOrSizing()
end
end)

drag:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" and IsModifiedClick("ALT") then
frame:StartSizing()
end
end)

local texture = drag:CreateTexture(nil, "OVERLAY")
texture:SetTexture([[Interface\addons\Fiend\media\draghandle.tga]])
texture:SetBlendMode("ADD")
texture:SetAlpha(0.7)
texture:SetAllPoints(drag)

drag.texture = texture
frame.drag = drag

self.frame = frame
end

function fiend:NewDisplay(title)
title = title or #self.displays + 1
if self.displays[title] then return end

local t = {
views = {},
menu = {},
events = {},
numViews = 0,
title = title,
}

local display = setmetatable(t, { __index = Display } )

display:CreateFrame(title)
display:ToolTip()

self.displays[title] = display

return display
end

function Display:CombatEvent(event, guid, ammount, name, overHeal)
if not self.events[event] then
return
end

for i, d in pairs(self.events[event]) do
if overHeal and d.overHeal then
d:Update(guid, overHeal, name)
elseif ammount > 0 then
d:Update(guid, ammount, name)
end
end
end

function Display:NewView(title, events, size, bg, color)
if self.views[title] then return self.views[title] end

local t = setmetatable({}, { __index = View })

for i, event in pairs(events) do
self.events[event] = self.events[event] or {}
table.insert(self.events[event], t)
end

t.bars = {}
t.size = size
t.title = title
t.bg = bg or self.bg
t.color = color
t.display = self
t.total = 0

t.guids = setmetatable({}, { __index = function(s, guid)
local bar
if next(pool) then
bar = table.remove(pool, 1)
else
bar = CreateFrame("Statusbar", nil, self.frame)
bar:SetStatusBarTexture(t.texture)
bar:SetMinMaxValues(0, 100)
bar:SetPoint("LEFT", 1, 0)
bar:SetPoint("RIGHT", - 1, 0)
bar:EnableMouse(true)
bar:Hide()

bar:SetScript("OnEnter", self.OnEnter)
bar:SetScript("OnLeave", function(self) tip:Hide(); self.tip = false end)

local bg = bar:CreateTexture(nil, "BACKGROUND")
bg:SetTexture(self.texture)
bg:SetAllPoints(bar)

bar.bg = bg

local left = bar:CreateFontString(nil, "OVERLAY")
left:SetFont(STANDARD_TEXT_FONT, size - 2)
left:SetPoint("LEFT", bar, "LEFT", 5, 0)
left:SetPoint("BOTTOM")
left:SetPoint("TOP")
left:SetShadowColor(0, 0, 0, 0.8)
left:SetShadowOffset(0.8, - 0.8)

bar.left = left

local right = bar:CreateFontString(nil, "OVERLAY")
right:SetFont(STANDARD_TEXT_FONT, size - 2)
right:SetPoint("RIGHT", self.frame, "RIGHT", - 5, 0)
right:SetPoint("TOP")
right:SetPoint("BOTTOM")
right:SetJustifyH("RIGHT")
right:SetShadowColor(0, 0, 0, 0.8)
right:SetShadowOffset(0.8, - 0.8)

bar.right = right
end

local col = t.color

if not col then
local unit = fiend:GetUnit(guid)
local class = select(2, GetPlayerInfoByGUID(guid)) or "WARRIOR"
col = RAID_CLASS_COLORS[class]
end

bar:SetHeight(size)
bar:SetStatusBarColor(col.r, col.g, col.b)
bar.bg:SetVertexColor(col.r, col.g, col.b, 0.1)

bar.left:SetText(name)
bar.right:SetText(0)

bar.guid = guid
bar.parent = t
bar.total = 0
bar.pos = 0
bar.col = col

table.insert(t.bars, bar)
rawset(s, guid, bar)

bar:Hide()

return bar
end})

local drop = self.dropDown

local menu = {
text = title,
owner = drop,
func = function(self)
t:Activate()
end,
}

self.menu[1][4].menuList[#self.menu[1][4].menuList + 1] = menu

if self.dropDown:IsShown() then
UIDropDownMenu_Refresh(self.dropDown)
end

if self.numViews == 0 then
t:Activate()
end

self.numViews = self.numViews + 1

self.views[title] = t

return t
end

function Display:ToolTip()
local drop = CreateFrame("Frame", "FiendDropDown_" .. self.title, UIParent, "UIDropDownMenuTemplate")

local title = "Fiend"

if self.currentView then
title = "Fiend - " .. self.currentView.title
end

-- </3
self.menu = {
{
{
text = title,
owner = drop,
isTitle = true,
}, {
text = L["Reset"],
owner = drop,
func = function()
if self.currentView then
self.currentView:RemoveAllBars()
end
end,
}, {
text = L["Reset All"],
owner = drop,
func = function()
for i, d in pairs(self.views) do
d:RemoveAllBars()
end
end,
}, {
text = L["Displays"],
owner = drop,
hasArrow = true,
menuList = {
},
}, {
text = L["Output"],
owner = drop,
hasArrow = true,
menuList = {
{
text = L["Guild"],
owner = drop,
func = function()
if self.currentView then
-- Later make this have a count
self.currentView:Output(self.printNum, "GUILD")
end
end,
}, {
text = L["Party"],
owner = drop,
func = function()
if self.currentView then
self.currentView:Output(self.printNum, "PARTY")
end
end,
}, {
text = L["Say"],
owner = drop,
func = function()
if self.currentView then
self.currentView:Output(self.printNum, "SAY")
end
end
}, {
text = L["Whisper"],
owner = drop,
func = function()
end,
}, {
text = L["Print"],
owner = drop,
func = function()
if self.currentView then
self.currentView:Output(self.printNum)
end
end
}, {
text = L["Count"],
owner = drop,
hasArrow = true,
menuList = {
},
},
},
}, {
text = self.frame:IsShown() and L["Hide"] or L["Show"],
owner = drop,
func = function()
if self.frame:IsShown() then
self.frame:Hide()
self.menu[1][6].text = L["Show"]
else
self.frame:Show()
self.menu[1][6].text = L["Hide"]
end
end,
}
},
}

local count = 0
for i = 5, 26, 5 do
count = count + 1

self.menu[1][5].menuList[6].menuList[count] = {
text = i or L["All"],
value = count,
func = function()
self.printNum = i
print(string.format(L["Set the output limit to %d"], i))
end,
}
end

self.menu[1][5].menuList[6].menuList[count + 1] = {
text = L["All"],
value = count + 1,
func = function()
self.printNum = nil
print(L["Set the output limit to All"])
end,
}

UIDropDownMenu_Initialize(drop, function(horse, level, menuList)
if not (menuList or self.menu[level]) then return end
for k, v in ipairs(menuList or self.menu[level]) do
v.value = k
UIDropDownMenu_AddButton(v, level)
end
end, "MENU", 1)

if fiend.menu then
count = #fiend.menu[1][2].menuList
fiend.menu[1][2].menuList[count + 1] = {
text = self.title,
hasArrow = true,
menuList = self.menu[1]
}
end

self.dropDown = drop

return drop
end
Something went wrong with that request. Please try again.