Цей модуль реалізує загальні шаблони інтерфейсу користувача, щоб уникнути накладних витрат через надмірні виклики #invoke.
Залежності[]
Див. також[]
{{Верстак}}
{{Інвентарне майстрування}}
{{Піч}}
{{Варильна стійка}}
{{Каменеріз}}
{{Ткацький верстат}}
{{Точило}}
{{Панель швидкого доступу}}
{{Інвентар}}
{{Інвентарний слот}}
- Модуль:UI
local slot = require( [[Модуль:Інвентарний слот]] ).slot
local addSlot = function( args, item, prefix, class, default )
local none, nostacksize
prefix = prefix or ''
if #prefix == 0 then
none = 'none'
nostacksize = ((item == '' or nil) and '') or (args and args[item] and args[item]:gsub( '[,%d]', '' ) or '')
end
return slot{
nostacksize or args[item], mod = args["Мод"], ['посилання'] = none or args[prefix .. 'link'],
['назва'] = none or args[prefix .. 'title'], ['клас'] = class, ['замовчування'] = default,
parsed = args.parsed
}
end
function experience_image(exp_value)
local MINMAX = {
{-32768, 2},
{3, 6},
{7, 16},
{17, 36},
{37, 72},
{73, 148},
{149, 306},
{307, 616},
{617, 1236},
{1237, 2476},
{2477, 32767}
}
local EXP_IMGS = {
"Experience Orb Value -32768-2.png",
"Experience Orb Value 3-6.png",
"Experience Orb Value 7-16.png",
"Experience Orb Value 17-36.png",
"Experience Orb Value 37-72.png",
"Experience Orb Value 73-148.png",
"Experience Orb Value 149-306.png",
"Experience Orb Value 307-616.png",
"Experience Orb Value 617-1236.png",
"Experience Orb Value 1237-2476.png",
"Experience Orb Value 2477-32767.png",
}
local n = assert( tonumber(exp_value), "Модуль:UI: Значення досвіду не є числом (" .. exp_value .. ")" )
local idx = 2; exp = tonumber( exp_value )
if exp <= MINMAX[#MINMAX][2] then
for i = 1, #MINMAX do
if MINMAX[i][1] < exp and MINMAX[i][2] >= exp then
idx = i
break
end
end
end
return tostring( EXP_IMGS[idx] )
end
local p = {}
-- Верстак
function p.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 pixel-image' )
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["Мод"] .. ').png}}'
)
end
body
:tag( 'span' )
:addClass( 'mcui-output' )
:wikitext( addSlot( args, 'Вихід', 'В', 'invslot-large' ) )
local shapeless = args["безформний"] or ''
local fixed = args["фіксований"] 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',
'Цей рецепт безформний, ресурси можуть розташовуватися в сітці верстака в будь-якому порядку.'
)
elseif fixed ~= '' then
local notFixed = args["нефіксований"] or ''
local exceptFixed = ''
if notFixed ~= '' then
exceptFixed = ', за винятком ' .. notFixed
end
icon:addClass( 'mcui-fixed' )
:attr( 'title',
'Цей рецепт фіксований, його інгредієнти не можуть бути переміщені або дзеркально відображені' .. exceptFixed .. '.'
)
end
end
return tostring( mw.html.create( 'div' ):node( body ) )
end
-- Піч
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 pixel-image' )
local input = body:tag( 'span' ):addClass( 'mcui-input' )
input:wikitext( addSlot( args, 'Вхід', 'Р' ) )
local fuel = input:tag( 'span' ):addClass( 'mcui-fuel' ):tag( 'br' ):done()
local fuelImg = args.FuelUsage or args["спожпал"] or ''
local burning = args["Вхід"] or '' ~= '' and args["Паливо"] 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["Мод"] .. ').png}}'
)
end
input:wikitext( addSlot( args, 'Паливо', 'П' ) )
local arrow = body:tag( 'span' ):addClass( 'mcui-arrow' ):tag( 'br' ):done()
local arrowImg = args["Прогрес"] or ''
if not burning or ( args["Вихід"] 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["Мод"] .. ').png}}'
)
end
body
:tag( 'span' )
:addClass( 'mcui-output' )
:wikitext( addSlot( args, 'Вихід', 'В', 'invslot-large' ) )
args["Досвід"] = args['Досвід'] or ''
if args["Досвід"] ~= '' then
-- Converts commas to dots, removes all spaces and splits the arguments with semicolon.
local split = mw.text.split(string.gsub(args["Досвід"], '[ ,]', {[' '] = '', [','] = '.'}), ';', true)
local animated = body:tag('span'):attr('title', 'Дрібна частина показує ймовірність отримання одиниці досвіду.')
:addClass('animated'):cssText('position:absolute;top:92px;left:108px;text-align:center;width:70px;')
local isNotFirst = true
for i, v in ipairs(split) do
assert(tonumber(v), 'Модуль:UI: "' .. v .. '" неправильне число')
local xp = tonumber(v)
animated:tag('span')
:addClass(isNotFirst and 'animated-active' or nil)
:wikitext('<span style="display:inline-block;margin-top:3px;width:16px;height:16px;vertical-align:top;background-size:16px 16px;background-image:{{FileUrl|' .. experience_image(xp) .. '}}"></span>'
.. '<span style="display:inline-block;vertical-align:top;font-family:\'Minecraft 1.1\';font-size:16px;color:#404040">'
.. (' ' and xp > 72 or '') .. xp .. '</span>')
isNotFirst = false
end
end
return tostring( mw.html.create( 'div' ):node( body ) )
end
-- Варильна стійка
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 pixel-image' )
local input = body:tag( 'span' ):addClass( 'mcui-input' )
input:tag( 'span' ):addClass( 'mcui-bubbling' ):tag( 'br' )
input:wikitext( addSlot( args, 'Вхід', 'Р' ) )
input:tag( 'span' ):addClass( 'mcui-arrow' ):tag( 'br' )
if ( args["Вхід"] or '' ) == '' or
( ( args["Вихід1"] or '' ) == '' and ( args["Вихід2"] or '' ) == '' and ( args["Вихід3"] 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, 'Вихід' .. i, 'В' .. i, 'mcui-output' .. i ) )
end
return tostring( mw.html.create( 'div' ):node( body ) )
end
-- Каменеріз
function p.stonecutter( 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-Stonecutter pixel-image' )
local input = body:tag( 'span' ):addClass( 'mcui-input' )
input:wikitext( addSlot( args, 'Вхід', 'Р' ) )
local arrow = body:tag( 'span' ):addClass( 'mcui-stonecutterArrow' )
if (args.arrow or '') ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. args.arrow .. ' (' .. args["Мод"] .. ').png}}'
)
end
arrow:wikitext( addSlot( args, 'Вихід', '', 'invslot-plain mcui-stonecutterSprite' ) )
body
:tag( 'span' )
:addClass( 'mcui-output' )
:wikitext( addSlot( args, 'Вихід', 'В', 'invslot-large' ) )
return tostring( mw.html.create( 'div' ):node( body ) )
end
-- Ткацький верстат
function p.loom( 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-Loom pixel-image' )
local tapestry = body:tag( 'span' ):addClass( 'mcui-tapestry' )
if args['Стяг'] and #args['Стяг']>0 then
tapestry:wikitext( addSlot( args, 'Стяг', 'B', 'mcui-inputBanner' ) )
end
if args['Барвник'] and #args['Барвник']>0 then
tapestry:wikitext( addSlot( args, 'Барвник', 'D', 'mcui-inputDye' ) )
end
if args['Візерунок'] and #args['Візерунок']>0 then
tapestry:wikitext( addSlot( args, 'Візерунок', 'P', 'mcui-inputPattern' ) )
end
tapestry:tag( 'span' ):tag( 'br' ):done()
local arrow = body:tag( 'span' ):addClass( 'mcui-loomArrow' )
if args.arrow or '' ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. args.arrow .. ' (' .. args["Мод"] .. ').png}}'
)
end
local sprite = args['Спрайт']
local bannerSprite
if sprite and #sprite>0 then
local animate = require( [[Модуль:AnimateSprite]] ).animate
bannerSprite = animate{
args['Спрайт'],
sheet = 'Спрайт/Слот'
}
else
bannerSprite = '<br>'
end
arrow
:tag( 'span' )
:addClass( 'mcui-bannerSprite' )
:wikitext( bannerSprite )
body
:tag( 'span' )
:addClass( 'mcui-output' )
:wikitext( addSlot( args, 'Вихід', 'В', 'invslot-large' ) )
return tostring( mw.html.create( 'div' ):node( body ) )
end
-- Точило
function p.grindstone( 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-Grindstone pixel-image' )
local grindstone = body:tag( 'span' ):addClass( 'mcui-grindstone' )
grindstone:wikitext( addSlot( args, 'Вхід1', 'Р1', 'mcui-input1' ) )
grindstone:wikitext( addSlot( args, 'Вхід2', 'Р2', 'mcui-input2' ) )
local arrow = body:tag( 'span' ):addClass( 'mcui-arrow' )
if args.arrow or '' ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. args.arrow .. ' (' .. args["Мод"] .. ').png}}'
)
end
body
:tag( 'span' )
:addClass( 'mcui-output' )
:wikitext( addSlot( args, 'Вихід', 'В', 'invslot-large' ) )
return tostring( mw.html.create( 'div' ):node( body ) )
end
-- Верстат коваля
function p.smithing( 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-Smithing_Table pixel-image' )
local smithing = body:tag( 'span') :addClass( 'mcui-smithing' )
smithing:wikitext( addSlot( args, 'Вхід1', 'Р1', 'mcui-input1' ) )
smithing:wikitext( addSlot( args, 'Вхід2', 'Р2', 'mcui-input2' ) )
local arrow = body:tag( 'span' ):addClass( 'mcui-arrow' )
if args.arrow or '' ~= '' then
arrow:css(
'background-image',
'{{FileUrl|' .. args.arrow .. ' (' .. args["Мод"] .. ').png}}'
)
end
body
:tag( 'span' )
:addClass( 'mcui-output' )
:wikitext( addSlot( args, 'Вихід', 'В', '' )
)
return tostring( mw.html.create( 'div' ):node( body ) )
end
return p