Repository navigation
Expand file tree
/
Copy pathEPLTowersUI.lua
More file actions
1650 lines (1530 loc) · 52.1 KB
/
Copy pathEPLTowersUI.lua
File metadata and controls
1650 lines (1530 loc) · 52.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- EPL Towers 2.2 - window, map, options, help, alerts, minimap button, slash commands
--
-- Everything here is drawn with the bundled Fira Sans Condensed: the game's own
-- Friz Quadrata has no Cyrillic letters, so Russian would show as blanks. That
-- is also why the addon has its own buttons (the game's button template swaps
-- to its own font on mouse-over) and its own tooltip frame.
local E = EPLTowers
local TOWERS = E.TOWERS
local NT = table.getn(TOWERS)
local COLORS = E.COLORS
local DIR = "Interface\\AddOns\\EPLTowers\\"
local FONT = DIR .. "fonts\\FiraSansCondensed-Regular.ttf"
local FONTB = DIR .. "fonts\\FiraSansCondensed-SemiBold.ttf"
local FLAGS = { en = DIR .. "media\\flag-en", ru = DIR .. "media\\flag-ru" }
local BAR_TEX = "Interface\\WorldStateFrame\\WorldState-CaptureBar"
local POI_TEX = "Interface\\Minimap\\POIIcons"
local PIP = DIR .. "media\\pip" -- round map dot: white centre takes the colour, black rim
-- faction crests from the game's PvP icons, cropped to the art (measured from the textures)
local CREST = {
Alliance = { "Interface\\TargetingFrame\\UI-PVP-Alliance", 0.008, 0.617, 0.031, 0.641 },
Horde = { "Interface\\TargetingFrame\\UI-PVP-Horde", 0.016, 0.609, 0.016, 0.609 },
}
local GOLD_R, GOLD_G, GOLD_B = 1, 0.82, 0.25
local MAP_W, MAP_H = 420, 280 -- the game's map is 1002 x 668
local W = MAP_W + 24
local ROW_H = 54
local TOP = 70 -- title plaque, language / score row, sync line
local BOTTOM = 46 -- button bar
local BAR_SCALE = 0.8 -- capture bar size in the tower rows
local main, mapFrame, listFrame, playerDot, syncDot, syncText, mapButton
local markers, rows, pills, scores = {}, {}, {}, {}
local optionsFrame, helpFrame, menu, mmButton, banner, tip
local autoOpened
local labels = {} -- font strings that follow the language switch
-------------------------------------------------------------------------------
-- Fonts, text, tooltip
-------------------------------------------------------------------------------
local function font(f, size, bold, flags)
if bold then f:SetFont(FONTB, size, flags or "") else f:SetFont(FONT, size, flags or "") end
end
local function text(parent, size, bold, layer, flags)
local f = parent:CreateFontString(nil, layer or "OVERLAY")
font(f, size, bold, flags)
f:SetShadowColor(0, 0, 0, 1)
f:SetShadowOffset(1, -1)
return f
end
-- a text that changes with the language
local function ltext(f, key)
f.lkey = key
table.insert(labels, f)
f:SetText(E.T(key))
return f
end
local function tipOpen(owner, anchor)
tip:SetOwner(owner, anchor or "ANCHOR_RIGHT")
end
-- our tooltip uses our font; lines are made as they are added, so set them all here
local function tipShow()
for i = 1, tip:NumLines() do
local l = getglobal("EPLTowersTipTextLeft" .. i)
local r = getglobal("EPLTowersTipTextRight" .. i)
if i == 1 then
if l then font(l, 14, true) end
else
if l then font(l, 12) end
if r then font(r, 12) end
end
end
tip:Show()
end
local function tipHide()
tip:Hide()
end
local function showTip()
tipOpen(this, this.tipAnchor)
tip:SetText(E.T(this.tipTitle, this.tipArg), GOLD_R, GOLD_G, GOLD_B)
if this.tipText then tip:AddLine(E.T(this.tipText), 1, 1, 1, 1) end
tipShow()
end
local function setTip(frame, titleKey, textKey)
frame.tipTitle = titleKey
frame.tipText = textKey
frame:SetScript("OnEnter", showTip)
frame:SetScript("OnLeave", tipHide)
end
-------------------------------------------------------------------------------
-- Frame chrome: gold dialog border, stone title plaque, buttons
-------------------------------------------------------------------------------
local function goldFrame(f)
f:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Border",
tile = true, tileSize = 32, edgeSize = 24,
insets = { left = 6, right = 6, top = 6, bottom = 6 },
})
f:SetBackdropColor(1, 1, 1, 0.97)
end
local function thinBorder(f, edge)
f:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = edge or 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
})
end
-- the stone plaque the game uses on its own dialogs (Game Menu, etc.)
local function plaque(f, key)
local h = f:CreateTexture(nil, "ARTWORK")
h:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
h:SetWidth(256)
h:SetHeight(64)
h:SetPoint("TOP", f, "TOP", 0, 12)
local t = text(f, 15, true)
t:SetPoint("TOP", h, "TOP", 0, -14)
t:SetTextColor(1, 0.82, 0)
ltext(t, key)
return h
end
local function closeButton(f, onClick)
local c = CreateFrame("Button", nil, f, "UIPanelCloseButton")
c:SetWidth(28)
c:SetHeight(28)
c:SetPoint("TOPRIGHT", f, "TOPRIGHT", -3, -3)
c:SetScript("OnClick", onClick)
return c
end
local function btnDown() this.label:SetPoint("CENTER", this, "CENTER", 1, -1) end
local function btnUp() this.label:SetPoint("CENTER", this, "CENTER", 0, 0) end
local function btnEnter()
this.label:SetTextColor(1, 1, 1)
if this.tipTitle then showTip() end
end
local function btnLeave()
this.label:SetTextColor(GOLD_R, GOLD_G, GOLD_B)
tipHide()
end
-- shrink a button's text until it fits (Russian words are longer)
local function fitLabel(b)
local size = 12.5
font(b.label, size, true)
while size > 9.5 and b.label:GetStringWidth() > b:GetWidth() - 8 do
size = size - 0.5
font(b.label, size, true)
end
end
local function newButton(parent, w, h, key, onClick, tipKey)
local b = CreateFrame("Button", nil, parent)
b:SetWidth(w)
b:SetHeight(h)
thinBorder(b, 12)
b:SetBackdropColor(0.16, 0.12, 0.05, 1)
b:SetBackdropBorderColor(0.85, 0.68, 0.3, 1)
local shine = b:CreateTexture(nil, "BORDER")
shine:SetPoint("TOPLEFT", b, "TOPLEFT", 3, -3)
shine:SetPoint("BOTTOMRIGHT", b, "BOTTOMRIGHT", -3, 3)
shine:SetTexture(1, 1, 1, 1)
shine:SetGradientAlpha("VERTICAL", 0, 0, 0, 0.35, 1, 0.9, 0.6, 0.14)
local hl = b:CreateTexture(nil, "HIGHLIGHT")
hl:SetPoint("TOPLEFT", b, "TOPLEFT", 3, -3)
hl:SetPoint("BOTTOMRIGHT", b, "BOTTOMRIGHT", -3, 3)
hl:SetTexture(1, 0.85, 0.4, 0.16)
b.label = text(b, 12.5, true)
b.label:SetPoint("CENTER", b, "CENTER", 0, 0)
b.label:SetTextColor(GOLD_R, GOLD_G, GOLD_B)
b.label.button = b
if key then
ltext(b.label, key)
fitLabel(b)
end
b:SetScript("OnMouseDown", btnDown)
b:SetScript("OnMouseUp", btnUp)
b:SetScript("OnEnter", btnEnter)
b:SetScript("OnLeave", btnLeave)
b:SetScript("OnClick", onClick)
b.tipTitle = key
b.tipText = tipKey
return b
end
-- game POI icons: 5 grey tower, 8 Alliance under attack, 9 Horde, 10 Alliance, 11 Horde under attack
local function setPoi(tex, index)
local x = math.mod(index, 8) * 0.125
local y = math.floor(index / 8) * 0.125
tex:SetTexCoord(x, x + 0.125, y, y + 0.125)
end
local function iconIndex(owner, dir)
if owner == "Alliance" then
if dir == -1 then return 8 end
return 10
elseif owner == "Horde" then
if dir == 1 then return 11 end
return 9
end
return 5
end
local function setCrest(tex, fac)
local c = CREST[fac]
if c then
tex:SetTexture(c[1])
tex:SetTexCoord(c[2], c[3], c[4], c[5])
else
tex:SetTexture(POI_TEX)
setPoi(tex, 5)
end
end
-------------------------------------------------------------------------------
-- Capture bar: a copy of the game's own bar (WorldStateCaptureBarTemplate),
-- same texture, layout and position formula, so it matches what you see in game.
-------------------------------------------------------------------------------
local function barTex(b, layer, w, h, l, r, t, bt)
local x = b:CreateTexture(nil, layer)
x:SetTexture(BAR_TEX)
x:SetWidth(w)
x:SetHeight(h)
x:SetTexCoord(l, r, t, bt)
return x
end
local function newCaptureBar(parent, scale)
local b = CreateFrame("Frame", nil, parent)
b:SetWidth(173)
b:SetHeight(26)
b:SetScale(scale)
local left = barTex(b, "BACKGROUND", 48, 9, 0.8203125, 1.0, 0, 0.140625)
left:SetPoint("LEFT", b, "LEFT", 26, 0)
local right = barTex(b, "BACKGROUND", 48, 9, 0.8203125, 1.0, 0.171875, 0.3125)
right:SetPoint("RIGHT", b, "RIGHT", -26, 0)
local mid = barTex(b, "BACKGROUND", 48, 9, 0.8203125, 1.0, 0.34375, 0.484375)
mid:SetPoint("LEFT", left, "RIGHT", 0, 0)
mid:SetPoint("RIGHT", right, "LEFT", 0, 0)
local art = barTex(b, "ARTWORK", 173, 26, 0, 0.67578125, 0, 0.40625)
art:SetPoint("TOP", b, "TOP", 0, 0)
local d1 = barTex(b, "ARTWORK", 3, 8, 0.74609375, 0.7578125, 0, 0.125)
d1:SetPoint("LEFT", left, "RIGHT", -1, 0)
local d2 = barTex(b, "ARTWORK", 3, 8, 0.74609375, 0.7578125, 0, 0.125)
d2:SetPoint("RIGHT", right, "LEFT", 1, 0)
b.hlLeft = barTex(b, "OVERLAY", 27, 28, 0, 0.10546875, 0.4375, 0.875)
b.hlLeft:SetBlendMode("ADD")
b.hlLeft:SetPoint("LEFT", b, "LEFT", -1, 0)
b.hlRight = barTex(b, "OVERLAY", 27, 28, 0, 0.10546875, 0.4375, 0.875)
b.hlRight:SetBlendMode("ADD")
b.hlRight:SetPoint("RIGHT", b, "RIGHT", 1, 0)
local ind = CreateFrame("Frame", nil, b)
ind:SetWidth(5)
ind:SetHeight(18)
local it = ind:CreateTexture(nil, "ARTWORK")
it:SetTexture(BAR_TEX)
it:SetAllPoints(ind)
it:SetTexCoord(0.77734375, 0.796875, 0, 0.28125)
ind.left = barTex(ind, "BACKGROUND", 8, 15, 0.7265625, 0.76171875, 0.140625, 0.375)
ind.left:SetPoint("RIGHT", ind, "LEFT", 1, 0)
ind.right = barTex(ind, "BACKGROUND", 8, 15, 0.76171875, 0.7265625, 0.140625, 0.375)
ind.right:SetPoint("LEFT", ind, "RIGHT", -1, 0)
b.ind = ind
return b
end
-- dir: 1 moving toward Alliance (arrow points left), -1 toward Horde (right)
local function drawBar(b, v, n, dir, faded)
if not v then
b.ind:Hide()
b.hlLeft:Hide()
b.hlRight:Hide()
b:SetAlpha(0.35)
return
end
b.ind:ClearAllPoints()
b.ind:SetPoint("CENTER", b, "LEFT", 25 + 124 * (1 - v / 100), 0) -- CaptureBar_Update
b.ind:Show()
if dir == 1 then b.ind.left:Show() else b.ind.left:Hide() end
if dir == -1 then b.ind.right:Show() else b.ind.right:Hide() end
local lo, hi = E.bounds(n)
if v > hi then b.hlLeft:Show() else b.hlLeft:Hide() end
if v < lo then b.hlRight:Show() else b.hlRight:Hide() end
if faded then b:SetAlpha(0.45) else b:SetAlpha(1) end
end
-------------------------------------------------------------------------------
-- Tooltips for towers and sync
-------------------------------------------------------------------------------
local function towerTooltip(frame, key)
local s = E.state[key]
local d = E.describe(key)
local e = d.e
local nowT = time()
tipOpen(frame, "ANCHOR_RIGHT")
tip:SetText(E.TN(key), GOLD_R, GOLD_G, GOLD_B)
local c = COLORS[s.owner or "Unknown"]
tip:AddLine(E.T("tOwner", E.FN(s.owner)), c[1], c[2], c[3])
if s.ownerAt then
local from = ""
if s.ownerSrc then from = E.T("tFrom", E.SrcName(s.ownerSrc)) end
tip:AddLine(E.T("tOwnerInfo", E.ago(nowT - s.ownerAt)) .. from, 0.6, 0.6, 0.6)
end
if s.value then
tip:AddLine(" ")
if e.live then
if s.src == "you" then
tip:AddLine(E.T("tLiveYou"), 0.25, 1, 0.25)
else
tip:AddLine(E.T("tLiveOther", E.SrcName(s.src)), 0.25, 1, 0.25)
end
else
local from = ""
if s.src then from = E.T("tFrom", E.SrcName(s.src)) end
tip:AddLine(E.T("tLastReading", E.ago(nowT - (s.valueAt or nowT))) .. from, 0.6, 0.6, 0.6)
end
tip:AddLine(E.T("tBar", s.value), 1, 1, 1)
if e.live and e.rate and e.rate ~= 0 then
for i = 1, table.getn(e.milestones) do
local m = e.milestones[i]
local mc = COLORS[m.fac]
local label
if m.full then label = E.T("full_" .. m.fac) else label = E.FN(m.fac) end
tip:AddDoubleLine(label, (e.approx and "< " or "") .. E.fmt(m.eta), mc[1], mc[2], mc[3], 1, 1, 1)
end
if e.approx then
tip:AddLine(E.T("tApprox"), 0.6, 0.6, 0.6, 1)
elseif e.slowing then
tip:AddLine(E.T("tSlow"), 0.6, 0.6, 0.6, 1)
else
tip:AddLine(E.T("tSpeed", e.per, e.speed), 0.6, 0.6, 0.6)
end
elseif e.live then
tip:AddLine(d.line1, 1, 1, 1)
tip:AddLine(d.line2, 0.6, 0.6, 0.6, 1)
end
end
tip:AddLine(" ")
tip:AddLine(E.T("tClick"), 0.5, 0.8, 1)
tipShow()
end
local function towerEnter()
towerTooltip(this, this.key)
end
local function syncTooltip()
tipOpen(this, "ANCHOR_BOTTOM")
tip:SetText(E.T("syncTitle"), GOLD_R, GOLD_G, GOLD_B)
tip:AddLine(E.T("syncBody"), 1, 1, 1, 1)
local nowT, now = time(), GetTime()
local any
for name, p in pairs(E.peers) do
if nowT - p.seen < 3600 then
if not any then
tip:AddLine(" ")
tip:AddLine(E.T("peersTitle"), GOLD_R, GOLD_G, GOLD_B)
any = true
end
local where = E.ago(nowT - p.seen)
if p.at and p.atGT and now - p.atGT <= E.LIVE_FOR then
where = "|cff40ff40" .. E.T("atTower", E.TS(p.at)) .. "|r"
end
local who = name
if not p.v2 then who = who .. "|cff888888" .. E.T("oldVersion") .. "|r" end
tip:AddDoubleLine(who, where, 1, 1, 1, 0.8, 0.8, 0.8)
end
end
if not any then
tip:AddLine(" ")
tip:AddLine(E.T("noPeers"), 0.6, 0.6, 0.6, 1)
end
tipShow()
end
-------------------------------------------------------------------------------
-- Alert banner (instead of the raid warning frame, whose font has no Cyrillic)
-------------------------------------------------------------------------------
local function bannerUpdate()
local b = banner
if b.anchoring then return end -- stays up while you place it
b.t = b.t + arg1
if b.t < 0.25 then
b:SetAlpha(b.t / 0.25)
elseif b.t < 5 then
b:SetAlpha(1)
elseif b.t < 6 then
b:SetAlpha(6 - b.t)
else
b:Hide()
end
end
-- saved as the top centre, so a longer or shorter message stays centred on that spot
local function applyBannerPos()
banner:ClearAllPoints()
local p = E.db.bannerPos
if p then
banner:SetPoint("TOP", UIParent, "BOTTOMLEFT", p.x, p.y)
else
banner:SetPoint("TOP", UIParent, "TOP", 0, -140)
end
end
local function bannerDragStop()
banner:StopMovingOrSizing()
local l, t = banner:GetLeft(), banner:GetTop()
if l and t then E.db.bannerPos = { x = l + banner:GetWidth() / 2, y = t } end
applyBannerPos()
end
local function buildBanner()
banner = CreateFrame("Frame", "EPLTowersBanner", UIParent)
banner:SetFrameStrata("HIGH")
banner:SetHeight(58)
banner:SetWidth(420)
-- click-through except while you are placing it (anchor mode)
banner:SetMovable(true)
banner:SetClampedToScreen(true)
banner:EnableMouse(false)
banner:RegisterForDrag("LeftButton")
banner:SetScript("OnDragStart", function() this:StartMoving() end)
banner:SetScript("OnDragStop", bannerDragStop)
applyBannerPos()
goldFrame(banner)
banner.done = newButton(banner, 110, 22, "oMoveDone", function() E.ToggleAnchor() end, "oMoveD")
banner.done:SetPoint("TOP", banner, "BOTTOM", 0, -4)
banner.done:Hide()
banner.crest = banner:CreateTexture(nil, "ARTWORK")
banner.crest:SetWidth(36)
banner.crest:SetHeight(36)
banner.crest:SetPoint("LEFT", banner, "LEFT", 14, 0)
banner.text = text(banner, 17, true)
banner.text:SetPoint("LEFT", banner.crest, "RIGHT", 10, 0)
banner.text:SetJustifyH("LEFT")
banner:SetScript("OnUpdate", bannerUpdate)
banner:Hide()
end
function E.ShowBanner(msg, r, g, b, fac)
if not banner then buildBanner() end
setCrest(banner.crest, fac)
banner.text:SetText(msg)
banner.text:SetTextColor(r, g, b)
banner:SetWidth(math.max(300, banner.text:GetStringWidth() + 84))
banner.t = 0
if not banner.anchoring then banner:SetAlpha(0) end
banner:Show()
end
local function updateMoveButton()
if not optionsFrame then return end
local b = optionsFrame.moveBtn
if banner and banner.anchoring then b.label.lkey = "oMoveDone" else b.label.lkey = "oMove" end
b.label:SetText(E.T(b.label.lkey))
fitLabel(b)
end
-- anchor mode: show the alert banner so it can be dragged anywhere
function E.ToggleAnchor()
if not banner then buildBanner() end
if banner.anchoring then
banner.anchoring = nil
banner:EnableMouse(false)
banner:SetBackdropBorderColor(1, 1, 1, 1)
banner.done:Hide()
banner:Hide()
E.print(E.T("anchorSaved"))
else
banner.anchoring = true
setCrest(banner.crest, E.myFaction)
banner.text:SetText(E.T("anchorSample"))
banner.text:SetTextColor(GOLD_R, GOLD_G, GOLD_B)
banner:SetWidth(math.max(300, banner.text:GetStringWidth() + 84))
banner:SetAlpha(1)
banner:EnableMouse(true)
banner:SetBackdropBorderColor(0.3, 1, 0.3, 1)
banner.done:Show()
banner:Show()
E.print(E.T("anchorStart"))
end
updateMoveButton()
end
-------------------------------------------------------------------------------
-- Popup menu for one tower
-------------------------------------------------------------------------------
local MENU = {
{ key = "mAnnounce", desc = "mAnnounceD", fn = function(k) E.announce(k) end },
{ key = "mSet", fac = "Alliance", desc = "mSetD", fn = function(k) E.manualOwner(k, "Alliance") end },
{ key = "mSet", fac = "Horde", desc = "mSetD", fn = function(k) E.manualOwner(k, "Horde") end },
{ key = "mSet", fac = "Neutral", desc = "mSetD", fn = function(k) E.manualOwner(k, "Neutral") end },
{ key = "mForget", desc = "mForgetD", fn = function(k) E.forget(k); E.print(E.T("forgotten", E.TN(k))) end },
{ key = "mClose", desc = "mCloseD" },
}
local function menuClick()
local item = MENU[this.index]
local key = menu.key
menu:Hide()
if item.fn then item.fn(key) end
E.UpdateUI()
end
local function menuTexts()
for i = 1, table.getn(MENU) do
local item = MENU[i]
local b = menu.items[i]
if item.fac then
b.label:SetText(E.T("mSet", COLORS[item.fac][4] .. E.FN(item.fac) .. "|r"))
b.tipArg = E.FN(item.fac)
else
b.label:SetText(E.T(item.key))
end
end
end
local function buildMenu()
menu = CreateFrame("Frame", "EPLTowersMenu", UIParent)
thinBorder(menu, 14)
menu:SetBackdropColor(0.06, 0.05, 0.04, 0.97)
menu:SetBackdropBorderColor(0.85, 0.68, 0.3, 1)
menu:SetFrameStrata("FULLSCREEN_DIALOG") -- above the options and help panels
menu:SetWidth(210)
menu:SetHeight(36 + table.getn(MENU) * 19)
menu:EnableMouse(true)
menu.title = text(menu, 13, true)
menu.title:SetPoint("TOPLEFT", menu, "TOPLEFT", 12, -10)
menu.title:SetTextColor(GOLD_R, GOLD_G, GOLD_B)
menu.items = {}
for i = 1, table.getn(MENU) do
local b = CreateFrame("Button", nil, menu)
b:SetWidth(194)
b:SetHeight(19)
b:SetPoint("TOPLEFT", menu, "TOPLEFT", 8, -28 - (i - 1) * 19)
b.index = i
local hl = b:CreateTexture(nil, "HIGHLIGHT")
hl:SetAllPoints(b)
hl:SetTexture(1, 0.85, 0.4, 0.14)
b.label = text(b, 12.5)
b.label:SetPoint("LEFT", b, "LEFT", 6, 0)
b:SetScript("OnClick", menuClick)
setTip(b, MENU[i].key, MENU[i].desc)
menu.items[i] = b
end
menu:SetScript("OnUpdate", function()
if MouseIsOver(menu) then
menu.away = 0
else
menu.away = (menu.away or 0) + arg1
if menu.away > 1.5 then menu:Hide() end
end
end)
menu:Hide()
end
function E.OpenMenu(key)
if not menu then buildMenu() end
menu.key = key
menu.away = 0
menu.title:SetText(E.TN(key))
menuTexts()
local x, y = GetCursorPosition()
local sc = UIParent:GetEffectiveScale()
menu:ClearAllPoints()
menu:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x / sc - 10, y / sc + 10)
menu:Show()
end
local function towerClick()
E.OpenMenu(this.key)
end
-------------------------------------------------------------------------------
-- Announce (in the chosen language; chat fonts have Cyrillic)
-------------------------------------------------------------------------------
-- cut to maxBytes without splitting a UTF-8 letter
local function utf8cut(s, maxBytes)
if string.len(s) <= maxBytes then return s end
local cut = maxBytes
while cut > 0 do
local b = string.byte(s, cut + 1)
if not b or b < 128 or b >= 192 then break end
cut = cut - 1
end
return string.sub(s, 1, cut) .. "..."
end
function E.announce(key, guild)
local msg
if key then
msg = E.T("annPrefix") .. E.describe(key).plain
else
local parts = {}
for i = 1, NT do
local d = E.describe(TOWERS[i].key)
table.insert(parts, d.plainShort or d.plain)
end
msg = E.T("annPrefix") .. table.concat(parts, " / ")
end
-- no colour codes or stray pipes in chat: the client rejects bad escapes
msg = string.gsub(msg, "|c%x%x%x%x%x%x%x%x", "")
msg = string.gsub(msg, "|r", "")
msg = string.gsub(msg, "|", "/")
msg = utf8cut(msg, 250)
local chan
if guild then
if IsInGuild() then chan = "GUILD" end
elseif GetNumRaidMembers() > 0 then
chan = "RAID"
elseif GetNumPartyMembers() > 0 then
chan = "PARTY"
end
if chan then
-- shared 30 s cooldown across everyone with the addon (see E.tryAnnounce)
E.tryAnnounce(chan, key or "ALL", msg)
else
if guild then E.print(E.T("onlyYouGuild")) else E.print(E.T("onlyYouGroup")) end
E.print(msg)
end
end
-------------------------------------------------------------------------------
-- Main window
-------------------------------------------------------------------------------
local function savePos()
local x, y = main:GetLeft(), main:GetTop()
if x and y then E.db.pos = { x = x, y = y } end
end
local function applyPos()
main:ClearAllPoints()
local p = E.db.pos
if p then
main:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", p.x, p.y)
else
main:SetPoint("CENTER", UIParent, "CENTER", 0, 80)
end
end
function E.setScale(v)
local old = main:GetScale()
local x, y = main:GetLeft(), main:GetTop()
main:SetScale(v)
E.db.opts.scale = v
if x and y then
-- keep the top left corner where it is on screen
E.db.pos = { x = x * old / v, y = y * old / v }
applyPos()
end
end
function E.Layout()
listFrame:ClearAllPoints()
if E.db.opts.showMap then
mapFrame:Show()
listFrame:SetPoint("TOPLEFT", main, "TOPLEFT", 12, -(TOP + MAP_H + 8))
main:SetHeight(TOP + MAP_H + 8 + NT * ROW_H + BOTTOM)
mapButton.label.lkey = "bMapHide"
else
mapFrame:Hide()
listFrame:SetPoint("TOPLEFT", main, "TOPLEFT", 12, -TOP)
main:SetHeight(TOP + NT * ROW_H + BOTTOM)
mapButton.label.lkey = "bMapShow"
end
mapButton.label:SetText(E.T(mapButton.label.lkey))
fitLabel(mapButton)
mapButton.tipTitle = mapButton.label.lkey
end
local function toggleMap()
E.db.opts.showMap = not E.db.opts.showMap
E.Layout()
E.RefreshOptions()
E.UpdateUI()
end
local function startMove()
if E.db.opts.lock then return end
main:StartMoving()
end
local function stopMove()
main:StopMovingOrSizing()
savePos()
end
local function pillClick()
E.ApplyLanguage(this.lang)
end
local function updatePills()
for _, p in pairs(pills) do
if p.lang == E.lang then
p:SetBackdropColor(0.28, 0.21, 0.07, 1)
p:SetBackdropBorderColor(1, 0.82, 0.3, 1)
p.label:SetTextColor(1, 1, 1)
p.flag:SetAlpha(1)
else
p:SetBackdropColor(0.05, 0.05, 0.06, 0.9)
p:SetBackdropBorderColor(0.45, 0.45, 0.45, 1)
p.label:SetTextColor(0.6, 0.6, 0.6)
p.flag:SetAlpha(0.45)
end
end
end
local function newPill(lang)
local b = CreateFrame("Button", nil, main)
b:SetWidth(86)
b:SetHeight(20)
thinBorder(b, 10)
local hl = b:CreateTexture(nil, "HIGHLIGHT")
hl:SetPoint("TOPLEFT", b, "TOPLEFT", 3, -3)
hl:SetPoint("BOTTOMRIGHT", b, "BOTTOMRIGHT", -3, 3)
hl:SetTexture(1, 0.85, 0.4, 0.16)
local edge = b:CreateTexture(nil, "ARTWORK")
edge:SetWidth(24)
edge:SetHeight(14)
edge:SetPoint("LEFT", b, "LEFT", 5, 0)
edge:SetTexture(0, 0, 0, 1)
b.flag = b:CreateTexture(nil, "OVERLAY")
b.flag:SetWidth(22)
b.flag:SetHeight(12)
b.flag:SetPoint("CENTER", edge, "CENTER", 0, 0)
b.flag:SetTexture(FLAGS[lang])
b.label = text(b, 12, true)
b.label:SetPoint("LEFT", edge, "RIGHT", 6, 0)
b.label:SetText(E.LANG_NAMES[lang]) -- each language in its own spelling
b.lang = lang
b:SetScript("OnClick", pillClick)
setTip(b, "langTip", "langBody")
return b
end
local function newScore(fac, x)
local g = CreateFrame("Frame", nil, main)
g:SetWidth(44)
g:SetHeight(20)
g:SetPoint("TOPRIGHT", main, "TOPRIGHT", x, -30)
g.icon = g:CreateTexture(nil, "ARTWORK")
g.icon:SetWidth(20)
g.icon:SetHeight(20)
g.icon:SetPoint("LEFT", g, "LEFT", 0, 0)
setCrest(g.icon, fac)
g.num = text(g, 15, true)
g.num:SetPoint("LEFT", g.icon, "RIGHT", 4, 0)
local c = COLORS[fac or "Neutral"]
g.num:SetTextColor(c[1], c[2], c[3])
scores[fac or "Neutral"] = g
end
local function buildMain()
main = CreateFrame("Frame", "EPLTowersFrame", UIParent)
main:SetWidth(W)
main:SetFrameStrata("MEDIUM")
goldFrame(main)
main:SetMovable(true)
main:EnableMouse(true)
main:SetClampedToScreen(true)
main:RegisterForDrag("LeftButton")
main:SetScript("OnDragStart", startMove)
main:SetScript("OnDragStop", stopMove)
main:SetScript("OnShow", function() E.UpdateUI() end)
main:SetScript("OnHide", function()
autoOpened = nil
if optionsFrame then optionsFrame:Hide() end
if helpFrame then helpFrame:Hide() end
if menu then menu:Hide() end
end)
plaque(main, "title")
-- the plaque sticks out above the frame: give it its own drag handle
local grab = CreateFrame("Frame", nil, main)
grab:SetWidth(150)
grab:SetHeight(30)
grab:SetPoint("TOP", main, "TOP", 0, 8)
grab:EnableMouse(true)
grab:RegisterForDrag("LeftButton")
grab:SetScript("OnDragStart", startMove)
grab:SetScript("OnDragStop", stopMove)
setTip(grab, "title", "dragTip")
local close = closeButton(main, function() main:Hide(); E.db.shown = false end)
setTip(close, "tClose", "dClose")
for i = 1, table.getn(E.LANGS) do
local p = newPill(E.LANGS[i])
p:SetPoint("TOPLEFT", main, "TOPLEFT", 14 + (i - 1) * 90, -30)
table.insert(pills, p)
end
newScore(nil, -14)
newScore("Horde", -62)
newScore("Alliance", -110)
-- sync line
local sb = CreateFrame("Button", nil, main)
sb:SetPoint("TOPLEFT", main, "TOPLEFT", 12, -53)
sb:SetWidth(MAP_W)
sb:SetHeight(14)
sb:SetScript("OnEnter", syncTooltip)
sb:SetScript("OnLeave", tipHide)
syncDot = sb:CreateTexture(nil, "ARTWORK")
syncDot:SetWidth(8)
syncDot:SetHeight(8)
syncDot:SetPoint("LEFT", sb, "LEFT", 3, 0)
syncText = text(sb, 12)
syncText:SetPoint("LEFT", syncDot, "RIGHT", 6, 0)
syncText:SetJustifyH("LEFT")
end
-------------------------------------------------------------------------------
-- You and your group on the map. Same data as the game's world map:
-- GetPlayerMapPosition on raid1..40 (or party1..4), 0,0 = not on this map.
-------------------------------------------------------------------------------
-- standard class colours (RAID_CLASS_COLORS is not always loaded on this client)
local CLASS_COLORS = {
WARRIOR = { 0.78, 0.61, 0.43 }, PALADIN = { 0.96, 0.55, 0.73 }, HUNTER = { 0.67, 0.83, 0.45 },
ROGUE = { 1.00, 0.96, 0.41 }, PRIEST = { 1.00, 1.00, 1.00 }, SHAMAN = { 0.00, 0.44, 0.87 },
MAGE = { 0.41, 0.80, 0.94 }, WARLOCK = { 0.58, 0.51, 0.79 }, DRUID = { 1.00, 0.49, 0.04 },
}
local groupDots = {}
local function classColor(unit)
local _, class = UnitClass(unit)
local c = class and CLASS_COLORS[class]
if c then return c[1], c[2], c[3] end
return 0.6, 0.8, 1
end
-- lists everyone under the mouse, like the game's map does
local function unitsEnter()
tipOpen(this, "ANCHOR_RIGHT")
tip:SetText(E.T("groupTitle"), GOLD_R, GOLD_G, GOLD_B)
if playerDot:IsVisible() and MouseIsOver(playerDot) then
tip:AddDoubleLine(UnitName("player") or "?", E.T("you"), 1, 0.85, 0.1, 0.8, 0.8, 0.8)
end
for i = 1, table.getn(groupDots) do
local d = groupDots[i]
if d:IsVisible() and MouseIsOver(d) then
local u = d.unit
local status = ""
if UnitIsDeadOrGhost(u) then
status = "|cffff5050" .. E.T("dead") .. "|r"
else
local hp, mx = UnitHealth(u), UnitHealthMax(u)
if mx and mx > 0 then status = math.floor(hp / mx * 100 + 0.5) .. "%" end
end
if d.sub then status = status .. " " .. E.T("grp", d.sub) end
local r, g, b = classColor(u)
tip:AddDoubleLine(UnitName(u) or "?", status, r, g, b, 0.8, 0.8, 0.8)
end
end
tipShow()
end
local function newDot(level, size)
local d = CreateFrame("Button", nil, mapFrame)
d:SetWidth(size)
d:SetHeight(size)
d:SetFrameLevel(mapFrame:GetFrameLevel() + level)
d.tex = d:CreateTexture(nil, "ARTWORK")
d.tex:SetAllPoints(d)
d.tex:SetTexture(PIP)
d:SetScript("OnEnter", unitsEnter)
d:SetScript("OnLeave", tipHide)
d:Hide()
return d
end
local function placeUnit(unit, n, sub)
if not UnitExists(unit) or UnitIsUnit(unit, "player") then return n end
local x, y = GetPlayerMapPosition(unit)
if not x or (x == 0 and y == 0) then return n end
n = n + 1
local d = groupDots[n]
if not d then
d = newDot(6, 11)
groupDots[n] = d
end
d.unit = unit
d.sub = sub
d:ClearAllPoints()
d:SetPoint("CENTER", mapFrame, "TOPLEFT", x * MAP_W, -y * MAP_H)
d.tex:SetVertexColor(classColor(unit))
if UnitIsDeadOrGhost(unit) then d:SetAlpha(0.45) else d:SetAlpha(1) end
d:Show()
return n
end
local function updateMapUnits()
local n = 0
if E.inZone() and E.mapIsEPL() then
local x, y = GetPlayerMapPosition("player")
if x and (x > 0 or y > 0) then
playerDot:ClearAllPoints()
playerDot:SetPoint("CENTER", mapFrame, "TOPLEFT", x * MAP_W, -y * MAP_H)
playerDot:Show()
else
playerDot:Hide()
end
if E.db.opts.showGroup then
local raid = GetNumRaidMembers()
if raid > 0 then
for i = 1, raid do
local _, _, sub = GetRaidRosterInfo(i)
n = placeUnit("raid" .. i, n, sub)
end
else
for i = 1, GetNumPartyMembers() do n = placeUnit("party" .. i, n) end
end
end
else
playerDot:Hide()
end
for i = n + 1, table.getn(groupDots) do groupDots[i]:Hide() end
end
-- the dots move smoothly: updated about 7 times a second while the map is on screen
local function mapTick()
this.acc = (this.acc or 0) + arg1
if this.acc < 0.15 then return end
this.acc = 0
updateMapUnits()
end
local function buildMap()
mapFrame = CreateFrame("Frame", nil, main)
mapFrame:SetWidth(MAP_W)
mapFrame:SetHeight(MAP_H)
mapFrame:SetPoint("TOPLEFT", main, "TOPLEFT", 12, -TOP)
-- the game's own EPL map: 4 x 3 tiles of 256 px, visible area 1002 x 668
local sc = MAP_W / 1002
for i = 1, 12 do
local row = math.floor((i - 1) / 4)
local col = math.mod(i - 1, 4)
local w, h, r, b = 256, 256, 1, 1
if col == 3 then w = 234; r = 234 / 256 end
if row == 2 then h = 156; b = 156 / 256 end
local tex = mapFrame:CreateTexture(nil, "BACKGROUND")
tex:SetTexture("Interface\\WorldMap\\EasternPlaguelands\\EasternPlaguelands" .. i)
tex:SetTexCoord(0, r, 0, b)
tex:SetWidth(w * sc)
tex:SetHeight(h * sc)
tex:SetPoint("TOPLEFT", mapFrame, "TOPLEFT", col * 256 * sc, -row * 256 * sc)
end
local shade = mapFrame:CreateTexture(nil, "BORDER")
shade:SetAllPoints(mapFrame)
shade:SetTexture(0, 0, 0, 0.2)
-- gold frame around the map (its own frame so it never hides the markers)
local edge = CreateFrame("Frame", nil, mapFrame)
edge:SetPoint("TOPLEFT", mapFrame, "TOPLEFT", -4, 4)
edge:SetPoint("BOTTOMRIGHT", mapFrame, "BOTTOMRIGHT", 4, -4)
edge:SetBackdrop({ edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 } })
edge:SetBackdropBorderColor(0.85, 0.68, 0.3, 1)
edge:SetFrameLevel(mapFrame:GetFrameLevel() + 1)
for i = 1, NT do
local t = TOWERS[i]
local m = CreateFrame("Button", nil, mapFrame)
m:SetFrameLevel(mapFrame:GetFrameLevel() + 3)
m:SetWidth(22)
m:SetHeight(22)
m:SetPoint("CENTER", mapFrame, "TOPLEFT", t.x * MAP_W, -t.y * MAP_H)
m:RegisterForClicks("LeftButtonUp", "RightButtonUp")
m.key = t.key
m.icon = m:CreateTexture(nil, "ARTWORK")
m.icon:SetAllPoints(m)
m.icon:SetTexture(POI_TEX)
m:SetScript("OnEnter", towerEnter)
m:SetScript("OnLeave", tipHide)
m:SetScript("OnClick", towerClick)
m.name = text(m, 12, true, "OVERLAY", "OUTLINE")
m.name:SetPoint("BOTTOM", m, "TOP", 0, 1)
m.name:SetTextColor(1, 0.86, 0.4)