A rough example (WIP) of creating a dialog using the DSL:
Code: Select all
Design
'@dlgContent' [[
label #msg 'dlg-label'
]]
'@dlgButtons' [[
button #cancel 'dlg-button-cancel' .btn-cancel
button #confirm 'dlg-button-ok' .btn-confirm
]]
-- ↑ ↑ ↑ ↑
-- type name caption style
local dlg = Dialog 'Hello World' '@dlgContent' '@dlgButtons'
dlg.on('close', function(eventName,eventData) {
game.player.print eventData.button.caption -- localised caption of button clicked
}
dlg.show() -- defaults to local player (player 1)
Using this approach, it's possible to create 'custom' components, essentially re-usable UI patterns that mods can incorporate in to their own UI.
I also plan on adding DSLs for defining prototypes in a much simpler, more maintainable manner.
If it's not possible to get LPeg bundled, I can fall back to LulPeg which is written entirely in Lua, but obviously a bit slower than LPeg. Both libraries have identical API, I'm doing my initial dev in LulPeg. There are some weird errors in LulPeg, so if possible I'd really *really* prefer to use the proper LPeg library.
Code: Select all
local success, lpeg = pcall(require, "lpeg")
lpeg = success and lpeg or require "lulpeg":register(not _ENV and _G)