forked from kahluamods/konfersk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKSK-Config.lua
2148 lines (1892 loc) · 59.9 KB
/
KSK-Config.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 KK = ksk.KK
local MakeFrame = KUI.MakeFrame
-- Local aliases for global or LUA library functions
local _G = _G
local tinsert = table.insert
local tconcat = table.concat
local tsort = table.sort
local strlower = string.lower
local strfmt = string.format
local strsub = string.sub
local strlen = string.len
local strfind = string.find
local pairs, ipairs, next = pairs, ipairs, next
local assert = assert
local white = ksk.white
local aclass = ksk.aclass
local info = ksk.info
local err = ksk.err
local CFGTYPE_GUILD = KK.CFGTYPE_GUILD
local CFGTYPE_PUG = KK.CFGTYPE_PUG
--[[
This file implements the configuration UI and provides functions for
manipulating various config options and refreshing the data. Most of
this code can only be run by an administrator although anyone can switch
active configurations.
The main UI creation function is ksk.InitialiseConfigUI() and it creates the
config tab contents and the three pages. The main data refresh function is
ksk.RefreshConfigUI(). However, there are a number of sub refresh functions
which reset only portions of the UI or stored data, all of which are called by
ksk.RefreshConfigUI().
ksk.RefreshConfigLootUI(reset)
Refreshes the loot distribution options page of the config tab.
ksk.RefreshConfigRollUI(reset)
Refreshes the loot rolling options page of the config tab.
ksk.RefreshConfigAdminUI(reset)
Refreshes the config admin page of the config tab.
]]
local admincfg = nil
local sortedconfigs = nil
local coadmin_selected = nil
local sortedadmins = nil
local newcfgdlg = nil
local copycfgdlg = nil
local orankdlg = nil
local rankpriodlg = nil
local coadmin_popup = nil
local silent_delete = nil
local qf = {}
--
-- We have a finite number of admins, in order to ensure that unique user
-- ID's will be created by each admin, so there is no clash when syncing.
-- This is the list of admin "prefixes" for the admins. Everything else is
-- in lower case in the system so we preserve that, using lower case letters
-- and numbers, making the total possible number of admins 36. This is the
-- numbering sequence for the admin ID.
--
local adminidseq = "0123456789abcdefghijklmnopqrstuvwxyz"
--
-- This file contains all of the UI handling code for the config panel,
-- as well as all config space manipulation functions. Since this code
-- deals with config spaces themselves, its data model is slightly
-- different. All of the main config options etc use the standard data
-- model but the admin screen has a different notion of the "current"
-- configuration. For that screen and that screen only, the configuration
-- it works with is dictated by the local variable admincfg, which is set
-- when a configuration space is selected in the left hand panel.
--
local function config_setenabled(onoff)
local onoff = onoff or false
if (qf.cfgopts) then
local en = false
qf.cfgopts.cfgowner:SetEnabled(onoff)
qf.cfgopts.cfgtype:SetEnabled(onoff)
if (onoff and K.player.is_guilded and K.player.is_gm) then
en = true
end
qf.cfgopts.orankedit:SetEnabled(en)
qf.cfgdelbutton:SetEnabled(onoff)
qf.cfgrenbutton:SetEnabled(onoff)
qf.cfgcopybutton:SetEnabled(onoff)
qf.coadadd:SetEnabled(onoff)
end
end
local function refresh_coadmins()
if (not admincfg) then
qf.coadminscroll.itemcount = 0
qf.coadminscroll:UpdateList()
return
end
local newadmins = {}
local ownerlist = {}
local tc = ksk.frdb.configs[admincfg]
local ul = ksk.frdb.configs[admincfg].users
coadmin_selected = nil
for k,v in pairs(tc.admins) do
tinsert(newadmins, k)
end
tsort(newadmins, function(a, b)
return ul[a].name < ul[b].name
end)
for k,v in pairs(newadmins) do
tinsert(ownerlist, { text = aclass(ul[v]), value = v })
end
sortedadmins = newadmins
qf.coadminscroll.itemcount = #sortedadmins
qf.coadminscroll:UpdateList()
qf.coadminscroll:SetSelected(nil)
qf.cfgownerdd:UpdateItems(ownerlist)
-- Don't throw an OnValueChanged event as that could have been what called us
-- and we don't want to create an infinite loop.
qf.cfgownerdd:SetValue(tc.owner, true)
end
--
-- This is a helper function for when a configuration is selected from the
-- list of possible configurations in the admin screen. It updates and
-- populates the admin options on the right side panel.
--
local function config_selectitem(objp, idx, slot, btn, onoff)
local onoff = onoff or false
config_setenabled(onoff)
if (onoff) then
admincfg = sortedconfigs[idx].id
local lcf = ksk.frdb.configs[admincfg]
local en
qf.cfgopts.cfgowner:SetValue(lcf.owner)
qf.cfgopts.cfgtype:SetValue(lcf.cfgtype)
en = ksk.csdata[admincfg].is_admin == 2 and true or false
qf.cfgopts.cfgowner:SetEnabled(en)
if (lcf.cfgtype ~= CFGTYPE_GUILD) then
qf.cfgopts.orankedit:SetEnabled(false)
end
qf.coadadd:SetEnabled(en and lcf.nadmins < 36)
qf.cfgrenbutton:SetEnabled(en)
if (not ksk.CanChangeConfigType()) then
en = false
end
qf.cfgopts.cfgtype:SetEnabled(en)
if (ksk.frdb.nconfigs > 1) then
qf.cfgdelbutton:SetEnabled(true)
else
qf.cfgdelbutton:SetEnabled(false)
end
else
admincfg = nil
end
if (admincfg and admincfg == ksk.currentid) then
refresh_coadmins()
end
end
--
-- Helper function for dealing with the selected item in the coadmin scroll
-- list.
--
local function coadmin_list_selectitem(objp, idx, slot, btn, onoff)
local en = false
local onoff = onoff or false
if (onoff and admincfg) then
local lcf = ksk.frdb.configs[admincfg]
coadmin_selected = sortedadmins[idx]
if (coadmin_selected ~= lcf.owner) then
en = ksk.csdata[admincfg].is_admin == 2 and true or false
end
else
coadmin_selected = nil
end
qf.coaddel:SetEnabled(en)
end
-- Low level helper function to add a new co-admin
local function add_coadmin(uid, cfgid)
assert(uid)
assert(cfgid)
local pcc = ksk.frdb.configs[cfgid]
if (not pcc) then
return
end
local newid
for i = 1, 36 do
local id = strsub(adminidseq, i, i)
local found = false
for k,v in pairs(pcc.admins) do
if (v.id == id) then
found = true
break
end
end
if (not found) then
newid = id
break
end
end
assert(newid, "fatal logic bug somewhere!")
-- Must add the event BEFORE we add the admin
ksk.AddEvent(cfgid, "MKADM", strfmt("%s:%s", uid, newid))
pcc.nadmins = pcc.nadmins + 1
pcc.admins[uid] = { id = newid }
end
local function new_space_button()
local box
if (not newcfgdlg) then
newcfgdlg, box = K.SingleStringInputDialog(ksk, "KSKSetupNewSpace",
L["Create Configuration"], L["NEWMSG"], 400, 165)
local function verify_with_create(objp, val)
if (strlen(val) < 1) then
err(L["invalid configuration space name. Please try again."])
objp:Show()
objp.ebox:SetFocus()
return true
end
ksk.CreateNewConfig(val, false)
newcfgdlg:Hide()
ksk.mainwin:Show()
return false
end
newcfgdlg:Catch("OnAccept", function(this, evt)
local rv = verify_with_create(this, this.ebox:GetText())
return rv
end)
newcfgdlg:Catch("OnCancel", function(this, evt)
newcfgdlg:Hide()
ksk.mainwin:Show()
return false
end)
box:Catch("OnEnterPressed", function(this, evt, val)
return verify_with_create(this, val)
end)
else
box = newcfgdlg.ebox
end
box:SetText("")
ksk.mainwin:Hide()
newcfgdlg:Show()
box:SetFocus()
end
local function rename_space_button(cfgid)
local function rename_helper(newname, old)
local rv = ksk.RenameConfig(old, newname)
if (rv) then
return true
end
return false
end
K.RenameDialog(ksk, L["Rename Configuration"], L["Old Name"],
ksk.frdb.configs[cfgid].name, L["New Name"], 32, rename_helper,
cfgid, true, ksk.mainwin)
end
local function copy_space_button(cfgid, newname, newid, shown)
if (not copycfgdlg) then
local ypos = 0
local arg = {
x = "CENTER", y = "MIDDLE",
name = "KSKCopyConfigDialog",
title = L["Copy Configuration"],
border = true,
width = 450,
height = 280,
canmove = true,
canresize = false,
escclose = true,
blackbg = true,
okbutton = { text = K.ACCEPTSTR },
cancelbutton = { text = K.CANCELSTR },
}
local ret = KUI:CreateDialogFrame(arg)
arg = {}
arg = {
x = 0, y = ypos, width = 200, height = 20, autosize = false,
justifyh = "RIGHT", font = "GameFontNormal",
text = L["Source Configuration"],
}
ret.str1 = KUI:CreateStringLabel(arg, ret)
arg.justifyh = "LEFT"
arg.text = ""
arg.border = true
arg.color = {r = 1, g = 1, b = 1, a = 1 }
ret.str2 = KUI:CreateStringLabel(arg, ret)
ret.str2:ClearAllPoints()
ret.str2:SetPoint("TOPLEFT", ret.str1, "TOPRIGHT", 12, 0)
arg = {}
ypos = ypos - 24
arg = {
x = 0, y = ypos, width = 200, height = 20, autosize = false,
justifyh = "RIGHT", font = "GameFontNormal",
text = L["Destination Configuration"],
}
ret.str3 = KUI:CreateStringLabel(arg, ret)
arg.justifyh = "LEFT"
arg.text = ""
arg.border = true
arg.color = {r = 1, g = 1, b = 1, a = 1 }
ret.str4 = KUI:CreateStringLabel(arg, ret)
ret.str4:ClearAllPoints()
ret.str4:SetPoint("TOPLEFT", ret.str3, "TOPRIGHT", 12, 0)
arg = {}
arg = {
x = 0, y = ypos, width = 200, height = 20, len = 32,
}
ret.dest = KUI:CreateEditBox(arg, ret)
ret.dest:ClearAllPoints()
ret.dest:SetPoint("TOPLEFT", ret.str3, "TOPRIGHT", 12, 0)
ret.dest:Catch("OnValueChanged", function(this, evt, newv)
copycfgdlg.newname = newv
end)
arg = {}
ypos = ypos - 24
local xpos = 90
arg = {
x = xpos, y = ypos, name = "KSKCopyListDD",
dwidth = 175, items = KUI.emptydropdown, itemheight = 16,
title = { text = L["Roll Lists to Copy"] }, mode = "MULTI",
}
ret.ltocopy = KUI:CreateDropDown(arg, ret)
arg = {}
ypos = ypos - 32
arg = {
x = xpos, y = ypos, label = { text = L["Copy Co-admins"] },
}
ret.copyadm = KUI:CreateCheckBox(arg, ret)
ret.copyadm:Catch("OnValueChanged", function(this, evt, val)
copycfgdlg.do_copyadm = val
end)
arg = {}
ypos = ypos - 24
arg = {
x = xpos, y = ypos, label = { text = L["Copy All User Flags"] },
}
ret.copyflags = KUI:CreateCheckBox(arg, ret)
ret.copyflags:Catch("OnValueChanged", function(this, evt, val)
copycfgdlg.do_copyflags = val
end)
arg = {}
ypos = ypos - 24
arg = {
x = xpos, y = ypos, label = { text = L["Copy Configuration Options"] },
}
ret.copycfg = KUI:CreateCheckBox(arg, ret)
ret.copycfg:Catch("OnValueChanged", function(this, evt, val)
copycfgdlg.do_copycfg = val
end)
arg = {}
ypos = ypos - 24
arg = {
x = xpos, y = ypos, label = { text = L["Copy Item Options"] },
}
ret.copyitem = KUI:CreateCheckBox(arg, ret)
ret.copyitem:Catch("OnValueChanged", function(this, evt, val)
copycfgdlg.do_copyitems = val
end)
arg = {}
ypos = ypos - 24
copycfgdlg = ret
ret.OnAccept = function(this)
--
-- First things first, see if we need to create the new configuration
-- or if we are copying into it.
--
if (not copycfgdlg.newname or copycfgdlg.newname == "") then
err(L["invalid configuration name. Please try again."])
return
end
if (copycfgdlg.newid == 0) then
copycfgdlg.newid = ksk.FindConfig(copycfgdlg.newname) or 0
end
if (copycfgdlg.newid == 0) then
local rv, ni = ksk.CreateNewConfig(copycfgdlg.newname, false)
if (rv) then
return
end
copycfgdlg.newid = ni
end
local newid = copycfgdlg.newid
local cfgid = copycfgdlg.cfgid
assert(ksk.frdb.configs[newid])
local dc = ksk.frdb.configs[newid]
local sc = ksk.frdb.configs[cfgid]
--
-- Copy the users. We cannot do a blind copy of the user ID's as the user
-- may already exist in the configuration with a different ID, so we have
-- to search the new configuration for each user. We go through the list
-- twice, the first time skipping alts, the second time just dealing with
-- alts. For the various user flags, we have to do them individually, as
-- we may need to send out events for each change to the new user.
--
for k,v in pairs(sc.users) do
if (not v.main) then
local du = ksk.FindUser(v.name, newid)
if (not du) then
du = ksk.CreateNewUser(v.name, v.class, newid, true, true)
end
if (copycfgdlg.do_copyflags) then
local fs
fs = ksk.UserIsEnchanter(k, v.flags, cfgid)
ksk.SetUserEnchanter(du, fs, newid)
fs = ksk.UserIsFrozen(k, v.flags, cfgid)
ksk.SetUserFrozen(du, fs, newid)
end
end
end
for k,v in pairs(sc.users) do
if (v.main) then
local du = ksk.FindUser(v.name, newid)
if (not du) then
du = ksk.CreateNewUser(v.name, v.class, newid, true, true)
end
if (copyflags) then
local fs
fs = ksk.UserIsEnchanter(k, v.flags, cfgid)
ksk.SetUserEnchanter(du, fs, newid)
fs = ksk.UserIsFrozen(k, v.flags, cfgid)
ksk.SetUserFrozen(du, fs, newid)
end
local mu = ksk.FindUser(sc.users[v.main].name, newid)
assert(mu)
ksk.SetUserIsAlt(du, true, mu, newid)
end
end
--
-- Now copy the roll lists (if any) we have been asked to copy.
--
for k,v in pairs(copycfgdlg.copylist) do
if (v == true) then
--
-- We can use the handy SMLST event to set the member list.
-- That event was originally intended for the CSV import
-- function but it serves our purposes perfectly as we can
-- set the entire member list with one event. No need to
-- recreate lists or anything like that.
--
local sl = sc.lists[k]
local dlid = ksk.FindList(sl.name, newid)
if (not dlid) then
--
-- Need to create the list
--
local rv, ri = ksk.CreateNewList(sl.name, newid)
assert(not rv)
dlid = ri
end
local dul = {}
for kk,vv in ipairs(sl.users) do
-- Find the user in the new config
local du = ksk.FindUser(sc.users[vv].name, newid)
assert(du)
tinsert(dul, du)
end
local dus = tconcat(dul, "")
ksk.SetMemberList(dus, dlid, newid)
--
-- Copy the list options and prepare a CHLST event
--
if (copycfgdlg.do_copycfg) then
local dl = dc.lists[dlid]
dl.sortorder = sl.sortorder
dl.def_rank = sl.def_rank
dl.strictcfilter = sl.strictcfilter
dl.strictrfilter = sl.strictrfilter
if (sl.extralist ~= "0") then
dl.extralist = ksk.FindList(sc.lists[sl.extralist].name, newid) or "0"
end
dl.tethered = sl.tethered
-- If this changes MUST change in KSK-Comms.lua(CHLST)
local es = strfmt("%s:%d:%d:%s:%s:%s:%s", dlid,
dl.sortorder, dl.def_rank, dl.strictcfilter and "Y" or "N",
dl.strictrfilter and "Y" or "N", dl.extralist,
dl.tethered and "Y" or "N")
ksk.AddEvent(newid, "CHLST", es)
end
end
end
--
-- Next up are the item options, if we have been asked to copy them.
-- We only copy items that do not exist. If the item exists in the
-- new config we leave it completely untouched.
--
if (copycfgdlg.do_copyitems) then
local sil = sc.items
local dil = dc.items
for k,v in pairs(sil) do
if (not dil[k]) then
local es = k .. ":"
ksk.AddItem(k, v.ilink, newid)
K.CopyTable(v, dil[k])
--
-- Obviously the UID for assign to next user will be
-- different, so we adjust for that.
--
if (v.user) then
dil[k].user = ksk.FindUser(sc.users[v.user].name, newid)
assert(dil[k].user)
end
ksk.MakeCHITM(k, dil[k], newid, true)
end
end
end
--
-- If we have been asked to preserve all of the config options then
-- copy them over now, but we will have to adjust the disenchanter
-- UIDs.
--
if (copycfgdlg.do_copycfg) then
K.CopyTable(sc.settings, dc.settings)
for k,v in pairs(sc.settings.denchers) do
if (v) then
dc.settings.denchers[k] = ksk.FindUser(sc.users[v].name, newid)
end
end
dc.cfgtype = sc.cfgtype
dc.owner = ksk.FindUser(sc.users[sc.owner].name, newid)
dc.oranks = sc.oranks
end
--
-- If they want to copy co-admins do so now.
--
if (copycfgdlg.do_copyadm) then
for k,v in pairs(sc.admins) do
local uid = ksk.FindUser(sc.users[k].name, newid)
assert(uid)
if (not dc.admins[uid]) then
add_coadmin(uid, newid)
end
end
end
ksk.FullRefresh(true)
copycfgdlg:Hide()
if (copycfgdlg.isshown) then
ksk.mainwin:Show()
end
end
ret.OnCancel = function(this)
copycfgdlg:Hide()
if (copycfgdlg.isshown) then
ksk.mainwin:Show()
end
end
end
copycfgdlg.do_copyadm = false
copycfgdlg.do_copyflags = true
copycfgdlg.do_copycfg = true
copycfgdlg.do_copyraid = false
copycfgdlg.do_copyitems = false
copycfgdlg.copylist = {}
copycfgdlg.newname = newname or ""
copycfgdlg.newid = newid or 0
copycfgdlg.cfgid = cfgid
--
-- Each time we are called we need to populate the dropdown list so that
-- it has the correct list of lists.
--
local function set_list(btn)
copycfgdlg.copylist[btn.value] = btn.checked
end
local items = {}
for k,v in pairs(ksk.frdb.configs[cfgid].lists) do
local ti = { text = v.name, value = k, keep = true, func = set_list }
ti.checked = function()
return copycfgdlg.copylist[k]
end
tinsert(items, ti)
end
tsort(items, function(a,b)
return strlower(a.text) < strlower(b.text)
end)
copycfgdlg.ltocopy:UpdateItems(items)
copycfgdlg.copyadm:SetChecked(copycfgdlg.do_copyadm)
copycfgdlg.copyflags:SetChecked(copycfgdlg.do_copyflags)
copycfgdlg.copycfg:SetChecked(copycfgdlg.do_copycfg)
copycfgdlg.copyitem:SetChecked(copycfgdlg.do_copyitems)
if (not copycfgdlg.newid or copycfgdlg.newid == 0) then
copycfgdlg.str4:Hide()
copycfgdlg.dest:Show()
copycfgdlg.dest:SetText(copycfgdlg.newname)
else
copycfgdlg.dest:Hide()
copycfgdlg.str4:Show()
copycfgdlg.str4:SetText(copycfgdlg.newname)
end
copycfgdlg.str2:SetText(ksk.frdb.configs[cfgid].name)
copycfgdlg.isshown = shown
ksk.mainwin:Hide()
copycfgdlg:Show()
end
function ksk.CopyConfigSpace(cfgid, newname, newid)
copy_space_button(cfgid, newname, newid, ksk.mainwin:IsShown())
end
local dencher_popup
local which_dencher
local which_dench_lbl
local function select_dencher(btn, lbl, num)
if (ksk.popupwindow) then
ksk.popupwindow:Hide()
ksk.popupwindow = nil
end
local ulist = {}
which_dencher = num
which_dench_lbl = lbl
tinsert(ulist, { value = 0, text = L["None"] })
for k,v in ipairs(ksk.sortedusers) do
local ok = true
for i = 1, ksk.MAX_DENCHERS do
if (ksk.cfg.settings.denchers[i] == v.id) then
ok = false
end
end
if (ok and ksk.UserIsEnchanter(v.id)) then
local ti = { value = v.id, text = aclass(ksk.cfg.users[v.id]) }
tinsert(ulist, ti)
end
end
local function pop_func(uid)
if (uid == 0) then
ksk.cfg.settings.denchers[which_dencher] = nil
which_dench_lbl:SetText("")
else
which_dench_lbl:SetText(aclass(ksk.cfg.users[uid]))
if (ksk.cfg.settings.denchers[which_dencher] ~= uid) then
ksk.cfg.settings.denchers[which_dencher] = uid
end
end
--
-- If we're in raid, refresh the raid's notion of possible denchers.
--
if (ksk.users) then
ksk.UpdateDenchers()
end
ksk.popupwindow:Hide()
ksk.popupwindow = nil
end
if (not dencher_popup) then
dencher_popup = K.PopupSelectionList(ksk, "KSKDencherPopup",
ulist, L["Select Enchanter"], 225, 400, btn, 16,
function(idx) pop_func(idx) end)
end
dencher_popup:UpdateList(ulist)
dencher_popup:ClearAllPoints()
dencher_popup:SetPoint("TOPLEFT", btn, "TOPRIGHT", 0, dencher_popup:GetHeight() /2)
dencher_popup:Show()
ksk.popupwindow = dencher_popup
end
local function change_cfg(which, val)
if (ksk.cfg and ksk.cfg.settings) then
if (ksk.cfg.settings[which] ~= val) then
ksk.cfg.settings[which] = val
end
end
end
local function rank_editor ()
if (not rankpriodlg) then
local ypos = 0
local arg = {
x = "CENTER", y = "MIDDLE",
name = "KSKRankEditorDialog",
title = L["Edit Rank Priorities"],
border = true,
width = 320,
height = ((K.guild.numranks +1) * 28) + 70,
canmove = true,
canresize = false,
escclose = true,
blackbg = true,
okbutton = { text = K.ACCEPTSTR },
cancelbutton = { text = K.CANCELSTR },
}
local ret = KUI:CreateDialogFrame(arg)
arg = {}
arg = {
x = 8, y = 0, height = 20, text = L["Guild Rank"],
font = "GameFontNormal",
}
ret.glbl = KUI:CreateStringLabel(arg, ret)
arg.x = 225
arg.text = L["Priority"]
ret.plbl = KUI:CreateStringLabel(arg, ret)
arg = {}
arg = {
x = 8, y = 0, width = 215, text = "",
}
earg = {
x = 225, y = 0, width = 36, initialvalue = "1", numeric = true, len = 2,
}
for i = 1, 10 do
local rlbl = "ranklbl" .. tostring(i)
local rpe = "rankprio" .. tostring(i)
arg.y = arg.y - 24
ret[rlbl] = KUI:CreateStringLabel(arg, ret)
earg.x = 225
earg.y = earg.y - 24
ret[rpe] = KUI:CreateEditBox(earg, ret)
ret[rlbl]:Hide()
ret[rpe]:Hide()
end
ret.OnCancel = function(this)
this:Hide()
ksk.mainwin:Show()
end
ret.OnAccept = function(this)
ksk.cfg.settings.rank_prio = {}
for i = 1, K.guild.numranks do
local rpe = "rankprio" .. tostring(i)
local tv = ret[rpe]:GetText()
if (tv == "") then
tv = "1"
end
local rrp = tonumber(tv)
if (rrp < 1) then
rrp = 1
end
if (rrp > 10) then
rrp = 10
end
ksk.cfg.settings.rank_prio[i] = rrp
end
this:Hide()
ksk.mainwin:Show()
end
rankpriodlg = ret
end
local rp = rankpriodlg
rp:SetHeight(((K.guild.numranks + 1) * 28) + 50)
for i = 1, 10 do
local rlbl = "ranklbl" .. tostring(i)
local rpe = "rankprio" .. tostring(i)
rp[rlbl]:Hide()
rp[rpe]:Hide()
end
for i = 1, K.guild.numranks do
local rlbl = "ranklbl" .. tostring(i)
local rpe = "rankprio" .. tostring(i)
rp[rlbl]:SetText(K.guild.ranks[i])
rp[rpe]:SetText(tostring(ksk.cfg.settings.rank_prio[i] or 1))
rp[rlbl]:Show()
rp[rpe]:Show()
end
rp:Show()
end
local function orank_edit_button()
if (not orankdlg) then
local arg = {
x = "CENTER", y = "MIDDLE",
name = "KSKiOfficerRankEditDlg",
title = L["Set Guild Officer Ranks"],
border = true,
width = 240,
height = 372,
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 = {
width = 170, height = 24
}
for i = 1, 10 do
y = y - 24
local cbn = "orankcb" .. tostring(i)
arg.y = y
arg.x = 10
arg.label = { text = " " }
ret[cbn] = KUI:CreateCheckBox(arg, ret)
end
ret.OnCancel = function(this)
this:Hide()
ksk.mainwin:Show()
end
ret.OnAccept = function(this)
local ccs
local oranks = ""
for i = 1, K.guild.numranks do
ccs = "orankcb" .. tostring(i)
if (this[ccs]:GetChecked()) then
oranks = oranks .. "1"
else
oranks = oranks .. "0"
end
end
oranks = strsub(oranks .. "0000000000", 1, 10)
ksk.frdb.configs[admincfg].oranks = oranks
ksk:SendAM("ORANK", "ALERT", oranks)
this:Hide()
ksk.mainwin:Show()
end
orankdlg = ret
end
local rp = orankdlg
local lcf = ksk.frdb.configs[admincfg]
rp:SetHeight(((K.guild.numranks + 1) * 28) + 10)
for i = 1, 10 do
local rcb = "orankcb" .. tostring(i)
if (K.guild.ranks[i]) then
rp[rcb]:SetText(K.guild.ranks[i])
rp[rcb]:Show()
rp[rcb]:SetChecked(strsub(lcf.oranks, i, i) == "1")
else
rp[rcb]:Hide()
end
end
ksk.mainwin:Hide()
rp:Show()
end
function ksk.InitialiseConfigUI()
local arg
local kmt = ksk.mainwin.tabs[ksk.CONFIG_TAB]
-- First set up the quick access frames we will be using.
qf.lootopts = kmt.tabs[ksk.CONFIG_LOOT_PAGE].content
qf.rollopts = kmt.tabs[ksk.CONFIG_ROLLS_PAGE].content
qf.cfgadmin = kmt.tabs[ksk.CONFIG_ADMIN_PAGE].content
--
-- Config panel, loot tab
--
local ypos = 0
local cf = qf.lootopts
arg = {
x = 0, y = ypos,
label = { text = L["Auto-open Bid Panel When Corpse Looted"] },
tooltip = { title = "$$", text = L["TIP001"] },
}
cf.autobid = KUI:CreateCheckBox(arg, cf)
cf.autobid:Catch("OnValueChanged", function(this, evt, val)
change_cfg("auto_bid", val)
end)
arg = {}
ypos = ypos - 24
arg = {
x = 0, y = ypos, label = { text = L["Silent Bidding"] },
tooltip = { title = "$$", text = L["TIP002"] },
}
cf.silentbid = KUI:CreateCheckBox(arg, cf)
cf.silentbid:Catch("OnValueChanged", function(this, evt, val)
change_cfg("silent_bid", val)
end)
arg = {}
arg = {
x = 225, y = ypos, label = { text = L["Display Tooltips in Loot List"] },
tooltip = { title = "$$", text = L["TIP003"] },
}
cf.tooltips = KUI:CreateCheckBox(arg, cf)
cf.tooltips:Catch("OnValueChanged", function(this, evt, val)
change_cfg("tooltips", val)
end)