Implement static frame too
This commit is contained in:
@@ -97,16 +97,99 @@ GridFrame = {
|
|||||||
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
|
||||||
|
|
||||||
local configFrame = GridFrame.new("HeimdallConfig",
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
local configFrame = StaticGridFrame.new("HeimdallConfig",
|
||||||
UIParent,
|
UIParent,
|
||||||
12, 20,
|
40, 24,
|
||||||
{ w = 512, h = 512 + 256 })
|
{ w = 512, h = 512 + 256 })
|
||||||
|
|
||||||
local innerFrame = GridFrame.new("HeimdallConfigInner",
|
|
||||||
configFrame.frame, 6, 20)
|
|
||||||
|
|
||||||
configFrame:Add(innerFrame.frame, 6, 6)
|
|
||||||
local colors = {
|
local colors = {
|
||||||
{ 1, 0, 0, 1 },
|
{ 1, 0, 0, 1 },
|
||||||
{ 0, 1, 0, 1 },
|
{ 0, 1, 0, 1 },
|
||||||
@@ -125,7 +208,7 @@ for i = 1, 20 do
|
|||||||
})
|
})
|
||||||
frame:SetBackdropColor(unpack(colors[i % #colors + 1]))
|
frame:SetBackdropColor(unpack(colors[i % #colors + 1]))
|
||||||
frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
|
||||||
innerFrame:Add(frame, 4, 2)
|
configFrame:Add(frame, 4, 2)
|
||||||
end
|
end
|
||||||
---@diagnostic disable-next-line: missing-fields
|
---@diagnostic disable-next-line: missing-fields
|
||||||
shared.Config = {}
|
shared.Config = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user