View Single Post
09-25-17, 10:09 PM   #16
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
[quote=Fizzlemizz;325288]There's also the problem (Edit: as mentioned by Kakjens) with small remainders giving a result of x.00 Mil. so it could be extended too:

ok the question is how do i implement this with my self.text at the bottom

Lua Code:
  1. --Thank you for your help
  2. --SDPhantom
  3. --Phanx
  4. --Fizzlemizz
  5. local AXP_COLOR = { r = 0.6, g = 0.2, b = 0.1 }
  6. --Lets set up the Frame
  7. local derArtifactBar = CreateFrame("Statusbar", "derArtifactBar",artifactFrame)
  8.     derArtifactBar:SetPoint("CENTER", 0, 0)
  9.     derArtifactBar:SetHeight(18)
  10.     derArtifactBar:SetWidth(artifactFrame:GetWidth() * .968)
  11.     derArtifactBar:SetStatusBarTexture("Interface\\AddOns\\_Deranjata\\media\\cast\\Waterline")
  12.     derArtifactBar:SetStatusBarColor(AXP_COLOR.r, AXP_COLOR.g, AXP_COLOR.b, 0.5)
  13.     derArtifactBar:SetBackdrop({
  14.     bgFile =  "Interface\\AddOns\\_Deranjata\\media\\cast\\Lines",
  15.     insets = { left = 1, right = 1, top = 1, bottom = 1 }
  16.     })
  17. derArtifactBar:SetBackdropColor(0.1, 0.1, 0.1)
  18. derArtifactBar:SetBackdropBorderColor(0.6, 0.6, 0.6)
  19. --lets clear any text then set out centerpoint
  20. derArtifactBar.Text=derArtifactBar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  21. derArtifactBar.Text:SetPoint("CENTER")      
  22.  
  23. --Registering out watched events
  24. derArtifactBar:RegisterEvent("PLAYER_ENTERING_WORLD")
  25. derArtifactBar:RegisterEvent("ARTIFACT_XP_UPDATE")
  26. derArtifactBar:RegisterEvent("UNIT_INVENTORY_CHANGED")
  27.  
  28. -- now lets update the position and text on the bar so we can always have accurate info
  29. derArtifactBar:SetScript("OnEvent", function(self, event, ...)
  30.     if not HasArtifactEquipped() then self:Hide() return end
  31.     self:Show()
  32.     local itemID, altItemID, name, icon, xp, pointsSpent, quality, artifactAppearanceID, appearanceModID, itemAppearanceID, altItemAppearanceID, altOnTop, artifactTier = C_ArtifactUI.GetEquippedArtifactInfo()
  33.     local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, xp, artifactTier)
  34.     self:SetMinMaxValues(0,xpForNextPoint)
  35.     self:SetValue(artifactXP)
  36.  
  37. --Begin Stack Overflow Fix
  38. --function for beautiful numbers
  39. local floor = math.floor
  40. local strlen, strsub = string.len, string.sub
  41. local function ReadableNumber(num)
  42.     local ret
  43.     local placeValue = ("%%.%df"):format(2) --probably can be improved into "%.0f"
  44.     local prefix = ""
  45.     if not num then
  46.         return "0 "
  47.     elseif num >= 1000000000000 then
  48.         prefix = " Tril" -- trillion
  49.         if mod(num, 1000000000000) < 10000000000 then
  50.             ret = floor(num / 1000000000000)
  51.         else
  52.             ret = placeValue:format(num / 1000000000000) .. " Tril" -- trillion
  53.         end
  54.     elseif num >= 1000000000 then
  55.         prefix = " Bil" -- billion
  56.         if mod(num, 1000000000) < 10000000 then
  57.             ret = floor(num / 1000000000)
  58.         else
  59.             ret = placeValue:format(num / 1000000000)
  60.         end
  61.     elseif num >= 1000000 then
  62.         prefix = " Mil" -- million
  63.         if mod(num, 1000000) < 10000 then
  64.             ret = floor(num / 1000000)
  65.         else
  66.             ret = placeValue:format(num / 1000000)
  67.         end
  68.     elseif num >= 1000 then
  69.         prefix = "k" -- thousand
  70.         ret = placeValue:format(num / 1000)
  71.     else
  72.         ret = num
  73.     end
  74.     local len = strlen(ret)
  75.     if len > 3 then
  76.         if strsub(ret, len-2, len-2) == "." and strsub(ret, len) == "0" then
  77.             ret = strsub(ret, 1, len-1)
  78.         end
  79.     end
  80.     return ret..prefix
  81. end
  82.  
  83. self.Text:SetFormattedText("Current %d%s/%d%s    +%d Points",artifactXP,prefix,xpForNextPoint,prefix,numPoints)
  84. end)
__________________

Last edited by Uitat : 09-25-17 at 10:18 PM.
  Reply With Quote