-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathEasyFindWindow.h
136 lines (102 loc) · 3.99 KB
/
EasyFindWindow.h
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
#pragma once
#include "EasyFind.h"
#include "eqlib/WindowOverride.h"
#include <glm/vec3.hpp>
//----------------------------------------------------------------------------
class CFindLocationWndOverride : public WindowOverride<CFindLocationWndOverride, CFindLocationWnd>
{
public:
enum class CustomRefType {
Added,
Modified,
};
struct RefData {
CustomRefType type = CustomRefType::Added;
const FindableLocation* data = nullptr;
};
//----------------------------------------------------------------------------
// overrides
virtual int OnProcessFrame() override;
virtual bool AboutToShow() override;
virtual int OnZone() override;
virtual int WndNotification(CXWnd* sender, uint32_t message, void* data) override;
uint32_t GetAvailableId();
//----------------------------------------------------------------------------
// zone connection handling
void AddZoneConnection(const FindableLocation& findableLocation);
void AddCustomLocations(bool initial);
void RemoveCustomLocations();
void UpdateListRowColor(int row);
void UpdateDistanceColumn();
FindableReference* GetReferenceForListIndex(int index) const;
CVector3 GetReferencePosition(FindableReference* ref, bool& found);
// 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 PerformFindWindowNavigation(int refId, int row, bool asGroup);
bool IsCustomLocationsAdded() const { return sm_customLocationsAdded; }
MQColor GetColorForReference(int refId);
RefData* GetCustomRefData(int refId);
const FindZoneConnectionData* GetOriginalZoneConnectionData(int index);
void LoadZoneConnections();
public:
void FindLocationByRefNum(int refNum, bool group);
template <typename T>
int FindClosestLocation(T&& callback)
{
int closestIndex = -1;
float closestDistance = FLT_MAX;
CVector3 myPos = { pLocalPlayer->Y, pLocalPlayer->X, pLocalPlayer->Z };
for (int i = 0; i < findLocationList->GetItemCount(); ++i)
{
if (callback(i))
{
// Get distance to target.
FindableReference* ref = GetReferenceForListIndex(i);
if (ref)
{
bool found = false;
CVector3 pos = GetReferencePosition(ref, found);
if (found)
{
float distance = myPos.GetDistanceSquared(pos);
if (distance < closestDistance)
{
closestDistance = distance;
closestIndex = i;
}
}
}
}
}
return closestIndex;
}
bool FindZoneConnectionByZoneIndex(EQZoneIndex zoneId, bool group);
bool FindLocation(std::string_view searchTerm, bool group);
void AddDistanceColumn();
void RemoveDistanceColumn();
void OnHooked();
void OnAboutToUnhook();
static void OnHooked(CFindLocationWndOverride* pWnd) { pWnd->OnHooked(); }
static void OnAboutToUnhook(CFindLocationWndOverride* pWnd) { pWnd->OnAboutToUnhook(); }
private:
bool FindLocationByListIndex(int listIndex, bool group);
// our "member variables" are static because we can't actually add new member variables,
// but we only ever have one instance of CFindLocationWnd, so this works out to be about the same.
static inline int sm_distanceColumn = -1;
static inline std::chrono::steady_clock::time_point sm_lastDistanceUpdate;
// tracks whether the custom locations have been added to the window or not.
static inline bool sm_customLocationsAdded = false;
// container holding our custom ref ids and their types.
static inline std::map<int, RefData> sm_customRefs;
// the original zone connections for values that we overwrote.
static inline std::map<int, FindZoneConnectionData> sm_originalZoneConnections;
// Holds queued commands in case we try to start a bit too early.
static inline std::string sm_queuedSearchTerm;
static inline bool sm_queuedGroupParam = false;
static inline EQZoneIndex sm_queuedZoneId = 0;
// tracking for options changes
static inline bool sm_displayDistanceColumn = true;
static inline bool sm_displayColors = true;
static inline MQColor sm_addedColor;
static inline MQColor sm_modifiedColor;
};