X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/3ce401749aaa236c206a034549ab161bd8bd1ec9..a5089abe1848cf4723b90b166660ac52c3d61dab:/kehys/player.lua diff --git a/kehys/player.lua b/kehys/player.lua index 89e15af..7fcc04c 100644 --- a/kehys/player.lua +++ b/kehys/player.lua @@ -14,7 +14,7 @@ local vehicletoggle = [=[ end ]=] -local updater = nil; +local playerUpdate = nil; local function initPlayer(parent, width, height, update, event) assert(type(parent) == "table", "Player frame creation missing parent!"); assert(type(width) == "number", "Player frame creation missing width!"); @@ -36,12 +36,12 @@ local function initPlayer(parent, width, height, update, event) f:SetAttribute("vehicle", "vehicle"); f.unit = "player"; f.displayed = "player"; - f.vehicle = "vehicle" - f.nonraid = true; + f.vehicle = "vehicle"; + f.constant = true; f.prev = {}; - updater = function() - CTimerAfter(0.1, updater); + playerUpdate = function() + CTimerAfter(0.1, playerUpdate); update(f); end f:SetScript("OnEvent", event); @@ -63,7 +63,7 @@ local function initPlayer(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); @@ -93,11 +93,11 @@ local function initPlayer(parent, width, height, update, event) 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:SetColorTexture(0.1, 0.1, 0.1, 0); f.healabsorb:Hide(); f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); - f.text:SetPoint("LEFT", f.health, "LEFT", 10, 0); - f.text:SetFont(STANDARD_TEXT_FONT, 13); + f.text:SetPoint("RIGHT", f, "RIGHT", -2, 8); + f.text:SetFont(STANDARD_TEXT_FONT, 15); f.text:Hide(); f.targeticon = f:CreateTexture(nil, "OVERLAY"); f.targeticon:SetPoint("CENTER", f, "TOP", 0, -1); @@ -114,8 +114,110 @@ local function initPlayer(parent, width, height, update, event) addon.RegisterEvents(f); addon.RegisterUnitEvents(f); event(f, "UPDATE_ALL_BARS"); - updater(); + playerUpdate(); f:Show(); + return f; +end + +local petUpdate = nil; +local function initPet(parent, width, height, update, event) + assert(type(parent) == "table", "Pet frame creation missing parent!"); + assert(type(width) == "number", "Pet frame creation missing width!"); + assert(type(height) == "number", "Pet frame creation missing height!"); + assert(type(update) == "function", + "Pet frame creation missing update function!"); + assert(type(event) == "function", + "Pet frame creation missing event function!"); + + local f = CreateFrame("Button", "kehysPet", parent, + "SecureUnitButtonTemplate,SecureHandlerStateTemplate"); + f:Hide(); + f:SetPoint("BOTTOMRIGHT", parent, "BOTTOMLEFT", -5, 0); + f:SetWidth(width); + f:SetHeight(height); + f.barwidth = width - 2; -- 1px padding + f:SetAttribute("unit", "pet"); + f:SetAttribute("displayed", "pet"); + f:SetAttribute("vehicle", "player"); + f.unit = "pet"; + f.displayed = "pet"; + f.vehicle = "player" + f.prev = {}; + + petUpdate = function() + if f.updating then + CTimerAfter(0.1, petUpdate); + 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; + petUpdate(); + end); + f:RegisterForClicks("AnyDown"); + f:SetAttribute("*type1", "target"); + f:SetAttribute("*type2", "togglemenu"); + f:SetAttribute("toggleForVehicle", true); + + -- 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, "BOTTOMLEFT"); + f.health:SetTexture(barTexture); + f.health:SetVertexColor(0.7, 0.7, 0.7); + 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, "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.name = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); + f.name:SetPoint("LEFT", f, "LEFT", 5, 0); + f.text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); + f.text:SetPoint("RIGHT", f, "RIGHT", -3, -1); + f.text:SetFont(STANDARD_TEXT_FONT, 10); + 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(); + + RegisterUnitWatch(f); + RegisterStateDriver(f, "vehicleui", "[vehicleui] vehicle; no"); + f:SetAttribute("_onstate-vehicleui", vehicletoggle); end CFrame:SetScript("OnEvent", function(self) @@ -124,6 +226,7 @@ CFrame:SetScript("OnEvent", function(self) CFrame:SetPoint("CENTER", nil, "CENTER"); CFrame:SetWidth(2); CFrame:SetHeight(2); - initPlayer(self, 160, 48, addon.FrameUpdate, addon.UnitEvent); + local player = initPlayer(self, 160, 48, addon.FrameUpdate, addon.UnitEvent); + initPet(player, 80, 24, addon.FrameUpdate, addon.UnitEvent); end); CFrame:RegisterEvent("PLAYER_LOGIN");