打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

RIA Wiki 已更新到 1.41!部分 CSS 在新版本下可能有不同的表现,请编辑者注意检查和修改。 目前wiki关闭了自行注册账号的功能,如需注册账号,请查阅Help:注册账号

模块:Iconbar

来自RIA | Wiki
秋月白留言 | 贡献2025年9月24日 (三) 14:25的版本
模块文档

此模板改编自Minecraft中文维基,原页面为mcwiki:模块:Iconbar

local p = {}
function p.bar(frame)
    local args = frame.args or {}
    
    local full = args.full
    local half = args.half or 'Half ' .. full
    local empty = args.empty or 'Empty ' .. full
    local value = math.abs(tonumber(args.value) or 0) / 2
    local min = math.ceil(math.abs(tonumber(args.min) or 0) / 2)
    local sizeValue = args.size or ''
    local title = args.title or ''
    local reverse = args.reverse or ''
    
    if not full then
        return '错误:缺少必需的full参数'
    end
    
    -- 修复标题处理:保留完整的title属性拼接
    local titleAttr = ''
    if title:lower() == 'none' then
        titleAttr = ''
    elseif title ~= '' then
        titleAttr = ' title="' .. title .. '"'
    else
        local displayValue = (tonumber(args.value) or 0)
        titleAttr = ' title="' .. displayValue .. '"'
    end
   
    -- 处理尺寸参数
    local sizeParam = ''
    if sizeValue ~= '' then
        if tonumber(sizeValue) then
            sizeParam = '|' .. sizeValue .. 'px'
        elseif sizeValue:match('em') then
            local emValue = tonumber(sizeValue:match('([%d%.]+)em')) or 1
            local pixelSize = math.floor(emValue * 16)
            sizeParam = '|' .. pixelSize .. 'px'
        else
            sizeParam = '|' .. sizeValue
        end
    else
        sizeParam = '|16px'
    end
    
    local fullIcon = ''
    local halfIcon = ''
    local emptyIcon = ''

    -- 生成图标
    if value == 0 then
        emptyIcon = '[[File:' .. empty .. sizeParam .. ']]'
    else
        local fullCount = math.floor(value)
        if fullCount > 0 then
            fullIcon = string.rep('[[File:' .. full .. sizeParam .. ']]', fullCount)
        end
        
        if math.floor(value) ~= value then
            halfIcon = '[[File:' .. half .. sizeParam .. ']]'
        end
    end
    
    -- 生成空图标
    local emptyCount = min - math.ceil(value)
    if emptyCount > 0 then
        emptyIcon = string.rep('[[File:' .. empty .. sizeParam .. ']]', emptyCount)
    end
    
    -- 修复:添加回span包装和title属性
    if reverse ~= '' then
        return '<span class="pixel-image nowrap"' .. titleAttr .. '>' .. emptyIcon .. halfIcon .. fullIcon .. '</span>'
    else
        return '<span class="pixel-image nowrap"' .. titleAttr .. '>' .. fullIcon .. halfIcon .. emptyIcon .. '</span>'
    end
end

return p