/
init.lua
1728 lines (1672 loc) · 56.2 KB
/
init.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
--[[
Created by Special.Ed
Shout out to the homies:
Lads
Dannuic (my on again off again thing)
Knightly (no, i won't take that bet)
--]]
--[[
Modified by Grimmier
Added a GUI and commands.
** Commands **
* /am show will toggle the search window.
* /am popup will toggle the alert popup window.
** Search Window **
* You can search with the search box
* Clicking the check box for track, and the spawn will be added to spawnlist
* Clicking ignore will remove the spawn from the list if it exists.
* you can navTo any spawn in the search window by clicking the button, rightclicking the name will target the spawn.
** Alert Window **
* The Alert Popup Window lists the spawns that you are tracking and are alive. Shown as "Name : Distance"
* Clicking the button on the Alert Window will NavTo the spawn.
* Closing the Alert Popup will keep it closed until something changes or your remind timer is up.
* remind setting is in minutes.
]]
local LIP = require('lib/LIP')
require('lib/ed/utils')
--- @type Mq
local mq = require('mq')
--- @type ImGui
require('ImGui')
Icons = require('mq.ICONS')
local COLOR = require('color.colors')
-- Variables
local arg = {...}
local amVer = '1.87'
local CMD = mq.cmd
local TLO = mq.TLO
local Me = TLO.Me
local SpawnCount = TLO.SpawnCount
local NearestSpawn = TLO.NearestSpawn
local Group = TLO.Group
local Raid = TLO.Raid
local Zone = TLO.Zone
local groupCmd = '/dgae ' -- assumes DanNet, if EQBC found we switch to '/bcca /'
local angle = 0
local CharConfig = 'Char_'..Me.DisplayName()..'_Config'
local CharCommands = 'Char_'..Me.DisplayName()..'_Commands'
local defaultConfig = { delay = 1,remindNPC=5, remind = 30, aggro = false, pcs = true, spawns = true, gms = true, announce = false, ignoreguild = true , beep = false, popup = false, distmid = 600, distfar = 1200, locked = false}
local tSafeZones, spawnAlerts = {}, {}
local alertTime, numAlerts = 0,0
local doBeep, doAlert, DoDrawArrow = false, false, false
-- [[ UI ]] --
local AlertWindow_Show, AlertWindowOpen, SearchWindowOpen, SearchWindow_Show, showTooltips= false, false, false, false, true
local currentTab = "zone"
local newSpawnName = ''
local zSettings = false
local theme = require('themes/themes')
local useThemeName = 'Default'
local openConfigGUI = false
local themeFile = mq.configDir .. '/MyThemeZ.lua'
local ZoomLvl = 1.0
local ColorCountAlert, ColorCountConf, ColorCount = 0, 0, 0
---@class
local DistColorRanges = {
orange = 600, -- distance the color changes from green to orange
red = 1200, -- distance the color changes from orange to red
}
local Table_Cache = {
Rules = {},
Unhandled = {},
Mobs = {},
}
local xTarTable = {}
local alertFlags = bit32.bor(ImGuiWindowFlags.NoCollapse)
local spawnListFlags = bit32.bor(
ImGuiTableFlags.Resizable,
ImGuiTableFlags.Sortable,
ImGuiTableFlags.SizingFixedFit,
ImGuiTableFlags.BordersV,
ImGuiTableFlags.BordersOuter,
ImGuiTableFlags.Reorderable,
ImGuiTableFlags.ScrollY,
ImGuiTableFlags.ScrollX,
ImGuiTableFlags.Hideable
)
local GUI_Main = {
Open = false,
Show = false,
Locked = false,
Flags = bit32.bor(
ImGuiWindowFlags.None
--ImGuiWindowFlags.NoSavedSettings
),
Refresh = {
Sort = {
Rules = true,
Filtered = true,
Unhandled = true,
Mobs = false,
},
Table = {
Rules = true,
Filtered = true,
Unhandled = true,
Mobs = false,
},
},
Search = '',
Table = {
Column_ID = {
ID = 1,
MobName = 2,
MobDirtyName = 3,
MobLoc = 4,
MobZoneName = 5,
MobDist = 6,
MobID = 7,
Action = 8,
Remove = 9,
MobLvl = 10,
MobConColor = 11,
MobAggro = 12,
MobDirection = 13,
Enum_Action = 14
},
Flags = bit32.bor(
ImGuiTableFlags.Resizable,
ImGuiTableFlags.Sortable,
--ImGuiTableFlags.RowBg,
--ImGuiTableFlags.NoKeepColumnsVisible,
--ImGuiTableFlags.SizingFixedFit,
-- ImGuiTableFlags.MultiSortable, -- MultiSort seems to not work at all.
ImGuiTableFlags.NoBordersInBodyUntilResize,
--ImGuiTableFlags.BordersOuter,
ImGuiTableFlags.Reorderable,
ImGuiTableFlags.ScrollY,
ImGuiTableFlags.ScrollX,
ImGuiTableFlags.Hideable
),
SortSpecs = {
Rules = nil,
Unhandled = nil,
Filtered = nil,
Mobs = nil,
},
},
}
-- helpers
local MsgPrefix = function() return string.format('\aw[%s] [\a-tAlert Master\aw] ::\ax ', mq.TLO.Time()) end
local GetCharZone = function()
return '\aw[\ao'..Me.DisplayName()..'\aw] [\at'..Zone.ShortName():lower()..'\aw] '
end
---comment Check to see if the file we want to work on exists.
---@param name string -- Full Path to file
---@return boolean -- returns true if the file exists and false otherwise
function File_Exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
local print_ts = function(msg) print(MsgPrefix()..msg) end
local function print_status()
print_ts('\ayAlert Status: '..tostring(active and 'on' or 'off'))
print_ts('\a-tPCs: \a-y'..tostring(pcs)..'\ax radius: \a-y'..tostring(radius)..'\ax zradius: \a-y'..tostring(zradius)..'\ax delay: \a-y'..tostring(delay)..'s\ax remind: \a-y'..tostring(remind)..' seconds\ax')
print_ts('\a-tremindNPC: \a-y'..tostring(remindNPC)..'\at minutes\ax')
print_ts('\agClose Range\a-t Below: \a-g'..tostring(DistColorRanges.orange)..'\ax')
print_ts('\aoMid Range\a-t Between: \a-g'..tostring(DistColorRanges.orange)..'\a-t and \a-r'..tostring(DistColorRanges.red)..'\ax')
print_ts('\arLong Rage\a-t Greater than: \a-r'..tostring(DistColorRanges.red)..'\ax')
print_ts('\a-tAnnounce PCs: \a-y'..tostring(announce)..'\ax')
print_ts('\a-tSpawns (zone wide): \a-y'..tostring(spawns)..'\ax')
print_ts('\a-tGMs (zone wide): \a-y'..tostring(gms)..'\ax')
print_ts('\a-tPopup Alerts: \a-y'..tostring(doAlert)..'\ax')
print_ts('\a-tBeep: \a-y'..tostring(doBeep)..'\ax')
end
local save_settings = function()
LIP.save(settings_path, settings)
end
local check_safe_zone = function()
return tSafeZones[Zone.ShortName():lower()]
end
local load_settings = function()
config_dir = TLO.MacroQuest.Path():gsub('\\', '/')
settings_file = '/config/AlertMaster.ini'
settings_path = config_dir..settings_file
if File_Exists(settings_path) then
settings = LIP.load(settings_path)
else
settings = {
[CharConfig] = defaultConfig,
[CharCommands] = {},
Ignore = {}
}
save_settings()
end
if File_Exists(themeFile) then
theme = dofile(themeFile)
end
useThemeName = theme.LoadTheme
-- if this character doesn't have the sections in the ini, create them
if settings[CharConfig] == nil then settings[CharConfig] = defaultConfig end
if settings[CharCommands] == nil then settings[CharCommands] = {} end
if settings['SafeZones'] == nil then settings['SafeZones'] = {} end
useThemeName = settings[CharConfig]['theme'] or 'Default'
settings[CharConfig]['theme'] = useThemeName
ZoomLvl = settings[CharConfig]['ZoomLvl'] or 1.0
settings[CharConfig]['ZoomLvl'] = ZoomLvl
delay = settings[CharConfig]['delay']
remind = settings[CharConfig]['remind']
pcs = settings[CharConfig]['pcs']
spawns = settings[CharConfig]['spawns']
gms = settings[CharConfig]['gms']
announce = settings[CharConfig]['announce']
ignoreguild = settings[CharConfig]['ignoreguild']
radius = settings[CharConfig]['radius'] or radius
settings[CharConfig]['radius'] = radius
zradius = settings[CharConfig]['zradius'] or zradius
settings[CharConfig]['zradius'] = zradius
remindNPC = settings[CharConfig]['remindNPC'] or 5
settings[CharConfig]['remindNPC'] = remindNPC
doBeep = settings[CharConfig]['beep'] or false
settings[CharConfig]['beep'] = doBeep
DoDrawArrow = settings[CharConfig]['arrows'] or false
settings[CharConfig]['arrows'] = DoDrawArrow
GUI_Main.Locked = settings[CharConfig]['locked'] or false
settings[CharConfig]['locked'] = GUI_Main.Locked
doAlert = settings[CharConfig]['popup'] or false
settings[CharConfig]['popup'] = doAlert
showAggro = settings[CharConfig]['aggro'] or false
settings[CharConfig]['aggro'] = showAggro
DistColorRanges.orange = settings[CharConfig]['distmid'] or 600
settings[CharConfig]['distmid'] = DistColorRanges.orange
DistColorRanges.red = settings[CharConfig]['distfar'] or 1200
settings[CharConfig]['distfar'] = DistColorRanges.red
save_settings()
if GUI_Main.Locked then
SearchWindow_Show = true
SearchWindowOpen = true
else
SearchWindow_Show = false
SearchWindowOpen = false
end
-- setup safe zone "set"
for k, v in pairs(settings['SafeZones']) do tSafeZones[v] = true end
end
local function ColorDistance(distance)
if distance < DistColorRanges.orange then
-- Green color for Close Range
return COLOR.color('green')
elseif distance >= DistColorRanges.orange and distance <= DistColorRanges.red then
-- Orange color for Mid Range
return COLOR.color('orange')
else
-- Red color for Far Distance
return COLOR.color('red')
end
end
local function isSpawnInAlerts(spawnName, spawnAlerts)
for _, spawnData in pairs(spawnAlerts) do
if spawnData.DisplayName() == spawnName or spawnData.Name() == spawnName then
return true
end
end
return false
end
---@param spawn MQSpawn
local function SpawnToEntry(spawn, id, table)
local pAggro = 0
if table == xTarTable then
pAggro = tonumber(spawn.PctAggro() or 0)
end
if spawn.ID() then
local entry = {
ID = id or 0,
MobName = spawn.DisplayName() or ' ',
MobDirtyName = spawn.Name() or ' ',
MobZoneName = mq.TLO.Zone.Name()or ' ',
MobDist = math.floor(spawn.Distance() or 0),
MobLoc = spawn.Loc() or ' ',
MobID = spawn.ID()or 0,
MobLvl = spawn.Level()or 0,
MobConColor = string.lower(spawn.ConColor() or 'white'),
MobAggro = pAggro,
MobDirection = spawn.HeadingTo() or '0',
Enum_Action = 'unhandled',
}
return entry
else
return
end
end
---@param spawn MQSpawn
local function InsertTableSpawn(dataTable, spawn, id, opts)
if spawn then
local entry = SpawnToEntry(spawn, id, dataTable)
if opts then
for k,v in pairs(opts) do
entry[k] = v
end
end
table.insert(dataTable, entry)
end
end
local function TableSortSpecs(a, b)
for i = 1, GUI_Main.Table.SortSpecs.SpecsCount do
local spec = GUI_Main.Table.SortSpecs:Specs(i)
local delta = 0
if spec.ColumnUserID == GUI_Main.Table.Column_ID.MobName then
if a.MobName and b.MobName then
if a.MobName < b.MobName then
delta = -1
elseif a.MobName> b.MobName then
delta = 1
end
else
return 0
end
elseif spec.ColumnUserID == GUI_Main.Table.Column_ID.MobID then
if a.MobID and b.MobID then
if a.MobID < b.MobID then
delta = -1
elseif a.MobID > b.MobID then
delta = 1
end
else
return 0
end
elseif spec.ColumnUserID == GUI_Main.Table.Column_ID.MobLvl then
if a.MobLvl and b.MobLvl then
if a.MobLvl < b.MobLvl then
delta = -1
elseif a.MobLvl > b.MobLvl then
delta = 1
end
else
return 0
end
elseif spec.ColumnUserID == GUI_Main.Table.Column_ID.MobDist then
if a.MobDist and b.MobDist then
if a.MobDist < b.MobDist then
delta = -1
elseif a.MobDist > b.MobDist then
delta = 1
end
else
return 0
end
elseif spec.ColumnUserID == GUI_Main.Table.Column_ID.MobAggro then
if a.MobAggro and b.MobAggro then
if a.MobAggro < b.MobAggro then
delta = -1
elseif a.MobAggro > b.MobAggro then
delta = 1
end
else
return 0
end
elseif spec.ColumnUserID == GUI_Main.Table.Column_ID.Action then
if a.Enum_Action < b.Enum_Action then
delta = -1
elseif a.Enum_Action > b.Enum_Action then
delta = 1
end
end
if delta ~= 0 then
if spec.SortDirection == ImGuiSortDirection.Ascending then
return delta < 0
else
return delta > 0
end
end
end
return a.MobName < b.MobName
end
local function RefreshUnhandled()
local splitSearch = {}
for part in string.gmatch(GUI_Main.Search, '[^%s]+') do
table.insert(splitSearch, part)
end
local newTable = {}
for k,v in ipairs(Table_Cache.Rules) do
local found = 0
for _,search in ipairs(splitSearch) do
if string.find(string.lower(v.MobName), string.lower(search)) then found = found + 1 end
if string.find(v.MobDirtyName, search) then found = found + 1 end
end
if #splitSearch == found then table.insert(newTable, v) end
end
Table_Cache.Unhandled = newTable
GUI_Main.Refresh.Sort.Rules = true
GUI_Main.Refresh.Table.Unhandled = true
end
local function RefreshZone()
local newTable = {}
xTarTable = {}
local npcs = mq.getFilteredSpawns(function(spawn) return spawn.Type() == 'NPC' end)
for i = 1, #npcs do
local spawn = npcs[i]
if #npcs>0 then InsertTableSpawn(newTable, spawn, tonumber(spawn.ID())) end
end
for i = 1, mq.TLO.Me.XTargetSlots() do
if mq.TLO.Me.XTarget(i)()~=nil and mq.TLO.Me.XTarget(i)() ~= 0 then
local spawn = mq.TLO.Me.XTarget(i)
if spawn.ID()>0 then InsertTableSpawn(xTarTable, spawn, tonumber(spawn.ID())) end
end
end
if showAggro then
for _, xTarEntry in ipairs(xTarTable) do
-- Check if xTarEntry already exists in newTable
local found = false
for j, newEntry in ipairs(newTable) do
if newEntry.MobID == xTarEntry.MobID then
-- Update newTable entry with xTarEntry data
newTable[j]['MobAggro'] = xTarEntry['MobAggro']
break
end
end
end
end
Table_Cache.Rules = newTable
Table_Cache.Mobs = newTable
GUI_Main.Refresh.Sort.Mobs = true
GUI_Main.Refresh.Table.Mobs = false
end
-----------------------
local function directions(heading)
-- convert headings from letter values to degrees
local dirToDeg = {
N = 0,
NEN = 22.5,
NE = 45,
ENE = 67.5,
E = 90,
ESE = 112.5,
SE = 135,
SES = 157.5,
S = 180,
SWS = 202.5,
SW = 225,
WSW = 247.5,
W = 270,
WNW = 292.5,
NW = 315,
NWN = 337.5
}
return dirToDeg[heading] or 0 -- Returns the degree value for the given direction, defaulting to 0 if not found
end
-- Tighter relative direction code for when I make better arrows.
local function getRelativeDirection(spawnDir)
local meHeading = directions(mq.TLO.Me.Heading())
local spawnHeadingTo = directions(spawnDir)
local difference = spawnHeadingTo - meHeading
difference = (difference + 360) % 360
return difference
end
function RotatePoint(p, cx, cy, angle)
local radians = math.rad(angle)
local cosA = math.cos(radians)
local sinA = math.sin(radians)
local newX = cosA * (p.x - cx) - sinA * (p.y - cy) + cx
local newY = sinA * (p.x - cx) + cosA * (p.y - cy) + cy
return ImVec2(newX, newY)
end
function DrawArrow(topPoint, width, height, color)
local draw_list = ImGui.GetWindowDrawList()
local p1 = ImVec2(topPoint.x, topPoint.y)
local p2 = ImVec2(topPoint.x + width, topPoint.y + height)
local p3 = ImVec2(topPoint.x - width, topPoint.y + height)
-- center
local center_x = (p1.x + p2.x + p3.x) / 3
local center_y = (p1.y + p2.y + p3.y) / 3
-- rotate
angle = angle + .01
p1 = RotatePoint(p1, center_x, center_y, angle)
p2 = RotatePoint(p2, center_x, center_y, angle)
p3 = RotatePoint(p3, center_x, center_y, angle)
draw_list:AddTriangleFilled(p1, p2, p3, ImGui.GetColorU32(color))
end
----------------------------
---comment
---@param counter integer -- the counter used for this window to keep track of color changes
---@param themeName string -- name of the theme to load form table
---@return integer -- returns the new counter value
local function DrawTheme(counter, themeName)
-- Push Theme Colors
for tID, tData in pairs(theme.Theme) do
if tData.Name == themeName then
for pID, cData in pairs(theme.Theme[tID].Color) do
ImGui.PushStyleColor(pID, ImVec4(cData.Color[1], cData.Color[2], cData.Color[3], cData.Color[4]))
counter = counter +1
end
end
end
return counter
end
local function DrawToggles()
local lockedIcon = GUI_Main.Locked and Icons.FA_LOCK .. '##lockTabButton' or
Icons.FA_UNLOCK .. '##lockTablButton'
if ImGui.Button(lockedIcon) then
--ImGuiWindowFlags.NoMove
GUI_Main.Locked = not GUI_Main.Locked
settings[CharConfig]['locked'] = GUI_Main.Locked
save_settings()
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Lock Window")
ImGui.EndTooltip()
end
ImGui.SameLine()
local gIcon = Icons.MD_SETTINGS
if ImGui.Button(gIcon) then
openConfigGUI = not openConfigGUI
save_settings()
--mq.pickle(themeFile, theme)
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Config")
ImGui.EndTooltip()
end
ImGui.SameLine()
-- Alert Popup Toggle Button
if doAlert then
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_green')) -- Green for enabled
if ImGui.Button(Icons.MD_ALARM) then CMD('/am doalert') end
ImGui.PopStyleColor(1)
else
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_red')) -- Red for disabled
if ImGui.Button(Icons.MD_ALARM_OFF) then CMD('/am doalert') end
ImGui.PopStyleColor(1)
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Toggle Popup Alerts On\\Off")
ImGui.EndTooltip()
end
ImGui.SameLine()
-- Beep Alert Toggle Button
if doBeep then
ImGui.PushStyleColor(ImGuiCol.Button,COLOR.color('btn_green')) -- Green for enabled
if ImGui.Button(Icons.FA_BELL_O) then CMD('/am beep') end
ImGui.PopStyleColor(1)
else
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_red')) -- Red for disabled
if ImGui.Button(Icons.FA_BELL_SLASH_O) then CMD('/am beep') end
ImGui.PopStyleColor(1)
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Toggle Beep Alerts On\\Off")
ImGui.EndTooltip()
end
ImGui.SameLine()
-- Alert Window Toggle Button
if AlertWindowOpen then
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_green')) -- Green for enabled
if ImGui.Button(Icons.MD_VISIBILITY) then CMD('/am popup') end
ImGui.PopStyleColor(1)
else
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_red')) -- Red for inactive state
if ImGui.Button(Icons.MD_VISIBILITY_OFF) then CMD('/am popup') end
ImGui.PopStyleColor(1)
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Show\\Hide Alert Window")
ImGui.EndTooltip()
end
ImGui.SameLine()
-- Button to add the new spawn
if ImGui.Button(Icons.FA_HASHTAG) then
CMD('/am spawnadd ${Target}')
npcs = settings[Zone.ShortName()] or {}
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Add Target #Dirty_Name0 to SpawnList")
ImGui.EndTooltip()
end
ImGui.SameLine()
-- Button to add the new spawn
if ImGui.Button(Icons.FA_BULLSEYE) then
CMD('/am spawnadd "${Target.DisplayName}"')
npcs = settings[Zone.ShortName()] or {}
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Add Target Clean Name to SpawnList\nThis is handy if you are hunting a specific type of Mob,\ntarget a moss snake and add, you will get all \"a moss snake\"")
ImGui.EndTooltip()
end
ImGui.SameLine(ImGui.GetWindowWidth() - 120)
-- Arrow Status Toggle Button
if DoDrawArrow then
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_green')) -- Green for enabled
if ImGui.Button(Icons.FA_ARROW_UP) then DoDrawArrow, settings[CharConfig]['arrows'] = false, false save_settings() end
ImGui.PopStyleColor(1)
else
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_red')) -- Red for disabled
if ImGui.Button(Icons.FA_ARROW_DOWN) then DoDrawArrow, settings[CharConfig]['arrows'] = true,true save_settings() end
ImGui.PopStyleColor(1)
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Toggle Drawing Arrows On\\Off")
ImGui.EndTooltip()
end
ImGui.SameLine(ImGui.GetWindowWidth() - 90)
-- Aggro Status Toggle Button
if showAggro then
ImGui.PushStyleColor(ImGuiCol.Button,COLOR.color('btn_green')) -- Green for enabled
if ImGui.Button(Icons.MD_PRIORITY_HIGH) then CMD('/am aggro') end
ImGui.PopStyleColor(1)
else
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_red')) -- Red for disabled
if ImGui.Button(Icons.MD_PRIORITY_HIGH) then CMD('/am aggro') end
ImGui.PopStyleColor(1)
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Toggle Aggro Status On\\Off")
ImGui.EndTooltip()
end
ImGui.SameLine(ImGui.GetWindowWidth() - 60)
-- Alert Master Scanning Toggle Button
if active then
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_green')) -- Green for enabled
if ImGui.Button(Icons.FA_HEARTBEAT) then CMD('/am off') end
ImGui.PopStyleColor(1)
else
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_red')) -- Red for disabled
if ImGui.Button(Icons.MD_DO_NOT_DISTURB) then CMD('/am on') end
ImGui.PopStyleColor(1)
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Toggle ALL Scanning and Alerts On\\Off")
ImGui.EndTooltip()
end
ImGui.SameLine()
-- Place a help icon
ImGui.SameLine(ImGui.GetWindowWidth() - 30) -- Position at right end of line.
if showTooltips then
ImGui.Text(Icons.MD_HELP)
else
ImGui.Text(Icons.MD_HELP_OUTLINE)
end
if ImGui.IsItemHovered() then
ImGui.SetTooltip("Right-Click.\nTo toggle Tooltips.")
if ImGui.IsMouseReleased(0) or ImGui.IsMouseReleased(1) then showTooltips = not showTooltips end
end
end
local function DrawRuleRow(entry)
ImGui.TableNextColumn()
-- Add to Spawn List Button
if ImGui.SmallButton(Icons.FA_USER_PLUS) then CMD('/am spawnadd "'..entry.MobName..'"') end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Add to Spawn List")
ImGui.EndTooltip()
end
ImGui.TableNextColumn()
-- Mob Name
ImGui.Text('%s', entry.MobName)
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Right-Click to Navigate\nCtrl+Right-Click Group Nav")
ImGui.EndTooltip()
end
-- Right-click interaction uses the original spawnName
if ImGui.IsItemHovered() then
if ImGui.IsKeyDown(ImGuiMod.Ctrl) and ImGui.IsMouseReleased(1) then
mq.cmdf("/noparse %s/docommand /timed ${Math.Rand[5,25]} /nav id %s",groupCmd,entry.MobID)
elseif
ImGui.IsMouseReleased(1) then
mq.cmdf('/nav id %s',entry.MobID)
end
end
ImGui.SameLine()
ImGui.TableNextColumn()
--Consider Color for Level Text
ImGui.PushStyleColor(ImGuiCol.Text,COLOR.color(entry.MobConColor))
ImGui.Text('%s', (entry.MobLvl))
ImGui.PopStyleColor()
ImGui.TableNextColumn()
--Distance
local distance = math.floor(entry.MobDist or 0)
ImGui.PushStyleColor(ImGuiCol.Text,ColorDistance(distance))
ImGui.Text(tostring(distance))
ImGui.PopStyleColor()
ImGui.TableNextColumn()
--Mob Aggro
if entry.MobAggro ~= 0 then
local pctAggro = tonumber(entry.MobAggro)/100
ImGui.PushStyleColor(ImGuiCol.PlotHistogram,COLOR.color('red'))
ImGui.ProgressBar(pctAggro, ImGui.GetColumnWidth(), 15)
ImGui.PopStyleColor()
else
end
ImGui.TableNextColumn()
--Mob ID
ImGui.Text('%s', (entry.MobID))
ImGui.TableNextColumn()
--Mob Loc
ImGui.Text('%s', (entry.MobLoc))
ImGui.TableNextColumn()
--Mob Direction
if DoDrawArrow then
angle = getRelativeDirection(entry.MobDirection) or 0
local cursorScreenPos = ImGui.GetCursorScreenPosVec()
DrawArrow(ImVec2(cursorScreenPos.x + 10, cursorScreenPos.y), 5, 15, ColorDistance(distance))
end
ImGui.SetWindowFontScale(1)
ImGui.TableNextColumn()
end
local function DrawSearchWindow()
if mq.TLO.Me.Zoning() then return end
if GUI_Main.Locked then
GUI_Main.Flags = bit32.bor(GUI_Main.Flags, ImGuiWindowFlags.NoMove, ImGuiWindowFlags.NoResize)
else
GUI_Main.Flags = bit32.band(GUI_Main.Flags, bit32.bnot(ImGuiWindowFlags.NoMove), bit32.bnot(ImGuiWindowFlags.NoResize))
end
if SearchWindowOpen then
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 5)
ColorCount = 0
ColorCount = DrawTheme(ColorCount, useThemeName)
SearchWindowOpen = ImGui.Begin("Alert Master##"..mq.TLO.Me.DisplayName(), SearchWindowOpen, GUI_Main.Flags)
ImGui.SetWindowFontScale(ZoomLvl)
DrawToggles()
--ImGui.SameLine()
ImGui.Separator()
-- next row
if ImGui.Button(Zone.Name(), 160,22) then
currentTab = "zone"
RefreshZone()
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Zone Short Name: %s\nSpawn Count: %s",Zone.ShortName(),tostring(#Table_Cache.Unhandled))
ImGui.EndTooltip()
end
ImGui.SameLine()
local tabLabel = "NPC List"
if next(spawnAlerts) ~= nil then
tabLabel = Icons.FA_BULLHORN .. " NPC List " .. Icons.FA_BULLHORN
ImGui.PushStyleColor(ImGuiCol.Button, COLOR.color('btn_red'))
if ImGui.Button(tabLabel) then
currentTab = "npcList"
end
ImGui.PopStyleColor(1)
else
ImGui.PushStyleColor(ImGuiCol.Button, 0.2, 0.4, 0.8, 0.4)
if ImGui.Button(tabLabel) then
currentTab = "npcList"
end
ImGui.PopStyleColor(1)
end
if currentTab == "zone" then
local searchText, selected = ImGui.InputText("Search##RulesSearch", GUI_Main.Search)
-- ImGui.PopItemWidth()
if selected and GUI_Main.Search ~= searchText then
GUI_Main.Search = searchText
GUI_Main.Refresh.Sort.Rules = true
GUI_Main.Refresh.Table.Unhandled = true
end
ImGui.SameLine()
if ImGui.Button("Clear##ClearRulesSearch") then
GUI_Main.Search = ''
GUI_Main.Refresh.Sort.Rules = false
GUI_Main.Refresh.Table.Unhandled = true
end
ImGui.Separator()
if ImGui.BeginTable('##RulesTable', 8, GUI_Main.Table.Flags) then
ImGui.TableSetupScrollFreeze(0, 1)
ImGui.TableSetupColumn(Icons.FA_USER_PLUS, ImGuiTableColumnFlags.NoSort, 15, GUI_Main.Table.Column_ID.Remove)
ImGui.TableSetupColumn("Name", ImGuiTableColumnFlags.DefaultSort, 120, GUI_Main.Table.Column_ID.MobName)
ImGui.TableSetupColumn("Lvl", ImGuiTableColumnFlags.DefaultSort, 30, GUI_Main.Table.Column_ID.MobLvl)
ImGui.TableSetupColumn("Dist", ImGuiTableColumnFlags.DefaultSort, 40, GUI_Main.Table.Column_ID.MobDist)
ImGui.TableSetupColumn("Aggro", ImGuiTableColumnFlags.DefaultSort, 30, GUI_Main.Table.Column_ID.MobAggro)
ImGui.TableSetupColumn("ID", ImGuiTableColumnFlags.DefaultSort, 30, GUI_Main.Table.Column_ID.MobID)
ImGui.TableSetupColumn("Loc", ImGuiTableColumnFlags.NoSort, 90, GUI_Main.Table.Column_ID.MobLoc)
ImGui.TableSetupColumn(Icons.FA_COMPASS, ImGuiTableColumnFlags.NoSort, 15, GUI_Main.Table.Column_ID.MobDirection)
ImGui.TableHeadersRow()
local sortSpecs = ImGui.TableGetSortSpecs()
if not TLO.Me.Zoning() then
if sortSpecs and (sortSpecs.SpecsDirty or GUI_Main.Refresh.Sort.Rules) then
if #Table_Cache.Unhandled > 0 then
GUI_Main.Table.SortSpecs = sortSpecs
table.sort(Table_Cache.Unhandled, TableSortSpecs)
GUI_Main.Table.SortSpecs = nil
end
sortSpecs.SpecsDirty = false
GUI_Main.Refresh.Sort.Rules = false
end
local clipper = ImGuiListClipper.new()
clipper:Begin(#Table_Cache.Unhandled)
while clipper:Step() do
for i = clipper.DisplayStart, clipper.DisplayEnd - 1, 1 do
local entry = Table_Cache.Unhandled[i + 1]
ImGui.PushID(entry.ID)
ImGui.TableNextRow()
DrawRuleRow(entry)
ImGui.PopID()
end
end
clipper:End()
end
ImGui.EndTable()
end
elseif currentTab == "npcList" then
-- Tab for NPC List
local npcs = settings[Zone.ShortName()] or {}
local changed
newSpawnName, changed = ImGui.InputText("##NewSpawnName", newSpawnName, 256)
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Enter Spawn Name this is CaseSensative,\n also accepts variables like: ${Target.DisplayName} and ${Target.Name}")
ImGui.EndTooltip()
end
ImGui.SameLine()
-- Button to add the new spawn
if ImGui.Button(Icons.FA_USER_PLUS) and newSpawnName ~= "" then
CMD('/am spawnadd "'..newSpawnName..'"')
newSpawnName = "" -- Clear the input text after adding
npcs = settings[Zone.ShortName()] or {}
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Add to SpawnList")
ImGui.EndTooltip()
end
-- Populate and sort sortedNpcs right before using it
local sortedNpcs = {}
for id, spawnName in pairs(npcs) do
table.insert(sortedNpcs, {
name = spawnName,
isInAlerts = isSpawnInAlerts(spawnName, spawnAlerts)
})
end
-- Sort the table so NPCs in alerts come first
table.sort(sortedNpcs, function(a, b)
if a.isInAlerts and not b.isInAlerts then
return true
elseif not a.isInAlerts and b.isInAlerts then
return false
else
return a.name < b.name
end
end)
-- Now build the table with the sorted list
if next(sortedNpcs) ~= nil then
if ImGui.BeginTable("NPCListTable", 3, spawnListFlags) then
-- Set up table headers
ImGui.TableSetupScrollFreeze(0, 1)
ImGui.TableSetupColumn("NPC Name", ImGuiTableColumnFlags.WidthAlwaysAutoResize)
ImGui.TableSetupColumn("Zone", ImGuiTableColumnFlags.WidthAlwaysAutoResize)
ImGui.TableSetupColumn(Icons.MD_DELETE)
ImGui.TableHeadersRow()
for index, npc in ipairs(sortedNpcs) do
local spawnName = npc.name
-- local sHeading = npc.HeadingTo() or '??'
ImGui.TableNextRow()
ImGui.TableNextColumn()
-- Modify the spawnName to create a display name
local displayName = spawnName:gsub("_", " "):gsub("%d*$", "") -- Replace underscores with spaces and remove trailing digits
-- Check if the spawn is in the alert list and change color
if npc.isInAlerts then
ImGui.PushStyleColor(ImGuiCol.Text, 0, 1, 0, 1) -- Green color for alert spawns
end
-- Display the name and handle interaction
ImGui.Text(displayName)
if npc.isInAlerts then
ImGui.PopStyleColor()
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Green Names are up!\n Right-Click to Navigate to " .. displayName.."\n Ctrl+Right-Click to Group Navigate to " .. displayName)
ImGui.EndTooltip()
end
-- Right-click interaction uses the original spawnName
if ImGui.IsItemHovered() then
if ImGui.IsKeyDown(ImGuiMod.Ctrl) and ImGui.IsMouseReleased(1) then
mq.cmdf('/noparse %s/docommand /timed ${Math.Rand[10,60]} /nav spawn "%s"',groupCmd,spawnName)
elseif
ImGui.IsMouseReleased(1) then
mq.cmdf('/nav spawn "%s"',spawnName)
end
end
end
ImGui.TableNextColumn()
ImGui.Text(Zone.ShortName())
local btnIcon = Icons.MD_DELETE
local buttonLabel = btnIcon .. "##Remove" .. tostring(index)
ImGui.TableNextColumn()
if ImGui.SmallButton(buttonLabel) then
CMD('/am spawndel "' .. spawnName .. '"')
end
if ImGui.IsItemHovered() and showTooltips then
ImGui.BeginTooltip()
ImGui.Text("Delete Spawn From SpawnList")
ImGui.EndTooltip()
end
end
ImGui.EndTable()
end
else
ImGui.Text('No spawns in list for this zone. Add some!')
end
end
ImGui.PopStyleVar(1)
if ColorCount > 0 then ImGui.PopStyleColor(ColorCount) end
ImGui.SetWindowFontScale(1)
--ImGui.BeginGroup()
-- ImGui.EndGroup()
if ImGui.IsWindowHovered() then
ImGui.SetWindowFocus("Alert Master##"..mq.TLO.Me.DisplayName())
end
ImGui.End()
end
end
local function Config_GUI(open)
if not openConfigGUI then return end
ColorCountConf = 0
-- local themeName = theme.LoadTheme or 'notheme'
ColorCountConf = DrawTheme(ColorCountConf, useThemeName)
open, openConfigGUI = ImGui.Begin("Alert master Config", open, bit32.bor(ImGuiWindowFlags.None, ImGuiWindowFlags.AlwaysAutoResize, ImGuiWindowFlags.NoCollapse))
ImGui.SetWindowFontScale(ZoomLvl)
if not openConfigGUI then
openConfigGUI = false
open = false
if ColorCountConf > 0 then ImGui.PopStyleColor(ColorCountConf) end
ImGui.SetWindowFontScale(1)
ImGui.End()
return open
end
ImGui.SameLine()
ImGui.Text("Cur Theme: %s", themeName)
-- Combo Box Load Theme
if ImGui.BeginCombo("Load Theme", themeName) then
ImGui.SetWindowFontScale(ZoomLvl)
for k, data in pairs(theme.Theme) do
local isSelected = data.Name == themeName
if ImGui.Selectable(data.Name, isSelected) then
theme.LoadTheme = data.Name
themeName = theme.LoadTheme
useThemeName = themeName
settings[CharConfig]['theme'] = useThemeName
save_settings()
end
end
ImGui.EndCombo()
end
-- Slider for adjusting zoom level
local tmpZoom = ZoomLvl
if ZoomLvl then
tmpZoom = ImGui.SliderFloat("Zoom Level", tmpZoom, 0.5, 2.0)
end
if ZoomLvl ~= tmpZoom then
ZoomLvl = tmpZoom
settings[CharConfig]['ZoomLvl'] = ZoomLvl
end
if ImGui.Button('close') then
openConfigGUI = false
end