forked from Wetxius/Numeration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.lua
378 lines (338 loc) · 12 KB
/
Window.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
local addon = select(2, ...)
local l = addon.locale
local s = addon.windows
local window = CreateFrame("Frame", "NumerationFrame", UIParent)
addon.window = window
local lines = {}
local noop = function() end
local backAction = noop
local reportAction = noop
local backdrop = {
bgFile = [[Interface\ChatFrame\ChatFrameBackground]]
}
local clickFunction = function(self, btn)
if btn == "LeftButton" then
self.detailAction(self)
elseif btn == "RightButton" then
backAction(self)
elseif btn == "MiddleButton" then
reportAction(self.num)
end
end
local optionFunction = function(f, id, _, checked)
addon:SetOption(id, checked)
end
local numReports = 9
local reportFunction = function(f, chatType, channel)
addon:Report(numReports, chatType, channel)
CloseDropDownMenus()
end
local dropdown = CreateFrame("Frame", "NumerationMenuFrame", nil, "UIDropDownMenuTemplate")
local menuTable = {
{text = "Numeration", isTitle = true, notCheckable = true, notClickable = true},
{text = CHAT_ANNOUNCE, notCheckable = true, hasArrow = true,
menuList = {
{text = CHAT_MSG_SAY, arg1 = "SAY", func = reportFunction, notCheckable = 1},
{text = PARTY, arg1 = "PARTY", func = reportFunction, notCheckable = 1},
{text = RAID, arg1 = "RAID", func = reportFunction, notCheckable = 1},
{text = INSTANCE, arg1 = "INSTANCE_CHAT", func = reportFunction, notCheckable = 1},
{text = GUILD, arg1 = "GUILD", func = reportFunction, notCheckable = 1},
{text = OFFICER, arg1 = "OFFICER", func = reportFunction, notCheckable = 1},
{text = WHISPER, func = function()
StaticPopupDialogs.REPORT_DIALOG.OnAccept = function(self)
reportFunction(self, "WHISPER", _G[self:GetName().."EditBox"]:GetText())
end
StaticPopup_Show("REPORT_DIALOG")
end, notCheckable = 1},
{text = CHANNEL, notCheckable = 1, keepShownOnClick = true, hasArrow = true, menuList = {}}
},
},
{text = GAMEOPTIONS_MENU, notCheckable = true, hasArrow = true,
menuList = {
{text = l.pet_merge, arg1 = "petsmerged", func = optionFunction, checked = function() return addon:GetOption("petsmerged") end, keepShownOnClick = true},
{text = l.only_boss, arg1 = "keeponlybosses", func = optionFunction, checked = function() return addon:GetOption("keeponlybosses") end, keepShownOnClick = true},
{text = l.only_instance, arg1 = "onlyinstance", func = optionFunction, checked = function() return addon:GetOption("onlyinstance") end, keepShownOnClick = true},
{text = l.show_icon, func = function(f, a1, a2, checked) addon:MinimapIconShow(checked) end, checked = function() return not NumerationCharOptions.minimap.hide end, keepShownOnClick = true},
},
},
{text = "", notCheckable = true, notClickable = true},
{text = RESET, func = function() StaticPopup_Show("RESET_DATA") end, notCheckable = true},
}
local updateReportChannels = function()
menuTable[2].menuList[8].menuList = table.wipe(menuTable[2].menuList[8].menuList)
for i = 1, GetNumDisplayChannels() do
local name, _, _, channelNumber, _, active, category = GetChannelDisplayInfo(i)
if category == "CHANNEL_CATEGORY_CUSTOM" then
tinsert(menuTable[2].menuList[8].menuList, {text = name, arg1 = "CHANNEL", arg2 = channelNumber, func = reportFunction, notCheckable = 1})
end
end
end
local reportActionFunction = function(num)
updateReportChannels()
numReports = num
EasyMenu(menuTable[2].menuList, dropdown, "cursor", 0 , 0, "MENU")
end
function window:OnInitialize()
self.maxlines = s.maxlines
self:SetWidth(s.width)
self:SetHeight(3+s.titleheight+s.maxlines*(s.lineheight+s.linegap))
self:SetClampedToScreen(true)
self:EnableMouse(true)
self:EnableMouseWheel(true)
self:SetMovable(true)
self:RegisterForDrag("LeftButton")
self:SetScript("OnDragStart", function() if IsAltKeyDown() then self:StartMoving() end end)
self:SetScript("OnDragStop", function()
self:StopMovingOrSizing()
-- positioning code taken from recount
local xOfs, yOfs = self:GetCenter()
local s = self:GetEffectiveScale()
local uis = UIParent:GetScale()
xOfs = xOfs*s - GetScreenWidth()*uis/2
yOfs = yOfs*s - GetScreenHeight()*uis/2
addon:SetOption("x", xOfs/uis)
addon:SetOption("y", yOfs/uis)
end)
self:SetBackdrop(backdrop)
self:SetBackdropColor(0, 0, 0, s.backgroundalpha)
local x, y = addon:GetOption("x"), addon:GetOption("y")
if not x or not y then
self:SetPoint(unpack(s.pos))
else
-- positioning code taken from recount
local s = self:GetEffectiveScale()
local uis = UIParent:GetScale()
self:SetPoint("CENTER", UIParent, "CENTER", x*uis/s, y*uis/s)
end
local scroll = self:CreateTexture(nil, "ARTWORK")
self.scroll = scroll
scroll:SetTexture([[Interface\Buttons\WHITE8X8]])
scroll:SetTexCoord(.8, 1, .8, 1)
scroll:SetVertexColor(0, 0, 0, .8)
scroll:SetWidth(4)
scroll:SetHeight(4)
scroll:Hide()
local reset = CreateFrame("Button", nil, self)
self.reset = reset
reset:SetBackdrop(backdrop)
reset:SetBackdropColor(0, 0, 0, s.titlealpha)
reset:SetWidth(s.titleheight)
reset:SetHeight(s.titleheight)
reset:SetPoint("TOPRIGHT", -1, -1)
reset:SetScript("OnMouseUp", function()
updateReportChannels()
numReports = 9
EasyMenu(menuTable, dropdown, "cursor", 0 , 0, "MENU")
end)
reset:SetScript("OnEnter", function() reset:SetBackdropColor(s.highlight[1], s.highlight[2], s.highlight[3], .3) end)
reset:SetScript("OnLeave", function() reset:SetBackdropColor(0, 0, 0, s.titlealpha) end)
reset.text = reset:CreateFontString(nil, "ARTWORK")
reset.text:SetFont(s.linefont, s.linefontsize, s.linefontstyle)
reset.text:SetShadowOffset(s.fontshadow and 1 or 0, s.fontshadow and -1 or 0)
reset.text:SetPoint("CENTER", 1, 0)
reset.text:SetText(">")
local segment = CreateFrame("Button", nil, self)
self.segment = segment
segment:SetBackdrop(backdrop)
segment:SetBackdropColor(0, 0, 0, s.titlealpha/2)
segment:SetWidth(s.titleheight-2)
segment:SetHeight(s.titleheight-2)
segment:SetPoint("RIGHT", reset, "LEFT", -2, 0)
segment:SetScript("OnMouseUp", function() addon.nav.view = "Sets" addon.nav.set = nil addon:RefreshDisplay() dropdown:Show() end)
segment:SetScript("OnEnter", function()
segment:SetBackdropColor(s.highlight[1], s.highlight[2], s.highlight[3], .3)
GameTooltip:SetOwner(segment, "ANCHOR_BOTTOMRIGHT")
local name = ""
if addon.nav.set == "current" then
name = l.current
else
local set = addon:GetSet(addon.nav.set)
if set then
name = set.name
end
end
GameTooltip:AddLine(name)
GameTooltip:Show()
end)
segment:SetScript("OnLeave", function() segment:SetBackdropColor(0, 0, 0, s.titlealpha/2) GameTooltip:Hide() end)
segment.text = segment:CreateFontString(nil, "ARTWORK")
segment.text:SetFont(s.linefont, s.linefontsize, s.linefontstyle)
segment.text:SetShadowOffset(s.fontshadow and 1 or 0, s.fontshadow and -1 or 0)
segment.text:SetPoint("CENTER", 0, 0)
segment.text:SetText("")
local title = self:CreateTexture(nil, "ARTWORK")
self.title = title
title:SetTexture(s.linetexture)
title:SetVertexColor(.25, .66, .35, s.titlealpha)
title:SetPoint("TOPLEFT", 1, -1)
title:SetPoint("BOTTOMRIGHT", reset, "BOTTOMLEFT", -1, 0)
local font = self:CreateFontString(nil, "ARTWORK")
self.titletext = font
font:SetJustifyH("LEFT")
font:SetFont(s.titlefont, s.titlefontsize, s.titlefontstyle)
font:SetShadowOffset(s.fontshadow and 1 or 0, s.fontshadow and -1 or 0)
font:SetTextColor(s.titlefontcolor[1], s.titlefontcolor[2], s.titlefontcolor[3], 1)
font:SetHeight(s.titlefontsize)
font:SetPoint("LEFT", title, "LEFT", 4, 0)
font:SetPoint("RIGHT", segment, "LEFT", -1, 0)
self.detailAction = noop
self:SetScript("OnMouseDown", clickFunction)
self:SetScript("OnMouseWheel", function(self, num)
addon:Scroll(num)
end)
end
function window:Clear()
-- self:SetBackAction()
self.scroll:Hide()
self:SetDetailAction()
for id,line in pairs(lines) do
line:SetIcon()
line.spellId = nil
line:Hide()
end
end
function window:UpdateSegment(segment)
if not segment then
self.segment:Hide()
else
self.segment.text:SetText(segment)
self.segment:Show()
end
end
function window:SetTitle(name, r, g, b)
self.title:SetVertexColor(r, g, b, s.titlealpha)
self.titletext:SetText(name)
end
function window:GetTitle()
return self.titletext:GetText()
end
function window:SetScrollPosition(curPos, maxPos)
if not s.scrollbar then return end
if maxPos <= s.maxlines then return end
local total = s.maxlines*(s.lineheight+s.linegap)
self.scroll:SetHeight(s.maxlines/maxPos*total)
self.scroll:SetPoint("TOPLEFT", self.reset, "BOTTOMRIGHT", 2, -1-(curPos-1)/maxPos*total)
self.scroll:Show()
end
function window:SetBackAction(f)
backAction = f or noop
reportAction = noop
end
local SetValues = function(f, c, m)
f:SetMinMaxValues(0, m)
f:SetValue(c)
end
local SetIcon = function(f, icon)
if icon then
f:SetWidth(s.width-s.lineheight-2)
f.icon:SetTexture(icon)
f.icon:Show()
else
f:SetWidth(s.width-2)
f.icon:Hide()
end
end
local SetLeftText = function(f, ...)
f.name:SetFormattedText(...)
end
local SetRightText = function(f, ...)
f.value:SetFormattedText(...)
end
local SetColor = function(f, r, g, b, a)
f:SetStatusBarColor(r, g, b, a or s.linealpha)
end
local SetDetailAction = function(f, func)
f.detailAction = func or noop
end
local SetReportNumber = function(f, num)
reportAction = reportActionFunction
f.num = num
end
window.SetDetailAction = SetDetailAction
local onEnter = function(self)
if not self.spellId then return end
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT", -20, s.lineheight)
GameTooltip:SetHyperlink("spell:"..self.spellId)
end
local onLeave = function(self)
GameTooltip:Hide()
end
function window:GetLine(id)
if lines[id] then return lines[id] end
local f = CreateFrame("StatusBar", nil, self)
lines[id] = f
f:EnableMouse(true)
f.detailAction = noop
f:SetScript("OnMouseDown", clickFunction)
f:SetScript("OnEnter", onEnter)
f:SetScript("OnLeave", onLeave)
f:SetStatusBarTexture(s.linetexture)
f:SetStatusBarColor(.6, .6, .6, 1)
f:SetWidth(s.width-2)
f:SetHeight(s.lineheight)
if id == 0 then
f:SetPoint("TOPRIGHT", self.reset, "BOTTOMRIGHT", 0, -1)
else
f:SetPoint("TOPRIGHT", lines[id-1], "BOTTOMRIGHT", 0, -s.linegap)
end
local icon = f:CreateTexture(nil, "OVERLAY")
f.icon = icon
icon:SetWidth(s.lineheight)
icon:SetHeight(s.lineheight)
icon:SetPoint("RIGHT", f, "LEFT")
icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
icon:Hide()
local value = f:CreateFontString(nil, "ARTWORK")
f.value = value
value:SetHeight(s.lineheight)
value:SetJustifyH("RIGHT")
value:SetFont(s.linefont, s.linefontsize, s.linefontstyle)
value:SetShadowOffset(s.fontshadow and 1 or 0, s.fontshadow and -1 or 0)
value:SetTextColor(s.linefontcolor[1], s.linefontcolor[2], s.linefontcolor[3], 1)
value:SetPoint("RIGHT", -1, 0)
local name = f:CreateFontString(nil, "ARTWORK")
f.name = name
name:SetHeight(s.lineheight)
name:SetNonSpaceWrap(false)
name:SetJustifyH("LEFT")
name:SetFont(s.linefont, s.linefontsize, s.linefontstyle)
name:SetShadowOffset(s.fontshadow and 1 or 0, s.fontshadow and -1 or 0)
name:SetTextColor(s.linefontcolor[1], s.linefontcolor[2], s.linefontcolor[3], 1)
name:SetPoint("LEFT", icon, "RIGHT", 1, 0)
name:SetPoint("RIGHT", value, "LEFT", -1, 0)
f.SetValues = SetValues
f.SetIcon = SetIcon
f.SetLeftText = SetLeftText
f.SetRightText = SetRightText
f.SetColor = SetColor
f.SetDetailAction = SetDetailAction
f.SetReportNumber = SetReportNumber
return f
end
StaticPopupDialogs.RESET_DATA = {
text = "Numeration: "..l.reset_data,
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function() addon:Reset() end,
timeout = 0,
whileDead = 1,
hideOnEscape = true,
preferredIndex = 5,
}
StaticPopupDialogs.REPORT_DIALOG = {
text = "Numeration: "..l.whisp_target,
OnShow = function (self)
if UnitCanCooperate("player", "target") then
self.editBox:SetText(GetUnitName("target", true))
reportFunction(self, "WHISPER", StaticPopup1EditBox:GetText())
StaticPopup_Hide("REPORT_DIALOG")
end
end,
button1 = WHISPER,
timeout = 0,
hasEditBox = 1,
whileDead = 1,
EditBoxOnEnterPressed = function(self) reportFunction(self, "WHISPER", StaticPopup1EditBox:GetText()) self:GetParent():Hide() end,
EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
preferredIndex = 5,
}