-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
320 lines (271 loc) · 10.8 KB
/
Copy pathCore.lua
File metadata and controls
320 lines (271 loc) · 10.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
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
local L = LibStub("AceLocale-3.0"):GetLocale("Emotive")
local options = {
name = "Emotive",
handler = Emotive,
type = "group",
args = {
dropdown = {
type = "toggle",
name = L["Show Dropdown"],
desc = L["Toggles the display of the Emotive dropdown menu."],
get = "IsShowDropdown",
set = "ToggleShowDropdown",
},
minimap = {
type = "toggle",
name = L["Show Minimap"],
desc = L["Toggles the display of the Emotive minimap icon."],
get = "IsShowMinimap",
set = "ToggleShowMinimap"
}
},
}
local defaults = {
profile = {
minimap = {
hide = false
},
menu = {
hide = false
},
recent = {},
},
}
function Emotive:OnInitialize()
Emotive.db = LibStub("AceDB-3.0"):New("EmotiveDB", defaults, true)
LibStub("AceConfig-3.0"):RegisterOptionsTable("Emotive", options)
Emotive.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Emotive", "Emotive")
Emotive:RegisterChatCommand("emotive", "ChatCommand")
Emotive.ldb = LibStub("LibDataBroker-1.1"):NewDataObject("Emotive", {
type = "data source",
text = "Emotive",
icon = "Interface\\AddOns\\" .. Emotive.name .. "\\images\\" .. Emotive.name,
OnClick = function(self, button)
if button == "RightButton" then
Emotive:Config()
else
if IsShiftKeyDown() then
Emotive:ToggleMinimap()
else
Emotive.ToggleEmotesList()
end
end
end,
OnTooltipShow = function(tooltip)
if tooltip and tooltip.AddLine then
tooltip:SetText(Emotive.name)
tooltip:AddLine("|cffff8040" .. L["Left Click"] .. "|r " .. L["to toggle dropdown"])
tooltip:AddLine("|cffff8040" .. L["Right Click"] .. "|r " .. L["for options"])
tooltip:AddLine("|cffff8040" .. L["Shift + Left Click"] .. "|r " .. L["to toggle minimap"])
tooltip:AddLine("|cffff8040" .. L["Drag"] .. "|r " .. L["to move this button"])
tooltip:Show()
end
end,
})
Emotive.icon = LibStub("LibDBIcon-1.0")
Emotive.icon:Register("Emotive", Emotive.ldb, Emotive.db.profile.minimap)
if (not Emotive.db.profile.menu.hide) then
Emotive.InitializeMenu()
end
end
function Emotive:Config()
if Emotive.optionsFrame then
if (InterfaceOptionsFrame:IsShown()) then
InterfaceOptionsFrame:Hide()
else
InterfaceOptionsFrame_OpenToCategory(Emotive.optionsFrame)
InterfaceOptionsFrame_OpenToCategory(Emotive.optionsFrame)
end
end
end
function Emotive:ChatCommand(input)
if not input or input:trim() == "" then
Emotive:Config()
else
LibStub("AceConfigCmd-3.0"):HandleCommand("emotive", "Emotive", input)
end
end
function Emotive:IsShowDropdown(info)
return not Emotive.db.profile.menu.hide
end
function Emotive:ToggleShowDropdown(info, value)
Emotive.db.profile.menu.hide = value
Emotive.ToggleEmotesList()
end
function Emotive:IsShowMinimap(info)
return not Emotive.db.profile.minimap.hide
end
function Emotive:ToggleShowMinimap(info, value)
Emotive.db.profile.minimap.hide = value
Emotive.ToggleMinimap()
end
function Emotive:InitializeMenu()
if (Emotive.menu and Emotive.menu:IsShown()) then
return
else
Emotive.ToggleEmotesList()
end
end
function Emotive:SendEmote(emote)
DEFAULT_CHAT_FRAME.editBox:SetText("/" .. emote)
ChatEdit_SendText(DEFAULT_CHAT_FRAME.editBox, 0)
local index = {}
for k,v in pairs(Emotive.db.profile.recent) do
index[v]=k
end
if (index[emote] ~= nil) then
table.remove(Emotive.db.profile.recent, index[emote])
table.insert(Emotive.db.profile.recent, 1, emote);
else
table.insert(Emotive.db.profile.recent, 1, emote)
end
while #Emotive.db.profile.recent > 5 do
table.remove(Emotive.db.profile.recent, #Emotive.db.profile.recent)
end
CloseDropDownMenus()
end
function Emotive:ToggleMinimap()
if (not Emotive.icon) then
return
end
if (Emotive.db.profile.minimap.hide) then
Emotive.db.profile.minimap.hide = false
Emotive.icon:Show("Emotive")
else
Emotive.db.profile.minimap.hide = true
Emotive.icon:Hide("Emotive")
end
end
function Emotive:ToggleEmotesList()
if (Emotive.menu and Emotive.db.profile.menu.hide) then
Emotive.db.profile.menu.hide = false
Emotive.menu:Show()
elseif (Emotive.menu) then
Emotive.db.profile.menu.hide = true
Emotive.menu:Hide()
else
function AddRecent()
local info = UIDropDownMenu_CreateInfo()
info.text, info.hasArrow, info.notCheckable, info.menuList = L["Recent"], true, 1, "RECENT"
UIDropDownMenu_AddButton(info)
end
function AddSeparator(level)
UIDropDownMenu_AddSeparator(level)
end
function AddEmote(emote, level)
local _, raceEn = UnitRace("player")
local faction = UnitFactionGroup("player", true);
local targetName, _ = UnitName("target")
local info = UIDropDownMenu_CreateInfo()
local descriptor = "Text"
local key = string.upper(string.sub(emote, 1, 1))
if Emotive.emotesByLetter[key] == nil then
return
end
if Emotive.emotesByLetter[key][emote] == nil then
return
end
local definition = Emotive.emotesByLetter[key][emote]
if definition["Animation"] and definition["Voice"] then
info.colorCode = "|cff1eff00"
descriptor = L["Animation"] .. "/" .. L["Voice"]
elseif definition["Animation"] then
info.colorCode = "|cff9482c9"
descriptor = L["Animation"]
elseif definition["Voice"] then
info.colorCode = "|cffff8000"
descriptor = L["Voice"]
end
info.tooltipTitle = L["Self"] .. " (" .. descriptor .. ")"
info.tooltipText = L[emote]["Self"]
if (targetName ~= nil) then
info.tooltipTitle = L["Target"] .. " (" .. descriptor .. ")"
info.tooltipText = L[emote]["Target"](targetName)
end
info.text, info.func, info.notCheckable, info.arg1, info.tooltipOnButton, info.tooltipWhileDisabled = emote, Emotive.SendEmote, 1, emote, 1, 1
--- Disable clicking if player doesn't meet restrictions
if definition["Restrictions"] ~= nil then
if definition["Restrictions"]["race"] ~= nil and definition["Restrictions"]["race"] ~= raceEn then
info.tooltipTitle = info.tooltipTitle .. " [" .. L["X Only"](definition["Restrictions"]["race"]) .. "]"
info.notClickable = 1
elseif definition["Restrictions"]["faction"] ~= nil and definition["Restrictions"]["faction"] ~= faction then
info.tooltipTitle = info.tooltipTitle .. " [" .. L["X Only"](definition["Restrictions"]["faction"]) .. "]"
info.notClickable = 1
elseif definition["Restrictions"]["target"] ~= nil then
if definition["Restrictions"]["target"] and targetName == nil then
info.tooltipTitle = info.tooltipTitle .. " [" .. L["X Only"]("Target") .. "]"
info.notClickable = 1
end
if not definition["Restrictions"]["target"] and targetName ~= nil then
info.tooltipTitle = info.tooltipTitle .. " [" .. L["X Only"]("Self") .. "]"
info.notClickable = 1
end
end
end
UIDropDownMenu_AddButton(info, level)
end
function AddLetter(letter)
if Emotive.emotesByLetter[letter] == nil then
return
end
local info = UIDropDownMenu_CreateInfo()
info.text, info.hasArrow, info.notCheckable, info.menuList = letter, true, 1, letter
UIDropDownMenu_AddButton(info)
end
function AddLetters()
local alphabet = L["Alphabet"]
for i = 1, #alphabet do
local letter = string.sub(alphabet, i, i)
AddLetter(letter)
end
end
function AddRecentEmotes(level)
for i = 1, #Emotive.db.profile.recent do
AddEmote(Emotive.db.profile.recent[i], level)
end
end
function MenuInitialize(self, level, menuList)
if (not level) then
level = 1;
end
if (level == 1) then
AddRecent()
AddSeparator()
AddLetters()
elseif menuList then
if (menuList == "RECENT") then
AddRecentEmotes(level)
else
local letterEmotes = {}
for emote in pairs(Emotive.emotesByLetter[menuList]) do
table.insert(letterEmotes, emote)
end
table.sort(letterEmotes)
for _, emote in ipairs(letterEmotes) do
AddEmote(emote, level)
end
end
end
end
Emotive.menu = CreateFrame("FRAME", "EmotiveDropDown", UIParent, "UIDropDownMenuTemplate")
Emotive.menu:SetPoint("CENTER")
Emotive.menu:SetMovable(true)
Emotive.menu:EnableMouse(true)
Emotive.menu:SetClampedToScreen(true)
Emotive.menu:RegisterForDrag("LeftButton")
Emotive.menu:SetFrameStrata("LOW")
if (Emotive.db.profile.menu.point and Emotive.db.profile.menu.relativePoint and Emotive.db.profile.menu.x and Emotive.db.profile.menu.y) then
Emotive.menu:ClearAllPoints()
Emotive.menu:SetPoint(Emotive.db.profile.menu.point, nil, Emotive.db.profile.menu.relativePoint, Emotive.db.profile.menu.x, Emotive.db.profile.menu.y)
end
UIDropDownMenu_SetWidth(Emotive.menu, 100)
UIDropDownMenu_SetText(Emotive.menu, L["Emotive"])
UIDropDownMenu_Initialize(Emotive.menu, MenuInitialize)
Emotive.menu:SetScript("OnDragStart", Emotive.menu.StartMoving)
Emotive.menu:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
Emotive.db.profile.menu.point, _, Emotive.db.profile.menu.relativePoint, Emotive.db.profile.menu.x, Emotive.db.profile.menu.y = self:GetPoint(1)
end)
Emotive.db.profile.menu.hide = false
end
end