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 Codex = require("Game/UI/CodexSkin") local Skin = require("Game/UI/RankSkin") local Screen = {} ---@class RankSlot ---@field x number ---@field y number ---@field w number ---@field h number ---@field portraitH number ---@field medalX number ---@field medalY number ---@field medalW number ---@field medalH number ---@field plateX number ---@field plateY number ---@field plateW number ---@field plateH number ---@field scoreX number ---@field scoreY number ---@field scoreW number ---@param value number ---@return string local function score(value) return math.abs(value)>=1000000 and W.Big(value) or W.Number(value) end ---@param row any ---@param rank integer ---@param metric string ---@param k number ---@return Panel local function podiumCard(row,rank,metric,k) -- Slots describe places, never identities. A new leader takes the centre slot with its own art. ---@type RankSlot[] local slots={ {x=257,y=11,w=355,h=416,portraitH=330,medalX=126,medalY=236,medalW=80,medalH=74, plateX=36,plateY=289,plateW=274,plateH=64,scoreX=29,scoreY=357,scoreW=296}, {x=24,y=29,w=277,h=405,portraitH=300,medalX=98,medalY=228,medalW=70,medalH=62, plateX=14,plateY=282,plateW=240,plateH=58,scoreX=0,scoreY=342,scoreW=267}, {x=566,y=42,w=270,h=394,portraitH=285,medalX=99,medalY=216,medalW=70,medalH=62, plateX=24,plateY=268,plateW=224,plateH=58,scoreX=2,scoreY=326,scoreW=266}, } local p=assert(slots[rank]) local id="rank-top-"..rank local card=UI.Panel(Base.Box(p.x,p.y,p.w,p.h,k,{id=id, backgroundColor=false,pointerEvents="none",children={ Skin.Portrait(row,0,0,p.w,p.portraitH,k,id.."-portrait-"..Skin.Identity(row)), Skin.Medal(rank,p.medalX,p.medalY,p.medalW,p.medalH,k), Skin.Nameplate(row,p.plateX,p.plateY,p.plateW,p.plateH,k,id.."-plate"), }})) local label=Base.Label(metric,0,0,58,48,28,k,{textAlign="center"}) local value=Base.Number(score(row.score),0,0,150,48,36,k,{id=id.."-score",textAlign="center", fontColor=Skin.Red,minFontSize=20*k/UI.Theme.FontSize(1)}) label:SetStyle({position="relative",left=0,top=0,flexShrink=0}) value:SetStyle({position="relative",left=0,top=0,flexShrink=0}) card:AddChild(W.Row({label,value},Base.Box(p.scoreX,p.scoreY,p.scoreW,48,k, {justifyContent="center",gap=6*k,pointerEvents="none"}))) return card end ---@param row any ---@param index integer ---@param k number ---@return Panel local function rankingRow(row,index,k) local h=row.me and 100 or 88 local id="rank-row-"..index ---@type Widget[] local children={} if row.me then children[#children+1]=UI.Panel(Base.Box(10,0,823,h,k,{id="rank-self-highlight", backgroundColor="#b5543b1f",borderRadius=16*k,borderWidth=2*k, borderColor=Skin.Red,borderAlign="inside",pointerEvents="none"})) children[#children+1]=UI.Panel(Base.Box(16,6,811,h-12,k,{backgroundColor=false, borderRadius=12*k,borderWidth=k,borderColor=Skin.Red,borderAlign="inside",pointerEvents="none"})) else children[#children+1]=Escort.Image("divider",27,h-5,789,5,k) end local rank=Base.Number(index,0,0,140,h,row.me and 52 or 44,k, {id=id.."-number",textAlign="center",fontColor=row.me and Skin.Red or Base.Ink}) local name=Escort.Label(row.name,0,0,354,h,34,k,{id=id.."-name"}) local value=Base.Number(score(row.score),0,0,135,h,37,k,{id=id.."-score",textAlign="right", fontColor=Skin.Red,minFontSize=20*k/UI.Theme.FontSize(1)}) for _,item in ipairs({rank,name,value}) do item:SetStyle({position="relative",left=0,top=0,flexShrink=0}) end local function spacer(width) return UI.Panel {width=width*k,height=k,backgroundColor=false,pointerEvents="none",flexShrink=0} end children[#children+1]=W.Row({rank,spacer(4),Skin.Avatar(row,k,id.."-avatar-"..Skin.Identity(row)), spacer(36),name,spacer(20),value},{width=843*k,height=h*k,paddingLeft=24*k, -- The authored 90px avatar intentionally extends 1px above/below an 88px row. paddingRight=40*k,gap=0,justifyContent="flex-start",allowOverflow=true,pointerEvents="none"}) return UI.Panel {id=id,width=843*k,height=h*k,flexShrink=0,padding=0, backgroundColor=false,pointerEvents="none",children=children} end ---@param a any ---@param w number ---@param availableHeight number ---@param k number ---@return Panel function Screen.Content(a,w,availableHeight,k) local tabs={{"prestige","声望"},{"silver","银两"},{"runs","押镖"},{"events","见闻"},{"cities","城池"}} local metric="声望" ---@type Widget[] local buttons={} for _,tab in ipairs(tabs) do local key,label=tab[1],tab[2] if a.rankMetric==key then metric=label end buttons[#buttons+1]=Skin.Category(label,a.rankMetric==key,k,function() if a.rankMetric==key then return end a.rankMetric=key a.content=nil a:Invalidate() end,"rank-"..key) end local board=a.engine.leaderboard(a.state,a.rankMetric) local rankPrefix="本镖局名次 " local rankValue="第"..board.rank.."名" local prefixWidth=UI.MeasureTextWidth(rankPrefix,35*k,"home-ink") local valueWidth=UI.MeasureTextWidth(rankValue,35*k,"home-ink") local rankName=Base.Label(rankPrefix,0,0,prefixWidth/k,48,35,k) local rankNumber=Base.Label(rankValue,0,0,valueWidth/k,48,35,k, {id="rank-my-position-value",fontColor=Skin.Red}) rankName:SetStyle({position="relative",left=0,top=0,flexShrink=0}) rankNumber:SetStyle({position="relative",left=0,top=0,flexShrink=0}) local header=UI.Panel {width=w,height=217*k,flexShrink=0,backgroundColor=false,children={ Escort.Plaque("本地江湖榜",237,3,420,k), Base.Label("江湖同道",75,9,150,40,27,k,{textAlign="center"}), W.Row(buttons,Base.Box(80,75,724,56,k,{gap=6*k,justifyContent="flex-start"})), Base.Label("与固定江湖对手比较经营进度。",141.5,131,600,40,26,k,{textAlign="center"}), W.Row({rankName,rankNumber},Base.Box(266.5,174,350,48,k, {id="rank-my-position",gap=0,justifyContent="center",pointerEvents="none"})), Escort.Image("divider",177,195,74,6,k),Escort.Image("divider",632,195,74,6,k), }} local podium=UI.Panel {id="rank-podium",width=843*k,height=448*k,marginLeft=20*k,flexShrink=0, backgroundColor=false,pointerEvents="none",children={ Codex.Image("scroll",0,0,843,448,k), UI.Panel(Base.Box(32,31,779,300,k,{overflow="hidden",backgroundColor=false,pointerEvents="none", children={Skin.Image("terrain",0,0,780,417,k)}})), }} -- The centre leader is drawn last, as in the authored Figma layer stack. for _,place in ipairs({2,3,1}) do local row=board.rows[place] if row then podium:AddChild(podiumCard(row,place,metric,k)) end end local tableHeader=UI.Panel {width=843*k,height=52*k,flexShrink=0,backgroundColor=false,pointerEvents="none", children={Base.Label("排名",24,0,140,52,30,k,{textAlign="center"}), Base.Label("江湖同道",324,0,300,52,30,k), Base.Label(metric,668,0,135,52,30,k,{id="rank-metric-heading",textAlign="center"})}} ---@type Widget[] local rows={tableHeader} local tableHeight=62 for i=4,#board.rows do local row=board.rows[i] rows[#rows+1]=rankingRow(row,i,k) tableHeight=tableHeight+(row.me and 100 or 88) end local list=Escort.Surface(843,tableHeight,k,{id="rank-leaderboard",marginLeft=20*k,marginTop=10*k,flexShrink=0}) list:AddChild(W.Column(rows,{position="absolute",left=0,top=5*k,width=843*k,gap=0,pointerEvents="none"})) return W.Column({header,podium,list},{id="rank-body",width=w,minHeight=availableHeight, gap=0,backgroundColor=false,flexShrink=0,paddingBottom=0}) end return Screen