Add some basic config buttons for spotter

This commit is contained in:
2025-01-06 22:17:38 +01:00
parent d44aa04e44
commit f680d36d2b

View File

@@ -2,13 +2,12 @@ local addonname, shared = ...
---@cast shared HeimdallShared
---@cast addonname string
---@class GridFrame
---@class GridFrame:Frame
---@field name string
---@field columns number
---@field frame Frame
---@field cellWidth number
---@field cellHeight number
---@field allowOverflow boolean
---@field columnHeights table<number, number>
GridFrame = {
---@param name string
@@ -65,13 +64,6 @@ GridFrame = {
end
end
if not self.allowOverflow then
if bestRow + self.cellHeight * rowspan > self.frame:GetHeight() then
print("Frame is too tall")
return
end
end
if bestColumn then
frame:SetParent(self.frame)
frame.gridData = {
@@ -101,7 +93,13 @@ GridFrame = {
end,
Recalculate = function(self)
local children = { self.frame:GetChildren() }
for _, child in pairs(children) do child:SetPos() end
for _, child in pairs(children) do
if child.gridData then
child:SetPos()
else
print("Child has no grid data", child)
end
end
end,
SetWidth = function(self, width)
self.frame:SetWidth(width)
@@ -114,7 +112,17 @@ GridFrame = {
for _, height in pairs(self.columnHeights) do
tallestRow = math.max(tallestRow, height)
end
self.cellHeight = height / tallestRow
if tallestRow > 0 then
self.cellHeight = height / tallestRow
end
self:Recalculate()
end,
SetPoint = function(self, point, relativeTo, relativePoint, offsetX, offsetY)
self.frame:SetPoint(point, relativeTo, relativePoint, offsetX, offsetY)
self:Recalculate()
end,
SetParent = function(self, parent)
self.frame:SetParent(parent)
self:Recalculate()
end
}
@@ -189,7 +197,9 @@ StaticGridFrame = {
local y = -(row - 1) * self.cellHeight
frame.colspan = colspan
frame.rowspan = rowspan
print("Setting width", self.cellWidth * colspan)
frame:SetWidth(self.cellWidth * colspan)
print("Setting height", self.cellHeight * rowspan)
frame:SetHeight(self.cellHeight * rowspan)
frame:SetPoint("TOPLEFT", self.frame, "TOPLEFT", x, y)
frame:SetParent(self.frame)
@@ -228,17 +238,22 @@ StaticGridFrame = {
end,
SetWidth = function(self, width)
self.frame:SetWidth(width)
self.cellWidth = self.frame:GetWidth() / self.columns
self.cellWidth = width / self.columns
self:Recalculate()
end,
SetHeight = function(self, height)
self.frame:SetHeight(height)
print("Setting height", height)
self.cellHeight = self.frame:GetHeight() / self.rows
print("Cell height", self.cellHeight)
self.cellHeight = height / self.rows
self:Recalculate()
end,
SetPoint = function(self, point, relativeTo, relativePoint, offsetX, offsetY)
self.frame:SetPoint(point, relativeTo, relativePoint, offsetX, offsetY)
self:Recalculate()
end,
SetParent = function(self, parent)
self.frame:SetParent(parent)
self:Recalculate()
end
}
local configFrame = StaticGridFrame.new("HeimdallConfig",
@@ -252,7 +267,7 @@ configFrame:MakeMovable()
-- end
--end)
local colors = {
local colors = {
{ 1, 0, 0, 1 },
{ 0, 1, 0, 1 },
{ 0, 0, 1, 1 },
@@ -261,20 +276,23 @@ local colors = {
{ 0, 1, 1, 1 },
{ 1, 1, 1, 1 },
}
HeimdallTestFrame = GridFrame.new("HeimdallPartyFrame", UIParent, 12, 20, { w = 1024, h = 1024 })
for i = 1, 10 do
local frame = CreateFrame("Frame", "HeimdallPartyFrame" .. i, UIParent)
frame:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
tileSize = 64,
tile = true
})
frame:SetBackdropColor(unpack(colors[i % #colors + 1]))
frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
HeimdallTestFrame:Add(frame, 4, 2)
end
HeimdallTestFrame:SetHeight(128)
HeimdallTestFrame:SetWidth(512)
--HeimdallTestFrame = GridFrame.new("HeimdallPartyFrame", UIParent, 12, 20, { w = 1024, h = 1024 })
--for i = 1, 10 do
-- local frame = CreateFrame("Frame", "HeimdallPartyFrame" .. i, UIParent)
-- frame:SetBackdrop({
-- bgFile = "Interface/Tooltips/UI-Tooltip-Background",
-- tileSize = 64,
-- tile = true
-- })
-- frame:SetBackdropColor(unpack(colors[i % #colors + 1]))
-- frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
-- HeimdallTestFrame:Add(frame, 4, 2)
--end
--HeimdallTestFrame:SetHeight(128)
--HeimdallTestFrame:SetWidth(512)
--configFrame:Add(HeimdallTestFrame, 20, 12)
---@diagnostic disable-next-line: missing-fields
shared.Config = {}
function shared.Config.Init()
@@ -322,9 +340,7 @@ function shared.Config.Init()
local editBox = CreateFrame("EditBox", name .. "EditBox", container.frame)
local editBoxtext = editBox:CreateFontString(nil, "OVERLAY", "GameFontNormal")
editBoxtext:SetText(text)
editBoxtext:SetPoint("TOPLEFT", container.frame, "TOPLEFT", 0, 0)
editBox:SetPoint("TOPLEFT", container.frame, "TOPLEFT", 0, -8)
editBox:SetAutoFocus(false)
editBox:SetFontObject("GameFontNormal")
editBox:SetText(Heimdall_Data.config.spotter.throttleTime)
@@ -352,35 +368,69 @@ function shared.Config.Init()
editBox:SetScript("OnEditFocusLost", function()
onDone(editBox:GetText())
end)
container:Add(editBoxtext, 1, 1)
container:Add(editBox, 2, 1)
-- I don't understand why this hack is necessary
-- Just put the god damn fucking text in the fucking frame
-- Why is the fucking text fucking levitating above the frame!?!?!
-- I'm so fucking tired of this shit
-- Why do we have to use "BOTTOMLEFT"!?
editBoxtext:SetPoint("BOTTOMLEFT", container.frame, "LEFT", 0, 0)
return container
end
--
local title = configFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
title:SetText("Heimdall Config")
configFrame:Add(title, 1, 12)
local spotterConfigFrame = GridFrame.new("HeimdallSpotterConfig",
configFrame.frame, 12, 20)
configFrame:Add(spotterConfigFrame.frame, 6, 3)
UIParent, 12, 20)
configFrame:Add(spotterConfigFrame, 6, 3)
local spotterTitle = spotterConfigFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
spotterTitle:SetText("Spotter")
spotterConfigFrame:Add(spotterTitle, 1, 12)
local spotterEnableButton = BasicButton("HeimdallSpotterConfigEnableButton",
spotterConfigFrame.frame, "Enable Spotter", function()
spotterConfigFrame.frame, "Enabled", function()
Heimdall_Data.config.spotter.enabled = not Heimdall_Data.config.spotter.enabled
return Heimdall_Data.config.spotter.enabled
end)
spotterConfigFrame:Add(spotterEnableButton, 1, 3)
spotterConfigFrame:Add(spotterEnableButton, 1, 5)
configFrame.frame:Hide()
-- local testEditBox = CreateBasicSmallEditBox("HeimdallSpotterConfigTestEditBox",
-- UIParent, "Test", function(text)
-- print(text)
-- end)
-- testEditBox:SetHeight(200)
-- spotterConfigFrame:Add(testEditBox.frame, 2, 6)
local spotterEveryoneButton = BasicButton("HeimdallSpotterConfigEveryoneButton",
spotterConfigFrame.frame, "Everyone", function()
Heimdall_Data.config.spotter.everyone = not Heimdall_Data.config.spotter.everyone
return Heimdall_Data.config.spotter.everyone
end)
spotterConfigFrame:Add(spotterEveryoneButton, 1, 6)
local spotterHostileButton = BasicButton("HeimdallSpotterConfigHostileButton",
spotterConfigFrame.frame, "Hostile", function()
Heimdall_Data.config.spotter.hostile = not Heimdall_Data.config.spotter.hostile
return Heimdall_Data.config.spotter.hostile
end)
spotterConfigFrame:Add(spotterHostileButton, 1, 4)
local spotterAllianceButton = BasicButton("HeimdallSpotterConfigAllianceButton",
spotterConfigFrame.frame, "Alliance", function()
Heimdall_Data.config.spotter.alliance = not Heimdall_Data.config.spotter.alliance
return Heimdall_Data.config.spotter.alliance
end)
spotterConfigFrame:Add(spotterAllianceButton, 1, 4)
local spotterStinkyButton = BasicButton("HeimdallSpotterConfigStinkyButton",
spotterConfigFrame.frame, "Stinky", function()
Heimdall_Data.config.spotter.stinky = not Heimdall_Data.config.spotter.stinky
return Heimdall_Data.config.spotter.stinky
end)
spotterConfigFrame:Add(spotterStinkyButton, 1, 4)
local testEditBox = CreateBasicSmallEditBox("HeimdallSpotterConfigTestEditBox",
spotterConfigFrame.frame, "Test", function(text)
print(text)
end)
spotterConfigFrame:Add(testEditBox, 2, 6)
--local spotterEveryoneButton = BasicButton("HeimdallSpotterEveryone", spotterConfigFrame, "Everyone", function(state)
-- Heimdall_Data.config.spotter.everyone = state