Quantcast
WoWInterface - View Single Post - Lua Help for New Coder
View Single Post
10-01-20, 12:29 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,307
You can just have one frame that hosts several Fontstrings and updates them as required (OnEvent, OnUpdate, or both) eg:

Lua Code:
  1. local fpsCheck = 3 -- update ~3 seconds
  2.  
  3. local AshStats = CreateFrame("frame", "AshStatsFrame")
  4. AshStats:SetBackdrop({ bgFile="Interface\\DialogFrame\\UI-DialogBox-Background",
  5.     edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border",
  6.     tile=1, tileSize=32, edgeSize=32,
  7.     insets={left=11, right=12, top=12, bottom=11}
  8. })
  9.  
  10. AshStats:SetWidth(170)
  11. AshStats:SetHeight(400)
  12. AshStats:SetPoint("CENTER",UIParent)
  13. AshStats:EnableMouse(true)
  14. AshStats:SetMovable(true)
  15. AshStats:RegisterForDrag("LeftButton")
  16. AshStats:SetScript("OnDragStart", function(self) self:StartMoving() end)
  17. AshStats:SetScript("OnDragStart", function(self) self:StartMoving() end)
  18. AshStats:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
  19. AshStats:SetFrameStrata("FULLSCREEN_DIALOG")
  20. -- fps fontstring
  21. AshStats.fps = AshStats:CreateFontString("$parentFPS","OVERLAY","GameTooltipText")
  22. AshStats.fps:SetPoint("TOPLEFT", 10, -10)
  23. AshStats.fps:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
  24. -- latence fontstring
  25. AshStats.lat = AshStats:CreateFontString("$parentLatency","OVERLAY","GameTooltipText")
  26. AshStats.lat:SetPoint("TOPLEFT", AshStats.fps, "BOTTOMLEFT", 0, 0)
  27. AshStats.lat:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
  28. -- zone fontstring
  29. AshStats.zone = AshStats:CreateFontString("$parentZone","OVERLAY","GameTooltipText")
  30. AshStats.zone:SetPoint("TOPLEFT", AshStats.lat, "BOTTOMLEFT", 0, 0)
  31. AshStats.zone:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
  32. -- other fontstring
  33. AshStats.arm = AshStats:CreateFontString("$parentArm","OVERLAY","GameTooltipText")
  34. AshStats.arm:SetPoint("TOPLEFT", AshStats.zone, "BOTTOMLEFT", 0, 0)
  35. AshStats.arm:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
  36.  
  37. AshStats:RegisterEvent("PLAYER_ENTERING_WORLD");
  38. AshStats:RegisterEvent("ZONE_CHANGED")
  39. AshStats:RegisterEvent("ZONE_CHANGED_INDOORS")
  40. AshStats:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  41. local function eventHandler(self, event, ...)
  42.     if event == "PLAYER_ENTERING_WORLD" then -- updates on entering world events only
  43.         self.arm:SetText("Some Stat or other")
  44.     end
  45.     -- everthing below updates on all events
  46. -- zone text
  47.     self.zone:SetText(GetMinimapZoneText())
  48.     local r, g, b = 1, 1, 1
  49.     local ZoneType = GetZonePVPInfo()
  50.     if ZoneType == "sanctuary" then
  51.         r, g, b = .41, .8, .94
  52.     elseif ZoneType == "friendly" then
  53.         r, g, b = .1, 1, .1
  54.     elseif ZoneType == "contested" then
  55.         r, g, b = 1, .7, 0
  56.     elseif ZoneType == "hostile" then
  57.         r, g, b = 1, .1, .1
  58.     elseif ZoneType == "arena" then
  59.         r, g, b = 1, .1, .1
  60.     else
  61.         r, g, b = 1, .82, 0
  62.     end
  63.     self.zone:SetTextColor(r, g, b)
  64. end
  65. AshStats:SetScript("OnEvent", eventHandler);
  66.  
  67. AshStats.elapsed = fpsCheck
  68. AshStats:SetScript("OnUpdate", function(self, elapsed)
  69.     self.elapsed = self.elapsed - elapsed -- Countdown to zero
  70.     if self.elapsed > 0 then return end
  71.     self.elapsed = fpsCheck -- and reset/start again
  72.  
  73. -- FPS
  74.     self.fps:SetText("Frame Rate - "..format("%0.i", GetFramerate()))
  75. -- Latency
  76.     local _,_,Latency = GetNetStats()
  77.     local r, g, b
  78.     if Latency > PERFORMANCEBAR_MEDIUM_LATENCY then -- 600
  79.         r, g, b = 1, 0, 0
  80.     elseif Latency > PERFORMANCEBAR_LOW_LATENCY then -- 300
  81.         r, g, b = 1, .82, 0
  82.     else
  83.         r, g, b = 0, 1, 0
  84.     end
  85.     self.lat:SetText(Latency.."ms")
  86.     self.lat:SetTextColor(r, g, b)
  87. end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote