Support atlasing UI textures for Lua API
MyGUI supports atlasing, so implementation is fairly trivial, but we need to decide on the API.
I believe there are these key goals:
- it should be possible to atlas UI that's initially designed with loose textures, without editing the UI layouts themselves. This will be particularly helpful with atlasing vanilla UI
- it should be possible to define UI with atlas syntax, but use loose files in development, to make it easy to switch to an actual atlas later
Proposed API snippet:
local ui = require('openmw.ui')
local v2 = require('openmw.util').vector2
local myAtlas = ui.atlas{
path = 'path/to/atlas.dds',
tiles = {
borderLeft = { -- name of the tile, used to refer to it later
offset = v2(10, 15), -- position of the top left corner in the atlas
size = v2(50, 50), -- size of the tile in pixels
-- used only during script development, is expected to be replaced when the atlas is finalized
path = 'fallback/non/atlased/texture.dds', -- use this texture instead of part of the atlas
},
-- ...
},
}
local atlasedImageLayout = {
type = ui.TYPE.Image,
props = {
atlasTile = myAtlas.borderLeft,
},
}
-- some "legacy" layout definition, potentially in another script / mod
local normalImageLayout = {
type = ui.TYPE.Image,
props = {
path = 'old/border/texture.dds',
},
}
-- replaces all uses of 'old/border/texture.dds' path with the atlas tile, globally
ui.atlasOverride('old/border/texture.dds', myAtlas.borderLeft)