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

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

模块:Iconbar:修订间差异

来自RIA | Wiki
秋月白留言 | 贡献
无编辑摘要
秋月白留言 | 贡献
无编辑摘要
第16行: 第16行:
     end
     end
      
      
     -- 处理标题
     -- 修复问题2:正确处理标题
     if title:lower() == 'none' then
     if title:lower() == 'none' then
         title = ''
         title = ''
第22行: 第22行:
         title = ' title="' .. title .. '"'
         title = ' title="' .. title .. '"'
     else
     else
         title = ' title="' .. value .. '"'
        -- 显示实际值,而不是处理后的值
        local displayValue = (tonumber(args.value) or 0)  -- 显示原始值,不是除以2后的值
         title = ' title="' .. displayValue .. '"'
     end
     end
    
    
     -- 处理尺寸参数
     -- 修复问题1:为em单位提供合理的缩放
     local sizeParam = ''
     local sizeParam = ''
     if sizeValue ~= '' then
     if sizeValue ~= '' then
         if tonumber(sizeValue) then
         if tonumber(sizeValue) then
            -- 纯数字:添加px单位
             sizeParam = '|' .. sizeValue .. 'px'
             sizeParam = '|' .. sizeValue .. 'px'
        elseif sizeValue:match('em') then
            -- em单位:转换为像素值,因为SVG需要具体尺寸
            local emValue = tonumber(sizeValue:match('([%d%.]+)em')) or 1
            local pixelSize = math.floor(emValue * 16)  -- 1em ≈ 16px
            sizeParam = '|' .. pixelSize .. 'px'
         else
         else
            -- 其他单位直接使用
             sizeParam = '|' .. sizeValue
             sizeParam = '|' .. sizeValue
         end
         end
    else
        -- 默认大小
        sizeParam = '|16px'
     end
     end
      
      
第59行: 第71行:
     end
     end
      
      
     -- 简化输出,移除span包装
     -- 简化输出
     if reverse ~= '' then
     if reverse ~= '' then
         return emptyIcon .. halfIcon .. fullIcon
         return emptyIcon .. halfIcon .. fullIcon

2025年9月24日 (三) 14:23的版本

模块文档

此模板改编自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
    
    -- 修复问题2:正确处理标题
    if title:lower() == 'none' then
        title = ''
    elseif title ~= '' then
        title = ' title="' .. title .. '"'
    else
        -- 显示实际值,而不是处理后的值
        local displayValue = (tonumber(args.value) or 0)  -- 显示原始值,不是除以2后的值
        title = ' title="' .. displayValue .. '"'
    end
   
    -- 修复问题1:为em单位提供合理的缩放
    local sizeParam = ''
    if sizeValue ~= '' then
        if tonumber(sizeValue) then
            -- 纯数字:添加px单位
            sizeParam = '|' .. sizeValue .. 'px'
        elseif sizeValue:match('em') then
            -- em单位:转换为像素值,因为SVG需要具体尺寸
            local emValue = tonumber(sizeValue:match('([%d%.]+)em')) or 1
            local pixelSize = math.floor(emValue * 16)  -- 1em ≈ 16px
            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
    
    -- 简化输出
    if reverse ~= '' then
        return emptyIcon .. halfIcon .. fullIcon
    else
        return fullIcon .. halfIcon .. emptyIcon
    end
end

return p