-- frame.lua -- 2019 Aleksi Blinnikka local _, addon = ...; local unpack = unpack; local format = string.format; local CreateFrame = CreateFrame; local CTimerAfter = C_Timer.After; local guids = addon.FrameGuids; local updaters = {}; local function showTooltip(frame) GameTooltip_SetDefaultAnchor(GameTooltip, frame); GameTooltip:SetUnit(frame:GetAttribute("unit")); end local function hideTooltip(frame) if GameTooltip:IsOwned(frame) then GameTooltip:FadeOut() end end local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist"; local frameid = 1; function addon.NewRaidFrame(parent, width, height, unit, attributes, update, event, onshow) assert(type(parent) == "table", "Frame creation missing parent!"); assert(type(width) == "number", "Frame creation missing width!"); assert(type(height) == "number", "Frame creation missing height!"); assert(type(unit) == "string", "Frame creation missing unit!"); assert(type(update) == "function", "Frame creation missing update function!"); assert(type(event) == "function", "Frame creation missing event function!"); assert(type(onshow) == "function", "Frame creation missing onshow function!"); if type(attributes) ~= "table" then attributes = {}; end local f = CreateFrame( "Button", format("kehys%i", frameid), parent, "SecureUnitButtonTemplate,SecureHandlerStateTemplate" ); frameid = frameid + 1; f:Hide(); -- hide frame to have an initial frame:OnShow call f:SetWidth(width); f:SetHeight(height); f.barwidth = width - 2; -- 1px padding on both sides f:SetAttribute("unit", unit); f.unit = unit; f.displayed = unit; f.vehicle = unit == "player" and "vehicle" or format("%spet", unit); f.prev = {} -- values stored from previous update f.alert = {}; -- alerting auras f.heal = {}; -- high healing auras f.tankcd = {}; -- tank CD auras f.stacks = {}; -- stacking aura tracking f.buff1 = {}; -- custom buff indicator 1 f.buff2 = {}; -- custom buff indicator 2 f.incoming = {}; -- incoming ability indicator f.rounds = 0; -- set up periodic updates updaters[f] = function() if f.updating then CTimerAfter(0.1, updaters[f]); return update(f) end end -- set scripts f:SetScript("OnShow", function() onshow(f); f.updating = true; updaters[f](); end); f:SetScript("OnHide", function() f:UnregisterAllEvents(); f.updating = false; if f.guid then guids[f.guid] = nil; f.guid = nil; end end); f:SetScript("OnEvent", event); f:SetScript("OnEnter", showTooltip); f:SetScript("OnLeave", hideTooltip); -- set attributes f:RegisterForClicks("AnyDown"); for attr, val in pairs(attributes) do f:SetAttribute(attr, val); end -- rest give target and menu f:SetAttribute("*type1", "target"); f:SetAttribute("*type2", "togglemenu"); -- create visuals f.base = f:CreateTexture(nil, "BACKGROUND"); f.base:SetAllPoints(); f.base:SetColorTexture(1, 1, 1); f.base:SetVertexColor(unpack(addon.Colors.Base)); f.glow = f:CreateTexture(nil, "BACKGROUND", nil, 1); f.glow:SetAllPoints(); f.glow:SetColorTexture(1, 1, 1); f.glow:SetVertexColor(unpack(addon.Colors.Glow)); f.background = f:CreateTexture(nil, "BACKGROUND", nil, 2); f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1); f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1); f.background:SetColorTexture(0.7, 0.7, 0.7); f.health = f:CreateTexture(nil, "BORDER"); f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT"); f.health:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT"); f.health:SetTexture(barTexture); f.health:SetVertexColor(0.3, 0.3, 0.3); f.health:Hide(); f.shield = f:CreateTexture(nil, "BORDER"); f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT"); f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT"); f.shield:SetTexture(barTexture); f.shield:SetVertexColor(0, 0.7, 1); f.shield:Hide(); f.shieldhl = f:CreateTexture(nil, "ARTWORK"); f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0); f.shieldhl:SetPoint("BOTTOMRIGHT"); f.shieldhl:SetColorTexture(0.5, 0.8, 1); f.shieldhl:Hide(); f.healpred = f:CreateTexture(nil, "ARTWORK"); f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT"); f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT"); f.healpred:SetColorTexture(0.5, 0.6, 0.5); f.healpred:Hide(); f.healabsorb = f:CreateTexture(nil, "ARTWORK"); f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT"); f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT"); f.healabsorb:SetColorTexture(0.1, 0.1, 0.1); f.healabsorb:Hide(); f.overlay = f:CreateTexture(nil, "ARTWORK", nil, 1); f.overlay:SetPoint("TOPLEFT", f.background, "TOPLEFT"); f.overlay:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT"); f.overlay:SetColorTexture(1, 1, 1); f.overlay:Hide(); f.role = f:CreateTexture(nil, "ARTWORK", nil, 2); f.role:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -3, 3); f.role:SetPoint("TOPLEFT", f, "BOTTOMRIGHT", -15, 15); f.role:SetTexture("Interface\\LFGFRAME\\LFGROLE"); f.role:Hide(); f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); f.name:SetPoint("CENTER", f, "CENTER", 0, 11); f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); f.text:SetPoint("CENTER", f, "CENTER", 0, -1); f.text:SetFont(STANDARD_TEXT_FONT, 13); f.text:Hide(); f.stack = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall"); f.stack:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT"); f.stack:Hide(); f.ready = f:CreateTexture(nil, "OVERLAY"); f.ready:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 1, 15); f.ready:SetPoint("BOTTOMRIGHT", f, "BOTTOMLEFT", 15, 1); f.ready:Hide(); f.buffind1 = f:CreateTexture(nil, "OVERLAY"); f.buffind1:SetPoint("TOPRIGHT", f.background, "TOPRIGHT", -1, -1); f.buffind1:SetWidth(6); f.buffind1:SetHeight(6); f.buffind1:SetColorTexture(0.8, 0.1, 0.1); f.buffind1:Hide(); f.buffind2 = f:CreateTexture(nil, "OVERLAY"); f.buffind2:SetPoint("TOPLEFT", f.background, "TOPLEFT", 1, -1); f.buffind2:SetWidth(4); f.buffind2:SetHeight(4); f.buffind2:SetColorTexture(0.8, 0.7, 0.1); f.buffind2:Hide(); f.defensive = f:CreateTexture(nil, "OVERLAY", nil, 1); f.defensive:SetPoint("TOPLEFT", f.background, "TOPLEFT", 1, -1); f.defensive:SetWidth(6); f.defensive:SetHeight(6); f.defensive:SetColorTexture(1, 0.3, 0); f.defensive:Hide(); f.targeticon = f:CreateTexture(nil, "OVERLAY"); f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1); f.targeticon:SetWidth(12); f.targeticon:SetHeight(12); f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons"); f.targeticon:Hide(); return f; end