--[[ * CyrHUD * Author: Sasky ]]-- if CyrHUD == nil then --noinspection GlobalCreationOutsideO CyrHUD = {} end ---------------------------------------------- -- Utility ---------------------------------------------- function bl(val) if val == nil then return "NIL" elseif val then return "T" else return "F" end end function nn(val) if val == nil then return "NIL" end return val end function CyrHUD.formatTime(delta, inclueSec) local sec = delta % 60 delta = (delta - sec) / 60 local min = delta % 60 local out = min .. "m" if inclueSec then out = out .. " " .. sec .. "s" end return out end ---------------------------------------------- -- Score ---------------------------------------------- function CyrHUD.updateScore() local cID = GetCurrentCampaignId() local time = CyrHUD.formatTime(GetSecondsUntilCampaignScoreReevaluation(cID), true) CyrHUD_UI_Time:SetText(time) CyrHUD_UI_AD:SetText("+" .. GetCampaignAlliancePotentialScore(cID, ALLIANCE_ALDMERI_DOMINION)) CyrHUD_UI_DC:SetText("+" .. GetCampaignAlliancePotentialScore(cID, ALLIANCE_DAGGERFALL_COVENANT)) CyrHUD_UI_EP:SetText("+" .. GetCampaignAlliancePotentialScore(cID, ALLIANCE_EBONHEART_PACT)) end ---------------------------------------------- -- Events ---------------------------------------------- function CyrHUD.eventAttackChange(_, keepID, battlegroundContext, underAttack) if underAttack then CyrHUD.add(keepID) elseif CyrHUD.battles[keepID] ~= nil then CyrHUD.battles[keepID]:update() end end ---------------------------------------------- -- Notification UI pool ---------------------------------------------- CyrHUD.entryCount = 0 CyrHUD.entries = {} CyrHUD.createEntry = function() local num = CyrHUD.entryCount + 1 local yoff = num*35-5 CyrHUD.entryCount = num local entry = {} local entryName = "CyrHUDEntry" .. num entry.main = WINDOW_MANAGER:CreateControl(entryName .. "main", CyrHUD_UI, CT_BACKDROP) entry.main:SetDimensions(280, 35) entry.main:SetAnchor(TOPLEFT, CyrHUD_UI, TOPLEFT, 0, yoff) entry.main:SetCenterColor( 0, 0, 0, .3 ) entry.main:SetEdgeColor( 0, 0, 0, 0 ) entry.icon = WINDOW_MANAGER:CreateControl(entryName .. "icon", entry.main, CT_TEXTURE) entry.icon:SetAnchor(TOPLEFT, entry.main, TOPLEFT, -2, -2) entry.icon:SetDimensions(40,40) entry.icon:SetDrawLayer(2) entry.ua = WINDOW_MANAGER:CreateControl(entryName .. "ua", entry.main, CT_TEXTURE) entry.ua:SetAnchor(TOPLEFT, entry.main, TOPLEFT, -2, -2) entry.ua:SetDimensions(40,40) entry.ua:SetTexture("/esoui/art/mappins/ava_attackburst_64.dds") entry.ua:SetDrawLayer(1) local fontMain = "EsoUI/Common/Fonts/univers67.otf|18|soft-shadow-thick" entry.name = WINDOW_MANAGER:CreateControl(entryName .. "name", entry.main, CT_LABEL) entry.name:SetDimensions(150,30) entry.name:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 35, 5) entry.name:SetFont(fontMain) --local fontSmall = "EsoUI/Common/Fonts/univers67.otf|14|soft-shadow-thin" entry.defSiege = WINDOW_MANAGER:CreateControl(entryName .. "defSiege", entry.main, CT_LABEL) entry.defSiege:SetDimensions(30,30) entry.defSiege:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 220, 5) entry.defSiege:SetFont(fontMain) entry.attSiege = WINDOW_MANAGER:CreateControl(entryName .. "attSiege", entry.main, CT_LABEL) entry.attSiege:SetDimensions(30,30) entry.attSiege:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 190, 5) entry.attSiege:SetFont(fontMain) entry.time = WINDOW_MANAGER:CreateControl(entryName .. "time", entry.main, CT_LABEL) entry.time:SetDimensions(30,30) entry.time:SetAnchor(TOPLEFT, entry.main, TOPLEFT, 250, 5) entry.time:SetFont(fontMain) entry.time:SetColor(.8,.8,.8) table.insert(CyrHUD.entries, entry) return entry end CyrHUD.getEntry = function() CyrHUD.ptr = CyrHUD.ptr + 1 if #CyrHUD.entries < CyrHUD.ptr then CyrHUD.createEntry() end CyrHUD.entries[CyrHUD.ptr].main:SetHidden(false) return CyrHUD.entries[CyrHUD.ptr] end CyrHUD.ptr = 0 CyrHUD.reset = function() for _,p in pairs(CyrHUD.entries) do p.main:SetHidden(true) end CyrHUD.ptr = 0 end CyrHUD.print = function(battle) local entry = CyrHUD.getEntry() entry.icon:SetTexture(battle:getIcon()) entry.name:SetText(battle.keepName) local color = CyrHUD.info[battle.defender].color entry.name:SetColor(color.r, color.g, color.b) entry.time:SetText(battle:getDuration()) local ds, dc = battle:getDefSiege() entry.defSiege:SetText(ds) entry.defSiege:SetColor(dc.r, dc.g, dc.b) local as, ac = battle:getAttSiege() entry.attSiege:SetText(as) entry.attSiege:SetColor(ac.r, ac.g, ac.b) local r,g,b,a = battle:getBGColor() entry.main:SetCenterColor(r,g,b,a) entry.ua:SetHidden(not battle.keepUA) end CyrHUD.printAll = function() CyrHUD.reset() for _,b in pairs(CyrHUD.battles) do CyrHUD.print(b) end end ---------------------------------------------- -- Battle management ---------------------------------------------- CyrHUD.battles = {} CyrHUD.add = function(keepID) if CyrHUD.battles[keepID] == nil then d("Adding " .. GetKeepName(keepID)) CyrHUD.battles[keepID] = CyrHUD.Battle(keepID) else CyrHUD.battles[keepID]:restart() end end CyrHUD.checkAdd = function(keepID) if CyrHUD.battles[keepID] == nil then local battle = CyrHUD.Battle(keepID) if battle:isBattle() then CyrHUD.battles[keepID] = battle end elseif CyrHUD.battles[keepID]:isBattle() then CyrHUD.battles[keepID]:restart() end end CyrHUD.updateAll = function() for i,_ in pairs(CyrHUD.battles) do --Update in-place CyrHUD.battles[i]:update() end end --TODO: Add outposts CyrHUD.scanKeeps = function() for i=3,20 do CyrHUD.checkAdd(i) end end ------------------------------------------------------------------------ -- Initialization ------------------------------------------------------------------------ --TODO: Properly setup on Addon init or playerLoad --TODO: only show while in Cyrodiil local function init() if WYK_QuestTracker_MQT then WYK_QuestTracker_MQT:SetAlpha(0) end CyrHUD_UI:SetHidden(false) d("Adding keep info") EVENT_MANAGER:RegisterForUpdate("CyrHUDKeepCheck", 5000, function() CyrHUD.scanKeeps() CyrHUD.updateAll() end) EVENT_MANAGER:RegisterForUpdate("CyrHUDUIUpdate", 1000, function() CyrHUD.printAll() CyrHUD.updateScore() end) EVENT_MANAGER:RegisterForEvent("CyrHUDAttackChange", EVENT_KEEP_UNDER_ATTACK_CHANGED, CyrHUD.eventAttackChange) showCyrHUD = true end local showCyrHUD = false SLASH_COMMANDS["/cyrhud"] = function() if showCyrHUD then EVENT_MANAGER:UnregisterForUpdate("CyrHUDKeepCheck") EVENT_MANAGER:UnregisterForUpdate("CyrHUDUIUpdate") EVENT_MANAGER:UnregisterForUpdate("CyrHUDUpdateAPCount") if WYK_QuestTracker_MQT then WYK_QuestTracker_MQT:SetAlpha(1) end CyrHUD_UI:SetHidden(true) showCyrHUD = false else init() end end