Multientry (#7)

* from retail

* from retail

* from retail

* from retail

* from retail

* from retail

* remove new threat functions as they are not well implemented for now
This commit is contained in:
NoM0Re
2024-11-27 12:09:02 +01:00
committed by GitHub
parent eb8221cf89
commit 13f734038d
67 changed files with 3493 additions and 969 deletions
@@ -0,0 +1,135 @@
if not WeakAuras.IsCorrectVersion() then return end
local Type, Version = "WeakAurasAnchorButtons", 2
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
local directions = { "TOPLEFT", "TOP", "TOPRIGHT", "LEFT", "CENTER", "RIGHT", "BOTTOMLEFT", "BOTTOM", "BOTTOMRIGHT" }
local buttonSize = 10
local frameWidth = 100
local frameHeight = 50
local titleHeight = 15
local methods = {
["OnAcquire"] = function(self)
self:SetWidth(frameWidth + buttonSize)
self:SetHeight(frameHeight + buttonSize + titleHeight + 2)
self:SetDisabled(false)
end,
["SetValue"] = function(self, text)
if not tContains(directions, text) then return end
for direction, button in pairs(self.buttons) do
if direction == text then
button.tex:SetVertexColor(0.9, 0.9, 0, 1)
else
button.tex:SetVertexColor(0.3, 0.3, 0.3, 1)
end
button:SetNormalTexture(button.tex)
end
self.value = text
end,
["GetValue"] = function(self)
return self.value
end,
["SetLabel"] = function(self, text)
if text and text ~= "" then
self.label:SetText(text);
self.label:Show()
else
self.label:SetText("")
self.label:Hide()
end
end,
["SetList"] = function() end,
["SetDisabled"] = function(self, disabled)
self.disabled = disabled
if disabled then
self.label:SetTextColor(0.5,0.5,0.5)
for _, button in pairs(self.buttons) do
button:EnableMouse(false)
end
else
self.label:SetTextColor(1,.82,0)
for _, button in pairs(self.buttons) do
button:EnableMouse(true)
end
end
end,
}
local function buttonClicked(self)
AceGUI:ClearFocus()
local frame = self:GetParent()
local widget = frame.obj
widget:SetValue(self.value)
widget:Fire("OnValueChanged", self.value)
end
local function Constructor()
local name = "WeakAurasAnchorButtons" .. AceGUI:GetNextWidgetNum(Type)
local frame = CreateFrame("Frame", name, UIParent)
frame:SetSize(frameWidth, frameHeight)
frame:SetFrameStrata("FULLSCREEN_DIALOG")
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall");
label:SetHeight(titleHeight);
label:SetJustifyH("CENTER");
label:SetPoint("TOP", frame, "TOP");
local background = CreateFrame("Frame", nil, frame)
background:SetSize(frameWidth, frameHeight)
background:SetPoint("TOP", frame, "TOP", 0, -(titleHeight + 4))
background:SetBackdrop({
bgFile = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\Square_FullWhite.tga",
edgeFile = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\Square_FullWhite.tga",
tile = true,
tileEdge = true,
--tileSize = 8,
edgeSize = 2
--insets = { left = 1, right = 1, top = 1, bottom = 1 },
})
background:SetBackdropColor(0.2,0.2,0.2,0.5)
background:SetBackdropBorderColor(1,1,1,0.6)
local buttons = {}
for _, direction in ipairs(directions) do
local button = CreateFrame("Button", nil, frame)
button:SetSize(buttonSize, buttonSize)
button:SetPoint(
"CENTER",
background,
direction
)
local buttonTex = button:CreateTexture()
buttonTex:SetAllPoints()
buttonTex:SetTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\Square_FullWhite.tga")
buttonTex:SetVertexColor(0.3, 0.3, 0.3, 1)
button:SetNormalTexture(buttonTex)
button.tex = buttonTex
button.value = direction
button:SetScript("OnClick", buttonClicked)
buttons[direction] = button
end
--- @type table<string, any>
local widget = {
frame = frame,
type = Type,
buttons = buttons,
label = label
}
for method, func in pairs(methods) do
widget[method] = func
end
return AceGUI:RegisterAsWidget(widget);
end
AceGUI:RegisterWidgetType(Type, Constructor, Version)
@@ -0,0 +1,43 @@
--[[-----------------------------------------------------------------------------
Input Widget that allows to show an alternative text when it does not have focus
-------------------------------------------------------------------------------]]
if not WeakAuras.IsCorrectVersion() then return end
local Type, Version = "WeakAurasInputFocus", 1
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
local OnEditFocusGained = function(self)
local textWithFocus = self.obj.textWithFocus
if textWithFocus and self:GetText() == self.obj.textWithoutFocus then
self:SetText(textWithFocus)
end
AceGUI:SetFocus(self.obj)
end
local function Constructor()
local button = AceGUI:Create("EditBox")
button.type = Type
button.editbox:SetScript("OnEditFocusGained", OnEditFocusGained)
local oldSetText = button.SetText
button.SetText = function(self, text)
text = text or ""
local pos = string.find(text, "\0", nil, true)
if pos then
self.textWithoutFocus = text:sub(1, pos -1)
self.textWithFocus = text:sub(pos + 1)
oldSetText(self, self.textWithoutFocus)
else
self.textWithFocus = nil
self.textWithoutFocus = nil
oldSetText(self, text)
end
end
return button
end
AceGUI:RegisterWidgetType(Type, Constructor, Version)
@@ -0,0 +1,379 @@
if not WeakAuras.IsCorrectVersion() then return end
-- based on the AceGUI widget, overwrites the enter handling
local Type, Version = "WeakAuras-MultiLineEditBoxWithEnter", 1
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs
local pairs = pairs
-- WoW APIs
local GetCursorInfo, GetSpellInfo, ClearCursor = GetCursorInfo, GetSpellInfo, ClearCursor
local CreateFrame, UIParent = CreateFrame, UIParent
local _G = _G
--[[-----------------------------------------------------------------------------
Support functions
-------------------------------------------------------------------------------]]
if not AceGUIWeakAurasMultiLineEditBoxWithEnterInsertLink then
-- upgradeable hook
hooksecurefunc("ChatEdit_InsertLink", function(...) return _G.AceGUIWeakAurasMultiLineEditBoxWithEnterInsertLink(...) end)
end
function _G.AceGUIWeakAurasMultiLineEditBoxWithEnterInsertLink(text)
for i = 1, AceGUI:GetWidgetCount(Type) do
local editbox = _G[("MultiLineEditBox%uEdit"):format(i)]
if editbox and editbox:IsVisible() and editbox:HasFocus() then
editbox:Insert(text)
return true
end
end
end
local function Layout(self)
self:SetHeight(self.numlines * 14 + (self.disablebutton and 19 or 41) + self.labelHeight)
if self.labelHeight == 0 then
self.scrollBar:SetPoint("TOP", self.frame, "TOP", 0, -23)
else
self.scrollBar:SetPoint("TOP", self.label, "BOTTOM", 0, -19)
end
if self.disablebutton then
self.scrollBar:SetPoint("BOTTOM", self.frame, "BOTTOM", 0, 21)
self.scrollBG:SetPoint("BOTTOMLEFT", 0, 4)
else
self.scrollBar:SetPoint("BOTTOM", self.button, "TOP", 0, 18)
self.scrollBG:SetPoint("BOTTOMLEFT", self.button, "TOPLEFT")
end
end
--[[-----------------------------------------------------------------------------
Scripts
-------------------------------------------------------------------------------]]
local function OnEnterPressed(self) -- EditBox
self:HighlightText(0, 0)
self.obj:Fire("OnEnterPressed", self:GetText())
end
local function OnClick(self) -- Button
self = self.obj
self.editBox:ClearFocus()
if not self:Fire("OnEnterPressed", self.editBox:GetText()) then
self.button:Disable()
end
end
local function OnCursorChanged(self, _, y, _, cursorHeight) -- EditBox
self, y = self.obj.scrollFrame, -y
local offset = self:GetVerticalScroll()
if y < offset then
self:SetVerticalScroll(y)
else
y = y + cursorHeight - self:GetHeight()
if y > offset then
self:SetVerticalScroll(y)
end
end
end
local function OnEditFocusLost(self) -- EditBox
self:HighlightText(0, 0)
self.obj:Fire("OnEditFocusLost")
end
local function OnEnter(self) -- EditBox / ScrollFrame
self = self.obj
if not self.entered then
self.entered = true
self:Fire("OnEnter")
end
end
local function OnLeave(self) -- EditBox / ScrollFrame
self = self.obj
if self.entered then
self.entered = nil
self:Fire("OnLeave")
end
end
local function OnMouseUp(self) -- ScrollFrame
self = self.obj.editBox
self:SetFocus()
self:SetCursorPosition(self:GetNumLetters())
end
local function OnReceiveDrag(self) -- EditBox / ScrollFrame
local type, id, info = GetCursorInfo()
if type == "spell" then
info = GetSpellInfo(id, info)
elseif type ~= "item" then
return
end
ClearCursor()
self = self.obj
local editBox = self.editBox
if not editBox:HasFocus() then
editBox:SetFocus()
editBox:SetCursorPosition(editBox:GetNumLetters())
end
editBox:Insert(info)
self.button:Enable()
end
local function OnSizeChanged(self, width, height) -- ScrollFrame
self.obj.editBox:SetWidth(width)
end
local function OnTextChanged(self, userInput) -- EditBox
if userInput then
self = self.obj
self:Fire("OnTextChanged", self.editBox:GetText())
self.button:Enable()
end
end
local function OnTextSet(self) -- EditBox
self:HighlightText(0, 0)
self:SetCursorPosition(self:GetNumLetters())
self:SetCursorPosition(0)
self.obj.button:Disable()
end
local function OnVerticalScroll(self, offset) -- ScrollFrame
local editBox = self.obj.editBox
editBox:SetHitRectInsets(0, 0, offset, editBox:GetHeight() - offset - self:GetHeight())
end
local function OnScrollRangeChanged(self, xrange, yrange)
if yrange == 0 then
self.obj.editBox:SetHitRectInsets(0, 0, 0, 0)
else
OnVerticalScroll(self, self:GetVerticalScroll())
end
end
local function OnShowFocus(frame)
frame.obj.editBox:SetFocus()
frame:SetScript("OnShow", nil)
end
local function OnEditFocusGained(frame)
AceGUI:SetFocus(frame.obj)
frame.obj:Fire("OnEditFocusGained")
end
--[[-----------------------------------------------------------------------------
Methods
-------------------------------------------------------------------------------]]
local methods = {
["OnAcquire"] = function(self)
self.editBox:SetText("")
self:SetDisabled(false)
self:SetWidth(200)
self:DisableButton(false)
self:SetNumLines()
self.entered = nil
self:SetMaxLetters(0)
end,
["OnRelease"] = function(self)
self:ClearFocus()
end,
["SetDisabled"] = function(self, disabled)
local editBox = self.editBox
if disabled then
editBox:ClearFocus()
editBox:EnableMouse(false)
editBox:SetTextColor(0.5, 0.5, 0.5)
self.label:SetTextColor(0.5, 0.5, 0.5)
self.scrollFrame:EnableMouse(false)
self.button:Disable()
else
editBox:EnableMouse(true)
editBox:SetTextColor(1, 1, 1)
self.label:SetTextColor(1, 0.82, 0)
self.scrollFrame:EnableMouse(true)
end
end,
["SetLabel"] = function(self, text)
if text and text ~= "" then
self.label:SetText(text)
if self.labelHeight ~= 10 then
self.labelHeight = 10
self.label:Show()
end
elseif self.labelHeight ~= 0 then
self.labelHeight = 0
self.label:Hide()
end
Layout(self)
end,
["SetNumLines"] = function(self, value)
if not value or value < 4 then
value = 4
end
self.numlines = value
Layout(self)
end,
["SetText"] = function(self, text)
self.editBox:SetText(text)
end,
["GetText"] = function(self)
return self.editBox:GetText()
end,
["SetMaxLetters"] = function (self, num)
self.editBox:SetMaxLetters(num or 0)
end,
["DisableButton"] = function(self, disabled)
self.disablebutton = disabled
if disabled then
self.button:Hide()
else
self.button:Show()
end
Layout(self)
end,
["ClearFocus"] = function(self)
self.editBox:ClearFocus()
self.frame:SetScript("OnShow", nil)
end,
["SetFocus"] = function(self)
self.editBox:SetFocus()
if not self.frame:IsShown() then
self.frame:SetScript("OnShow", OnShowFocus)
end
end,
["HighlightText"] = function(self, from, to)
self.editBox:HighlightText(from, to)
end,
["GetCursorPosition"] = function(self)
return self.editBox:GetCursorPosition()
end,
["SetCursorPosition"] = function(self, ...)
return self.editBox:SetCursorPosition(...)
end,
}
--[[-----------------------------------------------------------------------------
Constructor
-------------------------------------------------------------------------------]]
local backdrop = {
bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 16,
insets = { left = 4, right = 3, top = 4, bottom = 3 }
}
local function Constructor()
local frame = CreateFrame("Frame", nil, UIParent)
frame:Hide()
local widgetNum = AceGUI:GetNextWidgetNum(Type)
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
label:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, -4)
label:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, -4)
label:SetJustifyH("LEFT")
label:SetText(ACCEPT)
label:SetHeight(10)
local button = CreateFrame("Button", ("%s%dButton"):format(Type, widgetNum), frame, "UIPanelButtonTemplate")
button:SetPoint("BOTTOMLEFT", 0, 4)
button:SetHeight(22)
button:SetWidth(label:GetStringWidth() + 24)
button:SetText(ACCEPT)
button:SetScript("OnClick", OnClick)
button:Disable()
local text = button:GetFontString()
text:ClearAllPoints()
text:SetPoint("TOPLEFT", button, "TOPLEFT", 5, -5)
text:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -5, 1)
text:SetJustifyV("MIDDLE")
local scrollBG = CreateFrame("Frame", nil, frame)
scrollBG:SetBackdrop(backdrop)
scrollBG:SetBackdropColor(0, 0, 0)
scrollBG:SetBackdropBorderColor(0.4, 0.4, 0.4)
local scrollFrame = CreateFrame("ScrollFrame", ("%s%dScrollFrame"):format(Type, widgetNum), frame, "UIPanelScrollFrameTemplate")
local scrollBar = _G[scrollFrame:GetName() .. "ScrollBar"]
scrollBar:ClearAllPoints()
scrollBar:SetPoint("TOP", label, "BOTTOM", 0, -19)
scrollBar:SetPoint("BOTTOM", button, "TOP", 0, 18)
scrollBar:SetPoint("RIGHT", frame, "RIGHT")
scrollBG:SetPoint("TOPRIGHT", scrollBar, "TOPLEFT", 0, 19)
scrollBG:SetPoint("BOTTOMLEFT", button, "TOPLEFT")
scrollFrame:SetPoint("TOPLEFT", scrollBG, "TOPLEFT", 5, -6)
scrollFrame:SetPoint("BOTTOMRIGHT", scrollBG, "BOTTOMRIGHT", -4, 4)
scrollFrame:SetScript("OnEnter", OnEnter)
scrollFrame:SetScript("OnLeave", OnLeave)
scrollFrame:SetScript("OnMouseUp", OnMouseUp)
scrollFrame:SetScript("OnReceiveDrag", OnReceiveDrag)
scrollFrame:SetScript("OnSizeChanged", OnSizeChanged)
scrollFrame:HookScript("OnVerticalScroll", OnVerticalScroll)
scrollFrame:HookScript("OnScrollRangeChanged", OnScrollRangeChanged)
local editBox = CreateFrame("EditBox", ("%s%dEdit"):format(Type, widgetNum), scrollFrame)
editBox:SetAllPoints()
editBox:SetFontObject(ChatFontNormal)
editBox:SetMultiLine(true)
editBox:EnableMouse(true)
editBox:SetAutoFocus(false)
editBox:SetCountInvisibleLetters(false)
editBox:SetScript("OnCursorChanged", OnCursorChanged)
editBox:SetScript("OnEditFocusLost", OnEditFocusLost)
editBox:SetScript("OnEnter", OnEnter)
editBox:SetScript("OnEscapePressed", editBox.ClearFocus)
editBox:SetScript("OnLeave", OnLeave)
editBox:SetScript("OnMouseDown", OnReceiveDrag)
editBox:SetScript("OnReceiveDrag", OnReceiveDrag)
editBox:SetScript("OnTextChanged", OnTextChanged)
editBox:SetScript("OnTextSet", OnTextSet)
editBox:SetScript("OnEditFocusGained", OnEditFocusGained)
editBox:SetScript("OnEnterPressed", OnEnterPressed)
scrollFrame:SetScrollChild(editBox)
local widget = {
button = button,
editBox = editBox,
frame = frame,
label = label,
labelHeight = 10,
numlines = 4,
scrollBar = scrollBar,
scrollBG = scrollBG,
scrollFrame = scrollFrame,
type = Type
}
for method, func in pairs(methods) do
widget[method] = func
end
button.obj, editBox.obj, scrollFrame.obj = widget, widget, widget
return AceGUI:RegisterAsWidget(widget)
end
AceGUI:RegisterWidgetType(Type, Constructor, Version)
@@ -1,42 +0,0 @@
if not WeakAuras.IsCorrectVersion() then return end
local Type, Version = "WeakAurasSortedDropdown", 1
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
local function Constructor()
local DropDownConstructor = AceGUI.WidgetRegistry["Dropdown"];
if (not DropDownConstructor) then
return nil;
end
local widget = DropDownConstructor();
if (not widget) then
return nil;
end
local oldSetList = widget.SetList
widget.SetList = function(self, list, _, itemType)
local orderTable = {};
for k, v in pairs(list) do
tinsert(orderTable, { key = k, value = v });
end
local order = {};
table.sort(orderTable, function(a, b)
return a.value < b.value;
end);
for i, item in ipairs(orderTable) do
order[i] = item.key;
end
oldSetList(self, list, order, itemType)
end
widget.type = Type;
return widget;
end
AceGUI:RegisterWidgetType(Type, Constructor, Version)
@@ -0,0 +1,374 @@
--[[-----------------------------------------------------------------------------
Spin Box Widget
-------------------------------------------------------------------------------]]
local Type, Version = "WeakAurasSpinBox", 5
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then
return
end
-- Lua APIs
local math_min, math_max, floor = math.min, math.max, math.floor
local tonumber, pairs = tonumber, pairs
-- WoW APIs
local PlaySound = PlaySound
local CreateFrame, UIParent = CreateFrame, UIParent
local progressLeftOffset = -3
local progressExtraWidth = -0
local progressTopOffset = -2
local progressBottomOffset = 2
--[[-----------------------------------------------------------------------------
Support functions
-------------------------------------------------------------------------------]]
local function UpdateText(self)
local value = self:GetValue() or 0
if self.ispercent then
self.editbox:SetText(("%s%%"):format(floor(value * 1000 + 0.5) / 10))
else
self.editbox:SetText(floor(value * 100 + 0.5) / 100)
end
end
local function UpdateButtons(self)
local value = self:GetValue() or 0
if value > self.min then
self.leftbutton:Enable()
else
self.leftbutton:Disable()
end
if value < self.max then
self.rightbutton:Enable()
else
self.rightbutton:Disable()
end
end
local function UpdateProgressBar(self)
local value = self:GetValue() or 0
local p = 0
if self.min and self.max then
if self.min < self.max then
p = (value - self.min) / (self.max - self.min)
end
end
p = Clamp(p, 0, 1)
local w = p * (self.frame:GetWidth() - 45 + progressExtraWidth)
self.progressBar:SetWidth(max(w, 1))
self.progressBar:SetTexCoord(0, p , 0, 1)
end
local function UpdateHandleColor(self)
if self.progressBarHandle.mouseDown then
self.progressBarHandleTexture:SetVertexColor(0.6, 0.6, 0, 1)
--self.progressBarHandleTexture:SetColorTexture(0.6, 0.6, 0, 1)
elseif MouseIsOver(self.progressBarHandle) then
self.progressBarHandleTexture:SetVertexColor(0.8, 0.8, 0, 1)
--self.progressBarHandleTexture:SetColorTexture(0.8, 0.8, 0, 1)
else
self.progressBarHandleTexture:SetVertexColor(0.4, 0.4, 0, 1)
--self.progressBarHandleTexture:SetColorTexture(0.4, 0.4, 0, 1)
end
end
local function UpdateHandleVisibility(self)
if MouseIsOver(self.frame) then
self.progressBarHandle:Show()
UpdateHandleColor(self)
else
self.progressBarHandle:Hide()
end
end
--[[-----------------------------------------------------------------------------
Scripts
-------------------------------------------------------------------------------]]
local function SpinBox_OnValueDown(frame)
local self = frame.obj
--self.editbox:SetFocus()
local value = self.value or 0
local step = self.step or 1
value = math_max(self.min, value - step)
PlaySound("igMainMenuOptionCheckBoxOn")
self:SetValue(value, true)
end
local function SpinBox_OnValueUp(frame)
local self = frame.obj
--self.editbox:SetFocus()
local value = self.value or 0
local step = self.step or 1
value = math_min(self.max, value + step)
PlaySound("igMainMenuOptionCheckBoxOn")
self:SetValue(value, true)
end
local function EditBox_OnEscapePressed(frame)
frame:ClearFocus()
end
local function EditBox_OnEnterPressed(frame)
local self = frame.obj
local value = frame:GetText()
if self.ispercent then
value = value:gsub("%%", "")
value = tonumber(value) / 100
else
value = tonumber(value)
end
if value then
PlaySound("igMainMenuOptionCheckBoxOn")
self:SetValue(value, true)
end
frame:ClearFocus()
end
local function EditBox_OnEnter(frame)
frame.onEntered = true
if not frame.obj.progressBarHandle.mouseDown then
frame.obj:Fire("OnEnter")
end
end
local function EditBox_OnLeave(frame)
if frame.onEntered then
frame.obj:Fire("OnLeave")
end
frame.onEntered = false
end
local function Frame_OnEnter(frame)
UpdateHandleVisibility(frame.obj)
end
local function ProgressBarHandle_OnUpdate(frame, elapsed)
UpdateHandleColor(frame.obj)
if not IsMouseButtonDown("LeftButton") then
if frame.mouseDown then
frame.obj:SetValue(frame.obj:GetValue(), true)
frame.mouseDown = false
end
end
if frame.mouseDown then
frame.timeElapsed = frame.timeElapsed + elapsed
if frame.timeElapsed > 0.1 then
local currentX = GetCursorPosition()
local deltaX = currentX - frame.startX
deltaX = deltaX / frame.obj.editbox:GetEffectiveScale()
local p = deltaX / (frame.obj.frame:GetWidth() - 45 + progressExtraWidth)
local delta = p * (frame.obj.max - frame.obj.min)
local step = frame.obj.step
local v = frame.originalValue + delta
v = v - v % step
v = Clamp(v, frame.obj.min, frame.obj.max)
frame.obj:SetValue(v, false)
frame.timeElapsed = 0
end
else
UpdateHandleVisibility(frame.obj)
end
end
local function ProgressBarHandle_OnMouseDown(frame, button)
if button ~= "LeftButton" then
return
end
frame.startX = GetCursorPosition()
frame.originalValue = frame.obj:GetValue()
frame.timeElapsed = 0
frame.mouseDown = true
end
--[[-----------------------------------------------------------------------------
Methods
-------------------------------------------------------------------------------]]
local methods = {
["OnAcquire"] = function(self)
self:SetWidth(200)
self:SetHeight(44)
self:SetDisabled(false)
self:SetIsPercent(nil)
self:SetSpinBoxValues(0, 100, 1)
self:SetValue(0)
self.progressOpacity = 0
end,
["OnRelease"] = function(self)
self:ClearFocus()
end,
["OnWidthSet"] = function(self, width)
UpdateProgressBar(self)
end,
["SetDisabled"] = function(self, disabled)
self.disabled = disabled
if disabled then
self.label:SetTextColor(0.5, 0.5, 0.5)
self.editbox:SetTextColor(0.5, 0.5, 0.5)
self.editbox:EnableMouse(false)
self.editbox:ClearFocus()
self.leftbutton:Disable()
self.rightbutton:Disable()
else
self.label:SetTextColor(1, 0.82, 0)
self.editbox:SetTextColor(1, 1, 1)
self.editbox:EnableMouse(true)
end
end,
["SetValue"] = function(self, value, reload)
self.value = value
UpdateText(self)
UpdateButtons(self)
UpdateProgressBar(self)
-- In AceOptions the range is treated differently from other widget types
-- Whereas for other widgets OnValueChanged leads to a reload, this is done only
-- on OnMouseUp for ranges. (Probably to not reload the options while dragging)
if reload then
self:Fire("OnMouseUp", value)
else
self:Fire("OnValueChanged", value)
end
end,
["GetValue"] = function(self)
return self.value
end,
["SetLabel"] = function(self, text)
self.label:SetText(text)
end,
["SetSliderValues"] = function(self, ...)
self:SetSpinBoxValues(...)
end,
["SetSpinBoxValues"] = function(self, min, max, step)
self.min = min or 0
self.max = max or 100
self.step = step or 1
UpdateButtons(self)
UpdateProgressBar(self)
end,
["SetIsPercent"] = function(self, value)
self.ispercent = value
UpdateText(self)
end,
["ClearFocus"] = function(self)
self.editbox:ClearFocus()
end,
["SetFocus"] = function(self)
self.editbox:SetFocus()
self.progressBarHandle:Hide()
end,
}
--[[-----------------------------------------------------------------------------
Constructor
-------------------------------------------------------------------------------]]
local function Constructor()
local widgetName = ("%s%d"):format(Type, AceGUI:GetNextWidgetNum(Type)) -- Needs a name for 3.3.5 (InputBoxTemplate ($parent))
local frame = CreateFrame("Frame", widgetName, UIParent)
frame:SetScript("OnEnter", Frame_OnEnter)
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
label:SetPoint("TOPLEFT")
label:SetPoint("TOPRIGHT")
label:SetJustifyH("LEFT")
label:SetHeight(18)
local leftbutton = CreateFrame("Button", nil, frame)
leftbutton:SetSize(16, 16)
leftbutton:SetNormalTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\spinboxleft")
leftbutton:SetHighlightTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\spinboxlefth")
leftbutton:SetPushedTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\spinboxleftp")
leftbutton:SetDisabledTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\spinboxleftp")
leftbutton:SetScript("OnClick", SpinBox_OnValueDown)
local rightbutton = CreateFrame("Button", nil, frame)
rightbutton:SetSize(16, 16)
rightbutton:SetNormalTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\spinboxright")
rightbutton:SetHighlightTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\spinboxrighth")
rightbutton:SetPushedTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\spinboxrightp")
rightbutton:SetDisabledTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\spinboxrightp")
rightbutton:SetScript("OnClick", SpinBox_OnValueUp)
local editbox = CreateFrame("EditBox", nil, frame, "InputBoxTemplate")
editbox:SetAutoFocus(false)
editbox:SetFontObject(ChatFontNormal)
editbox:SetHeight(19)
editbox:SetJustifyH("CENTER")
editbox:EnableMouse(true)
editbox:EnableMouseWheel(false)
editbox:SetTextInsets(0, 0, 3, 3)
editbox:SetScript("OnEnter", EditBox_OnEnter)
editbox:SetScript("OnLeave", EditBox_OnLeave)
editbox:SetScript("OnEnterPressed", EditBox_OnEnterPressed)
editbox:SetScript("OnEscapePressed", EditBox_OnEscapePressed)
editbox:SetScript("OnEditFocusGained", function(frame)
AceGUI:SetFocus(frame.obj)
UpdateHandleVisibility(frame.obj)
end)
editbox:SetScript("OnEditFocusLost", function(frame)
UpdateHandleVisibility(frame.obj)
end)
leftbutton:SetPoint("TOPLEFT", 2, -18)
rightbutton:SetPoint("TOPRIGHT", -2, -18)
editbox:SetPoint("LEFT", leftbutton, "RIGHT", 8, 0)
editbox:SetPoint("RIGHT", rightbutton, "LEFT", -2, 0)
local progressBar = editbox:CreateTexture(nil, "ARTWORK", nil)
progressBar:SetTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\spinboxoverlay")
progressBar:SetVertexColor(0.50, 0.50, 0.50, 1)
progressBar:SetPoint("TOPLEFT", editbox, "TOPLEFT", progressLeftOffset, progressTopOffset)
progressBar:SetPoint("BOTTOMLEFT", editbox, "BOTTOMLEFT", progressLeftOffset, progressBottomOffset)
progressBar:SetWidth(0)
local progressBarHandle = CreateFrame("Frame", nil, editbox)
progressBarHandle:SetPoint("TOP", progressBar, "TOP", 0, 2)
progressBarHandle:SetPoint("BOTTOM", progressBar, "BOTTOM", 0, -2)
progressBarHandle:SetPoint("LEFT", progressBar, "RIGHT", -4, 0)
progressBarHandle:SetPoint("RIGHT", progressBar, "RIGHT", 4, 0)
progressBarHandle:EnableMouse(true)
progressBarHandle:Hide()
progressBarHandle:SetScript("OnMouseDown", ProgressBarHandle_OnMouseDown)
progressBarHandle:SetScript("OnUpdate", ProgressBarHandle_OnUpdate)
local progressBarHandleTexture = progressBarHandle:CreateTexture(nil, "ARTWORK")
progressBarHandleTexture:SetTexture("Interface\\AddOns\\WeakAuras\\Media\\Textures\\Square_White")
progressBarHandleTexture:SetVertexColor(0.8, 0.8, 0, 0.8)
progressBarHandleTexture:SetPoint("TOPLEFT", progressBarHandle, "TOPLEFT", 2, -2)
progressBarHandleTexture:SetPoint("BOTTOMRIGHT", progressBarHandle, "BOTTOMRIGHT", -2, 2)
local widget = {
label = label,
editbox = editbox,
leftbutton = leftbutton,
rightbutton = rightbutton,
progressBar = progressBar,
progressBarHandle = progressBarHandle,
progressBarHandleTexture = progressBarHandleTexture,
type = Type,
frame = frame,
}
for method, func in pairs(methods) do
widget[method] = func
end
editbox.obj, leftbutton.obj, rightbutton.obj, frame.obj, progressBarHandle.obj = widget, widget, widget, widget, widget
return AceGUI:RegisterAsWidget(widget)
end
AceGUI:RegisterWidgetType(Type, Constructor, Version)