Skip to content

Commit

Permalink
Add custom label settings
Browse files Browse the repository at this point in the history
  • Loading branch information
zanony committed Aug 31, 2019
1 parent 2df847c commit c73dfcf
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 38 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
88 changes: 50 additions & 38 deletions Chocolate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ local function resizeFrame(self)
if self.icon and settings.showIcon then
width = width + self.icon:GetWidth() + textOffset
end
if settings.showText then
if settings.widthBehavior == "fixed" then
width = width + settings.width
elseif settings.widthBehavior == "max" then
local textWidth = self.text:GetStringWidth()
width = width + min(textWidth, settings.width)
else
local textWidth = self.text:GetStringWidth()
width = width + textWidth
end

local textWidth = (settings.showText or settings.showLabel) and self.text:GetStringWidth() or 0
--local labelWidth = settings.showLabel and self.label:GetStringWidth() or 0

if settings.widthBehavior == "fixed" then
width = width + settings.width
elseif settings.widthBehavior == "max" then
width = width + min(textWidth, settings.width)
else
width = width + textWidth
end

self:SetWidth(width)
if self.bar then self.bar:UpdateCenter() end
end
Expand All @@ -38,21 +39,43 @@ local function TextUpdater(frame, value)
value = string.gsub(value, "|c........", "")
value = string.gsub(value, "|r", "")
end
local label = frame.settings.showLabel and frame.obj.label or nil
local text = frame.settings.showText and frame.obj.text or nil

if label and text then
frame.text:SetText(string.format("|c%s%s:|r %s", db.labelColor, label, text))
elseif label then
frame.text:SetText(string.format("|c%s%s|r", db.labelColor, label))
elseif text then
frame.text:SetText(text)

if frame.settings.showText then
frame.text:SetText(frame.labelText..value)
else
frame.text:SetText("")
frame.text:SetText(frame.labelText)
end

resizeFrame(frame)
end

local function isCustomLabel(frame)
return frame.settings.customLabel and frame.settings.customLabel ~= ""
end

local function getLabelFromObjOrSettings(frame, value)
if isCustomLabel(frame) then
return frame.settings.customLabel
else
if db.forceColor then
value = string.gsub(value, "|c........", "")
value = string.gsub(value, "|r", "")
end
return value and value or "";
end
end

local function LabelUpdater(frame, value)
if frame.settings.showLabel then
local delimiter = frame.settings.showText and ":" or ""
frame.labelText = string.format("|c%s%s%s|r ", db.labelColor, getLabelFromObjOrSettings(frame, value), delimiter)
else
frame.labelText = ""
end

TextUpdater(frame, frame.obj.text)
end

local function SettingsUpdater(self, value)
local settings = self.settings

Expand Down Expand Up @@ -85,8 +108,7 @@ local function SettingsUpdater(self, value)
self.text:SetPoint("LEFT", self, 0, 0)
end

TextUpdater(self, self.obj.text)

LabelUpdater(self, self.obj.label)
resizeFrame(self)
end

Expand Down Expand Up @@ -125,7 +147,7 @@ end
-- updaters code taken with permission from fortress
local updaters = {
text = TextUpdater,
label = TextUpdater,
label = LabelUpdater,
resizeFrame = resizeFrame,

icon = function(frame, value, name)
Expand Down Expand Up @@ -336,7 +358,7 @@ end

function ChocolatePiece:New(name, obj, settings, database)
db = database
local text = obj.text

local icon = obj.icon
local chocolate = CreateFrame("Button", "Chocolate" .. name)
chocolate.highlight = highlightBackground
Expand All @@ -348,12 +370,10 @@ function ChocolatePiece:New(name, obj, settings, database)
chocolate:EnableMouse(true)
chocolate:RegisterForDrag("LeftButton")

local fontPath = db.fontPath == " " and LSM:GetDefault("font") or db.fontPath

chocolate.text = chocolate:CreateFontString(nil, nil, "GameFontHighlight")
if db.fontPath == " " then
chocolate.text:SetFont(LSM:GetDefault("font"), db.fontSize)
else
chocolate.text:SetFont(db.fontPath, db.fontSize) --will onl be set when db.fontPath is valid
end
chocolate.text:SetFont(db.fontPath, db.fontSize)
chocolate.text:SetJustifyH("LEFT")

if icon then
Expand All @@ -373,20 +393,12 @@ function ChocolatePiece:New(name, obj, settings, database)
obj.label = name
end

TextUpdater(chocolate, text);
---if text then
--elseif obj.label then
--
--else
---- obj.text = name
-- chocolate.text:SetText(name)
--end

chocolate.name = name
chocolate:SetMovable(true)
chocolate:SetScript("OnDragStart", OnDragStart)
chocolate:SetScript("OnDragStop", OnDragStop)
SettingsUpdater(chocolate, settings.showText)
LabelUpdater(chocolate, obj.label)
return chocolate
end

Expand Down
24 changes: 24 additions & 0 deletions Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,21 @@ local function SetIcon(info, value)
ChocolateBar:AttributeChanged(nil, name, "updateSettings", value)
end



local function GetCustomLabel(info, value)
local cleanName = info[#info-2]
local name = chocolateOptions[cleanName].desc
return db.objSettings[name].customLabel
end

local function SetCustomLabel(info, value)
local cleanName = info[#info-2]
local name = chocolateOptions[cleanName].desc
db.objSettings[name].customLabel = value
ChocolateBar:AttributeChanged(nil, name, "updateSettings", value)
end

local function GetLabel(info, value)
local cleanName = info[#info-2]
local name = chocolateOptions[cleanName].desc
Expand Down Expand Up @@ -1619,6 +1634,15 @@ function ChocolateBar:AddObjectOptions(name,obj)
set = SetWidth,
disabled = IsDisabledTextWidth,
},
customLabel = {
type = 'input',
order = 2,
name = L["Custom Label"],
desc = L["Change the label of this plugin."],
width = "full",
get = GetCustomLabel,
set = SetCustomLabel,
},
},
},
textOffset = {
Expand Down
3 changes: 3 additions & 0 deletions localization/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ local AceLocale = LibStub:GetLibrary("AceLocale-3.0")
local L = AceLocale:NewLocale("ChocolateBar", "enUS", true)
if not L then return end


L["Custom Label"] = true
L["Change the label of this plugin."] = true
L["Show Label"] = true
L["Colorized Dragging"] = true
L["Colorize frames during drag & drop."] = true
Expand Down
Empty file modified pics/chocolatebar.tga
100644 → 100755
Empty file.
Empty file modified pics/chocolatebarGray.tga
100644 → 100755
Empty file.

0 comments on commit c73dfcf

Please sign in to comment.