-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCore.lua
190 lines (157 loc) · 6.15 KB
/
Core.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
PPF_Core = PPF:NewModule("PPF_Core")
function PPF_Core:OnEnable()
local function IsInParty()
return GetNumGroupMembers() > 0 and not IsInRaid()
end
function PPF:OnEvent()
if InCombatLockdown() then return end
local inInstance, instanceType = IsInInstance()
if PPF_Disabled() then
PPF_Pet:Hide()
PPF_PetButton:Hide()
PPF_P1:Hide()
PPF_P1Button:Hide()
PPF_P2:Hide()
PPF_P2Button:Hide()
PPF_P3:Hide()
PPF_P3Button:Hide()
PPF_P4:Hide()
PPF_P4Button:Hide()
elseif IsInParty() or (inInstance and instanceType == 'arena') then
local frames = { CompactPartyFrame:GetChildren() }
local anchor = nil
for i, frame in ipairs(frames) do
if frame.unit and frame:IsVisible() and (not anchor or frame:GetBottom() < anchor:GetBottom()) then
anchor = frame
end
end
if UnitExists("pet") then
PPF_Pet:SetPoint("LEFT", anchor, "LEFT", PPF_DB.positionx, PPF_DB.positiony)
PPF_Pet.name:SetText(UnitName("pet"))
-- Show frames if they got hidden earlier
PPF_Pet:Show()
PPF_PetButton:Show()
elseif PPF_Pet:IsShown() and not UnitExists("pet") then
PPF_Pet:Hide()
PPF_PetButton:Hide()
end
if UnitExists("partypet1") then
-- Set Position
if UnitExists("pet") then
PPF_P1:SetPoint("LEFT", PPF_Pet, "LEFT", 0, -30.5)
else
PPF_P1:SetPoint("LEFT", anchor, "LEFT", PPF_DB.positionx, PPF_DB.positiony)
end
-- Set Name
PPF_P1.name:SetText(UnitName("partypet1"))
-- Show frames if they got hidden earlier
PPF_P1:Show()
PPF_P1Button:Show()
elseif PPF_P1:IsShown() and not UnitExists("partypet1") then
PPF_P1:Hide()
PPF_P1Button:Hide()
end
if UnitExists("partypet2") then
-- Set Position
if UnitExists("partypet1") then
PPF_P2:SetPoint("LEFT", PPF_P1, "LEFT", 0, -30.5)
elseif UnitExists("pet") then
PPF_P2:SetPoint("LEFT", PPF_Pet, "LEFT", 0, -30.5)
else
PPF_P2:SetPoint("LEFT", anchor, "LEFT", PPF_DB.positionx, PPF_DB.positiony)
end
-- Set Name
PPF_P2.name:SetText(UnitName("partypet2"))
-- Show frames if they got hidden earlier
PPF_P2:Show()
PPF_P2Button:Show()
elseif PPF_P2:IsShown() and not UnitExists("partypet2") then
PPF_P2:Hide()
PPF_P2Button:Hide()
end
if UnitExists("partypet3") then
-- Set Position
if UnitExists("partypet2") then
PPF_P3:SetPoint("LEFT", PPF_P2, "LEFT", 0, -30.5)
elseif UnitExists("partypet1") then
PPF_P3:SetPoint("LEFT", PPF_P1, "LEFT", 0, -30.5)
elseif UnitExists("pet") then
PPF_P3:SetPoint("LEFT", PPF_Pet, "LEFT", 0, -30.5)
else
PPF_P3:SetPoint("LEFT", anchor, "LEFT", PPF_DB.positionx, PPF_DB.positiony)
end
-- Set Name
PPF_P3.name:SetText(UnitName("partypet3"))
-- Show frames if they got hidden earlier
PPF_P3:Show()
PPF_P3Button:Show()
elseif PPF_P3:IsShown() and not UnitExists("partypet3") then
PPF_P3:Hide()
PPF_P3Button:Hide()
end
if UnitExists("partypet4") then
-- Set Position
if UnitExists("partypet3") then
PPF_P4:SetPoint("LEFT", PPF_P3, "LEFT", 0, -30.5)
elseif UnitExists("partypet2") then
PPF_P4:SetPoint("LEFT", PPF_P2, "LEFT", 0, -30.5)
elseif UnitExists("partypet1") then
PPF_P4:SetPoint("LEFT", PPF_P1, "LEFT", 0, -30.5)
elseif UnitExists("pet") then
PPF_P4:SetPoint("LEFT", PPF_Pet, "LEFT", 0, -30.5)
else
PPF_P4:SetPoint("LEFT", anchor, "LEFT", PPF_DB.positionx, PPF_DB.positiony)
end
-- Set Name
PPF_P4.name:SetText(UnitName("partypet4"))
-- Show frames if they got hidden earlier
PPF_P4:Show()
PPF_P4Button:Show()
elseif PPF_P4:IsShown() and not UnitExists("partypet4") then
PPF_P4:Hide()
PPF_P4Button:Hide()
end
else
PPF_Pet:Hide()
PPF_PetButton:Hide()
PPF_P1:Hide()
PPF_P1Button:Hide()
PPF_P2:Hide()
PPF_P2Button:Hide()
PPF_P3:Hide()
PPF_P3Button:Hide()
PPF_P4:Hide()
PPF_P4Button:Hide()
end
end
-- Create Border
function PPF:ShowBorder(frame, unit)
if UnitIsUnit("target", unit) then
frame.border:Show()
else
frame.border:Hide()
end
end
function PPF:UpdateHealth(frame, unit)
frame:SetValue(UnitHealth(unit))
end
function PPF_Disabled()
if PPF_DB.enabled then
return false
else
return true
end
end
-- Register Events
PPF:RegisterEvent("GROUP_ROSTER_UPDATE", "OnEvent")
PPF:RegisterEvent("UNIT_CONNECTION", "OnEvent")
PPF:RegisterEvent("UNIT_AREA_CHANGED", "OnEvent")
PPF:RegisterEvent("UNIT_PHASE", "OnEvent")
PPF:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEvent")
PPF:RegisterEvent("PLAYER_ENTERING_WORLD", "OnEvent")
PPF:RegisterEvent("PLAYER_LOGIN", "OnEvent")
-- Small Delay to dodge errors
C_Timer.After(0.5, function()
PPF:RegisterEvent("UNIT_PET", "OnEvent")
end)
end