-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathBNConversations.lua
302 lines (254 loc) · 10 KB
/
BNConversations.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
BN_CONVERSATION_INVITE_HEIGHT = 22;
BN_CONVERSATION_INVITE_NUM_DISPLAYED = 7;
BN_CONVERSATION_MAX_CHANNEL_MEMBERS = BNGetMaxPlayersInConversation();
function BNConversationInviteDialog_OnLoad(self)
self:RegisterEvent("BN_CHAT_CHANNEL_CREATE_SUCCEEDED");
self:RegisterEvent("BN_CHAT_CHANNEL_CREATE_FAILED");
self:RegisterEvent("BN_FRIEND_ACCOUNT_ONLINE");
self:RegisterEvent("BN_FRIEND_ACCOUNT_OFFLINE");
-- special popup dialog settings
self.hideOnEscape = true;
self.exclusive = true;
BNConversationInvite_Reset();
end
function BNConversationInviteDialog_OnEvent(self, event, ...)
if ( event == "BN_CHAT_CHANNEL_CREATE_SUCCEEDED" ) then
local conversationID = ...;
BNConversationInvite_UnlockActions();
if ( PENDING_BN_WHISPER_TO_CONVERSATION_FRAME and
PENDING_BN_WHISPER_TO_CONVERSATION_FRAME.inUse ) then
FCF_RestoreChatsToFrame(DEFAULT_CHAT_FRAME, PENDING_BN_WHISPER_TO_CONVERSATION_FRAME);
FCF_SetTemporaryWindowType(PENDING_BN_WHISPER_TO_CONVERSATION_FRAME, "BN_CONVERSATION", conversationID);
end
elseif ( event == "BN_CHAT_CHANNEL_CREATE_FAILED" ) then
BNConversationInvite_UnlockActions();
elseif ( event == "BN_FRIEND_ACCOUNT_ONLINE" and self:IsShown() ) then
BNConversationInvite_Update();
elseif ( event == "BN_FRIEND_ACCOUNT_OFFLINE" and self:IsShown() ) then
local presenceID = ...;
BNConversationInvite_Unlock(presenceID);
BNConversationInvite_Deselect(presenceID);
end
end
function BNConversationInviteListCheckButton_OnClick(self, button)
local parent = self:GetParent();
if ( self:GetChecked() ) then
PlaySound("igMainMenuOptionCheckBoxOn");
BNConversationInvite_Select(parent.id);
else
PlaySound("igMainMenuOptionCheckBoxOff");
BNConversationInvite_Deselect(parent.id);
end
end
function BNConversationInvite_SelectPlayers(conversationID)
BNConversationInvite_SetMode("invite", conversationID);
BNConversationInvite_Reset();
for i=1, BNGetNumConversationMembers(conversationID) do
local accountID, toonID, name = BNGetConversationMemberInfo(conversationID, i);
BNConversationInvite_Lock(accountID);
end
StaticPopupSpecial_Show(BNConversationInviteDialog);
end
function BNConversationInvite_NewConversation(selected1, selected2)
BNConversationInvite_SetMode("create");
BNConversationInvite_Reset();
if ( selected1 ) then
BNConversationInvite_Select(selected1);
BNConversationInvite_Lock(selected1);
end
if ( selected2 ) then
BNConversationInvite_Select(selected2);
BNConversationInvite_Lock(selected2);
end
StaticPopupSpecial_Show(BNConversationInviteDialog);
end
function BNConversationInvite_Reset()
BNConversationInviteDialog.inviteTargets = {}; --Probably better to eat the gc than table.wipe in this case.
BNConversationInviteDialog.lockedTargets = {};
BNConversationInviteDialog.triggeringChatFrame = nil;
end
function BNConversationInvite_SetMode(mode, target)
local frame = BNConversationInviteDialog;
frame.mode = mode;
frame.target = target;
if ( mode == "create" ) then
frame.instructionText:SetText(NEW_CONVERSATION_INSTRUCTIONS);
BNConversationInvite_SetMinMaxInvites(2, 2);
elseif ( mode == "invite" ) then
local maxInvites = BN_CONVERSATION_MAX_CHANNEL_MEMBERS - BNGetNumConversationMembers(target);
frame.instructionText:SetFormattedText(INVITE_CONVERSATION_INSTRUCTIONS, maxInvites);
BNConversationInvite_SetMinMaxInvites(1, maxInvites);
else
error("Unhandled invite type: "..tostring(mode));
end
end
function BNConversationInvite_SetMinMaxInvites(minInvites, maxInvites)
local frame = BNConversationInviteDialog;
frame.minInvites = minInvites;
frame.maxInvites = maxInvites;
end
function BNConversationInviteDialogInviteButton_OnClick(self, button)
local inviteTargets = BNConversationInviteDialog.inviteTargets;
if ( BNConversationInviteDialog.mode == "create" ) then
if ( BNCreateConversation(inviteTargets[1], inviteTargets[2]) ) then
BNConversationInvite_LockActions();
PENDING_BN_WHISPER_TO_CONVERSATION_FRAME = BNConversationInviteDialog.triggeringChatFrame;
end
elseif ( BNConversationInviteDialog.mode == "invite" ) then
for _, player in pairs(inviteTargets) do
BNInviteToConversation(BNConversationInviteDialog.target, player);
end
else
error("Unhandled invite type: "..tostring(BNConversationInviteDialog.mode))
end
StaticPopupSpecial_Hide(BNConversationInviteDialog);
end
function BNConversationInvite_LockActions()
BNConversationInviteDialog.actionsLocked = true;
BNConversationInvite_UpdateInviteButtonState();
end
function BNConversationInvite_UnlockActions()
BNConversationInviteDialog.actionsLocked = false;
BNConversationInvite_UpdateInviteButtonState();
end
function BNConversationInvite_UpdateInviteButtonState()
local dialog = BNConversationInviteDialog;
local button = BNConversationInviteDialogInviteButton;
if ( dialog.actionsLocked or #dialog.inviteTargets < dialog.minInvites ) then
button:Disable();
else
button:Enable();
end
end
function BNConversationInvite_Select(player)
local inviteTargets = BNConversationInviteDialog.inviteTargets;
if ( not tContains(inviteTargets, player) ) then
tinsert(inviteTargets, player);
end
BNConversationInvite_Update();
end
function BNConversationInvite_Deselect(player)
local inviteTargets = BNConversationInviteDialog.inviteTargets;
tDeleteItem(inviteTargets, player);
BNConversationInvite_Update();
end
function BNConversationInvite_Lock(player)
local lockedTargets = BNConversationInviteDialog.lockedTargets;
if ( not tContains(lockedTargets, player) ) then
tinsert(lockedTargets, player);
end
BNConversationInvite_Update();
end
function BNConversationInvite_Unlock(player)
local lockedTargets = BNConversationInviteDialog.lockedTargets;
tDeleteItem(lockedTargets, player);
BNConversationInvite_Update();
end
function BNConversationInvite_Update()
local _, numBNetOnline = BNGetNumFriends();
local offset = FauxScrollFrame_GetOffset(BNConversationInviteDialogListScrollFrame);
for i=1, BN_CONVERSATION_INVITE_NUM_DISPLAYED do
local index = i + offset;
local frame = _G["BNConversationInviteDialogListFriend"..i];
if ( index <= numBNetOnline ) then
local friendIndex = index;
local presenceID, givenName, surname = BNGetFriendInfo(friendIndex);
frame.name:SetFormattedText(BATTLENET_NAME_FORMAT, givenName, surname);
frame.id = presenceID;
frame:Show();
else
frame:Hide();
end
frame.checkButton:SetChecked(tContains(BNConversationInviteDialog.inviteTargets, frame.id));
if ( tContains(BNConversationInviteDialog.lockedTargets, frame.id) or
(#BNConversationInviteDialog.inviteTargets >= BNConversationInviteDialog.maxInvites and --Disable everything if we've checked the max amount
not frame.checkButton:GetChecked() ) ) then --Never disable a button that is already checked) then
frame.checkButton:Disable();
frame.name:SetFontObject("GameFontDisable");
else
frame.checkButton:Enable();
frame.name:SetFontObject("GameFontHighlight");
end
end
BNConversationInvite_UpdateInviteButtonState();
FauxScrollFrame_Update(BNConversationInviteDialogListScrollFrame, numBNetOnline, BN_CONVERSATION_INVITE_NUM_DISPLAYED, BN_CONVERSATION_INVITE_HEIGHT);
end
----Member list functions.
function BNConversationButton_OnLoad(self)
self.chatFrame = _G["ChatFrame"..self:GetID()];
self.chatFrame.conversationButton = self;
BNConversationButton_UpdateAttachmentPoint(self);
BNConversationButton_UpdateTarget(self);
self:RegisterEvent("BN_CHAT_CHANNEL_LEFT");
self:RegisterEvent("BN_CHAT_CHANNEL_JOINED");
end
function BNConversationButton_OnClick(self, button)
if ( self.chatType == "BN_CONVERSATION" ) then
local frame = BNConversationInviteDialog;
if ( frame:IsShown() and frame.target == self.chatTarget ) then
StaticPopupSpecial_Hide(frame)
else
BNConversationInvite_SelectPlayers(self.chatTarget);
end
else
BNConversationInvite_NewConversation(BNet_GetPresenceID(self.chatTarget));
BNConversationInviteDialog.triggeringChatFrame = self.chatFrame;
end
end
function BNConversationButton_OnEvent(self, event, ...)
local arg1 = ...;
if ( event == "BN_CHAT_CHANNEL_LEFT" and arg1 == self.chatTarget ) then
BNConversationButton_UpdateEnabledState(self);
elseif ( event == "BN_CHAT_CHANNEL_JOINED" and arg1 == self.chatTarget ) then
BNConversationButton_UpdateEnabledState(self);
end
end
function BNConversationButton_UpdateEnabledState(self)
if ( self.chatType ~= "BN_CONVERSATION" or BNGetConversationInfo(self.chatTarget) ) then
self:Enable();
else
self:Disable();
end
end
function BNConversationButton_OnEnter(self, motion)
if ( self.chatType == "BN_CONVERSATION" ) then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
BNConversation_DisplayConversationTooltip(self.chatTarget);
GameTooltip:AddLine(" ");
GameTooltip:AddLine(CLICK_TO_INVITE_TO_CONVERSATION, nil, nil, nil, true);
GameTooltip:Show();
else
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:AddLine(CLICK_TO_START_CONVERSATION, nil, nil, nil, true);
GameTooltip:Show();
end
end
function BNConversation_DisplayConversationTooltip(conversationID)
local info = ChatTypeInfo["BN_CONVERSATION"];
GameTooltip:SetText(format(CONVERSATION_NAME, conversationID + MAX_WOW_CHAT_CHANNELS), info.r, info.g, info.b);
for i=1, BNGetNumConversationMembers(conversationID) do
local accountID, toonID, name = BNGetConversationMemberInfo(conversationID, i);
GameTooltip:AddLine(name, FRIENDS_BNET_NAME_COLOR.r, FRIENDS_BNET_NAME_COLOR.g, FRIENDS_BNET_NAME_COLOR.b);
end
GameTooltip:Show();
end
function BNConversationButton_OnLeave(self, motion)
if ( GameTooltip:GetOwner() == self ) then
GameTooltip:Hide();
end
end
function BNConversationButton_UpdateAttachmentPoint(self)
local chatFrame = self.chatFrame;
if ( chatFrame.isDocked ) then
self:SetPoint("BOTTOM", chatFrame.buttonFrame.upButton, "TOP", 0, 0);
else
self:SetPoint("BOTTOM", chatFrame.buttonFrame.minimizeButton, "TOP", 0, 0);
end
end
function BNConversationButton_UpdateTarget(self)
local chatFrame = self.chatFrame;
local chatTarget = tonumber(chatFrame.chatTarget) or chatFrame.chatTarget;
self.chatType = chatFrame.chatType;
self.chatTarget = chatTarget;
BNConversationButton_UpdateEnabledState(self);
end