-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPerfectRaid_Options.lua
More file actions
241 lines (203 loc) · 7.52 KB
/
PerfectRaid_Options.lua
File metadata and controls
241 lines (203 loc) · 7.52 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
--[[-------------------------------------------------------------------------
Copyright (c) 2006, Jim Whitehead II <cladhaire@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of PerfectRaid nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------]]
local Options = PerfectRaid:NewModule("PerfectRaid-Options")
local L = PerfectRaidLocals
function Options:Initialize()
end
function Options:Enable()
self.cmd = self:InitializeSlashCommand("PerfectRaid Options", "PERFECTRAID", "praid", "perfectraid")
self.cmd:RegisterSlashHandler(L["Show options GUI"], "^$", "ShowOptions")
self.cmd:RegisterSlashHandler(L["lock - Lock frames"], "^lock$", "LockFrames")
self.cmd:RegisterSlashHandler(L["unlock - Unlock frames"], "^unlock$", "UnlockFrames")
self.cmd:InjectDBCommands(PerfectRaid.db, "copy", "delete", "list", "reset", "set")
end
function Options:LockFrames()
local profile = PerfectRaid.db.profile
self:Print(L["Frames have been locked"])
profile.locked = true
end
function Options:UnlockFrames()
local profile = PerfectRaid.db.profile
self:Print(L["Frames have been unlocked"])
profile.locked = false
end
function Options:ShowOptions()
if not PROptions then
self:CreateOptions()
self:FadeIn(PROptions)
elseif PROptions:IsVisible() then
self:FadeOut(PROptions)
else
self:FadeIn(PROptions)
end
end
local tabs = {}
function Options:CreateOptions()
local frame = CreateFrame("Frame", "PROptions", UIParent, "PROptionsTemplate")
frame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
tile = true,
tileSize = 32,
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
edgeSize = 32,
insets = {
left = 11,
right = 12,
top = 12,
bottom = 11
}
})
frame:SetHeight(450)
frame:SetWidth(650)
frame:SetPoint("CENTER", 0, 50)
PROptionsHeaderTitle:SetText(L["PerfectRaid Options"])
local sortTbl = {}
for name,module in PerfectRaid:IterateModules() do
table.insert(sortTbl, name)
sortTbl[name] = module
end
table.sort(sortTbl)
for idx,name in ipairs(sortTbl) do
local module = sortTbl[name]
if module ~= self and type(module.CreateOptions) == "function" then
module:CreateOptions(self)
end
end
PanelTemplates_SetNumTabs(PROptions, #tabs)
PanelTemplates_SetTab(PROptions, 0)
self:TabOnClick(PROptionsTab3)
end
local work = {}
function Options:AddOptionsTab(title, frame)
local num = #tabs + 1
local name = "PROptionsTab"..num
local tab = CreateFrame("Button", name, PROptions, "PRTabTemplate")
tab.idx = num
if num == 1 then
tab:SetPoint("CENTER", PROptions, "BOTTOMLEFT", 50, -8)
else
local prev = getglobal("PROptionsTab"..num-1)
tab:SetPoint("TOPLEFT", prev, "TOPRIGHT", -16, 0)
end
tab:SetText(title)
tab.frame = frame
tab.title = title
tab:Show()
tab.frame:SetPoint("TOPLEFT", PROptions, "TOPLEFT", 20, -30)
tab.frame:SetPoint("BOTTOMRIGHT", PROptions, "BOTTOMRIGHT", -15, 10)
tab.frame:Hide()
table.insert(tabs, tab)
return tab
end
function Options:FadeIn(frame)
frame:Show()
UIFrameFadeIn(frame, 0.2)
end
function Options:FadeOut(frame)
--UIFrameFadeOut(frame, 0.2)
frame:Hide()
end
local tabselected
function Options:TabOnClick(tab)
local old = tabselected
if tabselected then
self:FadeOut(tabselected.frame)
end
self:FadeIn(tab.frame)
tabselected = tab
PanelTemplates_SetTab(PROptions, tab.idx)
self:TriggerMessage("PERFECTRAID_TAB_CHANGED", old, tab)
end
function Options:CreateListFrame(parent, num)
local function OnClick(self)
local scrollframe = getglobal(parent:GetName().."ScrollFrame")
local parent = self:GetParent()
local offset = FauxScrollFrame_GetOffset(scrollframe)
local idx = offset + self.idx
if parent.selected and parent.selected - offset == self.idx then
parent.entries[parent.selected - offset]:SetChecked(true)
elseif parent.selected then
local idx = parent.selected - offset
if idx <= num then
parent.entries[parent.selected - offset]:SetChecked(false)
end
end
parent.selected = idx
end
local function OnEnter(self)
if self.tooltip then
GameTooltip_SetDefaultAnchor(GameTooltip, self);
GameTooltip:SetText(self.tooltip)
end
end
local function OnLeave(self)
GameTooltip:Hide()
end
local function MakeEntry(name, parent)
local entry = CreateFrame("CheckButton", name, parent)
entry:SetScript("OnClick", OnClick)
entry:SetHeight(20)
entry:SetPoint("LEFT", 0, 0)
entry:SetPoint("RIGHT", -20, 0)
entry:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
entry:SetCheckedTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
entry:GetHighlightTexture():SetBlendMode("ADD")
entry.line1 = entry:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
entry.line1:SetPoint("LEFT", 0 ,0)
entry.line1:SetPoint("RIGHT", -5, 0)
entry.line1:SetJustifyH("LEFT")
entry:SetScript("OnEnter", OnEnter)
entry:SetScript("OnLeave", OnLeave)
return entry
end
parent.entries = {}
local entries = parent.entries
for i=1,num do
entries[i] = MakeEntry(parent:GetName().."Entry"..i, parent)
entries[i].idx = i
end
entries[1]:SetPoint("TOPLEFT",0,0)
for i=2,num do
entries[i]:SetPoint("TOPLEFT", entries[i-1], "BOTTOMLEFT", 0, 0)
end
local scrollframe = CreateFrame("ScrollFrame", parent:GetName().."ScrollFrame", parent, "FauxScrollFrameTemplate")
scrollframe:SetPoint("TOPLEFT", entries[1], "TOPLEFT", 0, 0)
scrollframe:SetPoint("BOTTOMRIGHT", entries[num], "BOTTOMRIGHT", 0, 0)
local texture = scrollframe:CreateTexture(nil, "BACKGROUND")
texture:SetTexture("Interface\\ChatFrame\\ChatFrameBackground")
texture:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 14, 0)
texture:SetPoint("BOTTOMRIGHT", scrollframe, "BOTTOMRIGHT", 23, 0)
texture:SetGradientAlpha("HORIZONTAL", 0.5, 0.25, 0.05, 0, 0.15,0.15, 0.15, 1)
local texture = scrollframe:CreateTexture(nil, "BACKGROUND")
texture:SetTexture("Interface\\ChatFrame\\ChatFrameBackground")
texture:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 4, 0)
texture:SetPoint("BOTTOMRIGHT", scrollframe, "BOTTOMRIGHT", 14, 0)
texture:SetGradientAlpha("HORIZONTAL", 0.15, 0.15, 0.15, 0.15, 1, 0.5, 0.25, 0.05, 0)
scrollframe.entries = entries
return scrollframe
end