This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRememberYou.lua
1090 lines (884 loc) · 27.6 KB
/
IRememberYou.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
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
-- IRememberYou addon (IRY)
-- Allows player to rate all players he ever met.
local languages={"EN","GR","FR"}
-- Initialize object
IRY=ZO_Object:Subclass()
-- Translate strings
local IRY_debug=false
local version=0.50
local tex_star="/IRememberYou/textures/star.dds"
local tex_star_over="/IRememberYou/textures/star_over.dds"
-- Util functions
-- debug
local function debug(text)
if not IRY_debug then return end
d(text)
end
local function compareByName(a,b)
if not a["name"] or not a["name"] then return end
return a["name"]<b["name"]
end
-- end of Util functions
-- Addon onload
function IRY_OnLoad(eventCode,AddonName)
-- Looking for known UI addons
if AddonName~="IRememberYou" then return end
debug("Addon loaded")
IRY_Book.currentpage=1
IRY_Obj = IRY:New()
-- chat commanhs
SLASH_COMMANDS["/iry"] = IRY.commandHandler
IRY_Book.loaded=true
end
-- Event functions
-- EVENT_RETICLE_TARGET_CHANGED
local function OnReticleChanged()
unitTag="reticleover"
if IRY:GetPlayerInfo(unitTag) then
alliance,name,level,vetrank=IRY:GetPlayerInfo(unitTag)
else
for i=1,5 do
_G["IRY_TargetRateStar"..i]:SetHidden(true)
end
return
end
-- Add new to database if enabled
if IRY.settings.targetCollect then
IRY:AddPlayer(alliance,name,level,vetrank)
end
-- Update info about target stars displaying
-- search for this name in player database
for k,v in pairs(IRY.playerDatabase.data) do
if v.name==name then
debug("Player found in db: "..name.." id: "..k)
-- Update player info
IRY:AddPlayer(alliance,name,level,vetrank)
-- display new stars at UI
if v.rate==-1 or not v.rate then
for i=1,5 do
_G["IRY_TargetRateStar"..i]:SetHidden(true)
end
end
for i=1,v.rate do
if i>=1 and i<=5 then
_G["IRY_TargetRateStar"..i]:SetHidden(false)
end
end
for i=v.rate+1,5 do
if i>=1 and i<=5 then
_G["IRY_TargetRateStar"..i]:SetHidden(true)
end
end
end
end
end
local function AddGroup()
debug("AddGroup called")
for i=1,GetGroupSize() do
unitTag=GetGroupUnitTagByIndex(i)
if IRY:GetPlayerInfo(unitTag) then
alliance,name,level,vetrank=IRY:GetPlayerInfo(unitTag)
IRY:AddPlayer(alliance,name,level,vetrank)
end
end
end
local function AddPlayerFromMenu(name)
IRY:AddPlayer(GetUnitAlliance("player"),name,0,0)
IRY_BookSearchEdit:SetText(name)
IRY:SearchPlayer(name)
IRY:SetHideState(false)
end
local function ChatHookClicked(self,linkData, linkText, button, ...)
local linkType, _, _ = zo_strsplit(":", linkData)
-- debug("Self: "..tostring(self:GetName()))
debug("linkData: "..tostring(linkData))
debug("linkType: "..tostring(linkType))
-- Call original
ZO_ChatSystem_OnLinkClicked(linkData, linkText, button, ...)
-- add our menu only to player linktype
if linkType ~= CHARACTER_LINK_TYPE and linkType~=DISPLAY_NAME_LINK_TYPE then return end
start,stop=string.find(linkData,"%[.*")
name=string.sub(linkData,start+1,stop-1)
debug("name: "..tostring(name))
if button == 2 then
ZO_Menu:SetHidden(true)
AddMenuItem(IRY_STRING_CHAT_MENU, function() AddPlayerFromMenu(name) end)
ShowMenu(nil, 1)
end
end
local function GameHooks()
debug("Unregistered: "..tostring(EVENT_MANAGER:UnregisterForEvent("IRememberYou", EVENT_PLAYER_ACTIVATED)))
local oldInteract = PLAYER_TO_PLAYER.ShowPlayerInteractMenu
PLAYER_TO_PLAYER.ShowPlayerInteractMenu = function(self, isIgnored)
self.menu:AddEntry(IRY_STRING_CHAT_MENU, tex_star, tex_star_over, function() AddPlayerFromMenu(self.currentTarget) end)
oldInteract(self, isIgnored)
end
for i=1,#ZO_ChatWindow.container.windows do
ZO_ChatWindow.container.windows[i].buffer:SetHandler("OnLinkClicked",ChatHookClicked)
end
end
-- end of Event functions
-- Core functions
function IRY:New()
debug("New called")
local obj = ZO_Object.New(self)
obj:Initialize(self)
return obj
end
-- initialize
function IRY:Initialize(self)
debug("Initialize called")
-- load data
IRY:LoadSavedVars()
-- Apply translate
IRY:ApplyLanguage(IRY.settings.language)
-- Create settings
IRY:CreateSettings()
-- Create scene
IRY:CreateScene()
-- Register Events
self:SetGroupCollectState()
-- Target events are already registered. We need it to show stars in UI
self.control=self
self.rows={}
-- Create rows
-- left page
for i=1,18 do
self.rows[i] = CreateControlFromVirtual("IRY_BookRow", IRY_Book, "IRY_BookRow_Virtual",i)
self.rows[i]:SetAnchor(RIGHT,IRY_Book,CENTER,0,-340+(35*i))
self.rows[i].stars={}
-- stars
for j=1,5 do
self.rows[i].stars[j] = CreateControlFromVirtual(("IRY_BookRow"..i.."Star"), self.rows[i], "IRY_Star_Virtual",j)
self.rows[i].stars[j]:SetAnchor(LEFT,self.rows[i],LEFT,240-30+(30*j),0)
self.rows[i].stars[j].starnumber=j
end
end
-- right page
for i=19,36 do
self.rows[i] = CreateControlFromVirtual("IRY_BookRow", IRY_Book, "IRY_BookRow_Virtual",i)
self.rows[i]:SetAnchor(LEFT,IRY_Book,CENTER,20,-970+(35*i))
self.rows[i].stars={}
-- stars
for j=1,5 do
self.rows[i].stars[j] = CreateControlFromVirtual(("IRY_BookRow"..i.."Star"), self.rows[i], "IRY_Star_Virtual",j)
self.rows[i].stars[j]:SetAnchor(LEFT,self.rows[i],LEFT,240-30+(30*j),0)
self.rows[i].stars[j].starnumber=j
end
end
-- search in progress
IRY.searching=false
-- Current show state:
IRY.hidden=true
-- Addintional stars displayeed
IRY.starsShowed=false
IRY:SwitchPage(1)
end
-- Load vars
function IRY:LoadSavedVars()
debug("LoadSavedVars called")
local default_playerDatabase={
data={}
}
local default_settings = {
groupCollect=true,
targetCollect=false,
language="EN"
}
self.settings = ZO_SavedVars:NewAccountWide("IRY_SavedVars", version, "settings", default_settings, nil)
self.playerDatabase = ZO_SavedVars:NewAccountWide("IRY_SavedVars", version, "playerDatabase", default_playerDatabase, nil)
self.searchDatabase = {}
end
-- Display functions
-- create settings
function IRY:CreateSettings()
local panelData = {
type = "panel",
name = IRY_STRING_SETTINGS_TITLE,
displayName = IRY_STRING_SETTINGS_TITLE,
author = "Bad Volt",
version = version
}
local optionsData={
[1] = {
type = "header",
name = IRY_STRING_SETTINGS_LANGUAGE_HEADER
},
[2] = {
type = "dropdown",
name = IRY_STRING_SETTINGS_LANGUAGE,
tooltip = IRY_STRING_SETTINGS_LANGUAGE_TOOLTIP,
choices = languages,
getFunc = function() return IRY.settings.language end,
setFunc = function(lang) return IRY:ChangeLanguage(lang) end,
warning = IRY_STRING_SETTINGS_LANGUAGE_WARNING
},
[3] = {
type = "header",
name = IRY_STRING_SETTINGS_COLLECTINFO_HEADER
},
[4] = {
type = "checkbox",
name = IRY_STRING_SETTINGS_CHECKBOX_1,
tooltip = IRY_STRING_SETTINGS_CHECKBOX_1_TOOLTIP,
getFunc = function() return self:IsGroupCollectEnabled() end,
setFunc = function() IRY.settings.groupCollect = not IRY.settings.groupCollect end
},
[5] = {
type = "checkbox",
name = IRY_STRING_SETTINGS_CHECKBOX_2,
tooltip = IRY_STRING_SETTINGS_CHECKBOX_2_TOOLTIP,
getFunc = function() return self:IsTargetCollectEnabled() end,
setFunc = function() IRY.settings.targetCollect = not IRY.settings.targetCollect end,
warning = IRY_STRING_SETTINGS_CHECKBOX_2_WARNING_DESRC
}
}
local LAM = LibStub("LibAddonMenu-2.0")
LAM:RegisterAddonPanel("IRY_Controls", panelData)
LAM:RegisterOptionControls("IRY_Controls", optionsData)
end
-- create scene
function IRY:CreateScene()
if not IRY_SCENE then
IRY_BOOK_FRAGMENT = ZO_FadeSceneFragment:New(IRY_Book)
IRY_COMMENT_FRAGMENT = ZO_FadeSceneFragment:New(IRY_Comment)
IRY_SCENE = ZO_Scene:New("iry", SCENE_MANAGER)
IRY_SCENE:AddFragment(FRAME_PLAYER_FRAGMENT)
IRY_SCENE:AddFragment(FRAME_EMOTE_FRAGMENT_JOURNAL)
IRY_SCENE:AddFragment(IRY_BOOK_FRAGMENT)
IRY_SCENE:AddFragment(IRY_COMMENT_FRAGMENT)
-- .dat unpacked only from 1.0. Looks like sth changed since then, using treasure map sound
IRY_SCENE:AddFragment(TREASURE_MAP_SOUNDS)
end
end
function IRY:ShowScene()
SCENE_MANAGER:Show("iry")
IRY_Comment:SetHidden(true)
end
function IRY:HideScene()
SCENE_MANAGER:Hide("iry")
IRY_Comment:SetHidden(true)
end
function IRY:SetHideState(state)
debug("New state: "..tostring(state))
if not state then
IRY:ShowScene()
else
IRY:HideScene()
end
end
-- settings Get functions
function IRY:IsGroupCollectEnabled()
return IRY.settings.groupCollect
end
function IRY:IsTargetCollectEnabled()
return IRY.settings.targetCollect
end
-- settings Set functions
-- Group
function IRY:SetGroupCollectState()
if IRY.settings.groupCollect then
debug("Registering Group events")
-- someone (except me) joined
EVENT_MANAGER:RegisterForEvent("IRememberYou", EVENT_GROUP_MEMBER_JOINED, AddGroup)
-- someone left
EVENT_MANAGER:RegisterForEvent("IRememberYou", EVENT_GROUP_MEMBER_LEFT, AddGroup)
-- invite recived
EVENT_MANAGER:RegisterForEvent("IRememberYou", EVENT_GROUP_INVITE_RECEIVED, AddGroup)
-- role changed
EVENT_MANAGER:RegisterForEvent("IRememberYou", EVENT_GROUP_MEMBER_ROLES_CHANGED, AddGroup)
else
debug("Unregistering Group events")
-- someone (except me) joined
EVENT_MANAGER:UnregisterForEvent("IRememberYou", EVENT_GROUP_MEMBER_JOINED)
-- someone left
EVENT_MANAGER:UnregisterForEvent("IRememberYou", EVENT_GROUP_MEMBER_LEFT)
-- invite recived
EVENT_MANAGER:UnregisterForEvent("IRememberYou", EVENT_GROUP_INVITE_RECEIVED)
-- role changed
EVENT_MANAGER:UnregisterForEvent("IRememberYou", EVENT_GROUP_MEMBER_ROLES_CHANGED)
end
end
function IRY:SetTargetCollectState()
if IRY.settings.targetCollect then
debug("Registering Target events")
else
debug("Unregistering Target events")
end
end
-- chat commands
function IRY.commandHandler(text)
-- We need to save register
if string.match(text,"^add ") then
local first,last=string.find(text,'%".+%"')
if (not first) or (not last) then d(IRY_STRING_ERROR_ADD_FORMAT) return end
local name = string.sub(text, first+1, last-1)
debug("Name from add: "..name)
IRY:AddPlayer(GetUnitAlliance("player"),name,0,0)
IRY:SetHideState(false)
end
-- rest to lower
text = string.lower(text)
if text=="cls" then
IRY:cls()
elseif text=="" then
IRY:SetHideState(not IRY.hidden)
else
for i=1,#IRY_TABLE_COMMANDS do
d(IRY_TABLE_COMMANDS[i])
end
end
end
-- clear addon data
function IRY:cls()
self.playerDatabase.data={}
ReloadUI()
end
-- end of chat commands
-- get info about target
function IRY:GetPlayerInfo(unitTag)
debug("IRY:GetPlayerInfo called")
local unitType = GetUnitType(unitTag)
local name = GetUnitName(unitTag)
if unitType~=UNIT_TYPE_PLAYER then return false end
if name=="" then return false end
local level = GetUnitLevel(unitTag)
local vetrank = GetUnitVeteranRank(unitTag)
local alliance = GetUnitAlliance(unitTag)
return alliance,name,level,vetrank
end
-- add player to database
function IRY:AddPlayer(alliance,name,level,vetrank)
debug("IRY:AddPlayer called")
-- Do not add self
if name==GetUnitName("player") then return end
local playerid=false
local saved_rate
debug(tostring(alliance)..", "..tostring(name)..", "..tostring(level)..", "..tostring(vetrank))
-- search for database
for i=1,#self.playerDatabase.data do
if self.playerDatabase.data[i].name==name then
playerid=i
end
end
if playerid then
-- if this player is already at our DB -> update info
saved_rate=self.playerDatabase.data[playerid].rate
saved_comment=self.playerDatabase.data[playerid].comment
self.playerDatabase.data[playerid]={
["name"]=name,
["alliance"]=alliance,
["level"]=level,
["vetrank"]=vetrank,
["rate"]=saved_rate,
["comment"]=saved_comment
}
else
-- if there's no such player -> add player data
self.playerDatabase.data[#self.playerDatabase.data+1]={
["name"]=name,
["alliance"]=alliance,
["level"]=level,
["vetrank"]=vetrank,
["rate"]=-1,
["comment"]=""
}
end
-- sort table by name
if #self.playerDatabase.data>1 then
table.sort(self.playerDatabase.data, compareByName)
end
IRY:SwitchPage(IRY_Book.currentpage)
-- repeat search after db is sorted and return id of player added
for i=1,#self.playerDatabase.data do
if self.playerDatabase.data[i].name==name then
debug("Player name: '"..name.."'. Player id: "..i)
return i
end
end
end
-- Allows playername or table[id]
function IRY:RemovePlayer(...)
debug("IRY:RemovePlayer called")
local arg={...}
local removed=false
if #arg>1 then
debug("Too many RemovePlayer attributes")
return false
end
if type(arg[1])=="number" then
local id=arg[1]
for k,v in pairs(self.playerDatabase.data) do
if k==id then
debug ("Player "..v.name.." with ID "..k.." was removed from db")
table.remove (self.playerDatabase.data,k)
removed = true
end
end
elseif type(arg[1])=="string" then
local name=arg[1]
for k,v in pairs(self.playerDatabase.data) do
if v.name==name then
debug ("Player "..v.name.." with ID "..k.." was removed from db")
table.remove (self.playerDatabase.data,k)
removed = true
end
end
else
debug("Wrong RemovePlayer attribute type")
return
end
if not removed then
debug("Something went wrong while removing player "..tostring(arg[1]))
end
return removed
end
-- Allows playername or id, rate
function IRY:RatePlayer(id,rate)
debug("IRY:RatePlayer called")
local rated=false
if type(id)=="number" and type(rate)=="number" then
for k,v in pairs(self.playerDatabase.data) do
if k==id then
debug ("Player "..v.name.." with ID "..k.." was rated for: "..rate)
v.rate=rate
rated=true
end
end
else
debug("Wrong attr type")
return rated
end
end
-- Shows comment window
function IRY:ShowCommentWindow(id)
debug("IRY:ShowCommentWindow called")
IRY_Comment:SetHidden(false)
IRY_Book:SetHidden(true)
IRY_Comment.id=id
local name=self.playerDatabase.data[id].name
local comment=self.playerDatabase.data[id].comment
IRY_CommentTitle:SetText(name)
IRY_CommentTextEdit:SetText(comment)
end
-- Save note about player
function IRY:SaveComment(self)
debug("IRY:SaveComment called")
-- 2nd parent
local parent=self:GetParent()
parent=parent:GetParent()
local id=parent.id
local comment=self:GetText()
debug("SaveComment=>")
debug("self: "..tostring(self:GetName()))
debug("2nd parent: "..tostring(parent:GetName()))
debug("id: "..tostring(id))
debug("comment: "..tostring(comment))
IRY.playerDatabase.data[id].comment=comment
IRY_Comment:SetHidden(true)
IRY_Book:SetHidden(false)
end
-- Switch page. Form 1
function IRY:SwitchPage(pagen)
debug("IRY:SwitchPage called")
local maxpages=math.ceil(#self.playerDatabase.data/36)
if maxpages<=0 then maxpages=1 end
self.searching=false
IRY:HidePrevNextButtons()
-- hide/show Prev button
if pagen>1 then
IRY_BookKeyStripMouseButtonsPreviousPage:SetHidden(false)
else
IRY_BookKeyStripMouseButtonsPreviousPage:SetHidden(true)
end
-- hide/show Prev button
if pagen<maxpages then
IRY_BookKeyStripMouseButtonsNextPage:SetHidden(false)
else
IRY_BookKeyStripMouseButtonsNextPage:SetHidden(true)
end
debug("pagen: "..pagen)
debug("maxpages: "..maxpages)
if pagen<1 or pagen>maxpages then return debug("pagen<1 or pagen>maxpages") end
IRY_Book.currentpage=pagen
pagen=pagen-1
for i=1,36 do
IRY:FillRow(i,i+(pagen*36))
end
if #self.playerDatabase.data==0 then
for i=1,36 do
self.rows[i]:SetHidden(true)
IRY_BookCounterLeftPage:SetText(0)
end
end
-- Modify counters
for i=1,18 do
if not self.rows[i]:IsHidden() then
IRY_BookCounterLeftPage:SetText(i+36*(IRY_Book.currentpage-1))
end
end
local allrowshidden=true
for i=19,36 do
if not self.rows[i]:IsHidden() then
IRY_BookCounterRightPage:SetText(i+36*(IRY_Book.currentpage-1))
allrowshidden=false
end
end
-- hide right counter if all rows are hidden
if allrowshidden then
IRY_BookCounterRightPage:SetHidden(true)
else
IRY_BookCounterRightPage:SetHidden(false)
end
IRY_BookCounterTotal:SetText(#self.playerDatabase.data)
end
-- Fill row
function IRY:FillRow(RowID,PlayerId)
if RowID<1 or RowID>36 then debug("Wrong Row ID") return false end
local basename=self.rows[RowID]:GetName()
if not self.playerDatabase.data[PlayerId] then
self.rows[RowID]:SetHidden(true)
return
end
-- hide if no such PlayerId
if self.playerDatabase.data[PlayerId] then
self.rows[RowID]:SetHidden(false)
else
self.rows[RowID]:SetHidden(true)
return
end
-- Apply name
if self.playerDatabase.data[PlayerId].name then
_G[basename.."Name"]:SetText(self.playerDatabase.data[PlayerId].name)
else
debug ("No Name for id: "..PlayerId)
end
-- Apply Alliance
if self.playerDatabase.data[PlayerId].alliance then
_G[basename.."Alliance"]:SetTexture(GetAllianceBannerIcon(self.playerDatabase.data[PlayerId].alliance))
else
debug ("No Alliance for id: "..PlayerId)
end
-- Apply Rate
if self.playerDatabase.data[PlayerId].rate then
local rate=self.playerDatabase.data[PlayerId].rate
if rate~=-1 then
for i=1,rate do
_G[basename].stars[i]:SetColor(1,1,0,1)
end
else
for i=1,5 do
_G[basename].stars[i]:SetColor(1,0,0,0.5)
end
end
else
debug ("No Rate for id: "..PlayerId)
end
-- debug("Setting PlayerId: "..PlayerId.."for RowID: "..RowID)
self.rows[RowID].id=PlayerId
-- Apply comment state
if IRY.playerDatabase.data[PlayerId].comment~="" then
_G[basename.."SetComment"]:SetColor(0,1,0,1)
else
_G[basename.."SetComment"]:SetColor(1,1,1,1)
end
end
-- XML function
-- Apply star to row clicked
function IRY:ApplyStar(self)
debug("IRY:ApplyStar called")
local id=(self:GetParent()).id
local rate=self.starnumber
debug("Player id: "..id)
debug("Rate: "..rate)
IRY:RatePlayer(id,rate)
-- Update book
IRY:SwitchPage(IRY_Book.currentpage)
end
-- XML function
-- Enter comment to player
function IRY:SetComment(self)
debug("IRY:SetComment called")
local parent=self:GetParent()
local id=parent.id
debug("Set Comment for id: "..id)
IRY:ShowCommentWindow(id)
-- Update book
IRY:SwitchPage(IRY_Book.currentpage)
end
-- XML function
-- LBM - drop rate
-- RMB - remove player from db
function IRY:DropRate(self, button)
debug("IRY:DropRate called")
local parent = self:GetParent()
local id=parent.id
if button==1 then
IRY:RatePlayer(id,-1)
IRY:ApplyRealStars(self)
elseif button==2 then
IRY:RemovePlayer(id)
end
-- Update book
IRY:SwitchPage(IRY_Book.currentpage)
end
-- XML function
-- Capture click on next/previous page
function IRY:SwitchPageClick(self, button)
debug("IRY:SwitchPageClick called")
local name=self:GetName()
if button==1 and name=="IRY_BookKeyStripMouseButtonsPreviousPage" then
IRY:SwitchPage(IRY_Book.currentpage-1)
elseif button == 2 and name=="IRY_BookKeyStripMouseButtonsNextPage" then
IRY:SwitchPage(IRY_Book.currentpage+1)
end
end
-- XML function
-- Highlight Stars OnMouseEnter
function IRY:HighhlightStars(self)
-- debug("IRY:HighhlightStars called")
local parent=self:GetParent()
for i=1,self.starnumber do
parent.stars[i]:SetColor(0,1,0,1)
end
for i=self.starnumber+1,1 do
parent.stars[i]:SetColor(1,0,0,0.5)
end
end
-- XML function
-- Apply current star value to this row
function IRY:ApplyRealStars(self)
-- debug("IRY:ApplyRealStars called")
local parent=self:GetParent()
local currentstars=IRY.playerDatabase.data[parent.id].rate
-- debug("currentstars: "..currentstars)
if currentstars>=1 and currentstars<=5 then
for i=1,currentstars do
parent.stars[i]:SetColor(1,1,0,1)
end
for i=currentstars+1,5 do
parent.stars[i]:SetColor(1,0,0,0.5)
end
else
for i=1,5 do
parent.stars[i]:SetColor(1,0,0,0.5)
end
end
end
function IRY:ApplyCommentRealState(self)
debug("IRY:ApplyCommentRealState called")
local parent=self:GetParent()
local id=parent.id
debug("self: "..self:GetName())
debug("parent: "..parent:GetName())
if IRY.playerDatabase.data[id].comment~="" then
self:SetColor(0,1,0,1)
else
self:SetColor(1,1,1,1)
end
end
-- XML function
-- Search for intut text in db
-- SearchDatabase stores only player ID from playerDatabase.
function IRY:SearchPlayer(text)
debug("IRY:SearchPlayer called. Text: "..text)
-- do not search if player missed focus
if text==IRY_STRING_SEARCH_DEFAULT then
self.searching=false
IRY:HidePrevNextButtons()
-- IRY:SwitchPage(1)
IRY_BookCounterLeftPage:SetHidden(false)
IRY_BookCounterRightPage:SetHidden(false)
IRY_BookCounterTotal:SetHidden(false)
debug("nil or default")
return
end
if text=="" then
IRY:SwitchPage(1)
return
end
IRY:HidePrevNextButtons()
self.searching=true
self.searchDatabase={}
for k,v in pairs(IRY.playerDatabase.data) do
-- debug("Search for: "..text.." in "..v.name)
local searchresult,_=string.find(string.lower(v.name),string.lower(text),0,true)
if searchresult ~=nil then
self.searchDatabase[#self.searchDatabase+1]=k
end
end
for i=1,#self.searchDatabase do
IRY:FillRow(i,self.searchDatabase[i])
end
for i=#self.searchDatabase+1,36 do
self.rows[i]:SetHidden(true)
end
IRY_BookCounterLeftPage:SetHidden(true)
IRY_BookCounterRightPage:SetHidden(true)
IRY_BookCounterTotal:SetHidden(true)
end
-- Hide Next/prev button if search is in progress
function IRY:HidePrevNextButtons()
debug("IRY:HidePrevNextButtons called")
local maxpages=math.ceil(#self.playerDatabase.data/36)
if maxpages<=0 then maxpages=1 end
debug("self.searching: "..tostring(self.searching))
if maxpages==1 then return end
if self.searching then
debug("HidePrevNextButtons: hiding all")
IRY_BookCounterLeftPage:SetHidden(true)
IRY_BookCounterRightPage:SetHidden(true)
IRY_BookCounterTotal:SetHidden(true)
IRY_BookKeyStripMouseButtonsPreviousPage:SetHidden(true)
IRY_BookKeyStripMouseButtonsNextPage:SetHidden(true)
else
debug("HidePrevNextButtons: showing all")
IRY_BookCounterLeftPage:SetHidden(false)
IRY_BookCounterRightPage:SetHidden(false)
IRY_BookCounterTotal:SetHidden(false)
IRY_BookKeyStripMouseButtonsPreviousPage:SetHidden(false)
IRY_BookKeyStripMouseButtonsNextPage:SetHidden(false)
end
end
function IRY:ChangeLanguage(lang)
debug("IRY:ChangeLanguage called")
if lang~="EN" and lang ~="GR" and lang ~="FR" then d("Sorry, "..lang.." is not supported yet") return false end
self.settings.language=lang
ReloadUI()
end
function IRY:ApplyLanguage(lang)
debug("IRY:ApplyLanguage called: "..lang)
if lang=="EN" then
-- XML Book
IRY_STRING_BOOK_TITLE="I Remember You"
IRY_STRING_BOOK_SEARCH="Search"
IRY_STRING_SEARCH_DEFAULT="Player name"
-- Settings
IRY_STRING_SETTINGS_TITLE="I Remember You"
IRY_STRING_SETTINGS_LANGUAGE_HEADER="Language"
IRY_STRING_SETTINGS_LANGUAGE="Select language:"
IRY_STRING_SETTINGS_LANGUAGE_TOOLTIP="Select language, you want this addon to work at"
IRY_STRING_SETTINGS_LANGUAGE_WARNING="UI will be reloaded"
IRY_STRING_SETTINGS_COLLECTINFO_HEADER="Add players form:"
IRY_STRING_SETTINGS_CHECKBOX_1="Group"
IRY_STRING_SETTINGS_CHECKBOX_1_TOOLTIP="Enables/Disables adding players from groups"
IRY_STRING_SETTINGS_CHECKBOX_2="Target"
IRY_STRING_SETTINGS_CHECKBOX_2_TOOLTIP="Enables/Disables adding players from your current target"
IRY_STRING_SETTINGS_CHECKBOX_2_WARNING_DESRC="This option can seriously increase number of players in your IRY book"
-- Controls
IRY_STRING_CONTROLS_DESCR="Show/Hide IRY book"
-- Other
IRY_STRING_ERROR_ADD_FORMAT="Wrong player name format"
IRY_STRING_CHAT_MENU="Rate"
IRY_TABLE_COMMANDS={
"==IRY commands: ==",
"/iry - display/hide IRY book",
'/iry add "Name" - add player',
"/iry cls - clear all data"
}
elseif lang=="GR" then
-- XML Book
IRY_STRING_BOOK_TITLE="I Remember You"
IRY_STRING_BOOK_SEARCH="Suche"
IRY_STRING_SEARCH_DEFAULT="Spieler Name"
-- Settings
IRY_STRING_SETTINGS_TITLE="I Remember You"
IRY_STRING_SETTINGS_LANGUAGE_HEADER="Sprache"
IRY_STRING_SETTINGS_LANGUAGE="Sprache auswählen:"
IRY_STRING_SETTINGS_LANGUAGE_TOOLTIP="Wähle die Sprache für dieses Addon aus"
IRY_STRING_SETTINGS_LANGUAGE_WARNING="UI wird neu geladen"
IRY_STRING_SETTINGS_COLLECTINFO_HEADER="Spieler hinzufügen über:"
IRY_STRING_SETTINGS_CHECKBOX_1="Gruppen"
IRY_STRING_SETTINGS_CHECKBOX_1_TOOLTIP="Aktiviert/Deaktiviert das Hinzufügen von Spieler aus Gruppen"
IRY_STRING_SETTINGS_CHECKBOX_2="Ziel"
IRY_STRING_SETTINGS_CHECKBOX_2_TOOLTIP="Aktiviert/Deaktiviert das Hinzufügen des aktuellen Zieles"
IRY_STRING_SETTINGS_CHECKBOX_2_WARNING_DESRC="Wird diese Option aktiviert kann die Anzahl der Einträge in deinem IRY Buch signifikant ansteigen"
-- Controls
IRY_STRING_CONTROLS_DESCR="IRY Buch anzeigen/verbergen"
-- Other
IRY_STRING_ERROR_ADD_FORMAT="Falsches Spieler Name Format"
IRY_STRING_CHAT_MENU="Bewerten"
IRY_TABLE_COMMANDS={
"==IRY commands: ==",
"/iry - IRY book anzeigen/verbergen",
'/iry add "Name" - Spieler hinzufügen',
"/iry cls - Alle Daten löschen"
}
elseif lang=="FR" then
-- XML Book
IRY_STRING_BOOK_TITLE="I Remember You"
IRY_STRING_BOOK_SEARCH="Chercher"
IRY_STRING_SEARCH_DEFAULT="Nom du joueur"