Quantcast
WoWInterface - View Single Post - code integration
View Single Post
09-25-17, 10:22 PM   #17
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,292
Most of the code is from Kakjens, I just messed with it a bit.

Edited to reduce the # coded IF statements.

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

Last edited by Fizzlemizz : 09-25-17 at 11:40 PM.
  Reply With Quote