vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | gDaysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
2 | gDaysToMonth = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; |
||
3 | |||
4 | gCalendarDisplayStartDayOfWeek = 0; |
||
5 | gCalendarDisplayStartDate = 0; |
||
6 | gCalendarDisplayEndDate = 0; |
||
7 | |||
8 | gCalendarActualDate = -1; |
||
9 | gCalendarActualDateIndex = -1; |
||
10 | |||
11 | gCalendarSelectedDate = -1; |
||
12 | gCalendarSelectedDateIndex = -1; |
||
13 | |||
14 | gCalendarPlayerList_cNumVisibleEntries = 5; |
||
15 | gCalendarPlayerList_cItemHeight = 15; |
||
16 | |||
17 | gCalendarMinutesPerDay = 1440; |
||
18 | gCalendarSecondsPerDay = gCalendarMinutesPerDay * 60; |
||
19 | |||
20 | gCalendar_InitializedDebug = false; |
||
21 | gCalendar_DebugFrame = nil; |
||
22 | |||
23 | function Calendar_InitDebugging() |
||
24 | if gCalendar_InitializedDebug then |
||
25 | return; |
||
26 | end |
||
27 | |||
28 | gCalendar_InitializedDebug = true; |
||
29 | |||
30 | -- Find the debug frame if there is one |
||
31 | |||
32 | for vChatIndex = 1, NUM_CHAT_WINDOWS do |
||
33 | local vFrameName = "ChatFrame"..vChatIndex; |
||
34 | local vChatFrame = getglobal(vFrameName); |
||
35 | |||
36 | if vChatFrame |
||
37 | and (vChatFrame:IsVisible() or vChatFrame.isDocked) then |
||
38 | local vTab = getglobal("ChatFrame"..vChatIndex.."Tab"); |
||
39 | local vName = vTab:GetText(); |
||
40 | |||
41 | if vName == "Debug" then |
||
42 | gCalendar_DebugFrame = vChatFrame; |
||
43 | _ERRORMESSAGE = function(message) Calendar_DebugMessage(message); end; |
||
44 | end |
||
45 | end |
||
46 | end |
||
47 | |||
48 | if gCalendar_DebugFrame then |
||
49 | Calendar_DebugMessage("Found debugging chat frame"); |
||
50 | end |
||
51 | end |
||
52 | |||
53 | function Calendar_DebugMessage(pMessage) |
||
54 | if gCalendar_DebugFrame then |
||
55 | gCalendar_DebugFrame:AddMessage(pMessage, 0.7, 0.3, 1.0); |
||
56 | |||
57 | local vTabFlash = getglobal(gCalendar_DebugFrame:GetName().."TabFlash"); |
||
58 | |||
59 | vTabFlash:Show(); |
||
60 | UIFrameFlash(vTabFlash, 0.25, 0.25, 60, nil, 0.5, 0.5); |
||
61 | else |
||
62 | DEFAULT_CHAT_FRAME:AddMessage(pMessage, 0.7, 0.3, 1.0); |
||
63 | end |
||
64 | end |
||
65 | |||
66 | function Calendar_NoteMessage(pMessage) |
||
67 | DEFAULT_CHAT_FRAME:AddMessage(pMessage, 0.8, 0.8, 0.5); |
||
68 | end |
||
69 | |||
70 | function Calendar_ErrorMessage(pMessage) |
||
71 | DEFAULT_CHAT_FRAME:AddMessage(pMessage, 0.8, 0.3, 0.5); |
||
72 | end |
||
73 | |||
74 | function Calendar_TestMessage(pMessage) |
||
75 | if gCalendar_DebugFrame then |
||
76 | gCalendar_DebugFrame:AddMessage(pMessage, 0.7, 0.3, 1.0); |
||
77 | else |
||
78 | DEFAULT_CHAT_FRAME:AddMessage(pMessage, 0.7, 0.3, 1.0); |
||
79 | end |
||
80 | end |
||
81 | |||
82 | function Calendar_GetCurrentYearMonthDayHourMinute() |
||
83 | local vDate = date("*t"); |
||
84 | |||
85 | return vDate.year, vDate.month, vDate.day, vDate.hour, vDate.min, vDate.sec; |
||
86 | end |
||
87 | |||
88 | function Calendar_GetCurrentLocalDateTimeStamp() |
||
89 | local vDate, vTime60 = Calendar_GetCurrentLocalDateTime60(); |
||
90 | |||
91 | return vDate * 86400 + vTime60; |
||
92 | end |
||
93 | |||
94 | function Calendar_GetCurrentLocalDateTime60() |
||
95 | local vDate = date("*t"); |
||
96 | |||
97 | return Calendar_ConvertMDYToDate(vDate.month, vDate.day, vDate.year), Calendar_ConvertHMSToTime60(vDate.hour, vDate.min, vDate.sec); |
||
98 | end |
||
99 | |||
100 | function Calendar_GetCurrentLocalDateTime() |
||
101 | local vDate = date("*t"); |
||
102 | |||
103 | return Calendar_ConvertMDYToDate(vDate.month, vDate.day, vDate.year), Calendar_ConvertHMToTime(vDate.hour, vDate.min); |
||
104 | end |
||
105 | |||
106 | function Calendar_GetCurrentUTCDateTime() |
||
107 | local vDate = date("!*t"); |
||
108 | |||
109 | return Calendar_ConvertMDYToDate(vDate.month, vDate.day, vDate.year), Calendar_ConvertHMToTime(vDate.hour, vDate.min); |
||
110 | end |
||
111 | |||
112 | function Calendar_GetCurrentLocalDate() |
||
113 | local vDate = date("*t"); |
||
114 | |||
115 | return Calendar_ConvertMDYToDate(vDate.month, vDate.day, vDate.year); |
||
116 | end |
||
117 | |||
118 | function Calendar_GetCurrentLocalTime() |
||
119 | local vDate = date("*t"); |
||
120 | |||
121 | return Calendar_ConvertHMToTime(vDate.hour, vDate.min); |
||
122 | end |
||
123 | |||
124 | function Calendar_GetCurrentUTCDateTime() |
||
125 | local vDate = date("!*t"); |
||
126 | |||
127 | return Calendar_ConvertMDYToDate(vDate.month, vDate.day, vDate.year), Calendar_ConvertHMToTime(vDate.hour, vDate.min); |
||
128 | end |
||
129 | |||
130 | function Calendar_GetCurrentUTCTime() |
||
131 | local vDate = date("!*t"); |
||
132 | |||
133 | return Calendar_ConvertHMToTime(vDate.hour, vDate.min); |
||
134 | end |
||
135 | |||
136 | function Calendar_GetCurrentServerTime() |
||
137 | return Calendar_ConvertHMToTime(GetGameTime()); |
||
138 | end |
||
139 | |||
140 | function Calendar_GetCurrentServerDateTime() |
||
141 | return Calendar_GetServerDateTimeFromLocalDateTime(Calendar_GetCurrentLocalDateTime()); |
||
142 | end |
||
143 | |||
144 | function Calendar_GetCurrentDateTimeUT60() |
||
145 | local vDate = date("!*t"); |
||
146 | |||
147 | return Calendar_ConvertMDYToDate(vDate.month, vDate.day, vDate.year) * gCalendarSecondsPerDay |
||
148 | + Calendar_ConvertHMSToTime60(vDate.hour, vDate.min, vDate.sec); |
||
149 | end |
||
150 | |||
151 | function Calendar_SetCheckButtonEnable(pCheckButton, pEnabled) |
||
152 | if pEnabled then |
||
153 | pCheckButton:Enable(); |
||
154 | pCheckButton:SetAlpha(1.0); |
||
155 | getglobal(pCheckButton:GetName().."Text"):SetAlpha(1.0); |
||
156 | else |
||
157 | pCheckButton:Disable(); |
||
158 | pCheckButton:SetAlpha(0.7); |
||
159 | getglobal(pCheckButton:GetName().."Text"):SetAlpha(0.7); |
||
160 | end |
||
161 | end |
||
162 | |||
163 | function Calendar_SetEditBoxEnable(pEditBox, pEnabled) |
||
164 | local vText = getglobal(pEditBox:GetName().."Text"); |
||
165 | |||
166 | if pEnabled then |
||
167 | pEditBox:SetAlpha(1.0); |
||
168 | if vText then |
||
169 | vText:SetAlpha(1.0); |
||
170 | end |
||
171 | pEditBox:EnableKeyboard(true); |
||
172 | pEditBox:EnableMouse(true); |
||
173 | |||
174 | pEditBox.isDisabled = false; |
||
175 | else |
||
176 | pEditBox:SetAlpha(0.7); |
||
177 | if vText then |
||
178 | vText:SetAlpha(0.7); |
||
179 | end |
||
180 | |||
181 | pEditBox:ClearFocus(); |
||
182 | pEditBox:EnableKeyboard(false); |
||
183 | pEditBox:EnableMouse(false); |
||
184 | |||
185 | pEditBox.isDisabled = true; |
||
186 | end |
||
187 | end |
||
188 | |||
189 | function Calendar_SetDropDownEnable(pDropDown, pEnabled) |
||
190 | if pEnabled then |
||
191 | pDropDown:SetAlpha(1.0); |
||
192 | getglobal(pDropDown:GetName().."Text"):SetAlpha(1.0); |
||
193 | getglobal(pDropDown:GetName().."Button"):EnableMouse(true); |
||
194 | else |
||
195 | pDropDown:SetAlpha(0.7); |
||
196 | getglobal(pDropDown:GetName().."Text"):SetAlpha(0.7); |
||
197 | getglobal(pDropDown:GetName().."Button"):EnableMouse(false); |
||
198 | end |
||
199 | end |
||
200 | |||
201 | function Calendar_SetButtonEnable(pButton, pEnabled) |
||
202 | if pEnabled then |
||
203 | pButton:Enable(); |
||
204 | pButton:SetAlpha(1.0); |
||
205 | pButton:EnableMouse(true); |
||
206 | --getglobal(pButton:GetName().."Text"):SetAlpha(1.0); |
||
207 | else |
||
208 | pButton:Disable(); |
||
209 | pButton:SetAlpha(0.7); |
||
210 | pButton:EnableMouse(false); |
||
211 | --getglobal(pButton:GetName().."Text"):SetAlpha(0.7); |
||
212 | end |
||
213 | end |
||
214 | |||
215 | function CalendarDropDown_SetSelectedValue2(pDropDown, pValue) |
||
216 | pDropDown.selectedName = nil; |
||
217 | pDropDown.selectedID = nil; |
||
218 | pDropDown.selectedValue = pValue; |
||
219 | end |
||
220 | |||
221 | function CalendarDropDown_SetSelectedValue(pDropDown, pValue) |
||
222 | -- Just return if the value isn't changing |
||
223 | |||
224 | if pDropDown.selectedValue == pValue then |
||
225 | return; |
||
226 | end |
||
227 | |||
228 | -- |
||
229 | |||
230 | UIDropDownMenu_SetText("", pDropDown); -- Set to empty in case the selected value isn't there |
||
231 | |||
232 | UIDropDownMenu_Initialize(pDropDown, pDropDown.initialize); |
||
233 | UIDropDownMenu_SetSelectedValue(pDropDown, pValue); |
||
234 | |||
235 | -- All done if the item text got set successfully |
||
236 | |||
237 | local vItemText = UIDropDownMenu_GetText(pDropDown); |
||
238 | |||
239 | if vItemText and vItemText ~= "" then |
||
240 | return; |
||
241 | end |
||
242 | |||
243 | -- Scan for submenus |
||
244 | |||
245 | local vRootListFrameName = "DropDownList1"; |
||
246 | local vRootListFrame = getglobal(vRootListFrameName); |
||
247 | local vRootNumItems = vRootListFrame.numButtons; |
||
248 | |||
249 | for vRootItemIndex = 1, vRootNumItems do |
||
250 | local vItem = getglobal(vRootListFrameName.."Button"..vRootItemIndex); |
||
251 | |||
252 | if vItem.hasArrow then |
||
253 | local vSubMenuFrame = getglobal("DropDownList2"); |
||
254 | |||
255 | UIDROPDOWNMENU_OPEN_MENU = pDropDown:GetName(); |
||
256 | UIDROPDOWNMENU_MENU_VALUE = vItem.value; |
||
257 | UIDROPDOWNMENU_MENU_LEVEL = 2; |
||
258 | |||
259 | UIDropDownMenu_Initialize(pDropDown, pDropDown.initialize, nil, 2); |
||
260 | UIDropDownMenu_SetSelectedValue(pDropDown, pValue); |
||
261 | |||
262 | -- All done if the item text got set successfully |
||
263 | |||
264 | local vItemText = UIDropDownMenu_GetText(pDropDown); |
||
265 | |||
266 | if vItemText and vItemText ~= "" then |
||
267 | return; |
||
268 | end |
||
269 | |||
270 | -- Switch back to the root menu |
||
271 | |||
272 | UIDROPDOWNMENU_OPEN_MENU = nil; |
||
273 | UIDropDownMenu_Initialize(pDropDown, pDropDown.initialize, nil, 1); |
||
274 | end |
||
275 | end |
||
276 | end |
||
277 | |||
278 | function Calendar_GetShortTimeString(pTime) |
||
279 | if pTime == nil then |
||
280 | return nil; |
||
281 | end |
||
282 | |||
283 | if TwentyFourHourTime then |
||
284 | local vHour, vMinute = Calendar_ConvertTimeToHM(pTime); |
||
285 | |||
286 | return format(TEXT(TIME_TWENTYFOURHOURS), vHour, vMinute); |
||
287 | else |
||
288 | local vHour, vMinute, vAMPM = Calendar_ConvertTimeToHMAMPM(pTime); |
||
289 | |||
290 | if vAMPM == 0 then |
||
291 | return format(TEXT(TIME_TWELVEHOURAM), vHour, vMinute); |
||
292 | else |
||
293 | return format(TEXT(TIME_TWELVEHOURPM), vHour, vMinute); |
||
294 | end |
||
295 | end |
||
296 | end |
||
297 | |||
298 | function Calendar_ConvertTimeToHM(pTime) |
||
299 | local vMinute = math.mod(pTime, 60); |
||
300 | local vHour = (pTime - vMinute) / 60; |
||
301 | |||
302 | return vHour, vMinute; |
||
303 | end |
||
304 | |||
305 | function Calendar_ConvertHMToTime(pHour, pMinute) |
||
306 | return pHour * 60 + pMinute; |
||
307 | end |
||
308 | |||
309 | function Calendar_ConvertHMSToTime60(pHour, pMinute, pSecond) |
||
310 | return pHour * 3600 + pMinute * 60 + pSecond; |
||
311 | end |
||
312 | |||
313 | function Calendar_ConvertTimeToHMAMPM(pTime) |
||
314 | local vHour, vMinute = Calendar_ConvertTimeToHM(pTime); |
||
315 | local vAMPM; |
||
316 | |||
317 | if vHour < 12 then |
||
318 | vAMPM = 0; |
||
319 | |||
320 | if vHour == 0 then |
||
321 | vHour = 12; |
||
322 | end |
||
323 | else |
||
324 | vAMPM = 1; |
||
325 | |||
326 | if vHour > 12 then |
||
327 | vHour = vHour - 12; |
||
328 | end |
||
329 | end |
||
330 | |||
331 | return vHour, vMinute, vAMPM; |
||
332 | end |
||
333 | |||
334 | function Calendar_ConvertHMAMPMToTime(pHour, pMinute, pAMPM) |
||
335 | local vHour; |
||
336 | |||
337 | if pAMPM == 0 then |
||
338 | vHour = pHour; |
||
339 | if vHour == 12 then |
||
340 | vHour = 0; |
||
341 | end |
||
342 | else |
||
343 | vHour = pHour + 12; |
||
344 | if vHour == 24 then |
||
345 | vHour = 12; |
||
346 | end |
||
347 | end |
||
348 | |||
349 | return Calendar_ConvertHMToTime(vHour, pMinute); |
||
350 | end |
||
351 | |||
352 | function Calendar_GetLongDateString(pDate, pIncludeDayOfWeek) |
||
353 | local vFormat; |
||
354 | |||
355 | if pIncludeDayOfWeek then |
||
356 | vFormat = GroupCalendar_cLongDateFormatWithDayOfWeek; |
||
357 | else |
||
358 | vFormat = GroupCalendar_cLongDateFormat; |
||
359 | end |
||
360 | |||
361 | return Calendar_GetFormattedDateString(pDate, vFormat); |
||
362 | end |
||
363 | |||
364 | function Calendar_GetShortDateString(pDate, pIncludeDayOfWeek) |
||
365 | return Calendar_GetFormattedDateString(pDate, GroupCalendar_cShortDateFormat); |
||
366 | end |
||
367 | |||
368 | function Calendar_FormatNamed(pFormat, pFields) |
||
369 | return string.gsub( |
||
370 | pFormat, |
||
371 | "%$(%w+)", |
||
372 | function (pField) |
||
373 | return pFields[pField]; |
||
374 | end); |
||
375 | end |
||
376 | |||
377 | function Calendar_GetFormattedDateString(pDate, pFormat) |
||
378 | local vMonth, vDay, vYear = Calendar_ConvertDateToMDY(pDate); |
||
379 | |||
380 | local vDate = |
||
381 | { |
||
382 | dow = GroupCalendar_cDayOfWeekNames[Calendar_GetDayOfWeekFromDate(pDate) + 1], |
||
383 | month = GroupCalendar_cMonthNames[vMonth], |
||
384 | monthNum = vMonth, |
||
385 | day = vDay, |
||
386 | year = vYear, |
||
387 | }; |
||
388 | |||
389 | return Calendar_FormatNamed(pFormat, vDate); |
||
390 | end |
||
391 | |||
392 | function Calendar_SetDisplayDate(pStartDate) |
||
393 | local vMonth, vDay, vYear = Calendar_ConvertDateToMDY(pStartDate); |
||
394 | local vDaysInMonth = Calendar_GetDaysInMonth(vMonth, vYear); |
||
395 | |||
396 | Calendar_SetCalendarRange( |
||
397 | Calendar_GetDayOfWeek(vMonth, 1, vYear), |
||
398 | vDaysInMonth); |
||
399 | |||
400 | local vCalendarTitle = getglobal("GroupCalendarMonthYearText"); |
||
401 | |||
402 | vCalendarTitle:SetText(GroupCalendar_cMonthNames[vMonth].." "..vYear); |
||
403 | |||
404 | gCalendarDisplayStartDate = pStartDate; |
||
405 | gCalendarDisplayEndDate = pStartDate + vDaysInMonth; |
||
406 | |||
407 | Calendar_HiliteActualDate(); |
||
408 | Calendar_HiliteSelectedDate(); |
||
409 | |||
410 | Calendar_UpdateEventIcons(); |
||
411 | end |
||
412 | |||
413 | function Calendar_SetActualDate(pDate) |
||
414 | gCalendarActualDate= pDate; |
||
415 | Calendar_HiliteActualDate(); |
||
416 | end |
||
417 | |||
418 | function Calendar_HiliteActualDate() |
||
419 | local vDayButton; |
||
420 | |||
421 | if gCalendarActualDateIndex >= 0 then |
||
422 | vDayButton = getglobal("GroupCalendarDay"..gCalendarActualDateIndex.."SlotIcon"); |
||
423 | vDayButton:SetTexture("Interface\\Buttons\\UI-EmptySlot-Disabled"); |
||
424 | gCalendarActualDateIndex = -1; |
||
425 | |||
426 | GroupCalendarTodayHighlight:Hide(); |
||
427 | end |
||
428 | |||
429 | if gCalendarActualDate < gCalendarDisplayStartDate |
||
430 | or gCalendarActualDate >= gCalendarDisplayEndDate then |
||
431 | return; |
||
432 | end |
||
433 | |||
434 | gCalendarActualDateIndex = gCalendarActualDate - gCalendarDisplayStartDate + gCalendarDisplayStartDayOfWeek; |
||
435 | |||
436 | if gCalendarActualDateIndex >= 0 then |
||
437 | local vDayButtonName = "GroupCalendarDay"..gCalendarActualDateIndex; |
||
438 | local vDayButtonIconName = vDayButtonName.."SlotIcon"; |
||
439 | |||
440 | vDayButton = getglobal(vDayButtonIconName); |
||
441 | vDayButton:SetTexture("Interface\\Buttons\\UI-EmptySlot"); |
||
442 | |||
443 | GroupCalendarTodayHighlight:SetPoint("CENTER", vDayButtonName, "CENTER", 0, -1); |
||
444 | GroupCalendarTodayHighlight:Show(); |
||
445 | end |
||
446 | end |
||
447 | |||
448 | function Calendar_SetSelectedDate(pDate) |
||
449 | gCalendarSelectedDate = pDate; |
||
450 | |||
451 | Calendar_HiliteSelectedDate(); |
||
452 | end |
||
453 | |||
454 | function Calendar_ClearSelectedDate() |
||
455 | gCalendarSelectedDate = -1; |
||
456 | Calendar_HiliteSelectedDate(); |
||
457 | end |
||
458 | |||
459 | function Calendar_SetSelectedDateIndexWithToggle(pIndex) |
||
460 | GroupCalendar_SelectDateWithToggle( |
||
461 | gCalendarDisplayStartDate + pIndex - gCalendarDisplayStartDayOfWeek); |
||
462 | end |
||
463 | |||
464 | function Calendar_SetSelectedDateIndex(pIndex) |
||
465 | GroupCalendar_SelectDate( |
||
466 | gCalendarDisplayStartDate + pIndex - gCalendarDisplayStartDayOfWeek); |
||
467 | end |
||
468 | |||
469 | function Calendar_HiliteSelectedDate() |
||
470 | local vDayButton; |
||
471 | |||
472 | if gCalendarSelectedDateIndex >= 0 then |
||
473 | vDayButton = getglobal("GroupCalendarDay"..gCalendarSelectedDateIndex); |
||
474 | vDayButton:SetChecked(nil); |
||
475 | gCalendarSelectedDateIndex = -1; |
||
476 | end |
||
477 | |||
478 | if gCalendarSelectedDate < gCalendarDisplayStartDate |
||
479 | or gCalendarSelectedDate >= gCalendarDisplayEndDate then |
||
480 | return; |
||
481 | end |
||
482 | |||
483 | gCalendarSelectedDateIndex = gCalendarSelectedDate - gCalendarDisplayStartDate + gCalendarDisplayStartDayOfWeek; |
||
484 | |||
485 | if gCalendarSelectedDateIndex >= 0 then |
||
486 | vDayButton = getglobal("GroupCalendarDay"..gCalendarSelectedDateIndex); |
||
487 | vDayButton:SetChecked(true); |
||
488 | end |
||
489 | end |
||
490 | |||
491 | function Calendar_GetEventTypeIconPath(pEventType) |
||
492 | local vIconSuffix; |
||
493 | |||
494 | if EventDatabase_IsResetEventType(pEventType) then |
||
495 | local vIsSystemIcon; |
||
496 | |||
497 | vIconSuffix, vIsSystemIcon = EventDatabase_GetResetEventLargeIconPath(pEventType); |
||
498 | |||
499 | if not vIconSuffix then |
||
500 | return ""; |
||
501 | end |
||
502 | |||
503 | if vIsSystemIcon then |
||
504 | return vIconSuffix; |
||
505 | end |
||
506 | else |
||
507 | if EventDatabase_GetEventNameByID(pEventType) then -- Don't attempt to show icons for event types we don't recognize |
||
508 | vIconSuffix = pEventType; |
||
509 | else |
||
510 | vIconSuffix = "Unknown"; |
||
511 | end |
||
512 | end |
||
513 | |||
514 | return "Interface\\AddOns\\GroupCalendar\\Textures\\Icon-"..vIconSuffix; |
||
515 | end |
||
516 | |||
517 | function Calendar_UpdateCompiledEventIcon(pDate, pCompiledSchedule, pCutoffServerDateTime) |
||
518 | if pDate < gCalendarDisplayStartDate or pDate >= gCalendarDisplayEndDate then |
||
519 | return; |
||
520 | end |
||
521 | |||
522 | local vIndex = pDate - gCalendarDisplayStartDate + gCalendarDisplayStartDayOfWeek; |
||
523 | local vDayIcon = getglobal("GroupCalendarDay"..vIndex.."Icon"); |
||
524 | local vOverlayIcon = getglobal("GroupCalendarDay"..vIndex.."OverlayIcon"); |
||
525 | local vCircledDate = getglobal("GroupCalendarDay"..vIndex.."CircledDate"); |
||
526 | local vDogEarIcon = getglobal("GroupCalendarDay"..vIndex.."DogEarIcon"); |
||
527 | |||
528 | vOverlayIcon:Hide(); |
||
529 | |||
530 | if pCompiledSchedule then |
||
531 | local vDayIconType = nil; |
||
532 | local vUnqualifiedDayIconType = nil; |
||
533 | local vExpiredDayIconType = nil; |
||
534 | local vExpiredUnqualifiedDayIconType = nil; |
||
535 | local vResetEventType = nil; |
||
536 | local vExpiredResetEventType = nil; |
||
537 | |||
538 | local vShowBirthdayIcon = false; |
||
539 | local vHasAppointment = false; |
||
540 | local vAppointmentIsDimmed = false; |
||
541 | local vGotDogEarEvent = false; |
||
542 | |||
543 | for vEventIndex, vCompiledEvent in pCompiledSchedule do |
||
544 | local vPlayerIsQualified = EventDatabase_PlayerIsQualifiedForEvent(vCompiledEvent.mEvent, gGroupCalendar_PlayerLevel); |
||
545 | |||
546 | if vCompiledEvent.mEvent.mType then |
||
547 | -- Determine if the event is expired |
||
548 | |||
549 | local vEventIsExpired = false; |
||
550 | |||
551 | if pCutoffServerDateTime |
||
552 | and vCompiledEvent.mEvent.mTime |
||
553 | and vCompiledEvent.mEvent.mDuration then |
||
554 | local vEventStartDateTime = vCompiledEvent.mEvent.mDate * gCalendarMinutesPerDay + vCompiledEvent.mEvent.mTime; |
||
555 | local vEventEndDateTime = vEventStartDateTime + vCompiledEvent.mEvent.mDuration; |
||
556 | |||
557 | vEventIsExpired = vEventEndDateTime <= pCutoffServerDateTime; |
||
558 | end |
||
559 | |||
560 | -- Check for birthday events |
||
561 | |||
562 | if vCompiledEvent.mEvent.mType == "Birth" then |
||
563 | vShowBirthdayIcon = true; |
||
564 | |||
565 | -- Check for cooldown/reset events |
||
566 | |||
567 | elseif EventDatabase_IsResetEventType(vCompiledEvent.mEvent.mType) then |
||
568 | |||
569 | if vEventIsExpired then |
||
570 | if not vExpiredResetEventType then |
||
571 | vExpiredResetEventType = vCompiledEvent.mEvent.mType; |
||
572 | end |
||
573 | else |
||
574 | if not vResetEventType then |
||
575 | vResetEventType = vCompiledEvent.mEvent.mType; |
||
576 | end |
||
577 | end |
||
578 | |||
579 | -- Check for ordinary events |
||
580 | |||
581 | else |
||
582 | local vIconPath = Calendar_GetEventTypeIconPath(vCompiledEvent.mEvent.mType); |
||
583 | |||
584 | if not vPlayerIsQualified then |
||
585 | if vEventIsExpired then |
||
586 | if not vExpiredUnqualifiedDayIconType then |
||
587 | vExpiredUnqualifiedDayIconType = vIconPath; |
||
588 | end |
||
589 | else |
||
590 | if not vUnqualifiedDayIconType then |
||
591 | vUnqualifiedDayIconType = vIconPath; |
||
592 | end |
||
593 | end |
||
594 | else |
||
595 | if vEventIsExpired then |
||
596 | if not vExpiredDayIconType then |
||
597 | vExpiredDayIconType = vIconPath; |
||
598 | end |
||
599 | else |
||
600 | if not vDayIconType then |
||
601 | vDayIconType = vIconPath; |
||
602 | end |
||
603 | end |
||
604 | end |
||
605 | end -- else Birth |
||
606 | end -- if mType |
||
607 | |||
608 | if (not vHasAppointment |
||
609 | or (vAppointmentIsDimmed and vPlayerIsQualified)) |
||
610 | and EventDatabase_PlayerIsAttendingEvent(vCompiledEvent.mOwner, vCompiledEvent.mEvent) then |
||
611 | vHasAppointment = true; |
||
612 | vAppointmentIsDimmed = not vPlayerIsQualified; |
||
613 | end |
||
614 | end -- for vEventIndex |
||
615 | |||
616 | -- Update the day icon |
||
617 | |||
618 | if vDayIconType then |
||
619 | vDayIcon:SetTexture(vDayIconType); |
||
620 | vDayIcon:SetAlpha(1.0); |
||
621 | vDayIcon:Show(); |
||
622 | elseif vUnqualifiedDayIconType then |
||
623 | vDayIcon:SetTexture(vUnqualifiedDayIconType); |
||
624 | vDayIcon:SetAlpha(0.25); |
||
625 | vDayIcon:Show(); |
||
626 | elseif vExpiredDayIconType then |
||
627 | vDayIcon:SetTexture(vExpiredDayIconType); |
||
628 | vDayIcon:SetAlpha(1.0); |
||
629 | vDayIcon:Show(); |
||
630 | elseif vExpiredUnqualifiedDayIconType then |
||
631 | vDayIcon:SetTexture(vExpiredUnqualifiedDayIconType); |
||
632 | vDayIcon:SetAlpha(0.25); |
||
633 | vDayIcon:Show(); |
||
634 | else |
||
635 | vDayIcon:SetTexture(nil); |
||
636 | vDayIcon:Hide(); |
||
637 | end |
||
638 | |||
639 | -- Show or hide the birthday icon |
||
640 | |||
641 | if vShowBirthdayIcon then |
||
642 | vOverlayIcon:SetTexture(Calendar_GetEventTypeIconPath("Birth")); |
||
643 | vOverlayIcon:Show(); |
||
644 | else |
||
645 | vOverlayIcon:Hide(); |
||
646 | end |
||
647 | |||
648 | -- Circle the date if necessary |
||
649 | |||
650 | if vHasAppointment then |
||
651 | if vAppointmentIsDimmed then |
||
652 | -- Show dimmed |
||
653 | |||
654 | vCircledDate:Show(); |
||
655 | vCircledDate:SetAlpha(0.4); |
||
656 | else |
||
657 | -- Show full brightness |
||
658 | |||
659 | vCircledDate:Show(); |
||
660 | vCircledDate:SetAlpha(1.0); |
||
661 | end |
||
662 | else |
||
663 | vCircledDate:Hide(); |
||
664 | end |
||
665 | |||
666 | -- Show the dog ear |
||
667 | |||
668 | if vResetEventType |
||
669 | or vExpiredResetEventType then |
||
670 | if not vResetEventType then |
||
671 | vResetEventType = vExpiredResetEventType; |
||
672 | end |
||
673 | |||
674 | local vIconCoords = EventDatabase_GetResetIconCoords(vResetEventType); |
||
675 | |||
676 | if vIconCoords then |
||
677 | vDogEarIcon:SetTexCoord(vIconCoords.left, vIconCoords.right, vIconCoords.top, vIconCoords.bottom); |
||
678 | vDogEarIcon:Show(); |
||
679 | else |
||
680 | vDogEarIcon:Hide(); |
||
681 | end |
||
682 | else |
||
683 | vDogEarIcon:Hide(); |
||
684 | end |
||
685 | |||
686 | else -- if pCompiledSchedule |
||
687 | vDayIcon:SetTexture(nil); |
||
688 | vDayIcon:Hide(); |
||
689 | end |
||
690 | end |
||
691 | |||
692 | function Calendar_GetCurrentCutoffDateTime() |
||
693 | local vCurrentDate, vCurrentTime; |
||
694 | local vCurrentServerDateTime; |
||
695 | |||
696 | if gGroupCalendar_Settings.ShowEventsInLocalTime then |
||
697 | local vServerDate, vServerTime; |
||
698 | |||
699 | vCurrentDate, vCurrentTime = Calendar_GetCurrentLocalDateTime(); |
||
700 | vServerDate, vServerTime = Calendar_GetServerDateTimeFromLocalDateTime(vCurrentDate, vCurrentTime); |
||
701 | vCurrentServerDateTime = vServerDate * gCalendarMinutesPerDay + vServerTime; |
||
702 | else |
||
703 | vCurrentDate, vCurrentTime = Calendar_GetCurrentServerDateTime(); |
||
704 | vCurrentServerDateTime = vCurrentDate * gCalendarMinutesPerDay + vCurrentTime; |
||
705 | end |
||
706 | |||
707 | return vCurrentDate, vCurrentTime, vCurrentServerDateTime; |
||
708 | end |
||
709 | |||
710 | function Calendar_UpdateEventIcons() |
||
711 | local vIndex = gCalendarDisplayStartDayOfWeek; |
||
712 | local vCurrentDate, vCurrentTime, vCurrentServerDateTime = Calendar_GetCurrentCutoffDateTime(); |
||
713 | |||
714 | for vDate = gCalendarDisplayStartDate, gCalendarDisplayEndDate - 1 do |
||
715 | local vCompiledSchedule = EventDatabase_GetCompiledSchedule(vDate); |
||
716 | local vCutoffDateTime = nil; |
||
717 | |||
718 | if vDate == vCurrentDate then |
||
719 | vCutoffDateTime = vCurrentServerDateTime; |
||
720 | end |
||
721 | |||
722 | Calendar_UpdateCompiledEventIcon(vDate, vCompiledSchedule, vCutoffDateTime); |
||
723 | |||
724 | vIndex = vIndex + 1; |
||
725 | end |
||
726 | end |
||
727 | |||
728 | function Calendar_ScheduleChanged(pDate, pSchedule) |
||
729 | if not GroupCalendarFrame:IsVisible() then |
||
730 | return; |
||
731 | end |
||
732 | |||
733 | local vCompiledSchedule = EventDatabase_GetCompiledSchedule(pDate); |
||
734 | local vCurrentDate, vCurrentTime, vCurrentServerDateTime = Calendar_GetCurrentCutoffDateTime(); |
||
735 | local vCutoffDateTime = nil; |
||
736 | |||
737 | if pDate == vCurrentDate then |
||
738 | vCutoffDateTime = vCurrentServerDateTime; |
||
739 | end |
||
740 | |||
741 | Calendar_UpdateCompiledEventIcon(pDate, vCompiledSchedule, vCutoffDateTime); |
||
742 | end |
||
743 | |||
744 | function Calendar_MajorDatabaseChange() |
||
745 | if not GroupCalendarFrame:IsVisible() then |
||
746 | return; |
||
747 | end |
||
748 | |||
749 | Calendar_UpdateEventIcons(); |
||
750 | end |
||
751 | |||
752 | function Calendar_NextMonth() |
||
753 | local vMonth, vDay, vYear = Calendar_ConvertDateToMDY(gCalendarDisplayStartDate); |
||
754 | |||
755 | vMonth = vMonth + 1; |
||
756 | |||
757 | if vMonth == 13 then |
||
758 | vMonth = 1; |
||
759 | vYear = vYear + 1; |
||
760 | end |
||
761 | |||
762 | Calendar_SetDisplayDate(Calendar_ConvertMDYToDate(vMonth, 1, vYear)); |
||
763 | end |
||
764 | |||
765 | function Calendar_PreviousMonth() |
||
766 | local vMonth, vDay, vYear = Calendar_ConvertDateToMDY(gCalendarDisplayStartDate); |
||
767 | |||
768 | vMonth = vMonth - 1; |
||
769 | |||
770 | if vMonth == 0 then |
||
771 | vMonth = 12; |
||
772 | vYear = vYear - 1; |
||
773 | end |
||
774 | |||
775 | Calendar_SetDisplayDate(Calendar_ConvertMDYToDate(vMonth, 1, vYear)); |
||
776 | end |
||
777 | |||
778 | function Calendar_Today() |
||
779 | local vMonth, vDay, vYear = Calendar_ConvertDateToMDY(gCalendarActualDate); |
||
780 | |||
781 | Calendar_SetDisplayDate(Calendar_ConvertMDYToDate(vMonth, 1, vYear)); |
||
782 | GroupCalendar_SelectDateWithToggle(gCalendarActualDate); |
||
783 | end |
||
784 | |||
785 | function Calendar_SetCalendarRange(pStartDay, pNumDays) |
||
786 | -- Hide days before the start day |
||
787 | |||
788 | gCalendarDisplayStartDayOfWeek = pStartDay; |
||
789 | |||
790 | for vIndex = 0, pStartDay - 1 do |
||
791 | local vDayButton = getglobal("GroupCalendarDay"..vIndex); |
||
792 | vDayButton:Hide(); |
||
793 | end |
||
794 | |||
795 | -- Set the text of the days |
||
796 | |||
797 | for vIndex = pStartDay, pStartDay + pNumDays - 1 do |
||
798 | local vDayNumber = vIndex - pStartDay + 1; |
||
799 | |||
800 | local vDayButton = getglobal("GroupCalendarDay"..vIndex); |
||
801 | local vDayIcon = getglobal("GroupCalendarDay"..vIndex.."Icon"); |
||
802 | local vDayText = getglobal("GroupCalendarDay"..vIndex.."Name"); |
||
803 | |||
804 | vDayButton:Show(); |
||
805 | vDayText:SetText(vDayNumber); |
||
806 | end |
||
807 | |||
808 | -- Hide the days after the end day |
||
809 | |||
810 | for vIndex = pStartDay + pNumDays, 36 do |
||
811 | local vDayButton = getglobal("GroupCalendarDay"..vIndex); |
||
812 | vDayButton:Hide(); |
||
813 | end |
||
814 | end |
||
815 | |||
816 | function Calendar_GetDaysInMonth(pMonth, pYear) |
||
817 | if pMonth == 2 and Calendar_IsLeapYear(pYear) then |
||
818 | return gDaysInMonth[pMonth] + 1; |
||
819 | else |
||
820 | return gDaysInMonth[pMonth]; |
||
821 | end |
||
822 | end |
||
823 | |||
824 | function Calendar_GetDaysToMonth(pMonth, pYear) |
||
825 | if pMonth > 2 and Calendar_IsLeapYear(pYear) then |
||
826 | return gDaysToMonth[pMonth] + 1; |
||
827 | elseif pMonth == 2 then |
||
828 | return gDaysToMonth[pMonth]; |
||
829 | else |
||
830 | return 0; |
||
831 | end |
||
832 | end |
||
833 | |||
834 | function Calendar_GetDaysInYear(pYear) |
||
835 | if Calendar_IsLeapYear(pYear) then |
||
836 | return 366; |
||
837 | else |
||
838 | return 365; |
||
839 | end |
||
840 | end |
||
841 | |||
842 | function Calendar_IsLeapYear(pYear) |
||
843 | return (math.mod(pYear, 400) == 0) |
||
844 | or ((math.mod(pYear, 4) == 0) and (math.mod(pYear, 100) ~= 0)); |
||
845 | end |
||
846 | |||
847 | function Calendar_GetDaysToDate(pMonth, pDay, pYear) |
||
848 | local vDays; |
||
849 | |||
850 | vDays = gDaysToMonth[pMonth] + pDay - 1; |
||
851 | |||
852 | if Calendar_IsLeapYear(pYear) and pMonth > 2 then |
||
853 | vDays = vDays + 1; |
||
854 | end |
||
855 | |||
856 | return vDays; |
||
857 | end |
||
858 | |||
859 | function Calendar_ConvertMDYToDate(pMonth, pDay, pYear) |
||
860 | local vDays = 0; |
||
861 | |||
862 | for vYear = 2000, pYear - 1 do |
||
863 | vDays = vDays + Calendar_GetDaysInYear(vYear); |
||
864 | end |
||
865 | |||
866 | return vDays + Calendar_GetDaysToDate(pMonth, pDay, pYear); |
||
867 | end |
||
868 | |||
869 | function Calendar_ConvertDateToMDY(pDate) |
||
870 | local vDays = pDate; |
||
871 | local vYear = 2000; |
||
872 | local vDaysInYear = Calendar_GetDaysInYear(vYear); |
||
873 | |||
874 | while vDays >= vDaysInYear do |
||
875 | vDays = vDays - vDaysInYear; |
||
876 | |||
877 | vYear = vYear + 1; |
||
878 | vDaysInYear = Calendar_GetDaysInYear(vYear); |
||
879 | end |
||
880 | |||
881 | local vIsLeapYear = Calendar_IsLeapYear(vYear); |
||
882 | |||
883 | for vMonth = 1, 12 do |
||
884 | local vDaysInMonth = gDaysInMonth[vMonth]; |
||
885 | |||
886 | if vMonth == 2 and vIsLeapYear then |
||
887 | vDaysInMonth = vDaysInMonth + 1; |
||
888 | end |
||
889 | |||
890 | if vDays < vDaysInMonth then |
||
891 | return vMonth, vDays + 1, vYear; |
||
892 | end |
||
893 | |||
894 | vDays = vDays - vDaysInMonth; |
||
895 | end |
||
896 | |||
897 | -- error |
||
898 | |||
899 | Calendar_DebugMessage("Calendar_ConvertDateToMDY: Failed: "..vDays.." unaccounted for in year "..vYear); |
||
900 | |||
901 | return 0, 0, 0; |
||
902 | end |
||
903 | |||
904 | function Calendar_GetDayOfWeek(pMonth, pDay, pYear) |
||
905 | local vDayOfWeek = 6; -- January 1, 2000 is a Saturday |
||
906 | |||
907 | for vYear = 2000, pYear - 1 do |
||
908 | if Calendar_IsLeapYear(vYear) then |
||
909 | vDayOfWeek = vDayOfWeek + 2; |
||
910 | else |
||
911 | vDayOfWeek = vDayOfWeek + 1; |
||
912 | end |
||
913 | end |
||
914 | |||
915 | vDayOfWeek = vDayOfWeek + Calendar_GetDaysToDate(pMonth, pDay, pYear); |
||
916 | |||
917 | return math.mod(vDayOfWeek, 7); |
||
918 | end |
||
919 | |||
920 | function Calendar_GetDayOfWeekFromDate(pDate) |
||
921 | return math.mod(pDate + 6, 7); -- + 6 because January 1, 2000 is a Saturday |
||
922 | end |
||
923 | |||
924 | function CalendarHourDropDown_OnLoad() |
||
925 | UIDropDownMenu_Initialize(this, CalendarHourDropDown_Initialize); |
||
926 | UIDropDownMenu_SetWidth(42); |
||
927 | UIDropDownMenu_Refresh(this); |
||
928 | end |
||
929 | |||
930 | function CalendarMinuteDropDown_OnLoad() |
||
931 | UIDropDownMenu_Initialize(this, CalendarMinuteDropDown_Initialize); |
||
932 | UIDropDownMenu_SetWidth(43); |
||
933 | UIDropDownMenu_Refresh(this); |
||
934 | end |
||
935 | |||
936 | function CalendarAMPMDropDown_OnLoad() |
||
937 | if TwentyFourHourTime then |
||
938 | this:Hide(); |
||
939 | else |
||
940 | UIDropDownMenu_Initialize(this, CalendarAMPMDropDown_Initialize); |
||
941 | UIDropDownMenu_SetWidth(48); |
||
942 | UIDropDownMenu_Refresh(this); |
||
943 | end |
||
944 | end |
||
945 | |||
946 | function CalendarDurationDropDown_OnLoad() |
||
947 | UIDropDownMenu_Initialize(this, CalendarDurationDropDown_Initialize); |
||
948 | UIDropDownMenu_SetWidth(120); |
||
949 | UIDropDownMenu_Refresh(this); |
||
950 | end |
||
951 | |||
952 | function CalendarEventTypeDropDown_OnLoad() |
||
953 | UIDropDownMenu_Initialize(this, CalendarEventTypeDropDown_Initialize); |
||
954 | UIDropDownMenu_SetWidth(150); |
||
955 | UIDropDownMenu_Refresh(this); |
||
956 | end |
||
957 | |||
958 | function CalendarGuildRank_OnLoad() |
||
959 | UIDropDownMenu_Initialize(this, CalendarGuildRankDropDown_Initialize); |
||
960 | UIDropDownMenu_SetWidth(100); |
||
961 | UIDropDownMenu_Refresh(this); |
||
962 | end |
||
963 | |||
964 | function CalendarTrustGroup_OnLoad() |
||
965 | UIDropDownMenu_Initialize(this, CalendarTrustGroupDropDown_Initialize); |
||
966 | UIDropDownMenu_SetWidth(220); |
||
967 | UIDropDownMenu_Refresh(this); |
||
968 | end |
||
969 | |||
970 | function CalendarPartySizeDropDown_OnLoad() |
||
971 | UIDropDownMenu_Initialize(this, CalendarPartySizeDropDown_Initialize); |
||
972 | UIDropDownMenu_SetWidth(130); |
||
973 | UIDropDownMenu_Refresh(this); |
||
974 | end |
||
975 | |||
976 | function CalendarPriorityDropDown_OnLoad() |
||
977 | UIDropDownMenu_Initialize(this, CalendarPriorityDropDown_Initialize); |
||
978 | UIDropDownMenu_SetWidth(130); |
||
979 | UIDropDownMenu_Refresh(this); |
||
980 | end |
||
981 | |||
982 | function CalendarCharactersDropDown_OnLoad() |
||
983 | UIDropDownMenu_Initialize(this, CalendarCharactersDropDown_Initialize); |
||
984 | UIDropDownMenu_SetWidth(110); |
||
985 | UIDropDownMenu_Refresh(this); |
||
986 | end |
||
987 | |||
988 | function CalendarAttendanceDropDown_OnLoad() |
||
989 | UIDropDownMenu_SetAnchor(-1, 4, this, "TOPLEFT", this:GetName(), "TOPRIGHT"); |
||
990 | UIDropDownMenu_Initialize(this, CalendarAttendanceDropDown_Initialize); |
||
991 | --UIDropDownMenu_Refresh(this); -- Don't refresh on menus which don't have a text portion |
||
992 | end |
||
993 | |||
994 | function CalendarClassDropDown_OnLoad() |
||
995 | UIDropDownMenu_Initialize(this, CalendarClassDropDown_Initialize); |
||
996 | UIDropDownMenu_SetWidth(110); |
||
997 | UIDropDownMenu_Refresh(this); |
||
998 | end |
||
999 | |||
1000 | function CalendarRaceDropDown_OnLoad() |
||
1001 | UIDropDownMenu_Initialize(this, CalendarRaceDropDown_Initialize); |
||
1002 | UIDropDownMenu_SetWidth(110); |
||
1003 | UIDropDownMenu_Refresh(this); |
||
1004 | end |
||
1005 | |||
1006 | function CalendarStatusDropDown_OnLoad() |
||
1007 | UIDropDownMenu_Initialize(this, CalendarStatusDropDown_Initialize); |
||
1008 | UIDropDownMenu_SetWidth(110); |
||
1009 | UIDropDownMenu_Refresh(this); |
||
1010 | end |
||
1011 | |||
1012 | function GroupCalendarViewMenu_OnLoad() |
||
1013 | UIDropDownMenu_Initialize(this, GroupCalendarViewMenu_Initialize); |
||
1014 | UIDropDownMenu_SetWidth(100); |
||
1015 | UIDropDownMenu_Refresh(this); |
||
1016 | end |
||
1017 | |||
1018 | function CalendarHourDropDown_Initialize() |
||
1019 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1020 | local vStartHour, vEndHour; |
||
1021 | |||
1022 | if TwentyFourHourTime then |
||
1023 | vStartHour = 0; |
||
1024 | vEndHour = 23; |
||
1025 | else |
||
1026 | vStartHour = 1; |
||
1027 | vEndHour = 12; |
||
1028 | end |
||
1029 | |||
1030 | for vIndex = vStartHour, vEndHour do |
||
1031 | vItem = {}; |
||
1032 | vItem.text = ""..vIndex; |
||
1033 | vItem.value = vIndex; |
||
1034 | vItem.owner = vFrame; |
||
1035 | vItem.func = CalendarDropDown_OnClick; |
||
1036 | UIDropDownMenu_AddButton(vItem); |
||
1037 | end |
||
1038 | end |
||
1039 | |||
1040 | function CalendarMinuteDropDown_Initialize() |
||
1041 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1042 | |||
1043 | for vIndex = 0, 59, 5 do |
||
1044 | vItem = {}; |
||
1045 | if vIndex < 10 then |
||
1046 | vItem.text = "0"..vIndex; |
||
1047 | else |
||
1048 | vItem.text = ""..vIndex; |
||
1049 | end |
||
1050 | |||
1051 | vItem.value = vIndex; |
||
1052 | vItem.owner = vFrame; |
||
1053 | vItem.func = CalendarDropDown_OnClick; |
||
1054 | |||
1055 | UIDropDownMenu_AddButton(vItem); |
||
1056 | end |
||
1057 | end |
||
1058 | |||
1059 | function CalendarAMPMDropDown_Initialize() |
||
1060 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1061 | |||
1062 | -- |
||
1063 | |||
1064 | local vItem = {}; |
||
1065 | vItem.text = "AM"; |
||
1066 | vItem.value = 0; |
||
1067 | vItem.owner = vFrame; |
||
1068 | vItem.func = CalendarDropDown_OnClick; |
||
1069 | |||
1070 | UIDropDownMenu_AddButton(vItem); |
||
1071 | |||
1072 | -- |
||
1073 | |||
1074 | local vItem = {}; |
||
1075 | vItem.text = "PM"; |
||
1076 | vItem.value = 1; |
||
1077 | vItem.owner = vFrame; |
||
1078 | vItem.func = CalendarDropDown_OnClick; |
||
1079 | |||
1080 | UIDropDownMenu_AddButton(vItem); |
||
1081 | end |
||
1082 | |||
1083 | function CalendarDurationDropDown_Initialize() |
||
1084 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1085 | |||
1086 | -- |
||
1087 | |||
1088 | local vDurations = {15, 30, 60, 90, 120, 150, 180, 240, 300, 360}; |
||
1089 | |||
1090 | for _, vDuration in vDurations do |
||
1091 | local vItem = {}; |
||
1092 | |||
1093 | local vMinutes = math.mod(vDuration, 60); |
||
1094 | local vHours = (vDuration - vMinutes) / 60; |
||
1095 | |||
1096 | if vHours == 0 then |
||
1097 | vItem.text = format(GroupCalendar_cPluralMinutesFormat, vMinutes); |
||
1098 | else |
||
1099 | if vMinutes ~= 0 then |
||
1100 | if vHours == 1 then |
||
1101 | vItem.text = format(GroupCalendar_cSingularHourPluralMinutes, vHours, vMinutes); |
||
1102 | else |
||
1103 | vItem.text = format(GroupCalendar_cPluralHourPluralMinutes, vHours, vMinutes); |
||
1104 | end |
||
1105 | else |
||
1106 | if vHours == 1 then |
||
1107 | vItem.text = format(GroupCalendar_cSingularHourFormat, vHours); |
||
1108 | elseif vHours > 0 then |
||
1109 | vItem.text = format(GroupCalendar_cPluralHourFormat, vHours); |
||
1110 | end |
||
1111 | end |
||
1112 | end |
||
1113 | |||
1114 | vItem.value = vDuration; |
||
1115 | vItem.owner = vFrame; |
||
1116 | vItem.func = CalendarDropDown_OnClick; |
||
1117 | |||
1118 | UIDropDownMenu_AddButton(vItem); |
||
1119 | end |
||
1120 | end |
||
1121 | |||
1122 | function Calendar_AddDividerMenuItem() |
||
1123 | UIDropDownMenu_AddButton({text = " ", notCheckable = true, notClickable = true}); |
||
1124 | end |
||
1125 | |||
1126 | function Calendar_AddCategoryMenuItem(pName) |
||
1127 | UIDropDownMenu_AddButton({text = pName, notCheckable = true, notClickable = true}); |
||
1128 | end |
||
1129 | |||
1130 | function Calendar_AddMenuItem(pFrame, pName, pValue, pChecked, pLevel) |
||
1131 | UIDropDownMenu_AddButton({text = pName, value = pValue, owner = pFrame, checked = pChecked, func = CalendarDropDown_OnClick, textR = NORMAL_FONT_COLOR.r, textG = NORMAL_FONT_COLOR.g, textB = NORMAL_FONT_COLOR.b}, pLevel); |
||
1132 | end |
||
1133 | |||
1134 | function Calendar_AddMenuItem2(pFrame, pName, pValue, pChecked, pLevel) |
||
1135 | UIDropDownMenu_AddButton({text = pName, value = pValue, owner = pFrame, checked = pChecked, func = CalendarDropDown_OnClick2, textR = NORMAL_FONT_COLOR.r, textG = NORMAL_FONT_COLOR.g, textB = NORMAL_FONT_COLOR.b}, pLevel); |
||
1136 | end |
||
1137 | |||
1138 | function CalendarEventTypeDropDown_AddEventGroupSubMenu(pFrame, pEventGroupName) |
||
1139 | local vEventTypes = gGroupCalendar_EventTypes[pEventGroupName]; |
||
1140 | |||
1141 | local vItem = {}; |
||
1142 | |||
1143 | vItem.text = vEventTypes.Title; |
||
1144 | vItem.owner = pFrame; |
||
1145 | vItem.hasArrow = 1; |
||
1146 | --vItem.notCheckable = 1; |
||
1147 | vItem.value = pEventGroupName; |
||
1148 | vItem.func = nil; |
||
1149 | |||
1150 | UIDropDownMenu_AddButton(vItem); |
||
1151 | end |
||
1152 | |||
1153 | function CalendarEventTypeDropDown_AddEventTypes(pFrame, pEventGroupName, pMenuLevel) |
||
1154 | local vEventTypes = gGroupCalendar_EventTypes[pEventGroupName]; |
||
1155 | |||
1156 | for vIndex, vEventItem in vEventTypes.Events do |
||
1157 | local vItem = {}; |
||
1158 | |||
1159 | vItem.text = vEventItem.name; |
||
1160 | vItem.value = vEventItem.id; |
||
1161 | vItem.owner = pFrame; |
||
1162 | vItem.func = CalendarDropDown_OnClick; |
||
1163 | |||
1164 | UIDropDownMenu_AddButton(vItem, pMenuLevel); |
||
1165 | end |
||
1166 | end |
||
1167 | |||
1168 | function CalendarEventTypeDropDown_Initialize() |
||
1169 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1170 | |||
1171 | if UIDROPDOWNMENU_MENU_LEVEL == 2 then |
||
1172 | CalendarEventTypeDropDown_AddEventTypes(vFrame, UIDROPDOWNMENU_MENU_VALUE, UIDROPDOWNMENU_MENU_LEVEL); |
||
1173 | else |
||
1174 | -- Populate the root menu items |
||
1175 | |||
1176 | CalendarEventTypeDropDown_AddEventTypes(vFrame, "General"); |
||
1177 | Calendar_AddDividerMenuItem(vFrame); |
||
1178 | CalendarEventTypeDropDown_AddEventGroupSubMenu(vFrame, "Dungeon"); |
||
1179 | CalendarEventTypeDropDown_AddEventGroupSubMenu(vFrame, "Battleground"); |
||
1180 | end |
||
1181 | end |
||
1182 | |||
1183 | function CalendarGuildRankDropDown_Initialize() |
||
1184 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1185 | local vNumRanks = GuildControlGetNumRanks(); |
||
1186 | |||
1187 | for vIndex = 1, vNumRanks do |
||
1188 | local vRankName = GuildControlGetRankName(vIndex); |
||
1189 | local vItem = {}; |
||
1190 | |||
1191 | vItem.text = vRankName; |
||
1192 | vItem.value = vIndex - 1; |
||
1193 | vItem.owner = vFrame; |
||
1194 | vItem.func = CalendarDropDown_OnClick; |
||
1195 | |||
1196 | UIDropDownMenu_AddButton(vItem); |
||
1197 | end |
||
1198 | end |
||
1199 | |||
1200 | function CalendarTrustGroupDropDown_Initialize() |
||
1201 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1202 | |||
1203 | for vIndex, vText in GroupCalendar_cTrustGroups do |
||
1204 | if vIndex ~= 2 |
||
1205 | or IsInGuild() then |
||
1206 | local vItem = {}; |
||
1207 | |||
1208 | vItem.text = vText; |
||
1209 | vItem.value = vIndex; |
||
1210 | vItem.owner = vFrame; |
||
1211 | vItem.func = CalendarDropDown_OnClick; |
||
1212 | |||
1213 | UIDropDownMenu_AddButton(vItem); |
||
1214 | end |
||
1215 | end |
||
1216 | end |
||
1217 | |||
1218 | function CalendarPartySizeDropDown_Initialize() |
||
1219 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1220 | local vSizes = {0, 5, 10, 15, 20, 40}; |
||
1221 | |||
1222 | for vIndex, vSize in vSizes do |
||
1223 | local vText = vSize; |
||
1224 | |||
1225 | if vText == 0 then |
||
1226 | vText = GroupCalendar_cNoMaximum; |
||
1227 | else |
||
1228 | vText = format(GroupCalendar_cPartySizeFormat, vSize); |
||
1229 | end |
||
1230 | |||
1231 | UIDropDownMenu_AddButton({text = vText, value = vSize, owner = vFrame, func = CalendarDropDown_OnClick}); |
||
1232 | end |
||
1233 | end |
||
1234 | |||
1235 | function CalendarPriorityDropDown_Initialize() |
||
1236 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1237 | |||
1238 | Calendar_AddMenuItem(vFrame, GroupCalendar_cPriorityDate, "Date") |
||
1239 | Calendar_AddMenuItem(vFrame, GroupCalendar_cPriorityRank, "Rank") |
||
1240 | end |
||
1241 | |||
1242 | function CalendarCharactersDropDown_Initialize() |
||
1243 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1244 | local vOwnedDatabases = EventDatabase_GetOwnedDatabases(); |
||
1245 | |||
1246 | for vIndex, vDatabase in vOwnedDatabases do |
||
1247 | local vItem = {}; |
||
1248 | |||
1249 | vItem.text = vDatabase.UserName; |
||
1250 | vItem.value = vDatabase.UserName; |
||
1251 | vItem.owner = vFrame; |
||
1252 | vItem.func = CalendarDropDown_OnClick; |
||
1253 | |||
1254 | UIDropDownMenu_AddButton(vItem); |
||
1255 | end |
||
1256 | end |
||
1257 | |||
1258 | function CalendarAttendanceDropDown_Initialize() |
||
1259 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1260 | local vAttendanceItem = vFrame:GetParent(); |
||
1261 | local vItem = vAttendanceItem.Item; |
||
1262 | |||
1263 | if vItem then |
||
1264 | if vItem.mType == "Whisper" then |
||
1265 | Calendar_AddCategoryMenuItem(vItem.mName); |
||
1266 | Calendar_AddMenuItem2(vFrame, GroupCalendar_cAddPlayerEllipses, "ADD"); |
||
1267 | Calendar_AddMenuItem2(vFrame, GroupCalendar_cRemove, "DELETE"); |
||
1268 | else |
||
1269 | Calendar_AddCategoryMenuItem(vItem.mName); |
||
1270 | Calendar_AddMenuItem2(vFrame, GroupCalendar_cEditPlayer, "EDIT"); |
||
1271 | Calendar_AddMenuItem2(vFrame, GroupCalendar_cRemove, "DELETE"); |
||
1272 | Calendar_AddCategoryMenuItem(GroupCalendar_cStatus); |
||
1273 | Calendar_AddMenuItem2(vFrame, GroupCalendar_cConfirmed, "Y"); |
||
1274 | Calendar_AddMenuItem2(vFrame, GroupCalendar_cStandby, "S"); |
||
1275 | Calendar_AddMenuItem2(vFrame, GroupCalendar_cDeclined, "N"); |
||
1276 | end |
||
1277 | end |
||
1278 | |||
1279 | vFrame:SetHeight(20); |
||
1280 | end |
||
1281 | |||
1282 | function CalendarClassDropDown_Initialize() |
||
1283 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1284 | |||
1285 | local vItem = {}; |
||
1286 | |||
1287 | vItem.text = GroupCalendar_cUnknown; |
||
1288 | vItem.value = "?"; |
||
1289 | vItem.owner = vFrame; |
||
1290 | vItem.func = CalendarDropDown_OnClick; |
||
1291 | |||
1292 | UIDropDownMenu_AddButton(vItem); |
||
1293 | |||
1294 | for vClassCode, vClassInfo in gGroupCalendar_ClassInfoByClassCode do |
||
1295 | if not vClassInfo.faction |
||
1296 | or vClassInfo.faction == gGroupCalendar_PlayerFactionGroup then |
||
1297 | local vItem = {}; |
||
1298 | |||
1299 | vItem.text = vClassInfo.name; |
||
1300 | vItem.value = vClassCode; |
||
1301 | vItem.owner = vFrame; |
||
1302 | vItem.func = CalendarDropDown_OnClick; |
||
1303 | |||
1304 | UIDropDownMenu_AddButton(vItem); |
||
1305 | end |
||
1306 | end |
||
1307 | end |
||
1308 | |||
1309 | function CalendarRaceDropDown_Initialize() |
||
1310 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1311 | |||
1312 | local vItem = {}; |
||
1313 | |||
1314 | vItem.text = GroupCalendar_cUnknown; |
||
1315 | vItem.value = "?"; |
||
1316 | vItem.owner = vFrame; |
||
1317 | vItem.func = CalendarDropDown_OnClick; |
||
1318 | |||
1319 | UIDropDownMenu_AddButton(vItem); |
||
1320 | |||
1321 | for vRaceCode, vRaceInfo in gGroupCalendar_RaceNamesByRaceCode do |
||
1322 | if vRaceInfo.faction == gGroupCalendar_PlayerFactionGroup then |
||
1323 | local vItem = {}; |
||
1324 | |||
1325 | vItem.text = vRaceInfo.name; |
||
1326 | vItem.value = vRaceCode; |
||
1327 | vItem.owner = vFrame; |
||
1328 | vItem.func = CalendarDropDown_OnClick; |
||
1329 | |||
1330 | UIDropDownMenu_AddButton(vItem); |
||
1331 | end |
||
1332 | end |
||
1333 | end |
||
1334 | |||
1335 | function CalendarStatusDropDown_Initialize() |
||
1336 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1337 | |||
1338 | vItem = {text = GroupCalendar_cConfirmed, value = "Y", owner = vFrame, func = CalendarDropDown_OnClick}; |
||
1339 | UIDropDownMenu_AddButton(vItem); |
||
1340 | |||
1341 | vItem = {text = GroupCalendar_cStandby, value = "S", owner = vFrame, func = CalendarDropDown_OnClick}; |
||
1342 | UIDropDownMenu_AddButton(vItem); |
||
1343 | end |
||
1344 | |||
1345 | function GroupCalendarViewMenu_Initialize() |
||
1346 | local vFrame = getglobal(UIDROPDOWNMENU_INIT_MENU); |
||
1347 | |||
1348 | UIDropDownMenu_AddButton({text = GroupCalendar_cViewByDate, value = "Date", owner = vFrame, func = CalendarDropDown_OnClick}); |
||
1349 | UIDropDownMenu_AddButton({text = GroupCalendar_cViewByRank, value = "Rank", owner = vFrame, func = CalendarDropDown_OnClick}); |
||
1350 | UIDropDownMenu_AddButton({text = GroupCalendar_cViewByName, value = "Name", owner = vFrame, func = CalendarDropDown_OnClick}); |
||
1351 | end |
||
1352 | |||
1353 | function CalendarDropDown_OnClick() |
||
1354 | UIDropDownMenu_SetSelectedValue(this.owner, this.value); |
||
1355 | CalendarDropDown_OnClick2(); |
||
1356 | end |
||
1357 | |||
1358 | function CalendarDropDown_OnClick2() |
||
1359 | if this.owner.ChangedValueFunc then |
||
1360 | this.owner.ChangedValueFunc(this.owner, this.value); |
||
1361 | end |
||
1362 | |||
1363 | CloseDropDownMenus(); |
||
1364 | end |
||
1365 | |||
1366 | function Calendar_SetEditBoxAutoCompleteText(pEditBox, pText) |
||
1367 | local vEditBoxText = strupper(pEditBox:GetText()); |
||
1368 | local vEditBoxTextLength = strlen(vEditBoxText); |
||
1369 | |||
1370 | pEditBox:SetText(pText); |
||
1371 | pEditBox:HighlightText(vEditBoxTextLength, -1); |
||
1372 | end |
||
1373 | |||
1374 | function Calendar_AutoCompletePlayerName(pEditBox) |
||
1375 | if Calendar_AutoCompleteFriend(pEditBox) then |
||
1376 | return true; |
||
1377 | end |
||
1378 | |||
1379 | return Calendar_AutoCompleteGuildMember(pEditBox); |
||
1380 | end |
||
1381 | |||
1382 | function Calendar_AutoCompleteFriend(pEditBox) |
||
1383 | local vNumFriends = GetNumFriends(); |
||
1384 | |||
1385 | if vNumFriends == 0 then |
||
1386 | return false; |
||
1387 | end |
||
1388 | |||
1389 | local vEditBoxText = strupper(pEditBox:GetText()); |
||
1390 | local vEditBoxTextLength = strlen(vEditBoxText); |
||
1391 | |||
1392 | for vIndex = 1, vNumFriends do |
||
1393 | local vName = GetFriendInfo(vIndex); |
||
1394 | |||
1395 | if strfind(strupper(vName), "^"..vEditBoxText) then |
||
1396 | Calendar_SetEditBoxAutoCompleteText(pEditBox, vName); |
||
1397 | return true; |
||
1398 | end |
||
1399 | end |
||
1400 | |||
1401 | return false; |
||
1402 | end |
||
1403 | |||
1404 | function Calendar_AutoCompleteGuildMember(pEditBox) |
||
1405 | local vNumMembers = GetNumGuildMembers(true); |
||
1406 | |||
1407 | if vNumMembers == 0 then |
||
1408 | return false; |
||
1409 | end |
||
1410 | |||
1411 | local vEditBoxText = strupper(pEditBox:GetText()); |
||
1412 | local vEditBoxTextLength = strlen(vEditBoxText); |
||
1413 | |||
1414 | for vIndex = 1, vNumMembers do |
||
1415 | local vName = GetGuildRosterInfo(vIndex); |
||
1416 | |||
1417 | if strfind(strupper(vName), "^"..vEditBoxText) then |
||
1418 | Calendar_SetEditBoxAutoCompleteText(pEditBox, vName); |
||
1419 | return true; |
||
1420 | end |
||
1421 | end |
||
1422 | |||
1423 | return false; |
||
1424 | end |
||
1425 | |||
1426 | function Calendar_InputFrameSizeChanged(pInputFrame) |
||
1427 | local vName = this:GetName(); |
||
1428 | local vWidth = pInputFrame:GetWidth(); |
||
1429 | local vHeight = pInputFrame:GetHeight(); |
||
1430 | |||
1431 | local vTopLeft = getglobal(vName.."TopLeft"); |
||
1432 | local vTop = getglobal(vName.."Top"); |
||
1433 | local vTopRight = getglobal(vName.."TopRight"); |
||
1434 | |||
1435 | local vLeft = getglobal(vName.."Left"); |
||
1436 | local vCenter = getglobal(vName.."Center"); |
||
1437 | local vRight = getglobal(vName.."Right"); |
||
1438 | |||
1439 | local vBottomLeft = getglobal(vName.."BottomLeft"); |
||
1440 | local vBottom = getglobal(vName.."Bottom"); |
||
1441 | local vBottomRight = getglobal(vName.."BottomRight"); |
||
1442 | |||
1443 | local vInnerWidth = vWidth - 12; |
||
1444 | local vInnerHeight = vHeight - 12; |
||
1445 | |||
1446 | vTopLeft:SetWidth(6); vTopLeft:SetHeight(6); |
||
1447 | vTop:SetWidth(vInnerWidth); vTop:SetHeight(6); |
||
1448 | vTopRight:SetWidth(6); vTopRight:SetHeight(6); |
||
1449 | |||
1450 | vLeft:SetWidth(6); vLeft:SetHeight(vInnerHeight); |
||
1451 | vCenter:SetWidth(vInnerWidth); vCenter:SetHeight(vInnerHeight); |
||
1452 | vRight:SetWidth(6); vRight:SetHeight(vInnerHeight); |
||
1453 | |||
1454 | vBottomLeft:SetWidth(6); vBottomLeft:SetHeight(6); |
||
1455 | vBottom:SetWidth(vInnerWidth); vBottom:SetHeight(6); |
||
1456 | vBottomRight:SetWidth(6); vBottomRight:SetHeight(6); |
||
1457 | end |
||
1458 | |||
1459 | function CalendarPlayerList_OnLoad() |
||
1460 | this.ItemFunction = CalendarPlayerList_NullItemFunction; |
||
1461 | this.SelectedIndex = 0; |
||
1462 | end |
||
1463 | |||
1464 | function CalendarPlayerList_OnShow() |
||
1465 | CalendarPlayerList_Update(this); |
||
1466 | end |
||
1467 | |||
1468 | function CalendarPlayerList_SetItemFunction(pPlayerListControl, pItemFunction) |
||
1469 | pPlayerListControl.ItemFunction = pItemFunction; |
||
1470 | end |
||
1471 | |||
1472 | function CalendarPlayerList_SetSelectionChangedFunction(pPlayerListControl, pSelectionChangedFunction) |
||
1473 | pPlayerListControl.SelectionChangedFunction = pSelectionChangedFunction; |
||
1474 | end |
||
1475 | |||
1476 | function CalendarPlayerList_SetColor(pPlayerListControl, pRed, pGreen, pBlue) |
||
1477 | local vControlName = pPlayerListControl:GetName(); |
||
1478 | local vHighlightFrameTextureName = vControlName.."HighlightFrameTexture"; |
||
1479 | local vHighlightFrameTexture = getglobal(vHighlightFrameTextureName); |
||
1480 | |||
1481 | pPlayerListControl.r = pRed; pPlayerListControl.g = pGreen; pPlayerListControl.b = pBlue; |
||
1482 | |||
1483 | for vIndex = 0, 4 do |
||
1484 | CalendarPlayerList_SetIndexedItemFrameColor(pPlayerListControl, vIndex, pRed, pGreen, pBlue); |
||
1485 | end |
||
1486 | |||
1487 | vHighlightFrameTexture:SetVertexColor(pRed, pGreen, pBlue); |
||
1488 | end |
||
1489 | |||
1490 | function CalendarPlayerList_SetIndexedItemFrameColor(pPlayerListControl, pIndex, pRed, pGreen, pBlue) |
||
1491 | local vControlName = pPlayerListControl:GetName(); |
||
1492 | local vItemFrameName = vControlName.."Item"..pIndex; |
||
1493 | local vItemFrame = getglobal(vItemFrameName); |
||
1494 | local vTextItem = getglobal(vItemFrameName.."Text"); |
||
1495 | |||
1496 | vItemFrame.r = pRed; |
||
1497 | vItemFrame.g = pGreen; |
||
1498 | vItemFrame.b = pBlue; |
||
1499 | |||
1500 | vTextItem:SetTextColor(pRed, pGreen, pBlue); |
||
1501 | end |
||
1502 | |||
1503 | gCalendarPlayerList_ActiveList = nil; |
||
1504 | |||
1505 | function CalendarPlayerList_ScrollUpdate() |
||
1506 | CalendarPlayerList_Update(gCalendarPlayerList_ActiveList); |
||
1507 | end |
||
1508 | |||
1509 | function CalendarPlayerList_Update(pPlayerListControl) |
||
1510 | local vControlName = pPlayerListControl:GetName(); |
||
1511 | local vScrollFrame = getglobal(vControlName.."ScrollFrame"); |
||
1512 | local vHighlightFrame = getglobal(vControlName.."HighlightFrame"); |
||
1513 | |||
1514 | local vNumItems = pPlayerListControl.ItemFunction(0); |
||
1515 | |||
1516 | for vIndex = 0, 4 do |
||
1517 | local vItemName = vControlName.."Item"..vIndex; |
||
1518 | local vItemFrame = getglobal(vItemName); |
||
1519 | |||
1520 | if vIndex < vNumItems then |
||
1521 | vItemFrame:Show(); |
||
1522 | else |
||
1523 | vItemFrame:Hide(); |
||
1524 | end |
||
1525 | end |
||
1526 | |||
1527 | FauxScrollFrame_Update( |
||
1528 | vScrollFrame, |
||
1529 | vNumItems, |
||
1530 | gCalendarPlayerList_cNumVisibleEntries, |
||
1531 | gCalendarPlayerList_cItemHeight, |
||
1532 | nil, |
||
1533 | nil, |
||
1534 | nil, |
||
1535 | vHighlightFrame, |
||
1536 | 130, |
||
1537 | 130); |
||
1538 | |||
1539 | CalendarPlayerList_UpdateItems(pPlayerListControl); |
||
1540 | end |
||
1541 | |||
1542 | function CalendarPlayerList_UpdateItems(pPlayerListControl) |
||
1543 | local vControlName = pPlayerListControl:GetName(); |
||
1544 | local vScrollFrame = getglobal(vControlName.."ScrollFrame"); |
||
1545 | local vFirstItemOffset = FauxScrollFrame_GetOffset(vScrollFrame); |
||
1546 | |||
1547 | for vIndex = 0, 4 do |
||
1548 | local vItem = pPlayerListControl.ItemFunction(vIndex + vFirstItemOffset + 1); |
||
1549 | local vItemName = vControlName.."Item"..vIndex; |
||
1550 | local vTextItem = getglobal(vItemName.."Text"); |
||
1551 | |||
1552 | vTextItem:SetText(vItem.Text); |
||
1553 | end |
||
1554 | end |
||
1555 | |||
1556 | function CalendarPlayerList_NullItemFunction(pIndex) |
||
1557 | if pIndex == 0 then |
||
1558 | return 10; |
||
1559 | end |
||
1560 | |||
1561 | return |
||
1562 | { |
||
1563 | Text = "Null item "..pIndex, |
||
1564 | }; |
||
1565 | end |
||
1566 | |||
1567 | function CalendarPlayerListItem_OnClick(pButton) |
||
1568 | local vPlayerListControl = this:GetParent(); |
||
1569 | |||
1570 | local vControlName = vPlayerListControl:GetName(); |
||
1571 | local vScrollFrame = getglobal(vControlName.."ScrollFrame"); |
||
1572 | local vFirstItemOffset = FauxScrollFrame_GetOffset(vScrollFrame); |
||
1573 | |||
1574 | local vPlayerIndex = this:GetID() + vFirstItemOffset + 1; |
||
1575 | |||
1576 | CalendarPlayerList_SelectIndexedPlayer(vPlayerListControl, vPlayerIndex); |
||
1577 | end |
||
1578 | |||
1579 | function CalendarPlayerList_SelectIndexedPlayer(pPlayerListControl, pIndex) |
||
1580 | local vControlName = pPlayerListControl:GetName(); |
||
1581 | local vScrollFrame = getglobal(vControlName.."ScrollFrame"); |
||
1582 | local vHighlightFrame = getglobal(vControlName.."HighlightFrame"); |
||
1583 | |||
1584 | -- Remove the old highlighting |
||
1585 | |||
1586 | if pPlayerListControl.SelectedIndex then |
||
1587 | local vItemFrameIndex = pPlayerListControl.SelectedIndex - FauxScrollFrame_GetOffset(vScrollFrame) - 1; |
||
1588 | |||
1589 | CalendarPlayerList_SetIndexedItemFrameColor(pPlayerListControl, vItemFrameIndex, pPlayerListControl.r, pPlayerListControl.g, pPlayerListControl.b); |
||
1590 | end |
||
1591 | |||
1592 | -- Show the new highlighting |
||
1593 | |||
1594 | if pIndex > 0 then |
||
1595 | local vItemFrameIndex = pIndex - FauxScrollFrame_GetOffset(vScrollFrame) - 1; |
||
1596 | local vItemFrameName = vControlName.."Item"..vItemFrameIndex; |
||
1597 | |||
1598 | vHighlightFrame:SetPoint("TOPLEFT", vItemFrameName, "TOPLEFT", 5, 0); |
||
1599 | vHighlightFrame:Show(); |
||
1600 | |||
1601 | CalendarPlayerList_SetIndexedItemFrameColor(pPlayerListControl, vItemFrameIndex, 1.0, 1.0, 1.0); |
||
1602 | pPlayerListControl.SelectedIndex = pIndex; |
||
1603 | else |
||
1604 | vHighlightFrame:Hide(); |
||
1605 | pPlayerListControl.SelectedIndex = nil; |
||
1606 | end |
||
1607 | |||
1608 | if pPlayerListControl.SelectionChangedFunction then |
||
1609 | pPlayerListControl.SelectionChangedFunction(pIndex); |
||
1610 | end |
||
1611 | end |
||
1612 | |||
1613 | function Calendar_GetChangedFieldList(pOldTable, pNewTable) |
||
1614 | local vChangedFields = {}; |
||
1615 | |||
1616 | for vIndex, vNewValue in pNewTable do |
||
1617 | local vOldValue = pOldTable[vIndex]; |
||
1618 | |||
1619 | if vOldValue == nil then -- New field |
||
1620 | vChangedFields[vIndex] = "NEW"; |
||
1621 | elseif vOldValue ~= vNewValue then -- Changed field |
||
1622 | vChangedFields[vIndex] = "UPD"; |
||
1623 | end |
||
1624 | end |
||
1625 | |||
1626 | for vIndex, vOldValue in pOldTable do |
||
1627 | local vNewValue = pNewTable[vIndex]; |
||
1628 | |||
1629 | if vNewValue == nil then -- Deleted field |
||
1630 | vChangedFields[vIndex] = "DEL"; |
||
1631 | end |
||
1632 | end |
||
1633 | |||
1634 | return vChangedFields; |
||
1635 | end |
||
1636 | |||
1637 | function Calendar_DumpArray(pPrefixString, pArray) |
||
1638 | if not pArray then |
||
1639 | Calendar_DebugMessage(pPrefixString.." is nil"); |
||
1640 | return; |
||
1641 | end |
||
1642 | |||
1643 | local vFoundElement = false; |
||
1644 | |||
1645 | for vIndex, vElement in pArray do |
||
1646 | vFoundElement = true; |
||
1647 | |||
1648 | local vType = type(vElement); |
||
1649 | local vPrefix; |
||
1650 | |||
1651 | if type(vIndex) == "number" then |
||
1652 | vPrefix = pPrefixString.."["..vIndex.."]"; |
||
1653 | else |
||
1654 | vPrefix = pPrefixString.."."..vIndex; |
||
1655 | end |
||
1656 | |||
1657 | if vType == "number" then |
||
1658 | Calendar_DebugMessage(vPrefix.." = "..vElement); |
||
1659 | elseif vType == "string" then |
||
1660 | Calendar_DebugMessage(vPrefix.." = \""..vElement.."\""); |
||
1661 | elseif vType == "boolean" then |
||
1662 | if vElement then |
||
1663 | Calendar_DebugMessage(vPrefix.." = true"); |
||
1664 | else |
||
1665 | Calendar_DebugMessage(vPrefix.." = false"); |
||
1666 | end |
||
1667 | elseif vType == "table" then |
||
1668 | Calendar_DumpArray(vPrefix, vElement); |
||
1669 | else |
||
1670 | Calendar_DebugMessage(vPrefix.." "..vType); |
||
1671 | end |
||
1672 | end |
||
1673 | |||
1674 | if not vFoundElement then |
||
1675 | Calendar_DebugMessage(pPrefixString.." is empty"); |
||
1676 | end |
||
1677 | end |
||
1678 | |||
1679 | -- NOTE: If any of LUA's "magic" characters ever need to be escaped they will |
||
1680 | -- need to be coded properly with a % preceeding them in the cSpecialChars |
||
1681 | -- string. Currently the "magic" characters are: ^$()%.[]*+-? |
||
1682 | |||
1683 | gGroupCalendar_cSpecialChars = ",/:;&|\n"; |
||
1684 | |||
1685 | gGroupCalendar_cSpecialCharMap = |
||
1686 | { |
||
1687 | c = ",", |
||
1688 | s = "/", |
||
1689 | cn = ":", |
||
1690 | sc = ";", |
||
1691 | a = "&", |
||
1692 | b = "|", |
||
1693 | n = "\n", |
||
1694 | }; |
||
1695 | |||
1696 | function Calendar_EscapeString(pString) |
||
1697 | return string.gsub( |
||
1698 | pString, |
||
1699 | "(["..gGroupCalendar_cSpecialChars.."])", |
||
1700 | function (pField) |
||
1701 | for vName, vChar in gGroupCalendar_cSpecialCharMap do |
||
1702 | if vChar == pField then |
||
1703 | return "&"..vName..";"; |
||
1704 | end |
||
1705 | end |
||
1706 | |||
1707 | return ""; |
||
1708 | end); |
||
1709 | end |
||
1710 | |||
1711 | function Calendar_UnescapeString(pString) |
||
1712 | return string.gsub( |
||
1713 | pString, |
||
1714 | "&(%w+);", |
||
1715 | function (pField) |
||
1716 | local vChar = gGroupCalendar_cSpecialCharMap[pField]; |
||
1717 | |||
1718 | if vChar ~= nil then |
||
1719 | return vChar; |
||
1720 | else |
||
1721 | return pField; |
||
1722 | end |
||
1723 | end); |
||
1724 | end |
||
1725 | |||
1726 | -- NOTE: If any of LUA's "magic" characters ever need to be escaped they will |
||
1727 | -- need to be coded properly with a % preceeding them in the cSpecialChars |
||
1728 | -- string. Currently the "magic" characters are: ^$()%.[]*+-? |
||
1729 | |||
1730 | gGroupCalendar_cSpecialChatChars = "`sS"; |
||
1731 | |||
1732 | gGroupCalendar_cSpecialChatCharMap = |
||
1733 | { |
||
1734 | a = "`", |
||
1735 | l = "s", |
||
1736 | u = "S" |
||
1737 | }; |
||
1738 | |||
1739 | function Calendar_EscapeChatString(pString) |
||
1740 | return string.gsub( |
||
1741 | pString, |
||
1742 | "(["..gGroupCalendar_cSpecialChatChars.."])", |
||
1743 | function (pField) |
||
1744 | for vName, vChar in gGroupCalendar_cSpecialChatCharMap do |
||
1745 | if vChar == pField then |
||
1746 | return "`"..vName; |
||
1747 | end |
||
1748 | end |
||
1749 | |||
1750 | return ""; |
||
1751 | end); |
||
1752 | end |
||
1753 | |||
1754 | function Calendar_UnescapeChatString(pString) |
||
1755 | return string.gsub( |
||
1756 | pString, |
||
1757 | "`(.)", |
||
1758 | function (pField) |
||
1759 | local vChar = gGroupCalendar_cSpecialChatCharMap[pField]; |
||
1760 | |||
1761 | if vChar ~= nil then |
||
1762 | return vChar; |
||
1763 | else |
||
1764 | return pField; |
||
1765 | end |
||
1766 | end); |
||
1767 | end |
||
1768 | |||
1769 | function Calendar_GetLocalTimeFromServerTime(pServerTime) |
||
1770 | if not pServerTime then |
||
1771 | return nil; |
||
1772 | end |
||
1773 | |||
1774 | local vLocalTime = pServerTime + gGroupCalendar_ServerTimeZoneOffset; |
||
1775 | |||
1776 | if vLocalTime < 0 then |
||
1777 | vLocalTime = vLocalTime + gCalendarMinutesPerDay; |
||
1778 | elseif vLocalTime >= gCalendarMinutesPerDay then |
||
1779 | vLocalTime = vLocalTime - gCalendarMinutesPerDay; |
||
1780 | end |
||
1781 | |||
1782 | return vLocalTime; |
||
1783 | end |
||
1784 | |||
1785 | function Calendar_GetServerTimeFromLocalTime(pLocalTime) |
||
1786 | local vServerTime = pLocalTime - gGroupCalendar_ServerTimeZoneOffset; |
||
1787 | |||
1788 | if vServerTime < 0 then |
||
1789 | vServerTime = vServerTime + gCalendarMinutesPerDay; |
||
1790 | elseif vServerTime >= gCalendarMinutesPerDay then |
||
1791 | vServerTime = vServerTime - gCalendarMinutesPerDay; |
||
1792 | end |
||
1793 | |||
1794 | return vServerTime; |
||
1795 | end |
||
1796 | |||
1797 | function Calendar_GetLocalDateTimeFromServerDateTime(pServerDate, pServerTime) |
||
1798 | if not pServerTime then |
||
1799 | return pServerDate, nil; |
||
1800 | end |
||
1801 | |||
1802 | local vLocalTime = pServerTime + gGroupCalendar_ServerTimeZoneOffset; |
||
1803 | local vLocalDate = pServerDate; |
||
1804 | |||
1805 | if vLocalTime < 0 then |
||
1806 | vLocalTime = vLocalTime + gCalendarMinutesPerDay; |
||
1807 | vLocalDate = vLocalDate - 1; |
||
1808 | elseif vLocalTime >= gCalendarMinutesPerDay then |
||
1809 | vLocalTime = vLocalTime - gCalendarMinutesPerDay; |
||
1810 | vLocalDate = vLocalDate + 1; |
||
1811 | end |
||
1812 | |||
1813 | return vLocalDate, vLocalTime; |
||
1814 | end |
||
1815 | |||
1816 | function Calendar_GetServerDateTimeFromLocalDateTime(pLocalDate, pLocalTime) |
||
1817 | if not pLocalTime then |
||
1818 | return pLocalDate, nil; |
||
1819 | end |
||
1820 | |||
1821 | local vServerTime = pLocalTime - gGroupCalendar_ServerTimeZoneOffset; |
||
1822 | local vServerDate = pLocalDate; |
||
1823 | |||
1824 | if vServerTime < 0 then |
||
1825 | vServerTime = vServerTime + gCalendarMinutesPerDay; |
||
1826 | vServerDate = vServerDate - 1; |
||
1827 | elseif vServerTime >= gCalendarMinutesPerDay then |
||
1828 | vServerTime = vServerTime - gCalendarMinutesPerDay; |
||
1829 | vServerDate = vServerDate + 1; |
||
1830 | end |
||
1831 | |||
1832 | return vServerDate, vServerTime; |
||
1833 | end |
||
1834 | |||
1835 | function Calendar_AddOffsetToDateTime(pDate, pTime, pOffset) |
||
1836 | local vDateTime = pDate * gCalendarMinutesPerDay + pTime + pOffset; |
||
1837 | |||
1838 | return math.floor(vDateTime / gCalendarMinutesPerDay), math.mod(vDateTime, gCalendarMinutesPerDay); |
||
1839 | end |
||
1840 | |||
1841 | function Calendar_AddOffsetToDateTime60(pDate, pTime60, pOffset60) |
||
1842 | local vDateTime60 = pDate * gCalendarSecondsPerDay + pTime60 + pOffset60; |
||
1843 | |||
1844 | return math.floor(vDateTime60 / gCalendarSecondsPerDay), math.mod(vDateTime60, gCalendarSecondsPerDay); |
||
1845 | end |
||
1846 | |||
1847 | function Calendar_GetServerDateTimeFromSecondsOffset(pSeconds) |
||
1848 | -- Calculate the local date and time of the reset (this is done in |
||
1849 | -- local date/time since it has a higher resolution) |
||
1850 | |||
1851 | local vLocalDate, vLocalTime60 = Calendar_GetCurrentLocalDateTime60(); |
||
1852 | |||
1853 | vLocalDate, vLocalTime60 = Calendar_AddOffsetToDateTime60(vLocalDate, vLocalTime60, pSeconds); |
||
1854 | |||
1855 | local vLocalTime = math.floor(vLocalTime60 / 60); |
||
1856 | |||
1857 | -- Convert to server date/time |
||
1858 | |||
1859 | return Calendar_GetServerDateTimeFromLocalDateTime(vLocalDate, vLocalTime); |
||
1860 | end |
||
1861 | |||
1862 | function Calendar_ArrayIsEmpty(pArray) |
||
1863 | if not pArray then |
||
1864 | return true; |
||
1865 | end |
||
1866 | |||
1867 | for vIndex, vValue in pArray do |
||
1868 | return false; |
||
1869 | end |
||
1870 | |||
1871 | return true; |
||
1872 | end |
||
1873 | |||
1874 | |||
1875 | local gGroupCalendar_PrimaryTradeskills = |
||
1876 | { |
||
1877 | Herbalism = |
||
1878 | { |
||
1879 | name = GroupCalendar_cHerbalismSkillName |
||
1880 | }, |
||
1881 | |||
1882 | Alchemy = |
||
1883 | { |
||
1884 | name = GroupCalendar_cAlchemySkillName, |
||
1885 | |||
1886 | cooldownItems = |
||
1887 | { |
||
1888 | GroupCalendar_cTransmuteMithrilToTruesilver, |
||
1889 | GroupCalendar_cTransmuteIronToGold, |
||
1890 | GroupCalendar_cTransmuteLifeToEarth, |
||
1891 | GroupCalendar_cTransmuteWaterToUndeath, |
||
1892 | GroupCalendar_cTransmuteWaterToAir, |
||
1893 | GroupCalendar_cTransmuteUndeathToWater, |
||
1894 | GroupCalendar_cTransmuteFireToEarth, |
||
1895 | GroupCalendar_cTransmuteEarthToLife, |
||
1896 | GroupCalendar_cTransmuteEarthToWater, |
||
1897 | GroupCalendar_cTransmuteAirToFire, |
||
1898 | GroupCalendar_cTransmuteArcanite, |
||
1899 | } |
||
1900 | }, |
||
1901 | Enchanting = |
||
1902 | { |
||
1903 | name = GroupCalendar_cEnchantingSkillName |
||
1904 | }, |
||
1905 | Engineering = |
||
1906 | { |
||
1907 | name = GroupCalendar_cEngineeringSkillName, |
||
1908 | }, |
||
1909 | Leatherworking = |
||
1910 | { |
||
1911 | name = GroupCalendar_cLeatherworkingSkillName, |
||
1912 | }, |
||
1913 | Blacksmithing = |
||
1914 | { |
||
1915 | name = GroupCalendar_cBlacksmithingSkillName, |
||
1916 | }, |
||
1917 | Tailoring = |
||
1918 | { |
||
1919 | name = GroupCalendar_cTailoringSkillName, |
||
1920 | cooldownItems = |
||
1921 | { |
||
1922 | GroupCalendar_cMooncloth, |
||
1923 | } |
||
1924 | }, |
||
1925 | Mining = |
||
1926 | { |
||
1927 | name = GroupCalendar_cMiningSkillName |
||
1928 | }, |
||
1929 | Skinning = |
||
1930 | { |
||
1931 | name = GroupCalendar_cSkinningSkillName |
||
1932 | }, |
||
1933 | }; |
||
1934 | |||
1935 | function Calendar_LookupTradeskillIDByName(pName) |
||
1936 | for vTradeskillID, vTradeskillInfo in gGroupCalendar_PrimaryTradeskills do |
||
1937 | if vTradeskillInfo.name == pName then |
||
1938 | return vTradeskillID; |
||
1939 | end |
||
1940 | end |
||
1941 | |||
1942 | return nil; |
||
1943 | end |
||
1944 | |||
1945 | function Calendar_GetPrimaryTradeskills() |
||
1946 | local vNumSkillLines = GetNumSkillLines(); |
||
1947 | local vFoundSkillHeader = false; |
||
1948 | local vTradeskillIDs = {}; |
||
1949 | |||
1950 | for vSkillLineIndex = 1, vNumSkillLines do |
||
1951 | local vSkillName, vHeader, vIsExpanded, vSkillRank, vNumTempPoints, vSkillModifier, |
||
1952 | vSkillMaxRank, vIsAbandonable, vStepCost, vRankCost, vMinLevel, vSkillCostType, |
||
1953 | vSkillDescription = GetSkillLineInfo(vSkillLineIndex); |
||
1954 | |||
1955 | if vHeader then |
||
1956 | if vFoundSkillHeader then |
||
1957 | return vTradeskillIDs; |
||
1958 | end |
||
1959 | |||
1960 | if vSkillName == TRADE_SKILLS then |
||
1961 | vFoundSkillHeader = true; |
||
1962 | end |
||
1963 | elseif vFoundSkillHeader then |
||
1964 | local vTradeskillID = Calendar_LookupTradeskillIDByName(vSkillName); |
||
1965 | |||
1966 | if vTradeskillID then |
||
1967 | table.insert(vTradeskillIDs, vTradeskillID); |
||
1968 | else |
||
1969 | Calendar_DebugMessage("GroupCalendar: Unknown primary profession: "..vSkillName); |
||
1970 | end |
||
1971 | end |
||
1972 | end |
||
1973 | |||
1974 | return vTradeskillIDs; |
||
1975 | end |
||
1976 | |||
1977 | function Calendar_IsCooldownItem(pCooldownItems, pItemName) |
||
1978 | for vIndex, vItemName in pCooldownItems do |
||
1979 | if vItemName == pItemName then |
||
1980 | return true; |
||
1981 | end |
||
1982 | end |
||
1983 | |||
1984 | return false; |
||
1985 | end |
||
1986 | |||
1987 | function Calendar_GetTradeskillCooldown(pTradeskillID) |
||
1988 | local vNumSkills = GetNumTradeSkills(); |
||
1989 | local vCooldownItems = gGroupCalendar_PrimaryTradeskills[pTradeskillID].cooldownItems; |
||
1990 | |||
1991 | if not vCooldownItems then |
||
1992 | return nil; |
||
1993 | end |
||
1994 | |||
1995 | for vSkillIndex = 1, vNumSkills do |
||
1996 | local vSkillName, vSkillType, vNumAvailable, vIsExpanded = GetTradeSkillInfo(vSkillIndex); |
||
1997 | |||
1998 | if Calendar_IsCooldownItem(vCooldownItems, vSkillName) then |
||
1999 | local vCooldown = GetTradeSkillCooldown(vSkillIndex); |
||
2000 | |||
2001 | return vCooldown; |
||
2002 | end |
||
2003 | end |
||
2004 | |||
2005 | return nil; |
||
2006 | end |
||
2007 | |||
2008 | function CalendarInputBox_OnLoad(pChildDepth) |
||
2009 | if not pChildDepth then |
||
2010 | pChildDepth = 0; |
||
2011 | end |
||
2012 | |||
2013 | local vParent = this:GetParent(); |
||
2014 | |||
2015 | for vDepthIndex = 1, pChildDepth do |
||
2016 | vParent = vParent:GetParent(); |
||
2017 | end |
||
2018 | |||
2019 | if vParent.lastEditBox then |
||
2020 | this.prevEditBox = vParent.lastEditBox; |
||
2021 | this.nextEditBox = vParent.lastEditBox.nextEditBox; |
||
2022 | |||
2023 | this.prevEditBox.nextEditBox = this; |
||
2024 | this.nextEditBox.prevEditBox = this; |
||
2025 | else |
||
2026 | this.prevEditBox = this; |
||
2027 | this.nextEditBox = this; |
||
2028 | end |
||
2029 | |||
2030 | vParent.lastEditBox = this; |
||
2031 | end |
||
2032 | |||
2033 | function CalendarInputBox_TabPressed() |
||
2034 | local vReverse = IsShiftKeyDown(); |
||
2035 | local vEditBox = this; |
||
2036 | |||
2037 | for vIndex = 1, 50 do |
||
2038 | local vNextEditBox; |
||
2039 | |||
2040 | if vReverse then |
||
2041 | vNextEditBox = vEditBox.prevEditBox; |
||
2042 | else |
||
2043 | vNextEditBox = vEditBox.nextEditBox; |
||
2044 | end |
||
2045 | |||
2046 | if vNextEditBox:IsVisible() |
||
2047 | and not vNextEditBox.isDisabled then |
||
2048 | vNextEditBox:SetFocus(); |
||
2049 | return; |
||
2050 | end |
||
2051 | |||
2052 | vEditBox = vNextEditBox; |
||
2053 | end |
||
2054 | end |