-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatApply.lua
More file actions
180 lines (147 loc) · 5.95 KB
/
Copy pathChatApply.lua
File metadata and controls
180 lines (147 loc) · 5.95 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
local ADDON_NAME, Addon = ...
local Apply = {}
Addon.ChatApply = Apply
local warnedClassicLocale
local function ConfigureGeneralFrame()
local chatFrame1 = _G.ChatFrame1
Addon.util.CallFrame(chatFrame1, "RemoveChannel", "Trade")
Addon.util.CallFrame(chatFrame1, "RemoveChannel", "Services")
for _, groupName in ipairs(Addon.GENERAL_REMOVALS) do
Addon.util.CallFrame(chatFrame1, "RemoveMessageGroup", groupName)
end
end
local function ConfigureLootFrame(frame, tabs)
if not frame then
return
end
local lootTab = tabs.lootTrade
Addon.util.CallFrame(frame, "RemoveAllMessageGroups")
Addon.util.CallFrame(frame, "RemoveAllChannels")
Addon.util.CallFrame(frame, "AddMessageGroup", "CHANNEL")
for _, channelName in ipairs(lootTab.channels or {}) do
Addon.util.CallFrame(frame, "AddChannel", channelName)
end
for _, groupName in ipairs(lootTab.messageGroups or {}) do
Addon.util.CallFrame(frame, "AddMessageGroup", groupName)
end
end
local function ConfigureClassicLFGChannels(frame, channels)
if not frame then
return
end
if GetLocale() ~= "enUS" then
if not warnedClassicLocale then
warnedClassicLocale = true
print("|cffffff00[CalmChat] Classic LFG auto-join currently supports enUS channel names only.|r")
end
Addon.util.CallFrame(frame, "AddMessageGroup", "CHANNEL")
for _, channelName in ipairs(channels) do
Addon.util.CallFrame(frame, "AddChannel", channelName)
end
return
end
Addon.util.CallFrame(frame, "AddMessageGroup", "CHANNEL")
for _, channelName in ipairs(channels) do
local _, joinedName = Addon.util.CallGlobal("JoinPermanentChannel", channelName, nil, frame:GetID(), 1)
Addon.util.CallFrame(frame, "AddChannel", joinedName or channelName)
end
end
local function ConfigureSecondaryFrame(frame, plan)
if not frame or not plan.secondary.enabled then
return
end
Addon.util.CallFrame(frame, "RemoveAllMessageGroups")
Addon.util.CallFrame(frame, "RemoveAllChannels")
if plan.secondary.kind == "services" then
Addon.util.CallFrame(frame, "AddMessageGroup", "CHANNEL")
for _, channelName in ipairs(plan.secondary.channels or {}) do
Addon.util.CallFrame(frame, "AddChannel", channelName)
end
elseif plan.secondary.kind == "lfg" then
if plan.secondary.autoJoin then
ConfigureClassicLFGChannels(frame, plan.secondary.channels or {})
else
Addon.util.CallFrame(frame, "AddMessageGroup", "CHANNEL")
for _, channelName in ipairs(plan.secondary.channels or {}) do
Addon.util.CallFrame(frame, "AddChannel", channelName)
end
end
end
if plan.capabilities.isRetail then
Addon.util.CallFrame(_G.ChatFrame1, "AddMessageGroup", "PING")
end
end
local function ConfigureFrameTitles(lootFrame, secondaryFrame, plan)
local tabs = plan.tabs
local chatFontSize = tonumber(plan.settings.chatFontSize) or Addon.DEFAULTS.settings.chatFontSize
if chatFontSize < Addon.CHAT_FONT_SIZE_MIN then
chatFontSize = Addon.CHAT_FONT_SIZE_MIN
elseif chatFontSize > Addon.CHAT_FONT_SIZE_MAX then
chatFontSize = Addon.CHAT_FONT_SIZE_MAX
end
for _, name in ipairs(_G.CHAT_FRAMES or {}) do
local frame = _G[name]
if frame then
local id = frame:GetID()
Addon.util.CallGlobal("FCF_SetChatWindowFontSize", nil, frame, chatFontSize)
if frame == lootFrame then
Addon.util.CallGlobal("FCF_SetWindowName", frame, tabs.lootTrade.name)
elseif frame == secondaryFrame and plan.secondary.enabled then
Addon.util.CallGlobal("FCF_SetWindowName", frame, plan.secondary.name)
elseif id == 1 then
Addon.util.CallGlobal("FCF_SetWindowName", frame, tabs.general.name)
if _G.LeftChatToggleButton then
frame:ClearAllPoints()
frame:SetPoint("BOTTOMLEFT", _G.LeftChatToggleButton, "TOPLEFT", 1, 3)
end
elseif id == 2 then
Addon.util.CallGlobal("FCF_SetWindowName", frame, tabs.log.name)
elseif plan.capabilities.isRetail and id == 3 and plan.settings.keepRetailVoiceFrame then
Addon.util.CallGlobal("VoiceTranscriptionFrame_UpdateVisibility", frame)
Addon.util.CallGlobal("VoiceTranscriptionFrame_UpdateVoiceTab", frame)
Addon.util.CallGlobal("VoiceTranscriptionFrame_UpdateEditBox", frame)
end
end
end
end
local function SelectGeneralWindow()
if type(FCFDock_SelectWindow) == "function" and _G.GENERAL_CHAT_DOCK and _G.ChatFrame1 then
FCFDock_SelectWindow(_G.GENERAL_CHAT_DOCK, _G.ChatFrame1)
end
end
local function ApplyCVars()
for _, cvar in ipairs(Addon.CVARS) do
Addon.util.SetCVarIfAvailable(cvar[1], cvar[2])
end
end
local function CreateFrames(plan)
local tabs = plan.tabs
if plan.settings.resetBeforeApply then
FCF_ResetChatWindows()
end
local lootFrame
if tabs.lootTrade.enabled then
lootFrame = FCF_OpenNewWindow(tabs.lootTrade.name) or _G.ChatFrame4
end
local secondaryFrame
if plan.secondary.enabled then
secondaryFrame = FCF_OpenNewWindow(plan.secondary.name) or _G.ChatFrame5
end
return lootFrame, secondaryFrame
end
function Apply.Execute(plan)
if type(plan) ~= "table" then
return false, "Invalid apply plan"
end
if not plan.capabilities.hasChatAPI then
return false, "Blizzard chat window APIs are unavailable."
end
ApplyCVars()
local lootFrame, secondaryFrame = CreateFrames(plan)
ConfigureFrameTitles(lootFrame, secondaryFrame, plan)
ConfigureGeneralFrame()
ConfigureLootFrame(lootFrame, plan.tabs)
ConfigureSecondaryFrame(secondaryFrame, plan)
SelectGeneralWindow()
return true
end