4 local format = string.format;
5 local CFrame = CreateFrame("Frame", "kehysTargetInit", UIParent);
6 local CTimerAfter = C_Timer.After;
8 local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist";
10 local function showTooltip(frame)
11 GameTooltip_SetDefaultAnchor(GameTooltip, frame);
12 GameTooltip:SetUnit(frame:GetAttribute("unit"));
15 local function hideTooltip()
16 GameTooltip:FadeOut();
19 local targetUpdate = nil;
20 local function initTarget(parent, width, height, update, event)
21 assert(type(parent) == "table", "Target frame creation missing parent!");
22 assert(type(width) == "number", "Target frame creation missing width!");
23 assert(type(height) == "number", "Target frame creation missing height!");
24 assert(type(update) == "function",
25 "Target frame creation missing update function!");
26 assert(type(event) == "function",
27 "Target frame creation missing event function!");
29 local f = CreateFrame("Button", "kehysTarget", parent,
30 "SecureUnitButtonTemplate,SecureHandlerStateTemplate");
32 f:SetPoint("CENTER", parent, "CENTER", 290, -178);
35 f.barwidth = width - 2; -- 1px padding
36 f:SetAttribute("unit", "target");
37 f:SetAttribute("displayed", "target");
39 f.displayed = "target";
42 targetUpdate = function()
44 CTimerAfter(0.1, targetUpdate);
48 f:SetScript("OnEvent", event);
49 f:SetScript("OnHide", function()
50 f:UnregisterAllEvents();
54 f:SetScript("OnShow", function()
55 addon.RegisterEvents(f);
56 addon.RegisterUnitEvents(f);
57 event(f, "UPDATE_ALL_BARS");
61 f:SetScript("OnEnter", showTooltip);
62 f:SetScript("OnLeave", hideTooltip);
63 f:RegisterForClicks("AnyDown");
64 f:SetAttribute("*type1", "target");
65 f:SetAttribute("*type2", "togglemenu");
66 f:SetAttribute("toggleForVehicle", false);
69 f.base = f:CreateTexture(nil, "BACKGROUND");
70 f.base:SetAllPoints();
71 f.base:SetColorTexture(0, 0, 0, 0.5);
72 f.background = f:CreateTexture(nil, "BACKGROUND", nil, 1);
73 f.background:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
74 f.background:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1);
75 f.health = f:CreateTexture(nil, "BORDER");
76 f.health:SetPoint("TOPLEFT", f.background, "TOPLEFT");
77 f.health:SetPoint("BOTTOMLEFT", f.background, "LEFT", 0, -height/8);
78 f.health:SetTexture(barTexture);
79 f.health:SetVertexColor(0.7, 0.7, 0.7);
81 f.mana = f:CreateTexture(nil, "BORDER");
82 f.mana:SetPoint("TOPLEFT", f.background, "LEFT", 0, -height/8);
83 f.mana:SetPoint("BOTTOMLEFT", f.background, "BOTTOMLEFT");
84 f.mana:SetTexture(barTexture);
85 f.mana:SetVertexColor(0.1, 0.5, 0.9);
87 f.manatext = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
88 f.manatext:SetPoint("BOTTOMRIGHT", f.background, "BOTTOMRIGHT", -2, 4);
90 f.shield = f:CreateTexture(nil, "BORDER");
91 f.shield:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
92 f.shield:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
93 f.shield:SetTexture(barTexture);
94 f.shield:SetVertexColor(0, 0.7, 1);
96 f.shieldhl = f:CreateTexture(nil, "ARTWORK");
97 f.shieldhl:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0);
98 f.shieldhl:SetPoint("BOTTOMRIGHT", f, "RIGHT", 0, -height/8);
99 f.shieldhl:SetColorTexture(0.5, 0.8, 1);
101 f.healpred = f:CreateTexture(nil, "ARTWORK");
102 f.healpred:SetPoint("TOPLEFT", f.health, "TOPRIGHT");
103 f.healpred:SetPoint("BOTTOMLEFT", f.health, "BOTTOMRIGHT");
104 f.healpred:SetColorTexture(0.5, 0.6, 0.5);
106 f.healabsorb = f:CreateTexture(nil, "ARTWORK");
107 f.healabsorb:SetPoint("TOPRIGHT", f.health, "TOPRIGHT");
108 f.healabsorb:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT");
109 f.healabsorb:SetColorTexture(0.1, 0.1, 0.1);
111 f.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
112 f.name:SetPoint("LEFT", f, "LEFT", 2, 8);
113 f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
114 f.text:SetPoint("RIGHT", f, "RIGHT", -2, 8);
115 f.text:SetFont(STANDARD_TEXT_FONT, 15);
117 f.targeticon = f:CreateTexture(nil, "OVERLAY");
118 f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1);
119 f.targeticon:SetWidth(12);
120 f.targeticon:SetHeight(12);
121 f.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons");
124 RegisterUnitWatch(f);
128 CFrame:SetScript("OnEvent", function(self)
129 self:UnregisterAllEvents();
130 CFrame:SetFrameStrata("LOW");
131 CFrame:SetPoint("CENTER", nil, "CENTER");
134 initTarget(self, 160, 48, addon.FrameUpdate, addon.UnitEvent);
136 CFrame:RegisterEvent("PLAYER_LOGIN");