Module:UI
Documentation for this module may be created at Module:UI/doc
local slot = require( [[Module:Inventory slot]] ).slot
local addSlot = function( args, item, prefix, class, default )
prefix = prefix or item
return slot{
args[item], mod = args.Mod, link = args[prefix .. 'link'],
title = args[prefix .. 'title'], class = class, default = default,
parsed = args.parsed
}
end
local p = {}
-- Crafting table
function p.craftingTable( f )
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
end
local arrow = 'Arrow (small)'
local shapeless = ''
if args.arrow or '' ~= '' then
arrow = args.arrow .. ' (' .. args.Mod .. ')'
end
if args.shapeless or '' ~= '' then
shapeless = '<span title="This recipe is shapeless; the inputs may be placed in any arrangement in the crafting grid.">[[File:Grid layout Shapeless.png|link=]]</span>'
elseif args.fixed or '' ~= '' then
local notFixed = ''
if args.notfixed or '' ~= '' then
notFixed = '; except for ' .. args.notfixed .. ', which can go anywhere'
end
shapeless = '<span title="This recipe is fixed, the input arrangement may not be moved or mirrored' .. notFixed .. '.">[[File:Grid layout Fixed.png|link=]]</span>'
end
local html = {
'{| class="grid-Crafting_Table" cellpadding="0" cellspacing="0"',
'| ' .. p.cell{ args.A1, mod = args.Mod, link = args.A1link, title = args.A1title },
'| ' .. p.cell{ args.B1, mod = args.Mod, link = args.B1link, title = args.B1title },
'| ' .. p.cell{ args.C1, mod = args.Mod, link = args.C1link, title = args.C1title },
'| rowspan="2" class="arrow" | [[File:Grid layout ' .. arrow .. '.png|link=]]',
'| rowspan="3" | ' .. p.cell{ args.Output, mod = args.Mod, link = args.Olink, title = args.Otitle, class = 'output' },
'|-',
'| ' .. p.cell{ args.A2, mod = args.Mod, link = args.A2link, title = args.A2title },
'| ' .. p.cell{ args.B2, mod = args.Mod, link = args.B2link, title = args.B2title },
'| ' .. p.cell{ args.C2, mod = args.Mod, link = args.C2link, title = args.C2title },
'|-',
'| ' .. p.cell{ args.A3, mod = args.Mod, link = args.A3link, title = args.A3title },
'| ' .. p.cell{ args.B3, mod = args.Mod, link = args.B3link, title = args.B3title },
'| ' .. p.cell{ args.C3, mod = args.Mod, link = args.C3link, title = args.C3title },
'| class="shapeless" | ' .. shapeless,
'|}'
}
return table.concat( html, '\n' );
end
function craftingTable( f )
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local body = mw.html.create( 'span' ):addClass( 'mcui mcui-Crafting_Table' )
local input = body:tag( 'span' ):addClass( 'mcui-input' )
for num = 1, 3 do
local row = input:tag( 'span' ):addClass( 'mcui-row' )
for _, letter in ipairs{ 'A', 'B', 'C' } do
row:wikitext( addSlot( args, letter .. num ) )
end
end
local arrow = body:tag( 'span' ):addClass( 'mcui-arrow' ):tag( 'br' ):done()
if args.arrow or '' ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. args.arrow .. ' (' .. args.Mod .. ').png}}'
)
end
body
:tag( 'span' )
:addClass( 'mcui-output' )
:wikitext( addSlot( args, 'Output', 'O', 'invslot-large' ) )
local shapeless = args.shapeless or ''
local fixed = args.fixed or ''
if shapeless ~= '' or fixed ~= '' then
local icon = body:tag( 'span' )
:addClass( 'mcui-icons' )
:tag( 'span' )
:tag( 'br' )
:done()
if shapeless ~= '' then
icon:addClass( 'mcui-shapeless' )
:attr( 'title',
'This recipe is shapeless, the inputs may be placed in any arrangement in the crafting grid.'
)
elseif fixed ~= '' then
local notFixed = args.notfixed or ''
local exceptFixed = ''
if notFixed ~= '' then
exceptFixed = '; except for ' .. notFixed .. ', which can go anywhere'
end
icon:addClass( 'mcui-fixed' )
:attr( 'title',
'This recipe is fixed, the input arrangement may not be moved or mirrored in the crafting grid' .. exceptFixed .. '.'
)
end
end
return tostring( mw.html.create( 'div' ):node( body ) )
end
-- Furnace
function p.furnace( f )
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local body = mw.html.create( 'span' ):addClass( 'mcui mcui-Furnace' )
local input = body:tag( 'span' ):addClass( 'mcui-input' )
input:wikitext( addSlot( args, 'Input', 'I' ) )
local fuel = input:tag( 'span' ):addClass( 'mcui-fuel' ):tag( 'br' ):done()
local fuelImg = args.FuelUsage or ''
local burning = args.Input or '' ~= '' and args.Fuel or '' ~= ''
if not burning then
fuel:addClass( 'mcui-inactive' )
if fuelImg ~= '' then
fuelImg = fuelImg .. ' (in-active)'
end
end
if fuelImg ~= '' then
fuel:css(
'background-image',
'{{FileUrl|' .. fuelImg .. ' (' .. args.Mod .. ').png}}'
)
end
input:wikitext( addSlot( args, 'Fuel', 'F' ) )
local arrow = body:tag( 'span' ):addClass( 'mcui-arrow' ):tag( 'br' ):done()
local arrowImg = args.Progress or ''
if not burning or ( args.Output or '' ) == '' then
arrow:addClass( 'mcui-inactive' )
if arrowImg ~= '' then
arrowImg = arrowImg .. ' (in-active)'
end
end
if arrowImg ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. arrowImg .. ' Progress (' .. args.Mod .. ').png}}'
)
end
body
:tag( 'span' )
:addClass( 'mcui-output' )
:wikitext( addSlot( args, 'Output', 'O', 'invslot-large' ) )
return tostring( mw.html.create( 'div' ):node( body ) )
end
-- Brewing Stand
function p.brewingStand( f )
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local body = mw.html.create( 'span' ):addClass( 'mcui mcui-Brewing_Stand' )
local input = body:tag( 'span' ):addClass( 'mcui-input' )
input:tag( 'span' ):addClass( 'mcui-bubbling' ):tag( 'br' )
input:wikitext( addSlot( args, 'Input', 'I' ) )
input:tag( 'span' ):addClass( 'mcui-arrow' ):tag( 'br' )
if ( args.Input or '' ) == '' or
( ( args.Output1 or '' ) == '' and ( args.Output2 or '' ) == '' and ( args.Output3 or '' ) == '' )
then
input:addClass( 'mcui-inactive' )
end
body:tag( 'span' ):addClass( 'mcui-paths' ):tag( 'br' )
local output = body:tag( 'span' ):addClass( 'mcui-output' )
for i = 1, 3 do
output:wikitext( addSlot( args, 'Output' .. i, 'O' .. i, 'mcui-output' .. i ) )
end
return tostring( mw.html.create( 'div' ):node( body ) )
end
return p