Thread Tools Display Modes
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
05-16-19, 09:37 AM   #2
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Let me try rephrasing my question. Once you create a frame, can you change the width dynamically by using frame:SetWidth?
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
05-16-19, 10:11 AM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
It depends on your SetPoint but if you've only set one point then yes. If you set a TOPLEFT/BOTTOMRIGHT or SetAllPoints then you would resize the the "container" (if you've only used one referece frame).

You might try a slightly taller bar with a slightly smaller font and the FontString with a SetAllPoints to the bar so you get two lines that wrap.

If you fix the width of the FontString to the width of the bar you will automaticaly get a "Text..." if the text gets too long.

Two FontStrings, Name(Justified Left) and Value (Justified Right or Center) sized 70/30 (80/20 or whatever works) across the bar so you get Steamwh... 92% if the name gets too long
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 05-16-19 at 11:40 AM.
  Reply With Quote
05-16-19, 12:49 PM   #4
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Originally Posted by Fizzlemizz View Post
It depends on your SetPoint but if you've only set one point then yes. If you set a TOPLEFT/BOTTOMRIGHT or SetAllPoints then you would resize the the "container" (if you've only used one referece frame).

You might try a slightly taller bar with a slightly smaller font and the FontString with a SetAllPoints to the bar so you get two lines that wrap.

If you fix the width of the FontString to the width of the bar you will automaticaly get a "Text..." if the text gets too long.

Two FontStrings, Name(Justified Left) and Value (Justified Right or Center) sized 70/30 (80/20 or whatever works) across the bar so you get Steamwh... 92% if the name gets too long
Thanks, I'll try it when I get home from work.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
06-06-19, 08:16 AM   #5
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
I meant to post earlier, that your suggestions worked for me! I have some other minor annoyances that I'm in the process of addressing.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
06-06-19, 09:30 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Fizzlemizz View Post
Two FontStrings, Name(Justified Left) and Value (Justified Right or Center) sized 70/30 (80/20 or whatever works) across the bar so you get Steamwh... 92% if the name gets too long
What I usually do, instead of manually setting the size for each FontString, I set the RIGHT anchor of Name to the LEFT point of Value. This dynamically allocates the width of both FontStrings without wasting space that could be used for the former.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Reputation Bar

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off