/
core.lua
124 lines (96 loc) · 3.43 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
-- rNamePlate: core
-- zork, 2016
-----------------------------
-- Variables
-----------------------------
local A, L = ...
local W = CreateFrame("Frame") --worker
local UFM = {} --unit frame mixin
local C_NamePlate = C_NamePlate
-----------------------------
-- SetCVar
-----------------------------
--default values
SetCVar('nameplateShowAll', GetCVarDefault("nameplateShowAll"))
SetCVar("nameplateMaxAlpha", GetCVarDefault("nameplateMaxAlpha"))
SetCVar("nameplateShowEnemies", GetCVarDefault("nameplateShowEnemies"))
SetCVar("ShowClassColorInNameplate", GetCVarDefault("ShowClassColorInNameplate"))
SetCVar("nameplateOtherTopInset", GetCVarDefault("nameplateOtherTopInset"))
SetCVar("nameplateOtherBottomInset", GetCVarDefault("nameplateOtherBottomInset"))
SetCVar("nameplateMinScale", GetCVarDefault("nameplateMinScale"))
SetCVar("namePlateMaxScale", GetCVarDefault("namePlateMaxScale"))
SetCVar("nameplateMinScaleDistance", GetCVarDefault("nameplateMinScaleDistance"))
SetCVar("nameplateMaxDistance", GetCVarDefault("nameplateMaxDistance"))
SetCVar("NamePlateHorizontalScale", GetCVarDefault("NamePlateHorizontalScale"))
SetCVar("NamePlateVerticalScale", GetCVarDefault("NamePlateVerticalScale"))
-----------------------------
-- Hide Blizzard
-----------------------------
function W:UpdateNamePlateOptions(...)
print("UpdateNamePlateOptions",...)
end
--disable blizzard nameplates
NamePlateDriverFrame:UnregisterAllEvents()
NamePlateDriverFrame:Hide()
NamePlateDriverFrame.UpdateNamePlateOptions = W.UpdateNamePlateOptions
-----------------------------
-- Worker
-----------------------------
function W:NAME_PLATE_CREATED(nameplate)
print("NAME_PLATE_CREATED",nameplate:GetName(),nameplate:GetSize())
local unitFrame = CreateFrame("Button", nameplate:GetName().."UnitFrame", nameplate)
unitFrame:SetAllPoints()
nameplate.unitFrame = unitFrame
--mix-in ubm table data
Mixin(unitFrame, UFM)
--create subframes (health, name, etc...)
unitFrame:Create(nameplate)
end
function W:NAME_PLATE_UNIT_ADDED(unit)
local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
nameplate.unitFrame:UnitAdded(nameplate,unit)
end
function W:NAME_PLATE_UNIT_REMOVED(unit)
local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
nameplate.unitFrame:UnitRemoved(nameplate,unit)
end
function W:OnEvent(event,...)
print("W:OnEvent",...)
self[event](event,...)
end
W:SetScript("OnEvent", W.OnEvent)
W:RegisterEvent("NAME_PLATE_CREATED")
W:RegisterEvent("NAME_PLATE_UNIT_ADDED")
W:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
--W:RegisterEvent("PLAYER_TARGET_CHANGED")
--W:RegisterEvent("DISPLAY_SIZE_CHANGED")
--W:RegisterEvent("UNIT_AURA")
--W:RegisterEvent("VARIABLES_LOADED")
--W:RegisterEvent("CVAR_UPDATE")
--W:RegisterEvent("RAID_TARGET_UPDATE")
--W:RegisterEvent("UNIT_FACTION")
-----------------------------
-- Unit Frame Mixin
-----------------------------
function UFM:Create(nameplate)
print("UFM:Create",self:GetName(),nameplate:GetName())
--create health bar
local t = self:CreateTexture(nil,"BACKGROUND",nil,-8)
t:SetColorTexture(0,1,0)
t:SetSize(32,32)
t:SetPoint("CENTER")
--create name
self:Hide()
end
function UFM:UnitAdded(nameplate,unit)
print("UFM:UnitAdded",self:GetName(),nameplate:GetName(),unit)
self.unit = unit
self.inVehicle = UnitInVehicle(unit)
self:Show()
end
function UFM:UnitRemoved(nameplate,unit)
print("UFM:UnitRemoved",self:GetName(),nameplate:GetName(),unit)
self.unit = nil
self.inVehicle = nil
self:Hide()
end