Implement offsetting to placement functions
This commit is contained in:
@@ -7,27 +7,99 @@ local configFrame = CreateFrame("Frame", "HeimdallConfig", UIParent)
|
|||||||
---@diagnostic disable-next-line: missing-fields
|
---@diagnostic disable-next-line: missing-fields
|
||||||
shared.Config = {}
|
shared.Config = {}
|
||||||
function shared.Config.Init()
|
function shared.Config.Init()
|
||||||
local function PutBelow(a, b)
|
local function PutBelow(a, b, offset)
|
||||||
a:SetPoint("LEFT", b, "LEFT", 0, -24)
|
local x = 0
|
||||||
|
local y = -24
|
||||||
|
if offset and offset.x then
|
||||||
|
x = x + offset.x
|
||||||
end
|
end
|
||||||
local function PutRight(a, b)
|
if offset and offset.y then
|
||||||
a:SetPoint("LEFT", b, "LEFT", 128, 0)
|
y = y + offset.y
|
||||||
|
end
|
||||||
|
a:SetPoint("LEFT", b, "LEFT", x, y)
|
||||||
|
end
|
||||||
|
local function PutRight(a, b, offset)
|
||||||
|
local x = 128
|
||||||
|
local y = 0
|
||||||
|
if offset and offset.x then
|
||||||
|
x = x + offset.x
|
||||||
|
end
|
||||||
|
if offset and offset.y then
|
||||||
|
y = y + offset.y
|
||||||
|
end
|
||||||
|
a:SetPoint("LEFT", b, "LEFT", x, y)
|
||||||
end
|
end
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param parent Frame
|
---@param parent Frame
|
||||||
---@param text string
|
---@param text string
|
||||||
---@param onClick function
|
---@param onClick fun(state: boolean)
|
||||||
local function BasicButton(name, parent, text, onClick)
|
local function BasicButton(name, parent, text, onClick)
|
||||||
local button = CreateFrame("CheckButton", name, parent, "UICheckButtonTemplate")
|
local button = CreateFrame("CheckButton", name, parent, "UICheckButtonTemplate")
|
||||||
button.text = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
button.text = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||||
button.text:SetText(text)
|
button.text:SetText(text)
|
||||||
button.text:SetPoint("LEFT", button, "RIGHT", 0, 0)
|
button.text:SetPoint("LEFT", button, "RIGHT", 0, 0)
|
||||||
button:SetSize(24, 24)
|
button:SetSize(24, 24)
|
||||||
button:SetScript("OnClick", onClick)
|
button:SetScript("OnClick", function()
|
||||||
|
onClick(button:GetChecked())
|
||||||
|
end)
|
||||||
|
|
||||||
button.PutBelow = PutBelow
|
button.PutBelow = PutBelow
|
||||||
button.PutRight = PutRight
|
button.PutRight = PutRight
|
||||||
return button
|
return button
|
||||||
end
|
end
|
||||||
|
---@param name string
|
||||||
|
---@param parent Frame
|
||||||
|
---@param text string
|
||||||
|
---@param onDone fun(text: string)
|
||||||
|
local function CreateBasicSmallEditBox(name, parent, text, onDone)
|
||||||
|
local editBox = CreateFrame("EditBox", name, parent)
|
||||||
|
editBox.text = editBox:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||||
|
editBox.text:SetText(text)
|
||||||
|
editBox.text:SetPoint("TOPLEFT", editBox, "TOPLEFT", 0, 8 + 4)
|
||||||
|
editBox:SetNumeric(true)
|
||||||
|
editBox:SetSize(128 - 8, 24)
|
||||||
|
editBox:SetAutoFocus(false)
|
||||||
|
editBox:SetFontObject("GameFontNormal")
|
||||||
|
editBox:SetText(Heimdall_Data.config.spotter.throttleTime)
|
||||||
|
editBox:SetBackdrop({
|
||||||
|
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
||||||
|
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
|
||||||
|
tile = true,
|
||||||
|
tileSize = 2,
|
||||||
|
edgeSize = 2,
|
||||||
|
insets = {
|
||||||
|
left = 2,
|
||||||
|
right = 2,
|
||||||
|
top = 2,
|
||||||
|
bottom = 2
|
||||||
|
}
|
||||||
|
})
|
||||||
|
editBox:SetBackdropColor(0.8, 0.8, 0.8, 1)
|
||||||
|
editBox:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
||||||
|
editBox:SetScript("OnEnterPressed", function()
|
||||||
|
onDone(editBox:GetText())
|
||||||
|
end)
|
||||||
|
editBox:SetScript("OnEscapePressed", function()
|
||||||
|
editBox:ClearFocus()
|
||||||
|
end)
|
||||||
|
editBox:SetScript("OnEditFocusLost", function()
|
||||||
|
onDone(editBox:GetText())
|
||||||
|
end)
|
||||||
|
|
||||||
|
editBox.PutBelow = function(a, b, offset)
|
||||||
|
offset = offset or {}
|
||||||
|
offset.x = (offset.x or 0) + 0
|
||||||
|
offset.y = (offset.y or 0) - 12
|
||||||
|
PutBelow(a, b, offset)
|
||||||
|
end
|
||||||
|
editBox.PutRight = function(a, b, offset)
|
||||||
|
offset = offset or {}
|
||||||
|
offset.x = (offset.x or 0) + 0
|
||||||
|
offset.y = (offset.y or 0) - 8
|
||||||
|
PutRight(a, b, offset)
|
||||||
|
end
|
||||||
|
return editBox
|
||||||
|
end
|
||||||
|
|
||||||
configFrame:SetSize(256 + 256, 512)
|
configFrame:SetSize(256 + 256, 512)
|
||||||
configFrame:SetPoint("CENTER")
|
configFrame:SetPoint("CENTER")
|
||||||
@@ -87,70 +159,43 @@ function shared.Config.Init()
|
|||||||
spotterConfigFrame:SetBackdropColor(0, 0, 0, 0.8)
|
spotterConfigFrame:SetBackdropColor(0, 0, 0, 0.8)
|
||||||
spotterConfigFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
spotterConfigFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
||||||
|
|
||||||
local spotterEnableButton = BasicButton("HeimdallSpotterEnable", spotterConfigFrame, "Enable Spotter", function()
|
local spotterEnableButton = BasicButton("HeimdallSpotterEnable", spotterConfigFrame, "Enable Spotter",
|
||||||
Heimdall_Data.config.spotter.enabled = spotterEnableButton:GetChecked()
|
function(state)
|
||||||
|
Heimdall_Data.config.spotter.enabled = state
|
||||||
end)
|
end)
|
||||||
spotterEnableButton:SetPoint("TOPLEFT", spotterConfigFrame, "TOPLEFT", 4, -4)
|
spotterEnableButton:SetPoint("TOPLEFT", spotterConfigFrame, "TOPLEFT", 4, -4)
|
||||||
spotterEnableButton:SetChecked(Heimdall_Data.config.spotter.enabled)
|
spotterEnableButton:SetChecked(Heimdall_Data.config.spotter.enabled)
|
||||||
|
|
||||||
local spotterEveryoneButton = BasicButton("HeimdallSpotterEveryone", spotterConfigFrame, "Everyone", function()
|
local spotterEveryoneButton = BasicButton("HeimdallSpotterEveryone", spotterConfigFrame, "Everyone", function(state)
|
||||||
Heimdall_Data.config.spotter.everyone = spotterEveryoneButton:GetChecked()
|
Heimdall_Data.config.spotter.everyone = state
|
||||||
end)
|
end)
|
||||||
spotterEveryoneButton:PutRight(spotterEnableButton)
|
spotterEveryoneButton:PutRight(spotterEnableButton)
|
||||||
spotterEveryoneButton:SetChecked(Heimdall_Data.config.spotter.everyone)
|
spotterEveryoneButton:SetChecked(Heimdall_Data.config.spotter.everyone)
|
||||||
|
|
||||||
local spotterHostileButton = BasicButton("HeimdallSpotterHostile", spotterConfigFrame, "Hostile", function()
|
local spotterHostileButton = BasicButton("HeimdallSpotterHostile", spotterConfigFrame, "Hostile", function(state)
|
||||||
Heimdall_Data.config.spotter.hostile = spotterHostileButton:GetChecked()
|
Heimdall_Data.config.spotter.hostile = state
|
||||||
end)
|
end)
|
||||||
spotterHostileButton:PutBelow(spotterEnableButton)
|
spotterHostileButton:PutBelow(spotterEnableButton)
|
||||||
spotterHostileButton:SetChecked(Heimdall_Data.config.spotter.hostile)
|
spotterHostileButton:SetChecked(Heimdall_Data.config.spotter.hostile)
|
||||||
|
|
||||||
local spotterAllianceButton = BasicButton("HeimdallSpotterAlliance", spotterConfigFrame, "Alliance", function()
|
local spotterAllianceButton = BasicButton("HeimdallSpotterAlliance", spotterConfigFrame, "Alliance", function(state)
|
||||||
Heimdall_Data.config.spotter.alliance = spotterAllianceButton:GetChecked()
|
Heimdall_Data.config.spotter.alliance = state
|
||||||
end)
|
end)
|
||||||
spotterAllianceButton:PutRight(spotterHostileButton)
|
spotterAllianceButton:PutRight(spotterHostileButton)
|
||||||
spotterAllianceButton:SetChecked(Heimdall_Data.config.spotter.alliance)
|
spotterAllianceButton:SetChecked(Heimdall_Data.config.spotter.alliance)
|
||||||
|
|
||||||
local spotterStinkyButton = BasicButton("HeimdallSpotterStinky", spotterConfigFrame, "Stinky", function()
|
local spotterStinkyButton = BasicButton("HeimdallSpotterStinky", spotterConfigFrame, "Stinky", function(state)
|
||||||
Heimdall_Data.config.spotter.stinky = spotterStinkyButton:GetChecked()
|
Heimdall_Data.config.spotter.stinky = state
|
||||||
end)
|
end)
|
||||||
spotterStinkyButton:PutBelow(spotterHostileButton)
|
spotterStinkyButton:PutBelow(spotterHostileButton)
|
||||||
spotterStinkyButton:SetChecked(Heimdall_Data.config.spotter.stinky)
|
spotterStinkyButton:SetChecked(Heimdall_Data.config.spotter.stinky)
|
||||||
|
|
||||||
local spotterThrottleBox = CreateFrame("EditBox", "HeimdallSpotterThrottle", configFrame)
|
local spotterThrottleBox = CreateBasicSmallEditBox("HeimdallSpotterThrottle", spotterConfigFrame, "Throttle Time",
|
||||||
spotterThrottleBox.text = spotterThrottleBox:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
function(text)
|
||||||
spotterThrottleBox.text:SetText("Throttle Time")
|
Heimdall_Data.config.spotter.throttleTime = tonumber(text)
|
||||||
spotterThrottleBox.text:SetPoint("TOPLEFT", spotterThrottleBox, "TOPLEFT", 0, 8 + 4)
|
|
||||||
spotterThrottleBox:SetNumeric(true)
|
|
||||||
spotterThrottleBox:SetSize(128 - 8, 24)
|
|
||||||
spotterThrottleBox:SetPoint("LEFT", spotterAllianceButton, "LEFT", 0, -24 - 8 - 4)
|
|
||||||
spotterThrottleBox:SetAutoFocus(false)
|
|
||||||
spotterThrottleBox:SetFontObject("GameFontNormal")
|
|
||||||
spotterThrottleBox:SetText(Heimdall_Data.config.spotter.throttleTime)
|
|
||||||
spotterThrottleBox:SetBackdrop({
|
|
||||||
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
|
||||||
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
|
|
||||||
tile = true,
|
|
||||||
tileSize = 2,
|
|
||||||
edgeSize = 2,
|
|
||||||
insets = {
|
|
||||||
left = 2,
|
|
||||||
right = 2,
|
|
||||||
top = 2,
|
|
||||||
bottom = 2
|
|
||||||
}
|
|
||||||
})
|
|
||||||
spotterThrottleBox:SetBackdropColor(0.8, 0.8, 0.8, 1)
|
|
||||||
spotterThrottleBox:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
|
||||||
spotterThrottleBox:SetScript("OnEnterPressed", function()
|
|
||||||
local throttleTime = tonumber(spotterThrottleBox:GetText())
|
|
||||||
if throttleTime then
|
|
||||||
Heimdall_Data.config.spotter.throttleTime = throttleTime
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
spotterThrottleBox:SetScript("OnEscapePressed", function()
|
|
||||||
spotterThrottleBox:ClearFocus()
|
|
||||||
end)
|
end)
|
||||||
|
spotterThrottleBox:PutRight(spotterStinkyButton)
|
||||||
|
|
||||||
-- ---@type table
|
-- ---@type table
|
||||||
-- local spotterEnableButton = CreateFrame("Button", "HeimdallSpotterEnable", configFrame, "UIPanelButtonTemplate")
|
-- local spotterEnableButton = CreateFrame("Button", "HeimdallSpotterEnable", configFrame, "UIPanelButtonTemplate")
|
||||||
-- spotterEnableButton:SetText("Enable Spotter")
|
-- spotterEnableButton:SetText("Enable Spotter")
|
||||||
|
|||||||
Reference in New Issue
Block a user