-
Notifications
You must be signed in to change notification settings - Fork 1
/
RETabBinder.lua
161 lines (152 loc) · 4.66 KB
/
RETabBinder.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
155
156
157
158
159
160
161
local _G = _G
local RE = CreateFrame("Frame", "RETabBinder")
_G.RETabBinder = RE
local print, pairs = _G.print, _G.pairs
local InCombatLockdown = _G.InCombatLockdown
local IsInInstance = _G.IsInInstance
local GetCurrentBindingSet = _G.GetCurrentBindingSet
local GetZonePVPInfo = _G.GetZonePVPInfo
local GetBindingKey = _G.GetBindingKey
local GetBindingAction = _G.GetBindingAction
local SetBinding = _G.SetBinding
local SaveBindings = _G.SaveBindings
RE.AceConfig = {
type = "group",
args = {
DefaultKey = {
name = "Use default bindings",
desc = "Disable to use bindings other than TAB/Shift-TAB.",
type = "toggle",
width = "full",
order = 1,
set = function(_, val) RE.Settings.DefaultKey = val; RE:OnEvent(nil, "ZONE_CHANGED_NEW_AREA") end,
get = function(_) return RE.Settings.DefaultKey end
},
OpenWorld = {
name = "Consider normal zones as PvP ones",
desc = "Enable to consider normal open world zones as PvP instances.",
type = "toggle",
width = "full",
order = 2,
set = function(_, val) RE.Settings.OpenWorld = val; RE:OnEvent(nil, "ZONE_CHANGED_NEW_AREA") end,
get = function(_) return RE.Settings.OpenWorld end
},
SilentMode = {
name = "Disable chat messages",
desc = "Disable printing status messages to the chat window.",
type = "toggle",
width = "full",
order = 3,
set = function(_, val) RE.Settings.SilentMode = val end,
get = function(_) return RE.Settings.SilentMode end
}
}
}
RE.DefaultConfig = {
DefaultKey = true,
OpenWorld = false,
SilentMode = false
}
RE.Fail = false
function RE:OnLoad(self)
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("DUEL_REQUESTED")
self:RegisterEvent("DUEL_FINISHED")
self:RegisterEvent("CHAT_MSG_SYSTEM")
self:RegisterEvent("ADDON_LOADED")
end
function RE:OnEvent(self, event, ...)
if event == "ADDON_LOADED" and ... == "RETabBinder" then
if not _G.RETabBinderSettings then
_G.RETabBinderSettings = RE.DefaultConfig
end
RE.Settings = _G.RETabBinderSettings
for key, value in pairs(RE.DefaultConfig) do
if RE.Settings[key] == nil then
RE.Settings[key] = value
end
end
_G.LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("RETabBinder", RE.AceConfig)
_G.LibStub("AceConfigDialog-3.0"):AddToBlizOptions("RETabBinder", "RETabBinder")
--RE:OnEvent(self, "ZONE_CHANGED_NEW_AREA")
self:UnregisterEvent("ADDON_LOADED")
elseif event == "ZONE_CHANGED_NEW_AREA" or (event == "PLAYER_REGEN_ENABLED" and RE.Fail) or event == "DUEL_REQUESTED" or event == "DUEL_FINISHED" or event == "CHAT_MSG_SYSTEM" then
if event == "CHAT_MSG_SYSTEM" and ... == _G.ERR_DUEL_REQUESTED then
event = "DUEL_REQUESTED"
elseif event == "CHAT_MSG_SYSTEM" then
return
end
local BindSet = GetCurrentBindingSet()
if BindSet ~= 1 and BindSet ~= 2 then
return
end
if InCombatLockdown() then
RE.Fail = true
return
end
local PVPType = GetZonePVPInfo()
local _, ZoneType = IsInInstance()
local TargetKey = GetBindingKey("TARGETNEARESTENEMYPLAYER")
if TargetKey == nil then
TargetKey = GetBindingKey("TARGETNEARESTENEMY")
end
if TargetKey == nil and RE.Settings.DefaultKey then
TargetKey = "TAB"
end
local LastTargetKey = GetBindingKey("TARGETPREVIOUSENEMYPLAYER")
if LastTargetKey == nil then
LastTargetKey = GetBindingKey("TARGETPREVIOUSENEMY")
end
if LastTargetKey == nil and RE.Settings.DefaultKey then
LastTargetKey = "SHIFT-TAB"
end
local CurrentBind
if TargetKey then
CurrentBind = GetBindingAction(TargetKey)
end
if ZoneType == "arena" or ZoneType == "pvp" or (RE.Settings.OpenWorld and ZoneType == "none") or PVPType == "combat" or event == "DUEL_REQUESTED" then
if CurrentBind ~= "TARGETNEARESTENEMYPLAYER" then
local Success
if TargetKey == nil then
Success = true
else
Success = SetBinding(TargetKey, "TARGETNEARESTENEMYPLAYER")
end
if LastTargetKey then
SetBinding(LastTargetKey, "TARGETPREVIOUSENEMYPLAYER")
end
if Success then
SaveBindings(BindSet)
RE.Fail = false
if not RE.Settings.SilentMode then
print("\124cFF74D06C[RETabBinder]\124r PVP Mode")
end
else
RE.Fail = true
end
end
else
if CurrentBind ~= "TARGETNEARESTENEMY" then
local Success
if TargetKey == nil then
Success = true
else
Success = SetBinding(TargetKey, "TARGETNEARESTENEMY")
end
if LastTargetKey then
SetBinding(LastTargetKey, "TARGETPREVIOUSENEMY")
end
if Success then
SaveBindings(BindSet)
RE.Fail = false
if not RE.Settings.SilentMode then
print("\124cFF74D06C[RETabBinder]\124r PVE Mode")
end
else
RE.Fail = true
end
end
end
end
end