forked from me0wg4ming/Quickcall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickcall.lua
More file actions
233 lines (200 loc) · 7.08 KB
/
Quickcall.lua
File metadata and controls
233 lines (200 loc) · 7.08 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
-- QuickCall Header for the Bindings
BINDING_HEADER_QUICKCALL = "Quick Call"
-- Valid AB base locations
local baseNames = {
["Farm"] = true,
["Stables"] = true,
["Lumber Mill"] = true,
["Blacksmith"] = true,
["Gold Mine"] = true,
}
-- SavedVariables setup
if not QuickCallDB then QuickCallDB = {} end
QuickCallDB.locked = QuickCallDB.locked ~= false -- default true
QuickCallDB.posX = QuickCallDB.posX or 400
QuickCallDB.posY = QuickCallDB.posY or 300
-- Custom mod
local function mod(a, b)
return a - math.floor(a / b) * b
end
-- Clamp helper
local function ClampToScreen(x, y)
local screenW = UIParent:GetWidth()
local screenH = UIParent:GetHeight()
x = math.max(0, math.min(x or 0, screenW - 220))
y = math.max(0, math.min(y or 0, screenH - 160))
return x, y
end
local function SaveFramePosition()
local _, _, _, x, y = QuickCallFrame:GetPoint()
x, y = ClampToScreen(x, y)
QuickCallDB.posX = x
QuickCallDB.posY = y
end
local function UpdateLockButton()
QuickCallFrame:EnableMouse(not QuickCallDB.locked)
if lockBtn then
lockBtn:SetText(QuickCallDB.locked and "Unlock" or "Lock")
end
end
local function ToggleLock()
QuickCallDB.locked = not QuickCallDB.locked
UpdateLockButton()
if QuickCallDB.locked then
DEFAULT_CHAT_FRAME:AddMessage("|cff66ccffQuickCall:|r |cffff0000Position locked!|r")
else
DEFAULT_CHAT_FRAME:AddMessage("|cff66ccffQuickCall:|r |cff00ff00Position unlocked!|r")
end
end
-- Layout constants
local buttonWidth = 25
local buttonHeight = 26
local spacing = 10
local buttonsPerRow = 4
local totalWidth = buttonsPerRow * buttonWidth + (buttonsPerRow - 1) * spacing
local frameWidth = totalWidth + 40
local frameHeight = 3 * buttonHeight + 3 * spacing + 70
-- Create main frame
local QuickCallFrame = CreateFrame("Frame", "QuickCallFrame", UIParent)
QuickCallFrame:SetClampedToScreen(true)
QuickCallFrame:SetWidth(frameWidth)
QuickCallFrame:SetHeight(frameHeight)
local x, y = ClampToScreen(QuickCallDB.posX, QuickCallDB.posY)
QuickCallFrame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", x, y)
QuickCallFrame:SetMovable(true)
QuickCallFrame:RegisterForDrag("LeftButton")
QuickCallFrame:SetScript("OnDragStart", function()
if not QuickCallDB.locked then QuickCallFrame:StartMoving() end
end)
QuickCallFrame:SetScript("OnDragStop", function()
QuickCallFrame:StopMovingOrSizing()
SaveFramePosition()
end)
QuickCallFrame:SetBackdrop({
bgFile = "Interface\\AddOns\\QuickCall\\Quickcall.tga",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = false,
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
QuickCallFrame:SetBackdropColor(1, 1, 1, 0.90)
-- Title text
local title = QuickCallFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("TOP", QuickCallFrame, "TOP", 0, -12)
title:SetText("Call Battleground Enemies")
title:SetTextColor(1, 1, 0)
title:SetFont("Fonts\\FRIZQT__.TTF", 10.5)
-- Shared zone check logic
local function NotInAB(callback)
local zone = GetRealZoneText()
local base = GetMinimapZoneText()
if zone == "Arathi Basin" or baseNames[base] then
callback()
return
end
DEFAULT_CHAT_FRAME:AddMessage("|cff66ccffQuickCall:|r |cffff0000You are not in Arathi Basin!|r")
end
-- Shared action handlers
local lastKnownBase = nil
local function HandleCall(index)
NotInAB(function()
local minimapZone = GetMinimapZoneText() or ""
local realZone = GetRealZoneText() or ""
if realZone == "Arathi Basin" and baseNames[minimapZone] then
lastKnownBase = minimapZone
end
if lastKnownBase and baseNames[lastKnownBase] then
local msg = (index == 8 and "8 or more at " or index .. " at ") .. lastKnownBase
SendChatMessage(msg, "BATTLEGROUND")
else
DEFAULT_CHAT_FRAME:AddMessage("|cff66ccffQuickCall:|r |cffff0000You are not at a valid base in Arathi Basin!|r")
end
end)
end
local function HandleClear()
NotInAB(function()
local minimapZone = GetMinimapZoneText() or ""
local realZone = GetRealZoneText() or ""
if realZone == "Arathi Basin" and baseNames[minimapZone] then
lastKnownBase = minimapZone
end
if lastKnownBase and baseNames[lastKnownBase] then
SendChatMessage(lastKnownBase .. " CLEAR", "BATTLEGROUND")
else
DEFAULT_CHAT_FRAME:AddMessage("|cff66ccffQuickCall:|r |cffff0000You are not at a valid base in Arathi Basin!|r")
end
end)
end
-- Buttons 1–8
local framePaddingX = (frameWidth - totalWidth) / 2
for i = 1, 8 do
local btn = CreateFrame("Button", "QuickCallButton"..i, QuickCallFrame, "UIPanelButtonTemplate")
btn:SetWidth(buttonWidth)
btn:SetHeight(buttonHeight)
btn:SetText(i == 8 and "8+" or tostring(i))
btn:GetFontString():SetPoint("LEFT", 4, 0)
btn:GetFontString():SetPoint("RIGHT", -4, 0)
local row = math.floor((i - 1) / buttonsPerRow)
local col = mod(i - 1, buttonsPerRow)
local x = framePaddingX + col * (buttonWidth + spacing)
local y = -30 - row * (buttonHeight + spacing)
btn:SetPoint("TOPLEFT", QuickCallFrame, "TOPLEFT", x, y)
btn:SetScript("OnClick", (function(index)
return function() HandleCall(index) end
end)(i))
end
-- CLEAR button
local clearBtn = CreateFrame("Button", "QuickCallClear", QuickCallFrame, "UIPanelButtonTemplate")
clearBtn:SetWidth(totalWidth)
clearBtn:SetHeight(buttonHeight)
clearBtn:SetText("BASE CLEAR")
clearBtn:SetPoint("TOP", QuickCallFrame, "TOP", 0, -2 * (buttonHeight + spacing) - 40)
clearBtn:SetScript("OnClick", HandleClear)
-- Lock/unlock toggle button
lockBtn = CreateFrame("Button", "QuickCallLockToggle", QuickCallFrame, "UIPanelButtonTemplate")
lockBtn:SetWidth(60)
lockBtn:SetHeight(20)
lockBtn:SetText("Lock")
lockBtn:SetPoint("BOTTOM", QuickCallFrame, "BOTTOM", 0, 8)
lockBtn:SetScript("OnClick", ToggleLock)
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:SetScript("OnEvent", function()
UpdateLockButton()
DEFAULT_CHAT_FRAME:AddMessage("|cff66ccffQuickCall:|r |cff00ff00addon loaded.|r")
end)
-- Keybinding functions
-- Set up keybindings CALL_1 through CALL_8 with closure fix
for i = 1, 8 do
local idx = i
setglobal("CALL_" .. idx, function() HandleCall(idx) end)
end
-- Add the CALL_CLEAR binding
setglobal("CALL_CLEAR", function() HandleClear() end)
--Show/hide in Arathi Basin
local function UpdateVisibility()
local zoneName = GetRealZoneText()
if zoneName == "Arathi Basin" then
QuickCallFrame:Show()
else
QuickCallFrame:Hide()
end
end
--Event handling (no more lock logic here — handled above)
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:SetScript("OnEvent", function()
UpdateVisibility()
end)
-- Slash command
SLASH_QUICKCALL1 = "/quickcall"
SLASH_QUICKCALL2 = "/qc"
SlashCmdList["QUICKCALL"] = function()
if QuickCallFrame:IsShown() then
QuickCallFrame:Hide()
else
QuickCallFrame:Show()
end
end
QuickCallFrame:Hide()