-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClassicArmoryLink.lua
154 lines (127 loc) · 5.46 KB
/
ClassicArmoryLink.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
148
149
150
151
152
153
154
local regionName = GetCurrentRegionName():lower()
local lastInspectedGUID = nil
local currentArmoryFrame = nil
local function CreateArmoryFrame(characterName, realmName)
-- Close the existing frame if it's open
if currentArmoryFrame and currentArmoryFrame:IsShown() then
currentArmoryFrame:Hide()
end
local realmSlug = Cal.GetRealmSlugByName(realmName)
-- Generate the URL
local armoryURL = string.format("https://classic-armory.info/%s/classic/%s/%s", regionName, realmSlug, characterName:lower())
local armoryFrame = CreateFrame("Frame", "ArmoryFrame", UIParent, "BackdropTemplate")
armoryFrame:SetPoint("CENTER")
armoryFrame:SetSize(600, 80)
armoryFrame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 32,
insets = { left = 8, right = 8, top = 8, bottom = 8 }
})
armoryFrame:SetMovable(true)
armoryFrame:EnableMouse(true)
armoryFrame:RegisterForDrag("LeftButton")
armoryFrame:SetScript("OnDragStart", armoryFrame.StartMoving)
armoryFrame:SetScript("OnDragStop", armoryFrame.StopMovingOrSizing)
-- Create the EditBox within the frame
local editBox = CreateFrame("EditBox", "ArmoryLinkBox", armoryFrame, "InputBoxTemplate")
editBox:SetSize(550, 20)
editBox:SetPoint("CENTER", armoryFrame, "CENTER", 0, 0)
local armoryURL = armoryURL -- Replace with your desired URL
editBox:SetText(armoryURL)
editBox:HighlightText()
editBox:SetAutoFocus(true)
editBox:SetScript("OnEscapePressed", function() armoryFrame:Hide() end)
-- give the editbox a title
local title = armoryFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("BOTTOM", editBox, "TOP", 0, 5)
title:SetText("Classic Armory Link")
-- Create a Close Button
local closeButton = CreateFrame("Button", "ArmoryCloseButton", armoryFrame, "UIPanelCloseButton")
closeButton:SetPoint("TOPRIGHT", armoryFrame, "TOPRIGHT")
closeButton:SetScript("OnClick", function() armoryFrame:Hide() end)
currentArmoryFrame = armoryFrame
return armoryFrame
end
local function CreateArmoryButton(parentFrame, isInspect)
if not parentFrame then return end -- Guard clause to ensure parentFrame is not nil
local armoryButton = CreateFrame("Button", nil, parentFrame, "UIPanelButtonTemplate")
armoryButton:SetSize(70, 20)
armoryButton:SetText("Armory")
armoryButton:SetFrameStrata("HIGH")
if isInspect then
armoryButton:SetPoint("TOPLEFT", parentFrame, "TOPLEFT", 160, -50)
armoryButton:Hide() -- Start hidden for Inspect Frame
else
armoryButton:SetPoint("TOPRIGHT", parentFrame, "TOPLEFT", 135, -76)
armoryButton:Hide() -- Start hidden for Character Frame
end
local function UpdateButtonVisibility()
if not isInspect then
local selectedTab = PanelTemplates_GetSelectedTab(CharacterFrame)
if selectedTab == 1 then
armoryButton:Show()
else
armoryButton:Hide()
end
elseif isInspect then
local selectedTab = PanelTemplates_GetSelectedTab(InspectFrame)
if selectedTab == 1 then
armoryButton:Show()
else
armoryButton:Hide()
end
end
end
if not isInspect then
hooksecurefunc("CharacterFrameTab_OnClick", UpdateButtonVisibility)
CharacterFrame:HookScript("OnShow", UpdateButtonVisibility)
elseif isInspect then
hooksecurefunc("InspectSwitchTabs", UpdateButtonVisibility)
InspectFrame:HookScript("OnShow", UpdateButtonVisibility)
end
parentFrame:HookScript("OnShow", function() armoryButton:Show() end)
parentFrame:HookScript("OnHide", function() armoryButton:Hide() end)
armoryButton:SetScript("OnClick", function()
local characterName, realmName
if isInspect then
_, _, _, _, _, characterName, realmName = GetPlayerInfoByGUID(lastInspectedGUID)
else
characterName = UnitName("player", true)
end
if not realmName or realmName == "" then
realmName = GetRealmName()
end
local armoryFrame = CreateArmoryFrame(characterName, realmName)
armoryFrame:Show()
end)
end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("INSPECT_READY")
eventFrame:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "ClassicArmoryLink" then
CreateArmoryButton(CharacterFrame, false)
elseif event == "INSPECT_READY" then
lastInspectedGUID = arg1
CreateArmoryButton(InspectFrame, true)
end
end)
local function SlashCommandHandler(param)
if not UnitExists("target") then
return
end
local realmName
if not UnitIsPlayer("target") then
print("Target is not a player.")
return
end
local characterName, realmName = UnitName("target", true)
if not realmName or realmName == "" then
realmName = GetRealmName()
end
local armoryFrame = CreateArmoryFrame(characterName, realmName)
armoryFrame:Show()
end
SLASH_CLASSICARMORYLINK1 = "/cal"
SlashCmdList["CLASSICARMORYLINK"] = SlashCommandHandler