Code:
-- =====================================================================
-- This script creates a color indicator frame in World of Warcraft
-- It reads text from ConROWindow and changes colors based on the number displayed
-- The frame changes to white during casting, channeling, or when GCD is active
-- =====================================================================
-- Clean up any existing frame to prevent duplicates
if ColorFrame then
ColorFrame:Hide()
ColorFrame:ClearAllPoints()
ColorFrame:SetParent(nil)
ColorFrame = nil
end
-- Define color mapping array
-- Each entry contains RGB values (red, green, blue) from 0 to 1
-- Index corresponds to the number displayed in ConROWindow (0-9)
local colors = {
{1, 0, 0}, -- 0: Red
{0, 1, 0}, -- 1: Green
{0, 0, 1}, -- 2: Blue
{1, 1, 0}, -- 3: Yellow
{1, 0, 1}, -- 4: Magenta
{0, 1, 1}, -- 5: Cyan
{0.5, 0.5, 0.5}, -- 6: Gray
{1, 0.5, 0}, -- 7: Orange
{0, 1, 0.5}, -- 8: Turquoise
{0.5, 0, 1} -- 9: Purple
}
-- Create the main frame
-- Attaches to WorldFrame to ensure it's always visible
-- Uses BackdropTemplate for visual debugging
local f = CreateFrame("Frame", "ColorFrame", WorldFrame, "BackdropTemplate")
f:SetHeight(1)
f:SetWidth(1)
f:SetPoint("TOPLEFT", WorldFrame, "TOPLEFT", 0, 0) -- Position at top-left corner
f:SetIgnoreParentScale(true) -- Prevent inheritance of parent's scaling
f:SetScale(1)
-- Create and setup the texture for the frame
-- Uses a white 8x8 texture as base which will be colored
local t = f:CreateTexture(nil, "ARTWORK")
t:SetTexture("Interface\\BUTTONS\\WHITE8X8")
t:SetTexCoord(0.07, 0.93, 0.07, 0.93) -- Adjust texture coordinates to prevent bleeding
t:SetAllPoints(f) -- Make texture fill the entire frame
t:SetVertexColor(1, 1, 1, 1) -- Start with white color
f.texture = t
-- Add a debug backdrop to make frame visible during development
-- Creates a black semi-transparent background with a black border
f:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
edgeSize = 1,
})
f:SetBackdropColor(0, 0, 0, 0.5) -- Semi-transparent black background
f:SetBackdropBorderColor(0, 0, 0, 1) -- Solid black border
-- Update timing configuration
local updateInterval = 0.1 -- Check for updates every 0.1 seconds
local timeSinceLastUpdate = 0
-- Function to check if Global Cooldown (GCD) is active
-- Uses spell ID 61304 which represents the global cooldown
local function IsGCDActive()
local spellCooldownInfo = C_Spell.GetSpellCooldown(61304)
if spellCooldownInfo.startTime == 0 then return false end
return (spellCooldownInfo.startTime + spellCooldownInfo.duration - GetTime()) > 0
end
-- Main update function that runs on every frame
f:SetScript("OnUpdate", function(self, elapsed)
timeSinceLastUpdate = timeSinceLastUpdate + elapsed
-- Only update at specified interval to reduce performance impact
if timeSinceLastUpdate >= updateInterval then
timeSinceLastUpdate = 0
-- Check player state (casting, channeling, GCD)
local casting = UnitCastingInfo("player") ~= nil
local channeling = UnitChannelInfo("player") ~= nil
local gcdActive = IsGCDActive()
-- Set color to white if player is casting, channeling, or GCD is active
if casting or channeling or gcdActive then
t:SetVertexColor(1, 1, 1, 1)
return
end
-- Color logic when player is not casting and GCD is not active
-- Reads number from ConROWindow and sets corresponding color
if ConROWindow and ConROWindow.fontkey and ConROWindow.fontkey:IsVisible() then
local text = ConROWindow.fontkey:GetText()
if text then
local number = tonumber(text)
if number and colors[number + 1] then
-- Set color from our color mapping array
local r, g, b = unpack(colors[number + 1])
t:SetVertexColor(r, g, b, 1)
else
-- Default to white if number is invalid
t:SetVertexColor(1, 1, 1, 1)
end
else
-- Default to white if no text
t:SetVertexColor(1, 1, 1, 1)
end
else
-- Default to white if ConROWindow is not visible
t:SetVertexColor(1, 1, 1, 1)
end
end
end)
-- Show the frame
f:Show()
--print("ColorFrame script loaded successfully!") -- Debug message