-
Notifications
You must be signed in to change notification settings - Fork 25
/
NxUI.lua
7980 lines (5810 loc) · 174 KB
/
NxUI.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
---------------------------------------------------------------------------------------
-- Carbonite UI code
-- Copyright 2007-2012 Carbon Based Creations, LLC
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
-- Carbonite - Addon for World of Warcraft(tm)
-- Copyright 2007-2012 Carbon Based Creations, LLC
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------------------
local NotInitializedWins = {}
local L = LibStub("AceLocale-3.0"):GetLocale("Carbonite")
local HideFramesOnEsc = {}
function Nx:UIInit()
local qc = {}
self.QualityColors = qc
for n = 0, 10 do
local r, g, b, hex = C_Item.GetItemQualityColor(n)
qc[n] = hex
end
qc[1] = "|cffe7e7e7" -- Dim the white
Nx.Font:Init()
Nx.Skin:Init()
Nx.Menu:Init()
Nx.Window:Init()
Nx.Button:Init()
Nx.List:Init()
Nx.DropDown:Init()
Nx.ToolBar:Init()
-- Nx.GList:Init()
end
---------------------------------------------------------------------------------------
function Nx.strpos (haystack, needle, offset)
--local pattern = string.format("(%s)", needle)
local i = string.find (haystack, needle, (offset or 0), true)
return (i ~= nil and i or false)
end
function Nx.prtStack (str)
local s = debugstack (2, 3, 2)
s = gsub (s, "Interface\\AddOns\\", "")
Nx.prtD ("%s: %s", str, s)
end
---------------------------------------------------------------------------------------
function Nx.ArrayConcat(...)
local t = {}
for n = 1,select("#",...) do
local arg = select(n,...)
if type(arg)=="table" then
for _,v in ipairs(arg) do
v._type = n
t[#t+1] = v
end
else
t[#t+1] = arg
end
end
return t
end
---------------------------------------------------------------------------------------
function Nx.IsFriend(name)
for i = 1, C_FriendList.GetNumFriends() do
local finfo = C_FriendList.GetFriendInfoByIndex (i)
if finfo.name == name then
return true
end
end
end
---------------------------------------------------------------------------------------
-- Chat printing
---------------------------------------------------------------------------------------
function Nx:prtGetChatFrames()
local t = {}
for n = 1, 10 do
local cfrm = _G["ChatFrame" .. n]
if cfrm and cfrm["name"] then
tinsert (t, cfrm["name"])
-- Nx.prt ("cfrm %s %s", n, cfrm["name"] or "nil")
end
end
sort (t)
-- Nx.prtVar ("", t)
return t
end
function Nx:prtSetChatFrame()
Nx.prtChatFrm = DEFAULT_CHAT_FRAME
for n = 1, 10 do
local cfrm = _G["ChatFrame" .. n]
if cfrm then
if cfrm["name"] == Nx.db.profile.General.ChatMsgFrm then
Nx.prtChatFrm = cfrm
end
end
end
end
function Nx.prt (...)
local args = {...}
local i = 1
-- replace missing/erroneous placeholders
function replace_placeholders(placeholder, item)
i = i + 1
--if (args[i] == nil) then
-- return '[missing argument]'
--end
if item ~= 's' and item ~= 'q' then
if type(args[i]) == 'string' and string.match(args[i], '^[.0-9]+$') then
return placeholder
elseif type(args[i]) ~= 'number' then
return '[not a number]'
end
end
return placeholder
end
args[1] = string.gsub((args[1] or 'nil'), '(%%[0-9.]*([cdeEfgGioqsuxX]))', replace_placeholders)
-- convert boolean and nil to string
for n = 1, #args do
if n > 1 then
if type(args[n]) == 'boolean' or type(args[n]) == 'nil' then
args[n] = tostring(args[n])
end
end
end
local f = Nx.prtChatFrm or DEFAULT_CHAT_FRAME
f:AddMessage ("|cffff0000[" .. Nx.TXTBLUE..L["Carbonite"].."|cffff0000] |cffffffff".. format (unpack(args)), 1, 1, 1)
end
function Nx.prtraw (msg)
local f = Nx.prtChatFrm or DEFAULT_CHAT_FRAME
-- msg = debugstack(2,3,2)
f:AddMessage (Nx.TXTBLUE..L["Carbonite"].." |cffffffff".. msg, 1, 1, 1)
end
function Nx.prtError (msg, ...)
UIErrorsFrame:AddMessage (format (msg, ...), 1, 1, 0)
end
-- Debug print
function Nx.prtD (...)
if Nx.DebugOn then
Nx.prt (...)
end
end
function Nx.prtCtrl (msg, ...)
if Nx.DebugOn and IsControlKeyDown() then
Nx.prt (msg, ...)
end
end
function Nx.prtTable (msg, s)
Nx.prt (msg.." Table: "..type (s))
if type (s) == "table" then
for k, v in pairs (s) do
if type (v) ~= "table" then
Nx.prtVar (" "..k, v)
else
Nx.prt (" "..k.." table")
end
end
end
end
function Nx.prtVar (msg, v)
local prt = Nx.prt
if v == nil then
prt (msg.." nil")
elseif type (v) == "boolean" then
prt (msg.." "..tostring (v))
elseif type (v) == "number" then
prt (format ("%s #%d (0x%x)", msg, v, v))
elseif type (v) == "string" then
local s = gsub (v, "%%", "%%%%")
prt (msg.. " '" .. s .."'")
elseif type (v) == "table" then
Nx.prtTable (msg, v)
else
prt (msg.." ? "..tostring (v))
end
end
function Nx.prtStrHex (msg, str)
local prt = Nx.prt
prt (msg..":")
for n = 1, #str, 4 do
local s = ""
for n2 = n, min (#str, n + 3) do
s = s .. format (" %x", strbyte (str, n2))
end
prt (s)
end
end
function Nx.prtFrame (msg, frm)
local prt = Nx.prt
local parent = frm:GetParent()
-- prt (msg.." Frame: %s", frm:GetName() or "nil")
prt (msg..L[" Frame: %s Shown%d Vis%d P>%s"], frm:GetName() or "nil",
frm:IsShown() or 0, frm:IsVisible() or 0, parent and parent:GetName() or "nil")
prt (L[" EScale %f, Lvl %f"], frm:GetEffectiveScale(), frm:GetFrameLevel())
prt (L[" LR %f, %f"], frm:GetLeft() or -999, frm:GetRight() or -999)
prt (L[" BT %f, %f"], frm:GetBottom() or -999, frm:GetTop() or -999)
local reg = { frm:GetRegions() }
for n, o in ipairs (reg) do
local str = ""
if o:IsObjectType ("Texture") then
str = o:GetTexture()
end
prt (" %d %s: %s", n, o:GetObjectType(), str)
end
end
function Nx.prtFrameChildren (msg, frm, lvl)
local prt = Nx.prt
lvl = lvl or 1
if msg then
prt (format ("FrameChildren (%s)", msg))
end
local pad = ""
for n = 1, lvl do
pad = pad.." "
end
local ch = { frm:GetChildren() }
for n = 1, #ch do
local c = ch[n]
if c:IsObjectType ("Frame") then
prt (L["%s#%d %s ID%s (%s) show%d l%d x%d y%d"], pad, n, c:GetName() or "nil",
c:GetID() or "nil", c:GetObjectType(),
c:IsShown() or 0, frm:GetFrameLevel(),
c:GetLeft() or -99999, c:GetTop() or -99999
)
Nx.prtFrameChildren (nil, c, lvl + 1)
end
end
end
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
-- Make the first letter a cap and the rest lower case
---------------------------------------------------------------------------------------
function Nx.Util_CapStr (str)
return strupper (strsub (str, 1, 1)) .. strlower (strsub (str, 2))
end
function Nx.Util_CleanName (name)
name = Nx.Util_CapStr (name)
name = gsub (name, "[~%^]", "")
return name
end
---------------------------------------------------------------------------------------
-- Count table entries
---------------------------------------------------------------------------------------
function Nx.Util_tcount (t)
local n = 0
if t then
for k, v in pairs (t) do
n = n + 1
end
end
return n
end
function Nx.Util_tcountrecurse (t)
local n = 0
if t then
for k, v in pairs (t) do
n = n + 1
if type (v) == "table" then
n = n + Nx.Util_tcountrecurse (v)
end
end
end
return n
end
---------------------------------------------------------------------------------------
-- Copy table entries recursively
---------------------------------------------------------------------------------------
function Nx.Util_TCopyRecurse (t)
local tc = {}
for k, v in pairs (t) do
if type (v) == "table" then
tc[k] = Nx.Util_TCopyRecurse (v)
else
tc[k] = v
end
end
return tc
end
---------------------------------------------------------------------------------------
-- Find item index in table
-- (table, search item)
---------------------------------------------------------------------------------------
function Nx.Util_TFindItemI (t, item)
for i, v in ipairs (t) do
if v == item then
return i
end
end
end
---------------------------------------------------------------------------------------
-- Move a indexed table index lower or higher
-- (table, index, not nil to move to lower index)
---------------------------------------------------------------------------------------
function Nx.Util_TMoveI (t, i, low)
if low then
if i > 1 then
t[i-1], t[i] = t[i], t[i-1]
return i - 1
end
else
if i < #t then
t[i+1], t[i] = t[i], t[i+1]
return i + 1
end
end
end
---------------------------------------------------------------------------------------
-- Move a indexed table item lower or higher
-- (table, match item, not nil to move to lower index)
---------------------------------------------------------------------------------------
function Nx.Util_TMoveItem (t, item, low)
for i, v in ipairs (t) do
if v == item then
if low then
if i > 1 then
t[i-1], t[i] = t[i], t[i-1]
return i - 1
end
else
if i < #t then
t[i+1], t[i] = t[i], t[i+1]
return i + 1
end
end
return
end
end
end
---------------------------------------------------------------------------------------
-- Serialize a table to a string
---------------------------------------------------------------------------------------
function Nx.Util_t2strRecurse (t)
local str = ""
if t then
str = "{"
for k, v in pairs (t) do
local kStr = k
if type (k) == "string" then
kStr = format ("\"%s\"", k)
end
if type (v) == "table" then
str = str .. format ("[%s]=%s,", kStr, Nx.Util_t2strRecurse (v))
elseif type (v) == "string" then
str = str .. format ("[%s]=\"%s\",", kStr, v)
else
str = str .. format ("[%s]=%s,", kStr, v)
end
end
str = str .. "}"
end
return str
end
---------------------------------------------------------------------------------------
-- Convert hex color number to R G B A floats (0-1)
-- (RRGGBBAA number)
---------------------------------------------------------------------------------------
function Nx.Util_dec2hex(input)
local base,key,output,remainder=16,"0123456789ABCDEF","",0
while input>0 do
input,remainder=floor(input/base), mod(input,base)+1
output=strsub(key,remainder,remainder)..output
end
return output..strrep("0", 2 - strlen(output))
end
function Nx.Util_str2rgba (colors)
local arr = { Nx.Split("|",colors) }
return tonumber(arr[1]), tonumber(arr[2]), tonumber(arr[3]), tonumber(arr[4])
end
function Nx.Util_str2rgb (colors)
local arr = { Nx.Split("|",colors) }
return tonumber(arr[1]), tonumber(arr[2]), tonumber(arr[3])
end
---------------------------------------------------------------------------------------
-- Convert hex color number to alpha float (0-1)
-- (RRGGBBAA number)
---------------------------------------------------------------------------------------
function Nx.Util_str2a (colors)
local arr = { Nx.Split("|",colors) }
return arr[4]
end
---------------------------------------------------------------------------------------
-- Convert hex color number to color string
-- (RGBA number)
---------------------------------------------------------------------------------------
function Nx.Util_str2colstr (colors)
local arr = { Nx.Split("|",colors) }
return format ("|c%02x%02x%02x%02x",arr[4]*255,arr[1]*255,arr[2]*255,arr[3]*255)
end
---------------------------------------------------------------------------------------
-- Convert color table
---------------------------------------------------------------------------------------
function Nx.Util_coltrgb2colstr (colors)
local t = {}
for k, v in pairs (colors) do
t[k] = format ("|cff%02x%02x%02x", v.r * 255, v.g * 255, v.b * 255)
end
return t
end
---------------------------------------------------------------------------------------
-- Step a value to the target value by a step
-- ret new value
---------------------------------------------------------------------------------------
function Nx.Util_StepValue (value, target, step)
if value < target then
value = value + step
if value > target then
value = target
end
elseif value > target then
value = value - step
if value < target then
value = target
end
end
return value
end
---------------------------------------------------------------------------------------
-- Check if mouse is over a frame
-- (frame)
-- ret XY offsets from bottom left corner or nil if not over
---------------------------------------------------------------------------------------
function Nx.Util_IsMouseOver (frm)
local x, y = GetCursorPosition()
x = x / frm:GetEffectiveScale()
local left = frm:GetLeft()
local right = frm:GetRight()
if x >= left and x <= right then
y = y / frm:GetEffectiveScale()
local top = frm:GetTop()
local bottom = frm:GetBottom()
if y >= bottom and y <= top then
return x - left, y - bottom
end
end
end
---------------------------------------------------------------------------------------
-- Get mouse position relative to a frame
-- (frame)
-- ret XY offsets from bottom left corner
---------------------------------------------------------------------------------------
function Nx.Util_GetMouseClampedXY (frm)
local x, y = GetCursorPosition()
x = x / frm:GetEffectiveScale()
local left = frm:GetLeft()
local right = frm:GetRight()
x = max (x, left)
x = min (x, right)
y = y / frm:GetEffectiveScale()
local top = frm:GetTop()
local bottom = frm:GetBottom()
y = max (y, bottom)
y = min (y, top)
return x - left, y - bottom
end
---------------------------------------------------------------------------------------
-- Clamp frame to screen
-- (frame)
-- ret XY offsets from bottom left corner
---------------------------------------------------------------------------------------
function Nx.Util_SnapToScreen (frm)
local sw = GetScreenWidth()
local sh = GetScreenHeight()
local atPt, relTo, relPt, x, y = frm:GetPoint()
local sc = frm:GetScale()
local l = frm:GetLeft() * sc -- Scale does not matter for left or bottom
local r = frm:GetRight() * sc
local t = frm:GetTop() * sc
local b = frm:GetBottom() * sc
local dist = 4
if abs (l - 0) < dist then
x = x - l / sc
end
if abs (r - sw) < dist then
x = x - (r - sw) / sc
end
if MultiBarLeft:IsVisible() then
local ml = MultiBarLeft:GetLeft()
if abs (r - ml) < dist then
x = x - (r - ml) / sc
end
end
if MultiBarRight:IsVisible() then
local ml = MultiBarRight:GetLeft()
if abs (r - ml) < dist then
x = x - (r - ml) / sc
end
end
if abs (b - 0) < dist then
y = y - b / sc
end
if abs (t - sh) < dist then
y = y - (t - sh) / sc
end
frm:SetPoint (atPt, x, y)
return nil
end
---------------------------------------------------------------------------------------
-- Recursively set child levels
---------------------------------------------------------------------------------------
function Nx.Util_SetChildLevels (frm, lvl)
if frm:GetNumChildren() > 0 then
local ch = { frm:GetChildren() }
for n, chf in pairs (ch) do
chf:SetFrameLevel (lvl)
if chf:GetNumChildren() > 0 then
Nx.Util_SetChildLevels (chf, lvl + 1)
end
end
end
end
---------------------------------------------------------------------------------------
-- Get a string from a money value
---------------------------------------------------------------------------------------
function Nx.Util_GetMoneyStr (money)
if not money then
return "|cffff4040?"
end
if money == 0 then
return "0"
end
local pre = money > 0 and "" or "-"
money = abs (money)
local str = ""
local g = floor (money / 10000)
if g > 0 then
str = format ("|cffffff00%dg", g)
end
local s = mod (floor (money / 100), 100)
if s > 0 then
str = format ("%s |cffbfbfbf%ds", str, s)
end
local c = mod (money, 100)
if c > 0 then
str = format ("%s |cff7f7f00%dc", str, c)
end
return pre .. strtrim (str)
end
---------------------------------------------------------------------------------------
-- Get a string from a seconds
---------------------------------------------------------------------------------------
function Nx.Util_GetTimeElapsedStr (seconds)
local secs = seconds
local mins = secs / 60 % 60
local hours = secs / 3600
if hours > 24 then
return format (L["%.1f days"], hours / 24)
elseif hours >= 1 then
return format (L["%.1f hours"], hours)
end
return format (L["%d mins"], mins)
end
function Nx.Util_SecondsToDays (seconds)
fdays = math.floor(seconds/86400)
fhours = math.floor((bit.mod(seconds,86400))/3600)
fminutes = math.floor(bit.mod((bit.mod(seconds,86400)),3600)/60)
fseconds = math.floor(bit.mod(bit.mod((bit.mod(seconds,86400)),3600),60))
return fdays.." days, "..fhours.." hours, "..fminutes.." minutes, "..fseconds.." seconds"
end
---------------------------------------------------------------------------------------
-- Get a string from a seconds in 00:00 minute:second format
---------------------------------------------------------------------------------------
function Nx.Util_GetTimeElapsedMinSecStr (seconds)
return format ("%d:%02d", seconds / 60 % 60, seconds % 60)
end
---------------------------------------------------------------------------------------
-- Nan to Zero conversion
---------------------------------------------------------------------------------------
function Nx.Util_NanToZero (somevar)
if value == math.huge or somevar == -math.huge then return 0 end
return (somevar ~= somevar and 0 or somevar)
end
---------------------------------------------------------------------------------------
-- Parse text and set for tooltip
---------------------------------------------------------------------------------------
function Nx:SetTooltipText (str)
if strbyte (str) == 33 then -- ! (item)
-- Nx.prt ("Item %s", str)
local link, s = Nx.Split ("^", str)
if not s or #s < 1 or IsAltKeyDown() then
str = strsub (link, 2)
Nx.Item:ShowTooltip (str, true)
return
end
str = s
elseif strbyte (str) == 64 then -- @ (quest)
str = "quest:" .. strsub (str, 2)
Nx.Item:ShowTooltip (str, true)
return
elseif strbyte (str) == 35 then -- # (enchant)
str = strsub (str, 2)
-- Nx.prt (str)
GameTooltip:SetHyperlink (str)
GameTooltip_ShowCompareItem()
return
end
local s1, s2 = strfind (str, "\n")
if s1 then
local t = { Nx.Split ("\n", str) }
GameTooltip:SetText (t[1], 1, 1, 1, 1, true) -- Wrap text
tremove (t, 1)
for _, line in ipairs (t) do
local s1, s2 = Nx.Split ("\t", line)
if s2 then
GameTooltip:AddDoubleLine (s1, s2, 1, 1, 1, 1, 1, 1)
else
GameTooltip:AddLine (line, 1, 1, 1, true) -- Wrap text
end
end
--[[
local s = strsub (str, 1, s1 - 1)
-- Nx.prt ("Tool %s", s)
GameTooltip:SetText (s, 1, 1, 1, 1, true)
s = strsub (str, s2 + 1)
GameTooltip:AddLine (s, 1, 1, 1, true)
--]]
GameTooltip:Show()
else
GameTooltip:SetText (str, 1, 1, 1, 1, true) -- Wrap text
end
end
---------------------------------------------------------------------------------------
-- Play a sound file if sounds enabled
---------------------------------------------------------------------------------------
function Nx:PlaySoundFile (file)
if GetCVar ("Sound_EnableSFX") ~= "0" then
PlaySoundFile (file)
end
end
---------------------------------------------------------------------------------------
-- Font stuff
---------------------------------------------------------------------------------------
function Nx.Font:Init()
self.Inited = true
-- Some code uses the "Nx" named font directly
self.Fonts = {
["Font.Small"] = { "NxFontS", "GameFontNormalSmall", "db" },
["Font.Medium"] = { "NxFontM", "GameFontNormal", "db" },
["Font.Map"] = { "NxFontMap", "GameFontNormalSmall", "db" },
["Font.MapLoc"] = { "NxFontMapLoc", "GameFontNormalSmall", "db" },
["Font.Menu"] = { "NxFontMenu", "GameFontNormalSmall", "db" },
}
self.Faces = {
{ "Arial", "Fonts\\ARIALN.TTF", },
{ "Friz", "Fonts\\FRIZQT__.TTF", },
{ "Morpheus", "Fonts\\MORPHEUS.TTF", },
{ "Skurri", "Fonts\\SKURRI.TTF", }
}
-- Predefine so we dont get dups
self.AddonFonts = {
["Arial Narrow"] = true,
["Friz Quadrata TT"] = true,
["Morpheus"] = true,
["Skurri"] = true,
}
for name, v in pairs (self.Fonts) do
local font = CreateFont (v[1])
v.Font = font
font:SetFontObject(v[2])
v.Font.db = v[3]
end
self:Update()
end
function Nx.Font:ModuleAdd (key, value)
self.Fonts[key] = value
local font = CreateFont (value[1])
value.Font = font
font:SetFontObject(value[2])
value.Font.db = value[3]
self:Update()
end
function Nx.Font:AddonLoaded()
if not self.Inited then
return
end
local found
found = self:FontScan ("LibSharedMedia-3.0")
if found then
self:Update()
end
end
function Nx.Font:FontScan (libName)
local sm
sm = LibStub(libName)
if sm then
local found
local fonts = sm.List(sm, "font")
-- Nx.prtVar ("SM", fonts)
for k, name in ipairs (fonts) do
if not self.AddonFonts[name] then
found = true
-- Nx.prtVar ("Font", name)
-- Nx.prtVar ("Fetch", sm["Fetch"] (sm, "font", name))
self.AddonFonts[name] = sm.Fetch(sm, "font", name)
tinsert (self.Faces, { name, self.AddonFonts[name] })
end
end
return found
end
end
function Nx.Font:GetObj (name)
return self.Fonts[name].Font
end
function Nx.Font:GetH (name)
-- Nx.prt ("Font %s", name or "nil")
return self.Fonts[name].H
end
function Nx.Font:GetIndex (name)
for k, v in ipairs (self.Faces) do
if v[1] == name then
return k
end
end
return 1
end
function Nx.Font:GetName (index)
local t = self.Faces[index]
return t and t[1]
end
function Nx.Font:GetFile (name)
for k, v in ipairs (self.Faces) do
if v[1] == name then
return v[2]
end
end
return self.Faces[2][2] -- Default to friz
end
function Nx.Font:Update()
for name, v in pairs (self.Fonts) do
local font = v.Font
local dbloc = v.Font.db
local fname, size, flags = font:GetFont()
local optname = "Nx." .. dbloc .. ".profile." .. name
-- Nx.prt ("Font %s %s %s", fname, size, flags)
local parts1, parts2 = Nx.Split(".",name)
local file = self:GetFile (Nx[dbloc].profile[parts1][parts2])
local size = Nx[dbloc].profile[parts1][parts2 .. "Size"]
font:SetFont (file, size, flags)
v.H = max (size + (Nx[dbloc].profile[parts1][parts2 .. "Spacing"] or 0), 6)
end
Nx.List:NextUpdateFull()
Nx.Window:AdjustAll()
end
---------------------------------------------------------------------------------------
-- Skin stuff
---------------------------------------------------------------------------------------