-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSkillBlocker.lua
288 lines (248 loc) · 9.93 KB
/
SkillBlocker.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
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
SkillBlocker = {}
SkillBlocker.lock = {}
local ADDON_NAME = "SkillBlocker"
local ADDON_VERSION = "1.0b"
local ESOUI_URL = "https://www.esoui.com/downloads/info2619-SkillBlocker.html"
local currentHotbar
local flag = true -- flip-flop for prehook control
local slotNum
--==============================SavedVariables==============================--
local variableVersion = 5
local savedVarsName = "SkillBlockerVars"
local defaults = {
settingsAccountWide = true,
displayAlert = false,
logToChat = true,
rememberLocks = true,
alertLogin = true,
mainBarSaved = {
[1] = false,
[2] = false,
[3] = false,
[4] = false,
[5] = false,
[6] = false
},
offBarSaved = {
[1] = false,
[2] = false,
[3] = false,
[4] = false,
[5] = false,
[6] = false
}
}
local function getSettings()
if SkillBlocker.settings.settingsAccountWide then
return SkillBlocker.globalSettings
else
return SkillBlocker.settings
end
end
SkillBlocker.getSettings = getSettings
--==============================LibAddonMenu==============================--
local LAM = LibAddonMenu2
local panelData = {
type = "panel",
name = "Skill Blocker",
author = "@adjutant",
version = ADDON_VERSION,
website = ESOUI_URL,
}
local optionsData = {
[1] = {
type = "checkbox",
name = "Remember locked skills?",
getFunc = function() return SkillBlocker.settings.rememberLocks end,
setFunc = function(value) SkillBlocker.settings.rememberLocks = value end,
width = "full",
},
[2] = {
type = "checkbox",
name = "Enable account-wide settings:",
getFunc = function() return SkillBlocker.settings.settingsAccountWide end,
setFunc = function(value) SkillBlocker.settings.settingsAccountWide = value end,
width = "full",
requiresReload = true
},
[3] = {
type = "description",
title = nil,
text = "Note: this will make settings below account-wide, however locked skills remain per-character.",
width = "full",
},
[4] = {
type = "header",
name = nil,
},
[5] = {
type = "checkbox",
name = "Display alert:",
tooltip = "Display ZOS-like alert on locked skill cast attempt",
getFunc = function() return SkillBlocker.getSettings().displayAlert end,
setFunc = function(value) SkillBlocker.getSettings().displayAlert = value end,
},
[6] = {
type = "checkbox",
name = "Log to chat:",
tooltip = "Log to chat on locked skill cast attempt",
getFunc = function() return SkillBlocker.getSettings().logToChat end,
setFunc = function(value) SkillBlocker.getSettings().logToChat = value end,
},
[7] = {
type = "checkbox",
name = "Alert on login:",
tooltip = "Display a chat message on login if you have saved locked skills",
getFunc = function() return SkillBlocker.getSettings().alertLogin end,
setFunc = function(value) SkillBlocker.getSettings().alertLogin = value end,
},
[8] = {
type = "description",
title = nil,
text = "This addon is in active development. Feature requests and bug reports are very welcome! Please leave your comments at ESOUI.",
width = "full",
},
}
--==============================Main==============================--
local function loadSaved()
for i = 1, 6 do
SkillBlocker.lock[i].mainBarLocked = SkillBlocker.settings.mainBarSaved[i]
SkillBlocker.lock[i].offBarLocked = SkillBlocker.settings.offBarSaved[i]
end
end
local function drawLocks() -- refresh lock textures based on their state and current hotbar
for i = 1, 6 do
if currentHotbar == 0 then -- main bar
SkillBlocker.lock[i]:SetHidden(false)
if SkillBlocker.lock[i].mainBarLocked then
SkillBlocker.lock[i]:SetNormalTexture("/esoui/art/miscellaneous/locked_up.dds")
SkillBlocker.lock[i]:SetPressedTexture("/esoui/art/miscellaneous/locked_down.dds")
SkillBlocker.lock[i]:SetMouseOverTexture("/esoui/art/miscellaneous/locked_over.dds")
else
SkillBlocker.lock[i]:SetNormalTexture("/esoui/art/miscellaneous/unlocked_up.dds")
SkillBlocker.lock[i]:SetPressedTexture("/esoui/art/miscellaneous/unlocked_down.dds")
SkillBlocker.lock[i]:SetMouseOverTexture("/esoui/art/miscellaneous/unlocked_over.dds")
end
elseif currentHotbar == 1 then -- offbar
SkillBlocker.lock[i]:SetHidden(false)
if SkillBlocker.lock[i].offBarLocked then
SkillBlocker.lock[i]:SetNormalTexture("/esoui/art/miscellaneous/locked_up.dds")
SkillBlocker.lock[i]:SetPressedTexture("/esoui/art/miscellaneous/locked_down.dds")
SkillBlocker.lock[i]:SetMouseOverTexture("/esoui/art/miscellaneous/locked_over.dds")
else
SkillBlocker.lock[i]:SetNormalTexture("/esoui/art/miscellaneous/unlocked_up.dds")
SkillBlocker.lock[i]:SetPressedTexture("/esoui/art/miscellaneous/unlocked_down.dds")
SkillBlocker.lock[i]:SetMouseOverTexture("/esoui/art/miscellaneous/unlocked_over.dds")
end
else
SkillBlocker.lock[i]:SetHidden(true) -- Werewolf, Volendrung, etc...
end
end
end
local function toggleLock(lock) -- toggle lock state based on current hotbar
if currentHotbar == 0 then
if lock.mainBarLocked then
lock.mainBarLocked = false
SkillBlocker.settings.mainBarSaved[lock.index] = false
PlaySound(SOUNDS.INVENTORY_ITEM_UNLOCKED)
else
lock.mainBarLocked = true
SkillBlocker.settings.mainBarSaved[lock.index] = true
PlaySound(SOUNDS.INVENTORY_ITEM_LOCKED)
end
elseif currentHotbar == 1 then
if lock.offBarLocked then
lock.offBarLocked = false
SkillBlocker.settings.offBarSaved[lock.index] = false
PlaySound(SOUNDS.INVENTORY_ITEM_UNLOCKED)
else
lock.offBarLocked = true
SkillBlocker.settings.offBarSaved[lock.index] = true
PlaySound(SOUNDS.INVENTORY_ITEM_LOCKED)
end
end
drawLocks()
end
local function loadLocks() -- register lock controls and anchors
for i = 1, 6 do
local lock = CreateControl(string.format("lock%d", i), ZO_SkillsAssignableActionBar, CT_BUTTON)
lock.index = i
lock.mainBarLocked = false
lock.offBarLocked = false
lock:SetDimensions(16,16)
lock:SetNormalTexture("/esoui/art/miscellaneous/unlocked_up.dds")
lock:SetPressedTexture("/esoui/art/miscellaneous/locked_up.dds")
lock:SetHandler("OnClicked", toggleLock)
SkillBlocker.lock[i] = lock
end
SkillBlocker.lock[1]:SetAnchor(BOTTOM, ZO_SkillsAssignableActionBarButton1, TOP, 0, -7)
SkillBlocker.lock[2]:SetAnchor(BOTTOM, ZO_SkillsAssignableActionBarButton2, TOP, 0, -7)
SkillBlocker.lock[3]:SetAnchor(BOTTOM, ZO_SkillsAssignableActionBarButton3, TOP, 0, -7)
SkillBlocker.lock[4]:SetAnchor(BOTTOM, ZO_SkillsAssignableActionBarButton4, TOP, 0, -7)
SkillBlocker.lock[5]:SetAnchor(BOTTOM, ZO_SkillsAssignableActionBarButton5, TOP, 0, -7)
SkillBlocker.lock[6]:SetAnchor(BOTTOM, ZO_SkillsAssignableActionBarButton6, TOP, 0, -7)
end
local function alert() -- called on locked skill cast attempt. More to come...?
if (SkillBlocker.getSettings().displayAlert) then
ZO_Alert(UI_displayAlert_CATEGORY_ERROR, SOUNDS.CHAMPION_PENDING_POINTS_CLEARED, SI_TRADEACTIONRESULT62)
end
if SkillBlocker.getSettings().logToChat then
d("[Skill Blocker]: \""..GetAbilityName(GetSlotBoundId(slotNum)).."\" is locked")
end
end
function SkillBlocker.unlockAll() -- hotkey
for i = 1, 6 do
SkillBlocker.lock[i].mainBarLocked = false
SkillBlocker.lock[i].offBarLocked = false
end
drawLocks()
d("[Skill Blocker]: all skills unlocked")
PlaySound(SOUNDS.INVENTORY_ITEM_UNLOCKED)
end
local function Initialize()
EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED)
ZO_CreateStringId("SI_BINDING_NAME_UNLOCK_ALL", "Unlock all skills")
SkillBlocker.settings = ZO_SavedVars:NewCharacterIdSettings(savedVarsName, variableVersion, "settings", defaults, GetWorldName())
SkillBlocker.globalSettings = ZO_SavedVars:NewAccountWide(savedVarsName, variableVersion, "globals", defaults, GetWorldName(), "AllAccountsTheSame")
LAM:RegisterAddonPanel("Skill Blocker", panelData)
LAM:RegisterOptionControls("Skill Blocker", optionsData)
currentHotbar = ACTION_BAR_ASSIGNMENT_MANAGER:GetCurrentHotbarCategory() -- get initial bar on login
loadLocks()
if (SkillBlocker.getSettings().rememberLocks) then
loadSaved()
if (SkillBlocker.getSettings().alertLogin) then
for i = 1, 6 do
if (SkillBlocker.lock[i].mainBarLocked or SkillBlocker.lock[i].offBarLocked) then
d("[Skill Blocker]: Some of your skills are locked!")
break
end
end
end
end
drawLocks()
ACTION_BAR_ASSIGNMENT_MANAGER:RegisterCallback("CurrentHotbarUpdated", -- to keep currentHotbar relevant
function(hotbarCategory, oldHotbarCategory)
currentHotbar = hotbarCategory
if SCENE_MANAGER:IsShowing("skills") then -- refresh textures if hotbar is swapped while in skills menu
drawLocks()
end
end)
ZO_PreHook("ZO_ActionBar_CanUseActionSlots", function()
flag = not flag -- Since ZO_ActionBar_CanUseActionSlots is called twice for each ability cast
if flag then
slotNum = tonumber(debug.traceback():match('keybind = "ACTION_BUTTON_(%d)')) -- get pressed button
if (slotNum == 9 or GetSlotBoundId(slotNum) == 0) then return false end -- break if consumable or empty slot
if (currentHotbar == 0 and SkillBlocker.lock[slotNum - 2].mainBarLocked) or
(currentHotbar == 1 and SkillBlocker.lock[slotNum - 2].offBarLocked) then
alert() -- notify player
return true -- ESO won't run ability press if PreHook returns true
end
end
end)
end
local function OnAddOnLoaded(event, addonName)
if addonName == ADDON_NAME then
Initialize()
end
end
EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED, OnAddOnLoaded)