-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GUI.lua
147 lines (135 loc) · 6.52 KB
/
GUI.lua
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 appName, JDT = ...
local SharedMedia = LibStub("LibSharedMedia-3.0")
local AceConfigRegistry = LibStub("AceConfigRegistry-3.0")
---creates the Anchor Frame
---@return Frame Anchor
---@return FontString TextBelowAnchor
---@return Cooldown|CooldownFrameTemplate CDFrame
---@return FontString CDText
JDT.CreateAnchor = function()
-- main frame
local Anchor = CreateFrame("Frame")
Anchor:SetSize(80, 80)
Anchor:SetScale(UIParent:GetEffectiveScale())
Anchor:SetPoint("CENTER", UIParent, "CENTER", JDT.db.profile.xOffset, JDT.db.profile.yOffset)
Anchor:Hide()
Anchor:SetMovable(true)
Anchor:SetScript("OnMouseDown", function(self, button) Anchor:StartMoving() end)
Anchor:SetScript("OnMouseUp", function(self, button) Anchor:StopMovingOrSizing() JDT.UpdateAnchorPositions()end)
-- background texture
local texture = Anchor:CreateTexture(nil, "BACKGROUND")
texture:SetAllPoints()
texture:SetColorTexture(0, 0, 0, 1)
-- text below the anchor
local text = Anchor:CreateFontString(nil, "OVERLAY", "GameTooltipText")
text:SetPoint("BOTTOM", 0, 2 - 0.1 * (80 * math.abs(UIParent:GetEffectiveScale()))-JDT.db.profile.TextFontSize)
text:SetText("Move me")
text:SetFont(SharedMedia:Fetch("font", JDT.db.profile.FontOptions), JDT.db.profile.TextFontSize, "OUTLINE")
-- foreground texture displaying the icon
local foreground = Anchor:CreateTexture(nil, "ARTWORK")
foreground:SetTexture("Interface\\AddOns\\DungeonAuraTools\\Files\\DungeonAuraTools.tga")
foreground:SetAllPoints()
-- cooldown frame
local cooldown = CreateFrame("Cooldown", "DAT_Cooldown", Anchor, "CooldownFrameTemplate")
cooldown:SetAllPoints(Anchor)
cooldown:SetParent(Anchor)
cooldown:SetDrawBling(false)
-- cooldown text
local cooldownText = Anchor:CreateFontString(nil, "OVERLAY", "GameTooltipText")
cooldownText:SetPoint("CENTER", 0, 0)
cooldownText:SetText("")
cooldownText:SetFont(SharedMedia:Fetch("font", JDT.db.profile.FontOptions), JDT.db.profile.CooldownTextFontSize, "OUTLINE")
return Anchor,text,cooldown,cooldownText
end
---starter function incase we need to do different stuff aswell
JDT.StartDummyCooldown = function()
JDT.DummyCooldown()
end
---function that handles the display of cooldowns
JDT.DummyCooldown = function()
if JDT.Anchor:IsShown() then
JDT.AnchorCooldown:SetCooldown(GetTime(), 10)
JDT.DummyCooldownText()
C_Timer.After(11, function() JDT.DummyCooldown() end)
end
end
---functino handling the display of cooldown text
JDT.DummyCooldownText = function()
if JDT.Anchor:IsShown() and JDT.db.profile.ShowTimer then
local starttime,_= JDT.AnchorCooldown:GetCooldownTimes()
local duration = Round(10-(GetTime()-starttime/1000)) -- this is some weird math we have to do since GetTime() returns seconds and GetCooldownTimes() returns miliseconds
if duration>0 then
JDT.AnchorCooldownText:SetText(duration)
C_Timer.After(1, function() JDT.DummyCooldownText() end)
else
JDT.AnchorCooldownText:SetText("")
end
else
JDT.AnchorCooldownText:SetText("")
end
end
---handles the setting of anchor position if it was moved by hand and updates the config display
JDT.UpdateAnchorPositions = function()
local x,y = JDT.Anchor:GetCenter()
JDT.db.profile.xOffset = x-GetScreenWidth()/2
JDT.db.profile.yOffset = y-GetScreenHeight()/2
AceConfigRegistry:NotifyChange(appName)
end
JDT.AnchorRefreshTypes = {
xOffset = "xOffset",
yOffset = "yOffset",
all = "all",
IconWidth = "IconWidth",
IconHeight = "IconHeight",
Font = "Font",
TextFontSize = "TextFontSize",
CooldownTextFontSize = "CooldownTextFontSize",
HideCD = "HideCD",
}
setmetatable(JDT.AnchorRefreshTypes, {
__index = function(_, key)
error(string.format("attempted to access invalid key: %s", tostring(key)), 2);
end,
})
---refreshes the Anchors display if needed
---@param type string
JDT.RefreshAnchor = function(type)
JDT.DebugPrint("updatingAnchor: "..type)
if not JDT.Anchor then
JDT.Anchor,JDT.AnchorText,JDT.AnchorCooldown,JDT.AnchorCooldownText = JDT.CreateAnchor()
end
if JDT.Anchor:IsShown() then
JDT.DebugPrint("Anchor is shown")
if type == JDT.AnchorRefreshTypes.all or type == JDT.AnchorRefreshTypes.yOffset or type == JDT.AnchorRefreshTypes.xOffset then -- x and y of the anchor
JDT.DebugPrint("xOffset: " .. JDT.db.profile.xOffset .. " yOffset: " .. JDT.db.profile.yOffset)
JDT.Anchor:SetPoint("CENTER", UIParent, "CENTER", JDT.db.profile.xOffset, JDT.db.profile.yOffset)
end
if type == JDT.AnchorRefreshTypes.all or type == JDT.AnchorRefreshTypes.IconWidth or type == JDT.AnchorRefreshTypes.IconHeight then -- height and width of the anchor
if JDT.db.profile.IconHeight and JDT.db.profile.IconWidth then
JDT.DebugPrint("IconWidth: " .. JDT.db.profile.IconWidth .. " IconHeight: " .. JDT.db.profile.IconHeight)
JDT.Anchor:SetSize(JDT.db.profile.IconWidth, JDT.db.profile.IconHeight)
end
end
if type == JDT.AnchorRefreshTypes.all or type == JDT.AnchorRefreshTypes.Font or type == JDT.AnchorRefreshTypes.TextFontSize then -- text font and size
JDT.AnchorText:SetFont(SharedMedia:Fetch("font", JDT.db.profile.FontOptions), JDT.db.profile.TextFontSize, "OUTLINE")
JDT.AnchorText:SetPoint("BOTTOM", 0, 2 - 0.1 * (JDT.db.profile.IconHeight * math.abs(UIParent:GetEffectiveScale()))-JDT.db.profile.TextFontSize)
end
if type == JDT.AnchorRefreshTypes.all or type == JDT.AnchorRefreshTypes.CooldownTextFontSize or type == JDT.AnchorRefreshTypes.Font then -- cooldown text size and font
JDT.AnchorCooldownText:SetFont(SharedMedia:Fetch("font", JDT.db.profile.FontOptions), JDT.db.profile.CooldownTextFontSize, "OUTLINE")
end
if type == JDT.AnchorRefreshTypes.all or type == JDT.AnchorRefreshTypes.HideCD then
if JDT.db.profile.HideCooldownText then
JDT.AnchorCooldown:Hide()
else
JDT.AnchorCooldown:Show()
end
end
--[[
if type == JDT.AnchorRefreshTypes.all or type == JDT.AnchorRefreshTypes. then
end
JDT.RefreshAnchor(JDT.AnchorRefreshTypes.yOffset,val)
]]
JDT.Anchor:SetScale(UIParent:GetEffectiveScale()) -- setting the UIScale since this might change between load of the addon and runtime
return
end
end