/trunk
--[[-------------------------------------------------------------------- |
PhanxConfig-ScrollingDropdown |
Simple scrolling dropdown widget generator. Requires LibStub. |
Based on tekKonfig-Dropdown by Tekkub and OmniCC_Options by Tuller. |
Requires PhanxConfig-Dropdown. |
This library is not intended for use by other authors. Absolutely no |
support of any kind will be provided for other authors using it, and |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local PhanxConfigDropdown = LibStub:GetLibrary("PhanxConfig-Dropdown", true) |
assert(PhanxConfigDropdown, "PhanxConfig-ScrollingDropdown requires PhanxConfig-Dropdown") |
local MINOR_VERSION = tonumber(("$Revision$"):match("%d+")) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-ScrollingDropdown", MINOR_VERSION) |
if not lib then return end |
local MAX_LIST_SIZE = 15 |
local function ListButton_OnClick(self) |
local dropdown = self:GetParent():GetParent() |
dropdown.selected = self.value |
dropdown.list:Hide() |
local container = dropdown:GetParent() |
container.valueText:SetText(self.value) |
local handler = container.ApplyValue or container.OnValueChanged |
if handler then |
handler(container, self.value) |
end |
PlaySound("UChatScrollButton") |
end |
local function CreateListButton(parent) |
local button = CreateFrame("Button", nil, parent) |
button:SetHeight(UIDROPDOWNMENU_BUTTON_HEIGHT) |
button.label = button:CreateFontString() |
button.label:SetFont((GameFontHighlightSmallLeft:GetFont()), UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT) |
button.label:SetJustifyH("LEFT") |
button.label:SetPoint("LEFT", 27, 0) |
button.check = button:CreateTexture(nil, "ARTWORK") |
button.check:SetWidth(24) |
button.check:SetHeight(24) |
button.check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check") |
button.check:SetPoint("LEFT") |
local highlight = button:CreateTexture(nil, "BACKGROUND") |
highlight:SetAllPoints(button) |
highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") |
highlight:SetAlpha(0.4) |
highlight:SetBlendMode("ADD") |
highlight:Hide() |
button:SetHighlightTexture(highlight) |
button:SetScript("OnClick", ListButton_OnClick) |
return button |
end |
local function UpdateList(self) |
local buttons = self.buttons |
local items = self:GetParent().items |
local listSize = min(#items, MAX_LIST_SIZE) |
local scrollFrame = self.scrollFrame |
local offset = scrollFrame.offset |
FauxScrollFrame_Update(scrollFrame, #items, listSize, UIDROPDOWNMENU_BUTTON_HEIGHT) |
local selected = self:GetParent().selected |
for i = 1, listSize do |
local index = i + offset |
local button = self.buttons[i] |
local item = items[index] |
if item then |
button.value = item |
button.label:SetText(item) |
if item == selected then |
button.check:Show() |
else |
button.check:Hide() |
end |
button:SetWidth(self.width) |
button:Show() |
else |
button.value = nil |
button.label:SetText() |
button.check:Hide() |
button:Hide() |
end |
if self.OnListButtonChanged then |
self:OnListButtonChanged(button, item, selected) |
end |
end |
for i = listSize + 1, #buttons do |
buttons[i]:Hide() |
end |
if self.scrollFrame:IsShown() then |
self:SetWidth(self.width + 50) |
else |
self:SetWidth(self.width + 30) |
end |
self:SetHeight((listSize * UIDROPDOWNMENU_BUTTON_HEIGHT) + (UIDROPDOWNMENU_BORDER_HEIGHT * 2)) |
end |
local function CreateList(parent) |
local list = CreateFrame("Button", parent:GetName() .. "List", parent) |
list:SetToplevel(true) |
list:Raise() |
list.text = list:CreateFontString() |
local ff = GameFontNormal:GetFont() |
list.text:SetFont(ff, UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT + 2) |
list.buttons = setmetatable({}, { __index = function(t, i) |
local button = CreateListButton(list) |
if i > 1 then |
button:SetPoint("TOPLEFT", t[i-1], "BOTTOMLEFT") |
else |
button:SetPoint("TOPLEFT", 15, -15) |
end |
t[i] = button |
return button |
end }) |
list.scrollFrame = CreateFrame("ScrollFrame", list:GetName() .. "ScrollFrame", list, "FauxScrollFrameTemplate") |
list.scrollFrame:SetPoint("TOPLEFT", 12, -14) |
list.scrollFrame:SetPoint("BOTTOMRIGHT", -36, 13) |
list.scrollFrame:SetScript("OnVerticalScroll", function(self, delta) |
FauxScrollFrame_OnVerticalScroll(self, delta, UIDROPDOWNMENU_BUTTON_HEIGHT, function() UpdateList(list) end) |
end) |
list:SetBackdrop({ |
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", |
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", |
insets = { left = 11, right = 12, top = 12, bottom = 11 }, |
tile = true, tileSize = 32, edgeSize = 32, |
}) |
list:SetScript("OnShow", function(self) |
self.width = 0 |
for i, item in pairs(self:GetParent().items) do |
self.text:SetText(item) |
self.width = max(self.text:GetStringWidth() + 60, self.width) |
end |
UpdateList(self) |
end) |
list:SetScript("OnHide", list.Hide) |
list:SetScript("OnClick", list.Hide) |
list:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 6, 8) |
list:Hide() |
return list |
end |
local function DropdownButton_OnClick(self) |
local list = self:GetParent().list |
if list then |
if list:IsShown() then |
list:Hide() |
else |
list:Show() |
end |
else |
local dropdown = self:GetParent() |
dropdown.list = CreateList(dropdown) |
dropdown.list:Show() |
end |
end |
local function GetValue(self) |
return self.dropdown.selected or self.valueText:GetText() |
end |
local function SetValue(self, value, text) |
self.valueText:SetText(text or value) |
self.dropdown.selected = value |
end |
local function SetValue(self, value, text) |
self.valueText:SetText(text or value) |
self.dropdown.selected = value |
end |
function lib:New(parent, name, desc, items) |
assert( type(parent) == "table" and parent.CreateFontString, "PhanxConfig-ScrollingDropdown: Parent is not a valid frame!" ) |
if type(name) ~= "string" then name = nil end |
if type(desc) ~= "string" then desc = nil end |
local container = PhanxConfigDropdown.CreateDropdown(parent, name, nil, desc) |
if type(items) == "table" then |
container.button:SetScript("OnClick", DropdownButton_OnClick) |
container.dropdown.items = items |
end |
container.SetValue = SetValue |
return container |
end |
--[[-------------------------------------------------------------------- |
PhanxConfig-ScrollingDropdown |
Simple scrolling dropdown widget generator. Requires LibStub. |
Based on tekKonfig-Dropdown by Tekkub and OmniCC_Options by Tuller. |
Requires PhanxConfig-Dropdown. |
This library is not intended for use by other authors. Absolutely no |
support of any kind will be provided for other authors using it, and |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local PhanxConfigDropdown = LibStub:GetLibrary("PhanxConfig-Dropdown", true) |
assert(PhanxConfigDropdown, "PhanxConfig-ScrollingDropdown requires PhanxConfig-Dropdown") |
local MINOR_VERSION = tonumber(("$Revision$"):match("%d+")) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-ScrollingDropdown", MINOR_VERSION) |
if not lib then return end |
local MAX_LIST_SIZE = 15 |
local function ListButton_OnClick(self) |
local dropdown = self:GetParent():GetParent() |
dropdown.selected = self.value |
dropdown.list:Hide() |
local container = dropdown:GetParent() |
container.valueText:SetText(self.value) |
local handler = container.func or container.ApplyValue or container.OnValueChanged |
if handler then |
handler(container, self.value) |
end |
PlaySound("UChatScrollButton") |
end |
local function CreateListButton(parent) |
local button = CreateFrame("Button", nil, parent) |
button:SetHeight(UIDROPDOWNMENU_BUTTON_HEIGHT) |
button.label = button:CreateFontString() |
button.label:SetFont((GameFontHighlightSmallLeft:GetFont()), UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT) |
button.label:SetJustifyH("LEFT") |
button.label:SetPoint("LEFT", 27, 0) |
button.check = button:CreateTexture(nil, "ARTWORK") |
button.check:SetWidth(24) |
button.check:SetHeight(24) |
button.check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check") |
button.check:SetPoint("LEFT") |
local highlight = button:CreateTexture(nil, "BACKGROUND") |
highlight:SetAllPoints(button) |
highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") |
highlight:SetAlpha(0.4) |
highlight:SetBlendMode("ADD") |
highlight:Hide() |
button:SetHighlightTexture(highlight) |
button:SetScript("OnClick", ListButton_OnClick) |
return button |
end |
local function UpdateList(self) |
local buttons = self.buttons |
local items = self:GetParent().items |
local listSize = min(#items, MAX_LIST_SIZE) |
local scrollFrame = self.scrollFrame |
local offset = scrollFrame.offset |
FauxScrollFrame_Update(scrollFrame, #items, listSize, UIDROPDOWNMENU_BUTTON_HEIGHT) |
local selected = self:GetParent().selected |
for i = 1, listSize do |
local index = i + offset |
local button = self.buttons[i] |
local item = items[index] |
if item then |
button.value = item |
button.label:SetText(item) |
if item == selected then |
button.check:Show() |
else |
button.check:Hide() |
end |
button:SetWidth(self.width) |
button:Show() |
else |
button.value = nil |
button.label:SetText() |
button.check:Hide() |
button:Hide() |
end |
if self.OnListButtonChanged then |
self:OnListButtonChanged(button, item, selected) |
end |
end |
for i = listSize + 1, #buttons do |
buttons[i]:Hide() |
end |
if self.scrollFrame:IsShown() then |
self:SetWidth(self.width + 50) |
else |
self:SetWidth(self.width + 30) |
end |
self:SetHeight((listSize * UIDROPDOWNMENU_BUTTON_HEIGHT) + (UIDROPDOWNMENU_BORDER_HEIGHT * 2)) |
end |
local function CreateList(parent) |
local list = CreateFrame("Button", parent:GetName() .. "List", parent) |
list:SetToplevel(true) |
list:Raise() |
list.text = list:CreateFontString() |
local ff = GameFontNormal:GetFont() |
list.text:SetFont(ff, UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT + 2) |
list.buttons = setmetatable({}, { __index = function(t, i) |
local button = CreateListButton(list) |
if i > 1 then |
button:SetPoint("TOPLEFT", t[i-1], "BOTTOMLEFT") |
else |
button:SetPoint("TOPLEFT", 15, -15) |
end |
t[i] = button |
return button |
end }) |
list.scrollFrame = CreateFrame("ScrollFrame", list:GetName() .. "ScrollFrame", list, "FauxScrollFrameTemplate") |
list.scrollFrame:SetPoint("TOPLEFT", 12, -14) |
list.scrollFrame:SetPoint("BOTTOMRIGHT", -36, 13) |
list.scrollFrame:SetScript("OnVerticalScroll", function(self, delta) |
FauxScrollFrame_OnVerticalScroll(self, delta, UIDROPDOWNMENU_BUTTON_HEIGHT, function() UpdateList(list) end) |
end) |
list:SetBackdrop({ |
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", |
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", |
insets = { left = 11, right = 12, top = 12, bottom = 11 }, |
tile = true, tileSize = 32, edgeSize = 32, |
}) |
list:SetScript("OnShow", function(self) |
self.width = 0 |
for i, item in pairs(self:GetParent().items) do |
self.text:SetText(item) |
self.width = max(self.text:GetStringWidth() + 60, self.width) |
end |
UpdateList(self) |
end) |
list:SetScript("OnHide", list.Hide) |
list:SetScript("OnClick", list.Hide) |
list:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 6, 8) |
list:Hide() |
return list |
end |
local function DropdownButton_OnClick(self) |
local list = self:GetParent().list |
if list then |
if list:IsShown() then |
list:Hide() |
else |
list:Show() |
end |
else |
local dropdown = self:GetParent() |
dropdown.list = CreateList(dropdown) |
dropdown.list:Show() |
end |
end |
------------------------------------------------------------------------ |
local methods = {} |
function methods:GetValue() |
return self.dropdown.selected or self.valueText:GetText() |
end |
function methods:SetValue(value, text) |
self.valueText:SetText(text or value) |
self.dropdown.selected = value |
end |
function methods:GetTooltipText() |
return self.tooltipText |
end |
function methods:SetTooltipText(text) |
self.tooltipText = text |
end |
function methods:SetFunction(func) |
self.func = func |
end |
------------------------------------------------------------------------ |
function lib:New(parent, name, tooltipText, items) |
assert(type(parent) == "table" and parent.CreateFontString, "PhanxConfig-ScrollingDropdown: Parent is not a valid frame!") |
if type(name) ~= "string" then name = nil end |
if type(tooltipText) ~= "string" then tooltipText = nil end |
local container = PhanxConfigDropdown.CreateDropdown(parent, name, nil, tooltipText) |
if type(items) == "table" then |
container.button:SetScript("OnClick", DropdownButton_OnClick) |
container.dropdown.items = items |
end |
for name, func in pairs(methods) do |
container[name] = func |
end |
return container |
end |
function lib.CreateScrollingDropdown(...) return lib:New(...) end |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-Button", MINOR_VERSION) |
if not lib then return end |
local scripts = { |
OnEnter = function(self) |
if self.hint then |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
GameTooltip:SetText(self.hint, nil, nil, nil, nil, true) |
end |
end, |
OnLeave = function(self) |
GameTooltip:Hide() |
end, |
OnClick = function(self, button) |
PlaySound("gsTitleOptionOK") |
if self.OnClick then |
self:OnClick(button) |
end |
end, |
OnMouseDown = function(self, button) |
if self:IsEnabled() then |
self.Left:SetTexture("Interface\\Buttons\\UI-Panel-Button-Down") |
self.Middle:SetTexture("Interface\\Buttons\\UI-Panel-Button-Down") |
self.Right:SetTexture("Interface\\Buttons\\UI-Panel-Button-Down") |
end |
end, |
OnMouseUp = function(self, button) |
if self:IsEnabled() then |
self.Left:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up") |
self.Middle:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up") |
self.Right:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up") |
end |
end, |
OnDisable = function(self) |
self.Left:SetTexture("Interface\\Buttons\\UI-Panel-Button-Disabled") |
self.Middle:SetTexture("Interface\\Buttons\\UI-Panel-Button-Disabled") |
self.Right:SetTexture("Interface\\Buttons\\UI-Panel-Button-Disabled") |
end, |
OnEnable = function(self) |
------------------------------------------------------------------------ |
local scripts = {} |
function scripts:OnClick(button) |
PlaySound("gsTitleOptionOK") |
local func = self.func or self.OnClick |
if func then |
func(self, button) |
end |
end |
function scripts:OnEnter() |
if self.tooltipText then |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, true) |
end |
end |
function scripts:OnLeave() |
GameTooltip:Hide() |
end |
function scripts:OnMouseDown(button) |
if self:IsEnabled() then |
self.Left:SetTexture("Interface\\Buttons\\UI-Panel-Button-Down") |
self.Middle:SetTexture("Interface\\Buttons\\UI-Panel-Button-Down") |
self.Right:SetTexture("Interface\\Buttons\\UI-Panel-Button-Down") |
end |
end |
function scripts:OnMouseUp(button) |
if self:IsEnabled() then |
self.Left:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up") |
self.Middle:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up") |
self.Right:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up") |
end, |
} |
end |
end |
local methods = { |
SetHint = function(self, text) |
self.hint = text |
end, |
GetHint = function(self) |
return self.hint |
end, |
} |
function scripts:OnEnable() |
self.Left:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up") |
self.Middle:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up") |
self.Right:SetTexture("Interface\\Buttons\\UI-Panel-Button-Up") |
end |
function scripts:OnDisable() |
self.Left:SetTexture("Interface\\Buttons\\UI-Panel-Button-Disabled") |
self.Middle:SetTexture("Interface\\Buttons\\UI-Panel-Button-Disabled") |
self.Right:SetTexture("Interface\\Buttons\\UI-Panel-Button-Disabled") |
end |
function lib:New(parent, name, hint) |
------------------------------------------------------------------------ |
local methods = {} |
function methods:GetTooltipText() |
return self.tooltipText |
end |
function methods:SetTooltipText(text) |
self.tooltipText = text |
end |
function methods:SetFunction(func) |
self.func = func |
end |
------------------------------------------------------------------------ |
function lib:New(parent, name, tooltipText) |
assert(type(parent) == "table" and parent.CreateFontString, "PhanxConfig-Button: Parent is not a valid frame!") |
if type(name) ~= "string" then name = nil end |
if type(hint) ~= "string" then hint = nil end |
if type(tooltipText) ~= "string" then tooltipText = nil end |
local button = CreateFrame("Button", nil, parent) |
button:SetWidth(math.min(44, button:GetTextWidth() + 8)) |
button:SetHeight(24) |
button.hint = hint |
button.tooltipText = tooltipText |
return button |
end |
local function OptionsPanel_OnShow(self) |
if InCombatLockdown() then return end |
local target = self.parent or self.name |
local i = 1 |
local i, target = 1, self.parent or self.name |
while true do |
local button = _G[ "InterfaceOptionsFrameAddOnsButton" .. i ] |
local button = _G["InterfaceOptionsFrameAddOnsButton"..i] |
if not button then break end |
local element = button.element |
if element.name == target then |
if element.hasChildren and element.collapsed then |
_G[ "InterfaceOptionsFrameAddOnsButton" .. i .. "Toggle" ]:Click() |
_G["InterfaceOptionsFrameAddOnsButton"..i.."Toggle"]:Click() |
end |
return |
end |
i = i + 1 |
end |
end |
local function OptionsPanel_OnClose(self) |
if InCombatLockdown() then return end |
local target = self.parent or self.name |
local i = 1 |
local i, target = 1, self.parent or self.name |
while true do |
local button = _G[ "InterfaceOptionsFrameAddOnsButton" .. i ] |
local button = _G["InterfaceOptionsFrameAddOnsButton"..i] |
if not button then break end |
local element = button.element |
if element.name == target then |
if element.hasChildren and not element.collapsed then |
local selection = InterfaceOptionsFrameAddOns.selection |
if not selection or selection.parent ~= target then |
_G[ "InterfaceOptionsFrameAddOnsButton" .. i .. "Toggle" ]:Click() |
_G["InterfaceOptionsFrameAddOnsButton"..i.."Toggle"]:Click() |
end |
end |
return |
end |
i = i + 1 |
end |
end |
--[[-------------------------------------------------------------------- |
PhanxConfig-ColorPicker |
Simple color picker widget generator. |
Based on OmniCC_Options by Tuller. |
Requires LibStub. |
This library is not intended for use by other authors. Absolutely no |
support of any kind will be provided for other authors using it, and |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local MINOR_VERSION = tonumber(("$Revision$"):match("%d+")) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-ColorPicker", MINOR_VERSION) |
if not lib then return end |
local prototype = {} |
function prototype:OnClick() |
self:OnLeave() |
if ColorPickerFrame:IsShown() then |
ColorPickerFrame:Hide() |
else |
self.r, self.g, self.b, self.opacity = self:GetValue() |
OpenColorPicker(self) |
ColorPickerFrame:SetFrameStrata("TOOLTIP") |
ColorPickerFrame:Raise() |
end |
end |
function prototype:OnEnter() |
local color = NORMAL_FONT_COLOR |
self.bg:SetVertexColor(color.r, color.g, color.b) |
if self.desc then |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
GameTooltip:SetText(self.desc, nil, nil, nil, nil, true) |
end |
end |
function prototype:OnLeave() |
local color = HIGHLIGHT_FONT_COLOR |
self.bg:SetVertexColor(color.r, color.g, color.b) |
GameTooltip:Hide() |
end |
function prototype:GetValue() |
local r, g, b, a = self.swatch:GetVertexColor() |
return floor(r * 100 + 0.5) / 100, floor(g * 100 + 0.5) / 100, floor(b * 100 + 0.5) / 100, floor(a * 100 + 0.5) / 100 |
end |
function prototype:SetValue(r, g, b, a) |
if type(r) == "table" then |
r, g, b, a = r.r or r[1], r.g or r[2], r.b or r[3], r.a or r[4] |
end |
r = floor(r * 100 + 0.5) / 100 |
g = floor(g * 100 + 0.5) / 100 |
b = floor(b * 100 + 0.5) / 100 |
a = a and self.hasOpacity and (floor(a * 100 + 0.5) / 100) or 1 |
self.swatch:SetVertexColor(r, g, b, a) |
self.bg:SetAlpha(a) |
local handler = self.ApplyValue or self.OnValueChanged |
if handler then |
-- Ignore updates while ColorPickerFrame:IsShown() if desired. |
handler(self, r, g, b, a) |
else |
-- Deprecated!!! |
if self.OnColorChanged then |
-- use this for immediate visual updating |
self:OnColorChanged(r, g, b, a) |
end |
if not ColorPickerFrame:IsShown() and self.PostColorChanged then |
-- use this for final updating after the color picker closes |
self:PostColorChanged(r, g, b, a) |
end |
end |
end |
function lib:New(parent, name, desc, hasOpacity) |
assert( type(parent) == "table" and parent.CreateFontString, "PhanxConfig-ColorPicker: Parent is not a valid frame!" ) |
if type(name) ~= "string" then name = nil end |
if type(desc) ~= "string" then desc = nil end |
local frame = CreateFrame("Button", nil, parent) |
frame:SetHeight(26) |
local swatch = frame:CreateTexture(nil, "OVERLAY") |
swatch:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch") |
swatch:SetPoint("LEFT", 5, 1) |
swatch:SetSize(17, 18) |
frame.swatch = swatch |
local bg = frame:CreateTexture(nil, "BACKGROUND") |
bg:SetTexture(1, 1, 1) |
bg:SetPoint("LEFT", 5, 1) |
bg:SetSize(16, 16) |
frame.bg = bg |
local label = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight") |
label:SetPoint("LEFT", swatch, "RIGHT", 7, 0) |
label:SetHeight(19) |
label:SetText(name) |
frame.label = label |
frame:SetWidth(math.min(186, math.max(5 + 16 + 7 + label:GetStringWidth(), 100))) |
frame:SetMotionScriptsWhileDisabled(true) |
frame.desc = desc |
for name, func in pairs(prototype) do |
frame[name] = func |
end |
frame:SetScript("OnClick", frame.OnClick) |
frame:SetScript("OnEnter", frame.OnEnter) |
frame:SetScript("OnLeave", frame.OnLeave) |
frame.hasOpacity = hasOpacity |
frame.cancelFunc = function() |
frame:SetValue(frame.r, frame.g, frame.b, frame.hasOpacity and frame.opacity or 1) |
end |
frame.opacityFunc = function() |
local r, g, b = ColorPickerFrame:GetColorRGB() |
local a = OpacitySliderFrame:GetValue() |
frame:SetValue(r, g, b, a) |
end |
frame.swatchFunc = function() |
local r, g, b = ColorPickerFrame:GetColorRGB() |
local a = OpacitySliderFrame:GetValue() |
frame:SetValue(r, g, b, a) |
end |
return frame |
end |
--[[-------------------------------------------------------------------- |
PhanxConfig-ColorPicker |
Simple color picker widget generator. |
Based on OmniCC_Options by Tuller. |
Requires LibStub. |
This library is not intended for use by other authors. Absolutely no |
support of any kind will be provided for other authors using it, and |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local MINOR_VERSION = tonumber(("$Revision$"):match("%d+")) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-ColorPicker", MINOR_VERSION) |
if not lib then return end |
------------------------------------------------------------------------ |
local scripts = {} |
function scripts:OnClick() |
if ColorPickerFrame:IsShown() then |
ColorPickerFrame:Hide() |
else |
self.r, self.g, self.b, self.opacity = self:GetValue() |
OpenColorPicker(self) |
ColorPickerFrame:SetFrameStrata("TOOLTIP") |
ColorPickerFrame:Raise() |
end |
end |
function scripts:OnEnter() |
local color = NORMAL_FONT_COLOR |
self.bg:SetVertexColor(color.r, color.g, color.b) |
if self.tooltipText then |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, true) |
end |
end |
function scripts:OnLeave() |
local color = HIGHLIGHT_FONT_COLOR |
self.bg:SetVertexColor(color.r, color.g, color.b) |
GameTooltip:Hide() |
end |
------------------------------------------------------------------------ |
local methods = {} |
function methods:GetValue() |
local r, g, b, a = self.swatch:GetVertexColor() |
return floor(r * 100 + 0.5) / 100, floor(g * 100 + 0.5) / 100, floor(b * 100 + 0.5) / 100, floor(a * 100 + 0.5) / 100 |
end |
function methods:SetValue(r, g, b, a) |
if type(r) == "table" then |
r, g, b, a = r.r or r[1], r.g or r[2], r.b or r[3], r.a or r[4] |
end |
r = floor(r * 100 + 0.5) / 100 |
g = floor(g * 100 + 0.5) / 100 |
b = floor(b * 100 + 0.5) / 100 |
a = a and self.hasOpacity and (floor(a * 100 + 0.5) / 100) or 1 |
self.swatch:SetVertexColor(r, g, b, a) |
self.bg:SetAlpha(a) |
local func = self.func or self.ApplyValue or self.OnValueChanged |
if func then |
-- Ignore updates while ColorPickerFrame:IsShown() if desired. |
func(self, r, g, b, a) |
end |
end |
function methods:GetTooltipText() |
return self.tooltipText |
end |
function methods:SetTooltipText(text) |
self.tooltipText = text |
end |
function methods:SetFunction(func) |
self.func = func |
end |
------------------------------------------------------------------------ |
function lib:New(parent, name, tooltipText, hasOpacity) |
assert(type(parent) == "table" and parent.CreateFontString, "PhanxConfig-ColorPicker: Parent is not a valid frame!") |
if type(name) ~= "string" then name = nil end |
if type(tooltipText) ~= "string" then tooltipText = nil end |
local frame = CreateFrame("Button", nil, parent) |
frame:SetHeight(26) |
local swatch = frame:CreateTexture(nil, "OVERLAY") |
swatch:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch") |
swatch:SetPoint("LEFT", 5, 1) |
swatch:SetSize(17, 18) |
frame.swatch = swatch |
local bg = frame:CreateTexture(nil, "BACKGROUND") |
bg:SetTexture(1, 1, 1) |
bg:SetPoint("LEFT", 5, 1) |
bg:SetSize(16, 16) |
frame.bg = bg |
local label = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight") |
label:SetPoint("LEFT", swatch, "RIGHT", 7, 0) |
label:SetHeight(19) |
frame.label = label |
frame:SetMotionScriptsWhileDisabled(true) |
for name, func in pairs(scripts) do |
frame[name] = func |
frame:SetScript(name, func) |
end |
for name, func in pairs(methods) do |
frame[name] = func |
end |
frame.hasOpacity = hasOpacity |
frame.cancelFunc = function() |
frame:SetValue(frame.r, frame.g, frame.b, frame.hasOpacity and frame.opacity or 1) |
end |
frame.opacityFunc = function() |
local r, g, b = ColorPickerFrame:GetColorRGB() |
local a = OpacitySliderFrame:GetValue() |
frame:SetValue(r, g, b, a) |
end |
frame.swatchFunc = function() |
local r, g, b = ColorPickerFrame:GetColorRGB() |
local a = OpacitySliderFrame:GetValue() |
frame:SetValue(r, g, b, a) |
end |
label:SetText(name) |
frame.tooltipText = tooltipText |
frame:SetWidth(math.min(186, math.max(5 + 16 + 7 + label:GetStringWidth(), 100))) |
return frame |
end |
function lib.CreateColorPicker(...) return lib:New(...) end |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-Dropdown", MINOR_VERSION) |
if not lib then return end |
------------------------------------------------------------------------ |
local function Frame_OnEnter(self) |
if self.OnEnter then |
self:OnEnter() |
elseif self.desc then |
elseif self.tooltipText then |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
GameTooltip:SetText(self.desc, nil, nil, nil, nil, true) |
GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, true) |
end |
end |
CloseDropDownMenus() |
end |
local function Disable(self) |
self.labelText:SetFontObject(GameFontDisable) |
self.valueText:SetFontObject(GameFontDisableSmall) |
self.button:Disable() |
------------------------------------------------------------------------ |
local methods = {} |
function methods:GetValue() |
return UIDropDownMenu_GetSelectedValue(self.dropdown) or self.valueText:GetText() |
end |
function methods:SetValue(value, text) |
UIDropDownMenu_SetSelectedValue(self.dropdown, value or "UNKNOWN") |
self.valueText:SetText(text or value) |
end |
local function Enable(self) |
function methods:GetTooltipText() |
return self.tooltipText |
end |
function methods:SetTooltipText(text) |
self.tooltipText = text |
end |
function methods:Enable() |
self.labelText:SetFontObject(GameFontNormal) |
self.valueText:SetFontObject(GameFontHighlightSmall) |
self.button:Enable() |
end |
local function GetValue(self) |
return UIDropDownMenu_GetSelectedValue(self.dropdown) or self.valueText:GetText() |
function methods:Disable() |
self.labelText:SetFontObject(GameFontDisable) |
self.valueText:SetFontObject(GameFontDisableSmall) |
self.button:Disable() |
end |
local function SetValue(self, value, text) |
UIDropDownMenu_SetSelectedValue(self.dropdown, value or "UNKNOWN") |
self.valueText:SetText(text or value) |
end |
------------------------------------------------------------------------ |
local i = 0 |
function lib:New(parent, name, desc, init) |
function lib:New(parent, name, tooltipText, init) |
assert( type(parent) == "table" and parent.CreateFontString, "PhanxConfig-Dropdown: Parent is not a valid frame!" ) |
if type(name) ~= "string" then name = nil end |
if type(desc) ~= "string" then desc = nil end |
if type(tooltipText) ~= "string" then tooltipText = nil end |
i = i + 1 |
frame.bg:SetAllPoints(true) |
frame.bg:SetTexture(0, 0, 0, 0) |
frame.desc = desc |
local dropdown = CreateFrame("Frame", "PhanxConfigDropdown" .. i, frame) -- UIDropDownMenu system requires a global name |
dropdown:SetPoint("BOTTOMLEFT", -16, -4) |
dropdown:SetPoint("BOTTOMRIGHT", 15, -4) |
label:SetPoint("TOPLEFT", frame, 5, 0) |
label:SetPoint("TOPRIGHT", frame, -5, 0) |
label:SetJustifyH("LEFT") |
label:SetText(name) |
frame.labelText = label |
local value = dropdown:CreateFontString(dropdown:GetName() .. "Text", "OVERLAY", "GameFontHighlightSmall") -- UIDropDownMenu system requires a global name |
button:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight") |
button:GetHighlightTexture():SetBlendMode("ADD") |
frame.Enable = Enable |
frame.Disable = Disable |
frame.GetValue = GetValue |
frame.SetValue = SetValue |
for name, func in pairs(methods) do |
button[name] = func |
end |
label:SetText(name) |
frame.tooltipText = tooltipText |
if type(init) == "function" then |
UIDropDownMenu_Initialize(dropdown, init) |
end |
## Interface: 50400 |
## Version: 5.4.2.wowi:revision |
## Title: Lib: PhanxConfigWidgets |
## Notes: Simple GUI configuration widgets. |
## Author: Phanx |
## X-Email: addons@phanx.net |
## OptionalDependencies: LibStub |
LibStub\LibStub.lua |
PhanxConfig-Button\PhanxConfig-Button.lua |
PhanxConfig-Checkbox\PhanxConfig-Checkbox.lua |
PhanxConfig-ColorPicker\PhanxConfig-ColorPicker.lua |
PhanxConfig-Dropdown\PhanxConfig-Dropdown.lua |
PhanxConfig-EditBox\PhanxConfig-EditBox.lua |
PhanxConfig-Header\PhanxConfig-Header.lua |
PhanxConfig-OptionsPanel\PhanxConfig-OptionsPanel.lua |
PhanxConfig-Panel\PhanxConfig-Panel.lua |
PhanxConfig-ScrollingDropdown\PhanxConfig-ScrollingDropdown.lua |
## Interface: 50400 |
## Version: 5.4.2.wowi:revision |
## Title: Lib: PhanxConfigWidgets |
## Notes: Simple GUI configuration widgets. |
## Author: Phanx |
## X-Email: addons@phanx.net |
## OptionalDependencies: LibStub |
LibStub\LibStub.lua |
PhanxConfig-Button\PhanxConfig-Button.lua |
PhanxConfig-Checkbox\PhanxConfig-Checkbox.lua |
PhanxConfig-ColorPicker\PhanxConfig-ColorPicker.lua |
PhanxConfig-Dropdown\PhanxConfig-Dropdown.lua |
PhanxConfig-EditBox\PhanxConfig-EditBox.lua |
PhanxConfig-Header\PhanxConfig-Header.lua |
PhanxConfig-OptionsPanel\PhanxConfig-OptionsPanel.lua |
PhanxConfig-Panel\PhanxConfig-Panel.lua |
PhanxConfig-ScrollingDropdown\PhanxConfig-ScrollingDropdown.lua |
PhanxConfig-Slider\PhanxConfig-Slider.lua |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local MINOR_VERSION = tonumber( string.match( "$Revision$", "%d+" ) ) |
local MINOR_VERSION = tonumber(string.match("$Revision$", "%d+")) |
local lib, oldminor = LibStub:NewLibrary( "PhanxConfig-EditBox", MINOR_VERSION ) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-EditBox", MINOR_VERSION) |
if not lib then return end |
lib.editboxes = lib.editboxes or { } |
if not PhanxConfigEditBoxInsertLink then |
hooksecurefunc( "ChatEdit_InsertLink", function( ... ) return _G.PhanxConfigEditBoxInsertLink( ... ) end ) |
hooksecurefunc("ChatEdit_InsertLink", function(...) return _G.PhanxConfigEditBoxInsertLink(...) end) |
end |
function PhanxConfigEditBoxInsertLink( link ) |
function PhanxConfigEditBoxInsertLink(link) |
for i = 1, #lib.editboxes do |
local editbox = lib.editboxes[ i ] |
if editbox and editbox:IsVisible() and editbox:HasFocus() then |
editbox:Insert( link ) |
editbox:Insert(link) |
return true |
end |
end |
end |
local function OnEnter( self ) |
local text = self:GetParent().desc |
------------------------------------------------------------------------ |
local scripts = {} |
function scripts:OnEnter() |
local text = self:GetParent().tooltipText |
if text then |
GameTooltip:SetOwner( self, "ANCHOR_RIGHT" ) |
GameTooltip:SetText( text, nil, nil, nil, nil, true ) |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
GameTooltip:SetText(text, nil, nil, nil, nil, true) |
end |
end |
local function OnLeave() |
GameTooltip:Hide() |
end |
local function OnEditFocusGained( self ) -- print("OnEditFocusGained") |
function scripts:OnEditFocusGained() -- print("OnEditFocusGained") |
local text = self:GetText() |
self.currText, self.origText = text, text |
self:HighlightText() |
end |
local function OnEditFocusLost( self ) -- print("OnEditFocusLost") |
function scripts:OnEditFocusLost() -- print("OnEditFocusLost") |
self:SetText(self.origText or "") |
self.currText, self.origText = nil, nil |
end |
local function OnTextChanged( self ) |
function scripts:OnTextChanged() |
if not self:HasFocus() then return end |
local text = self:GetText() |
local parent = self:GetParent() |
if parent.OnTextChanged and text ~= self.currText then |
parent:OnTextChanged( text ) |
parent:OnTextChanged(text) |
self.currText = text |
end |
end |
local function OnEnterPressed( self ) -- print("OnEnterPressed") |
function scripts:OnEnterPressed() -- print("OnEnterPressed") |
local text = self:GetText() |
if text:len() == 0 then text = nil end -- experimental |
if strlen(text) == 0 then text = nil end -- experimental |
self:ClearFocus() |
local parent = self:GetParent() |
if parent.OnValueChanged then |
parent:OnValueChanged( text ) |
local func = parent.func or parent.OnValueChanged |
if func then |
func(parent, text) |
end |
end |
local function OnEscapePressed( self ) -- print("OnEscapePressed") |
function scripts:OnEscapePressed() -- print("OnEscapePressed") |
self:ClearFocus() |
end |
local function OnReceiveDrag( self ) |
function scripts:OnReceiveDrag() |
local type, id, info = GetCursorInfo() |
if type == "item" then |
self:SetText( info ) |
OnEnterPressed( self ) |
self:SetText(info) |
scripts.OnEnterPressed(self) |
ClearCursor() |
elseif type == "spell" then |
local name = GetSpellInfo( id, info ) |
self:SetText( name ) |
OnEnterPressed( self ) |
local name = GetSpellInfo(id, info) |
self:SetText(name) |
scripts.OnEnterPressed(self) |
ClearCursor() |
end |
end |
local function SetText( self, text ) |
return self.editbox:SetText( text ) |
------------------------------------------------------------------------ |
local methods = {} |
function methods:GetText() |
return self.editbox:GetText() |
end |
function methods:SetTooltipText(text) |
return self.editbox:SetText(text) |
end |
function lib:New( parent, name, desc, maxLetters ) |
assert( type(parent) == "table" and parent.CreateFontString, "PhanxConfig-EditBox: Parent is not a valid frame!" ) |
function methods:GetTooltipText() |
return self.tooltipText |
end |
function methods:SetTooltipText(text) |
self.tooltipText = text |
end |
function methods:SetFunction(func) |
self.func = func |
end |
------------------------------------------------------------------------ |
function lib:New(parent, name, tooltipText, maxLetters) |
assert(type(parent) == "table" and parent.CreateFontString, "PhanxConfig-EditBox: Parent is not a valid frame!") |
if type(name) ~= "string" then name = nil end |
if type(desc) ~= "string" then desc = nil end |
if type(tooltipText) ~= "string" then tooltipText = nil end |
if type(maxLetters) ~= "number" then maxLetters = nil end |
local frame = CreateFrame( "Frame", nil, parent ) |
frame:SetWidth( 144 ) |
frame:SetHeight( 42 ) |
local frame = CreateFrame("Frame", nil, parent) |
frame:SetWidth(144) |
frame:SetHeight(42) |
-- local bg = frame:CreateTexture(nil, "BACKGROUND") |
-- bg:SetAllPoints(frame) |
-- bg:SetTexture(0, 0, 0) |
-- frame.bg = bg |
local editbox = CreateFrame( "EditBox", nil, frame ) |
editbox:SetPoint( "LEFT", 5, 0 ) |
editbox:SetPoint( "RIGHT", -5, 0 ) |
editbox:SetHeight( 19 ) |
editbox:EnableMouse( true ) |
editbox:SetAutoFocus( false ) |
editbox:SetFontObject( ChatFontNormal ) |
editbox:SetMaxLetters( maxLetters or 256 ) |
editbox:SetTextInsets( 0, 0, 3, 3 ) |
editbox:SetScript( "OnEnter", OnEnter ) |
editbox:SetScript( "OnLeave", OnLeave ) |
editbox:SetScript( "OnEditFocusGained", OnEditFocusGained ) |
editbox:SetScript( "OnTextChanged", OnTextChanged ) |
editbox:SetScript( "OnEnterPressed", OnEnterPressed ) |
editbox:SetScript( "OnTabPressed", OnEnterPressed ) |
editbox:SetScript( "OnEscapePressed", OnEscapePressed ) |
editbox:SetScript( "OnEditFocusLost", OnEditFocusLost ) |
editbox:SetScript( "OnReceiveDrag", OnReceiveDrag ) |
local editbox = CreateFrame("EditBox", nil, frame) |
editbox:SetPoint("LEFT", 5, 0) |
editbox:SetPoint("RIGHT", -5, 0) |
editbox:SetHeight(19) |
editbox:EnableMouse(true) |
editbox:SetAutoFocus(false) |
editbox:SetFontObject(ChatFontNormal) |
editbox:SetMaxLetters(maxLetters or 256) |
editbox:SetTextInsets(0, 0, 3, 3) |
lib.editboxes[ #lib.editboxes + 1 ] = editbox |
frame.editbox = editbox |
editbox.bgLeft = editbox:CreateTexture( nil, "BACKGROUND" ) |
editbox.bgLeft:SetPoint( "LEFT", 0, 0 ) |
editbox.bgLeft:SetSize( 8, 20 ) |
editbox.bgLeft:SetTexture( [[Interface\Common\Common-Input-Border]] ) |
editbox.bgLeft:SetTexCoord( 0, 0.0625, 0, 0.625 ) |
editbox.bgLeft = editbox:CreateTexture(nil, "BACKGROUND") |
editbox.bgLeft:SetPoint("LEFT", 0, 0) |
editbox.bgLeft:SetSize(8, 20) |
editbox.bgLeft:SetTexture([[Interface\Common\Common-Input-Border]]) |
editbox.bgLeft:SetTexCoord(0, 0.0625, 0, 0.625) |
editbox.bgRight = editbox:CreateTexture( nil, "BACKGROUND" ) |
editbox.bgRight:SetPoint( "RIGHT", 0, 0 ) |
editbox.bgRight:SetSize( 8, 20 ) |
editbox.bgRight:SetTexture( [[Interface\Common\Common-Input-Border]] ) |
editbox.bgRight:SetTexCoord( 0.9375, 1, 0, 0.625 ) |
editbox.bgRight = editbox:CreateTexture(nil, "BACKGROUND") |
editbox.bgRight:SetPoint("RIGHT", 0, 0) |
editbox.bgRight:SetSize(8, 20) |
editbox.bgRight:SetTexture([[Interface\Common\Common-Input-Border]]) |
editbox.bgRight:SetTexCoord(0.9375, 1, 0, 0.625) |
editbox.bgMiddle = editbox:CreateTexture( nil, "BACKGROUND" ) |
editbox.bgMiddle:SetPoint( "LEFT", editbox.bgLeft, "RIGHT" ) |
editbox.bgMiddle:SetPoint( "RIGHT", editbox.bgRight, "LEFT" ) |
editbox.bgMiddle:SetSize( 10, 20 ) |
editbox.bgMiddle:SetTexture( [[Interface\Common\Common-Input-Border]] ) |
editbox.bgMiddle:SetTexCoord( 0.0625, 0.9375, 0, 0.625 ) |
editbox.bgMiddle = editbox:CreateTexture(nil, "BACKGROUND") |
editbox.bgMiddle:SetPoint("LEFT", editbox.bgLeft, "RIGHT") |
editbox.bgMiddle:SetPoint("RIGHT", editbox.bgRight, "LEFT") |
editbox.bgMiddle:SetSize(10, 20) |
editbox.bgMiddle:SetTexture([[Interface\Common\Common-Input-Border]]) |
editbox.bgMiddle:SetTexCoord(0.0625, 0.9375, 0, 0.625) |
local label = editbox:CreateFontString( nil, "ARTWORK", "GameFontNormal" ) |
label:SetPoint( "BOTTOMLEFT", editbox, "TOPLEFT" ) |
label:SetPoint( "BOTTOMRIGHT", editbox, "TOPRIGHT" ) |
label:SetJustifyH( "LEFT" ) |
label:SetText( name ) |
local label = editbox:CreateFontString(nil, "ARTWORK", "GameFontNormal") |
label:SetPoint("BOTTOMLEFT", editbox, "TOPLEFT") |
label:SetPoint("BOTTOMRIGHT", editbox, "TOPRIGHT") |
label:SetJustifyH("LEFT") |
frame.label = label |
frame.desc = desc |
frame.SetText = SetText |
for name, func in pairs(scripts) do |
editbox:SetScript(name, func) -- NOT on the frame! |
end |
for name, func in pairs(methods) do |
frame[name] = func |
end |
frame.label:SetText(name) |
frame.tooltipText = tooltipText |
return frame |
end |
function lib.CreateEditBox( ... ) return lib:New( ... ) end |
--[[-------------------------------------------------------------------- |
PhanxConfig-Panel |
Simple background panel widget generator. Requires LibStub. |
This library is not intended for use by other authors. Absolutely no |
support of any kind will be provided for other authors using it, and |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local MINOR_VERSION = tonumber(("$Revision$"):match("%d+")) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-Panel", MINOR_VERSION) |
if not lib then return end |
local panelBackdrop = { |
bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, tileSize = 16, |
edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 16, |
insets = { left = 5, right = 5, top = 5, bottom = 5 } |
} |
function lib.CreatePanel(parent, width, height) |
assert( type(parent) == "table" and parent.CreateFontString, "PhanxConfig-Panel: Parent is not a valid frame!" ) |
local frame = CreateFrame("Frame", nil, parent) |
frame:SetFrameStrata(parent:GetFrameStrata()) |
frame:SetFrameLevel(parent:GetFrameLevel() + 1) |
frame:SetBackdrop(panelBackdrop) |
frame:SetBackdropColor(0.06, 0.06, 0.06, 0.4) |
frame:SetBackdropBorderColor(0.6, 0.6, 0.6, 1) |
frame:SetWidth(width or 1) |
frame:SetHeight(height or 1) |
return frame |
end |
--[[-------------------------------------------------------------------- |
PhanxConfig-Slider |
Simple slider widget generator. |
Based on tekKonfig-Slider and AceGUI-3.0-Slider. |
Requires LibStub. |
This library is not intended for use by other authors. Absolutely no |
support of any kind will be provided for other authors using it, and |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local MINOR_VERSION = tonumber(strmatch("$Revision$", "%d+")) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-Slider", MINOR_VERSION) |
if not lib then return end |
local scripts = { |
OnEnter = function(self) |
local text = self:GetParent().desc |
if text then |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
GameTooltip:SetText(text, nil, nil, nil, nil, true) |
end |
end, |
OnLeave = function(self) |
GameTooltip:Hide() |
end, |
OnMouseWheel = function(self, delta) |
local step = self:GetValueStep() * delta |
local minValue, maxValue = self:GetMinMaxValues() |
if step > 0 then |
self:SetValue(min(self:GetValue() + step, maxValue)) |
else |
self:SetValue(max(self:GetValue() + step, minValue)) |
end |
end, |
OnValueChanged = function(self) |
local parent = self:GetParent() |
local value = self:GetValue() |
local valueStep = self.valueStep |
if valueStep and valueStep > 0 then |
local minValue = self.minValue or 0 |
value = floor((value - minValue) / valueStep + 0.5) * valueStep + minValue |
end |
if self.valueFactor then |
value = value / self.valueFactor |
end |
local handler = parent.ApplyValue or parent.OnValueChanged |
if handler then |
value = handler(parent, value) or value |
end |
if parent.isPercent then |
parent.valueText:SetFormattedText("%.0f%%", value * 100) |
else |
parent:SetText(value) |
end |
end |
} |
local methods = { |
GetText = function(self) |
return self.valueText:GetText() |
end, |
SetText = function(self, text) |
return self.valueText:SetText(text) |
end, |
GetLabel = function(self) |
return self.labelText:GetText() |
end, |
SetLabel = function(self, text) |
return self.labelText:SetText(text) |
end, |
GetValue = function(self) |
return self.slider:GetValue() |
end, |
SetValue = function(self, value) |
if self.isPercent then |
self.valueText:SetFormattedText("%.0f%%", value * 100) |
else |
self:SetText(value) |
end |
if self.slider.valueFactor then |
value = value * self.slider.valueFactor |
end |
return self.slider:SetValue(value) |
end, |
} |
local function EditBox_OnEnterPressed(self) -- print("OnEnterPressed SLIDER") |
local parent = self:GetParent():GetParent() |
local text = self:GetText() |
self:ClearFocus() |
local value |
if parent.isPercent then |
value = tonumber(strmatch(text, "%d+")) / 100 |
else |
value = tonumber(text) |
end |
if value then |
parent:SetValue(value) |
end |
end |
local function EditBoxContainer_SetFormattedText(self, text, ...) |
return self.editbox:SetText(text:format(...)) |
end |
local sliderBG = { |
bgFile = "Interface\\Buttons\\UI-SliderBar-Background", |
edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", |
edgeSize = 8, tile = true, tileSize = 8, |
insets = { left = 3, right = 3, top = 6, bottom = 6 } |
} |
function lib:New(parent, name, desc, lowvalue, highvalue, valuestep, percent, noEditBox) |
assert(type(parent) == "table" and parent.CreateFontString, "PhanxConfig-Slider: Parent is not a valid frame!") |
if type(name) ~= "string" then name = nil end |
if type(desc) ~= "string" then desc = nil end |
if type(lowvalue) ~= "number" then lowvalue = 0 end |
if type(highvalue) ~= "number" then highvalue = 100 end |
if type(valuestep) ~= "number" then valuestep = 1 end |
local frame = CreateFrame("Frame", nil, parent) |
frame:SetWidth(186) |
frame:SetHeight(42) |
frame.desc = desc |
frame.bg = frame:CreateTexture(nil, "BACKGROUND") |
frame.bg:SetAllPoints(true) |
frame.bg:SetTexture(0, 0, 0, 0) |
local slider = CreateFrame("Slider", nil, frame) |
slider:SetPoint("BOTTOMLEFT", 3, 10) |
slider:SetPoint("BOTTOMRIGHT", -3, 10) |
slider:SetHeight(17) |
slider:SetHitRectInsets(0, 0, -10, -10) |
slider:SetOrientation("HORIZONTAL") |
slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal") |
slider:SetBackdrop(sliderBG) |
local label = slider:CreateFontString(nil, "ARTWORK", "GameFontNormal") |
label:SetPoint("TOPLEFT", frame, 5, 0) |
label:SetPoint("TOPRIGHT", frame, -5, 0) |
label:SetJustifyH("LEFT") |
label:SetText(name) |
local low = slider:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall") |
low:SetPoint("TOPLEFT", slider, "BOTTOMLEFT", 0, 3) |
if percent then |
low:SetFormattedText("%.0f%%", lowvalue * 100) |
else |
low:SetText(lowvalue) |
end |
local high = slider:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall") |
high:SetPoint("TOPRIGHT", slider, "BOTTOMRIGHT", 0, 3) |
if percent then |
high:SetFormattedText("%.0f%%", highvalue * 100) |
else |
high:SetText(highvalue) |
end |
local value |
if not noEditBox and LibStub("PhanxConfig-EditBox", true) then |
value = LibStub("PhanxConfig-EditBox"):New(frame, nil, desc, 5) |
value:SetPoint("TOP", slider, "BOTTOM", 0, 13) |
value:SetWidth(100) |
value.editbox:SetScript("OnEnter", scripts.OnEnter) |
value.editbox:SetScript("OnLeave", scripts.OnLeave) |
value.editbox:SetScript("OnEnterPressed", EditBox_OnEnterPressed) |
value.editbox:SetScript("OnTabPressed", EditBox_OnEnterPressed) |
value.editbox:SetFontObject(GameFontHighlightSmall) |
value.editbox:SetJustifyH("CENTER") |
value.SetFormattedText = EditBoxContainer_SetFormattedText |
else |
value = slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") |
value:SetPoint("TOP", slider, "BOTTOM", 0, 3) |
end |
local factor = 10 ^ max(strlen(tostring(valuestep):match("%.(%d+)") or ""), |
strlen(tostring(minvalue):match("%.(%d+)") or ""), |
strlen(tostring(maxvalue):match("%.(%d+)") or "")) |
if factor > 1 then |
slider.valueFactor = factor |
slider:SetMinMaxValues(lowvalue * factor, highvalue * factor) |
slider.minValue, slider.maxValue = lowvalue * factor, highvalue * factor |
slider:SetValueStep(valuestep * factor) |
slider.valueStep = valuestep * factor |
else |
slider:SetMinMaxValues(lowvalue, highvalue) |
slider.minValue, slider.maxValue = lowvalue, highvalue |
slider:SetValueStep(valuestep) |
slider.valueStep = valuestep |
end |
slider:EnableMouseWheel(true) |
slider:SetScript("OnEnter", scripts.OnEnter) |
slider:SetScript("OnLeave", scripts.OnLeave) |
slider:SetScript("OnMouseWheel", scripts.OnMouseWheel) |
slider:SetScript("OnValueChanged", scripts.OnValueChanged) |
frame.slider = slider |
frame.labelText = label |
frame.lowText = low |
frame.highText = high |
frame.valueText = value |
frame.isPercent = percent |
frame.GetText = methods.GetText |
frame.SetText = methods.SetText |
frame.GetValue = methods.GetValue |
frame.SetValue = methods.SetValue |
return frame |
end |
--[[-------------------------------------------------------------------- |
PhanxConfig-Slider |
Simple slider widget generator. |
Based on tekKonfig-Slider and AceGUI-3.0-Slider. |
Requires LibStub. |
This library is not intended for use by other authors. Absolutely no |
support of any kind will be provided for other authors using it, and |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local MINOR_VERSION = tonumber(strmatch("$Revision$", "%d+")) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-Slider", MINOR_VERSION) |
if not lib then return end |
------------------------------------------------------------------------ |
local scripts = {} |
function scripts:OnEnter() |
local text = self:GetParent().tooltipText |
if text then |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
GameTooltip:SetText(text, nil, nil, nil, nil, true) |
end |
end |
function scripts:OnLeave() |
GameTooltip:Hide() |
end |
function scripts:OnMouseWheel(delta) |
local step = self:GetValueStep() * delta |
local minValue, maxValue = self:GetMinMaxValues() |
if step > 0 then |
self:SetValue(min(self:GetValue() + step, maxValue)) |
else |
self:SetValue(max(self:GetValue() + step, minValue)) |
end |
end |
function scripts:OnValueChanged() |
local parent = self:GetParent() |
local value = self:GetValue() |
local minValue, maxValue = self:GetMinMaxValues() |
local valueStep = self.valueStep |
if valueStep and valueStep > 0 then |
value = floor((value - minValue) / valueStep + 0.5) * valueStep + minValue |
end |
if self.valueFactor then |
value = value / self.valueFactor |
end |
local func = parent.func or parent.ApplyValue or parent.OnValueChanged |
if func then |
value = func(parent, value) or value |
end |
if parent.isPercent then |
parent.valueText:SetFormattedText("%.0f%%", value * 100) |
else |
parent:SetText(value) |
end |
end |
------------------------------------------------------------------------ |
local methods = {} |
function methods:GetValue() |
return self.slider:GetValue() |
end, |
function methods:SetValue(value) |
if self.isPercent then |
self.valueText:SetFormattedText("%.0f%%", value * 100) |
else |
self:SetText(value) |
end |
if self.slider.valueFactor then |
value = value * self.slider.valueFactor |
end |
return self.slider:SetValue(value) |
end |
function methods:GetLabel() |
return self.labelText:GetText() |
end |
function methods:SetLabel(text) |
return self.labelText:SetText(text) |
end |
function methods:GetText() |
return self.valueText:GetText() |
end |
function methods:SetText(text) |
return self.valueText:SetText(text) |
end |
function methods:GetTooltipText() |
return self.tooltipText |
end |
function methods:SetTooltipText(text) |
self.tooltipText = text |
end |
function methods:SetFunction(func) |
self.func = func |
end |
------------------------------------------------------------------------ |
local function EditBox_OnEnterPressed(self) -- print("OnEnterPressed SLIDER") |
local parent = self:GetParent():GetParent() |
local text = self:GetText() |
self:ClearFocus() |
local value |
if parent.isPercent then |
value = tonumber(strmatch(text, "%d+")) / 100 |
else |
value = tonumber(text) |
end |
if value then |
parent:SetValue(value) |
end |
end |
local function EditBoxContainer_SetFormattedText(self, text, ...) |
return self.editbox:SetFormattedText(text, ...) |
end |
local sliderBG = { |
bgFile = "Interface\\Buttons\\UI-SliderBar-Background", |
edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", |
edgeSize = 8, tile = true, tileSize = 8, |
insets = { left = 3, right = 3, top = 6, bottom = 6 } |
} |
function lib:New(parent, name, tooltipText, lowvalue, highvalue, valuestep, percent, noEditBox) |
assert(type(parent) == "table" and parent.CreateFontString, "PhanxConfig-Slider: Parent is not a valid frame!") |
if type(name) ~= "string" then name = nil end |
if type(tooltipText) ~= "string" then tooltipText = nil end |
if type(lowvalue) ~= "number" then lowvalue = 0 end |
if type(highvalue) ~= "number" then highvalue = 100 end |
if type(valuestep) ~= "number" then valuestep = 1 end |
local frame = CreateFrame("Frame", nil, parent) |
frame:SetWidth(186) |
frame:SetHeight(42) |
frame.bg = frame:CreateTexture(nil, "BACKGROUND") |
frame.bg:SetAllPoints(true) |
frame.bg:SetTexture(0, 0, 0, 0) |
local slider = CreateFrame("Slider", nil, frame) |
slider:SetPoint("BOTTOMLEFT", 3, 10) |
slider:SetPoint("BOTTOMRIGHT", -3, 10) |
slider:SetHeight(17) |
slider:SetHitRectInsets(0, 0, -10, -10) |
slider:SetOrientation("HORIZONTAL") |
slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal") |
slider:SetBackdrop(sliderBG) |
local label = slider:CreateFontString(nil, "ARTWORK", "GameFontNormal") |
label:SetPoint("TOPLEFT", frame, 5, 0) |
label:SetPoint("TOPRIGHT", frame, -5, 0) |
label:SetJustifyH("LEFT") |
local low = slider:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall") |
low:SetPoint("TOPLEFT", slider, "BOTTOMLEFT", 0, 3) |
if percent then |
low:SetFormattedText("%.0f%%", lowvalue * 100) |
else |
low:SetText(lowvalue) |
end |
local high = slider:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall") |
high:SetPoint("TOPRIGHT", slider, "BOTTOMRIGHT", 0, 3) |
if percent then |
high:SetFormattedText("%.0f%%", highvalue * 100) |
else |
high:SetText(highvalue) |
end |
local value |
if not noEditBox and LibStub("PhanxConfig-EditBox", true) then |
value = LibStub("PhanxConfig-EditBox"):New(frame, nil, tooltipText, 5) |
value:SetPoint("TOP", slider, "BOTTOM", 0, 13) |
value:SetWidth(100) |
value.editbox:SetScript("OnEnter", scripts.OnEnter) |
value.editbox:SetScript("OnLeave", scripts.OnLeave) |
value.editbox:SetScript("OnEnterPressed", EditBox_OnEnterPressed) |
value.editbox:SetScript("OnTabPressed", EditBox_OnEnterPressed) |
value.editbox:SetFontObject(GameFontHighlightSmall) |
value.editbox:SetJustifyH("CENTER") |
value.SetFormattedText = EditBoxContainer_SetFormattedText |
else |
value = slider:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") |
value:SetPoint("TOP", slider, "BOTTOM", 0, 3) |
end |
local factor = 10 ^ max(strlen(tostring(valuestep):match("%.(%d+)") or ""), |
strlen(tostring(minvalue):match("%.(%d+)") or ""), |
strlen(tostring(maxvalue):match("%.(%d+)") or "")) |
if factor > 1 then |
slider.valueFactor = factor |
slider:SetMinMaxValues(lowvalue * factor, highvalue * factor) |
slider.minValue, slider.maxValue = lowvalue * factor, highvalue * factor |
slider:SetValueStep(valuestep * factor) |
slider.valueStep = valuestep * factor |
else |
slider:SetMinMaxValues(lowvalue, highvalue) |
slider.minValue, slider.maxValue = lowvalue, highvalue |
slider:SetValueStep(valuestep) |
slider.valueStep = valuestep |
end |
slider:EnableMouseWheel(true) |
slider:SetScript("OnEnter", scripts.OnEnter) |
slider:SetScript("OnLeave", scripts.OnLeave) |
slider:SetScript("OnMouseWheel", scripts.OnMouseWheel) |
slider:SetScript("OnValueChanged", scripts.OnValueChanged) |
frame.slider = slider |
frame.labelText = label |
frame.lowText = low |
frame.highText = high |
frame.valueText = value |
frame.isPercent = percent |
for name, func in pairs(methods) do |
frame[name] = func |
end |
label:SetText(name) |
frame.tooltipText = tooltipText |
return frame |
end |
function lib.CreateSlider(...) return lib:New(...) end |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local PhanxConfigButton = LibStub:GetLibrary( "PhanxConfig-Button", true ) |
assert( PhanxConfigButton, "PhanxConfig-KeyBinding requires PhanxConfig-Button" ) |
local PhanxConfigButton = LibStub:GetLibrary("PhanxConfig-Button", true) |
assert(PhanxConfigButton, "PhanxConfig-KeyBinding requires PhanxConfig-Button") |
local MINOR_VERSION = tonumber( string.match( "$Revision: 29 $", "%d+" ) ) |
local MINOR_VERSION = tonumber(string.match("$Revision$", "%d+")) |
local lib, oldminor = LibStub:NewLibrary( "PhanxConfig-KeyBinding", MINOR_VERSION ) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-KeyBinding", MINOR_VERSION) |
if not lib then return end |
------------------------------------------------------------------------ |
local HINT_TEXT_ACTIVE = "Press a key to bind, press Escape to clear the binding, or click the button again to cancel." |
local HINT_TEXT_INACTIVE = "Click the button to bind a key." |
do |
local GAME_LOCALE = GetLocale() |
if GAME_LOCALE == "esES" or GAME_LOCALE == "esMX" then |
if GAME_LOCALE == "deDE" then |
HINT_TEXT_ACTIVE = "Drücke eine Taste, um sie zu belegen. Drücke ESC, um die Belegung zu löschen, oder klick erneut, um zu abbrechen." |
HINT_TEXT_INACTIVE = "Klick, um eine Taste zu belegen." |
elseif GAME_LOCALE == "esES" or GAME_LOCALE == "esMX" then |
HINT_TEXT_ACTIVE = "Pulse una tecla para asignarlo, pulse Escape para borrar la asignación, o clic en el botón otra vez para cancelar." |
HINT_TEXT_INACTIVE = "Clic en el botón para asignar una tecla." |
elseif GAME_LOCALE == "frFR" then |
HINT_TEXT_ACTIVE = "Appuyez sur une touche pour assigner un raccourci, appuyez sur Echap pour effacer le raccourci, ou cliquez sur le bouton à nouveau pour annuler." |
HINT_TEXT_INACTIVE = "Cliquez sur le bouton pour assigner une touche." |
end |
end |
local function Button_SetValue( self, value ) |
if value and value ~= "" then |
self:SetText( value ) |
else |
self:SetText( NOT_BOUND ) |
end |
------------------------------------------------------------------------ |
local action = self.action |
if action then |
-- clear any previous bindings |
local prev1, prev2 = GetBindingKey( action ) |
if prev1 == value then return end |
if prev1 then SetBinding( prev1 ) end |
if prev2 then SetBinding( prev2 ) end |
local scripts = {} -- these are set on the button, not the container |
if value and value:len() > 0 then |
-- warn if overwriting an existing binding |
local curr = GetBindingAction( value ) |
if curr and curr:len() > 0 then |
print( KEY_UNBOUND_ERROR:format( curr ) ) |
end |
function scripts:OnEnter() |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
-- set new binding |
SetBinding( value, action ) |
-- restore second binding if there was one |
if prev2 then SetBinding( prev2, action ) end |
end |
-- save |
SaveBindings( GetCurrentBindingSet() ) |
end |
if self.OnKeyChanged then |
self:OnKeyChanged( value ) |
end |
end |
local function Button_RefreshValue( self ) |
if not self.action then return end |
local key = GetBindingKey( self.action ) |
if key then |
self:SetText( key ) |
else |
self:SetText( NOT_BOUND ) |
end |
end |
local function Button_OnEnter( self ) |
GameTooltip:SetOwner( self, "ANCHOR_RIGHT" ) |
local text = self.desc |
local text = self.tooltipText |
if text then |
GameTooltip:SetText( text, nil, nil, nil, nil, true ) |
GameTooltip:SetText(text, nil, nil, nil, nil, true) |
elseif self.waitingForKey then |
GameTooltip:SetText( HINT_TEXT_ACTIVE, nil, nil, nil, nil, true ) |
GameTooltip:SetText(HINT_TEXT_ACTIVE, nil, nil, nil, nil, true) |
else |
GameTooltip:SetText( HINT_TEXT_INACTIVE, nil, nil, nil, nil, true ) |
GameTooltip:SetText(HINT_TEXT_INACTIVE, nil, nil, nil, nil, true) |
end |
GameTooltip:Show() |
end |
local function Button_OnClick( self, button ) |
function scripts:OnClick(button) |
if button ~= "LeftButton" and button ~= "RightButton" then return end |
if self.waitingForKey then |
self:EnableKeyboard( false ) |
self:EnableKeyboard(false) |
self:UnlockHighlight() |
self.waitingForKey = nil |
else |
self:EnableKeyboard( true ) |
self:EnableKeyboard(true) |
self:LockHighlight() |
self.waitingForKey = true |
end |
["UNKNOWN"] = true, |
} |
local function Button_OnKeyDown( self, key ) |
if not self.waitingForKey then return end |
if ignoreKeys[ key ] then return end |
function scripts:OnKeyDown(key) |
if ignoreKeys[key] or not self.waitingForKey then return end |
if key == "ESCAPE" then |
key = "" |
elseif key == "MiddleButton" then |
key = "BUTTON3" |
elseif key:match( "^Button" ) then |
elseif key:match("^Button") then |
key = button:upper() |
end |
key = "ALT-" .. key |
end |
self:EnableKeyboard( false ) |
self:EnableKeyboard(false) |
self:UnlockHighlight() |
self.waitingForKey = nil |
if self:IsEnabled() then |
Button_SetValue( self, key ) |
self:SetValue(key) |
end |
------------------------------------------------------------------------ |
local methods = {} -- these are set on the button, not the container |
function methods:GetValue() |
return self.action and GetBindingKey(self.action) or nil |
end |
function methods:SetValue(value) |
if value and value ~= "" then |
self:SetText(value) |
else |
self:SetText(NOT_BOUND) |
end |
local action = self.action |
if action then |
-- clear any previous bindings |
local prev1, prev2 = GetBindingKey(action) |
if prev1 == value then return end |
if prev1 then SetBinding(prev1) end |
if prev2 then SetBinding(prev2) end |
if value and strlen(value) > 0 then |
-- warn if overwriting an existing binding |
local curr = GetBindingAction(value) |
if curr and strlen(curr) > 0 then |
print(format(KEY_UNBOUND_ERROR, curr)) |
end |
-- set new binding |
SetBinding(value, action) |
-- restore second binding if there was one |
if prev2 then SetBinding(prev2, action) end |
end |
-- save |
SaveBindings(GetCurrentBindingSet()) |
end |
local func = self.func or self.OnKeyChanged |
if func then |
func(self, value) |
end |
end |
local function Button_SetPoint( self, ... ) |
return self.container:SetPoint( ... ) |
function methods:GetTooltipText() |
return self.tooltipText |
end |
function methods:SetTooltipText(text) |
self.tooltipText = text |
end |
function lib.CreateKeyBinding( parent, name, desc, action ) |
assert( type( parent ) == "table" and parent.CreateFontString, "PhanxConfig-KeyBinding: Parent is not a valid frame!" ) |
if type( name ) ~= "string" then name = nil end |
if type( desc ) ~= "string" then desc = nil end |
function methods:SetFunction(func) |
self.func = func |
end |
local frame = CreateFrame( "Frame", nil, parent ) |
frame:SetWidth( 186 ) |
frame:SetHeight( 38 ) |
function methods:SetPoint(...) |
return self.container:SetPoint(...) |
end |
frame.bg = frame:CreateTexture( nil, "BACKGROUND" ) |
frame.bg:SetAllPoints( true ) |
frame.bg:SetTexture( 0, 0, 0, 0 ) |
function methods:RefreshValue() |
self:SetText(self:GetValue() or NOT_BOUND) |
end |
local button = PhanxConfigButton.CreateButton( frame, nil, desc ) |
button:SetPoint( "BOTTOMLEFT" ) |
button:SetPoint( "BOTTOMRIGHT" ) |
function methods:SetBindingAction(action) |
self.action = action |
end |
button:SetNormalFontObject( GameFontHighlightSmall ) |
------------------------------------------------------------------------ |
button:SetScript( "OnEnter", Button_OnEnter ) |
button:SetScript( "OnClick", Button_OnClick ) |
button:SetScript( "OnKeyDown", Button_OnKeyDown ) |
button:SetScript( "OnMouseDown", Button_OnKeyDown ) |
function lib:New(parent, name, tooltipText, action) |
assert(type(parent) == "table" and parent.CreateFontString, "PhanxConfig-KeyBinding: Parent is not a valid frame!") |
if type(name) ~= "string" then name = nil end |
if type(tooltipText) ~= "string" then tooltipText = nil end |
button:EnableKeyboard( false ) |
button:EnableMouse( true ) |
button:RegisterForClicks( "AnyDown" ) |
local frame = CreateFrame("Frame", nil, parent) |
frame:SetWidth(186) |
frame:SetHeight(38) |
button.label = button:CreateFontString( nil, "OVERLAY", "GameFontNormal" ) |
button.label:SetPoint( "TOPLEFT", frame, 5, 0 ) |
button.label:SetPoint( "TOPRIGHT", frame, -5, 0 ) |
button.label:SetJustifyH( "LEFT" ) |
button.label:SetText( name ) |
frame.bg = frame:CreateTexture(nil, "BACKGROUND") |
frame.bg:SetAllPoints(true) |
frame.bg:SetTexture(0, 0, 0, 0) |
button.action = action |
local button = PhanxConfigButton.CreateButton(frame, nil, tooltipText) |
button:SetPoint("BOTTOMLEFT") |
button:SetPoint("BOTTOMRIGHT") |
local label = button:CreateFontString(nil, "OVERLAY", "GameFontNormal") |
label:SetPoint("TOPLEFT", frame, 5, 0) |
label:SetPoint("TOPRIGHT", frame, -5, 0) |
label:SetJustifyH("LEFT") |
button.label = label |
button:SetNormalFontObject(GameFontHighlightSmall) |
button:EnableKeyboard(false) |
button:EnableMouse(true) |
button:RegisterForClicks("AnyDown") |
button.container = frame |
button.SetPoint = Button_SetPoint |
button.SetValue = Button_SetValue |
button.RefreshValue = Button_RefreshValue |
for name, func in pairs(scripts) do |
button:SetScript(name, func) |
end |
for name, func in pairs(methods) do |
button[name] = func |
end |
label:SetText(name) |
button.action = action |
button:RefreshValue() |
return button |
end |
--[[-------------------------------------------------------------------- |
PhanxConfig-Checkbox |
Simple checkbox widget generator. |
Based on tekKonfig-Checkbox by Tekkub. |
Requires LibStub. |
This library is not intended for use by other authors. Absolutely no |
support of any kind will be provided for other authors using it, and |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local MINOR_VERSION = tonumber(strmatch("$Revision$", "%d+")) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-Checkbox", MINOR_VERSION) |
if not lib then return end |
local scripts = {} |
function scripts:OnClick() |
local checked = self:GetChecked() == 1 |
PlaySound(checked and "igMainMenuOptionCheckBoxOn" or "igMainMenuOptionCheckBoxOff") |
self:GetScript("OnLeave")(self) |
local handler = self.ApplyValue or self.OnValueChanged or self.OnClick -- OnClick is deprecated |
if handler then |
handler(self, checked) |
end |
end |
function scripts:OnDisable() |
if self.disabled then return end |
local r, g, b = self.label:GetTextColor() |
self.label:SetTextColor(r / 2, g / 2, b / 2) |
self.disabled = true |
end |
function scripts:OnEnable() |
if not self.disabled then return end |
local r, g, b = self.label:GetTextColor() |
self.label:SetTextColor(r * 2, g * 2, b * 2) |
self.disabled = nil |
end |
function scripts:OnEnter() |
if self.desc then |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
GameTooltip:SetText(self.desc, nil, nil, nil, nil, true) |
end |
end |
function scripts:OnLeave() |
GameTooltip:Hide() |
end |
local methods = {} |
function methods:GetValue() |
return self:GetChecked() == 1 |
end |
function methods:SetValue(value, auto) |
self:SetChecked(value) |
end |
function lib:New(parent, text, desc) |
assert(type(parent) == "table" and type(rawget(parent, 0) == "userdata"), "PhanxConfig-Checkbox: parent must be a frame") |
if type(name) ~= "string" then name = nil end |
if type(desc) ~= "string" then desc = nil end |
local check = CreateFrame("CheckButton", nil, parent) |
check:SetSize(26, 26) |
check:SetMotionScriptsWhileDisabled(true) |
check:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up") |
check:SetPushedTexture("Interface\\Buttons\\UI-CheckBox-Down") |
check:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight") |
check:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check") |
check:SetDisabledCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check-Disabled") |
local label = check:CreateFontString(nil, "ARTWORK", "GameFontHighlight") |
label:SetPoint("LEFT", check, "RIGHT", 2, 1) |
label:SetText(text) |
check.label = label |
check:SetHitRectInsets(0, -1 * min(186, max(label:GetStringWidth(), 100)), 0, 0) |
check.desc = desc |
for name, func in pairs(methods) do |
check[name] = func |
end |
for name, func in pairs(scripts) do |
check:SetScript(name, func) |
end |
return check |
end |
--[[-------------------------------------------------------------------- |
PhanxConfig-Checkbox |
Simple checkbox widget generator. |
Based on tekKonfig-Checkbox by Tekkub. |
Requires LibStub. |
This library is not intended for use by other authors. Absolutely no |
support of any kind will be provided for other authors using it, and |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local MINOR_VERSION = tonumber(strmatch("$Revision$", "%d+")) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-Checkbox", MINOR_VERSION) |
if not lib then return end |
------------------------------------------------------------------------ |
local scripts = {} |
function scripts:OnClick() |
local checked = self:GetChecked() == 1 |
PlaySound(checked and "igMainMenuOptionCheckBoxOn" or "igMainMenuOptionCheckBoxOff") |
self:GetScript("OnLeave")(self) |
local handler = self.func or self.ApplyValue or self.OnValueChanged or self.OnClick -- OnClick is deprecated |
if handler then |
handler(self, checked) |
end |
end |
function scripts:OnEnter() |
if self.tooltipText then |
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, true) |
end |
end |
function scripts:OnLeave() |
GameTooltip:Hide() |
end |
function scripts:OnEnable() |
if not self.disabled then return end |
local r, g, b = self.label:GetTextColor() |
self.label:SetTextColor(r * 2, g * 2, b * 2) |
self.disabled = nil |
end |
function scripts:OnDisable() |
if self.disabled then return end |
local r, g, b = self.label:GetTextColor() |
self.label:SetTextColor(r / 2, g / 2, b / 2) |
self.disabled = true |
end |
------------------------------------------------------------------------ |
local methods = {} |
function methods:GetValue() |
return self:GetChecked() == 1 |
end |
function methods:SetValue(value, auto) |
self:SetChecked(value) |
end |
function methods:GetTooltipText() |
return self.tooltipText |
end |
function methods:SetTooltipText(text) |
self.tooltipText = text |
end |
function methods:SetFunction(func) |
self.func = func |
end |
------------------------------------------------------------------------ |
function lib:New(parent, text, tooltipText) |
assert(type(parent) == "table" and type(rawget(parent, 0) == "userdata"), "PhanxConfig-Checkbox: parent must be a frame") |
if type(name) ~= "string" then name = nil end |
if type(tooltipText) ~= "string" then tooltipText = nil end |
local check = CreateFrame("CheckButton", nil, parent) |
check:SetSize(26, 26) |
check:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up") |
check:SetPushedTexture("Interface\\Buttons\\UI-CheckBox-Down") |
check:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight") |
check:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check") |
check:SetDisabledCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check-Disabled") |
local label = check:CreateFontString(nil, "ARTWORK", "GameFontHighlight") |
label:SetPoint("LEFT", check, "RIGHT", 2, 1) |
label:SetText(text) |
check.label = label |
check:SetMotionScriptsWhileDisabled(true) |
for name, func in pairs(scripts) do |
check:SetScript(name, func) |
end |
for name, func in pairs(methods) do |
check[name] = func |
end |
check.tooltipText = tooltipText |
check:SetHitRectInsets(0, -1 * min(186, max(label:GetStringWidth(), 100)), 0, 0) |
return check |
end |
function lib.CreateCheckbox(...) return lib:New(...) end |
its internals may change at any time without notice. |
----------------------------------------------------------------------]] |
local MINOR_VERSION = tonumber( strmatch( "$Revision$", "%d+" ) ) |
local MINOR_VERSION = tonumber(strmatch("$Revision$", "%d+")) |
local lib, oldminor = LibStub:NewLibrary( "PhanxConfig-Header", MINOR_VERSION ) |
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-Header", MINOR_VERSION) |
if not lib then return end |
function lib:New( parent, titleText, notesText, noPrefix ) |
assert( type( parent ) == "table" and parent.CreateFontString, "Parent is not a valid frame!" ) |
if type( titleText ) ~= "string" then titleText = nil end |
if type( notesText ) ~= "string" then notesText = nil end |
function lib:New(parent, titleText, notesText, noPrefix) |
assert(type(parent) == "table" and parent.CreateFontString, "Parent is not a valid frame!") |
if type(titleText) ~= "string" then titleText = nil end |
if type(notesText) ~= "string" then notesText = nil end |
if not titleText then |
titleText = parent.name |
end |
if titleText and not noPrefix and parent.parent then |
titleText = format( "%s - %s", parent.parent, titleText ) |
titleText = format("%s - %s", parent.parent, titleText) |
end |
local title = parent:CreateFontString( nil, "ARTWORK", "GameFontNormalLarge" ) |
title:SetPoint( "TOPLEFT", 16, -16 ) |
title:SetPoint( "TOPRIGHT", -16, -16 ) |
title:SetJustifyH( "LEFT" ) |
title:SetText( titleText ) |
local title = parent:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge") |
title:SetPoint("TOPLEFT", 16, -16) |
title:SetPoint("TOPRIGHT", -16, -16) |
title:SetJustifyH("LEFT") |
title:SetText(titleText) |
local notes = parent:CreateFontString( nil, "ARTWORK", "GameFontHighlightSmall" ) |
notes:SetPoint( "TOPLEFT", title, "BOTTOMLEFT", 0, -8 ) |
notes:SetPoint( "TOPRIGHT", title, 0, -8 ) |
notes:SetHeight( 32 ) |
notes:SetJustifyH( "LEFT" ) |
notes:SetJustifyV( "TOP" ) |
notes:SetNonSpaceWrap( true ) |
notes:SetText( notesText ) |
local notes = parent:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") |
notes:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8) |
notes:SetPoint("TOPRIGHT", title, 0, -8) |
notes:SetHeight(32) |
notes:SetJustifyH("LEFT") |
notes:SetJustifyV("TOP") |
notes:SetNonSpaceWrap(true) |
notes:SetText(notesText) |
return title, notes |
end |
function lib.CreateHeader( ... ) return lib:New( ... ) end |