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:
repbar.png
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:
## Interface: 80000
## Title: JWRepBar2
## Version: 8.0
## Notes: Simple Rep Bar
## X-Category: Character Advancement
## OptionalDeps: JWXPBar
## RequiredDeps: rLib
## Author: JDoubleU00
## X-Email: [email]JDoubleU00@gmail.com[/email]
## X-Copyright: Copyright (c) 2017 JDoubleU00 MIT License
## X-Credits: Inspired by stExperience bar by Kendian
## X-Website: [url]https://github.com/JDoubleU00/JWRepBar[/url]
JWRepBar2.lua
Lua Code:
-- Yes Another XP Bar.
--Config area
local A, L = ...
L.addonName = A
L.dragFrames = {}
L.addonColor = "00FF00AA"
L.addonShortcut = "jwrep"
local cfg = {
fader = {
fadeInAlpha = 1,
fadeInDuration = 0.3,
fadeInSmooth = "OUT",
fadeOutAlpha = 0.4,
fadeOutDuration = 0.9,
fadeOutSmooth = "OUT",
fadeOutDelay = 0,
},
JWBarHeight = 28,
JWBarWidth = 350,
JWBarPoint = {"CENTER", "JWRepBarFrame","CENTER", 0, 0},
--JWBarTexture = "Interface\\TargetingFrame\\UI-StatusBar",
JWBarTexture = "Interface\\AddOns\\rThreat\\media\\statusbar",
JWBarFont = [[Interface\Addons\SharedMedia_MyMedia\font\Lato-Regular.ttf]],
JWBarFontSize = 18,
JWBarFontFlags = "NONE",
}
--Beyond here be dragons
function comma_value(n)
return tostring(math.floor(n)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
end
local function tchelper(first, rest)
return first:upper()..rest:lower()
end
local JWRepBarFrame = CreateFrame("Frame", "JWRepBarFrame", UIParent)
JWRepBarFrame:SetFrameStrata("HIGH")
JWRepBarFrame:SetHeight(cfg.JWBarHeight)
JWRepBarFrame:SetWidth(cfg.JWBarWidth)
if IsAddOnLoaded("JWXPBar") then
JWRepBarFrame:SetPoint("BOTTOM", "JWXPBarFrame", "TOP", 0, 5)
else
JWRepBarFrame:SetPoint("CENTER", UIPARENT, "CENTER", 0, -275)
end
--drag frame
rLib:CreateDragResizeFrame(JWRepBarFrame, L.dragFrames, -2, true)
if cfg.fader then
--frame fader
rLib:CreateFrameFader(JWRepBarFrame, cfg.fader)
end
--Create Background and Border
local backdrop = JWRepBarFrame:CreateTexture(nil, "BACKGROUND")
backdrop:SetHeight(cfg.JWBarHeight)
backdrop:SetWidth(cfg.JWBarWidth)
backdrop:SetPoint(unpack(cfg.JWBarPoint))
backdrop:SetTexture(cfg.JWBarTexture)
backdrop:SetVertexColor(0.1, 0.1, 0.1)
JWRepBarFrame.backdrop = backdrop
--Rep Bar
local JWRepBar = CreateFrame("StatusBar", "JWRepBar", JWRepBarFrame)
JWRepBar:SetWidth(cfg.JWBarWidth)
JWRepBar:SetHeight(cfg.JWBarHeight)
JWRepBar:SetPoint(unpack(cfg.JWBarPoint))
JWRepBar:SetStatusBarTexture(cfg.JWBarTexture)
JWRepBar:GetStatusBarTexture():SetHorizTile(false)
JWRepBarFrame.JWRepBar = JWRepBar
--Create XP Text
Text = JWRepBar:CreateFontString("JWRepBarText", "OVERLAY", "NumberFontNormal") --GameFontNormal
Text:SetFont(cfg.JWBarFont, cfg.JWBarFontSize, cfg.JWBarFontFlags)
Text:SetPoint("CENTER", JWRepBar, "CENTER",0,1)
Text:SetAlpha(1)
local function UpdateStatus()
local JWRepName, JWRepStanding, JWRepMin, JWRepMax, JWRepCur = GetWatchedFactionInfo()
if JWRepName then
local JWRepColor = FACTION_BAR_COLORS[JWRepStanding]
JWRepBar:SetStatusBarColor(JWRepColor.r * 0.8, JWRepColor.g * 0.8, JWRepColor.b * 0.8)
JWRepBar:SetMinMaxValues(JWRepMin, JWRepMax)
JWRepBar:SetValue(JWRepCur)
JWRepName = JWRepName:gsub("(%a)([%w_']*)", tchelper) --Proper case
--JWRepName = format("%s %s/%s ", JWRepName, comma_value(JWRepCur), comma_value(JWRepMax))
Text:SetText(format("%s %s/%s %.2f%%", JWRepName, comma_value(JWRepCur-JWRepMin), comma_value(JWRepMax-JWRepMin), (JWRepCur-JWRepMin)/(JWRepMax-JWRepMin)*100))
return
end
end
JWRepBarFrame:RegisterEvent("UPDATE_FACTION")
JWRepBarFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
JWRepBarFrame:SetScript("OnEvent", UpdateStatus)
--create slash commands
rLib:CreateSlashCmd(L.addonName, L.addonShortcut, L.dragFrames, L.addonColor)
As always, any help is appreciated.