Thread: Shield Strength
View Single Post
10/09/14, 05:19 PM   #5
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
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:
  1. <GuiXml>
  2.    <Controls>
  3.       <TopLevelControl name="ShieldInfo_Template" clampedToScreen="true" mouseEnabled="false" movable="false" hidden="true" virtual="true">
  4.          <Dimensions x="200" y="64" />
  5.          <Controls>
  6.  
  7.             <Backdrop alpha="0.3" hidden="true">
  8.                <Anchor point="TOPLEFT" offsetX="-8" offsetY="-8" />
  9.                <Anchor point="BOTTOMRIGHT" offsetX="8" offsetY="8" />
  10.                <Edge file="EsoUI/Art/Tooltips/UI-Border.dds" edgeFileWidth="128" edgeFileHeight="16" />
  11.                <Center file="EsoUI/Art/Tooltips/UI-TooltipCenter.dds" />
  12.                <Insets left="16" top="16" right="-16" bottom="-16" />
  13.  
  14.                <Controls>
  15.                   <Texture textureFile="EsoUI/Art/Tooltips/munge_overlay.dds" addressMode="WRAP">
  16.                      <AnchorFill />
  17.                   </Texture>
  18.                </Controls>
  19.  
  20.                <OnInitialized>
  21.                   self:GetParent().bd = self
  22.                </OnInitialized>
  23.             </Backdrop>
  24.  
  25.             <Texture textureFile="EsoUI/Art/Repair/inventory_tabicon_repair_up.dds">
  26.                <Anchor point="LEFT" />
  27.                <Dimensions x="64" y="64" />
  28.                <OnInitialized>
  29.                   self:GetParent().icon = self
  30.                </OnInitialized>
  31.             </Texture>
  32.  
  33.             <Label font="ZoFontTooltipTitle" color="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_NORMAL" verticalAlignment="CENTER">
  34.                <Anchor point="RIGHT" />
  35.                <Dimensions x="130" y="64" />
  36.                <OnInitialized>
  37.                   self:GetParent().label = self
  38.                </OnInitialized>
  39.             </Label>
  40.  
  41.          </Controls>
  42.       </TopLevelControl>
  43.    </Controls>
  44. </GuiXml>
ShieldInfo.lua
Lua Code:
  1. local ADDON_NAME = "ShieldInfo"
  2. local EM = GetEventManager()
  3. local WM = GetWindowManager()
  4. local SV, UI
  5. local current = 0
  6. local maximum = 0
  7.  
  8.  
  9. local function SetupUI(state)
  10.    UI:SetMouseEnabled(state)
  11.    UI:SetMovable(state)
  12.  
  13.    UI.bd:SetHidden(not state)
  14.    UI:SetHidden(not (state or (current > 0)))
  15.  
  16.    if current > 0 then
  17.       UI.label:SetText(("%d/%d"):format(current, maximum))
  18.    else
  19.       UI.label:SetText("current/max")
  20.    end
  21.  
  22.    if not state then
  23.       local valid, point, target, relPoint, x, y = UI:GetAnchor(0)
  24.  
  25.       if valid then
  26.          SV.Anchor = { p = point, t = target:GetName(), r = relPoint, x = x, y = y }
  27.       end
  28.    end
  29. end
  30.  
  31. local function OnMouseUp(self, button, upInside)
  32.    if upInside then
  33.       if button == 2 then
  34.          ClearMenu()
  35.          AddMenuItem("Save & Hide", function() SetupUI(false) end)
  36.          ShowMenu(self)
  37.       end
  38.    end
  39. end
  40.  
  41. local function UnitAttributeVisual(eventCode, unitTag, unitAttributeVisual, statType, attributeType, powerType, value1, value2, value3, value4)
  42.    if unitTag == "player" and unitAttributeVisual == ATTRIBUTE_VISUAL_POWER_SHIELDING and attributeType == ATTRIBUTE_HEALTH then
  43.       if eventCode == EVENT_UNIT_ATTRIBUTE_VISUAL_UPDATED then
  44.          current = current + (value2 - value1)
  45.          maximum = maximum + (value4 - value3)
  46.       elseif eventCode == EVENT_UNIT_ATTRIBUTE_VISUAL_ADDED then
  47.          current = current + value1
  48.          maximum = maximum + value2
  49.       elseif eventCode == EVENT_UNIT_ATTRIBUTE_VISUAL_REMOVED then
  50.          current = current - value1
  51.          maximum = maximum - value2
  52.       end
  53.    end
  54.  
  55.    if current > 0 then
  56.       UI.label:SetText(("%d/%d"):format(current, maximum))
  57.       UI:SetHidden(false)
  58.    else
  59.       UI:SetHidden(true)
  60.    end
  61. end
  62.  
  63. local function OnLoaded(event, name)
  64.    if name == ADDON_NAME then
  65.       EM:UnregisterForEvent(name, event)
  66.  
  67.       SV = ZO_SavedVars:New("SHIELD_INFO_SV", 1, { Anchor = { p = BOTTOM, t = "GuiRoot", r = CENTER, x = 0, y = -100 }, firstTime = true })
  68.  
  69.       UI = WM:CreateControlFromVirtual(nil, GuiRoot, "ShieldInfo_Template")
  70.  
  71.       UI:SetHandler("OnMouseUp", OnMouseUp)
  72.  
  73.       if SV.firstTime then
  74.          SV.firstTime = false
  75.          d("=== Shield Info ===")
  76.          d("Adjust ShieldInfo position and then right-click to hide window and save its position.")
  77.          d("Type /si to unlock ShieldInfo window again.")
  78.          SetupUI(true)
  79.       end
  80.  
  81.       UI:SetAnchor(SV.Anchor.p, _G[SV.Anchor.t], SV.Anchor.r, SV.Anchor.x, SV.Anchor.y)
  82.  
  83.       UI:RegisterForEvent(EVENT_UNIT_ATTRIBUTE_VISUAL_ADDED, UnitAttributeVisual)
  84.       UI:RegisterForEvent(EVENT_UNIT_ATTRIBUTE_VISUAL_REMOVED, UnitAttributeVisual)
  85.       UI:RegisterForEvent(EVENT_UNIT_ATTRIBUTE_VISUAL_UPDATED, UnitAttributeVisual)
  86.  
  87.       SLASH_COMMANDS["/si"] = function() SetupUI(true) end
  88.    end
  89. end
  90.  
  91. EM:RegisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED, OnLoaded)

Download link: https://www.dropbox.com/s/p1orffil60...ldInfo_0.1.zip

Last edited by Garkin : 10/09/14 at 05:34 PM.
  Reply With Quote