Quantcast
WoWInterface - View Single Post - code integration
View Single Post
09-25-17, 04:36 PM   #7
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
You had to add variable and use it for billions and trillions instead of replacing it everywhere (and forgetting to change "or 0" into "or 2"). Nevertheless, below is untested code:
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. --function for beautiful numbers
  29. local function ReadableNumber(num)
  30.     local ret
  31.     local placeValue = ("%%.%df"):format(0) --probably can be improved into "%.0f"
  32.     local placeValue1 = ("%%.%df"):format(2) --probably can be improved "%.2f"
  33.     if not num then
  34.         return "0 "
  35.     elseif num >= 1000000000000 then
  36.         ret = placeValue1:format(num / 1000000000000) .. " Tril" -- trillion
  37.     elseif num >= 1000000000 then
  38.         ret = placeValue1:format(num / 1000000000)  .. " Bil" -- billion
  39.     elseif num >= 1000000 then
  40.         ret = placeValue:format(num / 1000000) .. " Mil"-- million
  41.     elseif num >= 1000 then
  42.         ret = placeValue:format(num / 1000) .. "k" -- thousand
  43.     else
  44.         ret = num .. " "-- hundreds
  45.     end
  46.     return ret
  47. end
  48.  
  49. -- now lets update the position and text on the bar so we can always have accurate info
  50. derArtifactBar:SetScript("OnEvent", function(self, event, ...)
  51.     if not HasArtifactEquipped() then self:Hide() return end
  52.     self:Show()
  53.     local itemID, altItemID, name, icon, xp, pointsSpent, quality, artifactAppearanceID, appearanceModID, itemAppearanceID, altItemAppearanceID, altOnTop, artifactTier = C_ArtifactUI.GetEquippedArtifactInfo()
  54.     local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, xp, artifactTier)
  55.     self:SetMinMaxValues(0,xpForNextPoint)
  56.     self:SetValue(artifactXP)
  57.  
  58. --Begin Stack Overflow Fix
  59.  
  60. local currentAXP = ReadableNumber(artifactXP)
  61. local nextAXP = ReadableNumber(xpForNextPoint)
  62.  
  63.     --End Stack Overflow Fix **** also added the variable into the self.text:SetFormattedText Below
  64.    
  65.    self.Text:SetFormattedText("Current %s/%s    +%d Points",currentAXP, nextAXP, numPoints)
  66. end)
Several things could be improved, for example, reducing of used variables.

Last edited by Kakjens : 09-25-17 at 06:13 PM.
  Reply With Quote