Add some basic config buttons for spotter
This commit is contained in:
@@ -2,13 +2,12 @@ local addonname, shared = ...
|
|||||||
---@cast shared HeimdallShared
|
---@cast shared HeimdallShared
|
||||||
---@cast addonname string
|
---@cast addonname string
|
||||||
|
|
||||||
---@class GridFrame
|
---@class GridFrame:Frame
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field columns number
|
---@field columns number
|
||||||
---@field frame Frame
|
---@field frame Frame
|
||||||
---@field cellWidth number
|
---@field cellWidth number
|
||||||
---@field cellHeight number
|
---@field cellHeight number
|
||||||
---@field allowOverflow boolean
|
|
||||||
---@field columnHeights table<number, number>
|
---@field columnHeights table<number, number>
|
||||||
GridFrame = {
|
GridFrame = {
|
||||||
---@param name string
|
---@param name string
|
||||||
@@ -65,13 +64,6 @@ GridFrame = {
|
|||||||
end
|
end
|
||||||
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
|
if bestColumn then
|
||||||
frame:SetParent(self.frame)
|
frame:SetParent(self.frame)
|
||||||
frame.gridData = {
|
frame.gridData = {
|
||||||
@@ -101,7 +93,13 @@ GridFrame = {
|
|||||||
end,
|
end,
|
||||||
Recalculate = function(self)
|
Recalculate = function(self)
|
||||||
local children = { self.frame:GetChildren() }
|
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,
|
end,
|
||||||
SetWidth = function(self, width)
|
SetWidth = function(self, width)
|
||||||
self.frame:SetWidth(width)
|
self.frame:SetWidth(width)
|
||||||
@@ -114,7 +112,17 @@ GridFrame = {
|
|||||||
for _, height in pairs(self.columnHeights) do
|
for _, height in pairs(self.columnHeights) do
|
||||||
tallestRow = math.max(tallestRow, height)
|
tallestRow = math.max(tallestRow, height)
|
||||||
end
|
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()
|
self:Recalculate()
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@@ -189,7 +197,9 @@ StaticGridFrame = {
|
|||||||
local y = -(row - 1) * self.cellHeight
|
local y = -(row - 1) * self.cellHeight
|
||||||
frame.colspan = colspan
|
frame.colspan = colspan
|
||||||
frame.rowspan = rowspan
|
frame.rowspan = rowspan
|
||||||
|
print("Setting width", self.cellWidth * colspan)
|
||||||
frame:SetWidth(self.cellWidth * colspan)
|
frame:SetWidth(self.cellWidth * colspan)
|
||||||
|
print("Setting height", self.cellHeight * rowspan)
|
||||||
frame:SetHeight(self.cellHeight * rowspan)
|
frame:SetHeight(self.cellHeight * rowspan)
|
||||||
frame:SetPoint("TOPLEFT", self.frame, "TOPLEFT", x, y)
|
frame:SetPoint("TOPLEFT", self.frame, "TOPLEFT", x, y)
|
||||||
frame:SetParent(self.frame)
|
frame:SetParent(self.frame)
|
||||||
@@ -228,17 +238,22 @@ StaticGridFrame = {
|
|||||||
end,
|
end,
|
||||||
SetWidth = function(self, width)
|
SetWidth = function(self, width)
|
||||||
self.frame:SetWidth(width)
|
self.frame:SetWidth(width)
|
||||||
self.cellWidth = self.frame:GetWidth() / self.columns
|
self.cellWidth = width / self.columns
|
||||||
self:Recalculate()
|
self:Recalculate()
|
||||||
end,
|
end,
|
||||||
SetHeight = function(self, height)
|
SetHeight = function(self, height)
|
||||||
self.frame:SetHeight(height)
|
self.frame:SetHeight(height)
|
||||||
print("Setting height", height)
|
self.cellHeight = height / self.rows
|
||||||
self.cellHeight = self.frame:GetHeight() / self.rows
|
self:Recalculate()
|
||||||
print("Cell height", self.cellHeight)
|
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()
|
self:Recalculate()
|
||||||
end
|
end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local configFrame = StaticGridFrame.new("HeimdallConfig",
|
local configFrame = StaticGridFrame.new("HeimdallConfig",
|
||||||
@@ -252,7 +267,7 @@ configFrame:MakeMovable()
|
|||||||
-- end
|
-- end
|
||||||
--end)
|
--end)
|
||||||
|
|
||||||
local colors = {
|
local colors = {
|
||||||
{ 1, 0, 0, 1 },
|
{ 1, 0, 0, 1 },
|
||||||
{ 0, 1, 0, 1 },
|
{ 0, 1, 0, 1 },
|
||||||
{ 0, 0, 1, 1 },
|
{ 0, 0, 1, 1 },
|
||||||
@@ -261,20 +276,23 @@ local colors = {
|
|||||||
{ 0, 1, 1, 1 },
|
{ 0, 1, 1, 1 },
|
||||||
{ 1, 1, 1, 1 },
|
{ 1, 1, 1, 1 },
|
||||||
}
|
}
|
||||||
HeimdallTestFrame = GridFrame.new("HeimdallPartyFrame", UIParent, 12, 20, { w = 1024, h = 1024 })
|
|
||||||
for i = 1, 10 do
|
--HeimdallTestFrame = GridFrame.new("HeimdallPartyFrame", UIParent, 12, 20, { w = 1024, h = 1024 })
|
||||||
local frame = CreateFrame("Frame", "HeimdallPartyFrame" .. i, UIParent)
|
--for i = 1, 10 do
|
||||||
frame:SetBackdrop({
|
-- local frame = CreateFrame("Frame", "HeimdallPartyFrame" .. i, UIParent)
|
||||||
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
-- frame:SetBackdrop({
|
||||||
tileSize = 64,
|
-- bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
||||||
tile = true
|
-- tileSize = 64,
|
||||||
})
|
-- tile = true
|
||||||
frame:SetBackdropColor(unpack(colors[i % #colors + 1]))
|
-- })
|
||||||
frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
-- frame:SetBackdropColor(unpack(colors[i % #colors + 1]))
|
||||||
HeimdallTestFrame:Add(frame, 4, 2)
|
-- frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
||||||
end
|
-- HeimdallTestFrame:Add(frame, 4, 2)
|
||||||
HeimdallTestFrame:SetHeight(128)
|
--end
|
||||||
HeimdallTestFrame:SetWidth(512)
|
--HeimdallTestFrame:SetHeight(128)
|
||||||
|
--HeimdallTestFrame:SetWidth(512)
|
||||||
|
--configFrame:Add(HeimdallTestFrame, 20, 12)
|
||||||
|
|
||||||
---@diagnostic disable-next-line: missing-fields
|
---@diagnostic disable-next-line: missing-fields
|
||||||
shared.Config = {}
|
shared.Config = {}
|
||||||
function shared.Config.Init()
|
function shared.Config.Init()
|
||||||
@@ -322,9 +340,7 @@ function shared.Config.Init()
|
|||||||
local editBox = CreateFrame("EditBox", name .. "EditBox", container.frame)
|
local editBox = CreateFrame("EditBox", name .. "EditBox", container.frame)
|
||||||
local editBoxtext = editBox:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
local editBoxtext = editBox:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||||
editBoxtext:SetText(text)
|
editBoxtext:SetText(text)
|
||||||
editBoxtext:SetPoint("TOPLEFT", container.frame, "TOPLEFT", 0, 0)
|
|
||||||
|
|
||||||
editBox:SetPoint("TOPLEFT", container.frame, "TOPLEFT", 0, -8)
|
|
||||||
editBox:SetAutoFocus(false)
|
editBox:SetAutoFocus(false)
|
||||||
editBox:SetFontObject("GameFontNormal")
|
editBox:SetFontObject("GameFontNormal")
|
||||||
editBox:SetText(Heimdall_Data.config.spotter.throttleTime)
|
editBox:SetText(Heimdall_Data.config.spotter.throttleTime)
|
||||||
@@ -352,35 +368,69 @@ function shared.Config.Init()
|
|||||||
editBox:SetScript("OnEditFocusLost", function()
|
editBox:SetScript("OnEditFocusLost", function()
|
||||||
onDone(editBox:GetText())
|
onDone(editBox:GetText())
|
||||||
end)
|
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
|
return container
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
|
||||||
local title = configFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
|
local title = configFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
|
||||||
title:SetText("Heimdall Config")
|
title:SetText("Heimdall Config")
|
||||||
configFrame:Add(title, 1, 12)
|
configFrame:Add(title, 1, 12)
|
||||||
|
|
||||||
local spotterConfigFrame = GridFrame.new("HeimdallSpotterConfig",
|
local spotterConfigFrame = GridFrame.new("HeimdallSpotterConfig",
|
||||||
configFrame.frame, 12, 20)
|
UIParent, 12, 20)
|
||||||
configFrame:Add(spotterConfigFrame.frame, 6, 3)
|
configFrame:Add(spotterConfigFrame, 6, 3)
|
||||||
|
|
||||||
local spotterTitle = spotterConfigFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
|
local spotterTitle = spotterConfigFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
|
||||||
spotterTitle:SetText("Spotter")
|
spotterTitle:SetText("Spotter")
|
||||||
spotterConfigFrame:Add(spotterTitle, 1, 12)
|
spotterConfigFrame:Add(spotterTitle, 1, 12)
|
||||||
|
|
||||||
local spotterEnableButton = BasicButton("HeimdallSpotterConfigEnableButton",
|
local spotterEnableButton = BasicButton("HeimdallSpotterConfigEnableButton",
|
||||||
spotterConfigFrame.frame, "Enable Spotter", function()
|
spotterConfigFrame.frame, "Enabled", function()
|
||||||
Heimdall_Data.config.spotter.enabled = not Heimdall_Data.config.spotter.enabled
|
Heimdall_Data.config.spotter.enabled = not Heimdall_Data.config.spotter.enabled
|
||||||
return Heimdall_Data.config.spotter.enabled
|
return Heimdall_Data.config.spotter.enabled
|
||||||
end)
|
end)
|
||||||
spotterConfigFrame:Add(spotterEnableButton, 1, 3)
|
spotterConfigFrame:Add(spotterEnableButton, 1, 5)
|
||||||
|
|
||||||
configFrame.frame:Hide()
|
local spotterEveryoneButton = BasicButton("HeimdallSpotterConfigEveryoneButton",
|
||||||
-- local testEditBox = CreateBasicSmallEditBox("HeimdallSpotterConfigTestEditBox",
|
spotterConfigFrame.frame, "Everyone", function()
|
||||||
-- UIParent, "Test", function(text)
|
Heimdall_Data.config.spotter.everyone = not Heimdall_Data.config.spotter.everyone
|
||||||
-- print(text)
|
return Heimdall_Data.config.spotter.everyone
|
||||||
-- end)
|
end)
|
||||||
-- testEditBox:SetHeight(200)
|
spotterConfigFrame:Add(spotterEveryoneButton, 1, 6)
|
||||||
-- spotterConfigFrame:Add(testEditBox.frame, 2, 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)
|
--local spotterEveryoneButton = BasicButton("HeimdallSpotterEveryone", spotterConfigFrame, "Everyone", function(state)
|
||||||
-- Heimdall_Data.config.spotter.everyone = state
|
-- Heimdall_Data.config.spotter.everyone = state
|
||||||
|
|||||||
Reference in New Issue
Block a user