forked from kahluamods/konfersk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKSK-Users.lua
1521 lines (1309 loc) · 39.2 KB
/
KSK-Users.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
--[[
KahLua KonferSK - a suicide kings loot distribution addon.
WWW: http://kahluamod.com/ksk
Git: https://github.com/kahluamods/konfersk
IRC: #KahLua on irc.freenode.net
E-mail: [email protected]
Please refer to the file LICENSE.txt for the Apache License, Version 2.0.
Copyright 2008-2020 James Kean Johnston. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
local K = LibStub:GetLibrary("KKore")
if (not K) then
return
end
local ksk = K:GetAddon("KKonferSK")
local L = ksk.L
local KUI = ksk.KUI
local MakeFrame = KUI.MakeFrame
-- Local aliases for global or Lua library functions
local _G = _G
local tinsert = table.insert
local tremove = table.remove
local tsort = table.sort
local tostring, tonumber = tostring, tonumber
local strfmt = string.format
local strfind = string.find
local strlower = string.lower
local pairs, ipairs, next = pairs, ipairs, next
local assert = assert
local info = ksk.info
local err = ksk.err
local white = ksk.white
local green = ksk.green
local red = ksk.red
local class = ksk.class
local aclass = ksk.aclass
local createuserdlg = nil
local seluser = nil
local umemlist = nil
local uinfo = {}
local qf = {}
local HIST_WHEN = ksk.HIST_WHEN
local HIST_WHAT = ksk.HIST_WHAT
local HIST_WHO = ksk.HIST_WHO
local HIST_HOW = ksk.HIST_HOW
--
-- This file contains all of the UI handling code for the users panel,
-- as well as all user manipulation functions.
--
local function changed(res)
local res = res or false
if (not seluser) then
res = true
end
qf.userupdbtn:SetEnabled(not res)
end
local function hide_popup()
if (ksk.popupwindow) then
ksk.popupwindow:Hide()
ksk.popupwindow = nil
end
end
local function setup_uinfo()
if (not seluser) then
return
end
uinfo = {}
uinfo.role = ksk.UserRole(seluser) or 0
uinfo.enchanter = ksk.UserIsEnchanter(seluser) or false
local isalt, altidx, _, _, altname = ksk.UserIsAlt(seluser)
uinfo.isalt = isalt or false
uinfo.main = altname or ""
uinfo.mainid = altidx
uinfo.frozen = ksk.UserIsFrozen(seluser) or false
if (ksk.cfg.users[seluser].alts) then
uinfo.ismain = true
else
uinfo.ismain = false
end
end
local function enable_selected(en)
qf.usertopbar.seluser:SetShown(en)
qf.useropts.userrole:SetEnabled(en)
qf.useropts.enchanter:SetEnabled(en)
qf.useropts.isalt:SetEnabled(en)
qf.useropts.mainname:SetEnabled(en)
qf.useropts.frozen:SetEnabled(en)
qf.useropts.isalt:SetEnabled(en)
qf.useropts.mainsel:SetEnabled(en)
qf.userbuttons.deletebutton:SetEnabled(en)
qf.userbuttons.renamebutton:SetEnabled(en)
end
local function users_selectitem(objp, idx, slot, btn, onoff)
local onoff = onoff or false
hide_popup()
enable_selected(onoff)
if (onoff) then
seluser = ksk.sortedusers[idx].id
setup_uinfo()
if (ksk.cfg.owner == seluser) then
qf.userbuttons.deletebutton:SetEnabled(false)
end
qf.usertopbar.SetCurrentUser(seluser)
qf.useropts.userrole:SetValue(uinfo.role)
qf.useropts.enchanter:SetChecked(uinfo.enchanter)
qf.useropts.isalt:SetChecked(uinfo.isalt)
qf.useropts.mainname:SetText(uinfo.main)
qf.useropts.frozen:SetChecked(uinfo.frozen)
qf.useropts.isalt:SetEnabled(not uinfo.ismain)
qf.useropts.mainsel:SetEnabled(uinfo.isalt)
else
seluser = nil
end
ksk.RefreshMembership()
changed(true)
end
function ksk.CreateRoleListDropdown(name, x, y, parent, w)
local kk = ksk.KK
local arg = {
name = name, mode = "SINGLE", itemheight = 16,
x = x, y = y, dwidth = w or 150,
label = { text = L["User Role"], pos = "LEFT" },
items = {
{ text = kk.rolenames[kk.ROLE_UNSET], value = kk.ROLE_UNSET },
{ text = kk.rolenames[kk.ROLE_HEALER], value = kk.ROLE_HEALER },
{ text = kk.rolenames[kk.ROLE_MELEE], value = kk.ROLE_MELEE },
{ text = kk.rolenames[kk.ROLE_RANGED], value = kk.ROLE_RANGED },
{ text = kk.rolenames[kk.ROLE_CASTER], value = kk.ROLE_CASTER },
{ text = kk.rolenames[kk.ROLE_TANK], value = kk.ROLE_TANK },
},
tooltip = { title = "$$", text = L["TIP071"] },
}
return KUI:CreateDropDown(arg, parent)
end
local function create_user_button()
if (not createuserdlg) then
local arg = {
x = "CENTER", y = "MIDDLE",
name = "KSK CreateUserDlg",
title = L["Create User"],
border = true,
width = 350,
height = 175,
canmove = true,
canresize = false,
escclose = true,
blackbg = true,
okbutton = { text = K.ACCEPTSTR },
cancelbutton = { text = K.CANCELSTR },
}
local ret = KUI:CreateDialogFrame(arg)
arg = {
x = 5, y = 0, len = 48,
label = { text = L["User Name"], pos = "LEFT" },
tooltip = { title = "$$", text = L["TIP072"] },
}
ret.username = KUI:CreateEditBox(arg, ret)
ret.username:SetFocus()
arg = {
x = 5, y = -30, dwidth = 125, mode = "SINGLE", itemheight = 16,
label = { text = L["User Class"], pos = "LEFT" },
items = {}, name = "KSKCreateUserClassDD",
tooltip = { title = "$$", text = L["TIP073"] },
}
for k,v in pairs(K.IndexClass) do
if (v.c and not v.ign) then
tinsert(arg.items, { text = v.c, value = k, color = K.ClassColorsRGBPerc[k] })
end
end
ret.userclass = KUI:CreateDropDown(arg, ret)
ret.userclass.cset = nil
ret.userclass:Catch("OnValueChanged", function(this, evt, newv)
this.cset = newv
end)
ret.userrole = ksk.CreateRoleListDropdown("CreateUserRoleDD", 5, -60, ret)
ret.userrole.rset = 0
ret.userrole:Catch("OnValueChanged", function(this, evt, newv)
this.rset = newv
end)
ret.OnCancel = function(this)
this:Hide()
ksk.mainwin:Show()
end
ret.OnAccept = function(this)
if (not this.username:GetText() or this.username:GetText() == "") then
err(L["you must specify a character name."])
this.username:SetFocus()
return true
end
if (not this.userclass.cset) then
err(L["you must set a user class."])
return true
end
local uid = ksk.CreateNewUser(this.username:GetText(), this.userclass.cset)
if (uid) then
ksk.SetUserRole(uid, this.userrole.rset)
this:Hide()
ksk.mainwin:Show()
return false
end
end
createuserdlg = ret
end
ksk.mainwin:Hide()
createuserdlg:Show()
createuserdlg.userclass.cset = nil
createuserdlg.userclass:SetValue(nil)
createuserdlg.userrole:SetValue(ksk.KK.ROLE_UNSET)
createuserdlg.username:SetText("")
createuserdlg.username:SetFocus()
end
local function delete_user_button(uid)
ksk.DeleteUserCmd(uid)
end
local function rename_user_button(uid)
local function rename_helper(newname, old)
local found = nil
local cname = strlower(newname)
for k,v in pairs(ksk.cfg.users) do
if (strlower(v.name) == cname) then
found = ksk.cfg.users[k]
break
end
end
if (found) then
err(L["user %q already exists. Try again."], aclass(found))
return true
end
local rv = ksk.RenameUser(old, cname)
if (rv) then
return true
end
return false
end
K.RenameDialog(ksk, L["Rename User"], L["Old Name"],
ksk.cfg.users[uid].name, L["New Name"], 48, rename_helper,
uid, true)
end
local function guild_import_button(shown)
local arg = {
x = "CENTER", y = "MIDDLE",
name = "KSKGuildImportDlg",
title = L["Import Guild Users"],
border = true,
width = 250,
height = (K.guild.numranks * 28) + 92,
canmove = true,
canresize = false,
escclose = true,
blackbg = true,
okbutton = { text = K.ACCEPTSTR },
cancelbutton = {text = K.CANCELSTR },
}
local y = 24
local ret = KUI:CreateDialogFrame(arg)
arg = {
y = 0, width = 170, height = 24
}
for i = 1, K.guild.numranks do
y = y - 24
local cbn = "rankcb" .. tostring(i)
arg.y = y
arg.x = 10
arg.label = { text = K.guild.ranks[i] }
ret[cbn] = KUI:CreateCheckBox(arg, ret)
end
y = y - 24
arg = {
x = 10, y = y, minval = 1, maxval = K.maxlevel, initialvalue = K.maxlevel,
step = 1, label = { text = L["Minimum Level"], },
tooltip = { title = "$$", text = L["TIP074"] },
}
ret.minlevel = KUI:CreateSlider(arg, ret)
ret.isshown = shown
ret.OnCancel = function(this)
this:Hide()
if (this.isshown) then
ksk.mainwin:Show()
end
end
local function do_rank(r, minlev)
local rv = 0
local ngm = K.guild.numroster
for i = 1, ngm do
if (K.guild.roster.id[i].rank == r and K.guild.roster.id[i].level >= minlev) then
local nm = K.guild.roster.id[i].name
local uid = ksk.FindUser(nm)
if (not uid) then
local kcl = K.guild.roster.id[i].class
uid = ksk.CreateNewUser(nm, kcl, nil, true)
if (uid) then
rv = rv + 1
else
err("error adding user %q!", white(nm))
end
end
end
end
return rv
end
ret.OnAccept = function(this)
local cas,ccs
local tadd = 0
local minlev = this.minlevel:GetValue()
for i = 1, K.guild.numranks do
ccs = "rankcb" .. tostring(i)
if (this[ccs]:GetChecked()) then
tadd = tadd + do_rank(i, minlev)
end
end
if (tadd > 0) then
ksk.RefreshUsers()
ksk.RefreshRaid()
ksk:SendAM("RFUSR", "ALERT", true)
ksk.RefreshUsers()
end
this:Hide()
if (this.isshown) then
ksk.mainwin:Show()
end
info(L["added %d user(s)."], tadd)
end
ksk.mainwin:Hide()
ret:Show()
end
function ksk.ImportGuildUsers(shown)
guild_import_button(shown)
end
local selmain_popup
local function select_main(btn, lbl)
if (not seluser) then
return
end
hide_popup()
local ulist = {}
for k,v in pairs(ksk.cfg.users) do
if (k ~= seluser and not ksk.UserIsAlt(k, v.flags)) then
local ti = { text = aclass(v), value = k }
tinsert(ulist, ti)
end
end
tsort(ulist, function(a,b)
return ksk.cfg.users[a.value].name < ksk.cfg.users[b.value].name
end)
local function pop_func(puid)
local ulist = selmain_popup.selectionlist
changed()
qf.useraltnamebox:SetText(aclass(ksk.cfg.users[puid]))
hide_popup()
uinfo.isalt = true
uinfo.main = ksk.cfg.users[puid].name
uinfo.mainid = puid
end
if (not selmain_popup) then
selmain_popup = K.PopupSelectionList(ksk, "KSKMainSelPopup", ulist,
nil, 205, 400, ksk.mainwin.tabs[ksk.USERS_TAB].content, 16, pop_func,
nil, 20)
local arg = {
x = 0, y = 2, len = 48, font = "ChatFontSmall", width = 170,
tooltip = { title = L["User Search"], text = L["TIP099"] },
parent = selmain_popup.footer,
}
selmain_popup.usearch = KUI:CreateEditBox(arg, selmain_popup.footer)
selmain_popup.usearch.toplevel = selmain_popup
qf.selmainsearch = selmain_popup.usearch
local ulist = selmain_popup.selectionlist
selmain_popup.usearch:Catch("OnEnterPressed", function(this)
this:SetText("")
end)
selmain_popup.usearch:HookScript("OnEnter", function(this)
this.toplevel:StopTimeoutCounter()
end)
selmain_popup.usearch:HookScript("OnLeave", function(this)
this.toplevel:StartTimeoutCounter()
end)
selmain_popup.usearch:Catch("OnValueChanged", function(this, evt, newv, user)
if (not ksk.cfg.users or not ulist or selmain_popup.slist.itemcount < 1) then
return
end
if (user and newv and newv ~= "") then
local lnv = strlower(newv)
local tln
for k,v in pairs(ulist) do
tln = strlower(ksk.cfg.users[v.value].name)
if (strfind(tln, lnv, 1, true)) then
selmain_popup.slist:SetSelected(k, true)
return
end
end
end
end)
else
selmain_popup:UpdateList(ulist)
end
selmain_popup:ClearAllPoints()
selmain_popup:SetPoint("TOPLEFT", btn, "TOPRIGHT", 0, 0)
selmain_popup:Show()
ksk.popupwindow = selmain_popup
end
--
-- If we are in raid, add all of the current users who are missing to the
-- users database.
--
local function add_missing_button()
if (not ksk.users or not ksk.csd.is_admin or not ksk.nmissing or ksk.nmissing == 0) then
return
end
local added = 0
while (ksk.nmissing > 0 and added < 40) do
local _, v = next(ksk.missing)
ksk.CreateNewUser(v.name, v.class, nil, true, true)
added = added + 1
end
ksk.RefreshUsers()
ksk.RefreshRaid()
ksk:SendAM("RFUSR", "ALERT", true)
end
function ksk.InitialiseUsersUI()
local arg
--
-- Users tab. We have no sub-tabs so there is only one set of things
-- to do here.
--
local ypos = 0
local cf = ksk.mainwin.tabs[ksk.USERS_TAB].content
local tbf = ksk.mainwin.tabs[ksk.USERS_TAB].topbar
local ls = cf.vsplit.leftframe
local rs = cf.vsplit.rightframe
arg = {
x = 0, y = -18, text = "", autosize = false, width = 250,
font = "GameFontNormalSmall",
}
tbf.seluser = KUI:CreateStringLabel(arg, tbf)
qf.usertopbar = tbf
tbf.SetCurrentUser = function(userid)
if (userid) then
tbf.seluser:SetText(L["Currently Selected: "]..aclass(ksk.cfg.users[userid]))
else
tbf.seluser:SetText("")
end
end
--
-- Create the horizontal split for the buttons at the bottom
--
arg = {
inset = 0, height = 75,
leftsplit = true, name = "KSKUserAdminRHSplit",
}
rs.hsplit = KUI:CreateHSplit(arg, rs)
local tr = rs.hsplit.topframe
local br = rs.hsplit.bottomframe
ksk.qf.userbuttons = br
qf.userbuttons = br
--
-- The top portion is split into two, with the top half being the bit
-- that contains the actual user control buttons, and the bottom bit
-- being a scrolling list of all of the lists a user is a member of
-- (or not a member of).
--
arg = {
inset = 0, height = 180, name = "KSKUserAdminRTSplit",
leftsplit = true, topanchor = true,
}
tr.hsplit = KUI:CreateHSplit(arg, tr)
qf.useropts = tr.hsplit.topframe
local ttr = qf.useropts
local tmr = tr.hsplit.bottomframe
arg = {
inset = 0, height = 20, name = "KSKUserAdminLSSplit",
rightsplit = true
}
ls.hsplit = KUI:CreateHSplit(arg, ls)
local tls = ls.hsplit.topframe
local bls = ls.hsplit.bottomframe
--
-- The main contents window on the left side needs to be a scrolling
-- list to accomodate all of the users.
--
local function ulist_och(this)
local idx = this:GetID()
assert(ksk.sortedusers[idx])
qf.usersearch:SetText("")
qf.usersearch:ClearFocus()
local nid = ksk.sortedusers[idx].id
seluser = nid
setup_uinfo()
this:GetParent():GetParent():SetSelected(idx, false, true)
return true
end
arg = {
name = "KSKUsersScrollList",
itemheight = 16,
newitem = function(objp, num)
return KUI.NewItemHelper(objp, num, "KSKUsersButton", 155, 16,
nil, ulist_och, nil, nil)
end,
setitem = function(objp, idx, slot, btn)
return KUI.SetItemHelper(objp, btn, idx,
function(op, ix)
assert(ksk.sortedusers[ix])
local uid = ksk.sortedusers[ix].id
local tu = ksk.cfg.users[uid]
local alt = ksk.UserIsAlt(uid)
return(alt and " - " or "") .. aclass(tu)
end)
end,
selectitem = users_selectitem,
highlightitem = KUI.HighlightItemHelper,
}
tls.slist = KUI:CreateScrollList(arg, tls)
qf.userlist = tls.slist
local bdrop = {
bgFile = KUI.TEXTURE_PATH .. "TDF-Fill",
tile = true,
tileSize = 32,
insets = { left = 0, right = 0, top = 0, bottom = 0 }
}
tls.slist:SetBackdrop(bdrop)
arg = {
x = 0, y = 2, len = 16, font = "ChatFontSmall",
width = 170, tooltip = { title = L["User Search"], text = L["TIP099"] },
}
bls.searchbox = KUI:CreateEditBox(arg, bls)
qf.usersearch = bls.searchbox
bls.searchbox:Catch("OnEnterPressed", function(this, evt, newv, user)
this:SetText("")
end)
bls.searchbox:Catch("OnValueChanged", function(this, evt, newv, user)
if (not ksk.cfg.users) then
return
end
if (user and newv and newv ~= "") then
local lnv = strlower(newv)
local tln
for k,v in pairs(ksk.cfg.users) do
tln = strlower(v.name)
if (strfind(tln, lnv, 1, true)) then
for kk,vv in ipairs(ksk.sortedusers) do
if (ksk.cfg.users[vv.id].name == v.name) then
qf.userlist:SetSelected(kk, true)
break
end
end
return
end
end
end
end)
--
-- The actual user options
--
ttr.userrole = ksk.CreateRoleListDropdown("KSKUserRoleDropdown", 5, ypos, ttr)
ttr.userrole:Catch("OnValueChanged", function(this, evt, newv, user)
changed()
uinfo.role = newv
end)
ypos = ypos - 24
arg = {
x = 5, y = ypos, label = { text = L["User is an Enchanter"] },
tooltip = { title = "$$", text = L["TIP075"] },
}
ttr.enchanter = KUI:CreateCheckBox(arg, ttr)
ttr.enchanter:Catch("OnValueChanged", function(this, evt, val, user)
changed()
uinfo.enchanter = val
end)
ypos = ypos - 24
arg = {
x = 5, y = ypos, label = { text = L["User is an Alt of"] },
tooltip = { title = "$$", text = L["TIP076"] },
}
ttr.isalt = KUI:CreateCheckBox(arg, ttr)
ttr.isalt:Catch("OnValueChanged", function(this, evt, val, user)
changed()
ttr.mainsel:SetEnabled(val)
if (not val) then
uinfo.isalt = val
uinfo.main = ""
uinfo.mainid = ""
ttr.mainname:SetText("")
end
if (ksk.popupwindow) then
ksk.popupwindow:Hide()
ksk.popupwindow = nil
end
end)
ypos = ypos - 24
arg = {
x = 24, y = ypos, border = true, height = 20, width = 140,
autosize = false,
}
ttr.mainname = KUI:CreateStringLabel(arg, ttr)
qf.useraltnamebox = ttr.mainname
arg = {
x = 2, y = ypos, text = L["Select"], width = 80,
tooltip = { title = "$$", text = L["TIP077"] },
}
ttr.mainsel = KUI:CreateButton(arg, ttr)
ttr.mainsel:ClearAllPoints()
ttr.mainsel:SetPoint("TOPLEFT", ttr.mainname, "TOPRIGHT", 8, 2)
ttr.mainsel:Catch("OnClick", function(this, evt)
select_main(this)
end)
ypos = ypos - 24
arg = {
x = 5, y = ypos, label = { text = L["User is Frozen"] },
tooltip = { title = "$$", text = L["TIP078"] },
}
ttr.frozen = KUI:CreateCheckBox(arg, ttr)
ttr.frozen:Catch("OnValueChanged", function(this, evt, val, user)
changed()
uinfo.frozen = val
end)
ypos = ypos - 24
arg = {
x = 5, y = ypos, text = L["Update"], enabled = false,
tooltip = { title = "$$", text = L["TIP080"] },
}
ttr.updatebtn = KUI:CreateButton(arg, ttr)
qf.userupdbtn = ttr.updatebtn
ttr.updatebtn:Catch("OnClick", function(this, evt)
ksk.SetUserRole(seluser, uinfo.role, nil, true)
ksk.SetUserEnchanter(seluser, uinfo.enchanter, nil, true)
ksk.SetUserFrozen(seluser, uinfo.frozen, nil, true)
-- Must be last! It does refreshes which will erase uinfo.
ksk.SetUserIsAlt(seluser, uinfo.isalt, uinfo.mainid, nil, true)
ksk.RefreshAllMemberLists()
local es = strfmt("%s:%d:%s:%s:%s:%s:%s", seluser, uinfo.role,
uinfo.enchanter and "Y" or "N", uinfo.frozen and "Y" or "N",
"N", uinfo.isalt and "Y" or "N",
uinfo.mainid and uinfo.mainid or "")
ksk.AddEvent(ksk.currentid, "MDUSR", es, true)
ttr.updatebtn:SetEnabled(false)
end)
--
-- The middle right frame is used to display all of the roll lists,
-- and what position the user occupies on that list, if any. We create
-- a title label and then a frame to cover the rest of the frame, which
-- will house the scrolling list.
--
arg = {
x = "CENTER", y = 0, width = 240, height = 24, autosize = false,
text = strfmt(L["User %s / %s lists"], green(L["on"]), red(L["not on"])),
font = "GameFontNormal", border = true, justifyh = "CENTER",
}
tmr.title = KUI:CreateStringLabel(arg, tmr)
local tm = MakeFrame("Frame", nil, tmr)
tm:ClearAllPoints()
tm:SetPoint("TOPLEFT", tmr, "TOPLEFT", 0, -24)
tm:SetPoint("BOTTOMRIGHT", tmr, "BOTTOMRIGHT", 0, 0)
arg = {
name = "KSKUserInWhichScrollList",
itemheight = 16,
newitem = function(objp, num)
return KUI.NewItemHelper(objp, num, "KSKUmemButton", 200, 16,
nil, function() return end, nil, nil)
end,
setitem = function(objp, idx, slot, btn)
return KUI.SetItemHelper(objp, btn, idx, function(op, ix)
return umemlist[ix]
end)
end,
selectitem = function(objp, idx, slot, btn, onoff)
return KUI.SelectItemHelper(objp, idx, slot, btn, onoff,
function() return nil end)
end,
highlightitem = function(objp, idx, slot, btn, onoff)
return KUI.HighlightItemHelper(objp, idx, slot, btn, onoff)
end,
}
tm.slist = KUI:CreateScrollList(arg, tm)
qf.umemlist = tm.slist
tm.slist:SetBackdrop(bdrop)
--
-- The command buttons at the bottom of the left hand side to add and
-- delete users.
--
arg = {
x = 25, y = 0, width = 100, height = 24, text = L["Create"],
tooltip = { title = "$$", text = L["TIP081"] },
}
br.createbutton = KUI:CreateButton(arg, br)
br.createbutton:Catch("OnClick", function(this, evt)
create_user_button()
end)
arg = {
x = 130, y = 0, width = 100, height = 24, text = L["Delete"],
tooltip = { title = "$$", text = L["TIP082"] },
}
br.deletebutton = KUI:CreateButton(arg, br)
br.deletebutton:Catch("OnClick", function(this, evt)
delete_user_button(seluser)
end)
arg = {
x = 25, y = -25, width = 100, height = 24, text = L["Rename"],
tooltip = { title = "$$", text = L["TIP083"] },
}
br.renamebutton = KUI:CreateButton(arg, br)
br.renamebutton:Catch("OnClick", function(this, evt)
rename_user_button(seluser)
end)
arg = {
x = 130, y = -25, width = 100, height = 24, text = L["Guild Import"],
tooltip = { title = "$$", text = L["TIP084"] },
}
br.guildimp = KUI:CreateButton(arg, br)
br.guildimp:Catch("OnClick", function(this, evt)
guild_import_button(true)
end)
ksk.qf.guildimp = br.guildimp
arg = {
y = -50, width = 100, height = 24, text = L["Add Missing"],
justifyh = "CENTER", tooltip = { title = "$$", text = L["TIP086"] },
}
br.addmissing = KUI:CreateButton(arg, br)
br.addmissing:Catch("OnClick", function(this, evt)
add_missing_button()
end)
ksk.qf.addmissing = br.addmissing
end
function ksk.RefreshUsers()
local olduser = seluser or nil
local oldidx = nil
ksk.sortedusers = {}
seluser = nil
for k,v in pairs(ksk.cfg.users) do
if (not ksk.UserIsAlt(k, v.flags)) then
local ent = { id = k }
tinsert(ksk.sortedusers, ent)
end
end
tsort(ksk.sortedusers, function(a, b)
return ksk.cfg.users[a.id].name < ksk.cfg.users[b.id].name
end)
for i = #ksk.sortedusers, 1, -1 do
local usr = ksk.cfg.users[ksk.sortedusers[i].id]
if (usr.alts) then
for j = 1, #usr.alts do
local ent = {id = usr.alts[j]}
tinsert(ksk.sortedusers, i+j, ent)
end
end
end
for k,v in ipairs(ksk.sortedusers) do
if (v.id == olduser) then
oldidx = k
break
end
end
qf.userlist.itemcount = ksk.cfg.nusers
qf.userlist:UpdateList()
qf.userlist:SetSelected(oldidx)
changed(true)
ksk.RefreshCSData()
end
function ksk.FindUser(name, cfgid)
if (not ksk.frdb or not ksk.frdb.configs or ksk.frdb.tempcfg) then
return nil
end
local name = K.CanonicalName(name)
assert(name)
cfgid = cfgid or ksk.currentid
name = strlower(name)
for k,v in pairs(ksk.frdb.configs[cfgid].users) do
if (strlower(v.name) == name) then
return k
end
end
return nil
end
function ksk.GetUserFlags(userid, cfgid)
local cfgid = cfgid or ksk.currentid
if (not cfgid or not userid) then
return nil
end
if (not ksk.configs[cfgid]) then
return nil
else
if (not ksk.configs[cfgid].users[userid]) then
return nil
end
end
return ksk.configs[cfgid].users[userid].flags or ""
end
local function find_flag(userid, flags, flag, cfgid)
local fs = flags or ksk.GetUserFlags(userid, cfgid)
if (not fs) then
return false
end
if (strfind(fs, flag) ~= nil) then
return true
end
return false
end
local function set_flag(userid, flag, onoff, cfgid, arg, nocmd)
local cfgid = cfgid or ksk.currentid
local user = ksk.frdb.configs[cfgid].users[userid]
local onoff = onoff or false
if (not nocmd) then
local es = strfmt("%s:%s:%s:%s", userid, flag, onoff and "Y" or "N",
arg and tostring(arg) or "")
ksk.AddEvent(cfgid, "CHUSR", es, true)
end
if (onoff) then
if (not user.flags) then
user.flags = ""
end
if (strfind(user.flags, flag)) then
return false
end
user.flags = user.flags .. flag
return true
else
if (not user.flags) then
return false
end
if (strfind(user.flags, flag)) then
local nf = string.gsub(user.flags, flag, "")
user.flags = nf
end
return true
end
end
function ksk.UserIsEnchanter(userid, flags, cfg)
return find_flag(userid, flags, "E", cfg)
end
function ksk.UserIsFrozen(userid, flags, cfg)
return find_flag(userid, flags, "F", cfg)
end
function ksk.UserIsCoadmin(uid, cfgid)
local cfgid = cfgid or ksk.currentid
if (ksk.configs[cfgid].admins[uid] or ksk.configs[cfgid].owner == uid) then
return true
end
return false
end
function ksk.UserIsAlt(userid, flags, cfg)
local cfg = cfg or ksk.currentid
local rv = find_flag(userid, flags, "A", cfg)
if (rv == true) then
local mid, ts, ts2, ts3
local ut = ksk.frdb.configs[cfg].users
mid = ut[userid].main
if (ut[mid]) then
ts = class(ut[mid])
ts2 = aclass(ut[mid])
ts3 = ut[mid].name
end
return rv, mid, ts, ts2, ts3
end
return rv, nil, nil, nil, nil
end
function ksk.UserRole(userid, cfg)
local cfg = cfg or ksk.currentid
return ksk.configs[cfg].users[userid].role or 0
end
function ksk.SetUserEnchanter(userid, onoff, cfg, nocmd)
local cfg = cfg or ksk.currentid
local ret = false
local onoff = onoff or false