X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/4fb357642ebf6b8b7f103bf86e67a44de1dd00a7..52f2ef034b1fad1d0fa815270adee20afd295414:/kehys/target.lua diff --git a/kehys/target.lua b/kehys/target.lua index 342743b..ac30994 100644 --- a/kehys/target.lua +++ b/kehys/target.lua @@ -7,6 +7,15 @@ local CTimerAfter = C_Timer.After; local barTexture = "Interface\\AddOns\\kehys\\images\\minimalist"; +local function showTooltip(frame) + GameTooltip_SetDefaultAnchor(GameTooltip, frame); + GameTooltip:SetUnit(frame:GetAttribute("unit")); +end + +local function hideTooltip() + GameTooltip:FadeOut(); +end + local targetUpdate = nil; local function initTarget(parent, width, height, update, event) assert(type(parent) == "table", "Target frame creation missing parent!"); @@ -20,7 +29,7 @@ local function initTarget(parent, width, height, update, event) local f = CreateFrame("Button", "kehysTarget", parent, "SecureUnitButtonTemplate,SecureHandlerStateTemplate"); f:Hide(); - f:SetPoint("CENTER", parent, "CENTER", 300, -178); + f:SetPoint("CENTER", parent, "CENTER", 290, -178); f:SetWidth(width); f:SetHeight(height); f.barwidth = width - 2; -- 1px padding @@ -28,19 +37,34 @@ local function initTarget(parent, width, height, update, event) f:SetAttribute("displayed", "target"); f.unit = "target"; f.displayed = "target"; - f.nonraid = true; + f.constant = true; f.prev = {}; targetUpdate = function() - CTimerAfter(0.1, targetUpdate); - update(f); + if f.updating then + CTimerAfter(0.1, targetUpdate); + return update(f); + end end f:SetScript("OnEvent", event); + f:SetScript("OnHide", function() + f:UnregisterAllEvents(); + f.updating = false; + f.prev = {}; + end); + f:SetScript("OnShow", function() + addon.RegisterEvents(f); + addon.RegisterUnitEvents(f); + event(f, "UPDATE_ALL_BARS"); + f.updating = true; + targetUpdate(); + end); + f:SetScript("OnEnter", showTooltip); + f:SetScript("OnLeave", hideTooltip); 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"); @@ -53,7 +77,7 @@ local function initTarget(parent, width, height, update, event) 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:SetVertexColor(0.7, 0.7, 0.7); f.health:Hide(); f.mana = f:CreateTexture(nil, "BORDER"); f.mana:SetPoint("TOPLEFT", f.background, "LEFT", 0, -height/8); @@ -89,7 +113,7 @@ local function initTarget(parent, width, height, update, event) 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:SetFont(STANDARD_TEXT_FONT, 15); f.text:Hide(); f.targeticon = f:CreateTexture(nil, "OVERLAY"); f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1); @@ -97,17 +121,8 @@ local function initTarget(parent, width, height, update, event) 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(); + RegisterUnitWatch(f); return f; end