-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathEasyFindWindow.cpp
More file actions
1100 lines (915 loc) · 29.4 KB
/
EasyFindWindow.cpp
File metadata and controls
1100 lines (915 loc) · 29.4 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
#include "EasyFindWindow.h"
#include "EasyFindConfiguration.h"
#include "EasyFindZoneConnections.h"
//----------------------------------------------------------------------------
//
// Limit the rate at which we update the distance to findable locations
static constexpr std::chrono::milliseconds s_distanceCalcDelay = std::chrono::milliseconds{ 100 };
static bool s_performCommandFind = false;
static bool s_performGroupCommandFind = false;
static FindableLocations s_findableLocations;
static bool s_findableLocationsDirty = false;
//============================================================================
int CFindLocationWndOverride::OnProcessFrame()
{
// The following checks match what OnProcessFrame() does to determine when it is
// time to rebuild the ui. We use the same logic and anticipate the rebuild so that
// we don't lose our custom connections.
if (IsActive())
{
if (lastUpdateTime + 1000 < pDisplay->TimeStamp)
{
// What gets cleared:
// if playerListDirty is true, the findLocationList is completely cleared, and
// rebuilt from the ground up. This means all ref entries are removed and
// all list elements are removed.
// if playerListDirty, then only group members are changed.
if (playerListDirty)
{
// This will set sm_customLocationsAdded to false, allowing us to re-inject the
// data after OnProcessFrame() is called.
RemoveCustomLocations();
}
}
}
if (s_findableLocationsDirty)
{
RemoveCustomLocations();
s_findableLocationsDirty = false;
}
// if didRebuild is true, then this will reset the refs list.
int result = Super::OnProcessFrame();
bool updateColors = false;
if (sm_displayDistanceColumn != g_configuration->IsDistanceColumnEnabled())
{
sm_displayDistanceColumn = g_configuration->IsDistanceColumnEnabled();
if (sm_displayDistanceColumn)
{
AddDistanceColumn();
}
else
{
RemoveDistanceColumn();
updateColors = true;
}
}
if (sm_displayColors != g_configuration->IsColoredFindWindowEnabled()
|| sm_addedColor != g_configuration->GetColor(ConfiguredColor::AddedLocation)
|| sm_modifiedColor != g_configuration->GetColor(ConfiguredColor::ModifiedLocation))
{
sm_displayColors = g_configuration->IsColoredFindWindowEnabled();
sm_addedColor = g_configuration->GetColor(ConfiguredColor::AddedLocation);
sm_modifiedColor = g_configuration->GetColor(ConfiguredColor::ModifiedLocation);
updateColors = true;
}
// Update distance column. this will internally skip work if necessary.
UpdateDistanceColumn();
// Ensure that we wait for spawns to be populated into the spawn map first.
if ((zoneConnectionsRcvd || g_configuration->IsIgnoreZoneConnectionDataEnabled()) && !sm_customLocationsAdded && gSpawnCount > 0)
{
AddCustomLocations(true);
if (findLocationList->GetItemCount() > 0 && !findLocationList->IsVisible())
{
findLocationList->SetVisible(true);
noneLabel->SetVisible(false);
}
}
else if (!didFindRequest)
{
// Make sure that if data hasn't been requested, that we trigger the request. This
// normally happens on zone and when the window is about to be opened, which means
// that it doesn't happen on its own immediately after entering the game.
AboutToShow();
}
if (sm_customLocationsAdded && (!sm_queuedSearchTerm.empty() || sm_queuedZoneId != 0))
{
if (sm_queuedZoneId != 0)
{
FindZoneConnectionByZoneIndex(sm_queuedZoneId, sm_queuedGroupParam);
}
else
{
FindLocation(sm_queuedSearchTerm, sm_queuedGroupParam);
}
sm_queuedSearchTerm.clear();
sm_queuedGroupParam = false;
sm_queuedZoneId = 0;
}
if (updateColors)
{
// update the list
for (int i = 0; i < findLocationList->GetItemCount(); ++i)
{
UpdateListRowColor(i);
}
}
return result;
}
bool CFindLocationWndOverride::AboutToShow()
{
// Clear selection when showing, to avoid trying to find on appear.
if (findLocationList)
{
findLocationList->CurSel = -1;
}
// AboutToShow will reset the window, so anticipate that and remove our items first.
// We'll add them again in OnProcessFrame().
RemoveCustomLocations();
return Super::AboutToShow();
}
int CFindLocationWndOverride::OnZone()
{
// Reset any temporary state. When we zone everything is destroyed and we start over.
sm_customLocationsAdded = false;
sm_customRefs.clear();
sm_originalZoneConnections.clear();
int result = Super::OnZone();
LoadZoneConnections();
return result;
}
uint32_t CFindLocationWndOverride::GetAvailableId()
{
lastId++;
while (referenceList.FindFirst(lastId))
lastId++;
return lastId;
}
void CFindLocationWndOverride::AddZoneConnection(const FindableLocation& findableLocation)
{
// Scan items for something with the same name and description. If one exists that matches then we
// replace it and mark it as replaced. Otherwise we add a new element.
for (int i = 0; i < findLocationList->GetItemCount(); ++i)
{
if (ci_equals(findLocationList->GetItemText(i, 0), findableLocation.listCategory)
&& ci_equals(findLocationList->GetItemText(i, 1), findableLocation.listDescription))
{
if (!findableLocation.replace)
{
return;
}
// This is a matching item. Instead of adding a 2nd copy we just replace the entry with our own.
// Get the ref from the list. This will give us the index in the zone connections list.
int listRefId = (int)findLocationList->GetItemData(i);
FindableReference* listRef = referenceList.FindFirst(listRefId);
// Sanity check the type and then make the copy.
if (listRef->type == FindLocation_Switch || listRef->type == FindLocation_Location)
{
sm_originalZoneConnections[listRef->index] = unfilteredZoneConnectionList[listRef->index];
unfilteredZoneConnectionList[listRef->index] = findableLocation.eqZoneConnectionData;
sm_customRefs[listRefId] = { CustomRefType::Modified, &findableLocation };
// Modify the colors
UpdateListRowColor(i);
SPDLOG_DEBUG("\ayReplaced {} - {} with custom data", findableLocation.listCategory, findableLocation.listDescription);
}
return;
}
}
// add entry to zone connection list
unfilteredZoneConnectionList.Add(findableLocation.eqZoneConnectionData);
int id = unfilteredZoneConnectionList.GetCount() - 1;
// add reference
uint32_t refId = GetAvailableId();
FindableReference& ref = referenceList.Insert(refId);
ref.index = id;
ref.type = findableLocation.type;
sm_customRefs[refId] = { CustomRefType::Added, &findableLocation };
// update list box
SListWndCell cellName;
cellName.Text = findableLocation.listCategory;
SListWndCell cellDescription;
cellDescription.Text = findableLocation.listDescription;
SListWndLine line;
line.Cells.reserve(3); // reserve memory for 3 columns
line.Cells.Add(cellName);
line.Cells.Add(cellDescription);
if (sm_distanceColumn != -1)
line.Cells.Add(SListWndCell());
line.Data = refId;
// initialize the color
for (SListWndCell& cell : line.Cells)
cell.Color = (COLORREF)g_configuration->GetColor(ConfiguredColor::AddedLocation);
findLocationList->AddLine(&line);
SPDLOG_DEBUG("\aoAdded {} - {} with id {}", findableLocation.listCategory, findableLocation.listDescription, refId);
}
void CFindLocationWndOverride::AddCustomLocations(bool initial)
{
if (sm_customLocationsAdded)
return;
if (!pLocalPC)
return;
for (FindableLocation& location : s_findableLocations)
{
if (!location.initialized)
{
// check requirements
if (location.parsedData)
{
if (!location.parsedData->CheckRequirements())
continue;
}
// Assemble the eq object
if (location.type == FindLocation_Switch || location.type == FindLocation_Location)
{
location.listCategory = "Zone Connection";
location.eqZoneConnectionData.id = 0;
location.eqZoneConnectionData.subId = location.type == FindLocation_Location ? 0 : -1;
location.eqZoneConnectionData.type = location.type;
bool isSwitchRemoval = ci_equals(location.switchName, "none");
bool updatedFromSwitch = false;
// Search for an existing zone entry that matches this one.
for (FindZoneConnectionData& eqEntry : unfilteredZoneConnectionList)
{
if (eqEntry.zoneId == location.zoneId && eqEntry.zoneIdentifier == location.zoneIdentifier)
{
// Its a connection representing the same thing.
if (!location.replace)
{
location.skip = true;
}
// We replaced a switch with a location. Often times this just means we wanted to change the
// position where we click the switch, not remove the switch. Unless the configuration says
// switch: "none", then we just change the location only.
if (!isSwitchRemoval
&& eqEntry.type == FindLocation_Switch
&& location.eqZoneConnectionData.type == FindLocation_Location
&& location.spawnName.empty())
{
location.eqZoneConnectionData.type = FindLocation_Switch;
location.eqZoneConnectionData.id = eqEntry.id;
// set type to switch.
location.type = FindLocation_Switch;
updatedFromSwitch = true;
}
}
}
if (location.type == FindLocation_Switch && !updatedFromSwitch)
{
if (!location.switchName.empty())
{
EQSwitch* pSwitch = FindSwitchByName(location.switchName.c_str());
if (pSwitch)
{
location.eqZoneConnectionData.id = pSwitch->ID;
}
}
else if (location.switchId != -1)
{
location.eqZoneConnectionData.id = location.switchId;
}
}
if (!location.spawnName.empty())
{
// Get location of the npc
SPAWNINFO* pSpawn = FindSpawnByName(location.spawnName.c_str(), true);
if (pSpawn)
{
location.location = glm::vec3(pSpawn->Y, pSpawn->X, pSpawn->Z);
}
else
{
SPDLOG_ERROR("Failed to create translocator connection: Could not find \"\ay{}\ax\"!", location.spawnName);
continue;
}
}
location.eqZoneConnectionData.zoneId = location.zoneId;
location.eqZoneConnectionData.zoneIdentifier = location.zoneIdentifier;
if (location.location.has_value())
location.eqZoneConnectionData.location = CVector3(location.location->x, location.location->y, location.location->z);
if (location.name.empty())
{
CXStr name = GetFullZone(location.zoneId);
location.listDescription = name;
}
else
{
location.listDescription = location.name;
}
if (location.zoneIdentifier)
location.listDescription.append(fmt::format(" - {}", location.zoneIdentifier));
}
location.initialized = true;
}
if (!location.skip)
{
AddZoneConnection(location);
}
}
sm_customLocationsAdded = true;
}
void CFindLocationWndOverride::RemoveCustomLocations()
{
if (!sm_customLocationsAdded)
return;
if (!findLocationList)
return;
int index = 0;
// Remove all the items from the list that contain entries in our custom refs list.
while (index < findLocationList->GetItemCount())
{
int refId = (int)findLocationList->GetItemData(index);
auto iter = sm_customRefs.find(refId);
if (iter != sm_customRefs.end())
{
auto type = iter->second.type;
sm_customRefs.erase(iter);
if (type == CustomRefType::Added)
{
// This is a custom entry. Remove it completely.
findLocationList->RemoveLine(index);
// Remove the reference too
auto refIter = referenceList.find(refId);
if (refIter != referenceList.end())
{
// Remove the element from the zone connection list and fix up any other
// refs that tried to index anything after it.
auto& refData = refIter->value();
unfilteredZoneConnectionList.DeleteElement(refData.index);
if (refData.type == FindLocation_Location || refData.type == FindLocation_Switch)
{
// Remove it from the list and decrement any indices that occur after it.
for (auto& entry : referenceList)
{
if (entry.value().index > refData.index
&& (entry.value().type == FindLocation_Location || entry.value().type == FindLocation_Switch))
{
--entry.value().index;
}
}
}
referenceList.erase(refIter);
}
}
else if (type == CustomRefType::Modified)
{
// This is a modification to an existing entry. Restore it.
auto refIter = referenceList.find(refId);
if (refIter != referenceList.end())
{
auto& refData = refIter->value();
if (refData.type == FindLocation_Location || refData.type == FindLocation_Switch)
{
int connectionIndex = refData.index;
// Look the original data and do some sanity checks
auto connectionIter = sm_originalZoneConnections.find(connectionIndex);
if (connectionIter != sm_originalZoneConnections.end())
{
if (connectionIndex >= 0 && connectionIndex < unfilteredZoneConnectionList.GetCount())
{
// replace the content
unfilteredZoneConnectionList[connectionIndex] = connectionIter->second;
}
sm_originalZoneConnections.erase(connectionIter);
}
}
}
}
}
else
{
++index;
}
}
if (findLocationList->GetItemCount() == 0)
{
findLocationList->SetVisible(false);
noneLabel->SetVisible(true);
}
sm_customLocationsAdded = false;
}
void CFindLocationWndOverride::UpdateListRowColor(int row)
{
int listRefId = (int)findLocationList->GetItemData(row);
auto iter = sm_customRefs.find(listRefId);
if (iter != sm_customRefs.end())
{
CustomRefType type = iter->second.type;
SListWndLine& line = findLocationList->ItemsArray[row];
for (SListWndCell& cell : line.Cells)
{
if (sm_displayColors)
{
if (type == CustomRefType::Added)
cell.Color = (COLORREF)sm_addedColor;
else if (type == CustomRefType::Modified)
cell.Color = (COLORREF)sm_modifiedColor;
}
else
{
cell.Color = (COLORREF)MQColor(255, 255, 255);
}
}
}
}
int CFindLocationWndOverride::WndNotification(CXWnd* sender, uint32_t message, void* data)
{
if (sender == findLocationList)
{
if (message == XWM_LCLICK)
{
int selectedRow = (int)(uintptr_t)data;
int refId = (int)findLocationList->GetItemData(selectedRow);
// TODO: Configurable keybinds
if (pWndMgr->IsCtrlKey() || s_performCommandFind)
{
bool groupNav = (pWndMgr->IsShiftKey() && !s_performCommandFind) || s_performGroupCommandFind;
// Try to perform the navigation. If we succeed, bail out. Otherwise trigger the
// navigation via player path.
if (PerformFindWindowNavigation(refId, selectedRow, groupNav))
{
Show(false);
return 0;
}
}
auto refIter = sm_customRefs.find(refId);
if (refIter != sm_customRefs.end())
{
// Don't "find" custom locations
if (refIter->second.type == CustomRefType::Added)
{
SPDLOG_ERROR("Cannot use standard find window functionality for custom locations.");
return 0;
}
}
return Super::WndNotification(sender, message, data);
}
else if (message == XWM_COLUMNCLICK)
{
// CFindLocationWnd will proceed to override our sort with its own, so we'll just perform this
// operation in OnProcessFrame.
int colIndex = (int)(uintptr_t)data;
if (colIndex == sm_distanceColumn)
{
findLocationList->SetSortColumn(colIndex);
return 0;
}
}
else if (message == XWM_SORTREQUEST)
{
SListWndSortInfo* si = (SListWndSortInfo*)data;
if (si->SortCol == sm_distanceColumn)
{
si->SortResult = static_cast<int>(GetFloatFromString(si->StrLabel2, 0.0f) - GetFloatFromString(si->StrLabel1, 0.0f));
return 0;
}
}
}
return Super::WndNotification(sender, message, data);
}
void CFindLocationWndOverride::UpdateDistanceColumn()
{
if (sm_distanceColumn == -1)
return;
auto now = std::chrono::steady_clock::now();
bool periodicUpdate = false;
if (now - sm_lastDistanceUpdate > s_distanceCalcDelay)
{
sm_lastDistanceUpdate = now;
periodicUpdate = true;
}
CVector3 myPos = { pLocalPlayer->Y, pLocalPlayer->X, pLocalPlayer->Z };
bool needsSort = false;
for (int index = 0; index < findLocationList->ItemsArray.GetCount(); ++index)
{
// Only update columns if this is a periodic update or if a column is empty.
if (!findLocationList->GetItemText(index, sm_distanceColumn).empty() && !periodicUpdate)
{
continue;
}
FindableReference* ref = GetReferenceForListIndex(index);
if (!ref)
continue;
bool found = false;
CVector3 location = GetReferencePosition(ref, found);
if (found)
{
float distance = location.GetDistance(myPos);
char label[32];
sprintf_s(label, 32, "%.2f", distance);
findLocationList->SetItemText(index, sm_distanceColumn, label);
}
else
{
findLocationList->SetItemText(index, sm_distanceColumn, CXStr());
}
needsSort = true;
}
// If the distance coloumn is being sorted, update it.
if (findLocationList->SortCol == sm_distanceColumn && needsSort)
{
findLocationList->Sort();
}
}
CFindLocationWnd::FindableReference* CFindLocationWndOverride::GetReferenceForListIndex(int index) const
{
int refId = (int)findLocationList->GetItemData(index);
FindableReference* ref = referenceList.FindFirst(refId);
return ref;
}
CVector3 CFindLocationWndOverride::GetReferencePosition(FindableReference* ref, bool& found)
{
found = false;
if (ref->type == FindLocation_Player)
{
if (PlayerClient* pSpawn = GetSpawnByID(ref->index))
{
found = true;
return CVector3(pSpawn->Y, pSpawn->X, pSpawn->Z);
}
}
else if (ref->type == FindLocation_Location || ref->type == FindLocation_Switch)
{
const FindZoneConnectionData& zoneConn = unfilteredZoneConnectionList[ref->index];
if (zoneConn.location.X != 0.0f || zoneConn.location.Y != 0.0f || zoneConn.location.Z != 0.0f)
{
found = true;
return zoneConn.location;
}
else if (ref->type == FindLocation_Switch)
{
EQSwitch* pSwitch = GetSwitchByID(zoneConn.id);
if (pSwitch)
{
found = true;
return CVector3(pSwitch->Y, pSwitch->X, pSwitch->Z);
}
}
}
return CVector3();
}
// Returns true if we handled the navigation here. Returns false if we couldn't do it
// and that we should let the path get created so we can navigate to it.
bool CFindLocationWndOverride::PerformFindWindowNavigation(int refId, int row, bool asGroup)
{
if (!Navigation_IsInitialized())
{
SPDLOG_ERROR("Navigation requires the MQ2Nav plugin to be loaded.");
return false;
}
FindableReference* ref = referenceList.FindFirst(refId);
if (!ref)
{
return false;
}
FindLocationType type = ref->type;
const FindableLocation* customLocation = nullptr;
auto customIter = sm_customRefs.find(refId);
if (customIter != sm_customRefs.end())
{
customLocation = customIter->second.data;
type = customLocation->type;
}
switch (type)
{
case FindLocation_Player:
// In the case that we are finding a spawn, then the index is actually the spawn id,
// and we need to look it up.
if (PlayerClient* pSpawn = GetSpawnByID(ref->index))
{
if (asGroup)
{
// If we do this as a group, we execute via a command instead. This ensures that all
// members experience the same result (hopefully).
std::string command = fmt::format("/easyfind {}", pSpawn->DisplayedName);
DoGroupCommand(command, true);
return true;
}
std::string name;
if (pSpawn->Lastname[0] && pSpawn->Type == SPAWN_NPC)
name = fmt::format("{} ({})", pSpawn->DisplayedName, pSpawn->Lastname);
else
name = pSpawn->DisplayedName;
if (pSpawn->Type == SPAWN_PLAYER)
SPDLOG_INFO("Navigating to \ayPlayer:\ax \ag{}", name);
else
SPDLOG_INFO("Navigating to \aySpawn:\ax \ag{}", name);
FindLocationRequestState request;
request.spawnID = ref->index;
request.type = ref->type;
request.name = std::move(name);
if (customLocation)
request.findableLocation = std::make_shared<FindableLocation>(*customLocation);
Navigation_ExecuteCommand(std::move(request));
return true;
}
return false;
case FindLocation_Location:
case FindLocation_Switch: {
if (ref->index >= (uint32_t)unfilteredZoneConnectionList.GetCount())
{
SPDLOG_ERROR("Unexpected error: zone connection index is out of range!");
return false;
}
const FindZoneConnectionData& zoneConn = unfilteredZoneConnectionList[ref->index];
int32_t switchId = 0;
if (type == FindLocation_Switch)
{
switchId = zoneConn.id;
}
std::string locationName;
EQZoneInfo* pZoneInfo = pWorldData->GetZone(zoneConn.zoneId);
if (pZoneInfo)
locationName = pZoneInfo->LongName;
else
locationName = fmt::format("Unknown({})", (int)zoneConn.zoneId);
if (zoneConn.zoneIdentifier > 0)
locationName.append(fmt::format(" - {}", zoneConn.zoneIdentifier));
EQSwitch* pSwitch = nullptr;
if (type == FindLocation_Switch)
{
pSwitch = pSwitchMgr->GetSwitchById(switchId);
}
if (asGroup)
{
// If we do this as a group, we execute via a command instead. This ensures that all
// members experience the same result (hopefully).
// Get the name of the connection as it is displayed in the UI
CXStr itemText = findLocationList->GetItemText(row, 1);
std::string command = fmt::format("/easyfind {}", std::string_view{ itemText });
DoGroupCommand(command, true);
return true;
}
FindLocationRequestState request;
request.location = *(glm::vec3*)&zoneConn.location;
request.switchID = switchId;
request.type = type;
request.zoneId = zoneConn.zoneId;
if (customLocation)
request.findableLocation = std::make_shared<FindableLocation>(*customLocation);
if (pSwitch && g_configuration->IsVerboseMessages())
{
SPDLOG_INFO("Navigating to \ayZone Connection\ax: \ag{}\ax (via switch \ao{}\ax)", locationName, pSwitch->Name);
}
else
{
SPDLOG_INFO("Navigating to \ayZone Connection\ax: \ag{}\ax", locationName);
}
request.name = std::move(locationName);
Navigation_ExecuteCommand(std::move(request));
return true;
}
default:
SPDLOG_ERROR("Cannot navigate to selection type: {}", static_cast<int>(type));
break;
}
return false;
}
MQColor CFindLocationWndOverride::GetColorForReference(int refId)
{
MQColor color(255, 255, 255);
auto iter = sm_customRefs.find(refId);
if (iter != sm_customRefs.end())
{
if (iter->second.type == CustomRefType::Added)
color = g_configuration->GetColor(ConfiguredColor::AddedLocation);
else if (iter->second.type == CustomRefType::Modified)
color = g_configuration->GetColor(ConfiguredColor::ModifiedLocation);
}
return color;
}
CFindLocationWndOverride::RefData* CFindLocationWndOverride::GetCustomRefData(int refId)
{
auto iter = sm_customRefs.find(refId);
if (iter != sm_customRefs.end())
{
return &iter->second;
}
return nullptr;
}
const CFindLocationWnd::FindZoneConnectionData* CFindLocationWndOverride::GetOriginalZoneConnectionData(int index)
{
auto origIter = sm_originalZoneConnections.find(index);
if (origIter != sm_originalZoneConnections.end())
{
return &origIter->second;
}
return nullptr;
}
bool CFindLocationWndOverride::FindLocationByListIndex(int listIndex, bool group)
{
// Perform navigaiton by triggering a selection in the list.
s_performCommandFind = true;
s_performGroupCommandFind = group;
findLocationList->SetCurSel(listIndex);
findLocationList->ParentWndNotification(findLocationList, XWM_LCLICK, (void*)(intptr_t)listIndex);
s_performCommandFind = false;
s_performGroupCommandFind = false;
return true;
}
void CFindLocationWndOverride::FindLocationByRefNum(int refNum, bool group)
{
for (int index = 0; index < findLocationList->GetItemCount(); ++index)
{
int itemRefNum = (int)findLocationList->GetItemData(index);
if (itemRefNum == refNum)
{
FindLocationByListIndex(index, group);
return;
}
}
SPDLOG_ERROR("Couldn't find location by ref: {}", refNum);
}
bool CFindLocationWndOverride::FindZoneConnectionByZoneIndex(EQZoneIndex zoneId, bool group)
{
if (!sm_customLocationsAdded)
{
sm_queuedZoneId = sm_queuedZoneId;
sm_queuedGroupParam = group;
SPDLOG_WARN("Waiting for connections to be loaded!");
return true;
}
// look for exact match by zone id
int foundIndex = FindClosestLocation(
[&](int index)
{
int refId = (int)findLocationList->GetItemData(index);
FindableReference* ref = referenceList.FindFirst(refId);
if (!ref) return false;
if (ref->type == FindLocation_Location || ref->type == FindLocation_Switch)
{
FindZoneConnectionData& connData = unfilteredZoneConnectionList[ref->index];
return connData.zoneId == zoneId;
}
return false;
});
if (foundIndex == -1)
{
EQZoneInfo* pZoneInfo = pWorldData->GetZone(zoneId);
SPDLOG_ERROR("Could not find connection to \"\ay{}\ax\".", pZoneInfo ? pZoneInfo->LongName : "Unknown");
return false;
}
return FindLocationByListIndex(foundIndex, group);
}
bool CFindLocationWndOverride::FindLocation(std::string_view searchTerm, bool group)
{
// Strip quotes if they exist
if (searchTerm.size() > 2 && searchTerm[0] == '"' && searchTerm[searchTerm.size() - 1] == '"')
searchTerm = searchTerm.substr(1, searchTerm.size() - 2);
// If search term starts with "nav" then we forward to nav
if (ci_starts_with(searchTerm, "nav "))
{
searchTerm = searchTerm.substr(strlen("nav") + 1);
searchTerm = trim(searchTerm);
return Navigation_ExecuteCommand(searchTerm);
}
if (!sm_customLocationsAdded)
{
sm_queuedSearchTerm = searchTerm;
sm_queuedGroupParam = group;
SPDLOG_WARN("Waiting for connections to be loaded!");
return true;
}
int foundIndex = -1;
// Do an exact search first.
for (int i = 0; i < findLocationList->GetItemCount(); ++i)
{
CXStr itemText = findLocationList->GetItemText(i, 1);
if (ci_equals(itemText, searchTerm))
{
foundIndex = i;
break;
}
}
// Didn't find an exact match. Try an exact match against the short zone name of each connection.
if (foundIndex == -1)
{
foundIndex = FindClosestLocation(
[&](int index)
{
int refId = (int)findLocationList->GetItemData(index);
FindableReference* ref = referenceList.FindFirst(refId);
if (!ref) return false;
if (ref->type == FindLocation_Location || ref->type == FindLocation_Switch)
{
FindZoneConnectionData& connData = unfilteredZoneConnectionList[ref->index];
EQZoneInfo* pZoneInfo = pWorldData->GetZone(connData.zoneId);
return pZoneInfo && ci_equals(pZoneInfo->ShortName, searchTerm);
}
return false;
});
}
if (foundIndex == -1)
{
// if didn't find then try a substring search, picking the closest match by distance.
foundIndex = FindClosestLocation(
[&](int index) { return ci_find_substr(findLocationList->GetItemText(index, 1), searchTerm) != -1; });
if (foundIndex != -1)
{
SPDLOG_INFO("Finding closest point matching \"\ay{}\ax\".", searchTerm);
}
}
if (foundIndex == -1)
{
SPDLOG_ERROR("Could not find \"\ay{}\ax\".", searchTerm);
return false;
}
return FindLocationByListIndex(foundIndex, group);
}
void CFindLocationWndOverride::AddDistanceColumn()
{
CListWnd* locs = findLocationList;
if (locs->Columns.GetCount() == 2)
{
sm_distanceColumn = locs->AddColumn("Distance", 60, 0, CellTypeBasicText);
locs->SetColumnJustification(sm_distanceColumn, 0);
// Copy the color from the other columns
for (int i = 0; i < locs->GetItemCount(); ++i)
{
SListWndLine& line = locs->ItemsArray[i];
if (line.Cells.GetCount() == 2)
{
line.Cells.reserve(3);
line.Cells.Add(SListWndCell());
}
line.Cells[sm_distanceColumn].Color = line.Cells[sm_distanceColumn - 1].Color;
}
}
else if (locs->Columns.GetCount() == 3
&& (locs->Columns[2].StrLabel == "Distance" || locs->Columns[2].StrLabel == ""))
{
sm_distanceColumn = 2;
locs->SetColumnLabel(sm_distanceColumn, "Distance");
}
UpdateDistanceColumn();
}
void CFindLocationWndOverride::RemoveDistanceColumn()
{
CListWnd* locs = findLocationList;
if (sm_distanceColumn != -1)