ESOUI SVN ZAMUnitFramesReactionColors

[/] [trunk/] [ZAM_ReactionColors/] [ZAM_ReactionColors.lua] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 Seerah-7
-- ZAM_ReactionColors © ZAM Network LLC
2 Seerah-7
-- All Rights Reserved
3 Seerah-7
 
4 Seerah-7
local versionNo = "1.2"
5 2 Seerah-7
local f = WINDOW_MANAGER:CreateTopLevelWindow("ZAM_ReactionColors")
6 Seerah-7
local reticle = ZO_ReticleContainerReticle
7 Seerah-7
local stealthEye = ZO_ReticleContainerStealthEye
8 Seerah-7
local GetUnitReactionColor = GetUnitReactionColor
9 3 Seerah-7
local DoesUnitExist = DoesUnitExist
10 2 Seerah-7
local GetUnitLevel = GetUnitLevel
11 Seerah-7
local GetUnitReaction = GetUnitReaction
12 Seerah-7
local GetConColor = GetConColor
13 Seerah-7
local playerLevel = GetUnitLevel("player")
14 9 Seerah-7
local reaction, targetName, targetLevel, warning, lowHealth, db
15 2 Seerah-7
local colorByChoices = {"Reaction", "Level", "Level if hostile", "Disabled"}
16 Seerah-7
 
17 Seerah-7
local defaults = {
18 Seerah-7
        warning = true,
19 Seerah-7
        warningLevel = 5,
20 9 Seerah-7
        lowHealth = false,
21 Seerah-7
        healthLevel = 25,
22 2 Seerah-7
        colorBy = "Reaction",
23 Seerah-7
        colorTargetName = true,
24 Seerah-7
        colorTargetLevel = true,
25 Seerah-7
}
26 Seerah-7
 
27 Seerah-7
 
28 Seerah-7
local function CreateWarningTexture()
29 Seerah-7
        warning = WINDOW_MANAGER:CreateControl("ReactionColorsReticleWarning", ZO_ReticleContainer, CT_TEXTURE)
30 9 Seerah-7
        warning:SetTexture("ZAM_ReactionColors\\levelWarning.dds")
31 4 Seerah-7
        warning:SetDimensions(130,130)
32 Seerah-7
        warning:SetAnchor(CENTER, ZO_ReticleContainer, CENTER, 0, 0)
33 Seerah-7
        warning:SetColor(1, 0, 0, 1)
34 2 Seerah-7
        warning:SetHidden(true)
35 Seerah-7
end
36 Seerah-7
 
37 9 Seerah-7
local function CreateLowHealthTexture()
38 Seerah-7
        lowHealth = WINDOW_MANAGER:CreateControl("ReactionColorsReticleLowHealth", ZO_ReticleContainer, CT_TEXTURE)
39 Seerah-7
        lowHealth:SetTexture("ZAM_ReactionColors\\targetLowHealth.dds")
40 Seerah-7
        lowHealth:SetDimensions(130,130)
41 Seerah-7
        lowHealth:SetAnchor(CENTER, ZO_ReticleContainer, CENTER, 0, 0)
42 Seerah-7
        lowHealth:SetColor(1, 0, 0, 1)
43 Seerah-7
        lowHealth:SetHidden(true)
44 Seerah-7
end
45 Seerah-7
 
46 2 Seerah-7
local function UpdateColor()
47 3 Seerah-7
        if DoesUnitExist("reticleover") then
48 2 Seerah-7
                local r, g, b = GetUnitReactionColor("reticleover")
49 Seerah-7
                local level = GetUnitLevel("reticleover")
50 Seerah-7
                local r2, g2, b2 = GetConColor(level, playerLevel)
51 Seerah-7
                local hostile = GetUnitReaction("reticleover") == UNIT_REACTION_HOSTILE
52 Seerah-7
                if db.colorBy == "Reaction" then
53 Seerah-7
                        reticle:SetColor(r, g, b)
54 Seerah-7
                        stealthEye:SetColor(r, g, b)
55 Seerah-7
                elseif db.colorBy == "Level" or (db.colorBy == "Level if hostile" and hostile) then
56 Seerah-7
                        reticle:SetColor(r2, g2, b2)
57 Seerah-7
                        stealthEye:SetColor(r2, g2, b2)
58 Seerah-7
                --[[elseif db.colorBy == "Level if hostile" and hostile then
59 Seerah-7
                        reticle:SetColor(r2, g2, b2)
60 Seerah-7
                        stealthEye:SetColor(r2, g2, b2)]]
61 Seerah-7
                end
62 Seerah-7
                if db.colorTargetName then
63 Seerah-7
                        if not targetName then targetName = ZO_TargetUnitFramereticleoverName end
64 Seerah-7
                        targetName:SetColor(r, g, b, 1)
65 Seerah-7
                end
66 Seerah-7
                if db.colorTargetLevel then
67 Seerah-7
                        if not targetLevel then targetLevel = ZO_TargetUnitFramereticleoverLevel end
68 Seerah-7
                        targetLevel:SetColor(r2, g2, b2)
69 Seerah-7
                end
70 Seerah-7
                if warning and db.warning then
71 Seerah-7
                        if hostile and (level - playerLevel >= db.warningLevel) then
72 Seerah-7
                                warning:SetHidden(false)
73 Seerah-7
                        end
74 Seerah-7
                end
75 9 Seerah-7
                if lowHealth and db.lowHealth and not hostile and not lowHealth:IsHidden() then
76 Seerah-7
                        lowHealth:SetHidden(true)
77 Seerah-7
                end
78 2 Seerah-7
        else
79 14 Seerah-7
                if warning then warning:SetHidden(true) end
80 2 Seerah-7
                reticle:SetColor(1, 1, 1, 1)
81 Seerah-7
                stealthEye:SetColor(1, 1, 1, 1)
82 9 Seerah-7
                if lowHealth and db.lowHealth then lowHealth:SetHidden(true) end
83 2 Seerah-7
        end
84 Seerah-7
end
85 Seerah-7
 
86 14 Seerah-7
 
87 Seerah-7
local panelData = {
88 Seerah-7
        type = "panel",
89 Seerah-7
        name = "ZAM ReactionColors",
90 Seerah-7
        displayName = "|t72:36:ZAM_Stats\\ZAM_Logo.dds|t ReactionColors",
91 Seerah-7
        author = "Seerah",
92 Seerah-7
        version = versionNo,
93 Seerah-7
        slashCommand = "/zamrc",
94 Seerah-7
        registerForDefaults = true,     --add resetFunc to move UFs back to default position
95 Seerah-7
}
96 Seerah-7
local optionsData = {
97 Seerah-7
        [1] = {
98 Seerah-7
                type = "header",
99 Seerah-7
                name = "Coloring Options",
100 Seerah-7
        },
101 Seerah-7
        [2] = {
102 Seerah-7
                type = "dropdown",
103 Seerah-7
                name = "Color the targeting reticle by...",
104 Seerah-7
                tooltip = "Select when to color the targeting reticle.",
105 Seerah-7
                choices = colorByChoices,
106 Seerah-7
                getFunc = function() return db.colorBy end,
107 Seerah-7
                setFunc = function(colorBy) db.colorBy = colorBy end,
108 Seerah-7
                default = defaults.colorBy,
109 Seerah-7
        },
110 Seerah-7
        [3] = {
111 Seerah-7
                type = "checkbox",
112 Seerah-7
                name = "Color Target's Name",
113 Seerah-7
                tooltip = "Color the target's name by reaction.",
114 Seerah-7
                getFunc = function() return db.colorTargetName end,
115 Seerah-7
                setFunc = function(value)
116 Seerah-7
                                                db.colorTargetName = value
117 2 Seerah-7
                                                if not db.colorTargetName then
118 Seerah-7
                                                        targetName:SetColor(1, 1, 1)
119 Seerah-7
                                                end
120 14 Seerah-7
                                        end,
121 Seerah-7
                width = "half",
122 Seerah-7
                default = defaults.colorTargetName,
123 Seerah-7
        },
124 Seerah-7
        [4] = {
125 Seerah-7
                type = "checkbox",
126 Seerah-7
                name = "Color Target's Level",
127 Seerah-7
                tooltip = "Color the target's level by difficulty.",
128 Seerah-7
                getFunc = function() return db.colorTargetLevel end,
129 Seerah-7
                setFunc = function(value)
130 Seerah-7
                                                db.colorTargetLevel = value
131 2 Seerah-7
                                                if not db.colorTargetLevel then
132 Seerah-7
                                                        targetLevel:SetColor(1, 1, 1)
133 Seerah-7
                                                end
134 14 Seerah-7
                                        end,
135 Seerah-7
                width = "half",
136 Seerah-7
                default = defaults.colorTargetLevel,
137 Seerah-7
        },
138 Seerah-7
        [5] = {
139 Seerah-7
                type = "header",
140 Seerah-7
                name = "Alert Texture Options",
141 Seerah-7
        },
142 Seerah-7
        [6] = {
143 Seerah-7
                type = "checkbox",
144 Seerah-7
                name = "Warning Texture",
145 Seerah-7
                tooltip = "Display a warning texture for high level hostile targets.",
146 Seerah-7
                getFunc = function() return db.warning end,
147 Seerah-7
                setFunc = function(value)
148 Seerah-7
                                                db.warning = value
149 Seerah-7
                                                if db.warning and not warning then CreateWarningTexture() end
150 Seerah-7
                                        end,
151 Seerah-7
                width = "half",
152 Seerah-7
                default = defaults.warning,
153 Seerah-7
        },
154 Seerah-7
        [7] = {
155 Seerah-7
                type = "slider",
156 Seerah-7
                name = "Warning Threshold",
157 Seerah-7
                tooltip = "Display the warning icon if the target is this many levels higher than you.",
158 Seerah-7
                min = 2,
159 Seerah-7
                max = 10,
160 Seerah-7
                step = 1,
161 Seerah-7
                getFunc = function() return db.warningLevel end,
162 Seerah-7
                setFunc = function(value) db.warningLevel = value end,
163 Seerah-7
                width = "half",
164 Seerah-7
                default = defaults.warningLevel,
165 Seerah-7
        },
166 Seerah-7
        [8] = {
167 Seerah-7
                type = "checkbox",
168 Seerah-7
                name = "Low Health Texture",
169 Seerah-7
                tooltip = "Display a texture when your target's health gets low.",
170 Seerah-7
                getFunc = function() return db.lowHealth end,
171 Seerah-7
                setFunc = function(value)
172 Seerah-7
                                                db.lowHealth = value
173 Seerah-7
                                                if db.lowHealth and not lowHealth then CreateLowHealthTexture() end
174 Seerah-7
                                        end,
175 Seerah-7
                width = "half",
176 Seerah-7
                default = defaults.lowHealth,
177 Seerah-7
        },
178 Seerah-7
        [9] = {
179 Seerah-7
                type = "slider",
180 Seerah-7
                name = "Health Threshold",
181 Seerah-7
                tooltip = "Display the low health texture if the target is at this health percentage.",
182 Seerah-7
                min = 5,
183 Seerah-7
                max = 95,
184 Seerah-7
                step = 5,
185 Seerah-7
                getFunc = function() return db.healthLevel end,
186 Seerah-7
                setFunc = function(value) db.healthLevel = value end,
187 Seerah-7
                width = "half",
188 Seerah-7
                default = defaults.healthLevel,
189 Seerah-7
        },
190 Seerah-7
 
191 Seerah-7
}
192 Seerah-7
 
193 Seerah-7
local function CreateOptions()
194 Seerah-7
        local LAM = LibStub("LibAddonMenu-2.0")
195 Seerah-7
        LAM:RegisterAddonPanel("ZAMReactionColorsOptions", panelData)
196 Seerah-7
        LAM:RegisterOptionControls("ZAMReactionColorsOptions", optionsData)
197 2 Seerah-7
end
198 Seerah-7
 
199 Seerah-7
local function Initialize()
200 Seerah-7
        ZAM_ReactionColorsDB = ZAM_ReactionColorsDB or {}
201 Seerah-7
        for k,v in pairs(defaults) do
202 Seerah-7
            if type(ZAM_ReactionColorsDB[k]) == "nil" then
203 Seerah-7
                ZAM_ReactionColorsDB[k] = v
204 Seerah-7
            end
205 Seerah-7
        end
206 Seerah-7
        db = ZAM_ReactionColorsDB
207 Seerah-7
 
208 9 Seerah-7
        if db.lowHealth then
209 Seerah-7
                CreateLowHealthTexture()
210 Seerah-7
        end
211 2 Seerah-7
        if db.warning then
212 Seerah-7
                CreateWarningTexture()
213 Seerah-7
        end
214 Seerah-7
 
215 Seerah-7
        CreateOptions()
216 Seerah-7
end
217 Seerah-7
 
218 Seerah-7
 
219 Seerah-7
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_RETICLE_TARGET_CHANGED, UpdateColor)
220 3 Seerah-7
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_MOUSEOVER_CHANGED, UpdateColor)
221 2 Seerah-7
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_DISPOSITION_UPDATE, UpdateColor)
222 9 Seerah-7
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_POWER_UPDATE, function(event, unitTag, powerIndex, powerType, powerValue, powerMax, powerEffectiveMax)
223 Seerah-7
                if unitTag == "reticleover" and db.lowHealth and powerType == POWERTYPE_HEALTH then
224 Seerah-7
                        lowHealth:SetHidden(powerValue/powerEffectiveMax*100 > db.healthLevel)
225 Seerah-7
                end
226 Seerah-7
        end)
227 2 Seerah-7
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_ADD_ON_LOADED, function(event, addon)
228 Seerah-7
                if addon == "ZAM_ReactionColors" then
229 Seerah-7
                        Initialize()
230 Seerah-7
                end
231 11 Seerah-7
        end)
232 Seerah-7
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_LEVEL_UPDATE, function() playerLevel = GetUnitLevel("player") end)