local UI = require("urhox-libs/UI") local W = require("Game/UI/Widgets") local Base = require("Game/UI/HomeSkin") local Escort = require("Game/UI/EscortSkin") local Skin = require("Game/UI/CodexSkin") local Screen = {} ---@param a any ---@return any[] rows, string summary local function records(a) local E,s=a.engine,a.state local rows={} if a.codexTab=="roster" then local profiles={} for _,p in ipairs(E.data.ROSTER) do profiles[p.name]=p end for _,name in ipairs(s.codex.roster) do rows[#rows+1]={name=name,profile=profiles[name] or {name=name,cls="biaotou"}} end return rows,"招募记录 "..#s.codex.roster.." / "..#E.data.ROSTER.." 人" elseif a.codexTab=="events" then for _,id in ipairs(s.codex.events) do local ev=a.eventsById[id] if ev then rows[#rows+1]={name=ev.title,description=ev.text,status=ev.cat} end end return rows,"已记录 "..#s.codex.events.." / "..#E.data.EVENTS.." 则见闻" elseif a.codexTab=="goods" then for _,name in ipairs(s.codex.goods) do rows[#rows+1]={name=name,description="曾随镖队押运,已记入货物图鉴。",status="已押运"} end return rows,"曾押运 "..#s.codex.goods.." 种货物" elseif a.codexTab=="bonds" then for _,b in ipairs(E.bondList(s)) do rows[#rows+1]={name=b.name,description=b.desc,status=b.on and "已激活" or "尚未达成",active=b.on} end return rows,"羁绊战力 ×"..string.format("%.1f",E.bondMul(s)) else for _,t in ipairs(E.titleList(s)) do rows[#rows+1]={name=t.name,description=t.desc,status=t.got and "已获得" or "尚未达成",active=t.got} end return rows,"称号战力 ×"..string.format("%.1f",E.titleMul(s)) end end ---@param row any ---@param index integer ---@param k number ---@return Panel local function recordCard(row,index,k) local height=math.max(180,160+math.ceil(utf8.len(row.description or "")/25)*38) local family="home-ink" -- These four rare characters are absent in Ma Shan Zheng; the existing serif covers them. for _,c in ipairs({"窣","窸","箓","蹚"}) do if (row.name..(row.description or "")):find(c,1,true) then family="biaoju" break end end local card=Escort.Surface(843,height,k,{id="codex-record-"..index,flexShrink=0}) card:AddChild(Base.Label(row.name,32,16,570,55,40,k,{fontFamily=family})) card:AddChild(Base.Label(row.status or "",600,25,210,40,27,k, {textAlign="right",fontColor=row.active and Skin.Olive or "#805e2f"})) card:AddChild(Escort.Image("divider",32,80,779,8,k)) card:AddChild(Base.Label(row.description,32,100,779,height-120,28,k, {whiteSpace="normal",lineHeight=1.4,verticalAlign="top",fontFamily=family})) return card end ---@param a any ---@param w number ---@param availableHeight number ---@param k number ---@return Panel function Screen.Content(a,w,availableHeight,k) local rows,summary=records(a) ---@type Widget local count=Base.Label(summary,291.5,198,300,48,34,k,{id="codex-count",textAlign="center", minFontSize=20*k/UI.Theme.FontSize(1)}) if a.codexTab=="roster" then local parts={"招募记录 ",tostring(#a.state.codex.roster)," / "..#a.engine.data.ROSTER.." 人"} local widths,total={},0.0 for i,text in ipairs(parts) do widths[i]=UI.MeasureTextWidth(text,34*k,"home-ink")/k total=total+widths[i] end count=UI.Panel(Base.Box(291.5,198,300,48,k,{id="codex-count",text=summary, pointerEvents="none",backgroundColor=false})) local x=(300-total)/2 for i,text in ipairs(parts) do count:AddChild(Base.Label(text,x,0,widths[i]+1,48,34,k, {fontColor=i==2 and W.colors.red or Base.Ink})) x=x+widths[i] end end local header=UI.Panel {width=w,height=234*k,flexShrink=0,backgroundColor=false,children={ Escort.Plaque("江湖图鉴",260,3,363,k), Escort.Image("divider",201.5,98,130,3,k), Base.Label("行镖见闻",347.5,79,188,40,34,k,{textAlign="center"}), Escort.Image("divider",551.5,98,130,3,k), Escort.Image("divider",151.5,220.5,120,3,k), count, Escort.Image("divider",611.5,220.5,120,3,k), }} local categories=UI.Panel(Base.Box(54,128,788,56,k,{backgroundColor=false})) local tabs={{"events","见闻"},{"roster","镖师"},{"goods","货物"},{"bonds","羁绊"},{"titles","称号"}} for i,pair in ipairs(tabs) do local key,label=pair[1],pair[2] categories:AddChild(Skin.Category(label,a.codexTab==key,(i-1)*160,k,function() if a.codexTab==key then return end a.codexTab=key a.recordLimit=30 -- A new category starts at its heading, rather than inheriting a long list's offset. a.content=nil a:Invalidate() end,"codex-"..key)) end header:AddChild(categories) ---@type Widget[] local cards={} for i=1,math.min(#rows,a.recordLimit) do local row=rows[i] if a.codexTab=="roster" then local card=Skin.Character(row.name,row.profile,i==1,k,function() a:Open("codex-record",{name=row.name,bio=row.profile.bio or "曾在镖局效力",cls=row.profile.cls}) end) card:SetStyle({position="relative",left=0,top=0,flexShrink=0}) cards[#cards+1]=card else cards[#cards+1]=recordCard(row,i,k) end end if #rows==0 then local empty=Escort.Surface(843,220,k,{id="codex-empty",flexShrink=0}) empty:AddChild(Base.Label("此卷尚待续写",32,28,779,60,40,k,{textAlign="center"})) empty:AddChild(Base.Label("先去接一趟镖,沿途的人与货会逐渐记在这里。",55,106,733,80,28,k, {whiteSpace="normal",textAlign="center",lineHeight=1.5})) cards[#cards+1]=empty end if #rows>a.recordLimit then local more=Escort.Secondary("继续翻阅",0,0,843,64,k,function() a.recordLimit=a.recordLimit+30 a:Invalidate() end,{id="codex-more"}) more:SetStyle({position="relative",left=0,top=0,flexShrink=0}) cards[#cards+1]=more end local list=W.Column(cards,{id="codex-list",width=843*k,marginLeft=20*k,gap=10*k,flexShrink=0}) local spacer=UI.Panel {height=0,flexGrow=1,backgroundColor=false,pointerEvents="none"} return W.Column({header,list,spacer,Skin.Footer(k)},{id="codex-body",width=w,minHeight=availableHeight, gap=0,backgroundColor=false,flexShrink=0}) end return Screen