1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

207 lines
5.6 KiB
Lua
Raw Normal View History

local ui = require('openmw.ui')
local util = require('openmw.util')
2022-05-14 10:27:30 +00:00
local auxUi = require('openmw_aux.ui')
local constants = require('scripts.omw.mwui.constants')
local v2 = util.vector2
2022-05-19 19:49:14 +00:00
local whiteTexture = constants.whiteTexture
2022-05-14 10:27:30 +00:00
local menuTransparency = ui._getMenuTransparency()
local sideParts = {
2022-05-14 10:27:30 +00:00
left = v2(0, 0),
right = v2(1, 0),
top = v2(0, 0),
bottom = v2(0, 1),
}
local cornerParts = {
2022-05-14 10:27:30 +00:00
top_left = v2(0, 0),
top_right = v2(1, 0),
bottom_left = v2(0, 1),
bottom_right = v2(1, 1),
}
local borderSidePattern = 'textures/menu_%s_border_%s.dds'
local borderCornerPattern = 'textures/menu_%s_border_%s_corner.dds'
2022-05-14 10:27:30 +00:00
local borderResources = {}
local borderPieces = {}
for _, thickness in ipairs{'thin', 'thick'} do
borderResources[thickness] = {}
2022-05-14 10:27:30 +00:00
for k in pairs(sideParts) do
borderResources[thickness][k] = ui.texture{ path = borderSidePattern:format(thickness, k) }
end
2022-05-14 10:27:30 +00:00
for k in pairs(cornerParts) do
borderResources[thickness][k] = ui.texture{ path = borderCornerPattern:format(thickness, k) }
end
borderPieces[thickness] = {}
for k in pairs(sideParts) do
local horizontal = k == 'top' or k == 'bottom'
borderPieces[thickness][k] = {
type = ui.TYPE.Image,
props = {
resource = borderResources[thickness][k],
tileH = horizontal,
tileV = not horizontal,
},
}
end
for k in pairs(cornerParts) do
borderPieces[thickness][k] = {
type = ui.TYPE.Image,
props = {
resource = borderResources[thickness][k],
},
}
end
end
2022-05-14 10:27:30 +00:00
local function borderTemplates(thickness)
local borderSize = (thickness == 'thin') and constants.border or constants.thickBorder
2022-05-14 10:27:30 +00:00
local borderV = v2(1, 1) * borderSize
local result = {}
result.horizontalLine = {
type = ui.TYPE.Image,
props = {
resource = borderResources[thickness].top,
2022-05-14 10:27:30 +00:00
tileH = true,
tileV = false,
size = v2(0, borderSize),
relativeSize = v2(1, 0),
},
}
result.verticalLine = {
type = ui.TYPE.Image,
props = {
resource = borderResources[thickness].left,
2022-05-14 10:27:30 +00:00
tileH = false,
tileV = true,
size = v2(borderSize, 0),
relativeSize = v2(0, 1),
},
}
result.borders = {
content = ui.content {},
}
for k, v in pairs(sideParts) do
local horizontal = k == 'top' or k == 'bottom'
local direction = horizontal and v2(1, 0) or v2(0, 1)
result.borders.content:add {
template = borderPieces[thickness][k],
2022-05-14 10:27:30 +00:00
props = {
position = (direction - v) * borderSize,
relativePosition = v,
size = (v2(1, 1) - direction * 3) * borderSize,
relativeSize = direction,
}
}
end
for k, v in pairs(cornerParts) do
result.borders.content:add {
template = borderPieces[thickness][k],
props = {
2022-05-14 10:27:30 +00:00
position = -v * borderSize,
relativePosition = v,
size = borderV,
},
2022-05-14 10:27:30 +00:00
}
end
result.borders.content:add {
external = { slot = true },
props = {
position = borderV,
size = borderV * -2,
relativeSize = v2(1, 1),
}
}
2022-05-14 10:27:30 +00:00
result.box = {
type = ui.TYPE.Container,
content = ui.content{},
}
for k, v in pairs(sideParts) do
local horizontal = k == 'top' or k == 'bottom'
local direction = horizontal and v2(1, 0) or v2(0, 1)
result.box.content:add {
template = borderPieces[thickness][k],
props = {
2022-05-14 10:27:30 +00:00
position = (direction + v) * borderSize,
relativePosition = v,
size = (v2(1, 1) - direction) * borderSize,
relativeSize = direction,
}
}
end
for k, v in pairs(cornerParts) do
result.box.content:add {
template = borderPieces[thickness][k],
2022-05-14 10:27:30 +00:00
props = {
position = v * borderSize,
relativePosition = v,
size = borderV,
},
2022-05-14 10:27:30 +00:00
}
end
result.box.content:add {
external = { slot = true },
props = {
position = borderV,
relativeSize = v2(1, 1),
}
}
local backgroundTransparent = {
type = ui.TYPE.Image,
props = {
resource = whiteTexture,
color = util.color.rgb(0, 0, 0),
alpha = menuTransparency,
},
2022-05-14 10:27:30 +00:00
}
local backgroundSolid = {
type = ui.TYPE.Image,
props = {
resource = whiteTexture,
color = util.color.rgb(0, 0, 0),
},
}
result.boxTransparent = auxUi.deepLayoutCopy(result.box)
result.boxTransparent.content:insert(1, {
template = backgroundTransparent,
props = {
relativeSize = v2(1, 1),
size = borderV * 2,
},
})
result.boxSolid = auxUi.deepLayoutCopy(result.box)
result.boxSolid.content:insert(1, {
template = backgroundSolid,
props = {
relativeSize = v2(1, 1),
size = borderV * 2,
},
})
return result
end
local thinBorders = borderTemplates('thin')
local thickBorders = borderTemplates('thick')
return function(templates)
2022-05-14 10:27:30 +00:00
for k, t in pairs(thinBorders) do
templates[k] = t
end
for k, t in pairs(thickBorders) do
templates[k .. 'Thick'] = t
end
end