Thread Tools Display Modes
03/23/15, 05:56 AM   #1
lightz39
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 21
NuMotiv System Bar

UPDATE: Added latency functionality and a new scale friendly backdrop.

Hello everyone. This is the development topic to go along with the uploaded addon in the beta category. Here I will post the most recent code, developments and general information. If you would like to get involved I appreciate any tips, suggestions or ideas for general improvement.

For the current release 0.1 I worked on mimicing the default UI's Framerate indicator. This isn't exactly a ground breaking feature but it was a starting point for a beginner. As I move along I will be adding comments to the code to make things easier to understand if you are new like me or maybe give the experienced guys an idea of what I was trying to do so they can suggest a better way.



The code here will most likely be more up to date than the uploaded addon.

Txt Code:
  1. ;nmSystemBar ESO AddOn by NuMotiv. Visit the ESOUI Wiki for references: "http://wiki.esoui.com/Main_Page"
  2.  
  3. ;Defines the current API Version
  4. ## APIVersion: 100011
  5. ;Defines the AddOn name, displayed in AddOn Manager
  6. ## Title: NuMotiv System Bar |c6b96340.2
  7. ;Defines the AddOn description, displayed in AddOn Manager
  8. ## Description: |caaaaaaCurrently mimics the built in framerate and latency meters.                     |cd5c859Next Release: Add local time clock.
  9. ;Defines the current version
  10. ## Version: 0.2
  11. ;Defines the author's name
  12. ## Author: |c8625c4NuMotiv
  13. ;Defines the saved variables file
  14. ## SavedVariables: nmSystemBarSavedVariables
  15.  
  16. ;Defines the files loaded by the AddOn
  17. nmSystemBar.xml
  18. nmSystemBar.lua

Xml Code:
  1. <!--nmSystemBar ESO AddOn by NuMotiv. Visit the ESOUI Wiki for references: "http://wiki.esoui.com/Main_Page"-->
  2.  
  3. <!--Creates the container for the AddOn XML code-->
  4. <GuiXml>
  5.     <Controls>
  6.         <!--Create the top-level level control for the frame called "nmSystemBarWin"-->
  7.         <TopLevelControl name="nmSystemBarWin" movable="true" mouseEnabled="true" clampedToScreen="true" hidden="false">
  8.             <Dimensions x="168" y="68"/>
  9.             <ClampedToScreenInsets top="20" bottom="-20" left="20" right="-20"/>
  10.             <Anchor point="BOTTOMLEFT" relativeTo="GuiRoot" relativePoint="BOTTOMLEFT" offsetX="0" offsetY="0"/>
  11.             <Controls>
  12.                 <!--Sets the backdrop of the frame-->
  13.                 <Backdrop name="$(parent)Backdrop" integralWrapping="true">
  14.                     <Anchor point="TOPLEFT"/>
  15.                     <Anchor point="BOTTOMRIGHT"/>
  16.                     <Edge file="EsoUI/Art/ChatWindow/chat_BG_edge.dds" edgeFileWidth="256" edgeFileHeight="256" edgeSize="32"/>
  17.                     <Center file="EsoUI/Art/ChatWindow/chat_BG_center.dds"/>
  18.                     <Insets left="32" top="32" right="-32" bottom="-32"/>
  19.                 </Backdrop>
  20.                 <!--Create a control for the framerate meter-->
  21.                 <Control name="$(parent)FPS" mouseEnabled="true">
  22.                     <Dimensions x="65" y="40"/>
  23.                     <Anchor point="RIGHT" relativeTo="$(parent)" relativePoint="CENTER"/>
  24.                     <Controls>
  25.                         <!--Set the label for the framerate-->
  26.                         <Label name="$(parent)Label" font="ZoFontWinT2" color="c5c29e" horizontalAlignment="CENTER" verticalAlignment="CENTER">
  27.                             <AnchorFill/>
  28.                         </Label>
  29.                     </Controls>
  30.                     <!--Tells the framerate meter to move with the frame-->
  31.                     <OnMouseDown>
  32.                         self:GetParent():StartMoving()
  33.                     </OnMouseDown>
  34.                     <!--Tells it to stop moving with the frame-->
  35.                     <OnMouseUp>
  36.                         self:GetParent():StopMovingOrResizing()
  37.                     </OnMouseUp>
  38.                     <!--Tells the framerate meter to display a tooltip when mousing over-->
  39.                     <OnMouseEnter>
  40.                         nmSystemBar.FPSTooltip(self)
  41.                     </OnMouseEnter>        
  42.                     <!--Tells it to hide the tooltip when the mouse leaves the frame-->
  43.                     <OnMouseExit>
  44.                         nmSystemBar.HideTooltip(self)
  45.                     </OnMouseExit> 
  46.                 </Control>
  47.                 <!--Create a control for the latency meter-->
  48.                 <Control name="$(parent)Latency" mouseEnabled="true">
  49.                     <Dimensions x="65" y="40"/>
  50.                     <Anchor point="LEFT" relativeTo="$(parent)" relativePoint="CENTER"/>
  51.                     <Controls>
  52.                         <!--Draws the latency meter bars-->
  53.                         <Texture name="$(parent)Bars" textureFile="ESOUI/art/campaign/campaignbrowser_hipop.dds">
  54.                             <Dimensions x="26" y="26"/>
  55.                             <Anchor point="LEFT" relativeTo="$(parent)" relativePoint="LEFT"/>
  56.                         </Texture>
  57.                         <!--Set the label for the latency level-->
  58.                         <Label name="$(parent)Label" font="ZoFontWinT2" horizontalAlignment="LEFT" verticalAlignment="CENTER">
  59.                             <Anchor point="LEFT" relativeTo="$(parent)Bars" relativePoint="RIGHT"/>
  60.                         </Label>
  61.                     </Controls>
  62.                     <!--Tells the latency meter to move with the frame-->
  63.                     <OnMouseDown>
  64.                         self:GetParent():StartMoving()
  65.                     </OnMouseDown>
  66.                     <!--Tells it to stop moving with the frame-->
  67.                     <OnMouseUp>
  68.                         self:GetParent():StopMovingOrResizing()
  69.                     </OnMouseUp>
  70.                     <!--Tells the latency meter to display a tooltip when mousing over-->
  71.                     <OnMouseEnter>
  72.                         nmSystemBar.LatencyTooltip(self)
  73.                     </OnMouseEnter>        
  74.                     <!--Tells it to hide the tooltip when the mouse leaves the frame-->
  75.                     <OnMouseExit>
  76.                         nmSystemBar.HideTooltip(self)
  77.                     </OnMouseExit> 
  78.                 </Control>
  79.             </Controls>
  80.             <!--Save the position when the frame stops moving-->
  81.             <OnMoveStop>
  82.                 nmSystemBar.OnMoveStop()
  83.             </OnMoveStop>
  84.         </TopLevelControl>
  85.     </Controls>
  86. </GuiXml>

Lua Code:
  1. --nmSystemBar ESO AddOn by NuMotiv. Visit the ESOUI Wiki for references: "http://wiki.esoui.com/Main_Page"
  2.  
  3. --Create a top-level table called "nmSystemBar"
  4. nmSystemBar = {}
  5.  
  6. --Register the name "nmSystemBar" to the AddOn
  7. nmSystemBar.name = "nmSystemBar"
  8.  
  9. --Define local variables
  10. local MaxFPS = 999
  11. local MaxLatency = 999
  12. local HighLatency = 350
  13. local MidLatency = 150
  14. local LowLatency = 0
  15.  
  16. --Create a table for the default values "nmSystemBar.PositionDefaults"
  17. nmSystemBar.PositionDefaults = {x = -20, y = 20}
  18.  
  19. --Create a local function that gathers and displays the current framerate
  20. local function OnUpdate()
  21.     --Set "FPS" to the current framerate
  22.     local FPS = GetFramerate()
  23.     --Set "Latency" to the current latency level
  24.     local Latency = GetLatency()
  25.     --If the current framerate is higher than the maximum allowed value 999 set it to 999
  26.     if FPS > MaxFPS then
  27.         FPS = MaxFPS
  28.     end
  29.     --If the current latency is higher than the maximum allowed value 999 set it to 999
  30.     if Latency > MaxLatency then
  31.         Latency = MaxLatency
  32.     end
  33.     --Set the latency icon and color based on value
  34.     if Latency >= HighLatency then
  35.         nmSystemBarWinLatencyBars:SetTexture("ESOUI/art/campaign/campaignbrowser_lowpop.dds")
  36.         nmSystemBarWinLatencyBars:SetColor(1,0,0,1)
  37.         nmSystemBarWinLatencyLabel:SetColor(1,0,0,1)
  38.     elseif Latency >= MidLatency then
  39.         nmSystemBarWinLatencyBars:SetTexture("ESOUI/art/campaign/campaignbrowser_medpop.dds")
  40.     elseif Latency >= LowLatency then
  41.         nmSystemBarWinLatencyBars:SetTexture("ESOUI/art/campaign/campaignbrowser_hipop.dds")
  42.     end
  43.     --Set the framerate label to whatever the current value is
  44.     nmSystemBarWinFPSLabel:SetText("FPS: |cffffff"..zo_round(FPS))
  45.     nmSystemBarWinLatencyLabel:SetText(Latency)
  46. end
  47.  
  48. --Save the new position values
  49. function nmSystemBar.OnMoveStop()
  50.     nmSystemBar.SavedPosition.x = nmSystemBarWin:GetLeft()
  51.     nmSystemBar.SavedPosition.y = nmSystemBarWin:GetTop()
  52. end
  53.  
  54. --Create a function to initialize the AddOn
  55. function nmSystemBar.OnAddOnLoaded(event, name)
  56.     --Check for our AddOn
  57.     if name == nmSystemBar.name then
  58.         --Once the AddOn is loaded unregister the event
  59.         EVENT_MANAGER:UnregisterForEvent(nmSystemBar.name, EVENT_ADD_ON_LOADED)
  60.         --Create a new saved variables file in "Documents\Elder Scrolls Online\live\SavedVariables"
  61.         nmSystemBar.SavedPosition = ZO_SavedVars:New("nmSystemBarSavedVariables", 1, nil, nmSystemBar.PositionDefaults)
  62.         --Load the values from the saved variables
  63.         nmSystemBarWin:ClearAnchors()
  64.         nmSystemBarWin:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, nmSystemBar.SavedPosition.x, nmSystemBar.SavedPosition.y)
  65.         --Register the event "OnUpdate" and set its interval to 1000 milliseconds or 1 second
  66.         EVENT_MANAGER:RegisterForUpdate("UpdateFPS", 1000, OnUpdate)
  67.     end
  68. end
  69.  
  70. --When mousing over framerate label display the tooltip
  71. function nmSystemBar.FPSTooltip(self)
  72.     InitializeTooltip(InformationTooltip, self, BOTTOM, 0, 0)
  73.     SetTooltipText(InformationTooltip, "Frames per second. Higher values indicate a smoother experience.")
  74. end
  75.  
  76. function nmSystemBar.LatencyTooltip(self)
  77.     InitializeTooltip(InformationTooltip, self, BOTTOM, 0, 0)
  78.     SetTooltipText(InformationTooltip, "Your latency to the server in milliseconds. Higher values can result in decreased responsiveness while playing.")
  79. end
  80.  
  81. --When mouse leaves framerate label hide the tooltip
  82. function nmSystemBar.HideTooltip(self)
  83.     ClearTooltip(InformationTooltip)
  84. end
  85.  
  86. --Register the event OnAddOnLoaded to initialize our AddOn
  87. EVENT_MANAGER:RegisterForEvent(nmSystemBar.name, EVENT_ADD_ON_LOADED, nmSystemBar.OnAddOnLoaded)

Last edited by lightz39 : 03/29/15 at 07:37 AM.
 
03/26/15, 07:46 PM   #2
lightz39
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 21
Version 0.1B

Rewrote the code and added comments. Should be a little easier to follow now.
 

ESOUI » AddOns » Alpha/Beta AddOns » NuMotiv System Bar

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off