-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOutputSelectScrollFrame.lua
More file actions
150 lines (131 loc) · 4.16 KB
/
Copy pathOutputSelectScrollFrame.lua
File metadata and controls
150 lines (131 loc) · 4.16 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
OutputSelectScrollFrameMixin = {}
local dynamicEvents = {
"CHANNEL_UI_UPDATE",
"CHANNEL_LEFT",
};
function OutputSelectScrollFrameMixin:OnLoad()
ItemListScrollFrameMixin.OnLoad(self)
end
function OutputSelectScrollFrameMixin:OnEvent(event, ...)
if event == "CHANNEL_UI_UPDATE" then
self:UpdateOutputs()
end
end
function OutputSelectScrollFrameMixin:SetMessage(message)
self.message = message
self:UpdateOutputs()
end
function OutputSelectScrollFrameMixin:UpdateOutputs()
self.outputs = self:GetDefaultChatOutputs()
tAppendAll(self.outputs, self:GetChannelOutputs())
self:Update()
end
function OutputSelectScrollFrameMixin:GetRowData(index)
return self.outputs[index]
end
function OutputSelectScrollFrameMixin:GetNumItems()
return #self.outputs
end
function OutputSelectScrollFrameMixin:CreateItemRow(i)
local row = ItemListScrollFrameMixin.CreateItemRow(self, i)
row.CheckButton:SetScript("OnClick", function(checkButton, ...)
if row.CheckButton:GetChecked() then
self:AddMessageOutput(row.output)
else
self:RemoveMessageOutput(row.output)
end
end)
return row
end
function OutputSelectScrollFrameMixin:ResetItemRow(row)
row.CheckButton:SetChecked(false)
row.CheckButton.Text:SetText('');
end
function OutputSelectScrollFrameMixin:SetRowData(row, item)
if item then
local outputName = item.display or item.channel
row.CheckButton.Text:SetText(outputName);
local checked = self:IndexOfMessageOutput(self.message.outputs, item) ~= nil
row.CheckButton:SetChecked(checked)
row.output = item
end
end
-- SendChatMessage(msg [, chatType, languageID, target])
function OutputSelectScrollFrameMixin:GetDefaultChatOutputs()
return {
{ chatType = "SAY", display = SAY },
{ chatType = "EMOTE", display = EMOTE },
{ chatType = "YELL", display = YELL },
{ chatType = "PARTY", display = PARTY },
{ chatType = "RAID", display = RAID },
{ chatType = "RAID_WARNING", display = RAID_WARNING },
{ chatType = "INSTANCE_CHAT", display = INSTANCE_CHAT },
{ chatType = "GUILD", display = GUILD },
{ chatType = "OFFICER", display = OFFICER },
}
end
function OutputSelectScrollFrameMixin:GetChannelOutputs()
-- Union the the player's currently joined channels with the message's existing channel outputs
local channelOutputs = self:ConvertChannelList(GetChannelList())
self:EnsureMessageOutputs()
for _, output in ipairs(self.message.outputs) do
if output.chatType == "CHANNEL" then
-- check if output exists in channelOutputs
if not self:IndexOfMessageOutput(channelOutputs, output) then
table.insert(channelOutputs, output)
end
end
end
return channelOutputs
end
function OutputSelectScrollFrameMixin:ConvertChannelList(...)
local channelOutputs = {}
for i=1, select("#", ...), 3 do
--local channelID = select(i, ...);
local channel = select(i+1, ...);
--local disabled = select(i+2, ...);
table.insert(channelOutputs, { chatType = "CHANNEL", channel = channel })
end
return channelOutputs
end
function OutputSelectScrollFrameMixin:AddMessageOutput(output)
self:EnsureMessageOutputs()
if not self:IndexOfMessageOutput(self.message.outputs, output) then
table.insert(self.message.outputs, output)
self:UpdateOutputs()
end
end
function OutputSelectScrollFrameMixin:RemoveMessageOutput(output)
self:EnsureMessageOutputs()
local index = self:IndexOfMessageOutput(self.message.outputs, output)
if index then
self.message.outputs[index] = nil
self:UpdateOutputs()
end
end
function OutputSelectScrollFrameMixin:IndexOfMessageOutput(outputs, output)
local index = nil
if output then
index, _ = FindInTableIf(outputs, function(other)
return output.chatType == other.chatType and
(output.chatType ~= "CHANNEL" or (output.channel and output.channel == other.channel))
end)
end
return index
end
function OutputSelectScrollFrameMixin:EnsureMessageOutputs()
local ensured = false
if self.message then
if not self.message.outputs then
self.message.outputs = {}
end
ensured = true
end
return ensured
end
function OutputSelectScrollFrameMixin:OnShow()
FrameUtil.RegisterFrameForEvents(self, dynamicEvents);
end
function OutputSelectScrollFrameMixin:OnHide()
FrameUtil.UnregisterFrameForEvents(self, dynamicEvents);
end