I have written a small addon to test how shields works:
ShieldInfo.txt
Code:
## APIVersion: 100009
## Title: Shield Info v0.1
## Version: 0.1
## Author: Garkin
## SavedVariables: SHIELD_INFO_SV
ShieldInfo.xml
ShieldInfo.lua
ShieldInfo.xml
xml Code:
<GuiXml>
<Controls>
<TopLevelControl name="ShieldInfo_Template" clampedToScreen="true" mouseEnabled="false" movable="false" hidden="true" virtual="true">
<Dimensions x="200" y="64" />
<Controls>
<Backdrop alpha="0.3" hidden="true">
<Anchor point="TOPLEFT" offsetX="-8" offsetY="-8" />
<Anchor point="BOTTOMRIGHT" offsetX="8" offsetY="8" />
<Edge file="EsoUI/Art/Tooltips/UI-Border.dds" edgeFileWidth="128" edgeFileHeight="16" />
<Center file="EsoUI/Art/Tooltips/UI-TooltipCenter.dds" />
<Insets left="16" top="16" right="-16" bottom="-16" />
<Controls>
<Texture textureFile="EsoUI/Art/Tooltips/munge_overlay.dds" addressMode="WRAP">
<AnchorFill />
</Texture>
</Controls>
<OnInitialized>
self:GetParent().bd = self
</OnInitialized>
</Backdrop>
<Texture textureFile="EsoUI/Art/Repair/inventory_tabicon_repair_up.dds">
<Anchor point="LEFT" />
<Dimensions x="64" y="64" />
<OnInitialized>
self:GetParent().icon = self
</OnInitialized>
</Texture>
<Label font="ZoFontTooltipTitle" color="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_NORMAL" verticalAlignment="CENTER">
<Anchor point="RIGHT" />
<Dimensions x="130" y="64" />
<OnInitialized>
self:GetParent().label = self
</OnInitialized>
</Label>
</Controls>
</TopLevelControl>
</Controls>
</GuiXml>
ShieldInfo.lua
Lua Code:
local ADDON_NAME = "ShieldInfo"
local EM = GetEventManager()
local WM = GetWindowManager()
local SV, UI
local current = 0
local maximum = 0
local function SetupUI(state)
UI:SetMouseEnabled(state)
UI:SetMovable(state)
UI.bd:SetHidden(not state)
UI:SetHidden(not (state or (current > 0)))
if current > 0 then
UI.label:SetText(("%d/%d"):format(current, maximum))
else
UI.label:SetText("current/max")
end
if not state then
local valid, point, target, relPoint, x, y = UI:GetAnchor(0)
if valid then
SV.Anchor = { p = point, t = target:GetName(), r = relPoint, x = x, y = y }
end
end
end
local function OnMouseUp(self, button, upInside)
if upInside then
if button == 2 then
ClearMenu()
AddMenuItem("Save & Hide", function() SetupUI(false) end)
ShowMenu(self)
end
end
end
local function UnitAttributeVisual(eventCode, unitTag, unitAttributeVisual, statType, attributeType, powerType, value1, value2, value3, value4)
if unitTag == "player" and unitAttributeVisual == ATTRIBUTE_VISUAL_POWER_SHIELDING and attributeType == ATTRIBUTE_HEALTH then
if eventCode == EVENT_UNIT_ATTRIBUTE_VISUAL_UPDATED then
current = current + (value2 - value1)
maximum = maximum + (value4 - value3)
elseif eventCode == EVENT_UNIT_ATTRIBUTE_VISUAL_ADDED then
current = current + value1
maximum = maximum + value2
elseif eventCode == EVENT_UNIT_ATTRIBUTE_VISUAL_REMOVED then
current = current - value1
maximum = maximum - value2
end
end
if current > 0 then
UI.label:SetText(("%d/%d"):format(current, maximum))
UI:SetHidden(false)
else
UI:SetHidden(true)
end
end
local function OnLoaded(event, name)
if name == ADDON_NAME then
EM:UnregisterForEvent(name, event)
SV = ZO_SavedVars:New("SHIELD_INFO_SV", 1, { Anchor = { p = BOTTOM, t = "GuiRoot", r = CENTER, x = 0, y = -100 }, firstTime = true })
UI = WM:CreateControlFromVirtual(nil, GuiRoot, "ShieldInfo_Template")
UI:SetHandler("OnMouseUp", OnMouseUp)
if SV.firstTime then
SV.firstTime = false
d("=== Shield Info ===")
d("Adjust ShieldInfo position and then right-click to hide window and save its position.")
d("Type /si to unlock ShieldInfo window again.")
SetupUI(true)
end
UI:SetAnchor(SV.Anchor.p, _G[SV.Anchor.t], SV.Anchor.r, SV.Anchor.x, SV.Anchor.y)
UI:RegisterForEvent(EVENT_UNIT_ATTRIBUTE_VISUAL_ADDED, UnitAttributeVisual)
UI:RegisterForEvent(EVENT_UNIT_ATTRIBUTE_VISUAL_REMOVED, UnitAttributeVisual)
UI:RegisterForEvent(EVENT_UNIT_ATTRIBUTE_VISUAL_UPDATED, UnitAttributeVisual)
SLASH_COMMANDS["/si"] = function() SetupUI(true) end
end
end
EM:RegisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED, OnLoaded)
Download link:
https://www.dropbox.com/s/p1orffil60...ldInfo_0.1.zip