vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | GroupCalendar_cTitle = string.format(GroupCalendar_cTitle, gGroupCalendar_VersionString); |
2 | |||
3 | gGroupCalendar_Settings = |
||
4 | { |
||
5 | Debug = false, |
||
6 | ShowEventsInLocalTime = false, |
||
7 | }; |
||
8 | |||
9 | gGroupCalendar_PlayerSettings = nil; |
||
10 | gGroupCalendar_RealmSettings = nil; |
||
11 | |||
12 | gGroupCalendar_PlayerName = nil; |
||
13 | gGroupCalendar_PlayerGuild = nil; |
||
14 | gGroupCalendar_PlayerLevel = nil; |
||
15 | gGroupCalendar_PlayerFactionGroup = nil; |
||
16 | gGroupCalendar_PlayerGuildRank = nil; |
||
17 | gGroupCalendar_RealmName = GetRealmName(); |
||
18 | gGroupCalendar_Initialized = false; |
||
19 | |||
20 | gGroupCalendar_ServerTimeZoneOffset = 0; -- Offset that, when added to the server time yields the local time |
||
21 | |||
22 | gGroupCalendar_ActiveDialog = nil; |
||
23 | |||
24 | gGroupCalendar_CurrentPanel = 1; |
||
25 | |||
26 | gGroupCalendar_PanelFrames = |
||
27 | { |
||
28 | "GroupCalendarCalendarFrame", |
||
29 | "GroupCalendarChannelFrame", |
||
30 | "GroupCalendarTrustFrame", |
||
31 | "GroupCalendarAboutFrame", |
||
32 | }; |
||
33 | |||
34 | function GroupCalendar_OnLoad() |
||
35 | SlashCmdList["CALENDAR"] = GroupCalendar_ExecuteCommand; |
||
36 | |||
37 | SLASH_CALENDAR1 = "/calendar"; |
||
38 | |||
39 | tinsert(UISpecialFrames, "GroupCalendarFrame"); |
||
40 | |||
41 | UIPanelWindows["GroupCalendarFrame"] = {area = "left", pushable = 5, whileDead = 1}; |
||
42 | |||
43 | gGroupCalendar_PlayerName = UnitName("player"); |
||
44 | gGroupCalendar_PlayerLevel = UnitLevel("player"); |
||
45 | |||
46 | -- Register events |
||
47 | |||
48 | GroupCalendar_RegisterEvent(this, "VARIABLES_LOADED", GroupCalendar_VariablesLoaded); |
||
49 | GroupCalendar_RegisterEvent(this, "PLAYER_ENTERING_WORLD", GroupCalendar_PlayerEnteringWorld); |
||
50 | |||
51 | -- For updating auto-config settings and guild trust |
||
52 | -- values |
||
53 | |||
54 | GroupCalendar_RegisterEvent(this, "GUILD_ROSTER_UPDATE", GroupCalendar_GuildRosterUpdate); |
||
55 | GroupCalendar_RegisterEvent(this, "PLAYER_GUILD_UPDATE", GroupCalendar_PlayerGuildUpdate); |
||
56 | |||
57 | -- For updating the enabled events when the players |
||
58 | -- level changes |
||
59 | |||
60 | GroupCalendar_RegisterEvent(this, "PLAYER_LEVEL_UP", GroupCalendar_PlayerLevelUp); |
||
61 | |||
62 | -- For monitoring the status of the chat channel |
||
63 | |||
64 | GroupCalendar_RegisterEvent(this, "CHAT_MSG_SYSTEM", GroupCalendar_ChatMsgSystem); |
||
65 | GroupCalendar_RegisterEvent(this, "CHAT_MSG_CHANNEL_NOTICE", GroupCalendar_ChatMsgChannelNotice); |
||
66 | GroupCalendar_RegisterEvent(this, "CHAT_MSG_WHISPER", GroupCalendar_ChatMsgWhisper); |
||
67 | |||
68 | -- For suspending/resuming the chat channel during logout |
||
69 | |||
70 | GroupCalendar_RegisterEvent(this, "PLAYER_CAMPING", CalendarNetwork_SuspendChannel); |
||
71 | GroupCalendar_RegisterEvent(this, "PLAYER_QUITING", CalendarNetwork_SuspendChannel); |
||
72 | GroupCalendar_RegisterEvent(this, "LOGOUT_CANCEL", CalendarNetwork_ResumeChannel); |
||
73 | |||
74 | -- For monitoring tradeskill cooldowns |
||
75 | |||
76 | GroupCalendar_RegisterEvent(this, "TRADE_SKILL_UPDATE", EventDatabase_UpdateCurrentTradeskillCooldown); |
||
77 | GroupCalendar_RegisterEvent(this, "TRADE_SKILL_SHOW", EventDatabase_UpdateCurrentTradeskillCooldown); |
||
78 | GroupCalendar_RegisterEvent(this, "BAG_UPDATE_COOLDOWN", GroupCalendar_CheckItemCooldowns); |
||
79 | GroupCalendar_RegisterEvent(this, "BAG_UPDATE", GroupCalendar_CheckItemCooldowns); |
||
80 | |||
81 | -- For managing group invites |
||
82 | |||
83 | GroupCalendar_RegisterEvent(this, "PARTY_MEMBERS_CHANGED", CalendarGroupInvites_PartyMembersChanged); |
||
84 | GroupCalendar_RegisterEvent(this, "RAID_ROSTER_UPDATE", CalendarGroupInvites_PartyMembersChanged); |
||
85 | GroupCalendar_RegisterEvent(this, "PARTY_LOOT_METHOD_CHANGED", CalendarGroupInvites_PartyLootMethodChanged); |
||
86 | |||
87 | -- For dragging the window |
||
88 | |||
89 | this:RegisterForDrag("LeftButton"); |
||
90 | |||
91 | -- Tabs |
||
92 | |||
93 | PanelTemplates_SetNumTabs(this, table.getn(gGroupCalendar_PanelFrames)); |
||
94 | GroupCalendarFrame.selectedTab = gGroupCalendar_CurrentPanel; |
||
95 | PanelTemplates_UpdateTabs(this); |
||
96 | |||
97 | -- Done initializing |
||
98 | |||
99 | if DEFAULT_CHAT_FRAME then |
||
100 | DEFAULT_CHAT_FRAME:AddMessage(GroupCalendar_cLoadMessage, 0.8, 0.8, 0.2); |
||
101 | end |
||
102 | end |
||
103 | |||
104 | function GroupCalendar_RegisterEvent(pFrame, pEvent, pHandler) |
||
105 | if not pHandler then |
||
106 | Calendar_ErrorMessage("GroupCalendar: Attemping to install a nil handler for event "..pEvent); |
||
107 | return; |
||
108 | end |
||
109 | |||
110 | if not pFrame.EventHandlers then |
||
111 | pFrame.EventHandlers = {}; |
||
112 | end |
||
113 | |||
114 | pFrame.EventHandlers[pEvent] = pHandler; |
||
115 | pFrame:RegisterEvent(pEvent); |
||
116 | end |
||
117 | |||
118 | function GroupCalendar_UnregisterEvent(pFrame, pEvent) |
||
119 | if pFrame.EventHandlers then |
||
120 | pFrame.EventHandlers[pEvent] = nil; |
||
121 | end |
||
122 | |||
123 | pFrame:UnregisterEvent(pEvent); |
||
124 | end |
||
125 | |||
126 | function GroupCalendar_DispatchEvent(pFrame, pEvent) |
||
127 | if not pFrame.EventHandlers then |
||
128 | return false; |
||
129 | end |
||
130 | |||
131 | local vEventHandler = pFrame.EventHandlers[pEvent]; |
||
132 | |||
133 | if not vEventHandler then |
||
134 | Calendar_ErrorMessage("GroupCalendar: No event handler for "..pEvent); |
||
135 | return false; |
||
136 | end |
||
137 | |||
138 | vEventHandler(pEvent); |
||
139 | return true; |
||
140 | end |
||
141 | |||
142 | function GroupCalendar_VariablesLoaded() |
||
143 | gGroupCalendar_MinimumEventDate = Calendar_GetCurrentLocalDate() - gGroupCalendar_MaximumEventAge; |
||
144 | |||
145 | EventDatabase_SetUserName(gGroupCalendar_PlayerName); |
||
146 | EventDatabase_PlayerLevelChanged(gGroupCalendar_PlayerLevel); |
||
147 | CalendarNetwork_CheckPlayerGuild(); |
||
148 | |||
149 | EventDatabase_Initialize(); |
||
150 | |||
151 | CalendarNetwork_CalendarLoaded(); |
||
152 | end |
||
153 | |||
154 | function GroupCalendar_OnShow() |
||
155 | PlaySound("igCharacterInfoOpen"); |
||
156 | |||
157 | local vYear, vMonth, vDay, vHour, vMinute = Calendar_GetCurrentYearMonthDayHourMinute(); |
||
158 | local vMonthStartDate = Calendar_ConvertMDYToDate(vMonth, 1, vYear); |
||
159 | |||
160 | -- Update the guild roster |
||
161 | |||
162 | if IsInGuild() and GetNumGuildMembers() == 0 then |
||
163 | GuildRoster(); |
||
164 | end |
||
165 | |||
166 | Calendar_SetDisplayDate(vMonthStartDate); |
||
167 | Calendar_SetActualDate(vMonthStartDate + vDay - 1); |
||
168 | GroupCalendar_ShowPanel(1); -- Always switch back to the Calendar view when showing the window |
||
169 | |||
170 | GroupCalendarUseServerTime:SetChecked(not gGroupCalendar_Settings.ShowEventsInLocalTime); |
||
171 | end |
||
172 | |||
173 | function GroupCalendar_OnHide() |
||
174 | PlaySound("igCharacterInfoClose"); |
||
175 | CalendarEventEditor_DoneEditing(); |
||
176 | CalendarEventViewer_DoneViewing(); |
||
177 | CalendarEditor_Close(); |
||
178 | end |
||
179 | |||
180 | function GroupCalendar_OnEvent(pEvent) |
||
181 | local vLatencyStartTime; |
||
182 | |||
183 | if gGroupCalendar_Settings.DebugLatency then |
||
184 | vLatencyStartTime = GetTime(); |
||
185 | end |
||
186 | |||
187 | if GroupCalendar_DispatchEvent(this, pEvent) then |
||
188 | |||
189 | -- Handled |
||
190 | |||
191 | elseif pEvent == "CHAT_MSG_SYSTEM" then |
||
192 | CalendarNetwork_SystemMessage(arg1); |
||
193 | CalendarGroupInvites_SystemMessage(arg1); |
||
194 | |||
195 | elseif pEvent == "GUILD_ROSTER_UPDATE" then |
||
196 | -- Ignore the update if we're not initialized yet |
||
197 | |||
198 | if not gGroupCalendar_Initialized then |
||
199 | return; |
||
200 | end |
||
201 | |||
202 | CalendarNetwork_GuildRosterChanged(); |
||
203 | CalendarGroupInvites_GuildRosterChanged(); |
||
204 | |||
205 | elseif pEvent == "PLAYER_GUILD_UPDATE" then |
||
206 | CalendarNetwork_CheckPlayerGuild(); |
||
207 | |||
208 | -- Ignore the update if we're not initialized yet |
||
209 | |||
210 | if not gGroupCalendar_Initialized then |
||
211 | return; |
||
212 | end |
||
213 | |||
214 | GroupCalendar_UpdateEnabledControls(); |
||
215 | |||
216 | elseif pEvent == "PLAYER_LEVEL_UP" then |
||
217 | gGroupCalendar_PlayerLevel = tonumber(arg1); |
||
218 | EventDatabase_PlayerLevelChanged(gGroupCalendar_PlayerLevel); |
||
219 | GroupCalendar_MajorDatabaseChange(nil); |
||
220 | end |
||
221 | |||
222 | -- |
||
223 | |||
224 | if gGroupCalendar_Settings.DebugLatency then |
||
225 | local vElapsed = GetTime() - vLatencyStartTime; |
||
226 | |||
227 | if vElapsed > 0.1 then |
||
228 | Calendar_DebugMessage("Event "..pEvent.." took "..vElapsed.."s to execute"); |
||
229 | end |
||
230 | end |
||
231 | end |
||
232 | |||
233 | function GroupCalendar_PlayerEnteringWorld(pEvent) |
||
234 | Calendar_InitDebugging(); |
||
235 | |||
236 | gGroupCalendar_PlayerSettings = GroupCalendar_GetPlayerSettings(gGroupCalendar_PlayerName, GetRealmName()); |
||
237 | gGroupCalendar_RealmSettings = GroupCalendar_GetRealmSettings(GetRealmName()); |
||
238 | |||
239 | gGroupCalendar_PlayerLevel = UnitLevel("player"); |
||
240 | gGroupCalendar_PlayerFactionGroup = UnitFactionGroup("player"); |
||
241 | gGroupCalendar_PlayerSettings = GroupCalendar_GetPlayerSettings(gGroupCalendar_PlayerName, GetRealmName()); |
||
242 | gGroupCalendar_RealmSettings = GroupCalendar_GetRealmSettings(GetRealmName()); |
||
243 | EventDatabase_PlayerLevelChanged(gGroupCalendar_PlayerLevel); |
||
244 | GroupCalendar_CalculateTimeZoneOffset(); |
||
245 | GroupCalendar_MajorDatabaseChange(nil); |
||
246 | end |
||
247 | |||
248 | function GroupCalendar_ChatMsgChannel(pEvent) |
||
249 | if arg9 |
||
250 | and strlower(arg9) == gGroupCalendar_Channel.NameLower |
||
251 | and arg1 |
||
252 | and type(arg1) == "string" |
||
253 | then |
||
254 | if arg2 == gGroupCalendar_PlayerName then |
||
255 | -- Ignore messages from ourselves |
||
256 | |||
257 | if not gGroupCalendar_Settings.Debug then |
||
258 | return; |
||
259 | end |
||
260 | |||
261 | -- Special debugging case: allow self-send of messages starting with '!' |
||
262 | |||
263 | if strsub(arg1, 1, 1) ~= "!" then |
||
264 | return; |
||
265 | end |
||
266 | |||
267 | arg1 = strsub(arg1, 2); |
||
268 | end |
||
269 | |||
270 | -- Clean up drunkeness |
||
271 | |||
272 | if strsub(arg1, -8) == " ...hic!" then |
||
273 | arg1 = strsub(arg1, 1, -9); |
||
274 | end |
||
275 | |||
276 | arg1 = Calendar_UnescapeChatString(arg1); |
||
277 | |||
278 | -- |
||
279 | |||
280 | CalendarNetwork_ChannelMessageReceived(arg2, arg1); |
||
281 | end |
||
282 | end |
||
283 | |||
284 | function GroupCalendar_ChatMsgChannelNotice(pEvent) |
||
285 | local vChannelMessage = arg1; |
||
286 | local vChannelName = arg4; |
||
287 | local vChannelID = arg8; |
||
288 | local vActualChannelName = arg9; |
||
289 | |||
290 | CalendarNetwork_ChannelNotice(vChannelMessage, vChannelName, vChannelID, vActualChannelName); |
||
291 | end |
||
292 | |||
293 | function GroupCalendar_ChatMsgWhisper(pEvent) |
||
294 | CalendarWhisperLog_AddWhisper(arg2, arg1); |
||
295 | end |
||
296 | |||
297 | function GroupCalendar_ChatMsgSystem(pEvent) |
||
298 | CalendarNetwork_SystemMessage(arg1); |
||
299 | CalendarGroupInvites_SystemMessage(arg1); |
||
300 | end |
||
301 | |||
302 | function GroupCalendar_GuildRosterUpdate(pEvent) |
||
303 | -- Ignore the update if we're not initialized yet |
||
304 | |||
305 | if not gGroupCalendar_Initialized then |
||
306 | return; |
||
307 | end |
||
308 | |||
309 | CalendarNetwork_GuildRosterChanged(); |
||
310 | CalendarGroupInvites_GuildRosterChanged(); |
||
311 | end |
||
312 | |||
313 | function GroupCalendar_PlayerGuildUpdate(pEvent) |
||
314 | CalendarNetwork_CheckPlayerGuild(); |
||
315 | |||
316 | -- Ignore the update if we're not initialized yet |
||
317 | |||
318 | if not gGroupCalendar_Initialized then |
||
319 | return; |
||
320 | end |
||
321 | |||
322 | GroupCalendar_UpdateEnabledControls(); |
||
323 | end |
||
324 | |||
325 | function GroupCalendar_PlayerLevelUp(pEvent) |
||
326 | gGroupCalendar_PlayerLevel = tonumber(arg1); |
||
327 | EventDatabase_PlayerLevelChanged(gGroupCalendar_PlayerLevel); |
||
328 | GroupCalendar_MajorDatabaseChange(nil); |
||
329 | end |
||
330 | |||
331 | GroupCalendar_cCooldownItemInfo = |
||
332 | { |
||
333 | [15846] = {EventID = "Leatherworking"}, -- Salt Shaker |
||
334 | [17716] = {EventID = "Snowmaster"}, -- Snowmaster 9000 |
||
335 | }; |
||
336 | |||
337 | function GroupCalendar_CheckItemCooldowns() |
||
338 | for vBagIndex = 0, NUM_BAG_SLOTS do |
||
339 | local vNumBagSlots = GetContainerNumSlots(vBagIndex); |
||
340 | |||
341 | for vBagSlotIndex = 1, vNumBagSlots do |
||
342 | local vItemLink = GetContainerItemLink(vBagIndex, vBagSlotIndex); |
||
343 | |||
344 | if vItemLink then |
||
345 | local vStartIndex, vEndIndex, vLinkColor, vItemCode, vItemEnchantCode, vItemSubCode, vUnknownCode, vItemName = strfind(vItemLink, "|(%x+)|Hitem:(%d+):(%d+):(%d+):(%d+)|h%[([^%]]+)%]|h|r"); |
||
346 | |||
347 | if vStartIndex then |
||
348 | vItemCode = tonumber(vItemCode); |
||
349 | |||
350 | local vCooldownItemInfo = GroupCalendar_cCooldownItemInfo[vItemCode]; |
||
351 | |||
352 | if vCooldownItemInfo then |
||
353 | local vStart, vDuration, vEnable = GetContainerItemCooldown(vBagIndex, vBagSlotIndex); |
||
354 | |||
355 | -- local texture, itemCount, locked, quality, readable = GetContainerItemInfo(vBagIndex, vBagSlotIndex); |
||
356 | -- Calendar_TestMessage(vItemName..": "..texture); |
||
357 | |||
358 | if vEnable > 0 then |
||
359 | vRemainingTime = vDuration - (GetTime() - vStart); |
||
360 | |||
361 | if vRemainingTime > 0 then |
||
362 | EventDatabase_ScheduleTradeskillCooldownEvent(gGroupCalendar_UserDatabase, vCooldownItemInfo.EventID, vRemainingTime); |
||
363 | end |
||
364 | end |
||
365 | end |
||
366 | end |
||
367 | end |
||
368 | end |
||
369 | end |
||
370 | end |
||
371 | |||
372 | function GroupCalendar_UpdateEnabledControls() |
||
373 | if GroupCalendarFrame.selectedTab == 1 then |
||
374 | -- Update the calendar display |
||
375 | |||
376 | elseif GroupCalendarFrame.selectedTab == 2 then |
||
377 | -- Update the channel frame |
||
378 | |||
379 | Calendar_SetCheckButtonEnable(GroupCalendarAutoChannelConfig, IsInGuild()); |
||
380 | |||
381 | Calendar_SetEditBoxEnable(GroupCalendarChannelName, GroupCalendarManualChannelConfig:GetChecked()); |
||
382 | Calendar_SetEditBoxEnable(GroupCalendarChannelPassword, GroupCalendarManualChannelConfig:GetChecked()); |
||
383 | |||
384 | if IsInGuild() |
||
385 | and CanEditPublicNote() |
||
386 | and GroupCalendarManualChannelConfig:GetChecked() then |
||
387 | Calendar_SetCheckButtonEnable(GroupCalendarStoreAutoConfig, true); |
||
388 | |||
389 | if GroupCalendarStoreAutoConfig:GetChecked() then |
||
390 | Calendar_SetEditBoxEnable(GroupCalendarAutoConfigPlayer, true); |
||
391 | else |
||
392 | Calendar_SetEditBoxEnable(GroupCalendarAutoConfigPlayer, false); |
||
393 | end |
||
394 | else |
||
395 | Calendar_SetCheckButtonEnable(GroupCalendarStoreAutoConfig, false); |
||
396 | Calendar_SetEditBoxEnable(GroupCalendarAutoConfigPlayer, false); |
||
397 | end |
||
398 | |||
399 | Calendar_SetButtonEnable(GroupCalendarApplyChannelButton, GroupCalendar_ChannelPanelHasChanges()); |
||
400 | |||
401 | elseif GroupCalendarFrame.selectedTab == 3 then |
||
402 | -- Update the trust frame |
||
403 | |||
404 | if gGroupCalendar_PlayerSettings.Channel.AutoConfig then |
||
405 | Calendar_SetDropDownEnable(GroupCalendarTrustGroup, false); |
||
406 | Calendar_SetDropDownEnable(GroupCalendarTrustMinRank, false); |
||
407 | else |
||
408 | GroupCalendar_SaveTrustGroup(); |
||
409 | |||
410 | Calendar_SetDropDownEnable(GroupCalendarTrustGroup, true); |
||
411 | Calendar_SetDropDownEnable(GroupCalendarTrustMinRank, UIDropDownMenu_GetSelectedValue(GroupCalendarTrustGroup) == 2); |
||
412 | end |
||
413 | |||
414 | if UIDropDownMenu_GetSelectedValue(GroupCalendarTrustGroup) == 2 then |
||
415 | GroupCalendarTrustMinRank:Show(); |
||
416 | else |
||
417 | GroupCalendarTrustMinRank:Hide(); |
||
418 | end |
||
419 | |||
420 | elseif GroupCalendarFrame.selectedTab == 4 then |
||
421 | -- Update the ignore frame |
||
422 | |||
423 | end |
||
424 | end |
||
425 | |||
426 | function GroupCalendar_SetAutoChannelConfig(pEnableAutoConfig) |
||
427 | GroupCalendarAutoChannelConfig:SetChecked(pEnableAutoConfig); |
||
428 | GroupCalendarManualChannelConfig:SetChecked(not pEnableAutoConfig); |
||
429 | |||
430 | GroupCalendar_UpdateEnabledControls(); |
||
431 | end |
||
432 | |||
433 | function GroupCalendar_EnableAutoConfigPlayer(pEnableStoreAutoConfig) |
||
434 | GroupCalendarStoreAutoConfig:SetChecked(pEnableStoreAutoConfig); |
||
435 | GroupCalendar_UpdateEnabledControls(); |
||
436 | end |
||
437 | |||
438 | function GroupCalendar_SavePanel(pIndex) |
||
439 | if pIndex == 2 then |
||
440 | -- Channel panel |
||
441 | |||
442 | gGroupCalendar_PlayerSettings.Channel.AutoConfig = GroupCalendarAutoChannelConfig:GetChecked() == 1; |
||
443 | |||
444 | if gGroupCalendar_PlayerSettings.Channel.AutoConfig then |
||
445 | gGroupCalendar_PlayerSettings.Channel.Name = nil; |
||
446 | gGroupCalendar_PlayerSettings.Channel.Password = nil; |
||
447 | gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer = nil; |
||
448 | |||
449 | CalendarNetwork_ScheduleAutoConfig(0.5); |
||
450 | |||
451 | GroupCalendar_ShowPanel(pIndex); -- Refresh the controls |
||
452 | else |
||
453 | gGroupCalendar_PlayerSettings.Channel.Name = GroupCalendarChannelName:GetText(); |
||
454 | |||
455 | if gGroupCalendar_PlayerSettings.Channel.Name == "" then |
||
456 | gGroupCalendar_PlayerSettings.Channel.Name = nil; |
||
457 | end |
||
458 | |||
459 | gGroupCalendar_PlayerSettings.Channel.Password = GroupCalendarChannelPassword:GetText(); |
||
460 | |||
461 | if gGroupCalendar_PlayerSettings.Channel.Password == "" then |
||
462 | gGroupCalendar_PlayerSettings.Channel.Password = nil; |
||
463 | end |
||
464 | |||
465 | CalendarNetwork_SetChannel(gGroupCalendar_PlayerSettings.Channel.Name, gGroupCalendar_PlayerSettings.Channel.Password); |
||
466 | |||
467 | if GroupCalendarStoreAutoConfig:GetChecked() then |
||
468 | gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer = GroupCalendarAutoConfigPlayer:GetText(); |
||
469 | CalendarNetwork_SetAutoConfigData(gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer); |
||
470 | elseif gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer then |
||
471 | gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer = nil; |
||
472 | |||
473 | if CanEditPublicNote() then |
||
474 | CalendarNetwork_RemoveAllAutoConfigData(); |
||
475 | end |
||
476 | end |
||
477 | end |
||
478 | elseif pIndex == 3 then |
||
479 | -- Trust panel |
||
480 | |||
481 | if not gGroupCalendar_PlayerSettings.Channel.AutoConfig then |
||
482 | GroupCalendar_SaveTrustGroup(); |
||
483 | end |
||
484 | end |
||
485 | |||
486 | GroupCalendar_UpdateEnabledControls(); |
||
487 | end |
||
488 | |||
489 | function GroupCalendar_ChannelPanelHasChanges() |
||
490 | if (GroupCalendarAutoChannelConfig:GetChecked() == 1) |
||
491 | ~= gGroupCalendar_PlayerSettings.Channel.AutoConfig then |
||
492 | return true; |
||
493 | end |
||
494 | |||
495 | if GroupCalendarManualChannelConfig:GetChecked() then |
||
496 | local vChannelName = gGroupCalendar_PlayerSettings.Channel.Name; |
||
497 | |||
498 | if not vChannelName then |
||
499 | vChannelName = ""; |
||
500 | end |
||
501 | |||
502 | local vChannelPassword = gGroupCalendar_PlayerSettings.Channel.Password; |
||
503 | |||
504 | if not vChannelPassword then |
||
505 | vChannelPassword = ""; |
||
506 | end |
||
507 | |||
508 | if GroupCalendarChannelName:GetText() ~= vChannelName |
||
509 | or GroupCalendarChannelPassword:GetText() ~= vChannelPassword then |
||
510 | return true; |
||
511 | end |
||
512 | end |
||
513 | |||
514 | local vStoreAutoConfigIsEnabled = (not gGroupCalendar_PlayerSettings.Channel.AutoConfig) |
||
515 | and (gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer ~= nil); |
||
516 | |||
517 | if (GroupCalendarStoreAutoConfig:GetChecked() == 1) |
||
518 | ~= vStoreAutoConfigIsEnabled then |
||
519 | return true; |
||
520 | end |
||
521 | |||
522 | if GroupCalendarStoreAutoConfig:GetChecked() |
||
523 | and GroupCalendarAutoConfigPlayer:GetText() ~= gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer then |
||
524 | return true; |
||
525 | end |
||
526 | |||
527 | return false; |
||
528 | end |
||
529 | |||
530 | function GroupCalendar_SaveTrustGroup() |
||
531 | local vTrustGroup = UIDropDownMenu_GetSelectedValue(GroupCalendarTrustGroup); |
||
532 | local vChanged = false; |
||
533 | |||
534 | if vTrustGroup == 1 |
||
535 | and not gGroupCalendar_PlayerSettings.Security.TrustAnyone then |
||
536 | gGroupCalendar_PlayerSettings.Security.TrustAnyone = true; |
||
537 | gGroupCalendar_PlayerSettings.Security.TrustGuildies = false; |
||
538 | vChanged = true; |
||
539 | elseif vTrustGroup == 2 then |
||
540 | if not gGroupCalendar_PlayerSettings.Security.TrustGuildies then |
||
541 | gGroupCalendar_PlayerSettings.Security.TrustAnyone = false; |
||
542 | gGroupCalendar_PlayerSettings.Security.TrustGuildies = true; |
||
543 | vChanged = true; |
||
544 | end |
||
545 | |||
546 | local vMinTrustedRank = UIDropDownMenu_GetSelectedValue(GroupCalendarTrustMinRank); |
||
547 | |||
548 | if not vMinTrustedRank then |
||
549 | vMinTrustedRank = 1; |
||
550 | CalendarDropDown_SetSelectedValue(GroupCalendarTrustMinRank, vMinTrustedRank); |
||
551 | end |
||
552 | |||
553 | if vMinTrustedRank ~= gGroupCalendar_PlayerSettings.Security.MinTrustedRank then |
||
554 | gGroupCalendar_PlayerSettings.Security.MinTrustedRank = vMinTrustedRank; |
||
555 | vChanged = true; |
||
556 | end |
||
557 | elseif vTrustGroup == 3 |
||
558 | and (gGroupCalendar_PlayerSettings.Security.TrustAnyone |
||
559 | or gGroupCalendar_PlayerSettings.Security.TrustGuildies) then |
||
560 | gGroupCalendar_PlayerSettings.Security.TrustAnyone = false; |
||
561 | gGroupCalendar_PlayerSettings.Security.TrustGuildies = false; |
||
562 | vChanged = true; |
||
563 | end |
||
564 | |||
565 | if vChanged then |
||
566 | -- Update auto-config string with the trust config |
||
567 | |||
568 | if CanEditPublicNote() |
||
569 | and gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer then |
||
570 | CalendarNetwork_SetAutoConfigData(gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer); |
||
571 | end |
||
572 | |||
573 | CalendarTrust_TrustSettingsChanged(); |
||
574 | end |
||
575 | end |
||
576 | |||
577 | function GroupCalendar_ShowPanel(pPanelIndex) |
||
578 | if gGroupCalendar_CurrentPanel > 0 |
||
579 | and gGroupCalendar_CurrentPanel ~= pPanelIndex then |
||
580 | GroupCalendar_HidePanel(gGroupCalendar_CurrentPanel); |
||
581 | end |
||
582 | |||
583 | -- NOTE: Don't check for redundant calls since this function |
||
584 | -- will be called to reset the field values as well as to |
||
585 | -- actuall show the panel when it's hidden |
||
586 | |||
587 | gGroupCalendar_CurrentPanel = pPanelIndex; |
||
588 | |||
589 | -- Hide the event editor/viewer if the calendar panel is being hidden |
||
590 | |||
591 | if pPanelIndex ~= 1 then |
||
592 | CalendarEventEditor_DoneEditing(); |
||
593 | CalendarEventViewer_DoneViewing(); |
||
594 | CalendarEditor_Close(); |
||
595 | end |
||
596 | |||
597 | -- Update the control values |
||
598 | |||
599 | if pPanelIndex == 1 then |
||
600 | elseif pPanelIndex == 2 then |
||
601 | -- Channel panel |
||
602 | |||
603 | if gGroupCalendar_PlayerSettings.Channel.AutoConfig |
||
604 | and not IsInGuild() then |
||
605 | gGroupCalendar_PlayerSettings.Channel.AutoConfig = false; |
||
606 | end |
||
607 | |||
608 | GroupCalendarAutoChannelConfig:SetChecked(gGroupCalendar_PlayerSettings.Channel.AutoConfig); |
||
609 | GroupCalendarManualChannelConfig:SetChecked(not gGroupCalendar_PlayerSettings.Channel.AutoConfig); |
||
610 | |||
611 | local vChannelName; |
||
612 | local vAutoConfigPlayer; |
||
613 | |||
614 | if gGroupCalendar_PlayerSettings.Channel.AutoConfig then |
||
615 | vChannelName = gGroupCalendar_Channel.Name; |
||
616 | if gGroupCalendar_Channel.Password then |
||
617 | GroupCalendarChannelPassword:SetText("******"); |
||
618 | else |
||
619 | GroupCalendarChannelPassword:SetText(""); |
||
620 | end |
||
621 | |||
622 | vAutoConfigPlayer = gGroupCalendar_Channel.AutoPlayer; |
||
623 | else |
||
624 | vChannelName = gGroupCalendar_PlayerSettings.Channel.Name; |
||
625 | vAutoConfigPlayer = gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer; |
||
626 | |||
627 | if gGroupCalendar_PlayerSettings.Channel.Password then |
||
628 | GroupCalendarChannelPassword:SetText(gGroupCalendar_PlayerSettings.Channel.Password); |
||
629 | else |
||
630 | GroupCalendarChannelPassword:SetText(""); |
||
631 | end |
||
632 | end |
||
633 | |||
634 | if vChannelName ~= nil then |
||
635 | GroupCalendarChannelName:SetText(vChannelName); |
||
636 | else |
||
637 | GroupCalendarChannelName:SetText(""); |
||
638 | end |
||
639 | |||
640 | if vAutoConfigPlayer then |
||
641 | GroupCalendarAutoConfigPlayer:SetText(vAutoConfigPlayer); |
||
642 | else |
||
643 | GroupCalendarAutoConfigPlayer:SetText(""); |
||
644 | end |
||
645 | |||
646 | if not gGroupCalendar_PlayerSettings.Channel.AutoConfig |
||
647 | and gGroupCalendar_PlayerSettings.Channel.AutoConfigPlayer then |
||
648 | GroupCalendarStoreAutoConfig:SetChecked(true); |
||
649 | else |
||
650 | GroupCalendarStoreAutoConfig:SetChecked(false); |
||
651 | end |
||
652 | |||
653 | GroupCalendar_UpdateChannelStatus(); |
||
654 | |||
655 | elseif pPanelIndex == 3 then |
||
656 | -- Trust panel |
||
657 | |||
658 | GroupCalendarTrustGroup.ChangedValueFunc = GroupCalendar_UpdateEnabledControls; |
||
659 | |||
660 | if gGroupCalendar_PlayerSettings.Security.TrustGuildies |
||
661 | and not IsInGuild() then |
||
662 | gGroupCalendar_PlayerSettings.Security.TrustGuildies = false; |
||
663 | end |
||
664 | |||
665 | if gGroupCalendar_PlayerSettings.Security.TrustAnyone then |
||
666 | CalendarDropDown_SetSelectedValue(GroupCalendarTrustGroup, 1); |
||
667 | elseif gGroupCalendar_PlayerSettings.Security.TrustGuildies then |
||
668 | CalendarDropDown_SetSelectedValue(GroupCalendarTrustGroup, 2); |
||
669 | else |
||
670 | CalendarDropDown_SetSelectedValue(GroupCalendarTrustGroup, 3); |
||
671 | end |
||
672 | |||
673 | if gGroupCalendar_PlayerSettings.Security.TrustGuildies then |
||
674 | GroupCalendarTrustMinRank:Show(); |
||
675 | |||
676 | if gGroupCalendar_PlayerSettings.Security.MinTrustedRank ~= nil then |
||
677 | CalendarDropDown_SetSelectedValue(GroupCalendarTrustMinRank, gGroupCalendar_PlayerSettings.Security.MinTrustedRank); |
||
678 | else |
||
679 | UIDropDownMenu_SetText("", GroupCalendarTrustMinRank); -- In case the value doesn't exist |
||
680 | end |
||
681 | else |
||
682 | GroupCalendarTrustMinRank:Hide(); |
||
683 | end |
||
684 | |||
685 | CalendarPlayerList_SetItemFunction(CalendarTrustedPlayersList, GroupCalendar_GetIndexedTrustedPlayer); |
||
686 | CalendarPlayerList_SetSelectionChangedFunction(CalendarTrustedPlayersList, GroupCalendar_TrustedPlayerSelected); |
||
687 | |||
688 | CalendarPlayerList_SetItemFunction(CalendarExcludedPlayersList, GroupCalendar_GetIndexedExcludedPlayer); |
||
689 | CalendarPlayerList_SetSelectionChangedFunction(CalendarExcludedPlayersList, GroupCalendar_ExcludedPlayerSelected); |
||
690 | end |
||
691 | |||
692 | GroupCalendar_UpdateEnabledControls(); |
||
693 | |||
694 | getglobal(gGroupCalendar_PanelFrames[pPanelIndex]):Show(); |
||
695 | |||
696 | PanelTemplates_SetTab(GroupCalendarFrame, pPanelIndex); |
||
697 | end |
||
698 | |||
699 | function GroupCalendar_HidePanel(pFrameIndex) |
||
700 | if gGroupCalendar_CurrentPanel ~= pFrameIndex then |
||
701 | return; |
||
702 | end |
||
703 | |||
704 | GroupCalendar_SavePanel(pFrameIndex); |
||
705 | |||
706 | getglobal(gGroupCalendar_PanelFrames[pFrameIndex]):Hide(); |
||
707 | gGroupCalendar_CurrentPanel = 0; |
||
708 | end |
||
709 | |||
710 | function GroupCalendar_UpdateChannelStatus() |
||
711 | local vChannelStatus = CalendarNetwork_GetChannelStatus(); |
||
712 | local vStatusText = GroupCalendar_cChannelStatus[vChannelStatus]; |
||
713 | |||
714 | GroupCalendarChannelStatus:SetText(string.format(vStatusText.mText, gGroupCalendar_Channel.StatusMessage)); |
||
715 | GroupCalendarChannelStatus:SetTextColor(vStatusText.mColor.r, vStatusText.mColor.g, vStatusText.mColor.b); |
||
716 | |||
717 | if vChannelStatus == "Connected" then |
||
718 | Calendar_SetButtonEnable(GroupCalendarConnectChannelButton, true); |
||
719 | GroupCalendarConnectChannelButton:SetText(GroupCalendar_cDisconnectChannel); |
||
720 | elseif vChannelStatus == "Disconnected" or vChannelStatus == "Error" then |
||
721 | Calendar_SetButtonEnable(GroupCalendarConnectChannelButton, true); |
||
722 | GroupCalendarConnectChannelButton:SetText(GroupCalendar_cConnectChannel); |
||
723 | else |
||
724 | Calendar_SetButtonEnable(GroupCalendarConnectChannelButton, false); |
||
725 | end |
||
726 | end |
||
727 | |||
728 | function GroupCalendar_FixPlayerName(pName) |
||
729 | if pName == nil |
||
730 | or pName == "" then |
||
731 | return nil; |
||
732 | end |
||
733 | |||
734 | local vFirstChar = string.sub(pName, 1, 1); |
||
735 | |||
736 | if (vFirstChar >= "a" and vFirstChar <= "z") |
||
737 | or (vFirstChar >= "A" and vFirstChar <= "Z") then |
||
738 | return string.upper(vFirstChar)..string.lower(string.sub(pName, 2)); |
||
739 | else |
||
740 | return pName; |
||
741 | end |
||
742 | end |
||
743 | |||
744 | function GroupCalendar_AddTrustedPlayer(pPlayerName) |
||
745 | local vPlayerName = GroupCalendar_FixPlayerName(pPlayerName); |
||
746 | |||
747 | if vPlayerName == nil then |
||
748 | return; |
||
749 | end |
||
750 | |||
751 | gGroupCalendar_PlayerSettings.Security.Player[vPlayerName] = 1; |
||
752 | GroupCalendar_UpdateTrustedPlayerList(); |
||
753 | CalendarTrust_TrustSettingsChanged(); |
||
754 | end |
||
755 | |||
756 | function GroupCalendar_AddExcludedPlayer(pPlayerName) |
||
757 | local vPlayerName = GroupCalendar_FixPlayerName(pPlayerName); |
||
758 | |||
759 | if vPlayerName == nil then |
||
760 | return; |
||
761 | end |
||
762 | |||
763 | gGroupCalendar_PlayerSettings.Security.Player[vPlayerName] = 2; |
||
764 | GroupCalendar_UpdateTrustedPlayerList(); |
||
765 | CalendarTrust_TrustSettingsChanged(); |
||
766 | end |
||
767 | |||
768 | function GroupCalendar_RemoveTrustedPlayer(pPlayerName) |
||
769 | local vPlayerName = GroupCalendar_FixPlayerName(pPlayerName); |
||
770 | |||
771 | if vPlayerName == nil then |
||
772 | return; |
||
773 | end |
||
774 | |||
775 | gGroupCalendar_PlayerSettings.Security.Player[vPlayerName] = nil; |
||
776 | |||
777 | GroupCalendar_UpdateTrustedPlayerList(); |
||
778 | |||
779 | CalendarPlayerList_SelectIndexedPlayer(CalendarTrustedPlayersList, 0); |
||
780 | CalendarPlayerList_SelectIndexedPlayer(CalendarExcludedPlayersList, 0); |
||
781 | |||
782 | CalendarTrust_TrustSettingsChanged(); |
||
783 | end |
||
784 | |||
785 | function GroupCalendar_UpdateTrustedPlayerList() |
||
786 | CalendarPlayerList_Update(CalendarTrustedPlayersList); |
||
787 | CalendarPlayerList_Update(CalendarExcludedPlayersList); |
||
788 | end |
||
789 | |||
790 | function GroupCalendar_GetIndexedTrustedPlayer(pIndex) |
||
791 | if pIndex == 0 then |
||
792 | return CalendarTrust_GetNumTrustedPlayers(1); |
||
793 | end |
||
794 | |||
795 | return |
||
796 | { |
||
797 | Text = CalendarTrust_GetIndexedTrustedPlayers(1, pIndex); |
||
798 | }; |
||
799 | end |
||
800 | |||
801 | function GroupCalendar_GetIndexedExcludedPlayer(pIndex) |
||
802 | if pIndex == 0 then |
||
803 | return CalendarTrust_GetNumTrustedPlayers(2); |
||
804 | end |
||
805 | |||
806 | return |
||
807 | { |
||
808 | Text = CalendarTrust_GetIndexedTrustedPlayers(2, pIndex); |
||
809 | }; |
||
810 | end |
||
811 | |||
812 | function GroupCalendar_TrustedPlayerSelected(pIndex) |
||
813 | if pIndex == 0 then |
||
814 | return; |
||
815 | end |
||
816 | |||
817 | CalendarPlayerList_SelectIndexedPlayer(CalendarExcludedPlayersList, 0); |
||
818 | |||
819 | local vName = CalendarTrust_GetIndexedTrustedPlayers(1, pIndex); |
||
820 | |||
821 | if vName then |
||
822 | CalendarTrustedPlayerName:SetText(vName); |
||
823 | CalendarTrustedPlayerName:HighlightText(); |
||
824 | CalendarTrustedPlayerName:SetFocus(); |
||
825 | end |
||
826 | end |
||
827 | |||
828 | function GroupCalendar_ExcludedPlayerSelected(pIndex) |
||
829 | if pIndex == 0 then |
||
830 | return; |
||
831 | end |
||
832 | |||
833 | CalendarPlayerList_SelectIndexedPlayer(CalendarTrustedPlayersList, 0); |
||
834 | |||
835 | local vName = CalendarTrust_GetIndexedTrustedPlayers(2, pIndex); |
||
836 | |||
837 | if vName then |
||
838 | CalendarTrustedPlayerName:SetText(vName); |
||
839 | CalendarTrustedPlayerName:HighlightText(); |
||
840 | CalendarTrustedPlayerName:SetFocus(); |
||
841 | end |
||
842 | end |
||
843 | |||
844 | function GroupCalendar_SelectDateWithToggle(pDate) |
||
845 | if CalendarEditor_IsOpen() |
||
846 | and gCalendarEditor_SelectedDate == pDate then |
||
847 | CalendarEditor_Close(); |
||
848 | else |
||
849 | GroupCalendar_SelectDate(pDate); |
||
850 | end |
||
851 | end |
||
852 | |||
853 | function GroupCalendar_SelectDate(pDate) |
||
854 | Calendar_SetSelectedDate(pDate); |
||
855 | |||
856 | local vCompiledSchedule = EventDatabase_GetCompiledSchedule(pDate); |
||
857 | |||
858 | CalendarEditor_ShowCompiledSchedule(pDate, vCompiledSchedule); |
||
859 | end |
||
860 | |||
861 | function GroupCalendar_EditorClosed() |
||
862 | Calendar_ClearSelectedDate(); |
||
863 | end |
||
864 | |||
865 | function GroupCalendar_EventChanged(pDatabase, pEvent, pChangedFields) |
||
866 | GroupCalendar_ScheduleChanged(pDatabase, pEvent.mDate); |
||
867 | CalendarEventEditor_EventChanged(pEvent); |
||
868 | end |
||
869 | |||
870 | function GroupCalendar_ScheduleChanged(pDatabase, pDate) |
||
871 | GroupCalendar_ScheduleChanged2(pDatabase, pDate); |
||
872 | |||
873 | if gGroupCalendar_Settings.ShowEventsInLocalTime then |
||
874 | if gGroupCalendar_ServerTimeZoneOffset < 0 then |
||
875 | GroupCalendar_ScheduleChanged2(pDatabase, pDate - 1); |
||
876 | elseif gGroupCalendar_ServerTimeZoneOffset > 0 then |
||
877 | GroupCalendar_ScheduleChanged2(pDatabase, pDate + 1); |
||
878 | end |
||
879 | end |
||
880 | end |
||
881 | |||
882 | function GroupCalendar_ScheduleChanged2(pDatabase, pDate) |
||
883 | local vSchedule = pDatabase.Events[pDate]; |
||
884 | |||
885 | CalendarEditor_ScheduleChanged(pDate, pSchedule); |
||
886 | Calendar_ScheduleChanged(pDate, pSchedule); |
||
887 | CalendarEventViewer_ScheduleChanged(pDate); |
||
888 | end |
||
889 | |||
890 | function GroupCalendar_MajorDatabaseChange(pDatabase) |
||
891 | CalendarEditor_MajorDatabaseChange(); |
||
892 | CalendarEventViewer_MajorDatabaseChange(); |
||
893 | CalendarEventEditor_MajorDatabaseChange(); |
||
894 | Calendar_MajorDatabaseChange(); |
||
895 | end |
||
896 | |||
897 | gGroupCalendar_QueueElapsedTime = 0; |
||
898 | |||
899 | function GroupCalendar_Update(pElapsed) |
||
900 | local vLatencyStartTime; |
||
901 | |||
902 | -- Process invites |
||
903 | |||
904 | if gGroupCalendar_Settings.DebugLatency then |
||
905 | vLatencyStartTime = GetTime(); |
||
906 | end |
||
907 | |||
908 | CalendarGroupInvites_Update(pElapsed); |
||
909 | |||
910 | if gGroupCalendar_Settings.DebugLatency then |
||
911 | local vElapsed = GetTime() - vLatencyStartTime; |
||
912 | |||
913 | if vElapsed > 0.1 then |
||
914 | Calendar_DebugMessage("CalendarGroupInvites_Update took "..vElapsed.."s to execute"); |
||
915 | end |
||
916 | |||
917 | vLatencyStartTime = GetTime(); |
||
918 | end |
||
919 | |||
920 | -- Process the event queues if it's time |
||
921 | |||
922 | gGroupCalendar_QueueElapsedTime = gGroupCalendar_QueueElapsedTime + pElapsed; |
||
923 | |||
924 | if gGroupCalendar_QueueElapsedTime > 0.1 then |
||
925 | CalendarNetwork_ProcessQueues(gGroupCalendar_QueueElapsedTime); |
||
926 | |||
927 | gGroupCalendar_QueueElapsedTime = 0; |
||
928 | end |
||
929 | |||
930 | if gGroupCalendar_Settings.DebugLatency then |
||
931 | local vElapsed = GetTime() - vLatencyStartTime; |
||
932 | |||
933 | if vElapsed > 0.1 then |
||
934 | Calendar_DebugMessage("CalendarNetwork_ProcessQueues took "..vElapsed.."s to execute"); |
||
935 | end |
||
936 | |||
937 | vLatencyStartTime = GetTime(); |
||
938 | end |
||
939 | |||
940 | -- Stop the timer if it isn't needed |
||
941 | |||
942 | if not CalendarNetwork_NeedsUpdateTimer() |
||
943 | and not CalendarGroupInvites_NeedsUpdateTimer() then |
||
944 | if gGroupCalendar_Settings.DebugTimer then |
||
945 | Calendar_DebugMessage("GroupCalendar_Update: Stopping timer"); |
||
946 | end |
||
947 | |||
948 | GroupCalendarUpdateFrame:Hide(); |
||
949 | end |
||
950 | |||
951 | if gGroupCalendar_Settings.DebugLatency then |
||
952 | local vElapsed = GetTime() - vLatencyStartTime; |
||
953 | |||
954 | if vElapsed > 0.1 then |
||
955 | Calendar_DebugMessage("NeedsUpdateTimer took "..vElapsed.."s to execute"); |
||
956 | end |
||
957 | end |
||
958 | end |
||
959 | |||
960 | function GroupCalendar_StartUpdateTimer() |
||
961 | if GroupCalendarUpdateFrame:IsVisible() then |
||
962 | return; |
||
963 | end |
||
964 | |||
965 | if gGroupCalendar_Settings.DebugTimer then |
||
966 | Calendar_DebugMessage("GroupCalendar_StartUpdateTimer()"); |
||
967 | end |
||
968 | |||
969 | GroupCalendarUpdateFrame:Show(); |
||
970 | end |
||
971 | |||
972 | function GroupCalendar_StartMoving() |
||
973 | if not gGroupCalendar_PlayerSettings.UI.LockWindow then |
||
974 | GroupCalendarFrame:StartMoving(); |
||
975 | end |
||
976 | end |
||
977 | |||
978 | function GroupCalendar_GetPlayerSettings(pPlayerName, pRealmName) |
||
979 | -- Wipe the settings if they're the alpha version |
||
980 | |||
981 | if not gGroupCalendar_Settings.Format then |
||
982 | gGroupCalendar_Settings = |
||
983 | { |
||
984 | Debug = false, |
||
985 | Format = 1, |
||
986 | }; |
||
987 | end |
||
988 | |||
989 | local vSettings = gGroupCalendar_Settings[pRealmName.."_"..pPlayerName]; |
||
990 | |||
991 | if vSettings == nil then |
||
992 | vSettings = |
||
993 | { |
||
994 | Security = |
||
995 | { |
||
996 | TrustAnyone = false, |
||
997 | TrustGuildies = IsInGuild(), |
||
998 | MinTrustedRank = 1, |
||
999 | Player = {}, |
||
1000 | }, |
||
1001 | |||
1002 | Channel = |
||
1003 | { |
||
1004 | AutoConfig = IsInGuild(), |
||
1005 | AutoConfigPlayer = nil, |
||
1006 | Name = nil, |
||
1007 | Password = nil, |
||
1008 | }, |
||
1009 | |||
1010 | UI = |
||
1011 | { |
||
1012 | LockWindow = false, |
||
1013 | }, |
||
1014 | }; |
||
1015 | |||
1016 | gGroupCalendar_Settings[pRealmName.."_"..pPlayerName] = vSettings; |
||
1017 | end |
||
1018 | |||
1019 | return vSettings; |
||
1020 | end |
||
1021 | |||
1022 | function GroupCalendar_GetRealmSettings(pRealmName) |
||
1023 | local vSettings = gGroupCalendar_Settings[pRealmName]; |
||
1024 | |||
1025 | if vSettings == nil then |
||
1026 | vSettings = {}; |
||
1027 | gGroupCalendar_Settings[pRealmName] = vSettings; |
||
1028 | end |
||
1029 | |||
1030 | return vSettings; |
||
1031 | end |
||
1032 | |||
1033 | function GroupCalendar_RoundTimeOffsetToNearest30(pOffset) |
||
1034 | local vNegativeOffset; |
||
1035 | local vOffset; |
||
1036 | |||
1037 | if pOffset < 0 then |
||
1038 | vNegativeOffset = true; |
||
1039 | vOffset = -pOffset; |
||
1040 | else |
||
1041 | vNegativeOffset = false; |
||
1042 | vOffset = pOffset; |
||
1043 | end |
||
1044 | |||
1045 | vOffset = vOffset - (math.mod(vOffset + 15, 30) - 15); |
||
1046 | |||
1047 | if vNegativeOffset then |
||
1048 | return -vOffset; |
||
1049 | else |
||
1050 | return vOffset; |
||
1051 | end |
||
1052 | end |
||
1053 | |||
1054 | function GroupCalendar_CalculateTimeZoneOffset() |
||
1055 | local vServerTime = Calendar_ConvertHMToTime(GetGameTime()); |
||
1056 | local vLocalDate, vLocalTime = Calendar_GetCurrentLocalDateTime(); |
||
1057 | local vUTCDate, vUTCTime = Calendar_GetCurrentUTCDateTime(); |
||
1058 | |||
1059 | local vLocalDateTime = vLocalDate * 1440 + vLocalTime; |
||
1060 | local vUTCDateTime = vUTCDate * 1440 + vUTCTime; |
||
1061 | |||
1062 | local vLocalUTCDelta = GroupCalendar_RoundTimeOffsetToNearest30(vLocalDateTime - vUTCDateTime); |
||
1063 | local vLocalServerDelta = GroupCalendar_RoundTimeOffsetToNearest30(vLocalTime - vServerTime); |
||
1064 | local vServerUTCDelta = vLocalUTCDelta - vLocalServerDelta; |
||
1065 | |||
1066 | if vServerUTCDelta < (-12 * 60) then |
||
1067 | vServerUTCDelta = vServerUTCDelta + (24 * 60); |
||
1068 | elseif vServerUTCDelta > (12 * 60) then |
||
1069 | vServerUTCDelta = vServerUTCDelta - (24 * 60); |
||
1070 | end |
||
1071 | |||
1072 | vLocalServerDelta = vLocalUTCDelta - vServerUTCDelta; |
||
1073 | |||
1074 | if vLocalServerDelta ~= gGroupCalendar_ServerTimeZoneOffset then |
||
1075 | gGroupCalendar_ServerTimeZoneOffset = vLocalServerDelta; |
||
1076 | |||
1077 | -- Time zone changed |
||
1078 | |||
1079 | if gGroupCalendar_ServerTimeZoneOffset == 0 then |
||
1080 | GroupCalendarUseServerTime:Hide(); |
||
1081 | else |
||
1082 | GroupCalendarUseServerTime:Show(); |
||
1083 | end |
||
1084 | end |
||
1085 | end |
||
1086 | |||
1087 | function GroupCalendar_UpdateTimeTooltip() |
||
1088 | local vServerTime = Calendar_ConvertHMToTime(GetGameTime()); |
||
1089 | local vLocalDate = Calendar_GetCurrentLocalDate(); |
||
1090 | |||
1091 | local vServerTimeString = Calendar_GetShortTimeString(vServerTime); |
||
1092 | local vLocalDateString = Calendar_GetLongDateString(vLocalDate, true); |
||
1093 | |||
1094 | GameTooltip:AddLine(vLocalDateString); |
||
1095 | GameTooltip:AddLine(vServerTimeString); |
||
1096 | |||
1097 | if gGroupCalendar_ServerTimeZoneOffset ~= 0 then |
||
1098 | local vLocalTime = Calendar_GetLocalTimeFromServerTime(vServerTime); |
||
1099 | local vLocalTimeString = Calendar_GetShortTimeString(vLocalTime); |
||
1100 | |||
1101 | GameTooltip:AddLine(string.format(GroupCalendar_cLocalTimeNote, vLocalTimeString)); |
||
1102 | end |
||
1103 | |||
1104 | GameTooltip:Show(); |
||
1105 | end |
||
1106 | |||
1107 | function GroupCalendar_ChannelChanged() |
||
1108 | if CalendarNetwork_GetChannelStatus() == "Connected" then |
||
1109 | GroupCalendar_RegisterEvent(GroupCalendarFrame, "CHAT_MSG_CHANNEL", GroupCalendar_ChatMsgChannel); |
||
1110 | else |
||
1111 | GroupCalendar_UnregisterEvent(GroupCalendarFrame, "CHAT_MSG_CHANNEL"); |
||
1112 | end |
||
1113 | |||
1114 | if GroupCalendarFrame:IsVisible() |
||
1115 | and (gGroupCalendar_CurrentPanel == 2 |
||
1116 | or gGroupCalendar_CurrentPanel == 3) then |
||
1117 | if GroupCalendarAutoChannelConfig:GetChecked() then |
||
1118 | GroupCalendar_ShowPanel(gGroupCalendar_CurrentPanel); -- Refresh the channel and auto-player names |
||
1119 | end |
||
1120 | |||
1121 | if gGroupCalendar_CurrentPanel == 2 then |
||
1122 | GroupCalendar_UpdateChannelStatus(); |
||
1123 | end |
||
1124 | end |
||
1125 | end |
||
1126 | |||
1127 | function GroupCalendar_GetLocalizedStrings(pLocale) |
||
1128 | local vStrings = {}; |
||
1129 | |||
1130 | -- Initialize the strings with copies form the enUS set |
||
1131 | |||
1132 | for vIndex, vString in gCalendarLocalizedStrings.enUS do |
||
1133 | vStrings[vIndex] = vString; |
||
1134 | end |
||
1135 | |||
1136 | -- Select a set to use for overwriting |
||
1137 | |||
1138 | local vLocalizedStrings = gCalendarLocalizedStrings[pLocale]; |
||
1139 | |||
1140 | if not vLocalizedStrings then |
||
1141 | -- There's not a fit for the exact language/country specified, so just match the language |
||
1142 | |||
1143 | local vLanguageCode = string.sub(pLocale, 1, 2); |
||
1144 | |||
1145 | vLocalizedStrings = GroupCalendar_SelectLanguage(vLanguageCode); |
||
1146 | |||
1147 | if not vLocalizedStrings then |
||
1148 | return vStrings; |
||
1149 | end |
||
1150 | end |
||
1151 | |||
1152 | -- Overwrise the english strings with translated strings |
||
1153 | |||
1154 | for vIndex, vString in vLocalizedStrings do |
||
1155 | vStrings[vIndex] = vString; |
||
1156 | end |
||
1157 | |||
1158 | return vStrings; |
||
1159 | end |
||
1160 | |||
1161 | function GroupCalendar_SelectLanguage(pLanguageCode) |
||
1162 | -- There's not a fit for the exact language/country specified, so just match the language |
||
1163 | |||
1164 | local vLanguageCode = string.sub(pLocale, 1, 2); |
||
1165 | |||
1166 | for vLocale, vLocalizedStrings in gCalendarLocalizedStrings do |
||
1167 | if pLanguageCode == string.sub(vLocale, 1, 2) then |
||
1168 | return vLocalizedStrings; |
||
1169 | end |
||
1170 | end |
||
1171 | |||
1172 | -- No luck, hope they know english! |
||
1173 | |||
1174 | return nil; |
||
1175 | end |
||
1176 | |||
1177 | function GroupCalendar_ToggleChannelConnection() |
||
1178 | local vChannelStatus = CalendarNetwork_GetChannelStatus(); |
||
1179 | |||
1180 | if vChannelStatus == "Initializing" then |
||
1181 | return; |
||
1182 | end |
||
1183 | |||
1184 | if vChannelStatus == "Connected" then |
||
1185 | gGroupCalendar_Channel.Disconnected = true; |
||
1186 | |||
1187 | CalendarNetwork_LeaveChannel(); |
||
1188 | else |
||
1189 | gGroupCalendar_Channel.Disconnected = false; |
||
1190 | |||
1191 | CalendarNetwork_SetChannelStatus("Initializing"); |
||
1192 | |||
1193 | if gGroupCalendar_PlayerSettings.Channel.AutoConfig then |
||
1194 | CalendarNetwork_ScheduleAutoConfig(0.5); |
||
1195 | elseif gGroupCalendar_PlayerSettings.Channel.Name then |
||
1196 | CalendarNetwork_SetChannel( |
||
1197 | gGroupCalendar_PlayerSettings.Channel.Name, |
||
1198 | gGroupCalendar_PlayerSettings.Channel.Password); |
||
1199 | else |
||
1200 | CalendarNetwork_SetChannelStatus("Disconnected"); |
||
1201 | end |
||
1202 | end |
||
1203 | end |
||
1204 | |||
1205 | function GroupCalendar_ToggleCalendarDisplay() |
||
1206 | if GroupCalendarFrame:IsVisible() then |
||
1207 | HideUIPanel(GroupCalendarFrame); |
||
1208 | else |
||
1209 | ShowUIPanel(GroupCalendarFrame); |
||
1210 | end |
||
1211 | end |
||
1212 | |||
1213 | function GroupCalendar_SetUseServerDateTime(pUseServerDateTime) |
||
1214 | gGroupCalendar_Settings.ShowEventsInLocalTime = not pUseServerDateTime; |
||
1215 | |||
1216 | GroupCalendarUseServerTime:SetChecked(pUseServerDateTime); |
||
1217 | |||
1218 | GroupCalendar_MajorDatabaseChange(nil); -- Force the display to update |
||
1219 | end |
||
1220 | |||
1221 | function GroupCalendar_BeginModalDialog(pDialogFrame) |
||
1222 | if gGroupCalendar_ActiveDialog then |
||
1223 | GroupCalendar_EndModalDialog(gGroupCalendar_ActiveDialog); |
||
1224 | end |
||
1225 | |||
1226 | gGroupCalendar_ActiveDialog = pDialogFrame; |
||
1227 | end |
||
1228 | |||
1229 | function GroupCalendar_EndModalDialog(pDialogFrame) |
||
1230 | if pDialogFrame ~= gGroupCalendar_ActiveDialog then |
||
1231 | return; |
||
1232 | end |
||
1233 | |||
1234 | gGroupCalendar_ActiveDialog = nil; |
||
1235 | |||
1236 | pDialogFrame:Hide(); |
||
1237 | end |
||
1238 | |||
1239 | function GroupCalendar_ExecuteCommand(pCommandString) |
||
1240 | local vStartIndex, vEndIndex, vCommand, vParameter = string.find(pCommandString, "(%w+) ?(.*)"); |
||
1241 | |||
1242 | if not vCommand then |
||
1243 | ShowUIPanel(GroupCalendarFrame); |
||
1244 | return; |
||
1245 | end |
||
1246 | |||
1247 | local vCommandTable = |
||
1248 | { |
||
1249 | ["help"] = {func = GroupCalendar_ShowCommandHelp}, |
||
1250 | ["versions"] = {func = GroupCalendar_DumpUserVersions}, |
||
1251 | }; |
||
1252 | |||
1253 | local vCommandInfo = vCommandTable[strlower(vCommand)]; |
||
1254 | |||
1255 | if not vCommandInfo then |
||
1256 | GroupCalendar_ShowCommandHelp(); |
||
1257 | return; |
||
1258 | end |
||
1259 | |||
1260 | vCommandInfo.func(vParameter); |
||
1261 | end |
||
1262 | |||
1263 | function GroupCalendar_ShowCommandHelp() |
||
1264 | Calendar_NoteMessage("GroupCalendar commands:"); |
||
1265 | Calendar_NoteMessage(HIGHLIGHT_FONT_COLOR_CODE.."/calendar help"..NORMAL_FONT_COLOR_CODE..": Shows this list of commands"); |
||
1266 | Calendar_NoteMessage(HIGHLIGHT_FONT_COLOR_CODE.."/calendar versions"..NORMAL_FONT_COLOR_CODE..": Displays the last known versions of GroupCalendar each user was running"); |
||
1267 | end |
||
1268 | |||
1269 | function GroupCalendar_DumpUserVersions() |
||
1270 | for vRealmUser, vDatabase in gGroupCalendar_Database.Databases do |
||
1271 | if EventDatabase_DatabaseIsVisible(vDatabase) then |
||
1272 | if vDatabase.IsPlayerOwned then |
||
1273 | Calendar_NoteMessage(HIGHLIGHT_FONT_COLOR_CODE..vDatabase.UserName..NORMAL_FONT_COLOR_CODE..": "..gGroupCalendar_VersionString); |
||
1274 | elseif vDatabase.AddonVersion then |
||
1275 | Calendar_NoteMessage(HIGHLIGHT_FONT_COLOR_CODE..vDatabase.UserName..NORMAL_FONT_COLOR_CODE..": "..vDatabase.AddonVersion); |
||
1276 | else |
||
1277 | Calendar_NoteMessage(HIGHLIGHT_FONT_COLOR_CODE..vDatabase.UserName..NORMAL_FONT_COLOR_CODE..": Unknown version"); |
||
1278 | end |
||
1279 | end |
||
1280 | end |
||
1281 | end |