405 lines
15 KiB
Lua
405 lines
15 KiB
Lua
local addonname, shared = ...
|
|
---@cast shared HeimdallShared
|
|
---@cast addonname string
|
|
|
|
---@class GridFrame
|
|
---@field name string
|
|
---@field columns number
|
|
---@field frame Frame
|
|
---@field cellWidth number
|
|
---@field cellHeight number
|
|
---@field allowOverflow boolean
|
|
---@field columnCursors table<number, number>
|
|
GridFrame = {
|
|
---@param name string
|
|
---@param parent Frame
|
|
---@param columns number
|
|
---@param cellHeight number
|
|
---@param size {w: number, h:number}?
|
|
---@return GridFrame
|
|
new = function(name, parent, columns, cellHeight, size)
|
|
local self = setmetatable({}, {
|
|
__index = GridFrame
|
|
})
|
|
self.frame = CreateFrame("Frame", name, parent)
|
|
size = size or {}
|
|
if size.w then self.frame:SetWidth(size.w) end
|
|
if size.h then self.frame:SetHeight(size.h) end
|
|
self.allowOverflow = false
|
|
self.frame:SetPoint("CENTER", UIParent, "CENTER")
|
|
self.frame:SetBackdrop({
|
|
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
|
tileSize = 64,
|
|
tile = true
|
|
})
|
|
self.frame:SetBackdropColor(0, 0, 0, 0.8)
|
|
self.frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
|
|
|
self.columns = columns
|
|
self.cellWidth = self.frame:GetWidth() / columns
|
|
self.cellHeight = cellHeight
|
|
self.columnCursors = {}
|
|
for i = 1, columns do
|
|
self.columnCursors[i] = 0
|
|
end
|
|
|
|
local previousSetWidth = self.frame.SetWidth
|
|
self.frame.SetWidth = function(frame, width)
|
|
if not width then return end
|
|
previousSetWidth(frame, width)
|
|
self.cellWidth = self.frame:GetWidth() / self.columns
|
|
end
|
|
|
|
return self
|
|
end,
|
|
---@param self GridFrame
|
|
---@param frame Frame
|
|
---@param rowspan number
|
|
---@param colspan number
|
|
Add = function(self, frame, rowspan, colspan)
|
|
colspan = math.min(colspan, self.columns)
|
|
|
|
local bestStartColumn = nil
|
|
local bestMaxY = math.huge
|
|
|
|
for startColumn = 1, self.columns - colspan + 1 do
|
|
local currentMaxY = 0
|
|
for c = startColumn, startColumn + colspan - 1 do
|
|
currentMaxY = math.max(currentMaxY, self.columnCursors[c])
|
|
end
|
|
if currentMaxY < bestMaxY then
|
|
bestMaxY = currentMaxY
|
|
bestStartColumn = startColumn
|
|
end
|
|
end
|
|
|
|
if not self.allowOverflow then
|
|
if bestMaxY + self.cellHeight * rowspan > self.frame:GetHeight() then
|
|
print("Frame is too tall")
|
|
return
|
|
end
|
|
end
|
|
|
|
if bestStartColumn then
|
|
local x = (bestStartColumn - 1) * self.cellWidth
|
|
local y = -bestMaxY
|
|
print("Adding frame to grid", x, y, self.cellWidth * colspan, self.cellHeight * rowspan)
|
|
frame:SetWidth(self.cellWidth * colspan)
|
|
frame:SetHeight(self.cellHeight * rowspan)
|
|
frame:SetPoint("TOPLEFT", self.frame, "TOPLEFT", x, y)
|
|
|
|
for c = bestStartColumn, bestStartColumn + colspan - 1 do
|
|
self.columnCursors[c] = self.columnCursors[c] + self.cellHeight * rowspan
|
|
end
|
|
else
|
|
print("No available space in the grid.")
|
|
end
|
|
end
|
|
}
|
|
|
|
---@class StaticGridFrame
|
|
---@field name string
|
|
---@field rows number
|
|
---@field columns number
|
|
---@field frame Frame
|
|
---@field cellWidth number
|
|
---@field cellHeight number
|
|
---@field occupancy table<number, table<number, boolean>>
|
|
StaticGridFrame = {
|
|
---@param name string
|
|
---@param parent Frame
|
|
---@param rows number
|
|
---@param columns number
|
|
---@param size {w: number, h:number}?
|
|
---@return StaticGridFrame
|
|
new = function(name, parent, rows, columns, size)
|
|
local self = setmetatable({}, {
|
|
__index = StaticGridFrame
|
|
})
|
|
size = size or {}
|
|
self.frame = CreateFrame("Frame", name, parent)
|
|
self.frame:SetWidth(columns * 128)
|
|
self.frame:SetHeight(rows * 128)
|
|
self.frame:SetPoint("CENTER", UIParent, "CENTER")
|
|
self.frame:SetBackdrop({
|
|
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
|
tileSize = 64,
|
|
tile = true
|
|
})
|
|
self.frame:SetBackdropColor(0, 0, 0, 0.8)
|
|
self.frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
|
if size.w then self.frame:SetWidth(size.w) end
|
|
if size.h then self.frame:SetHeight(size.h) end
|
|
|
|
self.rows = rows
|
|
self.columns = columns
|
|
self.cellWidth = self.frame:GetWidth() / columns
|
|
self.cellHeight = self.frame:GetHeight() / rows
|
|
self.occupancy = {}
|
|
for row = 1, rows do
|
|
self.occupancy[row] = {}
|
|
for column = 1, columns do
|
|
self.occupancy[row][column] = false
|
|
end
|
|
end
|
|
return self
|
|
end,
|
|
---@param self StaticGridFrame
|
|
---@param frame Frame
|
|
---@param rowspan number
|
|
---@param colspan number
|
|
Add = function(self, frame, rowspan, colspan)
|
|
for row = 1, self.rows do
|
|
for col = 1, self.columns do
|
|
if not self.occupancy[row][col] then
|
|
local canPlace = true
|
|
for r = row, row + rowspan - 1 do
|
|
for c = col, col + colspan - 1 do
|
|
if not self.occupancy[r] or self.occupancy[r][c] then
|
|
canPlace = false
|
|
break
|
|
end
|
|
if not canPlace then break end
|
|
end
|
|
end
|
|
if canPlace then
|
|
local x = (col - 1) * self.cellWidth
|
|
local y = -(row - 1) * self.cellHeight
|
|
print(string.format("frame:SetWidth(%d)", self.cellWidth * colspan))
|
|
print(string.format("frame:SetHeight(%d)", self.cellHeight * rowspan))
|
|
frame:SetWidth(self.cellWidth * colspan)
|
|
frame:SetHeight(self.cellHeight * rowspan)
|
|
frame:SetPoint("TOPLEFT", self.frame, "TOPLEFT", x, y)
|
|
frame:SetParent(self.frame)
|
|
for r = row, row + rowspan - 1 do
|
|
for c = col, col + colspan - 1 do
|
|
self.occupancy[r][c] = true
|
|
end
|
|
end
|
|
return
|
|
end
|
|
end
|
|
end
|
|
end
|
|
print("No available space in the grid.")
|
|
end,
|
|
MakeMovable = function(self)
|
|
self.frame:SetMovable(true)
|
|
self.frame:EnableMouse(true)
|
|
self.frame:RegisterForDrag("LeftButton")
|
|
self.frame:SetScript("OnDragStart", function(self)
|
|
self:StartMoving()
|
|
end)
|
|
self.frame:SetScript("OnDragStop", function(self)
|
|
self:StopMovingOrSizing()
|
|
end)
|
|
end
|
|
}
|
|
|
|
local configFrame = StaticGridFrame.new("HeimdallConfig",
|
|
UIParent,
|
|
40, 12,
|
|
{ w = 1024+512, h = 1024 })
|
|
configFrame:MakeMovable()
|
|
|
|
local colors = {
|
|
{ 1, 0, 0, 1 },
|
|
{ 0, 1, 0, 1 },
|
|
{ 0, 0, 1, 1 },
|
|
{ 1, 1, 0, 1 },
|
|
{ 1, 0, 1, 1 },
|
|
{ 0, 1, 1, 1 },
|
|
{ 1, 1, 1, 1 },
|
|
}
|
|
for i = 1, 200 do
|
|
local frame = CreateFrame("Frame", "HeimdallConfigFrame" .. 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)
|
|
configFrame:Add(frame, 4, 2)
|
|
end
|
|
---@diagnostic disable-next-line: missing-fields
|
|
shared.Config = {}
|
|
function shared.Config.Init()
|
|
---@param name string
|
|
---@param parent Frame
|
|
---@param text string
|
|
---@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", function()
|
|
onClick(button:GetChecked())
|
|
end)
|
|
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
|
|
|
|
--
|
|
-- 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, { w: 0,h: 0 })
|
|
-- configFrame:Add(spotterConfigFrame.frame, 12, 6)
|
|
-- spotterConfigFrame.frame:SetBackdrop({
|
|
-- bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
|
-- edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
|
|
-- tile = true,
|
|
-- tileSize = 4,
|
|
-- edgeSize = 4,
|
|
-- insets = {
|
|
-- left = 4,
|
|
-- right = 4,
|
|
-- top = 4,
|
|
-- bottom = 4
|
|
-- }
|
|
-- })
|
|
-- spotterConfigFrame.frame:SetBackdropColor(1, 0, 0, 0.8)
|
|
-- spotterConfigFrame.frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
|
-- spotterConfigFrame:Show()
|
|
|
|
--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(state)
|
|
-- Heimdall_Data.config.spotter.everyone = state
|
|
--end)
|
|
--spotterEveryoneButton:PutRight(spotterEnableButton)
|
|
--spotterEveryoneButton:SetChecked(Heimdall_Data.config.spotter.everyone)
|
|
|
|
--local spotterHostileButton = BasicButton("HeimdallSpotterHostile", spotterConfigFrame, "Hostile", function(state)
|
|
-- Heimdall_Data.config.spotter.hostile = state
|
|
--end)
|
|
--spotterHostileButton:PutBelow(spotterEnableButton)
|
|
--spotterHostileButton:SetChecked(Heimdall_Data.config.spotter.hostile)
|
|
|
|
--local spotterAllianceButton = BasicButton("HeimdallSpotterAlliance", spotterConfigFrame, "Alliance", function(state)
|
|
-- Heimdall_Data.config.spotter.alliance = state
|
|
--end)
|
|
--spotterAllianceButton:PutRight(spotterHostileButton)
|
|
--spotterAllianceButton:SetChecked(Heimdall_Data.config.spotter.alliance)
|
|
|
|
--local spotterStinkyButton = BasicButton("HeimdallSpotterStinky", spotterConfigFrame, "Stinky", function(state)
|
|
-- Heimdall_Data.config.spotter.stinky = state
|
|
--end)
|
|
--spotterStinkyButton:PutBelow(spotterHostileButton)
|
|
--spotterStinkyButton:SetChecked(Heimdall_Data.config.spotter.stinky)
|
|
|
|
--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")
|
|
-- spotterEnableButton:SetSize(100, 30)
|
|
-- spotterEnableButton:SetPoint("TOPLEFT", configFrame, "TOPLEFT", 10, -40)
|
|
-- spotterEnableButton:SetScript("OnClick", function()
|
|
-- print("Button was clicked!")
|
|
-- end)
|
|
--
|
|
-- -- Create a text element
|
|
-- local text = configFrame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
|
|
-- text:SetText("This is some text in the frame.")
|
|
-- text:SetPoint("TOPLEFT", configFrame, "TOPLEFT", 10, -80)
|
|
--
|
|
-- -- Create a small edit box
|
|
-- local smallEditBox = CreateFrame("EditBox", nil, configFrame)
|
|
-- smallEditBox:SetSize(200, 20)
|
|
-- smallEditBox:SetPoint("TOPLEFT", configFrame, "TOPLEFT", 10, -110)
|
|
-- smallEditBox:SetAutoFocus(false)
|
|
-- smallEditBox:SetFontObject("GameFontNormal")
|
|
-- smallEditBox:SetScript("OnEnterPressed", function()
|
|
-- print("Entered text: " .. smallEditBox:GetText())
|
|
-- end)
|
|
--
|
|
-- -- Create a large edit box
|
|
-- local largeEditBox = CreateFrame("EditBox", nil, configFrame)
|
|
-- largeEditBox:SetSize(280, 100)
|
|
-- largeEditBox:SetPoint("TOP", configFrame, "TOP", 0, -150)
|
|
-- largeEditBox:SetAutoFocus(false)
|
|
-- largeEditBox:SetFontObject("GameFontNormal")
|
|
-- largeEditBox:SetMultiLine(true)
|
|
-- largeEditBox:EnableMouse(true)
|
|
-- largeEditBox:SetMaxLetters(0)
|
|
-- largeEditBox:SetScript("OnEscapePressed", function()
|
|
-- largeEditBox:ClearFocus()
|
|
-- end)
|
|
|
|
--configFrame:Hide()
|
|
print("Heimdall - Config loaded")
|
|
end
|
|
|
|
SlashCmdList["HEIMDALL_CONFIG"] = function()
|
|
configFrame:Show()
|
|
end
|
|
SLASH_HEIMDALL_CONFIG1 = "/heimdall_config"
|
|
SLASH_HEIMDALL_CONFIG2 = "/hc"
|