Compare with Previous | Blame | View Log
-- ZAM_ReactionColors © ZAM Network LLC
-- All Rights Reserved
local versionNo = "1.2"
local f = WINDOW_MANAGER:CreateTopLevelWindow("ZAM_ReactionColors")
local reticle = ZO_ReticleContainerReticle
local stealthEye = ZO_ReticleContainerStealthEye
local GetUnitReactionColor = GetUnitReactionColor
local DoesUnitExist = DoesUnitExist
local GetUnitLevel = GetUnitLevel
local GetUnitReaction = GetUnitReaction
local GetConColor = GetConColor
local playerLevel = GetUnitLevel("player")
local reaction, targetName, targetLevel, warning, lowHealth, db
local colorByChoices = {"Reaction", "Level", "Level if hostile", "Disabled"}
local defaults = {
warning = true,
warningLevel = 5,
lowHealth = false,
healthLevel = 25,
colorBy = "Reaction",
colorTargetName = true,
colorTargetLevel = true,
}
local function CreateWarningTexture()
warning = WINDOW_MANAGER:CreateControl("ReactionColorsReticleWarning", ZO_ReticleContainer, CT_TEXTURE)
warning:SetTexture("ZAM_ReactionColors\\levelWarning.dds")
warning:SetDimensions(130,130)
warning:SetAnchor(CENTER, ZO_ReticleContainer, CENTER, 0, 0)
warning:SetColor(1, 0, 0, 1)
warning:SetHidden(true)
end
local function CreateLowHealthTexture()
lowHealth = WINDOW_MANAGER:CreateControl("ReactionColorsReticleLowHealth", ZO_ReticleContainer, CT_TEXTURE)
lowHealth:SetTexture("ZAM_ReactionColors\\targetLowHealth.dds")
lowHealth:SetDimensions(130,130)
lowHealth:SetAnchor(CENTER, ZO_ReticleContainer, CENTER, 0, 0)
lowHealth:SetColor(1, 0, 0, 1)
lowHealth:SetHidden(true)
end
local function UpdateColor()
if DoesUnitExist("reticleover") then
local r, g, b = GetUnitReactionColor("reticleover")
local level = GetUnitLevel("reticleover")
local r2, g2, b2 = GetConColor(level, playerLevel)
local hostile = GetUnitReaction("reticleover") == UNIT_REACTION_HOSTILE
if db.colorBy == "Reaction" then
reticle:SetColor(r, g, b)
stealthEye:SetColor(r, g, b)
elseif db.colorBy == "Level" or (db.colorBy == "Level if hostile" and hostile) then
reticle:SetColor(r2, g2, b2)
stealthEye:SetColor(r2, g2, b2)
--[[elseif db.colorBy == "Level if hostile" and hostile then
reticle:SetColor(r2, g2, b2)
stealthEye:SetColor(r2, g2, b2)]]
end
if db.colorTargetName then
if not targetName then targetName = ZO_TargetUnitFramereticleoverName end
targetName:SetColor(r, g, b, 1)
end
if db.colorTargetLevel then
if not targetLevel then targetLevel = ZO_TargetUnitFramereticleoverLevel end
targetLevel:SetColor(r2, g2, b2)
end
if warning and db.warning then
if hostile and (level - playerLevel >= db.warningLevel) then
warning:SetHidden(false)
end
end
if lowHealth and db.lowHealth and not hostile and not lowHealth:IsHidden() then
lowHealth:SetHidden(true)
end
else
if warning then warning:SetHidden(true) end
reticle:SetColor(1, 1, 1, 1)
stealthEye:SetColor(1, 1, 1, 1)
if lowHealth and db.lowHealth then lowHealth:SetHidden(true) end
end
end
local panelData = {
type = "panel",
name = "ZAM ReactionColors",
displayName = "|t72:36:ZAM_Stats\\ZAM_Logo.dds|t ReactionColors",
author = "Seerah",
version = versionNo,
slashCommand = "/zamrc",
registerForDefaults = true, --add resetFunc to move UFs back to default position
}
local optionsData = {
[1] = {
type = "header",
name = "Coloring Options",
},
[2] = {
type = "dropdown",
name = "Color the targeting reticle by...",
tooltip = "Select when to color the targeting reticle.",
choices = colorByChoices,
getFunc = function() return db.colorBy end,
setFunc = function(colorBy) db.colorBy = colorBy end,
default = defaults.colorBy,
},
[3] = {
type = "checkbox",
name = "Color Target's Name",
tooltip = "Color the target's name by reaction.",
getFunc = function() return db.colorTargetName end,
setFunc = function(value)
db.colorTargetName = value
if not db.colorTargetName then
targetName:SetColor(1, 1, 1)
end
end,
width = "half",
default = defaults.colorTargetName,
},
[4] = {
type = "checkbox",
name = "Color Target's Level",
tooltip = "Color the target's level by difficulty.",
getFunc = function() return db.colorTargetLevel end,
setFunc = function(value)
db.colorTargetLevel = value
if not db.colorTargetLevel then
targetLevel:SetColor(1, 1, 1)
end
end,
width = "half",
default = defaults.colorTargetLevel,
},
[5] = {
type = "header",
name = "Alert Texture Options",
},
[6] = {
type = "checkbox",
name = "Warning Texture",
tooltip = "Display a warning texture for high level hostile targets.",
getFunc = function() return db.warning end,
setFunc = function(value)
db.warning = value
if db.warning and not warning then CreateWarningTexture() end
end,
width = "half",
default = defaults.warning,
},
[7] = {
type = "slider",
name = "Warning Threshold",
tooltip = "Display the warning icon if the target is this many levels higher than you.",
min = 2,
max = 10,
step = 1,
getFunc = function() return db.warningLevel end,
setFunc = function(value) db.warningLevel = value end,
width = "half",
default = defaults.warningLevel,
},
[8] = {
type = "checkbox",
name = "Low Health Texture",
tooltip = "Display a texture when your target's health gets low.",
getFunc = function() return db.lowHealth end,
setFunc = function(value)
db.lowHealth = value
if db.lowHealth and not lowHealth then CreateLowHealthTexture() end
end,
width = "half",
default = defaults.lowHealth,
},
[9] = {
type = "slider",
name = "Health Threshold",
tooltip = "Display the low health texture if the target is at this health percentage.",
min = 5,
max = 95,
step = 5,
getFunc = function() return db.healthLevel end,
setFunc = function(value) db.healthLevel = value end,
width = "half",
default = defaults.healthLevel,
},
}
local function CreateOptions()
local LAM = LibStub("LibAddonMenu-2.0")
LAM:RegisterAddonPanel("ZAMReactionColorsOptions", panelData)
LAM:RegisterOptionControls("ZAMReactionColorsOptions", optionsData)
end
local function Initialize()
ZAM_ReactionColorsDB = ZAM_ReactionColorsDB or {}
for k,v in pairs(defaults) do
if type(ZAM_ReactionColorsDB[k]) == "nil" then
ZAM_ReactionColorsDB[k] = v
end
end
db = ZAM_ReactionColorsDB
if db.lowHealth then
CreateLowHealthTexture()
end
if db.warning then
CreateWarningTexture()
end
CreateOptions()
end
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_RETICLE_TARGET_CHANGED, UpdateColor)
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_MOUSEOVER_CHANGED, UpdateColor)
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_DISPOSITION_UPDATE, UpdateColor)
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_POWER_UPDATE, function(event, unitTag, powerIndex, powerType, powerValue, powerMax, powerEffectiveMax)
if unitTag == "reticleover" and db.lowHealth and powerType == POWERTYPE_HEALTH then
lowHealth:SetHidden(powerValue/powerEffectiveMax*100 > db.healthLevel)
end
end)
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_ADD_ON_LOADED, function(event, addon)
if addon == "ZAM_ReactionColors" then
Initialize()
end
end)
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_LEVEL_UPDATE, function() playerLevel = GetUnitLevel("player") end)