forked from zorkqz/ReturnBuffTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWidget.lua
More file actions
147 lines (126 loc) · 5.63 KB
/
Widget.lua
File metadata and controls
147 lines (126 loc) · 5.63 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
local ReturnBuffTracker = LibStub("AceAddon-3.0"):GetAddon("ReturnBuffTracker")
function ReturnBuffTracker:CreateMainFrame()
local theFrame = CreateFrame("Frame", "ReturnBuffTrackerUI", UIParent)
theFrame:ClearAllPoints()
if ReturnBuffTracker.db.profile.position then
theFrame:SetPoint("BOTTOMLEFT", ReturnBuffTracker.db.profile.position.x, ReturnBuffTracker.db.profile.position.y)
else
theFrame:SetPoint("CENTER", UIParent)
end
theFrame:SetHeight(140)
theFrame:SetWidth(ReturnBuffTracker.db.profile.width)
theFrame:SetMinResize(100, 0)
theFrame:SetMaxResize(1000, 1000)
theFrame:SetFrameStrata("BACKGROUND")
theFrame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
tile = true,
tileSize = 16,
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 16,
insets = {left = 4, right = 4, top = 4, bottom = 4},
})
theFrame:SetBackdropBorderColor(1.0, 1.0, 1.0)
theFrame:SetBackdropColor(24 / 255, 24 / 255, 24 / 255)
theFrame:EnableMouse(true)
theFrame:SetMovable(true)
theFrame:SetResizable(true)
local resizeButton = CreateFrame("Button", nil, theFrame)
resizeButton:SetSize(16, 16)
resizeButton:SetPoint("BOTTOMRIGHT")
resizeButton:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
resizeButton:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
resizeButton:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
resizeButton:SetScript("OnMouseDown", function(self, button)
theFrame:StartSizing("RIGHT")
theFrame:SetUserPlaced(true)
end)
resizeButton:SetScript("OnMouseUp", function(self, button)
theFrame:StopMovingOrSizing()
ReturnBuffTracker.db.profile.width = theFrame:GetWidth()
end)
theFrame:SetScript("OnMouseDown", function(self) self:StartMoving() end)
theFrame:SetScript("OnMouseUp", function(self)
self:StopMovingOrSizing()
if not ReturnBuffTracker.db.profile.position then
ReturnBuffTracker.db.profile.position = {}
end
ReturnBuffTracker.db.profile.position.x = theFrame:GetLeft()
ReturnBuffTracker.db.profile.position.y = theFrame:GetBottom()
end)
theFrame:Show()
ReturnBuffTracker.mainFrame = theFrame
end
function ReturnBuffTracker:SetHeightForBars(numOfBars)
numOfBars = numOfBars - 1
if numOfBars <= 0 then numOfBars = 0 end
local height = 5 + 16 + numOfBars * 16 + 5
ReturnBuffTracker.mainFrame:SetHeight(height)
end
function ReturnBuffTracker:CreateHeaderBar(text, r, g, b)
local theBar = CreateFrame("Frame", text, ReturnBuffTracker.mainFrame)
theBar.textString = theBar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
theBar.textString:SetPoint("CENTER", ReturnBuffTracker.mainFrame, "TOP", 0, -7)
theBar.textString:SetText(text)
end
function ReturnBuffTracker:CreateInfoBar(text, r, g, b)
local theBar = CreateFrame("Frame", text, ReturnBuffTracker.mainFrame)
theBar.text = text
theBar:SetHeight(16)
theBar:SetWidth(120)
theBar:SetPoint("TOPLEFT", ReturnBuffTracker.mainFrame, "TOPLEFT", 5, -5)
theBar.texture = theBar:CreateTexture(nil, "BACKGROUND")
theBar.texture:SetPoint("TOPLEFT", ReturnBuffTracker.mainFrame, "TOPLEFT", 5, -5)
theBar.texture:SetColorTexture(r, g, b, 0.9)
theBar.texture:SetHeight(16)
theBar.texture:Hide()
theBar.textString = theBar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
theBar.textString:SetPoint("CENTER", ReturnBuffTracker.mainFrame, "TOP", 0, -7)
theBar.textString:SetText(text)
theBar.SetIndex = function(self, index)
if index then
theBar:Show()
theBar:SetPoint("TOPLEFT", ReturnBuffTracker.mainFrame, "TOPLEFT", 5, -5 - (index * 16))
theBar.texture:SetPoint("TOPLEFT", ReturnBuffTracker.mainFrame, "TOPLEFT", 5, -5 - (index * 16))
theBar.textString:SetPoint("TOP", ReturnBuffTracker.mainFrame, "TOP", 0, -7 - (index * 16))
else
theBar:Hide()
end
end
theBar.Update = function(self, value, maxValue, tooltip)
local percentage = value / maxValue
local totalWidth = ReturnBuffTracker.mainFrame:GetWidth() - 10
local width = floor(totalWidth * percentage)
if width > 0 then
theBar.texture:SetWidth(totalWidth * percentage)
theBar.texture:Show()
else
theBar.texture:Hide()
end
theBar:SetWidth(totalWidth)
theBar.tooltip = tooltip
end
theBar:SetScript("OnEnter", function(self)
GameTooltip:AddLine("Missing " .. self.text .. ": ", 1, 1, 1)
if self.tooltip then
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
for k, v in ipairs(self.tooltip) do
GameTooltip:AddLine(v, 1, 1, 1)
end
GameTooltip:Show()
end
end)
theBar:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
theBar:SetScript("OnMouseDown", function(self) ReturnBuffTracker.mainFrame:StartMoving() end)
theBar:SetScript("OnMouseUp", function(self)
ReturnBuffTracker.mainFrame:StopMovingOrSizing()
if not ReturnBuffTracker.db.profile.position then
ReturnBuffTracker.db.profile.position = {}
end
ReturnBuffTracker.db.profile.position.x = ReturnBuffTracker.mainFrame:GetLeft()
ReturnBuffTracker.db.profile.position.y = ReturnBuffTracker.mainFrame:GetBottom()
end)
return theBar
end