模块:EventShopList
用于显示活动商店的表格,可勾选部分素材计算需要的活动道具总数。
- 同一代币(token_alias)的本表格在一个页面中只能引用一次,否则将会出错。
参数:
- token_alias
- 必须,活动道具的名称。
- token_icon
- 活动道具图标的文件名,默认是以token_alias为名的道具图标png文件,默认样式为无框。
- token_icon_size
- 活动道具图标的大小,默认30px。
- data
- 必须,活动商店信息,有多种方式可选。
可交换道具
可交换道具
1;;{{材料消耗|凝胶||30px}} 凝胶;;5;;30;;#95c1ff
其中;;是分隔符。
从左往右的每项分别为:是否初始选中(1/0),兑换项目的名称,库存数量,单价,背景色(可省略,并可使用预设颜色名称【金/紫/蓝/灰/彩/复刻】)。
注意:预设的“灰”不对应T1灰色道具,仅对家具、时装这类无法衡量稀有度但又需要标注的道具使用。对于确实出现了售卖这类道具的情况会手动指定。阶段分隔符
阶段分隔符
X;;阶段 00 X;;金色阶段;;linear-gradient(45deg, #F1E944, #F4CF36, #ddbdbd, #EAEBEE 40%)从左往右的每项分别为:X,分段名称,背景色(可选)。
注释
注释
C;;{{mdi|circle-small}}柏喙及其信物也可以通过[[危机合约]]结晶圣所 / 机密圣所兑换获得。
从左往右的每项分别为:C,注释内容。可折叠分组
可折叠分组
因沙洲遗闻的特别商店状态而导入。分组是一个特殊的指令,通常不会使用。
在要分组的位置写入如下分组声明指令:
G/1/S;;STAGE 1;;linear-gradient(45deg, #e5e340, #898751, #383838, #EAEBEE 22%)
从左往右的每项分别为:G指令组,分组标题,背景色(可选)。
G指令组是一个以斜杠(/)分隔的指令组,从左到右为:G,组编号,是否初始显示(有任何值代表不折叠)
当分组声明指令存在时,接下来的所有【可交换道具】与【注释】指令将被划归到该分组,可通过分组的右侧按钮显示和隐藏,避免列表冗长。
要结束分组,请写入分组中止指令:
G/X
注:
- PRTS的道具图标文件名格式为
道具_<道具名>(无框)或道具_带框_<道具名>(带稀有度框),可按需修改。 - 请勿在阶段分隔符或注释中使用过于复杂的HTML语句,可能会导致渲染出错。
- 兑换项目图标现使用下列标准:
local p = {}
local rarityClassTable = {
["金"] = "eventshoplist-rarity-gold",
["紫"] = "eventshoplist-rarity-purple",
["蓝"] = "eventshoplist-rarity-blue",
["灰"] = "eventshoplist-rarity-gray",
["白"] = "eventshoplist-rarity-white",
["复刻"] = "eventshoplist-rarity-reprint",
["彩"] = "eventshoplist-rarity-rainbow",
}
local darkToneClassTable = {
["金"] = "eventshoplist-tone-gold",
["紫"] = "eventshoplist-tone-purple",
["蓝"] = "eventshoplist-tone-blue",
["灰"] = "eventshoplist-tone-gray",
["白"] = "eventshoplist-tone-white",
["复刻"] = "eventshoplist-tone-reprint",
["彩"] = "eventshoplist-tone-rainbow",
["#ffe0b2"] = "eventshoplist-tone-gold",
["#ffbb78"] = "eventshoplist-tone-orange",
["#f0d2ac"] = "eventshoplist-tone-tan",
["#d1c4e9"] = "eventshoplist-tone-purple",
["#e995ff"] = "eventshoplist-tone-purple",
["#bbdefb"] = "eventshoplist-tone-blue",
["#95c1ff"] = "eventshoplist-tone-blue",
["#e0e0e0"] = "eventshoplist-tone-gray",
["#e9d9f9"] = "eventshoplist-tone-lavender",
}
local function normalizeColor(color)
return mw.ustring.lower((color or ""):gsub("%s+", ""))
end
local function getDarkToneClass(color, resolvedColor)
return darkToneClassTable[color] or darkToneClassTable[normalizeColor(color)] or darkToneClassTable[normalizeColor(resolvedColor)]
end
function p.list(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local token_name = mw.text.trim(args["token_alias"] or "")
local token_icon_file = mw.text.trim(args["token_icon"] or "道具_" .. token_name .. ".png")
local token_icon_size = mw.text.trim(args["token_icon_size"] or "30px")
local data_str = mw.text.trim(args["data"] or "")
local nocss = mw.text.trim(args["nocss"] or "")
local token_icon = string.format("[[File:%s|%s|link=]]", token_icon_file, token_icon_size)
local selectall_str = frame:callParserFunction{name = '#Widget:ShopItemSelectAll', args = {item = token_name}}
local checkbox_css = frame:callParserFunction{name = '#Widget:ShopItemListCss'}
res_table = {}
table.insert(res_table, frame:extensionTag{ name = 'templatestyles', args = { src = 'EventShopList/styles.css' } } .. '\n')
if nocss=="" then
table.insert(res_table, checkbox_css .. "\n")
end
table.insert(res_table, '{| class="wikitable logo eventshoplist" style="white-space:normal;width:600px;max-width:100%;display:table;"\n')
table.insert(res_table, string.format('!style="width:1.5em;"|%s!!可兑换道具!!style="width:5.0em;"|库存!!style="width:6.0em;"|单价\n', selectall_str))
local data_table = mw.text.split(data_str, "\n", true)
local colorTable = {["金"]="#FFE0B2",["紫"]="#D1C4E9",["蓝"]="#BBDEFB",["灰"]="#E0E0E0",["复刻"]="linear-gradient(90deg,#b2f7ff,#bfb0f9);",["彩"]="linear-gradient(90deg,#FFE082,#FFCCBC,#A5D6A7,#FFCC80);"}
local cur_collapseGroup = nil
local cur_collapseGroupCollapse = nil
for i = 1, #data_table do
local datum_table = mw.text.split(data_table[i], ";;", true)
local name = mw.text.trim(datum_table[2] or "")
if datum_table[1]:sub(1,1)=='G' then --折叠模式
groupParam = mw.text.split(datum_table[1], "/", true)
if groupParam[2] == 'X' then --结束折叠呼号
cur_collapseGroup = nil
cur_collapseGroupCollapse = nil
else --执行折叠呼号
cur_collapseGroup = groupParam[2] --取出ID
cur_collapseGroupCollapse = (not groupParam[3]) and true or false --是否不折叠(直接显示)
--换行符
local str = '|- class="eventshoplist-group"'
if datum_table[3] or datum_table[4] then
str = str .. " style=\"text-align:center; "
if datum_table[3] then str = str.."background:"..datum_table[3].."; " end
if datum_table[4] then str = str.."color:"..datum_table[4]..";" end
str = str .."\""
end
str = str .. "\n"
table.insert(res_table, str)
--标题
table.insert(res_table, string.format("|class=\"eventshoplist-group-title\" colspan=3|'''%s'''\n", name))
--按钮
str = "|class=\"eventshoplist-toggle mw-customtoggle-eventShopList%s mw-collapsible __isC1__\" id=\"mw-customcollapsible-eventShopList%s\"|展开 <span class=\"mdi mdi-chevron-down\"></span>\n"
str = str .. "|class=\"eventshoplist-toggle mw-customtoggle-eventShopList%s mw-collapsible __isC2__\" id=\"mw-customcollapsible-eventShopList%s\"|收起 <span class=\"mdi mdi-chevron-up\"></span>\n"
str = string.format(str, cur_collapseGroup, cur_collapseGroup, cur_collapseGroup, cur_collapseGroup)
if not cur_collapseGroupCollapse then --为空时不折叠
str = (str:gsub("__isC1__", "mw-collapsed")):gsub("__isC2__", "")
else
str = (str:gsub("__isC1__", "")):gsub("__isC2__", "mw-collapsed")
end
table.insert(res_table, str)
end
elseif datum_table[1]=='X' then --普通标题
local sectionClasses = {"eventshoplist-section"}
if name:find("金色") then
table.insert(sectionClasses, "eventshoplist-section-gold")
elseif name:find("紫色") then
table.insert(sectionClasses, "eventshoplist-section-purple")
elseif name:find("灰色") then
table.insert(sectionClasses, "eventshoplist-section-gray")
elseif name:find("无限") then
table.insert(sectionClasses, "eventshoplist-section-infinite")
end
table.insert(res_table, '|- class="' .. table.concat(sectionClasses, " ") .. '"\n')
if datum_table[3] or datum_table[4] then
local str = "|class=\"eventshoplist-section-title\" style=\"text-align:center; "
if datum_table[3] then str = str.."background:"..datum_table[3].."; " end
if datum_table[4] then str = str.."color:"..datum_table[4]..";" end
str = str..string.format("\" colspan=4|'''%s'''\n", name)
table.insert(res_table, str)
else
table.insert(res_table, string.format("!class=\"eventshoplist-section-title\" colspan=4|%s\n", name))
end
elseif datum_table[1]=='C' then --注释
table.insert(res_table, '|-\n')
local str = "|__style__ __curColl__ colspan=4|%s\n"
if datum_table[3] or datum_table[4] then
local sstr = ""
if datum_table[3] then sstr = sstr.."background:"..datum_table[3].."; " end
if datum_table[4] then sstr = sstr.."color:"..datum_table[4]..";" end
str = str:gsub("__style__", sstr)
else
str = str:gsub("__style__", "")
end
if cur_collapseGroup then
local cgstr = ("class=\"mw-collapsible __isC__\" id=\"mw-customcollapsible-eventShopList%s\""):format(cur_collapseGroup)
cgstr = cgstr:gsub("__isC__", cur_collapseGroupCollapse and "mw-collapsed" or "")
str = str:gsub("__curColl__", cgstr)
else
str = str:gsub("__curColl__", "")
end
str = string.format(str, name)
table.insert(res_table, str)
else --商品
local color = mw.text.trim(datum_table[5] or "")
local textColor = mw.text.trim(datum_table[6] or "")
local resolvedColor = colorTable[color] or color
local checkbox_str = ""
local rowClasses = {"eventshoplist-item"}
if rarityClassTable[color] then
table.insert(rowClasses, rarityClassTable[color])
elseif color:find("linear%-gradient") then
table.insert(rowClasses, "eventshoplist-rarity-gradient")
end
local darkToneClass = getDarkToneClass(color, resolvedColor)
if darkToneClass then
table.insert(rowClasses, darkToneClass)
end
local num_limit = tonumber(mw.text.trim(datum_table[3] or ""))
local unit_price = tonumber(mw.text.trim(datum_table[4] or ""))
if num_limit ~= nil and unit_price ~= nil then
checkbox_str = frame:expandTemplate{title = "商店列表复选框", args = { token_name, num_limit * unit_price, ((datum_table[1] == '1') and "是" or "否")}}
end
local num_limit_str = (num_limit ~= nil) and num_limit or mw.text.trim(datum_table[3] or "——")
local unit_price_str = (unit_price ~= nil) and tostring(unit_price) or mw.text.trim(datum_table[4] or "——")
--换行
if cur_collapseGroup then
table.insert(rowClasses, "mw-collapsible")
if cur_collapseGroupCollapse then
table.insert(rowClasses, "mw-collapsed")
end
end
local str = '|- class="' .. table.concat(rowClasses, " ") .. '"'
if cur_collapseGroup then
str = str .. (' id="mw-customcollapsible-eventShopList%s"'):format(cur_collapseGroup)
end
if color~="" or textColor~="" then
str = str .. string.format(" style=\"background:%s;color:%s\"", resolvedColor, textColor)
end
str = str .. "\n"
table.insert(res_table, str)
--table.insert(res_table, (color ~= "") and (string.format('|-style="background:%s"\n', color)) or ('|-\n'))
table.insert(res_table, string.format("|%s||%s||%s||%s%s\n", checkbox_str, name, num_limit_str, token_icon, unit_price_str))
end
end
local total_str = frame:callParserFunction{name = '#Widget:ShopItemTotalCost', args = {item = token_name}}
table.insert(res_table, '|-\n')
table.insert(res_table, string.format('| ||colspan="2"|勾选项目总价||%s\'\'\'%s\'\'\'\n', token_icon, total_str))
table.insert(res_table, '|}')
return table.concat(res_table)
end
return p