-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.lua
203 lines (171 loc) · 6.12 KB
/
core.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
local addonName, addon = ...
--PrimalComboPoints = setmetatable({}, { __index = _G })
PrimalComboPoints = LibStub("AceAddon-3.0"):NewAddon("PrimalComboPoints", "AceConsole-3.0")
--setmetatable(PrimalComboPoints, { __index = _G })
PrimalComboPoints._G = _G
setfenv(1, PrimalComboPoints)
local PrimalComboPoints = _G.PrimalComboPoints
local AceGUI = _G.LibStub("AceGUI-3.0")
local AceConfig = _G.LibStub("AceConfig-3.0")
local AceConfigDialog = _G.LibStub("AceConfigDialog-3.0")
local comboPointFrame = _G.CreateFrame("Frame", nil, _G.UIParent)
local comboPointFrames = {}
local comboPoints
comboPointFrame:SetSize(32, 32)
comboPointFrame:SetClampedToScreen(true)
comboPointFrame:SetScript("OnDragStart", function(self, button)
self:StartMoving()
end)
comboPointFrame:SetScript("OnDragStop", function(self, button)
self:StopMovingOrSizing()
db.global.xOffset, db.global.yOffset = _G.math.floor(self:GetLeft() + .5), _G.math.floor(self:GetBottom() + .5)
self:SetPoint("BOTTOMLEFT", db.global.xOffset, db.global.yOffset)
end)
local backdrop = {
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
tile = false,
edgeSize = 1,
insets = {
left = 0,
right = 0,
top = 0,
bottom = 0,
},
}
for i = 1, _G.MAX_COMBO_POINTS do
local frame = _G.CreateFrame("Frame", nil, comboPointFrame)
frame:SetSize(15, 15)
comboPointFrames[i] = frame
end
for i = 1, _G.MAX_COMBO_POINTS - 1 do
local frame = comboPointFrames[i]
frame:SetSize(15, 15)
frame:SetBackdrop(backdrop)
frame:SetBackdropBorderColor(0, 0, 0)
frame:SetBackdropColor(0, 0, 0, .25)
end
comboPointFrames[1]:SetPoint("BOTTOMLEFT", comboPointFrame)
comboPointFrames[2]:SetPoint("BOTTOMRIGHT", comboPointFrame)
comboPointFrames[3]:SetPoint("TOPRIGHT", comboPointFrame)
comboPointFrames[4]:SetPoint("TOPLEFT", comboPointFrame)
do
local frame = comboPointFrames[5]
frame:SetFrameLevel(comboPointFrame:GetFrameLevel() + 2)
frame:SetSize(22, 22)
frame:SetBackdrop(backdrop)
frame:SetBackdropBorderColor(0, 0, 0)
frame:SetBackdropColor(1, 1, 1, 0.75)
frame:SetPoint("CENTER", comboPointFrame)
frame:Hide()
end
function comboPointFrame:update(newCP)
comboPoints = newCP
for i = 1, comboPoints do
comboPointFrames[i]:SetBackdropColor(1, 1, 1, .5)
end
for i = comboPoints + 1, _G.MAX_COMBO_POINTS - 1 do
comboPointFrames[i]:SetBackdropColor(0, 0, 0, .25)
end
if comboPoints == _G.MAX_COMBO_POINTS then
if not comboPointFrames[5]:IsShown() then
comboPointFrames[5]:Show()
end
else
comboPointFrames[5]:Hide()
end
end
------------------------------------------------------------------------------------------------------------------------
handlerFrame = _G.CreateFrame("Frame")
handlerFrame:SetScript("OnEvent", function(self, event, ...)
return self[event](self, ...)
end)
function handlerFrame:UNIT_POWER_UPDATE(unit, arg2)
if unit ~= "player" -- Not related to the player's character
or arg2 ~= "COMBO_POINTS" -- Not a Combo Point-related event
then -- Skip update, as it isn't a relevant notification
return
end
local newCP = _G.UnitPower("player", 4)
if db.global.sound and newCP == _G.MAX_COMBO_POINTS and newCP ~= comboPoints then
local file = [[Interface\AddOns\PrimalComboPoints\media\sounds\noisecrux\vio]] .. _G.math.random(10) .. ".ogg"
_G.PlaySoundFile(file, "Master")
end
comboPointFrame:update(newCP)
end
-- UNIT_COMBO_POINTS isn't posted even thought we lose combo points.
function handlerFrame:PLAYER_ENTERING_WORLD()
local newCP = _G.UnitPower("player", 4)
comboPointFrame:update(newCP)
end
------------------------------------------------------------------------------------------------------------------------
local options = {
type = "group",
name = "Options",
args = {
general = {
type = "group",
name = "General",
order = 100,
args = {
toggleLock = {
type = "toggle",
name = "Lock Frame",
desc = "Enable to prevent dragging of the combo point frame.",
set = function(info, val)
comboPointFrame:EnableMouse(not val)
comboPointFrame:SetMovable(not val)
comboPointFrame:RegisterForDrag(not val and "LeftButton" or nil)
db.global.lock = val
end,
get = function(info) return db.global.lock end,
order = 100,
},
enableSound = {
type = "toggle",
name = "Enable Sound",
desc = "Play a sound when reaching 5 combo points.",
set = function(info, val)
db.global.sound = val
end,
get = function(info) return db.global.sound end,
order = 110,
},
},
},
},
}
AceConfig:RegisterOptionsTable("PrimalComboPoints", options)
AceConfigDialog:SetDefaultSize("PrimalComboPoints", 480, 360)
------------------------------------------------------------------------------------------------------------------------
-- http://www.wowace.com/addons/ace3/pages/api/ace-addon-3-0/
function PrimalComboPoints:OnInitialize()
_G.assert(_G.MAX_COMBO_POINTS and _G.MAX_COMBO_POINTS == 5)
do -- http://www.wowace.com/addons/ace3/pages/api/ace-db-3-0/
local defaults = {
global = {
sound = true,
lock = false,
},
}
self.db = _G.LibStub("AceDB-3.0"):New("PrimalComboPointsDB", defaults, true)
end
if not (db.global.xOffset and db.global.yOffset) then
comboPointFrame:SetPoint("CENTER", 0, 0)
else
comboPointFrame:SetPoint("BOTTOMLEFT", db.global.xOffset, db.global.yOffset)
end
if not db.global.lock then
comboPointFrame:EnableMouse(true)
comboPointFrame:SetMovable(true)
comboPointFrame:RegisterForDrag("LeftButton")
end
self:RegisterChatCommand("primalcombopoints", function() AceConfigDialog:Open("PrimalComboPoints") end)
self:RegisterChatCommand("pcp", function() AceConfigDialog:Open("PrimalComboPoints") end)
end
-- http://www.wowace.com/addons/ace3/pages/api/ace-addon-3-0/
function PrimalComboPoints:OnEnable()
handlerFrame:RegisterUnitEvent("UNIT_POWER_UPDATE", "player")
handlerFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
end
-- vim: tw=120 sts=2 sw=2 et