置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:Sandbox/红石小蝈/UserPage

猛汉♂百科,万男皆可猛的百科全书!转载请标注来源页面的网页链接,并声明引自猛汉百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
upage = {}
upage.main_color = "#0fa0df"
upage.base_color = "#99eeff"
-- variables
boxes = {}
hbox_cnt = 0
hobbies_at = 1
hobbies = {}

local function set_default(args, default)
    for i, v in pairs(default) do
        if args[i] == nil then
            args[i] = v
        end
    end
end

function upage.box_base(args)
    set_default(args, upage.box_base_default)
    local width = 64 * args.w - 8
    local height = 64 * args.h - 8
    local retobj = mw.html.create("div")
    retobj
        :css{
            display = "inline-flex",
            margin = "4px",
            width = tostring(width).."px",
            height = tostring(height).."px",
            background = args.bg,
            ["box-shadow"] = "3px 3px 8px rgba(0,0,0,0.5)",
            ["font-size"] = "10px"
        }:css(args.bs)
        :wikitext(args.c)
    return tostring(retobj)
end

upage.box_base_default = {
    bg = "#FFF",
    bs = {},
    w = 1,
    h = 1,
}

function upage.box(args)
    set_default(args, upage.box_default)
    local css = {
        ["align-items"] = "center", 
        ["justify-content"] = "center",
        ["text-align"] = "center",
        ["color"] = args.fg,
        overflow = "hidden"
    }
    for i, j in ipairs(args.bs) do
        css[i] = j
    end
    return upage.box_base{
        bs = css,
        c = args.t
    }
end

upage.box_default = {fg = "#ccc", bs = {}, t = ""}

function upage.empty()
    local retobj = mw.html.create("div")
    retobj:css{
        display = "inline-flex",
        width = "64px", height = "64px",
    }
    return tostring(retobj)
end

function upage.glass()
    local retobj = mw.html.create("div")
    retobj
        :css{
            display = "inline-flex",
            width = "64px", height = "64px",
            ["background-color"] = "rgb(155, 183, 213)"
        }
    local div1 = retobj:tag("div")
    div1
        :css{
            position = "relative",
            left = "4px", top = "4px",
            width = "56px", height = "56px",
            ["background-color"] = "rgb(163, 199, 214)";
        }
    div1:tag("div")
        :css{
            position = "absolute",
            left = "4px", top = "12px",
            width = "4px", height = "4px",
            ["background-color"] = "rgb(155, 183, 213)"
        }
    div1:tag("div")
        :css{
            position = "absolute",
            left = "8px", top = "8px",
            width = "4px", height = "4px",
            ["background-color"] = "rgb(155, 183, 213)"
        }
    div1:tag("div")
        :css{
            position = "absolute",
            left = "12px", top = "4px",
            width = "4px", height = "4px",
            ["background-color"] = "rgb(155, 183, 213)"
        }
    div1:tag("div")
        :css{
            position = "absolute",
            right = "8px", bottom = "4px",
            width = "4px", height = "4px",
            ["background-color"] = "rgb(155, 183, 213)"
        }
    div1:tag("div")
        :css{
            position = "absolute",
            right = "4px", bottom = "8px",
            width = "4px", height = "4px",
            ["background-color"] = "rgb(155, 183, 213)"
        }
    return tostring(retobj)
end

upage.vd = upage.empty -- vd for "void", uses as fillings.

function upage.large_box(args)
    set_default(args, upage.large_box_default)
    local idc = 0
    local retobj = mw.html.create("div")
    retobj:css{
        display = "inline-block",
        margin = "4px",
        position = "relative",
        width = "248px",
        height = "56px",
        background = args.bg,
        ["box-shadow"] = "3px 3px 8px rgba(0,0,0,0.5)"
    }
    local left = "0"
    if type(args.id_l) == "string" then
        idc = idc + 1
        retobj
            :tag("div")
            :css{
                display = "flex",
                position = "absolute",
                left = "0",
                top = "0",
                width = "56px",
                height = "56px",
                background = args.id_l_bg,
                ["align-items"] = "center",
                ["justify-content"] = "center",
                overflow = "hidden"
            }:tag("div")
            :css{
                ["max-height"] = "56px",
                ["text-align"] = "center",
                ["font-weight"] = "bold",
                ["font-size"] = args.id_l_s,
                color = args.id_l_c,
                ["line-height"] = "1em"
            }:wikitext(args.id_l)
        left = "56px"
    end
    if type(args.id_r) == "string" then
        idc = idc + 1
        retobj
            :tag("div")
            :css{
                display = "flex",
                position = "absolute",
                right = "0",
                top = "0",
                width = "56px",
                height = "56px",
                background = args.id_r_bg,
                ["align-items"] = "center",
                ["justify-content"] = "center",
                overflow = "hidden"
            }:tag("div")
            :css{
                ["max-height"] = "56px",
                ["text-align"] = "center",
                ["font-weight"] = "bold",
                ["font-size"] = args.id_r_s,
                color = args.id_r_c,
                ["line-height"] = "1em"
            }:wikitext(args.id_r)
    end
    local width = 248 - 56 * idc
    local inner = retobj:tag("div")
    inner
        :css{
            display = "flex",
            position = "absolute",
            top = "0",
            height = "56px",
            left = left,
            width = tostring(width).."px",
            ["align-items"] = "center",
            overflow = "auto"
        }:tag("div")
            :css{
                ["padding-left"] = "0.5em",
                ["padding-right"] = "0.5em",
                width = tostring(width).."px",
                ["max-height"] = "56px",
                ["text-align"] = "left",
                ["font-size"] = args.content_s,
                ["line-height"] = "1.4em",
                color = args.content_c
            }:wikitext(args.content)
    return tostring(retobj)
end

upage.large_box_default = {
    bg = "#FFF",
    id_l_bg = upage.main_color,
    id_l_s = "20px",
    id_l_c = "#000",
    id_r_bg = upage.main_color,
    id_r_s = "20px",
    id_r_c = "#000",
    content_s = "10px",
    content_c = "#000",
    content = "",
}

function upage.hide_box(args)
    set_default(args, upage.hide_box_default)
    local count = hbox_cnt
    local left_size = nil
    if type(args.id_l) == "string" then
        if mw.ustring.len(args.id_l) == 1 then
            left_size = "30px"
        else
            left_size = "20px"
        end
    end
    local retobj = mw.html.create("div")
    local lbobj = mw.html.create("div")
    lbobj:addClass("mw-customtoggle-mnahide-"..count)
    lbobj:tag("div")
        :addClass("mw-collapsible")
        :attr("id", "mw-customcollapsible-mnahide-"..count)
        :wikitext(args.expp)
    lbobj:tag("div")
        :addClass("mw-collapsible")
        :addClass("mw-collapsed")
        :attr("id", "mw-customcollapsible-mnahide-"..count)
        :wikitext(args.fldp)
    local innerobj = mw.html.create("div")
    innerobj
        :css{
            ["padding-left"] = "0.5em",
            ["padding-right"] = "0.5em",
            ["text-align"] = "left"        
        }:wikitext(mw.getCurrentFrame():expandTemplate{title = args.source})
    retobj
        :css{
            display = "flex",
            ["flex-direction"] = "column"
        }:wikitext(upage.large_box{
            id_l_bg = upage.main_color,
            id_l = args.id_l,
            id_l_s = left_size,
            id_l_c = args.id_l_c,
            content = tostring(lbobj)
        }):tag("div")
            :addClass("mw-collapsible mw-collapsed")
            :attr("id", "mw-customcollapsible-mnahide-"..count)
            :wikitext(upage.box_base{
                w = 4,
                h = args.h,
                bs = {overflow = "auto"},
                c = tostring(innerobj),
            })
    hbox_cnt = count + 1
    return tostring(retobj)
end

upage.hide_box_default = {
    h = 4,
    id_l_c = "#000"
}

function set_hobbies(list)
    for i, j in ipairs(list) do
        hobbies[i] = j
    end
    math.randomseed(os.time())
    for i = #hobbies, 2, -1 do
        local j = math.random(i)
        hobbies[i], hobbies[j] = hobbies[j], hobbies[i]
    end
end

function upage.get_hobby()
    local ret = mw.html.create("div")
    ret:css{
        position = "relative",
        width = "64px",
        height = "64px"
    }:wikitext(upage.box{
        bs = {
            position = "absolute",
            left = "0px",
            top = "0px"
        },
        t = hobbies[hobbies_at],
    })
    hobbies_at = hobbies_at + 1
    return tostring(ret)
end

function upage.generate(frame)
    --local source_name = frame.args.source
    --local content_json = frame:expandTemplate{title = source_name}
    local content = require("Module:Sandbox/红石小蝈/Data")
    set_hobbies(content.hobbies)
    for _, i in ipairs(content.large_boxes) do
        boxes[i.box_id] = upage.large_box(i)
    end
    for _, i in ipairs(content.hide_boxes) do
        boxes[i.box_id] = upage.hide_box(i)
    end
    local ret = mw.html.create("div")
    local inner = ret:css("position", "relative")
        :tag("div"):css{
            ["min-width"] = "100%",
            ["max-width"] = "100%",
            ["overflow-x"] = "auto",
            ["background-color"] = upage.base_color
        }:tag("div"):css{
            width = "1096px", -- 64 * 16 + margin * 2 + padding * 2
            margin = "auto"
        }:tag("div"):css{
            display = "flex",
            background = "#FFF",
            width = "1024px",
            margin = "32px",
            ["box-shadow"] = "inset 3px 3px 10px rgba(0,0,0,0.5)",
            padding = "4px",
            ["align-items"] = "center",
            ["justify-content"] = "center",
            ["flex-direction"] = "column"
        }
    for _, j in ipairs(frame.args) do
        local newline = inner:tag("div")
        newline
            :css{
                display = "flex",
                align = "top",
                ["justify-content"] = "center",
                ["flex-direction"] = "row"
            }
        local x = 1
        while x <= 16 do
            if string.sub(j, x, x) == "#" then
                newline:wikitext(upage.get_hobby())
                x = x + 1
            elseif string.sub(j, x, x) == " "  or string.sub(j, x, x) == "%" then
                newline:wikitext(upage.vd())
                x = x + 1
            elseif string.sub(j, x, x) == "*" then
                newline:wikitext(upage.vd())
                x = x + 1
            elseif string.sub(j, x, x) == "@" then
                newline:wikitext(upage.vd())
                x = x + 1
            else
                newline:wikitext(boxes[string.sub(j, x, x+3)])
                x = x + 4
            end
        end
    end
    return tostring(ret)
end

return upage