Module:Icons: Difference between revisions

m
Updated currency links
No edit summary
Tag: Manual revert
m (Updated currency links)
 
(6 intermediate revisions by 2 users not shown)
Line 789: Line 789:


if menu then
if menu then
return '{| class="articletable" style="display:inline-block;vertical-align:middle;"\r\n|-\r\n|' .. expIcon .. resultText .. '\r\n|}'
return '{| class="articletable img-text" style="vertical-align:middle;"\r\n|-\r\n|' .. expIcon .. resultText .. '\r\n|}'
elseif not noicon and not nospan then
elseif not noicon and not nospan then
return '<span style="display:inline-block">' .. expIcon .. resultText .. '</span>'
return '<span class="img-text">' .. expIcon .. resultText .. '</span>'
else
else
return resultText
return resultText
Line 810: Line 810:
result = result.." Level "..level
result = result.." Level "..level


result = '<span style="display:inline-block">'..result..'</span>'
result = '<span class="img-text">'..result..'</span>'
return result
return result
end
end
Line 837: Line 837:
result = result..p.Icon({linkname, img=iconname, type='item', notext=true, nospan=true, alt=altTextItem})..p.Icon({'Mastery', notext=true, nospan=true, alt=altTextMastery})
result = result..p.Icon({linkname, img=iconname, type='item', notext=true, nospan=true, alt=altTextItem})..p.Icon({'Mastery', notext=true, nospan=true, alt=altTextMastery})
if showText then result = result..'[['..linkname..']] [[Mastery]]' end
if showText then result = result..'[['..linkname..']] [[Mastery]]' end
result = '<span style="display:inline-block">'..result..'</span>'
result = '<span class="img-text">'..result..'</span>'
return result
return result
end
end
Line 850: Line 850:


function p._Currency(fileName, link, altText, amount, maxAmount)
function p._Currency(fileName, link, altText, amount, maxAmount)
local ret = {}
local function numColour(amount)
table.insert(ret, '<span style="display:inline-block">')
if tonumber(amount) < 0 then
-- Currency icon
return mw.html.create('span')
if fileName ~= nil then
:css('color', 'red')
table.insert(ret, '[[File:' .. fileName .. '|25px')
:wikitext(formatnum(amount))
if link ~= nil then
:done()
table.insert(ret, '|link=' .. link)
else
return formatnum(amount)
end
end
table.insert(ret, '|alt=' .. ((altText == nil and '') or altText) .. ']]')
end
end
local html = mw.html.create('span')
:addClass('img-text')
-- Currency amounts
-- Currency amounts
if tonumber(amount) ~= nil then
if tonumber(amount) ~= nil then
local function numColour(amount)
local text = mw.html.create('span')
if tonumber(amount) < 0 then
:css('margin-right', '0.2em')
return '<span style="color:red;">' .. formatnum(amount) .. '</span>'
:node(numColour(amount))
else
if (tonumber(maxAmount) ~= nil and maxAmount > amount) then
return formatnum(amount)
text:wikitext(' - ' .. numColour(maxAmount))
end
end
end
table.insert(ret, '&nbsp;' .. numColour(amount))
html:node(text:done())
if (tonumber(maxAmount) ~= nil and maxAmount > amount) then
end
table.insert(ret, ' - ' .. numColour(maxAmount))
-- Currency icon
if fileName ~= nil then
html:wikitext('[[File:'):wikitext(fileName):wikitext('|25px')
if link ~= nil then
html:wikitext('|link='):wikitext(link)
end
end
html:wikitext('|alt=')
:wikitext(((altText == nil and '') or altText))
:wikitext(']]')
end
html:done()
if ((amount ~= nil and tonumber(amount) == nil)
or (maxAmount ~= nil and tonumber(maxAmount) == nil)) then
html:wikitext('[[Category:Pages with non-numeric currency arguments]]')
end
end
table.insert(ret, '</span>')
return table.concat(ret)
return tostring(html)
end
end


function p.GP(amt, maxamt)
function p.GP(amt, maxamt)
return p._Currency('Coins.svg', 'Coins', 'GP', amt, maxamt)
return p._Currency('Coins.svg', 'Gold Pieces', 'GP', amt, maxamt)
end
end


function p.SC(amt, maxamt)
function p.SC(amt, maxamt)
return p._Currency('Slayer Coins.svg', 'Currency#Slayer Coins', 'SC', amt, maxamt)
return p._Currency('Slayer Coins.svg', 'Slayer Coins', 'SC', amt, maxamt)
end
end


function p.RC(amt, maxamt)
function p.RC(amt, maxamt)
return p._Currency('Raid_Coins.svg', 'Currency#Raid Coins', 'RC', amt, maxamt)
return p._Currency('Raid_Coins.svg', 'Raid Coins', 'RC', amt, maxamt)
end
 
-- p.Currency() is called by various currency templates:
-- [[Template:GP]], [[Template:SC]], [[Template:RC]]
function p.Currency(frame)
local args = frame.args ~= nil and frame.args or frame
local currID, minVal, maxVal, _
currID = args[1]
if args[2] ~= nil and args[2] ~= '' then
minVal, _ = string.gsub(args[2], ',', '')
end
if args[3] ~= nil and args[3] ~= '' then
maxVal, _ = string.gsub(args[3], ',', '')
end
if currID == 'GP' then
return p.GP(minVal, maxVal)
elseif currID == 'SC' then
return p.SC(minVal, maxVal)
elseif currID == 'RC' then
return p.RC(minVal, maxVal)
else
return Shared.printError('Invalid currency: ' .. (currID == nil and 'nil' or currID))
end
end
end


1,055

edits