local UI = require("urhox-libs/UI") local W = require("Game/UI/Widgets") local Support = require("Game/RuleSupport") local Skin = require("Game/UI/HomeSkin") local Home = {} local art = Skin.Root.."images/" function Home.Scale() return math.min(graphics:GetWidth()/UI.GetScale(),680)/440 end ---@param name string ---@param size number ---@param props? table ---@return Widget function Home.Icon(name,size,props) return Skin.Image(name,0,0,size,size,1,Support.assign({position="relative"},props or {})) end ---@param text any ---@param size number ---@param props? table ---@return Label function Home.Text(text,size,props) return W.Label(text,Support.assign({fontFamily="biaoju",fontSize=size*Home.Scale()*0.8, fontColor="#402c1e",lineHeight=1.25},props or {})) end ---@param title string ---@param children Widget[] ---@param props? table ---@return Panel function Home.Card(title,children,props) local k=Home.Scale() local items={UI.Panel {width=124*k,height=30*k,marginTop=-23*k,marginBottom=3*k, backgroundImage=art.."ribbon.png",backgroundFit="fill",alignItems="center",justifyContent="center", children={Home.Text(title,18,{fontColor="#fff1cf",fontWeight="bold"})}}} for _,child in ipairs(children) do items[#items+1]=child end return W.Column(items,Support.assign({padding=14*k,paddingTop=14*k,marginTop=12*k,gap=8*k, backgroundColor="#f3dfb9",backgroundImage=art.."paper.png",borderColor="#bd925f", borderWidth=1.5,borderRadius=7*k,boxShadow={{x=0,y=3,blur=5,color={53,32,12,45}}}},props or {})) end ---@param text string ---@param action function ---@param props? table ---@return Button function Home.Primary(text,action,props) local k=Home.Scale() return W.Button(text,action,Support.assign({fontFamily="biaoju",fontWeight="bold",fontSize=20*k, height=48*k,minHeight=44,paddingVertical=5*k,backgroundColor="#ab422d", backgroundImage=art.."primary.png",hoverBackgroundColor="#bc5134",pressedBackgroundColor="#853321", textColor="#fff0cb",disabledTextColor="#82694b",disabledBackgroundColor="#dfc8a3", disabledBackgroundImageOpacity=0.25,borderColor="#ba7047",borderWidth=1,borderRadius=3*k},props or {})) end ---@param text string ---@param action function ---@param props? table ---@return Button function Home.Secondary(text,action,props) local k=Home.Scale() return W.Secondary(text,action,Support.assign({fontFamily="biaoju",fontSize=11*k,height=34*k, minHeight=32,paddingHorizontal=8*k,paddingVertical=4*k,backgroundColor="#efdab4", hoverBackgroundColor="#e7c897",pressedBackgroundColor="#d9b782",textColor="#65432b", borderWidth=1,borderColor="#bc9466",borderRadius=3*k},props or {})) end ---@param a any ---@return Panel function Home.Header(a) local w,_,k=Skin.Metrics() local s,E=a.state,a.engine local rank=s and E.rankInfo(s) or nil local function currency(value) if not value then return "—" end return value>=1000000 and W.Big(value) or W.Number(value) end return UI.Panel {id="home-header",width=w,height=120*k,flexShrink=0,backgroundColor=false,children={ Skin.Paper(883,120,k,{position="absolute",left=0,top=0}), Skin.Image("portrait",28,9,105,105,k), Skin.Label("长风镖局",147,18,190,50,40,k), Skin.Label(rank and rank.rank.name or "新镖局",149,69,185,36,27,k,{fontColor="#805c3e"}), UI.Panel(Skin.Box(342,29,1.5,73,k,{backgroundColor="#bc9971",pointerEvents="none"})), Skin.Image("silver",392,32,46,34,k), Skin.Label("银两",442,32,80,39,27,k), Skin.Number(currency(s and s.silver),395,70,145,38,30,k,{id="home-silver"}), Skin.Image("prestige",566,24,42,48,k), Skin.Label("可用声望",612,31,150,40,27,k), Skin.Image("people",567,75,38,29,k), Skin.Number(currency(s and s.prestige),630,70,130,38,30,k,{id="home-prestige"}), Skin.Button(783,17,84,84,k,function() a:Open("menu") end,{id="game-menu",children={ Skin.Image("gear",12,12,60,60,k)}}), }} end ---@return Panel function Home.Courtyard() local w,h,k=Skin.Metrics() return Skin.Courtyard(w,h,k) end ---@param a any ---@param pages table ---@return Panel function Home.Navigation(a,pages) local w,_,k=Skin.Metrics() ---@type number[] local starts={0,175,316,457,598,739} ---@type number[] local widths={175,141,141,141,141,144} ---@type Widget[] local children={Skin.Paper(883,172,k,{position="absolute",left=0,top=0})} for i,pair in ipairs(pages) do local key,title=pair[1],pair[2] local active=a.page==key local width=widths[i] ---@type Widget[] local contents={} if active then contents[#contents+1]=Skin.Image("selected-brush",0,0,width,160,k,{objectFit="fill"}) end contents[#contents+1]=Skin.Image(key,(width-96)/2,16,96,96,k) contents[#contents+1]=Skin.Label(title,0,118,width,40,31,k, {textAlign="center",fontColor=active and "#9b3825" or "#503720"}) children[#children+1]=Skin.Button(starts[i],7,width,160,k,function() a:SetPage(key) end, {id="nav-"..key,children=contents}) end return UI.Panel {id="home-navigation",width=w,height=172*k,flexShrink=0, backgroundColor=false,padding=0,children=children} end ---@param a any ---@return Panel function Home.Shortcuts(a) local k=Home.Scale() local function shortcut(icon,text,id,action) return W.Button("",action,{id=id,width="auto",flexGrow=1,flexBasis=0,minWidth=0,height=66*k, paddingHorizontal=8*k,paddingVertical=5*k,borderColor="#ba946b",borderWidth=1,borderRadius=5*k, backgroundColor="#f2dfbd",backgroundImage=art.."paper.png",hoverBackgroundColor="#ecd1a5", pressedBackgroundColor="#dcb982",boxShadow=false,children={W.Row({Home.Icon(icon,48*k), Home.Text(text,17,{fontWeight="bold",flexGrow=1,flexBasis=0,minWidth=0}), Home.Text("›",29,{fontColor="#9c452d",width=14*k})}, {height="100%",gap=5*k,pointerEvents="none"})}}) end return W.Row({shortcut("road","商路开拓","home-city-road",function() if #a.state.runs>0 then a:Toast("镖队归来后再安排商路开拓") return end if a.engine.cityGoal(a.state) then a:Open("road-progress") else a.cityPicker=true a:Invalidate() end end),shortcut("steward",a.autoOn and "托管中" or "掌柜托管","auto-settings",function() a:Open("auto") end)}, {gap=10*k,marginTop=4*k}) end return Home