-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIconer.lua
More file actions
executable file
·226 lines (181 loc) · 5.8 KB
/
Iconer.lua
File metadata and controls
executable file
·226 lines (181 loc) · 5.8 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
local _, Iconer = ...
local icons = {
[0] = "None",
[1] = "|cffffff00Star|r",
[2] = "|cffff8000Circle|r",
[3] = "|cffff00ffDiamond|r",
[4] = "|cff7CFC00Triangle|r",
[5] = "|cffc7c7cfMoon|r",
[6] = "|cff00BFFFSquare|r",
[7] = "|cffFF4500Cross|r",
[8] = "|cffffffffSkull|r",
}
local db, auto;
local timeTillNext = 0;
local _, battleTag = BNGetInfo();
function Iconer:setup()
local frame = CreateFrame("Frame");
frame:RegisterEvent("ADDON_LOADED"); -- Fired when saved variables are loaded
frame:RegisterEvent("GROUP_ROSTER_UPDATE"); -- Fired when saved variables are loaded
function frame:OnEvent(event, arg1)
if event == "ADDON_LOADED" and arg1 == "Iconer" then
if IconerDB == nil then
IconerDB = {}
end
if IconerDB.icons == nil then
IconerDB.icons = {}
end
db = IconerDB.icons;
if IconerDB.auto == nil then
IconerDB.auto = {
group = false
}
end
auto = IconerDB.auto;
-- Setup Slash Commands
SLASH_ICONER1 = '/iconer';
SlashCmdList["ICONER"] = IconerCommand;
-- Setup Options UI
Iconer:registerOptions();
elseif event == "GROUP_ROSTER_UPDATE" then
-- Check if auto-icon is enabled
if not auto.group then
--print("Auto-icon is not enabled. Skipping.")
return;
end
if GetNumSubgroupMembers() > 0 then
--print("Group has members, so Iconer is being run.")
IconerCommand()
end
end
end
frame:SetScript("OnEvent", frame.OnEvent);
end
function IconerCommand(msg, editbox)
local clear = msg == "clear";
if msg=="options" then
Settings.OpenToCategory(Iconer_Options.categoryId);
return
end
-- Check if enough time has past to apply
if timeTillNext < GetTime() then
--print("Enough time has past, running Iconer.")
timeTillNext = GetTime()+1
else
--print("Not enough time has past, skipping Iconer.")
return;
end
r=SetRaidTarget;
local icon = db[battleTag];
if icon then
r("player",0);
if not clear then
r("player",icon);
end
end
ma=db
for i=1, BNGetNumFriends() do
a=C_BattleNet.GetFriendAccountInfo(i);
b=a.battleTag;
c=a.gameAccountInfo.characterName;
if c and ma[b] then
r(c, 0)
if not clear then
r(c, ma[b])
end
end
end
end
function Iconer:registerOptions()
local options = Iconer_Options;
options.name = "Iconer";
-- Setup Friends List
local friendsList = CreateFrame("Frame", nil, Iconer_Options_Friends);
friendsList:SetSize(1,1);
Iconer_Options_Friends.ScrollBar:ClearAllPoints();
Iconer_Options_Friends.ScrollBar:SetPoint("TOPLEFT", Iconer_Options_FriendsBackdrop, "TOPRIGHT", -14, -20) ;
Iconer_Options_Friends.ScrollBar:SetPoint("BOTTOMRIGHT", Iconer_Options_FriendsBackdrop, "BOTTOMRIGHT", -10, 19) ;
Iconer_Options_Friends:SetScrollChild(friendsList);
Iconer:createFriendsList(friendsList)
Iconer_Options_Friends:SetClipsChildren(true);
-- Setup Auto-running options
Iconer_Options_Auto:SetScript("OnClick", function(self)
Iconer:setAutoGroup(self)
end)
Iconer_Options_Auto:SetChecked(auto.group)
-- Add the panel to the Interface Options
local category, layout = Settings.RegisterCanvasLayoutCategory(Iconer_Options, "Iconer");
Iconer_Options.categoryId = category:GetID();
Settings.RegisterAddOnCategory(category);
end
function Iconer:createFriendsList(friendsList)
local friends, nf, friend = {}, {};
-- Add self
local wowAccountGUID = select(3, BNGetInfo())
if(wowAccountGUID == nil) then
-- When the user isn't logged into Battle.net, this will stop loading Iconer before errors are thrown
return
end
friends[1] = C_BattleNet.GetAccountInfoByID(wowAccountGUID);
-- Add favorites and store non-favorites
for i=1, BNGetNumFriends() do
friend=C_BattleNet.GetFriendAccountInfo(i);
if friend then
if friend.isFavorite then
friends[#friends+1] = friend;
else
nf[#nf+1] = friend;
end
end
end
-- Add non-favorites to end of table
for i=1,#nf do
friends[#friends+1] = nf[i]
end
-- Create list of friends
for i=1, #friends do
a=friends[i]
b=a.battleTag;
c=a.gameAccountInfo.characterName;
local btn = CreateFrame("Frame", nil, friendsList, "Iconer_FriendTemplate");
btn:SetPoint("TOPLEFT", 0, -(i-1)*45) ;
if b == battleTag then
btn.battleTag:SetText("You");
btn.character:SetText(UnitName("player"));
else
btn.battleTag:SetText(b);
--btn.battleTag:SetText("FriendBattleTag#" .. math.ceil(math.random()*9999));
btn.character:SetText(c and c or "Not playing" );
if c == nil then btn.character:SetTextColor(.486,.518,.541) end
end
btn.dropDown = btn.dropdown;
btn.dropDown.battleTag = b;
UIDropDownMenu_SetWidth(btn.dropDown, 100)
UIDropDownMenu_SetText(btn.dropDown, db[b] and icons[db[b]] or icons[0])
-- Create and bind the initialization function to the dropdown menu
UIDropDownMenu_Initialize(btn.dropDown, function(self, level, menuList)
local info = UIDropDownMenu_CreateInfo()
local battleTag = self.battleTag;
for i=0,#icons do
info.text, info.arg1, info.checked = icons[i], i, i == db[battleTag]
info.menuList = i
info.func = function(self, newValue)
-- Update the dropdown text to the new selection
UIDropDownMenu_SetText(btn.dropDown, icons[newValue])
self.checked = true;
-- Save the new selection to the db
if newValue == 0 then
db[battleTag] = nil;
else
db[battleTag] = newValue;
end
end
UIDropDownMenu_AddButton(info)
end
end)
end
end
function Iconer:setAutoGroup(button)
auto.group = button:GetChecked()
end
Iconer:setup();