Thread: Reputation Bar
View Single Post
05-12-19, 10:27 PM   #1
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Reputation Bar

I need some feedback/ideas/help on my reputation bar addon JWRepBar (I'll use the same ideas for my XP bar addon JWXPBar). As you can see in the screenshot, the reputation is just about to exceed the width of the bar. I'd like the bar to be dynamic and increase in size to accommodate the reputation displayed. Here are some ideas I have but, I'm not sold on them. I've looked at a lot of examples and they all seem to follow the approach to create a frame, then the bars, font then set the text later after calculating the rep.

1. Make the font smaller, but I like 18pt. font due to my eyes.
2. Make the bar wide enough to account for the longest reputation string. Not practical and could lead to some really long bars.
3. I tried to make the code that creates the frame and bars a function so I could call it and pass the width base on the length of the reputation string. It never worked very well, or I was missing something in my coding.
4. Change the format (i.e. 10.6k/12k), but I'm also not sure if I like it.
5. Modify the display of the rep so that after a set length it shows ... (Bilgewater Ca...).

Here is a screenshot:

Click image for larger version

Name:	repbar.png
Views:	172
Size:	58.9 KB
ID:	9229

Here is my code (I'm omitting the code from Zork's rLib as it doesn't directly affect the creation of the bar):
Lua Code:
  1. ## Interface: 80000
  2. ## Title: JWRepBar2
  3. ## Version: 8.0
  4. ## Notes: Simple Rep Bar
  5. ## X-Category: Character Advancement
  6. ## OptionalDeps: JWXPBar
  7. ## RequiredDeps: rLib
  8.  
  9. ## Author: JDoubleU00
  10. ## X-Email: [email]JDoubleU00@gmail.com[/email]
  11. ## X-Copyright: Copyright (c) 2017 JDoubleU00 MIT License
  12. ## X-Credits: Inspired by stExperience bar by Kendian
  13. ## X-Website: [url]https://github.com/JDoubleU00/JWRepBar[/url]
  14.  
  15. JWRepBar2.lua
Lua Code:
  1. -- Yes Another XP Bar.
  2.  
  3. --Config area
  4. local A, L = ...
  5.  
  6. L.addonName       = A
  7. L.dragFrames      = {}
  8. L.addonColor      = "00FF00AA"
  9. L.addonShortcut   = "jwrep"
  10.  
  11. local cfg = {
  12.     fader = {
  13.         fadeInAlpha = 1,
  14.         fadeInDuration = 0.3,
  15.         fadeInSmooth = "OUT",
  16.         fadeOutAlpha = 0.4,
  17.         fadeOutDuration = 0.9,
  18.         fadeOutSmooth = "OUT",
  19.         fadeOutDelay = 0,
  20.     },
  21.     JWBarHeight = 28,
  22.     JWBarWidth = 350,
  23.     JWBarPoint = {"CENTER", "JWRepBarFrame","CENTER", 0, 0},
  24.     --JWBarTexture = "Interface\\TargetingFrame\\UI-StatusBar",
  25.     JWBarTexture = "Interface\\AddOns\\rThreat\\media\\statusbar",
  26.     JWBarFont = [[Interface\Addons\SharedMedia_MyMedia\font\Lato-Regular.ttf]],
  27.     JWBarFontSize = 18,
  28.     JWBarFontFlags = "NONE",
  29. }
  30.  
  31.  
  32.  
  33. --Beyond here be dragons
  34. function comma_value(n)
  35.   return tostring(math.floor(n)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
  36. end
  37.  
  38. local function tchelper(first, rest)
  39.   return first:upper()..rest:lower()
  40. end
  41.  
  42. local JWRepBarFrame = CreateFrame("Frame", "JWRepBarFrame", UIParent)
  43. JWRepBarFrame:SetFrameStrata("HIGH")
  44. JWRepBarFrame:SetHeight(cfg.JWBarHeight)
  45. JWRepBarFrame:SetWidth(cfg.JWBarWidth)
  46. if IsAddOnLoaded("JWXPBar") then
  47.     JWRepBarFrame:SetPoint("BOTTOM", "JWXPBarFrame", "TOP", 0, 5)
  48. else
  49.     JWRepBarFrame:SetPoint("CENTER", UIPARENT, "CENTER", 0, -275)
  50. end
  51.    
  52. --drag frame
  53. rLib:CreateDragResizeFrame(JWRepBarFrame, L.dragFrames, -2, true)
  54.  
  55. if cfg.fader then
  56.     --frame fader
  57.     rLib:CreateFrameFader(JWRepBarFrame, cfg.fader)
  58. end
  59.  
  60. --Create Background and Border
  61. local backdrop = JWRepBarFrame:CreateTexture(nil, "BACKGROUND")
  62. backdrop:SetHeight(cfg.JWBarHeight)
  63. backdrop:SetWidth(cfg.JWBarWidth)
  64. backdrop:SetPoint(unpack(cfg.JWBarPoint))
  65. backdrop:SetTexture(cfg.JWBarTexture)
  66. backdrop:SetVertexColor(0.1, 0.1, 0.1)
  67. JWRepBarFrame.backdrop = backdrop
  68.  
  69. --Rep Bar
  70. local JWRepBar = CreateFrame("StatusBar", "JWRepBar", JWRepBarFrame)
  71. JWRepBar:SetWidth(cfg.JWBarWidth)
  72. JWRepBar:SetHeight(cfg.JWBarHeight)
  73. JWRepBar:SetPoint(unpack(cfg.JWBarPoint))
  74. JWRepBar:SetStatusBarTexture(cfg.JWBarTexture)
  75. JWRepBar:GetStatusBarTexture():SetHorizTile(false)
  76. JWRepBarFrame.JWRepBar = JWRepBar
  77.  
  78. --Create XP Text
  79. Text = JWRepBar:CreateFontString("JWRepBarText", "OVERLAY", "NumberFontNormal") --GameFontNormal
  80. Text:SetFont(cfg.JWBarFont, cfg.JWBarFontSize, cfg.JWBarFontFlags)
  81. Text:SetPoint("CENTER", JWRepBar, "CENTER",0,1)
  82. Text:SetAlpha(1)
  83.  
  84. local function UpdateStatus()
  85.     local JWRepName, JWRepStanding, JWRepMin, JWRepMax, JWRepCur = GetWatchedFactionInfo()
  86.     if JWRepName then
  87.         local JWRepColor = FACTION_BAR_COLORS[JWRepStanding]
  88.         JWRepBar:SetStatusBarColor(JWRepColor.r * 0.8, JWRepColor.g * 0.8, JWRepColor.b * 0.8)
  89.         JWRepBar:SetMinMaxValues(JWRepMin, JWRepMax)
  90.         JWRepBar:SetValue(JWRepCur)
  91.         JWRepName = JWRepName:gsub("(%a)([%w_']*)", tchelper) --Proper case
  92.         --JWRepName = format("%s %s/%s ", JWRepName, comma_value(JWRepCur), comma_value(JWRepMax))     
  93.         Text:SetText(format("%s %s/%s %.2f%%", JWRepName, comma_value(JWRepCur-JWRepMin), comma_value(JWRepMax-JWRepMin), (JWRepCur-JWRepMin)/(JWRepMax-JWRepMin)*100))
  94.         return
  95.     end
  96. end
  97.  
  98. JWRepBarFrame:RegisterEvent("UPDATE_FACTION")
  99. JWRepBarFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  100. JWRepBarFrame:SetScript("OnEvent", UpdateStatus)
  101.  
  102. --create slash commands
  103. rLib:CreateSlashCmd(L.addonName, L.addonShortcut, L.dragFrames, L.addonColor)

As always, any help is appreciated.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote