ESOUI SVN ZAMUnitFramesReactionColors

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Seerah-7
local f = WINDOW_MANAGER:CreateTopLevelWindow("ZAM_ReactionColors")
2 Seerah-7
local reticle = ZO_ReticleContainerReticle
3 Seerah-7
local stealthEye = ZO_ReticleContainerStealthEye
4 Seerah-7
local GetUnitReactionColor = GetUnitReactionColor
5 Seerah-7
local IsGameCameraUnitHightlightedValid = IsGameCameraUnitHightlightedValid
6 Seerah-7
local GetUnitLevel = GetUnitLevel
7 Seerah-7
local GetUnitReaction = GetUnitReaction
8 Seerah-7
local GetConColor = GetConColor
9 Seerah-7
local playerLevel = GetUnitLevel("player")
10 Seerah-7
local reaction, targetName, targetLevel, warning, db
11 Seerah-7
local colorByChoices = {"Reaction", "Level", "Level if hostile", "Disabled"}
12 Seerah-7
 
13 Seerah-7
local defaults = {
14 Seerah-7
        warning = true,
15 Seerah-7
        warningLevel = 5,
16 Seerah-7
        colorBy = "Reaction",
17 Seerah-7
        colorTargetName = true,
18 Seerah-7
        colorTargetLevel = true,
19 Seerah-7
}
20 Seerah-7
 
21 Seerah-7
 
22 Seerah-7
local function CreateWarningTexture()
23 Seerah-7
        warning = WINDOW_MANAGER:CreateControl("ReactionColorsReticleWarning", ZO_ReticleContainer, CT_TEXTURE)
24 Seerah-7
        --warning:SetTexture("EsoUI\\pts\\Addons\\ZAM_ReactionColors\\Aura7.dds")
25 Seerah-7
        warning:SetTexture("EsoUI\\Art\\TreeIcons\\tutorial_idexicon_death_down.dds")
26 Seerah-7
        warning:SetDimensions(85,85)
27 Seerah-7
        warning:SetAnchor(CENTER, ZO_ReticleContainer, CENTER, 0, -50)
28 Seerah-7
        warning:SetColor(1, 0, 0, .5)
29 Seerah-7
        warning:SetHidden(true)
30 Seerah-7
end
31 Seerah-7
 
32 Seerah-7
local function UpdateColor()
33 Seerah-7
        if IsGameCameraUnitHightlightedValid() then
34 Seerah-7
                local r, g, b = GetUnitReactionColor("reticleover")
35 Seerah-7
                local level = GetUnitLevel("reticleover")
36 Seerah-7
                local r2, g2, b2 = GetConColor(level, playerLevel)
37 Seerah-7
                local hostile = GetUnitReaction("reticleover") == UNIT_REACTION_HOSTILE
38 Seerah-7
                if db.colorBy == "Reaction" then
39 Seerah-7
                        reticle:SetColor(r, g, b)
40 Seerah-7
                        stealthEye:SetColor(r, g, b)
41 Seerah-7
                elseif db.colorBy == "Level" or (db.colorBy == "Level if hostile" and hostile) then
42 Seerah-7
                        reticle:SetColor(r2, g2, b2)
43 Seerah-7
                        stealthEye:SetColor(r2, g2, b2)
44 Seerah-7
                --[[elseif db.colorBy == "Level if hostile" and hostile then
45 Seerah-7
                        reticle:SetColor(r2, g2, b2)
46 Seerah-7
                        stealthEye:SetColor(r2, g2, b2)]]
47 Seerah-7
                end
48 Seerah-7
                if db.colorTargetName then
49 Seerah-7
                        if not targetName then targetName = ZO_TargetUnitFramereticleoverName end
50 Seerah-7
                        targetName:SetColor(r, g, b, 1)
51 Seerah-7
                end
52 Seerah-7
                if db.colorTargetLevel then
53 Seerah-7
                        if not targetLevel then targetLevel = ZO_TargetUnitFramereticleoverLevel end
54 Seerah-7
                        targetLevel:SetColor(r2, g2, b2)
55 Seerah-7
                end
56 Seerah-7
                if warning and db.warning then
57 Seerah-7
                        if hostile and (level - playerLevel >= db.warningLevel) then
58 Seerah-7
                                warning:SetHidden(false)
59 Seerah-7
                        else
60 Seerah-7
                                warning:SetHidden(true)
61 Seerah-7
                        end
62 Seerah-7
                end
63 Seerah-7
        else
64 Seerah-7
                reticle:SetColor(1, 1, 1, 1)
65 Seerah-7
                stealthEye:SetColor(1, 1, 1, 1)
66 Seerah-7
        end
67 Seerah-7
end
68 Seerah-7
 
69 Seerah-7
local function CreateOptions()
70 Seerah-7
        local LAM = LibStub("LibAddonMenu-1.0")
71 Seerah-7
        local zamPanel = LAM:CreateControlPanel("ZAM_ADDON_OPTIONS", "ZAM Addons")
72 Seerah-7
        LAM:AddHeader(zamPanel, "ZAM_ReactionColors_Options_Header", "ZAM ReactionColors")
73 Seerah-7
        LAM:AddDropdown(zamPanel, "ZAM_ReactionColors_Options_ColorBy", "Color the targeting reticle by...",
74 Seerah-7
                                        "Select when to color the targeting reticle.", colorByChoices,
75 Seerah-7
                                        function() return db.colorBy end,
76 Seerah-7
                                        function(colorBy)db.colorBy = colorBy end)
77 Seerah-7
        LAM:AddCheckbox(zamPanel, "ZAM_ReactionColors_Options_Warning", "Warning Icon", "Display a warning icon for high level hostile targets.",
78 Seerah-7
                                        function() return db.warning end,
79 Seerah-7
                                        function()
80 Seerah-7
                                                db.warning = not db.warning
81 Seerah-7
                                                if db.warning and not warning then CreateWarningTexture() end
82 Seerah-7
                                        end)
83 Seerah-7
        LAM:AddSlider(zamPanel, "ZAM_ReactionColors_Options_WarningLevel", "Warning Threshold",
84 Seerah-7
                                        "Display the warning icon if the target is this many levels higher than you.", 2, 10, 1,
85 Seerah-7
                                        function() return db.warningLevel end,
86 Seerah-7
                                        function(value) db.warningLevel = value end)
87 Seerah-7
        LAM:AddCheckbox(zamPanel, "ZAM_ReactionColors_Options_ColorTargetName", "Color Target's Name", "Color the target's name by reaction.",
88 Seerah-7
                                        function() return db.colorTargetName end,
89 Seerah-7
                                        function()
90 Seerah-7
                                                db.colorTargetName = not db.colorTargetName
91 Seerah-7
                                                if not db.colorTargetName then
92 Seerah-7
                                                        targetName:SetColor(1, 1, 1)
93 Seerah-7
                                                end
94 Seerah-7
                                        end)
95 Seerah-7
        LAM:AddCheckbox(zamPanel, "ZAM_ReactionColors_Options_ColorTargetLevel", "Color Target's Level", "Color the target's level by difficulty.",
96 Seerah-7
                                        function() return db.colorTargetLevel end,
97 Seerah-7
                                        function()
98 Seerah-7
                                                db.colorTargetLevel = not db.colorTargetLevel
99 Seerah-7
                                                if not db.colorTargetLevel then
100 Seerah-7
                                                        targetLevel:SetColor(1, 1, 1)
101 Seerah-7
                                                end
102 Seerah-7
                                        end)
103 Seerah-7
end
104 Seerah-7
 
105 Seerah-7
local function Initialize()
106 Seerah-7
        ZAM_ReactionColorsDB = ZAM_ReactionColorsDB or {}
107 Seerah-7
        for k,v in pairs(defaults) do
108 Seerah-7
            if type(ZAM_ReactionColorsDB[k]) == "nil" then
109 Seerah-7
                ZAM_ReactionColorsDB[k] = v
110 Seerah-7
            end
111 Seerah-7
        end
112 Seerah-7
        db = ZAM_ReactionColorsDB
113 Seerah-7
 
114 Seerah-7
        if db.warning then
115 Seerah-7
                CreateWarningTexture()
116 Seerah-7
        end
117 Seerah-7
 
118 Seerah-7
        CreateOptions()
119 Seerah-7
end
120 Seerah-7
 
121 Seerah-7
 
122 Seerah-7
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_RETICLE_TARGET_CHANGED, UpdateColor)
123 Seerah-7
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_DISPOSITION_UPDATE, UpdateColor)
124 Seerah-7
EVENT_MANAGER:RegisterForEvent("ZAM_ReactionColors", EVENT_ADD_ON_LOADED, function(event, addon)
125 Seerah-7
                if addon == "ZAM_ReactionColors" then
126 Seerah-7
                        Initialize()
127 Seerah-7
                end
128 Seerah-7
        end)