-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.lua
More file actions
130 lines (114 loc) · 3.65 KB
/
Main.lua
File metadata and controls
130 lines (114 loc) · 3.65 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
--[[
DOCUMENTATION USED:
http://wowprogramming.com/docs/events/UNIT_ENTERED_VEHICLE
http://wowprogramming.com/docs/events/UNIT_EXITED_VEHICLE
http://wowprogramming.com/docs/api/SetOverrideBinding
http://wowprogramming.com/docs/api/ClearOverrideBindings
FrameXML/Bindings.xml
]]
--INITIALIZE
local addon = LibStub("AceAddon-3.0"):NewAddon(
"Clutch", "AceConsole-3.0", "AceEvent-3.0")
addon.frame = CreateFrame("Frame") --For override bindings.
addon.config = LibStub("AceConfig-3.0")
addon.config.dialog = LibStub("AceConfigDialog-3.0")
_G.Clutch = addon
local db_defaults = {
profile = {
bindings = {
default = {"1", "2", "3", "4", "5", "6" },
custom = {}
}
}
}
--SHORTHAND/UTILITY FUNCTIONS
local db
local function IsKeybound()
return ClutchCheckButton:GetChecked()
end
local function InVehicle()
return UnitHasVehicleUI("player")
end
local function ShowMessage(text)
ClutchMessageText:SetText(text)
ClutchMessage:Show()
end
local function HideMessage()
ClutchMessage:Hide()
end
--ACE ADDON HANDLERS
function addon:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("ClutchDB", db_defaults, true)
db = self.db.profile
self.config:RegisterOptionsTable("Clutch", self.options, "clutch")
self.config.dialog:AddToBlizOptions("Clutch", nil,
nil, "general")
end
function addon:OnEnable()
--self:RegisterChatCommand("clutch", "SlashCmdHandler")
self:RegisterEvent("UNIT_ENTERED_VEHICLE")
self:RegisterEvent("UNIT_EXITED_VEHICLE")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
end
function addon:OnDisable()
end
--MAIN FUNCTIONS
function addon:SlashCmdHandler(input)
local arg = self:GetArgs(input)
if arg == "clear" then
print("Clutch bindings cleared!")
self:ClearBindings()
elseif arg == "joust" then
print("Setting to Yumi's defaults!")
db.bindings.default = { "E", "4", "F", "R", "SHIFT-R", "T" }
elseif arg == "default" then
print("Setting to default 1-6 bindings!")
db.bindings.default = { "1", "2", "3", "4", "5", "6" }
elseif arg == "reset" then
print("Unsetting 'ClutchDB' Bindings variable!")
self:ResetDB()
elseif arg == "" then
InterfaceOptionsFrame_OpenToCategory(ClutchOptions)
else
print("HELP MESSAGE HERE")
end
end
function addon:UNIT_ENTERED_VEHICLE(event, unit, arg2)
if InVehicle() and not InCombatLockdown() and not IsKeybound() then
self:SetBindings()
end
end
function addon:UNIT_EXITED_VEHICLE(event, unit, arg2)
if InCombatLockdown() and IsKeybound() then
ShowMessage("Waiting to leave combat to unbind keys...")
elseif IsKeybound() then
self:ClearBindings()
end
end
function addon:PLAYER_REGEN_ENABLED()
ClutchCheckButton:Enable()
if IsKeybound() and not InVehicle() then
self:ClearBindings()
HideMessage()
end
end
function addon:PLAYER_REGEN_DISABLED()
ClutchCheckButton:Disable()
end
function addon:SetBindings()
local vehicle = GetUnitName("vehicle")
local bindings = db.bindings.custom[vehicle] ~= nil and
db.bindings.custom[vehicle] or db.bindings.default
for i = 1, VEHICLE_MAX_ACTIONBUTTONS do
if HasAction(i) then
SetOverrideBinding(self.frame, true, bindings[i],
"ACTIONBUTTON" .. i)
end
end
ClutchCheckButton:SetChecked(true)
end
function addon:ClearBindings()
ClearOverrideBindings(self.frame)
ClutchCheckButton:SetChecked(false)
end