Quantcast
WoWInterface: SVN - oUF_Industrial - Rev 33 - /trunk/Addon.lua

WoWInterface SVN oUF_Industrial

[/] [trunk/] [Addon.lua] - Rev 33

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

local _G = _G
local TL, TC, TR = 'TOPLEFT', 'TOP', 'TOPRIGHT'
local ML, MC, MR = 'LEFT', 'CENTER', 'RIGHT'
local BL, BC, BR = 'BOTTOMLEFT', 'BOTTOM', 'BOTTOMRIGHT'

local frame_name = 'oUF_Industrial_'

local padding = 3
local spacing = 1
local margin = 1

local bar_width = 300 - padding * 2
local bar_texture = [[Interface\AddOns\oUF_Industrial\media\textures\statusbar]]

local health_width = bar_width
local health_height = 25
local health_texture = bar_texture

local power_width = bar_width
local power_height = 5
local power_texture = bar_texture

local text_inset = 3
local text_font = _G.GameFontNormal:GetFont()
local text_color = {1, 1, 1}

local colors_raid = _G.RAID_CLASS_COLORS
local pethappiness = {':<',':|',':3'}
local shortclassnames = {
        DEATHKNIGHT = 'DK',
        DRUID = 'DR',
        HUNTER = 'HT',
        MAGE = 'MG',
        PALADIN = 'PL',
        PRIEST = 'PR',
        ROGUE = 'RG',
        SHAMAN = 'SH',
        WARLOCK = 'WL',
        WARRIOR = 'WR',
}

local show_menu
local unit_class
local unit_level
local unit_name
local unit_tapped
local update_health
local update_power
local update_name
local create_unitframe
local create_pet_unitframe
local create_party_unitframe
local target_onupdate

function show_menu (frame)
        local unit = frame.unit:sub(1, -2)
        local cunit = frame.unit:gsub("(.)", string.upper, 1)

        if(unit == "party" or unit == "partypet") then
                ToggleDropDownMenu(1, nil, _G["PartyMemberFrame"..frame.id.."DropDown"], "cursor", 0, 0)
        elseif(_G[cunit.."FrameDropDown"]) then
                ToggleDropDownMenu(1, nil, _G[cunit.."FrameDropDown"], "cursor", 0, 0)
        end
end

function unit_class (unit)
        local class = select(2, UnitClass(unit))
        local color = RAID_CLASS_COLORS[class]

        return color and ('|cff%02X%02X%02X%s|r'):format(color.r*255, color.g*255, color.b*255, shortclassnames[class]) or ''
end

function unit_level (unit)
        local color = GetDifficultyColor(UnitLevel(unit))
        return color and ('|cff%02X%02X%02X%s|r'):format(color.r*255, color.g*255, color.b*255, UnitLevel(unit))
end

function unit_name (unit)
        return ('|cff%s%s|r'):format(UnitIsFriend(unit, 'player') == 1 and '00ff00' or 'ff0000', UnitName(unit))
end

function unit_tapped (unit)
        if UnitIsTapped(unit) then
                if UnitIsTappedByPlayer(unit) then
                        return '|cff00ff00*|r'
                end
                return '|cffff0000*|r'
        end
        return ''
end

function update_health (frame, event, unit, bar, min, max)
        bar.value:SetText(min)
        update_name(frame)
end

function update_power (frame, event, unit, bar, min, max)
        bar.value:SetText(min > 0 and min or '')
        update_name(frame)
end

function update_name (frame)
        local unit = frame.unit
        if not UnitExists(unit) then return end

        frame.Name:SetText(('%s %s %s%s'):format(
                unit_level(unit),
                unit_class(unit),
                unit_name(unit),
                unit_tapped(unit)
        ))
end

function create_unitframe (frame, unit)
        local background = frame:CreateTexture(nil, 'BACKGROUND')
        local health = CreateFrame('StatusBar', nil, frame)
        local power = CreateFrame('StatusBar', nil, frame)
        local buffs = CreateFrame('Frame', nil, frame)
        local debuffs = CreateFrame('Frame', nil, frame)
        local rlicon = health:CreateTexture(nil, 'OVERLAY')
        local ricon = health:CreateTexture()
        local mlicon = health:CreateTexture()
        local threat = health:CreateTexture()
        local castbar = CreateFrame('StatusBar', nil, health)
        health.info = health:CreateFontString(nil, 'OVERLAY')
        health.value = health:CreateFontString(nil, 'OVERLAY')
        power.info = power:CreateFontString(nil, 'OVERLAY')
        power.value = power:CreateFontString(nil, 'OVERLAY')
        frame.menu = show_menu
        castbar.Icon = castbar:CreateTexture()

        -- healthbar
        health:SetPoint(TL, frame, TL, padding, -padding)
        health:SetWidth(health_width)
        health:SetHeight(health_height)
        health:SetStatusBarTexture(health_texture)
        health:SetStatusBarColor(0.25, 0.25, 0.25)

        health.info:SetPoint(ML, health, ML, text_inset, 0)
        health.info:SetJustifyH('LEFT')
        health.info:SetFont(text_font, 10)
        health.info:SetTextColor(unpack(text_color))
        health.info:SetShadowColor(0, 0, 0)
        health.info:SetShadowOffset(1, -1)

        health.value:SetPoint(MR, health, MR, -text_inset, 0)
        health.value:SetJustifyH('RIGHT')
        health.value:SetFont(text_font, 10)
        health.value:SetTextColor(unpack(text_color))
        health.value:SetShadowColor(0, 0, 0)
        health.value:SetShadowOffset(1, -1)

        -- powerbar
        power:SetPoint(TL, health, BL, 0, -spacing)
        power:SetWidth(power_width)
        power:SetHeight(power_height)
        power:SetStatusBarTexture(power_texture)
        power:SetStatusBarColor(128/255, 255/255, 0)

        power.info:SetPoint(ML, power, ML, text_inset, 0)
        power.info:SetJustifyH('LEFT')
        power.info:SetFont(text_font, 10)
        power.info:SetTextColor(unpack(text_color))
        power.info:SetShadowColor(0, 0, 0)
        power.info:SetShadowOffset(1, -1)

        power.value:SetPoint(MR, health.value, ML, -text_inset, 0)
        power.value:SetJustifyH('RIGHT')
        power.value:SetFont(text_font, 10)
        power.value:SetTextColor(unpack(text_color))
        power.value:SetShadowColor(0, 0, 0)
        power.value:SetShadowOffset(1, -1)

        -- castbar
        --[[castbar.Icon:SetPoint(ML, power, ML)
        castbar.Icon:SetWidth(power:GetHeight())
        castbar.Icon:SetHeight(power:GetHeight())]]

        --[[castbar:SetPoint(TL, castbar.Icon, TR)
        castbar:SetPoint(BL, castbar.Icon, BR)
        castbar:SetPoint(TR, power, TR)
        castbar:SetPoint(BR, power, BR)]]
        castbar:SetAllPoints(power)
        castbar:SetToplevel(true)
        castbar:SetStatusBarTexture(health_texture)
        --castbar:SetStatusBarColor(128/255, 255/255, 0, 0.5)
        castbar:SetStatusBarColor(0.25, 0.5, 1)

        -- buffs
        local size = 16
        local height = health_height + spacing + power_height
        local width = health_width / 2
        local number = math.floor(width / size) * 2 -- times two for two lines vertically
        buffs:SetPoint(TR, frame, TL, -padding / 2, -padding)
        buffs:SetWidth(width)
        buffs:SetHeight(height)
        buffs.size = size
        buffs.num = number
        buffs.initialAnchor = TR
        buffs['growth-x'] = 'LEFT'
        buffs['growth-y'] = 'DOWN'

        debuffs:SetPoint(ML, frame, MR, padding / 2, -padding)
        debuffs:SetWidth(width)
        debuffs:SetHeight(height)
        debuffs.size = size
        debuffs.num = number
        debuffs.initialAnchor = TL
        debuffs['growth-x'] = 'LEFT'
        debuffs['growth-y'] = 'DOWN'

        -- rlicon icon
        rlicon:SetPoint(MC, frame, TL)
        rlicon:SetWidth(16)
        rlicon:SetHeight(16)

        -- raid icon
        ricon:SetPoint(MC, frame, TC)
        ricon:SetWidth(16)
        ricon:SetHeight(16)

        -- master looter icon
        mlicon:SetPoint(ML, rlicon, MR)
        mlicon:SetWidth(16)
        mlicon:SetHeight(16)

        -- threat
        threat:SetPoint(MC, frame, TR)
        threat:SetWidth(16)
        threat:SetHeight(16)

        -- frame
        frame:RegisterForClicks('anyup')
        frame:SetAttribute('type2', 'menu')
        frame:SetAttribute('initial-width', health_width + padding * 2)
        frame:SetAttribute('initial-height', health_height + power_height + padding * 2 + spacing)

        background:SetAllPoints(frame)
        background:SetTexture(0, 0, 0, 1)

        frame.Health = health
        frame.PostUpdateHealth = update_health
        frame.Power = power
        frame.PostUpdatePower = update_power
        frame.Name = health.info
        frame.Info = power.info
        frame.Castbar = castbar
        frame.Buffs = buffs
        frame.Debuffs = debuffs
        frame.Leader = rlicon
        frame.RaidIcon = ricon
        frame.MasterLooter = mlicon
        frame.Threat = threat
end

function create_pet_unitframe(frame, unit)
        create_unitframe(frame, unit)

        local happiness = frame.Health:CreateTexture()
        happiness:SetPoint(MC, frame, BR)
        happiness:SetWidth(16)
        happiness:SetHeight(16)

        frame.Happiness = happiness
end

function create_party_unitframe (frame, unit)
        create_unitframe(frame, unit)

        -- out of range fading
        frame.Range = true
        frame.inRangeAlpha = 1
        frame.outsideRangeAlpha = 0.5

        local buffs = frame.Buffs

        local size = 16
        local width = power_width
        local height = size
        local number = math.floor(width / size)
        buffs:SetPoint(TC, frame, BC, 0, -padding / 2)
        buffs:SetWidth(width)
        buffs:SetHeight(height)
        buffs.size = size
        buffs.num = number
        buffs.initialAnchor = TL
        buffs['growth-x'] = MR
        buffs['growth-y'] = BC
end

function target_onupdate (frame)
        -- the default ouf .+target updating is .5 seconds, I'd like it instant
        frame:PLAYER_ENTERING_WORLD('OnTargetUpdate')
end

oUF:RegisterStyle('Industrial', create_unitframe)
oUF:RegisterStyle('Industrial-pet', create_pet_unitframe)
oUF:RegisterStyle('Industrial-party', create_party_unitframe)

oUF:SetActiveStyle('Industrial-pet')
local pet          = oUF:Spawn('pet', frame_name..'pet')
oUF:SetActiveStyle('Industrial')
local player       = oUF:Spawn('player', frame_name..'player')
local target       = oUF:Spawn('target', frame_name..'target')
local targettarget = oUF:Spawn('targettarget', frame_name..'targettarget')
oUF:SetActiveStyle('Industrial-party')
local party1       = oUF:Spawn('party1', frame_name..'party1')
local party2       = oUF:Spawn('party2', frame_name..'party2')
local party3       = oUF:Spawn('party3', frame_name..'party3')
local party4       = oUF:Spawn('party4', frame_name..'party4')

targettarget:SetScript('OnUpdate', target_onupdate)

pet:SetPoint(MC, UIParent, MC, 0, -300)
player:SetPoint(BC, pet, TC, 0, margin)
target:SetPoint(BC, player, TC, 0, margin)
targettarget:SetPoint(BC, target, TC, 0, margin)

party1:SetPoint(ML, UIParent, ML)
party2:SetPoint(TC, party1, BC, 0, -20)
party3:SetPoint(TC, party2, BC, 0, -20)
party4:SetPoint(TC, party3, BC, 0, -20)

Go to most recent revision | Compare with Previous | Blame