-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerMenu.lua
More file actions
383 lines (350 loc) · 11.3 KB
/
PlayerMenu.lua
File metadata and controls
383 lines (350 loc) · 11.3 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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
--[[ $Id: PlayerMenu.lua 70828 2008-04-22 03:41:29Z hshh $ ]]--
PlayerMenu = LibStub("AceAddon-3.0"):NewAddon("PlayerMenu", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("PlayerMenu")
--save blizzard origin variables
local menus = {"FRIEND", "PLAYER", "PARTY", "RAID_PLAYER"}
local menus_new_items = {"GUILD_INVITE", "ADD_FRIEND", "GET_NAME", "WHO", "EXTMENU"}
local PM_BLZ_ORIGIN = {}
local m,k,v
local _G = getfenv(0)
for _,m in ipairs(menus) do
PM_BLZ_ORIGIN[m]={}
for k,v in pairs(_G.UnitPopupMenus[m]) do
PM_BLZ_ORIGIN[m][k]=v
end
end
local ExtMaxButton = 20
--db get/set function
local function get(info)
local k = info[#info]
return PlayerMenu.db.profile[k]
end
local function set(info,value)
local k = info[#info]
PlayerMenu.db.profile[k] = value
end
function PlayerMenu:OnInitialize()
local defaults = {
profile = {
leftButton = false,
useFocus = false,
extAutoHide = 3,
clearTargetAfterCast = true,
}
}
self.db = LibStub("AceDB-3.0"):New("PlayerMenu_Settings", defaults, "Default")
local options = {
type = "group",
get = get,
set = set,
args = {
leftButton = {
order = 100,
type = "toggle",
name = L["Left Button Menu"],
desc = L["Mouse left click to show menu"],
},
useFocus = {
order = 200,
type = "toggle",
name = L["Use Focus to Cast"],
desc = L["Use focus feature to cast spell instead of using target."],
},
extAutoHide = {
order = 300,
type = "range",
name = L["Extend Menu Hide Delay"],
desc = L["Set extend menu auto hide delay time."],
min = 1,
max = 20,
step = 1,
},
clearTargetAfterCast = {
order = 400,
type = "toggle",
name = L["Clear Target After Cast"],
},
resetdb = {
order = 500,
type = "execute",
name = L["Reset"],
confirm = true,
confirmText = L["ResetDB_Confirm"],
func = function()
self.db:ResetDB()
self:OnDisable()
self:OnEnable()
self:Print(L["All settings are reset to default value."])
end,
},
}
}
LibStub("AceConfig-3.0"):RegisterOptionsTable("PlayerMenu", options)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("PlayerMenu", "PlayerMenu")
end
function PlayerMenu:OnEnable()
self:InitSpell()
self:RegisterEvent("SPELLS_CHANGED", "InitSpell")
self:RegisterEvent("LEARNED_SPELL_IN_TAB", "InitSpell")
self:RegisterEvent("PLAYER_REGEN_DISABLED", "ExtMenu_AutoHide") --hide ext menu in battle
self:SecureHook("UnitPopup_OnClick")
self:SecureHook("UnitPopup_HideButtons")
if (self.db.profile.leftButton) then
self:SecureHook("SetItemRef")
end
local v,vv
for _,v in ipairs(menus_new_items) do
UnitPopupButtons[v] = { text = L[v], dist = 0 }
for _,vv in ipairs(menus) do
tinsert(UnitPopupMenus[vv], getn(UnitPopupMenus[vv])-1, v)
end
end
end
function PlayerMenu:OnDisable()
local v,vv,kkk,vvv
for _,v in ipairs(menus_new_items) do
for _,vv in ipairs(menus) do
UnitPopupMenus[vv]={}
for kkk,vvv in pairs(PM_BLZ_ORIGIN[vv]) do
UnitPopupMenus[vv][kkk]=vvv
end
end
UnitPopupButtons[v] = nil
end
self:ExtMenu_AutoHide()
end
function PlayerMenu:UnitPopup_HideButtons()
-- hide ext menu
self:ExtMenu_AutoHide()
--local dropdownMenu = getglobal(UIDROPDOWNMENU_INIT_MENU) --fix 3.08 bug by rimu
local dropdownMenu = UIDROPDOWNMENU_INIT_MENU;
local diffFactionGroup
if dropdownMenu.unit and UnitFactionGroup("player") ~= UnitFactionGroup(dropdownMenu.unit) then
diffFactionGroup = true
end
local realm
if dropdownMenu.unit then
_,realm = UnitName(dropdownMenu.unit)
end
for index, value in ipairs(UnitPopupMenus[dropdownMenu.which]) do
if value == "GET_NAME" then
if dropdownMenu.name == UnitName("player") then
UnitPopupShown[UIDROPDOWNMENU_MENU_LEVEL][index] = 0
else
UnitPopupShown[UIDROPDOWNMENU_MENU_LEVEL][index] = 1
end
elseif value == "WHO" or value == "ADD_FRIEND" then
if dropdownMenu.name == UnitName("player") or (realm and realm ~="") or diffFactionGroup then
UnitPopupShown[UIDROPDOWNMENU_MENU_LEVEL][index] = 0
else
UnitPopupShown[UIDROPDOWNMENU_MENU_LEVEL][index] = 1
end
elseif value == "GUILD_INVITE" then
if not CanGuildInvite() or dropdownMenu.name == UnitName("player") or (realm and realm ~="") or diffFactionGroup then
UnitPopupShown[UIDROPDOWNMENU_MENU_LEVEL][index] = 0
else
UnitPopupShown[UIDROPDOWNMENU_MENU_LEVEL][index] = 1
end
elseif value == "EXTMENU" then
UnitPopupShown[UIDROPDOWNMENU_MENU_LEVEL][index] = 1
end
end
end
function PlayerMenu:UnitPopup_OnClick()
--local dropdownFrame = getglobal(UIDROPDOWNMENU_INIT_MENU) --fix 3.08 bug by rimu
local dropdownFrame = UIDROPDOWNMENU_INIT_MENU
local button = this.value
local name = dropdownFrame.name
if (button == "ADD_FRIEND") then
AddFriend(name)
elseif (button == "GUILD_INVITE") then
GuildInvite(name)
elseif (button == "GET_NAME") then
ChatFrameEditBox:Show()
local realm
if dropdownFrame.unit then
_,realm = UnitName(dropdownFrame.unit)
end
if (realm and realm ~="") then
ChatFrameEditBox:Insert(name .. " - " .. realm)
else
ChatFrameEditBox:Insert(name)
end
elseif (button == "WHO") then
SendWho(name)
elseif (button == "EXTMENU") then
self:ExtMenu_InitButton(name)
self:ExtMenu_Show()
end
PlaySound("UChatScrollButton")
end
function PlayerMenu:SetItemRef(link, text, button)
if ( strsub(link, 1, 6) == "player" ) then
local namelink = strsub(link, 8);
local name, lineid = strsplit(":", namelink);
if ( name and (strlen(name) > 0) ) then
if ( IsModifiedClick("CHATLINK") ) then
local staticPopup;
staticPopup = StaticPopup_Visible("ADD_IGNORE");
if ( staticPopup ) then
-- If add ignore dialog is up then enter the name into the editbox
getglobal(staticPopup.."EditBox"):SetText(name);
return;
end
staticPopup = StaticPopup_Visible("ADD_MUTE");
if ( staticPopup ) then
-- If add ignore dialog is up then enter the name into the editbox
getglobal(staticPopup.."EditBox"):SetText(name);
return;
end
staticPopup = StaticPopup_Visible("ADD_FRIEND");
if ( staticPopup ) then
-- If add ignore dialog is up then enter the name into the editbox
getglobal(staticPopup.."EditBox"):SetText(name);
return;
end
staticPopup = StaticPopup_Visible("ADD_GUILDMEMBER");
if ( staticPopup ) then
-- If add ignore dialog is up then enter the name into the editbox
getglobal(staticPopup.."EditBox"):SetText(name);
return;
end
staticPopup = StaticPopup_Visible("ADD_TEAMMEMBER");
if ( staticPopup ) then
-- If add ignore dialog is up then enter the name into the editbox
getglobal(staticPopup.."EditBox"):SetText(name);
return;
end
staticPopup = StaticPopup_Visible("ADD_RAIDMEMBER");
if ( staticPopup ) then
-- If add ignore dialog is up then enter the name into the editbox
getglobal(staticPopup.."EditBox"):SetText(name);
return;
end
staticPopup = StaticPopup_Visible("CHANNEL_INVITE");
if ( staticPopup ) then
getglobal(staticPopup.."EditBox"):SetText(name);
return;
end
if ( ChatFrameEditBox:IsVisible() ) then
ChatFrameEditBox:Insert(name);
elseif ( HelpFrameOpenTicketText:IsVisible() ) then
HelpFrameOpenTicketText:Insert(name);
else
SendWho("n-"..name);
end
else
ChatFrameEditBox:Hide()
FriendsFrame_ShowDropdown(name, 1, lineid);
end
end
return;
end
end
function PlayerMenu:InitSpell()
self.SpellCache = {}
self.SpellCache_Count = 0
local _, class = UnitClass("player")
if class == "ROGUE" or class == "WARRIOR" or class == "HUNTER" then return end
-- check if spell is in spellbook
local k,v
local spell = {}
for k,v in pairs(self.Spell) do
if GetSpellInfo(k) then
tinsert(spell, k)
end
end
self.SpellCache = spell
self.SpellCache_Count = getn(spell)
end
function PlayerMenu:ExtMenu_ButtonOnClick()
PlayerMenu:ExtMenu_AutoHide()
end
function PlayerMenu:ExtMenu_InitButton(name)
if not name then
name = UnitName("player")
end
local lastTarget = UnitName("target")
PMEM_Frame_Button1:SetText(L["Set Target"])
PMEM_Frame_Button1:SetAttribute("type1", "macro")
PMEM_Frame_Button1:SetAttribute("macrotext", "/target "..name)
PMEM_Frame_Button1:Show()
PMEM_Frame_Button2:SetText(L["Set Focus"])
PMEM_Frame_Button2:SetAttribute("type1", "macro")
if lastTarget and lastTarget~=name then
PMEM_Frame_Button2:SetAttribute("macrotext", "/target "..name.."\n/focus\n/target "..lastTarget)
else
PMEM_Frame_Button2:SetAttribute("macrotext", "/target "..name.."\n/focus")
end
PMEM_Frame_Button2:Show()
PMEM_Frame_Button3:SetText(TRADE)
PMEM_Frame_Button3:SetAttribute("type1", "macro")
PMEM_Frame_Button3:SetAttribute("macrotext", "/target "..name.."\n/trade")
PMEM_Frame_Button3:Show()
local spell_id = 1
for i=4, self.SpellCache_Count+3 do
local button = getglobal("PMEM_Frame_Button"..i)
button:SetText(self.SpellCache[spell_id])
button:SetAttribute("type1", "macro")
if self.db.profile.useFocus then
button:SetAttribute("macrotext", "/focus "..name.."\n/cast [target=focus] "..self.SpellCache[spell_id].."\n/stopcasting\n/clearfocus")
else
if lastTarget and self.db.profile.clearTargetAfterCast and not self.SpellIgnoreClearTarget[self.SpellCache[spell_id]] then
button:SetAttribute("macrotext", "/target "..name.."\n/cast "..self.SpellCache[spell_id].."\n/stopcasting\n/target "..lastTarget)
else
button:SetAttribute("macrotext", "/target "..name.."\n/cast "..self.SpellCache[spell_id].."\n/stopcasting\n")
end
end
button:Show()
spell_id = spell_id + 1
end
for i=self.SpellCache_Count+4,ExtMaxButton do
local button = getglobal("PMEM_Frame_Button"..i)
button:Hide()
end
self.ExtMenuWidth = 0
for i=1, ExtMaxButton do
local button = getglobal("PMEM_Frame_Button"..i)
local width = button:GetTextWidth()
if width > self.ExtMenuWidth then
self.ExtMenuWidth = width
end
end
self.ExtMenuWidth = self.ExtMenuWidth + 2*12
self.ExtMenuHeight = (self.SpellCache_Count + 3 + 2) * 12 -- 3 fix button, top and bottom space
end
function PlayerMenu:ExtMenu_AutoHide()
if PlayerMenu.Timer_ExtMenu_AutoHide then
PlayerMenu:CancelTimer(PlayerMenu.Timer_ExtMenu_AutoHide, true)
PlayerMenu.Timer_ExtMenu_AutoHide = nil
end
if PMEM_Frame:IsVisible() then
PMEM_Frame:Hide()
end
end
function PlayerMenu:ExtMenu_Show()
self.Timer_ExtMenu_AutoHide = self:ScheduleTimer("ExtMenu_AutoHide", self.db.profile.extAutoHide)
local point, relativeTo, relativePoint, xOfs, yOfs = this:GetParent():GetPoint()
PMEM_Frame:SetHeight(self.ExtMenuHeight)
PMEM_Frame:SetWidth(self.ExtMenuWidth)
PMEM_Frame:ClearAllPoints()
PMEM_Frame:SetPoint(point, relativeTo, relativePoint, xOfs, yOfs)
PMEM_Frame:Show()
end
function PlayerMenu:ExtMenu_OnEnter(button)
if PlayerMenu.Timer_ExtMenu_AutoHide then
PlayerMenu:CancelTimer(PlayerMenu.Timer_ExtMenu_AutoHide, true)
PlayerMenu.Timer_ExtMenu_AutoHide = nil
end
if button then
local spell = this:GetText()
if spell and spell ~= L["Set Target"] and spell ~= L["Set Focus"] and spell ~= TRADE then
PMEM_FrameSpellIcon:SetTexture(self.Spell[spell])
PMEM_FrameSpellIcon:Show()
end
end
end
function PlayerMenu:ExtMenu_OnLeave()
PlayerMenu.Timer_ExtMenu_AutoHide = PlayerMenu:ScheduleTimer("ExtMenu_AutoHide", PlayerMenu.db.profile.extAutoHide)
PMEM_FrameSpellIcon:Hide()
end