-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarCursor.lua
More file actions
344 lines (291 loc) · 9.77 KB
/
Copy pathStarCursor.lua
File metadata and controls
344 lines (291 loc) · 9.77 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
local addonName = "StarCursor"
local baseSize = 32
local trailSize = 20
local optionsCategory
-- Default Settings
local defaultSettings = {
scale = 2.2,
alpha = 1.0,
trail = true,
r = 1,
g = 1,
b = 1,
texture = "Star (Default)",
trailTexture = "Match Cursor",
}
local currentTexturePath = "Interface\\Cooldown\\star4"
-- Main Icon List
local textureList = {
{ name = "Star (Default)", path = "Interface\\Cooldown\\star4" },
{ name = "Ring", path = "Interface\\Cooldown\\ping4" },
{ name = "Dot", path = "Interface\\COMMON\\Indicator-Gray" },
}
-- Trail Style List
local trailTextureList = {
{ name = "Match Cursor", path = "MATCH" },
{ name = "Star", path = "Interface\\Cooldown\\star4" },
{ name = "Ring", path = "Interface\\Cooldown\\ping4" },
{ name = "Dot", path = "Interface\\COMMON\\Indicator-Gray" },
}
local function GetTexturePath(name)
for _, data in ipairs(textureList) do
if data.name == name then
return data.path
end
end
return textureList[1].path
end
local function GetTrailTexturePath(name)
for _, data in ipairs(trailTextureList) do
if data.name == name then
return data.path
end
end
return "MATCH"
end
-- 1. Main Frame
local frame = CreateFrame("Frame", "StarCursorMain", UIParent)
frame:SetSize(baseSize, baseSize)
frame:SetFrameStrata("TOOLTIP")
frame:SetIgnoreParentAlpha(true)
local tex = frame:CreateTexture(nil, "OVERLAY")
tex:SetAllPoints()
frame.tex = tex
-- 2. Trail Frames
local trails = {}
for i = 1, 40 do
local t = CreateFrame("Frame", nil, UIParent)
t:SetSize(trailSize, trailSize)
t:SetFrameStrata("TOOLTIP")
t.tex = t:CreateTexture(nil, "OVERLAY")
t.tex:SetAllPoints()
t:Hide()
trails[i] = t
end
-- 3. Update Visuals
local function UpdateVisuals()
if not StarCursorDB then
return
end
currentTexturePath = GetTexturePath(StarCursorDB.texture)
frame:SetAlpha(StarCursorDB.alpha or 1)
frame.tex:SetTexture(currentTexturePath)
frame.tex:SetVertexColor(StarCursorDB.r or 1, StarCursorDB.g or 1, StarCursorDB.b or 1)
frame.tex:SetBlendMode("ADD")
end
-- 4. Animation Variables
local currentVisualScale = 0
local lastX, lastY = 0, 0
-- 5. Main Loop
frame:SetScript("OnUpdate", function(self, elapsed)
if not StarCursorDB then
return
end
local x, y = GetCursorPosition()
local uiscale = UIParent:GetEffectiveScale()
if uiscale == 0 then
uiscale = 1
end
x = x / uiscale
y = y / uiscale
frame:SetPoint("CENTER", UIParent, "BOTTOMLEFT", x, y)
local dist = math.sqrt((x - lastX) ^ 2 + (y - lastY) ^ 2)
-- Speed Scale Logic
local speedFactor = math.min(dist / 15, 1.0)
local targetScale = (StarCursorDB.scale or 1) * speedFactor
local smoothSpeed = (targetScale > currentVisualScale) and 15 or 5
currentVisualScale = currentVisualScale + (targetScale - currentVisualScale) * (elapsed * smoothSpeed)
if currentVisualScale < 0.05 then
currentVisualScale = 0
end
frame:SetSize(baseSize * currentVisualScale, baseSize * currentVisualScale)
-- Trail Logic
if StarCursorDB.trail and currentVisualScale > 0.2 and dist > 3 then
local t = trails[1]
table.remove(trails, 1)
t:SetPoint("CENTER", UIParent, "BOTTOMLEFT", x, y)
local trailScale = currentVisualScale * 0.6
t:SetSize(trailSize * trailScale, trailSize * trailScale)
-- Trail Texture Selection
local selectedTrailStyle = StarCursorDB.trailTexture or "Match Cursor"
local trailPathToUse
if selectedTrailStyle == "Match Cursor" then
trailPathToUse = currentTexturePath
else
trailPathToUse = GetTrailTexturePath(selectedTrailStyle)
if trailPathToUse == "MATCH" then
trailPathToUse = currentTexturePath
end
end
t.tex:SetTexture(trailPathToUse)
t.tex:SetVertexColor(StarCursorDB.r or 1, StarCursorDB.g or 1, StarCursorDB.b or 1, 1.0)
t.tex:SetBlendMode("ADD")
local startAlpha = (StarCursorDB.alpha or 1) * 0.6
t:SetAlpha(startAlpha)
t:Show()
UIFrameFadeOut(t, 0.5, startAlpha, 0)
table.insert(trails, t)
end
lastX, lastY = x, y
end)
-- 6. Color Picker
local function OpenColorPicker()
local function ColorCallback()
local r, g, b = ColorPickerFrame:GetColorRGB()
StarCursorDB.r, StarCursorDB.g, StarCursorDB.b = r, g, b
UpdateVisuals()
end
if ColorPickerFrame.SetupColorPickerAndShow then
ColorPickerFrame:SetupColorPickerAndShow({
r = StarCursorDB.r,
g = StarCursorDB.g,
b = StarCursorDB.b,
swatchFunc = ColorCallback,
})
else
ColorPickerFrame.func = ColorCallback
ColorPickerFrame:SetColorRGB(StarCursorDB.r, StarCursorDB.g, StarCursorDB.b)
ColorPickerFrame:Show()
end
end
-- 7. Settings UI
local panel = CreateFrame("Frame", "StarCursorOptions", UIParent)
panel.name = "StarCursor"
local function InitOptions()
local title = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 16, -16)
title:SetText("StarCursor Settings")
-- Trail Checkbox
local trailBtn = CreateFrame("CheckButton", "StarCursorTrailCheck", panel, "InterfaceOptionsCheckButtonTemplate")
trailBtn:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -20)
_G[trailBtn:GetName() .. "Text"]:SetText("Enable Trail")
trailBtn:SetChecked(StarCursorDB.trail)
trailBtn:SetScript("OnClick", function(self)
StarCursorDB.trail = self:GetChecked()
end)
-- Scale Slider
local scaleSlider = CreateFrame("Slider", "StarCursorScale", panel, "OptionsSliderTemplate")
scaleSlider:SetPoint("TOPLEFT", trailBtn, "BOTTOMLEFT", 0, -40)
scaleSlider:SetMinMaxValues(0.2, 5.0)
scaleSlider:SetValueStep(0.1)
scaleSlider:SetObeyStepOnDrag(true)
_G[scaleSlider:GetName() .. "Text"]:SetText("Max Size (At Full Speed)")
scaleSlider:SetValue(StarCursorDB.scale)
scaleSlider:SetScript("OnValueChanged", function(self, value)
StarCursorDB.scale = value
currentVisualScale = value
UpdateVisuals()
end)
-- Alpha Slider
local alphaSlider = CreateFrame("Slider", "StarCursorAlpha", panel, "OptionsSliderTemplate")
alphaSlider:SetPoint("TOPLEFT", scaleSlider, "BOTTOMLEFT", 0, -40)
alphaSlider:SetMinMaxValues(0.1, 1.0)
alphaSlider:SetValueStep(0.1)
alphaSlider:SetObeyStepOnDrag(true)
_G[alphaSlider:GetName() .. "Text"]:SetText("Transparency")
alphaSlider:SetValue(StarCursorDB.alpha)
alphaSlider:SetScript("OnValueChanged", function(self, value)
StarCursorDB.alpha = value
currentVisualScale = StarCursorDB.scale
UpdateVisuals()
end)
-- ICON HEADER
local iconHeader = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
iconHeader:SetPoint("TOPLEFT", alphaSlider, "BOTTOMLEFT", 0, -25)
iconHeader:SetText("Cursor Icon")
-- ICON DROPDOWN
local iconDropdown = CreateFrame("DropdownButton", "StarCursorIconDropdown", panel, "WowStyle1DropdownTemplate")
iconDropdown:SetPoint("TOPLEFT", iconHeader, "BOTTOMLEFT", -15, -10)
iconDropdown:SetWidth(150)
iconDropdown:SetupMenu(function(dropdown, rootDescription)
for _, data in ipairs(textureList) do
rootDescription:CreateRadio(data.name, function()
return StarCursorDB.texture == data.name
end, function()
StarCursorDB.texture = data.name
currentVisualScale = StarCursorDB.scale
UpdateVisuals()
end)
end
end)
-- TRAIL HEADER
local trailHeader = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
trailHeader:SetPoint("TOPLEFT", iconDropdown, "BOTTOMLEFT", 15, -20)
trailHeader:SetText("Trail Style")
-- TRAIL DROPDOWN
local trailDropdown = CreateFrame("DropdownButton", "StarCursorTrailDropdown", panel, "WowStyle1DropdownTemplate")
trailDropdown:SetPoint("TOPLEFT", trailHeader, "BOTTOMLEFT", -15, -10)
trailDropdown:SetWidth(150)
trailDropdown:SetupMenu(function(dropdown, rootDescription)
for _, data in ipairs(trailTextureList) do
rootDescription:CreateRadio(data.name, function()
return StarCursorDB.trailTexture == data.name
end, function()
StarCursorDB.trailTexture = data.name
currentVisualScale = StarCursorDB.scale
UpdateVisuals()
end)
end
end)
-- Color Button
local colorBtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
colorBtn:SetSize(200, 25)
colorBtn:SetPoint("TOPLEFT", trailDropdown, "BOTTOMLEFT", 15, -20)
colorBtn:SetText("Change Color")
colorBtn:SetScript("OnClick", OpenColorPicker)
-- Reset Button
local resetBtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
resetBtn:SetSize(200, 25)
resetBtn:SetPoint("TOPLEFT", colorBtn, "BOTTOMLEFT", 0, -30)
resetBtn:SetText("Reset to Defaults")
resetBtn:SetScript("OnClick", function()
StarCursorDB.scale = defaultSettings.scale
StarCursorDB.alpha = defaultSettings.alpha
StarCursorDB.trail = defaultSettings.trail
StarCursorDB.r = defaultSettings.r
StarCursorDB.g = defaultSettings.g
StarCursorDB.b = defaultSettings.b
StarCursorDB.texture = defaultSettings.texture
StarCursorDB.trailTexture = defaultSettings.trailTexture
trailBtn:SetChecked(defaultSettings.trail)
scaleSlider:SetValue(defaultSettings.scale)
alphaSlider:SetValue(defaultSettings.alpha)
iconDropdown:GenerateMenu()
trailDropdown:GenerateMenu()
print("|cFF00FF00StarCursor:|r Reset complete.")
UpdateVisuals()
end)
end
-- 8. Initialization
local loader = CreateFrame("Frame")
loader:RegisterEvent("ADDON_LOADED")
loader:SetScript("OnEvent", function(self, event, arg1)
if arg1 ~= addonName then
return
end
StarCursorDB = StarCursorDB or {}
for k, v in pairs(defaultSettings) do
if StarCursorDB[k] == nil then
StarCursorDB[k] = v
end
end
InitOptions()
UpdateVisuals()
if Settings and Settings.RegisterCanvasLayoutCategory then
optionsCategory = Settings.RegisterCanvasLayoutCategory(panel, panel.name)
Settings.RegisterAddOnCategory(optionsCategory)
else
InterfaceOptions_AddCategory(panel)
end
self:UnregisterEvent("ADDON_LOADED")
end)
-- Slash Command
SLASH_STARCURSOR1 = "/starcursor"
SlashCmdList["STARCURSOR"] = function()
if optionsCategory and Settings and Settings.OpenToCategory then
Settings.OpenToCategory(optionsCategory:GetID())
else
InterfaceOptionsFrame_OpenToCategory(panel)
InterfaceOptionsFrame_OpenToCategory(panel)
end
end