-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThisIsMe.lua
More file actions
2398 lines (2160 loc) · 81.5 KB
/
Copy pathThisIsMe.lua
File metadata and controls
2398 lines (2160 loc) · 81.5 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
-----------------------------------------------------------------------------------------------
-- Client Lua Script for ThisIsMe
-- Copyright (c) NCsoft. All rights reserved
-----------------------------------------------------------------------------------------------
require "Window"
require "Unit"
require "ICComm"
require "ICCommLib"
require "GameLib"
require "HousingLib"
require "CombatFloater"
-----------------------------------------------------------------------------------------------
-- ThisIsMe Module Definition
-----------------------------------------------------------------------------------------------
local ThisIsMe = {}
local LibCommExt = nil
local ProfileWindow = {}
local ThisIsMeInst = nil
local Major, Minor, Patch, Suffix = 0, 3, 8, 1 -- 10 is j
local YOURADDON_CURRENT_VERSION = string.format("%d.%d.%d", Major, Minor, Patch)
local Locale = nil
local GeminiLocale = nil
local glog
-----------------------------------------------------------------------------------------------
-- Constants
-----------------------------------------------------------------------------------------------
local kcrSelectedText = ApolloColor.new("UI_BtnTextHoloPressed")
local kcrNormalText = ApolloColor.new("UI_BtnTextHoloNormal")
local redErrorText = ApolloColor.new("AddonError")
local defaultText = ApolloColor.new("UI_WindowTextDefault")
local listDefault = "CRB_Basekit:kitInnerFrame_MetalGold_FrameBright2"
local listBright = "CRB_Basekit:kitInnerFrame_MetalGold_FrameBright"
local listDull = "CRB_Basekit:kitInnerFrame_MetalGold_FrameDull"
local portraitDominion = ApolloColor.new(2, 0.8, 0.7, 1)
local portraitExile = ApolloColor.new(1.0, 0.8, 1.3, 1)
local portraitNeutral = ApolloColor.new(1.2, 0.9, 1, 1)
-----------------------------------------------------------------------------------------------
-- Initialization
-----------------------------------------------------------------------------------------------
function ThisIsMe:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
-- initialize variables here
o.profileListEntries = {} -- keep track of all the list items
o.characterProfiles = {}
o.sortedCharacterProfiles = {}
o.seenEveryone = false
o.sortMode = 1
o.sortInvert = false
o.sortByOnline = true
o.portraits = {
["3"]={"charactercreate:sprCharC_Finalize_RaceAurinM", "charactercreate:sprCharC_Finalize_RaceAurinF"},
["5"]={"charactercreate:sprCharC_Finalize_RaceDrakenM", "charactercreate:sprCharC_Finalize_RaceDrakenF"},
["6"]={"charactercreate:sprCharC_Finalize_RaceGranokM", "charactercreate:sprCharC_Finalize_RaceGranokF"},
["7"]={"charactercreate:sprCharC_Finalize_RaceExileM", "charactercreate:sprCharC_Finalize_RaceExileF"},
["8"]={"charactercreate:sprCharC_Finalize_RaceMechariM", "charactercreate:sprCharC_Finalize_RaceMechariF"},
["9"]={"charactercreate:sprCharC_Finalize_RaceMordeshM", "charactercreate:sprCharC_Finalize_RaceMordeshF"},
["10"]={"charactercreate:sprCharC_Finalize_RaceDomM", "charactercreate:sprCharC_Finalize_RaceDomF"},
["11"]={"charactercreate:sprCharC_Finalize_RaceDomM", "charactercreate:sprCharC_Finalize_RaceDomF"}
}
o.portraitUnknown = "charactercreate:sprCharC_Finalize_SkillLevel1"
o.portraitChua = "charactercreate:sprCharC_Finalize_RaceChua"
o.Comm = nil
o.channel = "__TIM__"
o.sendTimer = nil
o.profileEdit = false
o.profileCharacter = nil
o.editedProfile = {}
o.fullyLoaded = false
o.enableUpdateButton = true
o.messageCharacterLimit = 80
o.messagesPerSecond = 5
o.protocolVersionMin = 4
o.protocolVersionMax = 4
o.profileRequestBuffer = {}
o.defaultProtocolVersion = 4
o.options = {}
o.options.logLevel = 0
o.options.debugMode = false
o.options.protocolVersion = o.defaultProtocolVersion
o.options.useDefaultProtocolVersion = true
o.dropdownTextMap = {
"Name",
"Age",
"Race",
"Gender",
"EyeColour",
"BodyType",
"Length",
"HairColour",
"HairStreaks",
"HairStyle",
"HairLength",
"HairQuality",
"TailSize",
"TailState",
"TailDecoration",
"Tattoos",
"Scars",
"Talents",
"Disabilities",
"FacialHair"
}
for k, v in pairs(o.dropdownTextMap) do
o.dropdownTextMap[v] = k
end
o.myCharacters = {}
o.TargetFrame = nil
return o
end
-----------------------------------------------------------------------------------------------
-- Initialization Functions
-----------------------------------------------------------------------------------------------
function ThisIsMe:Init()
local bHasConfigureFunction = false
local strConfigureButtonText = ""
local tDependencies = {
"Gemini:Timer-1.0",
"LibCommExt-1.0",
"Gemini:Logging-1.2",
"Gemini:Locale-1.0"
}
Apollo.RegisterAddon(self, bHasConfigureFunction, strConfigureButtonText, tDependencies)
end
function ThisIsMe:OnLoad()
-- load our form file
self.xmlDoc = XmlDoc.CreateFromFile("ThisIsMe.xml")
self.xmlDoc:RegisterCallback("OnDocLoaded", self)
GeminiTimer = Apollo.GetPackage("Gemini:Timer-1.0").tPackage
GeminiTimer:Embed(self)
LibCommExt = Apollo.GetPackage("LibCommExt-1.0").tPackage
GeminiLocale = Apollo.GetPackage("Gemini:Locale-1.0").tPackage
Locale = GeminiLocale:GetLocale("ThisIsMe", true)
local GeminiLogging = Apollo.GetPackage("Gemini:Logging-1.2").tPackage
glog = GeminiLogging:GetLogger({
level = GeminiLogging.DEBUG,
pattern = "TIM %D %n %c %l - %m",
appender = "GeminiConsole"
})
self:LoadEntries()
end
function ThisIsMe:OnDocLoaded()
--glog:FlushBuffer()
if self.xmlDoc ~= nil and self.xmlDoc:IsLoaded() then
self.wndMain = Apollo.LoadForm(self.xmlDoc, "ProfileList", nil, self)
if self.wndMain == nil then
Apollo.AddAddonErrorText(self, "Could not load the main window.")
return
end
-- item list
self.wndProfileList = self.wndMain:FindChild("ItemList")
self.wndMain:Show(false, true)
-- Register handlers for events, slash commands and timer, etc.
-- e.g. Apollo.RegisterEventHandler("KeyDown", "OnKeyDown", self)
Apollo.RegisterSlashCommand("tim", "OnThisIsMeOn", self)
Apollo.RegisterSlashCommand("timvi", "OnTestCommand", self)
Apollo.RegisterEventHandler("InterfaceMenuListHasLoaded", "OnInterfaceMenuListHasLoaded", self)
self:OnInterfaceMenuListHasLoaded()
Apollo.RegisterEventHandler("ToggleMyAddon", "OnThisIsMeOn", self)
Apollo.RegisterEventHandler("TargetUnitChanged", "OnTargetUnitChanged", self)
self.wndProfile = Apollo.LoadForm(self.xmlDoc, "Profile", nil, self)
if self.wndProfile == nil then
Apollo.AddAddonErrorText(self, "Could not load the profile window.")
return
end
self.wndProfile:Show(false, true)
self.wndProfileContainer = self.wndProfile:FindChild("ListContainer")
self.wndOptions = Apollo.LoadForm(self.xmlDoc, "OptionsWindow", nil, self)
if self.wndOptions == nil then
Apollo.AddAddonErrorText(self, "Could not load the options window.")
return
end
self.wndOptions:Show(false, true)
self.wndCLWarn = Apollo.LoadForm(self.xmlDoc, "ClearListWarning", nil, self)
if self.wndCLWarn == nil then
Apollo.AddAddonErrorText(self, "Could not load the list-clearing warning window.")
return
end
self.wndCLWarn:Show(false, true)
GeminiLocale:TranslateWindow(Locale, self.wndOptions)
end
self.startupTimer = ApolloTimer.Create(5, false, "CheckComms", self)
self.dataCheckTimer = ApolloTimer.Create(1, true, "CheckData", self)
self:resetHeartbeat()
glog:debug("Currently known alts:")
for k, v in pairs(self.myCharacters) do
glog:debug(k)
end
self.myCharacters[GameLib.GetPlayerCharacterName()] = true
end
function ThisIsMe:OnInterfaceMenuListHasLoaded()
Event_FireGenericEvent("InterfaceMenuList_NewAddOn", "This Is Me", {"ToggleMyAddon", "", "CRB_HUDAlerts:sprAlert_CallBase"})
Event_FireGenericEvent("OneVersion_ReportAddonInfo", "This Is Me", Major, Minor, Patch, Suffix)
end
function ThisIsMe:ConnectToTargetFrame()
if self.TargetFrameAddon == nil then
self.VanillaFrame = Apollo.GetAddon("TargetFrame")
self.TargetFrameAddon = self.VanillaFrame
end
if self.TargetFrameAddon == nil then
self.KuronaFrames = Apollo.GetAddon("KuronaFrames")
self.TargetFrameAddon = self.KuronaFrames
end
if self.TargetFrameAddon == nil then
self.ForgeFrames = Apollo.GetAddon("ForgeUI_UnitFrames")
self.TargetFrameAddon = self.ForgeFrames
end
if self.TargetFrameButton then
self.TargetFrameButton:Destroy()
self.TargetFrameButton = nil
end
if self.CurrentTarget ~= nil and self.CurrentTarget:IsACharacter() and self.characterProfiles[self.CurrentTarget:GetName()] ~= nil then
if self.VanillaFrame then
local targetFrame = self.VanillaFrame.luaTargetFrame
if targetFrame then
targetFrame = targetFrame.wndLargeFrame
if targetFrame then
self.TargetFrame = targetFrame
self.TargetFrameButton = Apollo.LoadForm(self.xmlDoc, "TIMProfileButton", targetFrame, self)
end
end
elseif self.KuronaFrames then
local targetFrame = self.KuronaFrames.targetFrame
if targetFrame then
self.TargetFrameButton = Apollo.LoadForm(self.xmlDoc, "TIMKuronaButton", targetFrame, self)
end
elseif self.ForgeFrames then
local targetFrame = self.ForgeFrames.wndTargetFrame
if targetFrame then
self.TargetFrameButton = Apollo.LoadForm(self.xmlDoc, "TIMForgeButton", targetFrame, self)
end
end
end
end
function ThisIsMe:OnTargetUnitChanged(targetID)
self.CurrentTarget = targetID
self:ConnectToTargetFrame()
end
function ThisIsMe:OpenProfileViaTargetFrame()
if self.CurrentTarget ~= nil then
self.profileEdit = false
self.profileCharacter = self.CurrentTarget:GetName()
self:OpenProfileView()
end
end
function ThisIsMe:LoadEntries()
self.hairStyle = {
Locale["N/A"],
Locale["Other"],
Locale["Plain"],
Locale["Pig-tails"],
Locale["Pony-tail"],
Locale["Mohawk"],
Locale["Dreadlocks"],
Locale["Pompadour"],
Locale["Mullet"],
Locale["Comb-over"]
}
self.hairLength = {
Locale["N/A"],
Locale["Other"],
Locale["Bald"],
Locale["Short/Small"],
Locale["Shoulder-Length/Medium"],
Locale["Waist-Length/Large"],
Locale["Hip-Length/Huge"]
}
self.hairQuality = {
Locale["N/A"],
Locale["Other"],
Locale["Lustrous"],
Locale["Glossy"],
Locale["Dull"],
Locale["Gelled"],
Locale["Styled"],
Locale["Well Kept"],
Locale["Neatly Combed"],
Locale["Plain"],
Locale["Messy"],
Locale["Untamed"],
Locale["Leafy"],
Locale["Unclean"],
Locale["Ragged"],
Locale["Very Curly"],
Locale["Curly"],
Locale["Spikey"],
Locale["Braided"],
Locale["Crystalline"],
Locale["Full"],
Locale["Thinning"]
}
self.hairColour = {
Locale["N/A"],
Locale["Other"],
Locale["Gray"]
}
self.tailSize = {
Locale["N/A"],
Locale["Other"],
Locale["Long"],
Locale["Short"],
Locale["Cut Off"],
Locale["Cut Short"],
Locale["Thick"],
Locale["Muscular"],
Locale["Thin"],
Locale["Ratty"]
}
self.tailState = {
Locale["N/A"],
Locale["Other"],
Locale["Fluffy"],
Locale["Gloriously Fluffy"],
Locale["Bald"],
Locale["Patchy"],
Locale["Scaled"],
Locale["Leathery"],
Locale["Cracked"],
Locale["Dirty"]
}
self.tailDecoration = {
Locale["N/A"],
Locale["Other"],
Locale["Circlet/Band"],
Locale["Pierced - Loops"],
Locale["Pierced - Studs"]
}
self.genders = {
Locale["N/A"],
Locale["Other"],
Locale["Male"],
Locale["Female"],
Locale["Transmale"],
Locale["Transfemale"],
Locale["Genderless"]
}
self.races = {
Locale["N/A"],
Locale["Other"],
Locale["Aurin"],
Locale["Chua"],
Locale["Draken"],
Locale["Granok"],
Locale["Human"],
Locale["Mechari"],
Locale["Mordesh"],
Locale["Cassian Highborn"],
Locale["Cassian Lowborn"],
Locale["Luminai"]
}
self.ages = {
Locale["N/A"],
Locale["Other"],
Locale["Baby"],
Locale["Child"],
Locale["Teen"],
Locale["Young Adult"],
Locale["Adult"],
Locale["Middle-Aged"],
Locale["Old"],
Locale["Ancient"],
Locale["Ageless"]
}
self.bodyTypes = {
Locale["N/A"],
Locale["Other"],
Locale["Skin And Bones"],
Locale["Slim"],
Locale["Average"],
Locale["Thick"],
Locale["Chunky"],
Locale["Wirey"],
Locale["Toned"],
Locale["Athletic"],
Locale["Muscular"],
Locale["Top-Heavy"],
Locale["Pear-Shaped"],
Locale["Perfect Hourglass"],
Locale["Barrel-Chested"]
}
self.heights = {
Locale["N/A"],
Locale["Other"],
Locale["Tiny"],
Locale["Short"],
Locale["Below Average"],
Locale["Average"],
Locale["Above Average"],
Locale["Tall"],
Locale["Gargantuan"]
}
self.sortModes = {
Locale["Newest First"],
Locale["By Character Name"],
Locale["By Customized Name"]
}
end
---------------------------------------------------------------------------------------------------
-- Utility Functions
---------------------------------------------------------------------------------------------------
function ThisIsMe:PrintTable(table)
for k, v in pairs(table) do
if type(v) == "table" then glog:debug(k .. ": table")
elseif type(v) == "userdata" then glog:debug(k .. ": userdata")
elseif type(v) == "boolean" then glog:debug(k .. ": boolean")
else glog:debug(k .. ": " .. v) end
end
end
function ThisIsMe:NilCheckString(name, value)
if value ~= nil then
return name .. " is not nil"
end
return name .. " is nil"
end
function ThisIsMe:getCharAt(input, num)
if input == nil or num == nil or num < 0 then
return nil
end
if input:len() <= num then
return nil
end
return input:sub(num, num)
end
function ThisIsMe:GetRaceEnum(unit)
if unit ~= nil then
local unitRace = unit:GetRaceId()
local race = nil
if unitRace == GameLib.CodeEnumRace.Aurin then race = 3; self.currentFaction = "E"
elseif unitRace == GameLib.CodeEnumRace.Chua then race = 4; self.currentFaction = "D"
elseif unitRace == GameLib.CodeEnumRace.Draken then race = 5; self.currentFaction = "D"
elseif unitRace == GameLib.CodeEnumRace.Granok then race = 6; self.currentFaction = "E"
elseif unitRace == GameLib.CodeEnumRace.Human then race = 7
elseif unitRace == GameLib.CodeEnumRace.Mechari then race = 8; self.currentFaction = "D"
elseif unitRace == GameLib.CodeEnumRace.Mordesh then race = 9; self.currentFaction = "E"
end
return race
end
end
function ThisIsMe:GetGenderEnum(unit)
if unit ~= nil then
local unitGender = unit:GetGender()
local gender = nil
if unit:GetRaceId() == GameLib.CodeEnumRace.Chua then gender = 7
elseif unitGender == Unit.CodeEnumGender.Male then gender = 3
elseif unitGender == Unit.CodeEnumGender.Female then gender = 4
else gender = 1 end
return gender
end
end
function ThisIsMe:Clamp(num, min, max)
if num < min then return min end
if num > max then return max end
return num
end
function ThisIsMe:GetWindowAbsolutePosition(window)
local position = window:GetClientRect() -- might want to change this to GetRect too. Otherwise I'm just gonna get rect.
local x = position.nLeft
local y = position.nTop
local newWindow = window:GetParent()
local left, top, right, bottom
while newWindow ~= nil do
left, top, right, bottom = newWindow:GetRect()
x = x + left
y = y + top
newWindow = newWindow:GetParent()
end
return {nLeft = x, nTop = y, nRight = x + position.nWidth, nBottom = y + position.nHeight, nWidth = position.nWidth, nHeight = position.nHeight}
end
function ThisIsMe:TableIterator(myTable)
local orderedIndex = {}
for key in pairs(myTable) do
table.insert(orderedIndex, key)
end
table.sort(orderedIndex)
return orderedIndex
end
function ThisIsMe:sipairs(myTable)
local sorted = {}
for n in pairs(myTable) do table.insert(sorted, n) end
table.sort(sorted, f)
local i = 0 -- iterator variable
local iter = function () -- iterator function
i = i + 1
if sorted[i] == nil then return nil
else return sorted[i], myTable[sorted[i]]
end
end
return iter
end
---------------------------------------------------------------------------------------------------
-- Profile Functions
---------------------------------------------------------------------------------------------------
function ThisIsMe:Unit()
if self.currentUnit == nil then
self.currentUnit = GameLib.GetPlayerUnit()
if self.currentUnit ~= nil then
self:CheckData() -- we've got new data to check
end
end
return self.currentUnit
end
function ThisIsMe:Character()
if self.currentCharacter == nil and self:Unit() ~= nil then
self.currentCharacter = self:Unit():GetName()
if self.currentCharacter ~= nil then
self:CheckData() -- we've got new data to check
end
end
return self.currentCharacter
end
function ThisIsMe:Faction()
if (self.currentFaction == nil or self.currentFaction == "?") and self:Unit() ~= nil then
local factionNum = self:Unit():GetFaction()
if factionNum == 166 then
self.currentFaction = "D"
elseif factionNum == 167 then
self.currentFaction = "E"
else
glog:error("Faction unknown: " .. (factionNum or "nil"))
return "?"
end
if self.currentFaction ~= nil then
self:CheckData() -- we've got new data to check
end
end
return self.currentFaction
end
function ThisIsMe:Profile()
if self.currentProfile == nil and self:Character() ~= nil then
self.currentProfile = self.characterProfiles[self:Character()]
if self.currentProfile ~= nil then
self:CheckData() -- we've got new data to check
end
end
return self.currentProfile
end
function ThisIsMe:CheckData()
self:Profile() -- just try to get all the data we can, while we're at it.
if self.profileEmptyCheck ~= true and self:Profile() ~= nil then
if next(self.currentProfile) == nil or self.currentProfile.Version == nil then
self.characterProfiles[self:Character()] = self:GetProfileDefaults(self:Character(), self:Unit())
self.characterProfiles[self:Character()].OwnProfile = true
glog:info("Profile was empty/unusable; resetting.")
else
glog:info("Profile found; Name: " .. self.currentCharacter)
end
self.profileEmptyCheck = true
glog:info("Checked profile for content.")
end
if self.dataLoadedCheck ~= true and self.dataLoaded == true and self.currentCharacter ~= nil then
if next(self.characterProfiles) == nil then
self.characterProfiles[self:Character()] = self:GetProfileDefaults(self:Character(), self:Unit())
end
for k, v in self:sipairs(self.characterProfiles) do
self:UpdateOnlineStatus(k)
end
self.dataLoadedCheck = true
glog:info("Checked loaded data for content.")
end
if self.commCheck ~= true and self.Comm ~= nil and self.Comm:IsReady() and self.currentFaction ~= nil and self.currentFaction ~= "?" and self.currentCharacter ~= nil then
self.commCheck = true
if not self.announcedSelf then
self:SendPresenceMessage()
end
end
if not self.fullyLoaded and self.profileEmptyCheck and self.commCheck and self.dataLoaded and self.dataLoadedCheck then
self.fullyLoaded = true
glog:info("TIM fully checked and loaded!")
if self.dataCheckTimer ~= nil then
self.dataCheckTimer:Stop()
self.dataCheckTimer = nil
end
end
end
-----------------------------------------------------------------------------------------------
-- Generic UI Functions
-----------------------------------------------------------------------------------------------
function ThisIsMe:CloseAllWindows()
self.wndMain:Close()
self.wndOptions:Close()
self.wndProfile:Close()
end
-- on SlashCommand "/tim"
function ThisIsMe:OnThisIsMeOn()
self:OpenProfileList()
end
function ThisIsMe:OnClose( wndHandler, wndControl, eMouseButton )
self:CloseAllWindows()
end
-----------------------------------------------------------------------------------------------
-- Profile List Functions
-----------------------------------------------------------------------------------------------
function ThisIsMe:OpenProfileList()
self:CloseAllWindows()
self.wndMain:Invoke()
-- populate the item list
self:PopulateProfileList()
if self.seenEveryone ~= true then
self:SendPresenceRequestMessage()
end
end
function ThisIsMe:OnEditProfileClick()
self.profileEdit = true
self.profileCharacter = self:Character()
self:ApplyDefaultTextMap(self.profileCharacter)
self:OpenProfileView()
end
function ThisIsMe:OpenProfileView()
if self.profileEdit then self.profileCharacter = self:Character() end
self:CloseAllWindows()
self.wndProfile:Invoke()
local Title = self.wndProfile:FindChild("Title")
if Title ~= nil then
Title:SetText(self:GetProfileName(self.profileCharacter))
end
local okButton = self.wndProfile:FindChild("OkButton")
if okButton then
okButton:Show(self.profileEdit, true)
end
local cancelButton = self.wndProfile:FindChild("CancelButton")
if cancelButton then
if self.profileEdit then
cancelButton:SetText("Cancel")
else
cancelButton:SetText("Close")
end
end
self:PopulateProfileView()
end
-- when the Profile's Cancel button is clicked
function ThisIsMe:OnProfileCancel()
self:OpenProfileList()
end
-- when the Profile's OK button is clicked
function ThisIsMe:OnProfileOK()
if self.profileEdit == true and self.editedProfile ~= nil and not self:CompareTableEqualBoth(self.characterProfiles[self:Character()], self.editedProfile) then
self.editedProfile.OwnProfile = true
self.characterProfiles[self:Character()] = self.editedProfile
self:SendPresenceMessage()
end
self:OpenProfileList()
end
function ThisIsMe:OnSave(eLevel)
if eLevel ~= GameLib.CodeEnumAddonSaveLevel.Realm then
return nil
end
if self.characterProfiles ~= nil then
for k, v in pairs(self.characterProfiles) do
v.ProtocolVersion = nil
v.PartialSnippets = nil
v.Online = nil
v.Name = nil
v.BufferedMessages = nil
end
end
self.options.useDefaultProtocolVersion = (self.options.protocolVersion == self.defaultProtocolVersion)
return {characterProfiles = self.characterProfiles, options = self.options, myCharacters = self.myCharacters}
end
function ThisIsMe:OnRestore(eLevel, tData)
if GameLib.CodeEnumAddonSaveLevel.Realm then
if tData.characterProfiles ~= nil then
if next(tData.characterProfiles) ~= nil then
self.characterProfiles = {}
for k, v in pairs(tData.characterProfiles) do
if v.Persist == nil then
v.Persist = not self:IsProfileDefault(v)
end
if v.Persist == true or v.OwnProfile == true then
local addTextMap = false
if v.TextMap == nil then
addTextMap = true
end
self.characterProfiles[k] = self:CopyTable(v, self:GetProfileDefaults(k))
self.characterProfiles[k].ProtocolVersion = nil
if self.characterProfiles[k].Messages ~= nil then
if self.characterProfiles[k].Snippets == nil then
self.characterProfiles[k].Snippets = self.characterProfiles[k].Messages
end
self.characterProfiles[k].Messages = nil
end
self:ApplyDefaultTextMap(self.characterProfiles[k])
end
end
end
end
self.options = self.options or {}
if tData.logLevel ~= nil then
self.options.logLevel = tData.logLevel
end
if tData.debugMode ~= nil then
self.options.debugMode = tData.debugMode
end
if tData.options ~= nil then
self.options = self:CopyTable(tData.options, self.options)
end
if self.options.protocolVersion < self.protocolVersionMin then self.options.protocolVersion = self.protocolVersionMin end
if self.options.protocolVersion > self.protocolVersionMax then self.options.protocolVersion = self.protocolVersionMax end
if self.options.useDefaultProtocolVersion then
self.options.protocolVersion = self.defaultProtocolVersion
end
self.dataLoaded = true
if tData.myCharacters then
for k, v in pairs(tData.myCharacters) do
self.myCharacters[k] = v
end
end
end
self:CheckData()
end
function ThisIsMe:OnOptionsClick( wndHandler, wndControl, eMouseButton )
self:OpenOptions()
end
function ThisIsMe:OnTestClick( wndHandler, wndControl, eMouseButton )
local scale = 1
local nextScale = scale * 32
for x = 0, 5, 1 do
self:TestVarIntRange(scale - 2, scale + 2)
scale = nextScale
nextScale = nextScale * 33
end
end
function ThisIsMe:TestVarIntRange(num, numEnd)
if num < 0 then num = 0 end
for x = num, numEnd, 1 do
self:TestVarInt(x)
end
end
function ThisIsMe:TestVarInt(num)
local enc = LibCommExt:EncodeVarInt(num)
local out, msg = LibCommExt:DecodeVarInt(enc)
glog:debug("StartNum: " .. num .. ", Encoded: " .. enc .. ", Decoded: " .. out)
end
function ThisIsMe:TestVarString(str)
local enc = LibCommExt:EncodeVarString(str)
local out, msg = LibCommExt:DecodeVarString(enc)
glog:debug("StartStr: " .. str .. ", Encoded: " .. enc .. ", Decoded: " .. out)
end
function ThisIsMe:OnTestCommand(cmd, arg)
local msg = LibCommExt:EncodeTypeData(2, tonumber(arg))
glog:debug(msg)
local type, num, tmp = LibCommExt:DecodeTypeData(msg)
glog:debug(type .. " " .. num)
end
-----------------------------------------------------------------------------------------------
-- ProfileList Functions
-----------------------------------------------------------------------------------------------
function ThisIsMe:ProfileSort(profile1, profile2)
if profile1 == nil then
if profile2 == nil then
return false
end
return false
end
if profile2 == nil then return false end
if self.sortByOnline then
local p1online = self:IsPlayerOnline(profile1.Name)
local p2online = self:IsPlayerOnline(profile2.Name)
if p1online and not p2online then return true end
if p2online and not p1online then return false end
end
return profile1.Name < profile2.Name
end
function ThisIsMe:PopulateProfileList()
if self.profileListSortTimer ~= nil then
self.profileListSortTimer:Stop()
self.profileListSortTimer = nil
end
self.profileListSortTimer = ApolloTimer.Create(0.1, false, "PopulateProfileListImpl", self)
end
-- populate profile list
function ThisIsMe:PopulateProfileListImpl()
if self.profileListSortTimer ~= nil then
self.profileListSortTimer:Stop()
self.profileListSortTimer = nil
end
if self.wndProfileList == nil then return end
local position = self.wndProfileList:GetVScrollPos()
-- make sure the profile list is empty to start with
self:DestroyProfileList()
GeminiLocale:TranslateWindow(Locale, self.wndMain)
-- add profiles
local ordered = {}
for k, v in pairs(self.characterProfiles) do
if k ~= nil and v ~= nil then
table.insert(ordered, {Name=k, Profile=v, SortFunction="ProfileSort", SortTable=self})
end
end
table.sort(ordered, function(a,b) return a.SortTable[a.SortFunction](a.SortTable, a, b) end)
for k, v in ipairs(ordered) do
self:AddItem(v.Name, v.Profile)
end
-- now all the profiles are added, call ArrangeChildrenVert to list out the list items vertically
self.wndProfileList:ArrangeChildrenVert()
local testButton = self.wndMain:FindChild("TestButton")
if testButton then
testButton:Show(self.options.debugMode == true, true)
end
local filtersButton = self.wndMain:FindChild("FiltersButton")
if filtersButton then
filtersButton:Show(self.options.debugMode == true, true)
end
self.wndProfileList:SetVScrollPos(position)
end
-- clear the item list
function ThisIsMe:DestroyProfileList()
if self.wndProfileList ~= nil then
local children = self.wndProfileList:GetChildren()
-- destroy all the wnd inside the list
for idx, wnd in pairs(children ) do
wnd:Destroy()
end
end
-- clear the list item array
self.profileListEntries = {}
self.wndSelectedListItem = nil
end
-- add an item into the item list
function ThisIsMe:AddItem(name, profile)
-- load the window item for the list item
local wnd = Apollo.LoadForm(self.xmlDoc, "ListItem", self.wndProfileList, self)
-- keep track of the window item created
self.profileListEntries[wnd] = name
self:SetItem(wnd, name, profile)
wnd:SetData(name)
end
function ThisIsMe:SetItem(item, name, profile)
if self:IsPlayerOnline(name) then
item:SetSprite(listBright)
else
item:SetSprite(listDull)
end
if self.heartbeatTimers == nil or self.heartbeatTimers[name] == nil then self:SchedulePlayerTimeout(name) end
-- give it a piece of data to refer to
local wndItemText = item:FindChild("Name")
if wndItemText then
wndItemText:SetText(" " .. self:GetProfileName(name))
wndItemText:SetTextColor(kcrNormalText) end
local wndIngameName = item:FindChild("IngameName")
if wndIngameName then
wndIngameName:SetText(" " .. Locale["IngameNameShorthand"] .. ": " .. name)
end
local wndVersionText = item:FindChild("Version")
local upToDate = false
if wndVersionText then
if (profile.Version ~= nil and profile.StoredVersion ~= nil and profile.Version == profile.StoredVersion) or name == self:Character() then
wndVersionText:SetText(" " .. Locale["Uptodate"])
wndVersionText:SetTextColor(defaultText)
upToDate = true
else
wndVersionText:SetText(" " .. Locale["Outdated"])
wndVersionText:SetTextColor(defaultText)
end
if profile.ProtocolVersion ~= nil and type(profile.ProtocolVersion) == "number" and not self:AllowedProtocolVersion(profile.ProtocolVersion) then
if profile.ProtocolVersion > self.options.protocolVersion then
wndVersionText:SetText(" Newer Protocol")
else
wndVersionText:SetText(" Outdated Protocol")
end
wndVersionText:SetTextColor(redErrorText)
end
end
local wndRaceGender = item:FindChild("RaceGender")
if wndRaceGender then
local showGender = false
local showRace = false
if profile.Gender ~= nil and profile.Gender >= 3 and profile.Gender ~= 7 then showGender = true end
if profile.Race ~= nil and profile.Race >= 3 then showRace = true end
local text = ""
if showGender then
text = text .. " " .. self.genders[profile.Gender]
end
if showRace then
text = text .. " " .. self.races[profile.Race]
end
wndRaceGender:SetText(text)
end
local wndAgeBuild = item:FindChild("AgeBuild")
if wndAgeBuild then
wndAgeBuild:SetText("")
end
local wndUpdateButton = item:FindChild("UpdateButton")
if wndUpdateButton then
wndUpdateButton:SetData(name)
if upToDate or name == self:Character() then
wndUpdateButton:Enable(false)
else
wndUpdateButton:Enable(self.enableUpdateButton == true and (self:AllowedProtocolVersion(profile.ProtocolVersion) or profile.ProtocolVersion == nil or type(profile.ProtocolVersion) ~= "number"))
end
end
local wndViewButton = item:FindChild("ViewButton")
if wndViewButton then
wndViewButton:SetData(name)
end
local wndKeepButton = item:FindChild("KeepButton")