+-- target.lua
+local _, addon = ...;
+local unpack = unpack;
+local format = string.format;
+local CFrame = CreateFrame("Frame", "kehysTargetInit", UIParent);
+local CTimerAfter = C_Timer.After;
+
+local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist";
+
+local targetUpdate = nil;
+local function initTarget(parent, width, height, update, event)
+ assert(type(parent) == "table", "Target frame creation missing parent!");
+ assert(type(width) == "number", "Target frame creation missing width!");
+ assert(type(height) == "number", "Target frame creation missing height!");
+ assert(type(update) == "function",
+ "Target frame creation missing update function!");
+ assert(type(event) == "function",
+ "Target frame creation missing event function!");
+
+ local f = CreateFrame("Button", "kehysTarget", parent,
+ "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
+ f:Hide();
+ f:SetPoint("CENTER", parent, "CENTER", 300, -178);
+ f:SetWidth(width);
+ f:SetHeight(height);
+ f.barwidth = width - 2; -- 1px padding
+ f:SetAttribute("unit", "target");
+ f:SetAttribute("displayed", "target");
+ f.unit = "target";
+ f.displayed = "target";
+ f.nonraid = true;
+ f.prev = {};
+
+ targetUpdate = function()
+ CTimerAfter(0.1, targetUpdate);
+ update(f);
+ end
+ f:SetScript("OnEvent", event);
+ f:RegisterForClicks("AnyDown");
+ f:SetAttribute("*type1", "target");
+ f:SetAttribute("*type2", "togglemenu");
+ f:SetAttribute("toggleForVehicle", false);
+ RegisterUnitWatch(f);
+
+ -- create visuals
+ f.base = f:CreateTexture(nil, "BACKGROUND");
+ f.base:SetAllPoints();
+ f.base:SetColorTexture(0, 0, 0, 0.5);
+ f.background = f:CreateTexture(nil, "BACKGROUND", nil, 1);
+ f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
+ f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
+ f.health = f:CreateTexture(nil, "BORDER");
+ f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
+ f.health:SetPoint("BOTTOMLEFT", f.background, "LEFT", 0, -height/8);
+ f.health:SetTexture(barTexture);
+ f.health:SetVertexColor(0.8, 0.8, 0.8);
+ f.health:Hide();
+ f.mana = f:CreateTexture(nil, "BORDER");
+ f.mana:SetPoint("TOPLEFT", f.background, "LEFT", 0, -height/8);
+ f.mana:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
+ f.mana:SetTexture(barTexture);
+ f.mana:SetVertexColor(0.1, 0.5, 0.9);
+ f.mana:Hide();
+ f.manatext = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
+ f.manatext:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT", -2, 4);
+ f.manatext: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, "RIGHT", 0, -height/8);
+ 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.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
+ f.name:SetPoint("LEFT", f, "LEFT", 2, 8);
+ f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
+ f.text:SetPoint("RIGHT", f, "RIGHT", -2, 8);
+ f.text:SetFont(STANDARD_TEXT_FONT, 13);
+ f.text: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();
+ f.status = f:CreateTexture(nil, "OVERLAY");
+ f.status:SetPoint("TOPLEFT", f.background, "BOTTOMLEFT", -8, 8);
+ f.status:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMLEFT", 8, -8);
+ f.status:SetTexture("Interface\\CHARACTERFRAME\\UI-StateIcon");
+ f.status:Hide();
+
+ addon.RegisterEvents(f);
+ addon.RegisterUnitEvents(f);
+ event(f, "UPDATE_ALL_BARS");
+ targetUpdate();
+ f:Show();
+ return f;
+end
+
+CFrame:SetScript("OnEvent", function(self)
+ self:UnregisterAllEvents();
+ CFrame:SetFrameStrata("LOW");
+ CFrame:SetPoint("CENTER", nil, "CENTER");
+ CFrame:SetWidth(2);
+ CFrame:SetHeight(2);
+ initTarget(self, 160, 48, addon.FrameUpdate, addon.UnitEvent);
+end);
+CFrame:RegisterEvent("PLAYER_LOGIN");