Repository navigation
Expand file tree
/
Copy pathCallAssistance.lua
More file actions
1146 lines (1047 loc) · 44.7 KB
/
Copy pathCallAssistance.lua
File metadata and controls
1146 lines (1047 loc) · 44.7 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
-- CallAssistance — Gegenstueck zu CallSpell
-- Laeuft beim Anfragenden: Tabelle wie CallSpell, aber ohne Stimme.
-- "Macro erstellen" baut ein Makro, das den Fluestertext an die jeweilige Person schickt.
-- Wird das Makro gedrueckt, kommt der eigene ausgehende Chat zurueck
-- (CHAT_MSG_WHISPER_INFORM) — dann zeigt das Addon Symbol + Restlaufzeit.
--
-- Restlaufzeit: zuerst aus der Aura-API (C_UnitAuras), sonst selbst heruntergezaehlt
-- ab dem Moment des Fluesterns mit der eingetragenen Gesamtdauer.
local ADDON = "CallAssistance"
local VERSION = "2.3"
-- ---------------------------------------------------------------- Sprachen
local TEXTE = {
de = {
zauber = "Anfragen",
anzeige = "Anzeige",
kanaele = "Eigene Nachrichten, die zählen",
sprache = "Sprache",
sprache_auto = "automatisch", sprache_de = "Deutsch", sprache_en = "Englisch",
col_name = "Name", col_spellid = "SpellID", col_symbol = "Symbol",
col_phrase = "Flüstertext", col_target = "Ziel", col_dauer = "Dauer",
cb_symbol = "Symbol zeigen", cb_zahl = "Zahl zeigen", cb_balken = "Balken zeigen",
cb_whisper = "Flüstern", cb_party = "Gruppe", cb_raid = "Raid",
cb_debug = "Debug-Meldungen im Chat",
slider_size = "Symbolgröße",
btn_macro = "Macro erstellen", btn_new = "+ Anfrage hinzufügen",
hint_spells = "Symbol leer = Zauber-Symbol · Ziel = wer den Zauber wirkt · "
.. "Dauer = Sekunden, die der Buff hält (0 = gar nicht anzeigen). × entfernt die Zeile.",
hilfe_titel = "— Befehle:",
geladen = "CallAssistance %s geladen — /ca für Befehle",
makro_angelegt = "Makro angelegt (charakterspezifisch): %s",
kein_platz = "kein freier Makro-Platz",
ziel_fehlt = "Ziel fehlt in der Zeile",
phrase_fehlt = "Flüstertext fehlt in der Zeile",
test = "Test-Anzeige läuft (10 s)",
an = "ist AN", aus = "ist AUS",
an_kurz = "an", aus_kurz = "aus",
unbekannt = "unbekannter Befehl: %s",
zeile_falsch = "Zeilennummer fehlt oder falsch: /ca %s <Zeile> <Wert>",
weg_fehlt = "Zeile gibt es nicht",
neu_fehlt = "SpellID fehlt: /ca neu <SpellID> [Name]",
neu_gemacht = "hinzugefügt: %s (ID %d) — Flüstertext jetzt mit /ca phrase %d <Text> setzen",
gesetzt = "%s: %s = %s",
treffer = "Anfrage erkannt: %s",
import_ok = "%d Anfrage(n) übernommen — Namen kommen aus dem Zauber",
import_leer = "Code fehlt: /ca import <SpellID>|<Flüstertext>|<Ziel>|<Dauer>;…",
export_kopf = "Code zum Weitergeben:",
kein_kampf = "im Kampf nicht möglich — bitte außerhalb",
position_hinweis = "Anzeige hierher ziehen · /ca position beendet",
position_an = "Platzieren: Anzeige mit der Maus verschieben, dann /ca position zum Beenden",
position_aus = "Platzieren beendet",
btn_move = "Anzeige verschieben",
btn_done = "Fertig",
buff_aus_api = "Restzeit aus Buff-API: %s",
buff_nicht_lesbar = "Buff nicht lesbar — zähle selbst (%.0f s)",
hilfe = [[
/ca config Einstellungen (auch: Optionen -> Addons -> Call Assistance)
/ca test Test-Anzeige, 10 s
/ca an | /ca aus Addon ein/aus
/ca neu <SpellID> [Name] neue Zeile in der Anfrage-Tabelle
/ca weg <Zeile> Zeile entfernen
/ca phrase <Zeile> <Text> Flüstertext setzen
/ca icon <Zeile> <ID> eigenes Symbol (0 = Zauber-Symbol)
/ca ziel <Zeile> <Name> Person, die den Zauber wirkt
/ca dauer <Zeile> <Sek> Gesamtdauer für den Selbst-Countdown
/ca macro <Zeile> Makro für die Zeile erstellen
/ca export Code zum Weitergeben an einen Mitspieler
/ca import <Code> Tabelle aus so einem Code übernehmen
/ca macros für alle Zeilen Makros anlegen
/ca position Anzeige mit der Maus verschieben
/ca anzeige symbol|zahl|balken an|aus
/ca debug zeigt, was erkannt wird]],
},
en = {
zauber = "Requests",
anzeige = "Display",
kanaele = "Own messages that count",
sprache = "Language",
sprache_auto = "automatic", sprache_de = "German", sprache_en = "English",
col_name = "Name", col_spellid = "SpellID", col_symbol = "Icon",
col_phrase = "Whisper text", col_target = "Target", col_dauer = "Duration",
cb_symbol = "Show icon", cb_zahl = "Show number", cb_balken = "Show bar",
cb_whisper = "Whisper", cb_party = "Party", cb_raid = "Raid",
cb_debug = "Debug messages in chat",
slider_size = "Icon size",
btn_macro = "Create macro", btn_new = "+ Add request",
hint_spells = "Icon empty = spell icon · Target = who casts the spell · "
.. "Duration = seconds the buff lasts (0 = do not show at all). × removes the row.",
hilfe_titel = "— commands:",
geladen = "CallAssistance %s loaded — /ca for commands",
makro_angelegt = "macro created (character specific): %s",
kein_platz = "no free macro slot",
ziel_fehlt = "target missing in the row",
phrase_fehlt = "whisper text missing in the row",
test = "Test display running (10 s)",
an = "is ON", aus = "is OFF",
an_kurz = "on", aus_kurz = "off",
unbekannt = "unknown command: %s",
zeile_falsch = "row number missing or wrong: /ca %s <row> <value>",
weg_fehlt = "no such row",
neu_fehlt = "SpellID missing: /ca new <SpellID> [Name]",
neu_gemacht = "added: %s (ID %d) — set the whisper text with /ca phrase %d <text>",
gesetzt = "%s: %s = %s",
treffer = "request detected: %s",
import_ok = "%d request(s) imported — names come from the spell",
import_leer = "code missing: /ca import <SpellID>|<whisper text>|<target>|<duration>;…",
export_kopf = "code to share:",
kein_kampf = "not possible in combat — please do it outside",
position_hinweis = "drag the display here · /ca position to finish",
position_an = "placing: move the display with the mouse, then /ca position to finish",
position_aus = "placing finished",
btn_move = "Move display",
btn_done = "Done",
buff_aus_api = "remaining from buff API: %s",
buff_nicht_lesbar = "buff not readable — counting myself (%.0f s)",
hilfe = [[
/ca config settings (also: Options -> AddOns -> Call Assistance)
/ca test test display, 10 s
/ca an | /ca aus addon on/off
/ca new <SpellID> [Name] add a row to the request table
/ca weg <row> remove a row
/ca phrase <row> <text> set the whisper text
/ca icon <row> <ID> custom icon (0 = spell icon)
/ca ziel <row> <name> who casts the spell
/ca dauer <row> <sec> total duration for the self-countdown
/ca macro <row> create the macro for the row
/ca export code to share with another player
/ca import <code> take over a table from such a code
/ca macros create macros for all rows
/ca position move the display with the mouse
/ca anzeige symbol|zahl|balken an|aus
/ca debug show what is detected]],
},
}
local function spracheWahl()
local quelle = CallAssistanceDB or DB
local wahl = (quelle and quelle.sprache) or "auto"
if wahl == "de" or wahl == "en" then return wahl end
local spiel = GetLocale and GetLocale() or "enUS"
if string.sub(spiel, 1, 2) == "de" then return "de" end
return "en"
end
local function T(schluessel, ...)
local texte = TEXTE[spracheWahl()] or TEXTE.en
local wert = texte[schluessel] or TEXTE.en[schluessel] or schluessel
if select("#", ...) > 0 then
return string.format(wert, ...)
end
return wert
end
-- ---------------------------------------------------------------- Daten
local VORGABEN = {
sprache = "auto",
aktiv = true,
fluestern = true,
gruppe = true,
raid = true,
zeigeSymbol = true,
zeigeZahl = true,
zeigeBalken = true,
groesse = 40,
debug = false,
position = nil, -- {point, x, y}
}
-- Startzeilen der Tabelle (bewusst neutral, jeder pflegt seine Zauber selbst)
local START = {
{ name = "Rescue", spellID = 370665, icon = 0, phrase = "rescue me", ziel = "", dauer = 10 },
}
local DB
-- Einstellungsseite (Definition weiter unten, hier nur vorwaerts deklariert)
local optionenPanel, inhaltFrame, aufbauZaehler = nil, nil, 0
local aufbauen, baueOptionen, oeffneOptionen
local function kopiere(t)
local neu = {}
for k, v in pairs(t) do
neu[k] = type(v) == "table" and kopiere(v) or v
end
return neu
end
local function dbInit()
CallAssistanceDB = CallAssistanceDB or {}
DB = CallAssistanceDB
for k, v in pairs(VORGABEN) do
if DB[k] == nil then
DB[k] = type(v) == "table" and kopiere(v) or v
end
end
if type(DB.posten) ~= "table" or #DB.posten == 0 then
DB.posten = {}
for _, z in ipairs(START) do
table.insert(DB.posten, { name = z.name, spellID = z.spellID, icon = z.icon,
phrase = z.phrase, ziel = z.ziel, dauer = z.dauer })
end
end
if type(DB.naechsteID) ~= "number" then DB.naechsteID = 1 end
for _, e in ipairs(DB.posten) do
if e.name == nil then e.name = "" end
if e.spellID == nil then e.spellID = 0 end
if e.icon == nil then e.icon = 0 end
if e.phrase == nil then e.phrase = "" end
if e.ziel == nil then e.ziel = "" end
if type(e.dauer) ~= "number" then e.dauer = 10 end
if e.id == nil then
e.id = DB.naechsteID
DB.naechsteID = DB.naechsteID + 1
end
end
end
local function istDa()
if not DB then dbInit() end
end
local function normalisiere(text)
if type(text) ~= "string" then return "" end
text = string.lower(text)
text = string.gsub(text, "^%s+", "")
text = string.gsub(text, "%s+$", "")
return text
end
local function kurzName(name)
if type(name) ~= "string" then return "" end
local ohneRealm = string.match(name, "^([^%-]+)")
return string.lower(ohneRealm or name)
end
local function passt(text, posten)
local t = normalisiere(text)
local p = normalisiere(posten.phrase)
if #p == 0 then return false end
return string.find(t, p, 1, true) ~= nil
end
local function istDebug()
return DB and DB.debug
end
local function melde(text, farbe)
if istDebug() then
print((farbe or "|cff8080ff") .. "CallAssistance|r " .. text)
end
end
-- ---------------------------------------------------------------- Anzeige
-- Ein beweglicher Rahmen, darin je Anfrage eine Zeile: Symbol, Zahl darauf, Balken darunter.
local ANZEIGE_BREITE = 220
local anzeige = CreateFrame("Frame", "CallAssistanceAnzeige", UIParent)
anzeige:SetSize(ANZEIGE_BREITE, 60)
anzeige:SetFrameStrata("HIGH")
anzeige:SetClampedToScreen(true)
anzeige:SetMovable(true)
anzeige:EnableMouse(true)
anzeige:RegisterForDrag("LeftButton")
anzeige:SetScript("OnDragStart", anzeige.StartMoving)
anzeige:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local point, _, _, x, y = self:GetPoint()
if DB then DB.position = { point = point, x = x, y = y } end
end)
anzeige:Hide()
-- laufende Anfragen (Liste, damit die Reihenfolge stabil bleibt)
local laufend = {}
local function zeilenBauen()
local groesse = DB.groesse or 40
local abstand = 6
local hoehe = groesse + 12
for i, eintrag in ipairs(laufend) do
local zeile = eintrag.zeile
if not zeile then
zeile = CreateFrame("Frame", nil, anzeige)
zeile.symbol = zeile:CreateTexture(nil, "ARTWORK")
zeile.symbol:SetTexCoord(0.07, 0.93, 0.07, 0.93)
zeile.zahl = zeile:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
zeile.zahl:SetPoint("CENTER", 0, 0)
zeile.zahl:SetJustifyH("CENTER")
if zeile.zahl.SetShadowColor then
zeile.zahl:SetShadowColor(0, 0, 0, 1)
zeile.zahl:SetShadowOffset(1, -1)
end
zeile.balkenHinter = zeile:CreateTexture(nil, "BACKGROUND")
zeile.balkenHinter:SetColorTexture(0, 0, 0, 0.6)
zeile.balken = zeile:CreateTexture(nil, "ARTWORK")
zeile.balken:SetColorTexture(0.2, 1, 0.3, 0.95)
zeile.namensText = zeile:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
zeile.namensText:SetWidth(60)
zeile.namensText:SetJustifyH("LEFT")
eintrag.zeile = zeile
end
local z = eintrag.zeile
z:SetSize(groesse + 70, hoehe)
z:SetPoint("TOPLEFT", anzeige, "TOPLEFT", 0, -(i - 1) * (hoehe + abstand))
z.symbol:SetSize(groesse, groesse)
z.symbol:SetPoint("TOPLEFT", z, "TOPLEFT", 0, 0)
z.symbol:SetShown(DB.zeigeSymbol and true or false)
z.zahl:SetPoint("CENTER", z, "TOPLEFT", groesse / 2, -groesse / 2)
z.zahl:SetShown(DB.zeigeZahl and true or false)
z.balkenHinter:ClearAllPoints()
z.balkenHinter:SetPoint("TOPLEFT", z, "TOPLEFT", 0, -groesse - 2)
z.balkenHinter:SetSize(groesse, 4)
z.balken:ClearAllPoints()
z.balken:SetPoint("TOPLEFT", z, "TOPLEFT", 0, -groesse - 2)
z.balken:SetHeight(4)
z.balkenHinter:SetShown(DB.zeigeBalken and true or false)
z.balken:SetShown(DB.zeigeBalken and true or false)
-- Name rechts neben dem Symbol
z.namensText:SetPoint("LEFT", z.symbol, "RIGHT", 6, 0)
z.namensText:SetText(eintrag.posten.name or "")
z:Show()
end
local anzahl = #laufend
anzeige:SetHeight(math.max(1, anzahl * (hoehe + abstand)))
anzeige:SetWidth(groesse + 70)
if anzahl > 0 then anzeige:Show() else anzeige:Hide() end
end
local function setzePosition()
if not DB then return end
local p = DB.position
anzeige:ClearAllPoints()
if p and p.point then
anzeige:SetPoint(p.point, UIParent, p.point, p.x or 0, p.y or 0)
else
anzeige:SetPoint("CENTER", UIParent, "CENTER", 0, 120)
end
end
-- Positionier-Modus: Anzeige sichtbar machen, damit sie sich mit der Maus verschieben lässt.
local platzFlaeche, platzHinweis, platzKnopf
local platzieren = false
local function setzePlatzieren(an)
if not DB then return end
platzieren = an and true or false
if not platzFlaeche then
platzFlaeche = anzeige:CreateTexture(nil, "BACKGROUND")
platzFlaeche:SetAllPoints()
platzFlaeche:SetColorTexture(0.2, 0.7, 1, 0.25)
platzHinweis = anzeige:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
platzHinweis:SetPoint("BOTTOM", anzeige, "TOP", 0, 4)
end
if platzieren then
if not platzKnopf then
platzKnopf = CreateFrame("Button", "CallAssistanceFertig", UIParent, "UIPanelButtonTemplate")
platzKnopf:SetSize(160, 30)
platzKnopf:SetPoint("CENTER", UIParent, "CENTER", 0, -60)
platzKnopf:SetFrameStrata("DIALOG")
platzKnopf:SetScript("OnClick", function() setzePlatzieren(false) end)
end
platzKnopf:SetText(T("btn_done"))
platzKnopf:Show()
platzHinweis:SetText(T("position_hinweis"))
platzFlaeche:Show()
platzHinweis:Show()
local groesse = DB.groesse or 40
anzeige:SetSize(groesse + 70, groesse + 12)
anzeige:Show()
else
if platzKnopf then platzKnopf:Hide() end
platzFlaeche:Hide()
platzHinweis:Hide()
if #laufend == 0 then anzeige:Hide() end
end
end
-- ---------------------------------------------------------------- Buff lesen
-- Liefert Restsekunden oder nil, wenn (gerade) nicht lesbar / nicht aktiv.
-- 🔴 Im Kampf sperrt WoW Addons den Aura-Zugriff komplett
-- ("Auras cannot be accessed when secret while tainted by ...") — dann gar nicht erst fragen,
-- sondern den Selbst-Countdown laufen lassen.
local function buffRest(posten)
if InCombatLockdown() then return nil end
if not posten.spellID or posten.spellID <= 0 then return nil end
if not C_UnitAuras or not C_UnitAuras.GetPlayerAuraBySpellID then return nil end
local ok, daten = pcall(C_UnitAuras.GetPlayerAuraBySpellID, posten.spellID)
if not ok or not daten then return nil end
local ablauf = daten.expirationTime
if type(ablauf) ~= "number" or ablauf <= 0 then return nil end
local rest = ablauf - GetTime()
if rest <= 0 then return nil end
return rest, daten.duration
end
-- ---------------------------------------------------------------- Anfrage starten
local indexLaufend = {}
local beende
local function formatiere(rest)
if rest >= 60 then
return string.format("%d:%02d", math.floor(rest / 60), math.floor(rest % 60))
end
if rest >= 3 then return string.format("%d", math.floor(rest + 0.5)) end
return string.format("%.1f", math.max(0, rest))
end
local function starte(posten, dauerOverride)
istDa()
local jetzt = GetTime()
local eintrag = indexLaufend[posten.id]
if not eintrag then
eintrag = { posten = posten, start = jetzt }
indexLaufend[posten.id] = eintrag
table.insert(laufend, eintrag)
end
eintrag.start = jetzt
-- Dauer 0 = diese Anfrage soll gar nicht angezeigt werden
local dauer = dauerOverride or posten.dauer
if not dauer or dauer <= 0 then
if indexLaufend[posten.id] then beende(indexLaufend[posten.id]) end
return nil
end
eintrag.dauer = dauer
eintrag.gesamt = eintrag.dauer
eintrag.bis = nil
eintrag.ausApi = false
eintrag.aktiv = true
zeilenBauen()
local icon = posten.icon
local z = eintrag.zeile
if not icon or icon <= 0 then
icon = (posten.spellID and posten.spellID > 0) and C_Spell.GetSpellTexture(posten.spellID) or nil
end
if icon then z.symbol:SetTexture(icon) end
z.namensText:SetText(posten.name or "")
z.zahl:SetText(formatiere(eintrag.dauer))
z.zahl:SetTextColor(1, 1, 1)
z.balken:SetWidth(DB.groesse or 40)
z.balken:SetColorTexture(0.2, 1, 0.3, 0.95)
return eintrag
end
beende = function(eintrag)
indexLaufend[eintrag.posten.id] = nil
for i, e in ipairs(laufend) do
if e == eintrag then
table.remove(laufend, i)
break
end
end
if eintrag.zeile then eintrag.zeile:Hide() end
eintrag.aktiv = false
zeilenBauen()
end
anzeige:SetScript("OnUpdate", function(_, dt)
if #laufend == 0 then return end
local jetzt = GetTime()
for i = #laufend, 1, -1 do
local eintrag = laufend[i]
if eintrag ~= nil then
local rest, buffDauer = buffRest(eintrag.posten)
if rest then
eintrag.rest = rest
eintrag.ausApi = true
if buffDauer and buffDauer > 0 then eintrag.dauer = buffDauer end
eintrag.gesamt = eintrag.gesamt or eintrag.dauer
else
eintrag.ausApi = false
rest = eintrag.dauer - (jetzt - eintrag.start)
eintrag.rest = rest
eintrag.gesamt = eintrag.dauer
end
local z = eintrag.zeile
if z then
if rest <= 0 then
beende(eintrag)
else
z.zahl:SetText(formatiere(rest))
local anteil = 1
if eintrag.gesamt and eintrag.gesamt > 0 then
anteil = math.max(0, math.min(1, rest / eintrag.gesamt))
end
z.balken:SetWidth(math.max(1, (DB.groesse or 40) * anteil))
if rest <= 5 then
z.zahl:SetTextColor(1, 0.35, 0.35)
z.balken:SetColorTexture(1, 0.25, 0.25, 0.95)
else
z.zahl:SetTextColor(1, 1, 1)
z.balken:SetColorTexture(0.2, 1, 0.3, 0.95)
end
-- Symbol bleibt voll sichtbar; im Kampf ist der Buff grundsätzlich
-- nicht abfragbar, ein Hinweis darauf wäre also immer an.
z.symbol:SetDesaturated(false)
z.symbol:SetAlpha(1)
end
end
end
end
end)
-- ---------------------------------------------------------------- Ereignisse
local rahmen = CreateFrame("Frame")
local function istEigeneNachricht(event, absender)
if event == "CHAT_MSG_WHISPER_INFORM" then return true end
local ich = kurzName(UnitName and UnitName("player") or "")
return #ich > 0 and kurzName(absender) == ich
end
local function pruefe(event, text, absender)
istDa()
if not DB.aktiv then return end
if event == "CHAT_MSG_WHISPER_INFORM" and not DB.fluestern then return end
if (event == "CHAT_MSG_PARTY" or event == "CHAT_MSG_PARTY_LEADER") and not DB.gruppe then return end
if (event == "CHAT_MSG_RAID" or event == "CHAT_MSG_RAID_LEADER") and not DB.raid then return end
if event ~= "CHAT_MSG_WHISPER_INFORM" and not istEigeneNachricht(event, absender) then return end
melde("eigene Nachricht: " .. tostring(text), "|cff8080ff")
for _, posten in ipairs(DB.posten) do
-- pcall: im Kampf kann Chat-Text gesperrt sein — dann still weitermachen
local ok, treffer = pcall(passt, text, posten)
if not ok then
melde("Text nicht lesbar (Kampf?): " .. tostring(treffer), "|cffff4040")
return
end
if treffer then
local eintrag = starte(posten)
if not eintrag then return end
melde(T("treffer", posten.name or "?"), "|cff80ff80")
local rest = buffRest(posten)
if rest then
melde(T("buff_aus_api", formatiere(rest)), "|cff80ff80")
else
melde(T("buff_nicht_lesbar", eintrag.dauer), "|cffcccccc")
end
return
end
end
melde("kein Treffer: " .. tostring(text), "|cffcccccc")
end
rahmen:RegisterEvent("PLAYER_LOGIN")
rahmen:RegisterEvent("CHAT_MSG_WHISPER_INFORM")
rahmen:RegisterEvent("CHAT_MSG_PARTY")
rahmen:RegisterEvent("CHAT_MSG_PARTY_LEADER")
rahmen:RegisterEvent("CHAT_MSG_RAID")
rahmen:RegisterEvent("CHAT_MSG_RAID_LEADER")
rahmen:SetScript("OnEvent", function(_, event, arg1, arg2, ...)
if event == "PLAYER_LOGIN" then
dbInit()
if C_ChatInfo and C_ChatInfo.RegisterAddonMessagePrefix then
C_ChatInfo.RegisterAddonMessagePrefix("CALLSPELL")
end
setzePosition()
print("|cff40ff40CallAssistance|r " .. T("geladen", VERSION))
baueOptionen()
return
end
pruefe(event, arg1, arg2)
end)
-- ---------------------------------------------------------------- Makro
local function makroName(posten)
local name = "CA" .. tostring(posten.name or "Call")
if #name > 16 then name = string.sub(name, 1, 16) end
return name
end
local function makroErstellen(posten)
istDa()
if InCombatLockdown() then return end
if not posten.ziel or #posten.ziel == 0 then
print("|cffff8080CallAssistance|r " .. T("ziel_fehlt"))
return
end
if not posten.phrase or #posten.phrase == 0 then
print("|cffff8080CallAssistance|r " .. T("phrase_fehlt"))
return
end
local name = makroName(posten)
local texture = (posten.icon and posten.icon > 0) and posten.icon or nil
if not texture and posten.spellID and posten.spellID > 0 then
texture = C_Spell.GetSpellTexture(posten.spellID)
end
texture = texture or 134400
-- Zweite Zeile startet den Countdown direkt: im Kampf ist der eigene Chattext
-- für Addons gesperrt ("secret string"), das Chat-Ereignis allein reicht dort nicht.
local koerper = string.format("/w %s %s\n/ca start %d", posten.ziel, posten.phrase,
math.floor(posten.spellID or 0))
local index = GetMacroIndexByName and GetMacroIndexByName(name) or 0
if index and index > 0 then
DeleteMacro(index)
end
local neu = CreateMacro(name, texture, koerper, true) -- true = charakterspezifisch
if neu then
print("|cff00ff00CallAssistance|r " .. T("makro_angelegt", name))
else
print("|cffff8080CallAssistance|r " .. T("kein_platz"))
end
end
-- ---------------------------------------------------------------- Export / Import
-- Kompakter Textcode, damit der Mitspieler nichts eintippen muss:
-- <SpellID>|<Flüstertext>|<Ziel>;<SpellID>|<Flüstertext>|<Ziel>
-- Der Name der Anfrage kommt aus dem Zauber (C_Spell.GetSpellInfo), nicht aus dem Code.
local function exportCode()
local teile = {}
for _, p in ipairs(DB.posten) do
local phrase = tostring(p.phrase or ""):gsub("[;|]", " ")
local ziel = tostring(p.ziel or ""):gsub("[;|]", " ")
table.insert(teile, string.format("%d|%s|%s|%d", p.spellID or 0, phrase, ziel,
math.floor(p.dauer or 10)))
end
return table.concat(teile, ";")
end
local function importCode(code)
if type(code) ~= "string" or #code == 0 then return 0 end
-- Trenner tolerant: | ist der Standard, # und , werden ebenfalls akzeptiert
if not string.find(code, "|", 1, true) then
code = string.gsub(code, "#", "|")
code = string.gsub(code, ",", "|")
end
local anzahl = 0
for eintrag in string.gmatch(code, "([^;]+)") do
local felder = {}
for feld in string.gmatch(eintrag .. "|", "([^|]*)|") do
table.insert(felder, feld)
end
local spellID = tonumber(felder[1])
if spellID and spellID > 0 then
local phrase = felder[2] or ""
local ziel = felder[3] or ""
local dauer = tonumber(felder[4])
if dauer then dauer = math.floor(dauer) end
if not dauer or dauer < 0 then dauer = nil end
local name
if C_Spell and C_Spell.GetSpellInfo then
local info = C_Spell.GetSpellInfo(spellID)
if info and info.name then name = info.name end
end
local vorhanden
for _, p in ipairs(DB.posten) do
if p.spellID == spellID then vorhanden = p; break end
end
if vorhanden then
vorhanden.phrase = phrase
vorhanden.ziel = ziel
if dauer then vorhanden.dauer = dauer end
if name and #name > 0 then vorhanden.name = name end
else
DB.naechsteID = (DB.naechsteID or 1) + 1
table.insert(DB.posten, {
id = DB.naechsteID,
name = name or ("Spell " .. tostring(spellID)),
spellID = spellID,
icon = 0,
phrase = phrase,
ziel = ziel,
dauer = dauer or 10,
})
end
anzahl = anzahl + 1
end
end
if optionenPanel and aufbauen then aufbauen() end
-- Makros gleich mit anlegen, damit dem Mitspieler ein Befehl reicht
if not InCombatLockdown() then
for _, posten in ipairs(DB.posten) do
if posten.ziel and #tostring(posten.ziel) > 0
and posten.phrase and #tostring(posten.phrase) > 0 then
makroErstellen(posten)
end
end
end
return anzahl
end
-- ---------------------------------------------------------------- Slash
local function hilfe()
print("|cff40ff40CallAssistance|r " .. T("hilfe_titel") or "—")
print(T("hilfe"))
end
SLASH_CALLASSISTANCE1 = "/ca"
SLASH_CALLASSISTANCE2 = "/callassist"
SlashCmdList["CALLASSISTANCE"] = function(rest)
istDa()
rest = rest or ""
local befehl, arg = rest:match("^(%S*)%s*(.*)$")
befehl = string.lower(befehl or "")
if befehl == "" or befehl == "help" then
hilfe()
elseif befehl == "config" then
oeffneOptionen()
elseif befehl == "an" then
DB.aktiv = true; print("|cff40ff40CallAssistance|r " .. T("an"))
elseif befehl == "aus" then
DB.aktiv = false; print("|cff40ff40CallAssistance|r " .. T("aus"))
elseif befehl == "debug" then
DB.debug = not DB.debug
print("|cff40ff40CallAssistance|r debug: " .. (DB.debug and "an" or "aus"))
elseif befehl == "test" then
local p = DB.posten[1]
if p then
local e = starte(p, 10)
local z = e.zeile
local icon = p.icon > 0 and p.icon or C_Spell.GetSpellTexture(p.spellID)
if icon then z.symbol:SetTexture(icon) end
e.bis = GetTime() + 10
print("|cff40ff40CallAssistance|r " .. T("test"))
end
elseif befehl == "neu" or befehl == "new" then
local id = tonumber(arg:match("^(%d+)"))
local name = arg:match("^%d+%s+(.*)$")
if not id then
print("|cffff8080CallAssistance|r " .. T("neu_fehlt"))
return
end
if not name or #name == 0 then name = T("zauber") end
DB.naechsteID = (DB.naechsteID or 1) + 1
table.insert(DB.posten, { id = DB.naechsteID, name = name, spellID = id, icon = 0,
phrase = "", ziel = "", dauer = 10 })
print("|cff40ff40CallAssistance|r " .. T("neu_gemacht", name, id, #DB.posten))
if optionenPanel then aufbauen() end
elseif befehl == "weg" then
local idx = tonumber(arg)
if not idx or not DB.posten[math.floor(idx)] then
print("|cffff8080CallAssistance|r " .. T("weg_fehlt"))
return
end
local eintrag = DB.posten[math.floor(idx)]
if eintrag and indexLaufend[eintrag.id] then beende(indexLaufend[eintrag.id]) end
table.remove(DB.posten, math.floor(idx))
if optionenPanel then aufbauen() end
elseif befehl == "phrase" or befehl == "ziel" or befehl == "dauer" or befehl == "icon" then
local nr, wert = arg:match("^(%d+)%s*(.-)$")
local posten = nr and DB.posten[math.floor(tonumber(nr))]
if not posten then
print("|cffff8080CallAssistance|r " .. T("zeile_falsch", befehl))
return
end
if befehl == "phrase" then
posten.phrase = wert
elseif befehl == "ziel" then
posten.ziel = wert
elseif befehl == "icon" then
local n = tonumber(wert)
posten.icon = (n and n > 0) and math.floor(n) or 0
elseif befehl == "dauer" then
local n = tonumber(wert)
if n and n >= 0 then posten.dauer = math.floor(n) end
end
print("|cff40ff40CallAssistance|r " .. T("gesetzt", posten.name or "?", befehl, tostring(wert)))
if optionenPanel then aufbauen() end
elseif befehl == "import" then
local anzahl = importCode(arg)
if anzahl == 0 then
print("|cffff8080CallAssistance|r " .. T("import_leer"))
else
print("|cff40ff40CallAssistance|r " .. T("import_ok", anzahl))
end
elseif befehl == "export" then
print("|cff40ff40CallAssistance|r " .. T("export_kopf"))
print(exportCode())
elseif befehl == "position" or befehl == "bewegen" then
setzePlatzieren(not platzieren)
print("|cff40ff40CallAssistance|r " .. (platzieren and T("position_an") or T("position_aus")))
elseif befehl == "start" then
local id = tonumber(arg)
local gefunden
if id then
for _, posten in ipairs(DB.posten) do
if posten.spellID == math.floor(id) then gefunden = posten; break end
end
end
if not gefunden and id then gefunden = DB.posten[math.floor(id)] end
if gefunden then
starte(gefunden)
-- Zusätzlich per Addon-Kanal an den Caster: dort zeigt CallSpell das Symbol,
-- auch im Kampf, wo der Chattext gesperrt ist.
local ziel = gefunden.ziel
if ziel and #tostring(ziel) > 0 and C_ChatInfo and C_ChatInfo.SendAddonMessage then
pcall(C_ChatInfo.SendAddonMessage, "CALLSPELL",
tostring(math.floor(gefunden.spellID or 0)), "WHISPER", ziel)
end
end
elseif befehl == "macros" then
istDa()
if InCombatLockdown() then
print("|cffff8080CallAssistance|r " .. T("kein_kampf"))
return
end
local anzahl = 0
for _, posten in ipairs(DB.posten) do
if posten.ziel and #posten.ziel > 0 then
makroErstellen(posten)
anzahl = anzahl + 1
end
end
if anzahl == 0 then print("|cffff8080CallAssistance|r " .. T("ziel_fehlt")) end
elseif befehl == "macro" then
local idx = tonumber(arg)
local posten = idx and DB.posten[math.floor(idx)]
if not posten then
print("|cffff8080CallAssistance|r " .. T("zeile_falsch", "macro"))
return
end
makroErstellen(posten)
elseif befehl == "anzeige" then
local was, wert = arg:match("^(%S+)%s*(%S*)$")
local felder = { symbol = "zeigeSymbol", zahl = "zeigeZahl", balken = "zeigeBalken" }
local feld = was and felder[string.lower(was)]
if not feld then
print("|cffff8080CallAssistance|r " .. T("unbekannt", tostring(was)))
return
end
DB[feld] = (wert ~= "aus" and wert ~= "off")
zeilenBauen()
print("|cff40ff40CallAssistance|r " .. was .. ": " .. (DB[feld] and "an" or "aus"))
else
print("|cffff8080CallAssistance|r " .. T("unbekannt", befehl))
end
end
-- ---------------------------------------------------------------- Einstellungen (Spiel-Optionen)
local function ueberschrift(eltern, text, y)
local fs = eltern:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
fs:SetPoint("TOPLEFT", eltern, "TOPLEFT", 12, y)
fs:SetText(text)
return fs
end
local function hinweis(eltern, text, y, breite)
local fs = eltern:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
fs:SetPoint("TOPLEFT", eltern, "TOPLEFT", 12, y)
fs:SetWidth(breite or 480)
fs:SetJustifyH("LEFT")
fs:SetText(text)
return fs
end
local function kaestchen(eltern, beschriftung, x, y, lesen, schreiben)
local cb = CreateFrame("CheckButton", nil, eltern, "UICheckButtonTemplate")
cb:SetPoint("TOPLEFT", eltern, "TOPLEFT", x, y)
cb:SetSize(26, 26)
if cb.Text then cb.Text:SetText(beschriftung) end
cb:SetScript("OnClick", function(self) schreiben(self:GetChecked() and true or false) end)
cb.aktualisiere = function() cb:SetChecked(lesen() and true or false) end
cb.aktualisiere()
return cb
end
-- Schlichtes Eingabefeld (kein InputBoxTemplate: das verschiebt den Textbereich)
local function feld(eltern, x, y, breite, lesen, schreiben)
local eb = CreateFrame("EditBox", nil, eltern)
eb:SetSize(breite, 20)
eb:SetPoint("TOPLEFT", eltern, "TOPLEFT", x, y)
eb:SetAutoFocus(false)
eb:SetMaxLetters(80)
eb:SetFontObject(GameFontHighlight)
eb:SetTextColor(1, 1, 1)
eb:SetJustifyH("LEFT")
eb:SetTextInsets(4, 4, 0, 0)
eb:EnableMouse(true)
local bg = eb:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
bg:SetColorTexture(1, 1, 1, 0.08)
eb:SetText(tostring(lesen() or ""))
eb:SetCursorPosition(0)
local function sichern(self) schreiben(self:GetText() or "") end
eb:SetScript("OnEnterPressed", function(self) sichern(self); self:ClearFocus() end)
eb:SetScript("OnEditFocusLost", sichern)
eb:SetScript("OnEscapePressed", function(self) self:SetText(tostring(lesen() or "")); self:ClearFocus() end)
eb.aktualisiere = function() eb:SetText(tostring(lesen() or "")) end
return eb
end
-- Spalten: Name, SpellID, Symbol, Fluestertext, Ziel, Dauer | Macro | ×
local SPALTEN = { { "col_name", 8, 70 }, { "col_spellid", 82, 56 }, { "col_symbol", 142, 56 },
{ "col_phrase", 202, 86 }, { "col_target", 292, 76 }, { "col_dauer", 372, 40 } }
aufbauen = function()
if inhaltFrame then
inhaltFrame:Hide()
inhaltFrame = nil
end
aufbauZaehler = aufbauZaehler + 1
local c = CreateFrame("Frame", nil, optionenPanel)
c:SetAllPoints(optionenPanel)
inhaltFrame = c
local y = -16
-- ---------------- Anfrage-Tabelle
ueberschrift(c, T("zauber"), y)
y = y - 30
for _, spalte in ipairs(SPALTEN) do
local fs = c:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
fs:SetPoint("TOPLEFT", c, "TOPLEFT", spalte[2], y)
fs:SetText(T(spalte[1]))
end
local linie = c:CreateTexture(nil, "ARTWORK")
linie:SetColorTexture(1, 1, 1, 0.15)
linie:SetPoint("TOPLEFT", c, "TOPLEFT", 12, y - 14)
linie:SetSize(596, 1)
local felder = {}
local zeilenY = y - 22
for i, posten in ipairs(DB.posten) do
local idx = i -- eigene Kopie je Zeile (Lua 5.1 teilt die Laufvariable)
local zy = zeilenY - (i - 1) * 28
felder[i] = {
name = feld(c, 8, zy, 70,
function() return DB.posten[idx] and DB.posten[idx].name end,
function(t) local e = DB.posten[idx]; if e and #t > 0 then e.name = t end end),
spellID = feld(c, 82, zy, 56,
function() local e = DB.posten[idx]; return e and tostring(e.spellID) end,
function(t) local e = DB.posten[idx]; local n = tonumber(t)
if e and n and n > 0 then e.spellID = math.floor(n) end end),
icon = feld(c, 142, zy, 56,
function() local e = DB.posten[idx]; return (e and e.icon and e.icon > 0) and tostring(e.icon) or "" end,
function(t) local e = DB.posten[idx]; local n = tonumber(t)
if e then e.icon = (n and n > 0) and math.floor(n) or 0 end end),
phrase = feld(c, 202, zy, 86,
function() local e = DB.posten[idx]; return e and e.phrase end,
function(t) local e = DB.posten[idx]; if e then e.phrase = t end end),
ziel = feld(c, 292, zy, 76,
function() local e = DB.posten[idx]; return e and e.ziel end,
function(t) local e = DB.posten[idx]; if e then e.ziel = t end end),
dauer = feld(c, 372, zy, 40,
function() local e = DB.posten[idx]; return e and tostring(e.dauer) end,
function(t) local e = DB.posten[idx]; local n = tonumber(t)
if e and n and n >= 0 then e.dauer = math.floor(n) end end),
}
local makro = CreateFrame("Button", nil, c, "UIPanelButtonTemplate")
makro:SetSize(104, 20)
makro:SetPoint("TOPLEFT", c, "TOPLEFT", 418, zy)
makro:SetText(T("btn_macro"))
makro:SetScript("OnClick", function() makroErstellen(DB.posten[idx]) end)
felder[i].makro = makro
local weg = CreateFrame("Button", nil, c, "UIPanelButtonTemplate")
weg:SetSize(18, 18)
weg:SetPoint("TOPLEFT", c, "TOPLEFT", 534, zy + 1)
weg:SetText("×")
weg:SetScript("OnClick", function()
local eintrag = DB.posten[idx]
if eintrag and indexLaufend[eintrag.id] then beende(indexLaufend[eintrag.id]) end
table.remove(DB.posten, idx)
aufbauen()
end)
felder[i].weg = weg
end
y = zeilenY - math.max(1, #DB.posten) * 28 - 6
local neuerKnopf = CreateFrame("Button", nil, c, "UIPanelButtonTemplate")
neuerKnopf:SetSize(170, 22)
neuerKnopf:SetPoint("TOPLEFT", c, "TOPLEFT", 12, y)
neuerKnopf:SetText(T("btn_new"))
neuerKnopf:SetScript("OnClick", function()
DB.naechsteID = (DB.naechsteID or 1) + 1
table.insert(DB.posten, { id = DB.naechsteID, name = T("zauber"), spellID = 0,
icon = 0, phrase = "", ziel = "", dauer = 10 })
aufbauen()
end)