Implement offsetting to placement functions

This commit is contained in:
2025-01-03 10:48:26 +01:00
parent f1e2f60836
commit e425fa9209

View File

@@ -7,27 +7,99 @@ local configFrame = CreateFrame("Frame", "HeimdallConfig", UIParent)
---@diagnostic disable-next-line: missing-fields
shared.Config = {}
function shared.Config.Init()
local function PutBelow(a, b)
a:SetPoint("LEFT", b, "LEFT", 0, -24)
local function PutBelow(a, b, offset)
local x = 0
local y = -24
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
local function PutRight(a, b)
a:SetPoint("LEFT", b, "LEFT", 128, 0)
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
---@param name string
---@param parent Frame
---@param text string
---@param onClick function
---@param onClick fun(state: boolean)
local function BasicButton(name, parent, text, onClick)
local button = CreateFrame("CheckButton", name, parent, "UICheckButtonTemplate")
button.text = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
button.text:SetText(text)
button.text:SetPoint("LEFT", button, "RIGHT", 0, 0)
button:SetSize(24, 24)
button:SetScript("OnClick", onClick)
button:SetScript("OnClick", function()
onClick(button:GetChecked())
end)
button.PutBelow = PutBelow
button.PutRight = PutRight
return button
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:SetPoint("CENTER")
@@ -87,70 +159,43 @@ function shared.Config.Init()
spotterConfigFrame:SetBackdropColor(0, 0, 0, 0.8)
spotterConfigFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
local spotterEnableButton = BasicButton("HeimdallSpotterEnable", spotterConfigFrame, "Enable Spotter", function()
Heimdall_Data.config.spotter.enabled = spotterEnableButton:GetChecked()
end)
local spotterEnableButton = BasicButton("HeimdallSpotterEnable", spotterConfigFrame, "Enable Spotter",
function(state)
Heimdall_Data.config.spotter.enabled = state
end)
spotterEnableButton:SetPoint("TOPLEFT", spotterConfigFrame, "TOPLEFT", 4, -4)
spotterEnableButton:SetChecked(Heimdall_Data.config.spotter.enabled)
local spotterEveryoneButton = BasicButton("HeimdallSpotterEveryone", spotterConfigFrame, "Everyone", function()
Heimdall_Data.config.spotter.everyone = spotterEveryoneButton:GetChecked()
local spotterEveryoneButton = BasicButton("HeimdallSpotterEveryone", spotterConfigFrame, "Everyone", function(state)
Heimdall_Data.config.spotter.everyone = state
end)
spotterEveryoneButton:PutRight(spotterEnableButton)
spotterEveryoneButton:PutRight(spotterEnableButton)
spotterEveryoneButton:SetChecked(Heimdall_Data.config.spotter.everyone)
local spotterHostileButton = BasicButton("HeimdallSpotterHostile", spotterConfigFrame, "Hostile", function()
Heimdall_Data.config.spotter.hostile = spotterHostileButton:GetChecked()
local spotterHostileButton = BasicButton("HeimdallSpotterHostile", spotterConfigFrame, "Hostile", function(state)
Heimdall_Data.config.spotter.hostile = state
end)
spotterHostileButton:PutBelow(spotterEnableButton)
spotterHostileButton:PutBelow(spotterEnableButton)
spotterHostileButton:SetChecked(Heimdall_Data.config.spotter.hostile)
local spotterAllianceButton = BasicButton("HeimdallSpotterAlliance", spotterConfigFrame, "Alliance", function()
Heimdall_Data.config.spotter.alliance = spotterAllianceButton:GetChecked()
local spotterAllianceButton = BasicButton("HeimdallSpotterAlliance", spotterConfigFrame, "Alliance", function(state)
Heimdall_Data.config.spotter.alliance = state
end)
spotterAllianceButton:PutRight(spotterHostileButton)
spotterAllianceButton:PutRight(spotterHostileButton)
spotterAllianceButton:SetChecked(Heimdall_Data.config.spotter.alliance)
local spotterStinkyButton = BasicButton("HeimdallSpotterStinky", spotterConfigFrame, "Stinky", function()
Heimdall_Data.config.spotter.stinky = spotterStinkyButton:GetChecked()
local spotterStinkyButton = BasicButton("HeimdallSpotterStinky", spotterConfigFrame, "Stinky", function(state)
Heimdall_Data.config.spotter.stinky = state
end)
spotterStinkyButton:PutBelow(spotterHostileButton)
spotterStinkyButton:PutBelow(spotterHostileButton)
spotterStinkyButton:SetChecked(Heimdall_Data.config.spotter.stinky)
local spotterThrottleBox = CreateFrame("EditBox", "HeimdallSpotterThrottle", configFrame)
spotterThrottleBox.text = spotterThrottleBox:CreateFontString(nil, "OVERLAY", "GameFontNormal")
spotterThrottleBox.text:SetText("Throttle Time")
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)
local spotterThrottleBox = CreateBasicSmallEditBox("HeimdallSpotterThrottle", spotterConfigFrame, "Throttle Time",
function(text)
Heimdall_Data.config.spotter.throttleTime = tonumber(text)
end)
spotterThrottleBox:PutRight(spotterStinkyButton)
-- ---@type table
-- local spotterEnableButton = CreateFrame("Button", "HeimdallSpotterEnable", configFrame, "UIPanelButtonTemplate")
-- spotterEnableButton:SetText("Enable Spotter")