模块:EventShopList

来自PRTS
跳转到导航 跳转到搜索

用于显示活动商店的表格,可勾选部分素材计算需要的活动道具总数。

  • 同一代币(token_alias)的本表格在一个页面中只能引用一次,否则将会出错。

参数:

  • token_alias
必须,活动道具的名称。
  • token_icon
活动道具图标的文件名,默认是以token_alias为名的道具图标png文件,默认样式为无框。
  • token_icon_size
活动道具图标的大小,默认30px。
  • data
必须,活动商店信息,有多种方式可选。
可交换道具 
阶段分隔符 
注释 
可折叠分组 

注:

  • PRTS的道具图标文件名格式为道具_<道具名>(无框)或道具_带框_<道具名>(带稀有度框),可按需修改。
  • 请勿在阶段分隔符或注释中使用过于复杂的HTML语句,可能会导致渲染出错。
  • 兑换项目图标现使用下列标准:

local p = {}

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 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}}
	
	res_table = {}
	table.insert(res_table, '{| class="wikitable logo" 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 = '|-'
				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("|colspan=3|'''%s'''\n", name))
				--按钮
				str = "|class=\"mw-customtoggle-eventShopList%s mw-collapsible __isC1__\" id=\"mw-customcollapsible-eventShopList%s\"|展开 <span class=\"mdi mdi-chevron-down\"></span>\n"
				str = str .. "|class=\"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 --普通标题
			table.insert(res_table, '|-\n')
			if datum_table[3] or datum_table[4] then
				local 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..string.format("\" colspan=4|'''%s'''\n", name)
				table.insert(res_table, str)
			else
				table.insert(res_table, string.format("!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 checkbox_str = ""
			
			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 "——")
			
			--换行
			local str = '|-__style__ __curColl__\n'
			if color~="" or textColor~="" then
				str = str:gsub("__style__", string.format("style=\"background:%s;color:%s\"", colorTable[color] or color, textColor) )
			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
			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