-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalaCalendar.lua
More file actions
4168 lines (4073 loc) · 135 KB
/
alaCalendar.lua
File metadata and controls
4168 lines (4073 loc) · 135 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[--
by ALA
--]]--
local _G = _G;
local __ala_meta__ = _G.__ala_meta__;
local ADDON, NS = ...;
__ala_meta__.cal = NS;
local __iswrath = select(4, GetBuildInfo()) > 30000;
local __isdev = select(2, GetAddOnInfo("!!!!!DebugMe")) ~= nil;
local _G = _G;
local setfenv = setfenv;
local rawset = rawset;
local next = next;
local _GlobalRef = { };
local _GlobalAssign = { };
function NS:BuildEnv(category)
local _G = _G;
_GlobalRef[category] = _GlobalRef[category] or { };
_GlobalAssign[category] = _GlobalAssign[category] or { };
local Ref = _GlobalRef[category];
local Assign = _GlobalAssign[category];
setfenv(2, setmetatable(
{ },
{
__index = function(tbl, key, val)
Ref[key] = (Ref[key] or 0) + 1;
return _G[key];
end,
__newindex = function(tbl, key, value)
rawset(tbl, key, value);
Assign[key] = (Assign[key] or 0) + 1;
return value;
end,
}
));
end
function NS:MergeGlobal(DB)
local _Ref = DB._GlobalRef;
if _Ref ~= nil then
for category, db in next, _Ref do
local to = _GlobalRef[category];
if to == nil then
_GlobalRef[category] = db;
else
for key, val in next, db do
to[key] = (to[key] or 0) + val;
end
end
end
end
DB._GlobalRef = _GlobalRef;
local _Assign = DB._GlobalAssign;
if _Assign ~= nil then
for category, db in next, _Assign do
local to = _GlobalAssign[category];
if to == nil then
_GlobalAssign[category] = db;
else
for key, val in next, db do
to[key] = (to[key] or 0) + val;
end
end
end
end
DB._GlobalAssign = _GlobalAssign;
end
local LOCALE = GetLocale();
----------------------------------------------------------------------------------------------------upvalue
----------------------------------------------------------------------------------------------------LUA
local date, time = date, time;
local select, next, inext = select, next, ipairs({ });
local type, tonumber, tostring = type, tonumber, tostring;
local getfenv, setfenv, pcall = getfenv, setfenv, pcall;
local abs, ceil, floor, max, min = abs, ceil, floor, max, min;
local format, gsub, strlen, strlower, strmatch, strsub, strupper, strsplit = format, gsub, string.len, string.lower, string.match, string.sub, string.upper, string.split;
local getmetatable, setmetatable, rawget, rawset = getmetatable, setmetatable, rawget, rawset;
local tinsert, tremove, wipe, unpack = tinsert, tremove, wipe, unpack;
----------------------------------------------------------------------------------------------------GAME
local C_Timer = C_Timer;
local print = print;
local GetServerTime = GetServerTime;
local CreateFrame = CreateFrame;
--------------------------------------------------
local RegisterAddonMessagePrefix = RegisterAddonMessagePrefix or C_ChatInfo.RegisterAddonMessagePrefix;
local IsAddonMessagePrefixRegistered = IsAddonMessagePrefixRegistered or C_ChatInfo.IsAddonMessagePrefixRegistered;
local GetRegisteredAddonMessagePrefixes = GetRegisteredAddonMessagePrefixes or C_ChatInfo.GetRegisteredAddonMessagePrefixes;
local SendAddonMessage = SendAddonMessage or C_ChatInfo.SendAddonMessage;
local SendAddonMessageLogged = SendAddonMessageLogged or C_ChatInfo.SendAddonMessageLogged;
--------------------------------------------------
local Ambiguate = Ambiguate;
local C_Map = C_Map;
local C_QuestLog = C_QuestLog;
local GetGossipAvailableQuests = GetGossipAvailableQuests;
local UnitGUID = UnitGUID;
local GetQuestID = GetQuestID;
local IsInRaid, IsInGroup = IsInRaid, IsInGroup;
local GetGuildInfo = GetGuildInfo;
local GetPlayerInfoByGUID = GetPlayerInfoByGUID;
local LE_PARTY_CATEGORY_HOME, LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_HOME, LE_PARTY_CATEGORY_INSTANCE;
local GetDailyQuestsCompleted, GetMaxDailyQuests = GetDailyQuestsCompleted, GetMaxDailyQuests;
local GetQuestResetTime = GetQuestResetTime;
local GetQuestsCompleted = GetQuestsCompleted;
local GetNumSavedInstances, GetSavedInstanceInfo, GetSavedInstanceEncounterInfo = GetNumSavedInstances, GetSavedInstanceInfo, GetSavedInstanceEncounterInfo;
--------------------------------------------------
local GameTooltip = GameTooltip;
local RAID_CLASS_COLORS = RAID_CLASS_COLORS;
local CLASS_ICON_TCOORDS = CLASS_ICON_TCOORDS;
local _ = nil;
local function _log_(...)
print(date('\124cff00ffff%H:%M:%S\124r cal'), ...);
end
local function _noop_()
end
--------------------------------------------------
local NUM_ROW = 6;
local NUM_COL = 7;
local ui_style = {
texture_white = "Interface\\Buttons\\WHITE8X8",
texture_unk = "Interface\\Icons\\inv_misc_questionmark",
texture_highlight = "Interface\\Buttons\\UI-Common-MouseHilight",
texture_triangle = "interface\\transmogrify\\transmog-tooltip-arrow",
texture_arrowleft = "Interface\\AddOns\\alaCalendar\\ARTWORK\\ArrowLeft",
texture_arrowright = "Interface\\AddOns\\alaCalendar\\ARTWORK\\ArrowRight",
texture_collapsed = "Interface\\AddOns\\alaCalendar\\ARTWORK\\PlusButtonClear",
texture_expanded = "Interface\\AddOns\\alaCalendar\\ARTWORK\\MinusButtonClear",
texture_claw = "interface\\timer\\panda-logo",
texture_config = "Interface\\AddOns\\alaCalendar\\ARTWORK\\Config",
texture_triangle_normal_color = { 0.5, 0.5, 0.5, 1.0, },
texture_triangle_pushed_color = { 0.25, 0.25, 0.25, 1.0, },
texture_close = "Interface\\AddOns\\alaCalendar\\ARTWORK\\Close",
texture_reset = "Interface\\Buttons\\UI-RefreshButton",
frameTitle_YSize = 48,
cal_XToBorder = 4,
cal_YToBorder = 4,
weekTitle_YSize = 30,
weekTitle_BG = "Interface\\Calendar\\CalendarBackground",
weekTitle_BG_Coord = { 0.0, 0.3515625, 0.72265625, 0.81640625, },
cell_YToWeekTitle = 4,
cell_XSize = 90,
cell_YSize = 90,
cell_XInt = 0,
cell_YInt = 0,
cell_BG = "Interface\\Calendar\\CalendarBackground",
cell_BG_Coord = { 0.0, 0.3515625, 0.0, 0.3515625, },
cell_this_month_maskColor = { 0.25, 0.25, 0.25, 0.5, },
cell_today_mask_color = { 1.0, 0.5, 0.0, 1.0, },
cell_Highlight = "interface\\buttons\\checkbuttonhilight",
cell_HighlightCoord = { 0.05, 0.95, 0.05, 0.95, },
--
board_XSize = 360,
board_YSize = 600,
board_buttonHeight = 24,
buttonHighlightColor = { 0.5, 0.5, 0.0, 0.25, },
buttonGlowColor = { 0.0, 0.25, 0.0, 0.15, },
char_buttonHeight = 32,
frameFont = SystemFont_Shadow_Med1:GetFont(),--=="Fonts\ARKai_T.ttf"
frameFontSize = min(select(2, SystemFont_Shadow_Med1:GetFont()) + 1, 15),
frameFontOutline = "",
weekTitleFontSize = min(select(2, SystemFont_Shadow_Med1:GetFont()) + 5, 18),
cellTitleFontSize = min(select(2, SystemFont_Shadow_Med1:GetFont()) + 5, 18),
bigFontSize = 32,
smallFontSize = select(2, SystemFont_Shadow_Med1:GetFont()),
today_color = { 0.5, 0.75, 1.0, 0.9, },
ad_color = { 0.25, 0.5, 0.75, 0.9, },
};
ui_style.cal_XSize = ui_style.cell_XSize * (NUM_COL) + ui_style.cell_XInt * (NUM_COL - 1);
ui_style.cal_YSize = ui_style.weekTitle_YSize + ui_style.cell_YToWeekTitle + ui_style.cell_YSize * (NUM_ROW) + ui_style.cell_YInt * (NUM_ROW - 1);
ui_style.frame_XSize = ui_style.cal_XToBorder * 2 + ui_style.cal_XSize;
ui_style.frame_YSize = ui_style.frameTitle_YSize + ui_style.cal_YToBorder * 2 + ui_style.cal_YSize;
ui_style.festival_Size = min(ui_style.cell_XSize, ui_style.cell_YSize) * 0.45;
ui_style.cell_inst_Size = min(ui_style.cell_XSize * 0.25, ui_style.cell_YSize * 0.25);
--
local BIG_NUMBER = 4294967295;
--[[
-- "Interface\\Buttons\\WHITE8X8",
-- "Interface\\Tooltips\\UI-Tooltip-Background",
-- "Interface\\ChatFrame\\ChatFrameBackground"
alaCalendarSV = {
var = {
[GUID] = {
[instance] = bool,
realm_id = number,
realm_name = string,
},
},
set = {
first_col_day = bool,
[instance] = bool,
},
_version = number,
}
]]
----------------------------------------------------------------------------------------------------
local L = NS.L;
L.INSTANCE = __ala_meta__.__raidlib.__raid_meta.L;
local ARTWORK_ICON_PATH = "Interface\\AddOns\\alaCalendar\\ARTWORK\\ICON";
---------------------------------------------------------------------------------------------------
local AVAR, VAR, SET = nil, nil, nil;
local gui = { };
local DB = nil;
local PLAYER_GUID = UnitGUID('player');
local PLAYER_NAME = UnitName('player');
local PLAYER_REALM_ID = tonumber(GetRealmID());
local PLAYER_REALM_NAME = GetRealmName();
local PLAYER_REALM_NAME_NOBLANK = gsub(PLAYER_REALM_NAME, " ", "");
local PLAYER_FULLNAME = PLAYER_NAME .. "-" .. PLAYER_REALM_NAME_NOBLANK;
function NS.info_OnEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
if self.info_lines then
for _, v in next, self.info_lines do
GameTooltip:AddLine(v);
end
end
GameTooltip:Show();
end
function NS.info_OnLeave(self)
if GameTooltip:IsOwned(self) then
GameTooltip:Hide();
end
end
function NS.IsEastAsiaFormat()
return LOCALE == "zhCN" or LOCALE == "zhTW" or LOCALE == "koKR";
end
NS:BuildEnv("cal");
local _EventHandler = CreateFrame("FRAME");
do -- EventHandler
local function OnEvent(self, event, ...)
return NS[event](...);
end
function _EventHandler:FireEvent(event, ...)
local func = NS[event];
if func then
return func(...);
end
end
function _EventHandler:RegEvent(event)
NS[event] = NS[event] or _noop_;
self:RegisterEvent(event);
self:SetScript("OnEvent", OnEvent);
end
function _EventHandler:UnregEvent(event)
self:UnregisterEvent(event);
end
end
local T_Scheduler = setmetatable({ }, { __mode = 'k', })
function NS.F_ScheduleDelayCall(func, delay)
local sch = T_Scheduler[func];
if sch == nil then
sch = { };
sch[1] = function()
func();
sch[2] = false;
end;
elseif sch[2] then
return;
end
sch[2] = true;
C_Timer.After(delay or 0.2, sch[1]);
end
do -- util
local data_valid_time = 86400;
function NS.seconds_to_colored_formatted_time_len(sec)
local p = max(0.0, 1.0 - sec / data_valid_time);
local r = 0.0;
local g = 0.0;
if p > 0.5 then
r = (1.0 - p) * 255.0;
g = 255.0;
else
r = 255.0;
g = p * 255;
end
--
local d = floor(sec / 86400);
sec = sec % 86400;
local h = floor(sec / 3600);
sec = sec % 3600;
local m = floor(sec / 60);
sec = sec % 60;
if d > 0 then
return format(L["COLORED_FORMATTED_TIME_LEN"][1], r, g, d, h, m, sec);
elseif h > 0 then
return format(L["COLORED_FORMATTED_TIME_LEN"][2], r, g, h, m, sec);
elseif m > 0 then
return format(L["COLORED_FORMATTED_TIME_LEN"][3], r, g, m, sec);
else
return format(L["COLORED_FORMATTED_TIME_LEN"][4], r, g, sec);
end
end
function NS.seconds_to_formatted_time(sec)
if sec and type(sec) == 'number' then
return date(L["FORMATTED_TIME"], sec);
end
end
function NS.seconds_to_formatted_time_len(sec)
local d = floor(sec / 86400);
sec = sec % 86400;
local h = floor(sec / 3600);
sec = sec % 3600;
local m = floor(sec / 60);
sec = sec % 60;
if d > 0 then
return format(L["FORMATTED_TIME_LEN"][1], d, h, m, sec);
elseif h > 0 then
return format(L["FORMATTED_TIME_LEN"][2], h, m, sec);
elseif m > 0 then
return format(L["FORMATTED_TIME_LEN"][3], m, sec);
else
return format(L["FORMATTED_TIME_LEN"][4], sec);
end
end
end
do -- MAIN
local date_engine = { };
do -- date_engine
local const_epoch = { 1970, 1, 1, 0, 0, 0, 4, 0, };
do
const_epoch[8] = const_epoch[8] - const_epoch[6] - const_epoch[5] * 60 - const_epoch[4] * 3600;
const_epoch[4] = 0;
const_epoch[5] = 0;
const_epoch[6] = 0;
if const_epoch[2] ~= 1 or const_epoch[3] ~= 1 then
local ofs_days = date_engine.get_year_day_index(const_epoch[1], const_epoch[2], const_epoch[3]) - 1;
const_epoch[2] = 1;
const_epoch[3] = 1;
const_epoch[7] = (const_epoch[7] - ofs_days) % NUM_COL;
const_epoch[8] = const_epoch[8] - ofs_days * 86400;
end
end
local month_days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, };
function date_engine.time()
return GetServerTime();
end
function date_engine.date(_format, _time)
_time = _time or date_engine.time();
return date(_format, _time);
end
function date_engine.built_in_date(_format, _time)
_time = _time or date_engine.time();
local Y, m, d, W, R = date_engine.get_localized_ofs_date_val(_time);
local H = floor(R / 3600);
local M = floor((R % 3600) / 60);
local S = R % 60;
_format = gsub(_format, "%%[Yy]", Y);
_format = gsub(_format, "%%m", format("%02d", m));
_format = gsub(_format, "%%[Bb]", L.MONTH[m]);
_format = gsub(_format, "%%d", format("%02d", d));
_format = gsub(_format, "%%H", format("%02d", H));
_format = gsub(_format, "%%M", format("%02d", M));
_format = gsub(_format, "%%S", format("%02d", S));
_format = gsub(_format, "%%w", W);
_format = gsub(_format, "%%lw", L.WEEKTITLE[W]);
_format = gsub(_format, "%%%%", "%%");
return _format;
end
function date_engine.get_user_time_zone()
local utc = date("!*t");
local loc = date("*t");
-- year, month, day, hour, min, sec, wday, yday, isdst
local sec = ((loc.year == utc.year) and (loc.yday - utc.yday) * 86400 or ((loc.year > utc.year) and 86400 or -86400)) +
(loc.hour - utc.hour) * 3600 + (loc.min - utc.min) * 60 + (loc.sec - utc.sec);
if sec == 0 then
return 0;
elseif sec > 0 then
return floor((sec + 1800) / 3600);
else
return ceil((sec - 1800) / 3600);
end
end
function date_engine.get_month_days(Y, M)
if M == 2 then
-- mod4 = 0 and mod100 ~= 0
-- mod400 == 0 and mod3200 ~= 0
-- mod172800 == 0
--[[if Y % 172800 == 0 then
return 29;
elseif Y % 3200 == 0 then
return 28;
else--]]if Y % 400 == 0 then
return 29;
elseif Y % 100 == 0 then
return 28;
elseif Y % 4 == 0 then
return 29;
else
return 28;
end
else
return month_days[M];
end
end
function date_engine.get_year_days(Y)
-- mod4 = 0 and mod100 ~= 0
-- mod400 == 0 and mod3200 ~= 0
-- mod172800 == 0
--[[if Y % 172800 == 0 then
return 366;
elseif Y % 3200 == 0 then
return 365;
else--]]if Y % 400 == 0 then
return 366;
elseif Y % 100 == 0 then
return 365;
elseif Y % 4 == 0 then
return 366;
else
return 365;
end
end
function date_engine.get_year_remaining_days(Y, M, D)
local days = date_engine.get_month_days(Y, M) - D + 1;
for month = M + 1, 12 do
days = days + date_engine.get_month_days(Y, month);
end
return days;
end
function date_engine.get_year_day_index(Y, M, D)
local days = 0;
for month = 1, M - 1 do
days = days + date_engine.get_month_days(Y, month);
end
days = days + D;
return days;
end
function date_engine.localized_ofs(val)
if SET.dst then
return val - (date_engine.timeZone + 1) * 3600;
else
return val - date_engine.timeZone * 3600;
end
end
function date_engine.get_localized_ofs_date_val(val) -- localized_ofs time modified by timeZone offset [time - timeZone * 3600]
-- val = date_engine.localized_ofs(val);
local Y, M, D, h, m, s, w, ofs = unpack(const_epoch);
ofs = date_engine.localized_ofs(ofs);
-- M, D are always 1 h, m, s are always 0
w = (w + floor((val - ofs) / 86400)) % NUM_COL;
while true do
local yhs = date_engine.get_year_days(Y) * 86400;
if ofs + yhs < val then
Y = Y + 1;
ofs = ofs + yhs;
elseif ofs + yhs == val then
Y = Y + 1;
return Y, 1, 1, w, 0;
else
while true do
local mhs = date_engine.get_month_days(Y, M) * 86400;
if ofs + mhs < val then
M = M + 1;
ofs = ofs + mhs;
elseif ofs + mhs == val then
M = M + 1;
return Y, M, 1, w, 0;
else
local diff = val - ofs;
return Y, M, 1 + floor(diff / 86400), w, diff % 86400;
end
end
end
end
end
function date_engine.get_localized_start_of_day(val)
val = val or date_engine.time();
if SET.dst then
return val - (val + (date_engine.timeZone + 1) * 3600) % 86400;
else
return val - (val + date_engine.timeZone * 3600) % 86400;
end
end
function NS.set_time_zone()
date_engine.timeZone = SET.use_realm_time_zone and NS.realmTimeZone or date_engine.userTimeZone;
end
function NS.InitTimeZone()
local userTimeZone = date_engine.get_user_time_zone();
date_engine.userTimeZone = userTimeZone;
NS.apply_region[SET.region]();
NS.set_time_zone();
end
function date_engine.inst_next_reset(inst)
local val = NS.milestone[inst];
if val ~= nil then
if val.type == "fixed_cycle" then
return val[1] + floor((date_engine.time() + val[2] - val[1]) / val[2]) * val[2];
else
end
end
end
end
NS.date_engine = date_engine;
local extern_list = { };
do -- external
function NS.ext_Reset()
wipe(extern_list);
end
-- inst = 'string' or 'number' or table{ tex, coord, title, color, } or function(text)return tex, coord, title, color
-- text = 'string' or 'number' or table{ tex, coord, title, color, } or function(inst)return tex, coord, title, color
function NS.ext_RegHeader(inst, text)
if extern_list[inst] == nil then
extern_list[inst] = { text = text, };
return;
else
return false;
end
end
-- key = 'string' or 'number' or table{ tex, coord, title, color_title, } or function(inst, val)return tex, coord, title, color_title
-- val = 'string' or 'number' or table{ tex, coord, title, color_title, cool, color_cool, } or function(inst, key)return tex, coord, title, color_title, cool, color_cool
function NS.ext_AddLine(inst, key, val)
local list = extern_list[inst];
if list then
list[key] = val;
return true;
else
return false;
end
end
function NS.ext_UpdateBoard()
local board = gui["BOARD"];
if board then
board:update_list();
if board:IsShown() then
board:update_func();
end
end
end
end
do -- func
local function cal_and_val(Y1, M1, D1, W1)
while M1 <= 0 do
M1 = M1 + 12;
Y1 = Y1 - 1;
end
while M1 > 12 do
M1 = M1 - 12;
Y1 = Y1 + 1;
end
local N1 = date_engine.get_month_days(Y1, M1);
local W1S = (W1 - D1 + 1) % NUM_COL;
local W1E = (W1 - D1 + N1) % NUM_COL;
local PS1 = (W1S - SET.first_col_day) % NUM_COL + 1;
local PE1 = (W1E - SET.first_col_day) % NUM_COL + 1; -- ((SET.first_col_day - 1) % NUM_COL - W1E) % NUM_COL;
local L1 = (PS1 - 1 + N1 + NUM_COL - PE1) / NUM_COL;
return Y1, M1, D1, N1, W1S, W1E, PS1, PE1, L1;
end
function NS.proc_update_calendar(frame)
-- local
local var = frame.var;
local now = date_engine.time();
local Y, M, D, W, R = date_engine.get_localized_ofs_date_val(now); -- TODAY
local Y1, M1, D1, W1, N1, W1S, W1E, PS1, PE1, L1 = Y, M, 1, (W + 1 - D) % NUM_COL; -- BASE DATE OF PROCESSING
local NOW1 = now - R - (D - 1) * 86400;
local Y0, M0, D0, N0, NOW0; -- DATE of cell{ col = 1, row = 1 }
-- proc var
local month_ofs = var.month_ofs;
local line_ofs = var.line_ofs;
if month_ofs ~= 0 then
local M1days = 0;
if month_ofs > 0 then
for ofs = 0, month_ofs - 1 do
M1days = M1days + date_engine.get_month_days(Y1, M1);
M1 = M1 + 1;
if M1 > 12 then
Y1 = Y1 + 1;
M1 = 1;
end
end
else
for ofs = 0, month_ofs + 1, -1 do
M1 = M1 - 1;
if M1 <= 0 then
Y1 = Y1 - 1;
M1 = 12;
end
M1days = M1days - date_engine.get_month_days(Y1, M1);
end
end
W1 = (W1 + M1days) % NUM_COL;
NOW1 = NOW1 + M1days * 86400;
end
Y1, M1, D1, N1, W1S, W1E, PS1, PE1, L1 = cal_and_val(Y1, M1, D1, W1);
-- _log_("1#B", Y1 .. '-' .. M1 .. '-' .. D1 .. '#' .. W1, month_ofs, line_ofs, N1, "S" .. W1S, "E" .. W1E);
--
if line_ofs < 0 then
while true do
local tm1 = M1 - 1;
local ty1 = Y1;
if tm1 <= 0 then
tm1 = 12;
ty1 = ty1 - 1;
end
local tM1days = date_engine.get_month_days(ty1, tm1);
local tW1 = (W1 - tM1days) % NUM_COL;
local tY1, tM1, tD1, tN1, tW1S, tW1E, tPS1, tPE1, tL1 = cal_and_val(ty1, tm1, D1, tW1);
if -line_ofs >= tL1 then
month_ofs = month_ofs - 1;
line_ofs = line_ofs + tL1;
if PS1 ~= 1 then
line_ofs = line_ofs - 1;
end
W1 = tW1;
Y1, M1, D1, N1, W1S, W1E, PS1, PE1, L1 = tY1, tM1, tD1, tN1, tW1S, tW1E, tPS1, tPE1, tL1;
NOW1 = NOW1 - tM1days * 86400;
else
local days0 = - line_ofs * NUM_COL + PS1 - 1;
if days0 > NUM_COL * NUM_ROW * 0.5 then
month_ofs = month_ofs - 1;
line_ofs = line_ofs + tL1;
if PS1 ~= 1 then
line_ofs = line_ofs - 1;
end
W1 = tW1;
Y1, M1, D1, N1, W1S, W1E, PS1, PE1, L1 = tY1, tM1, tD1, tN1, tW1S, tW1E, tPS1, tPE1, tL1;
NOW1 = NOW1 - tM1days * 86400;
else
break;
end
end
end
elseif line_ofs > 0 then
while true do
if line_ofs >= L1 then
local M1days = date_engine.get_month_days(Y1, M1);
month_ofs = month_ofs + 1;
line_ofs = line_ofs - L1;
W1 = (W1 + M1days) % NUM_COL;
Y1, M1, D1, N1, W1S, W1E, PS1, PE1, L1 = cal_and_val(Y1, M1 + 1, D1, W1);
NOW1 = NOW1 + M1days * 86400;
if PS1 ~= 1 then
line_ofs = line_ofs + 1;
end
else
local days0 = (L1 - 1 - line_ofs) * NUM_COL + PE1;
if days0 < NUM_COL * NUM_ROW * 0.5 then
local M1days = date_engine.get_month_days(Y1, M1);
month_ofs = month_ofs + 1;
line_ofs = line_ofs - L1;
W1 = (W1 + M1days) % NUM_COL;
Y1, M1, D1, N1, W1S, W1E, PS1, PE1, L1 = cal_and_val(Y1, M1 + 1, D1, W1);
NOW1 = NOW1 + M1days * 86400;
if PS1 ~= 1 then
line_ofs = line_ofs + 1;
end
else
break;
end
end
end
end
-- _log_("2#B", Y1 .. '-' .. M1 .. '-' .. D1 .. '#' .. W1, month_ofs, line_ofs, N1, "S" .. W1S, "E" .. W1E);
if line_ofs > 0 then
Y0, M0, N0 = Y1, M1, N1;
D0 = (line_ofs - 1) * NUM_COL + NUM_COL - PS1 + 1 + 1;
NOW0 = NOW1 + (D0 - D1) * 86400;
elseif line_ofs < 0 then
M0 = M1 - 1;
if M0 <= 0 then
Y0 = Y1 - 1;
M0 = 12;
else
Y0 = Y1;
end
N0 = date_engine.get_month_days(Y0, M0);
D0 = N0 + 1 - (- line_ofs) * NUM_COL - PS1 + D1;
NOW0 = NOW1 - (N0 - D0 + D1) * 86400;
else
if PS1 == 1 then
Y0, M0, D0, N0, NOW0 = Y1, M1, D1, N1, NOW1;
else
M0 = M1 - 1;
if M0 <= 0 then
Y0 = Y1 - 1;
M0 = 12;
else
Y0 = Y1;
end
N0 = date_engine.get_month_days(Y0, M0);
D0 = N0 + 1 - PS1 + D1;
NOW0 = NOW1 - (N0 - D0 + D1) * 86400;
end
end
var.month_ofs = month_ofs;
var.line_ofs = line_ofs;
var.first_cell_time = { Y0, M0, D0, N0, NOW0, };
var.center_cell_time = { Y1, M1, D1, N1, NOW1, };
-- gui
if NS.IsEastAsiaFormat() then
frame:SetDateLeftText(format(L.YEAR_FORMAT, Y1));
frame:SetDateRightText(format(L.MONTH_FORMAT, L.MONTH[M1]));
else
frame:SetDateRightText(format(L.YEAR_FORMAT, Y1));
frame:SetDateLeftText(format(L.MONTH_FORMAT, L.MONTH[M1]));
end
local cells = frame.cells;
local ofs = 0;
local dst_ofs = SET.dst and 3600 or 0;
--
for col = 1, NUM_ROW do
local rc = cells[col];
for row = 1, NUM_COL do
local cell = rc[row];
cell:SetTitle(M0 .. "-" .. D0);
if M0 == M1 then
cell:Bright();
else
cell:Dark();
end
if Y0 == Y and M0 == M and D0 == D then
cell:Today();
else
cell:NotToday();
end
cell.now = NOW0;
cell:HideFestival1Tex();
cell:HideFestival2Tex();
cell:HideCurtain1Tex();
cell:HideCurtain2Tex();
local info = nil;
local info_line_num = 0;
cell:ResetInstance();
local state = cell.state;
wipe(state);
for _, inst in inext, NS.milestone_list, 0 do
if SET.inst_hash[inst] then
local val = NS.milestone[inst];
if val and val.phase <= NS.CUR_PHASE then
local first_seen = val.dst and (val[1] - dst_ofs) or val[1];
local start_of_day_first_seen = date_engine.get_localized_start_of_day(first_seen);
if NOW0 >= start_of_day_first_seen then
if val.type == "fixed_cycle" then
local diff = (NOW0 - start_of_day_first_seen) % val[2];
local end_time_ofs = val[5] + first_seen - start_of_day_first_seen;
if diff <= max(end_time_ofs, 86400 - 1) then -- in the range of dur, at least one day
if diff < 86400 then -- the first day
if val.festival then
if val.texture_channel2 then
cell:SetFestival2Tex(val[6]);
if val[9] then
cell:SetFestival2TexCoord(unpack(val[9]));
end
else
cell:SetFestival1Tex(val[6]);
if val[9] then
cell:SetFestival1TexCoord(unpack(val[9]));
end
end
end
if end_time_ofs < 86400 then
state[inst] = 2;
else
state[inst] = 1;
end
else
local last_day_remaining = end_time_ofs % 86400;
if last_day_remaining == 0 then
last_day_remaining = 86400;
end
if diff + 86400 > end_time_ofs - last_day_remaining then
state[inst] = -1;
else
state[inst] = 0;
end
end
if val[7] then
if val.curtain_channel2 then
cell:SetCurtain2Tex(val[7]);
if val[10] then
cell:SetCurtain2TexCoord(unpack(val[10]));
end
else
cell:SetCurtain1Tex(val[7]);
if val[10] then
cell:SetCurtain1TexCoord(unpack(val[10]));
end
end
end
if val.instance then
if SET.instance_icon then
cell:AddInstance(val[6], val[9]);
end
if SET.instance_text then
if info_line_num >= 2 then
info = info and (info .. "\n" .. inst) or inst;
info_line_num = 1;
else
info = info and (info .. ", " .. inst) or inst;
info_line_num = info_line_num + 1;
end
end
end
end
elseif val.type == "month_week_day" then
local fit = false;
if val[2] and val[2] > 1 then
local y, m = date_engine.get_localized_ofs_date_val(first_seen);
local n_month = (Y0 - y) * 12 + (M0 - m);
fit = n_month % val[2] == 0;
else
fit = true;
end
if fit then
local day_check = (val[3] - ((row + SET.first_col_day - 1) % NUM_COL - D0 + 1) % NUM_COL + 1) % NUM_COL;
day_check = day_check == 0 and 7 or day_check;
local diff = (D0 - day_check) * 86400;-- + (to_ddate_engineate.timeZone - NS.realmTimeZone) * 3600;
local start_ofs = val[4] + (date_engine.timeZone - NS.realmTimeZone) * 3600;
if (diff + 86400 - 1) >= start_ofs and diff < (start_ofs + val[5]) then
if diff < (floor(start_ofs / 86400) * 86400 + 86400) then -- the first day
if val.festival then
if val.texture_channel2 then
cell:SetFestival2Tex(val[6]);
if val[9] then
cell:SetFestival2TexCoord(unpack(val[9]));
end
else
cell:SetFestival1Tex(val[6]);
if val[9] then
cell:SetFestival1TexCoord(unpack(val[9]));
end
end
end
if (start_ofs + val[5]) < (diff + 86400) then
state[inst] = 2;
else
state[inst] = 1;
end
else
if diff < (start_ofs + val[5] - 86400) then
if val[7] then
if val.curtain_channel2 then
cell:SetCurtain2Tex(val[7]);
if val[10] then
cell:SetCurtain2TexCoord(unpack(val[10]));
end
else
cell:SetCurtain1Tex(val[7]);
if val[10] then
cell:SetCurtain1TexCoord(unpack(val[10]));
end
end
end
state[inst] = 0;
else
if val[7] then
if val.texture_channel2 then
cell:SetFestival2Tex(val[8]);
if val[11] then
cell:SetFestival2TexCoord(unpack(val[11]));
end
else
cell:SetFestival1Tex(val[8]);
if val[11] then
cell:SetFestival1TexCoord(unpack(val[11]));
end
end
end
state[inst] = -1;
end
end
if val.instance then
if SET.instance_icon then
cell:AddInstance(val[6], val[9]);
end
if SET.instance_text then
info = info and (info .. "\n" .. inst) or inst;
end
end
end
end
elseif val.type == "yearly_date" then
end
end
end
end
end
cell:RefreshInstance();
if SET.instance_text and info ~= nil then
cell:SetInfo("\124cffbfffff" .. info .. "\124r");
else
cell:SetInfo(nil);
end
D0 = D0 + 1;
NOW0 = NOW0 + 86400;
if D0 > N0 then
M0 = M0 + 1;
if M0 > 12 then
Y0 = Y0 + 1;
M0 = 1;
end
D0 = 1;
N0 = date_engine.get_month_days(Y0, M0);
end
end
end
end
--
local function clean_up()
local now = date_engine.time()
local earliest = BIG_NUMBER;
for GUID, VAR in next, AVAR do
for _, inst in next, SET.raid_list do
local var = VAR[inst];
if var[2] then
if var[2] <= now then
wipe(var);
else
earliest = min(earliest, var[2]);
end
end
end
end
return earliest;
end
local instance_name_hash = __ala_meta__.__raidlib.__raid_meta.hash;
function NS.proc_locked_down_instance()
for _, inst in next, SET.raid_list do
wipe(VAR[inst]);
end
local earliest = BIG_NUMBER;
local now = date_engine.time()
for instanceIndex = 1, GetNumSavedInstances() do
local name, id, reset, difficulty, locked, extended, instanceIDMostSig, isRaid, maxPlayers, difficultyName, numEncounters, encounterProgress = GetSavedInstanceInfo(instanceIndex);
if locked and isRaid then
local inst = instance_name_hash[name];
if inst then
local t = now + reset;
local var = VAR[inst];
var[1] = id;
var[2] = t;
var[3] = numEncounters;
var[4] = encounterProgress;
earliest = min(earliest, t);
for encounterIndex = 1, numEncounters do
local bossName, fileDataID, isKilled, unknown4 = GetSavedInstanceEncounterInfo(instanceIndex, encounterIndex);
var[4 + encounterIndex * 2 - 1] = bossName;
var[4 + encounterIndex * 2] = isKilled;
end
else
end
end
end
C_Timer.After(min(earliest - now + 1, 3600, clean_up() - now), NS.proc_locked_down_instance);
--
NS.ui_update_board();
end
function NS.InitInstance()
for _, inst in next, SET.raid_list do
if VAR[inst] == nil then
VAR[inst] = { };
end
end
C_Timer.After(0.1, NS.proc_locked_down_instance);
end
function NS.PLAYER_LOGOUT(...)
VAR.PLAYER_LEVEL = UnitLevel('player');
NS.proc_locked_down_instance();
end
function NS.ENCOUNTER_END()
NS.F_ScheduleDelayCall(NS.proc_locked_down_instance);
end
function NS.BOSS_KILL()
NS.F_ScheduleDelayCall(NS.proc_locked_down_instance);
end
function NS.UPDATE_INSTANCE_INFO()
NS.F_ScheduleDelayCall(NS.proc_locked_down_instance);
end
function NS.PLAYER_LEVEL_UP(level)
VAR.PLAYER_LEVEL = level;
end
function NS.init_var(VAR)
for _, inst in next, SET.raid_list do
if VAR[inst] == nil then
VAR[inst] = { };
end
end
return VAR;
end