local UI = require("urhox-libs/UI") local W = require("Game/UI/Widgets") local Skin = require("Game/UI/HomeSkin") local Dispatch = require("Game/UI/Dispatch") local Screen = {} ---@param a any ---@param k number ---@return Panel local function currentOrder(a,k) ---@type any local model=Dispatch.Order(a) local card=Skin.Surface(844,264,k,{id="home-current-order"}) card:AddChild(Skin.Plaque("当前镖单",24,-36,k)) card:AddChild(Skin.Image("cart",35,39,133,118,k)) card:AddChild(Skin.Button(191,20,430,132,k,model.details,{id="business-picker"})) card:AddChild(Skin.Label(model.title,201,41,420,48,34,k,{id="home-order-title"})) local prefix="押运报酬:银两 " local prefixWidth=UI.MeasureTextWidth(prefix,30*k,"home-ink")/k card:AddChild(Skin.Label(prefix,201,96,prefixWidth,46,30,k)) card:AddChild(Skin.Number(W.Number(model.reward),201+prefixWidth,96,420-prefixWidth,46,30,k, {id="home-order-reward"})) card:AddChild(Skin.Secondary("调整队伍",645,64,k,function() a:Open("team") end,{id="team-picker"})) card:AddChild(Skin.Primary(model.actionLabel,79,163,k,model.start, {id=model.actionId,disabled=model.disabled})) return card end ---@param a any ---@param run any ---@param k number ---@return Panel local function inTransit(a,run,k) local card=Skin.Surface(844,199,k,{id=run and "home-run-"..run.id or "home-no-runs"}) card:AddChild(Skin.Plaque("在途镖队",24,-10,k)) card:AddChild(Skin.Image("cart",35,67,133,118,k)) if not run then card:AddChild(Skin.Label("暂无在途镖队",196,65,610,48,34,k,{id="home-run-empty"})) card:AddChild(Skin.Label("整备队伍,接下一趟好生意",196,118,610,42,25,k,{fontColor="#806346"})) return card end local name=run.bizName or (a.engine.runBusiness(run) or {}).name or "镖队在途" if run.cityGoalId then for _,city in ipairs(a.engine.CITY_CONTRACTS) do if city.id==run.cityGoalId then name=city.name.." · "..(run.cityKind=="contract" and city.ability or run.cityKind=="open" and "首批货物" or "短途押运") break end end end card:AddChild(Skin.Button(180,50,650,125,k,function() a:Open("run-detail",{run=run}) end, {id="run-detail-"..run.id})) card:AddChild(Skin.Label(name,196,65,420,48,34,k)) local bar=UI.ProgressBar(Skin.Box(197,130,417,20,k,{id="home-progress-"..run.id, value=0,fillColor="#5c9f93",trackBgColor="#cfb490",borderRadius=10*k,showLabel=false, borderWidth=0,pointerEvents="none"})) card:AddChild(bar) local prefix=Skin.Label("剩余 ",635,101,75,45,30,k) local number=Skin.Number("",704,101,90,45,30,k) local suffix=Skin.Label("秒",790,101,34,45,30,k) local status=Skin.Label("",635,101,190,45,27,k) card:AddChild(prefix) card:AddChild(number) card:AddChild(suffix) card:AddChild(status) local lastValue="" local function update(r) local active=not r.done and not r.paused prefix:SetVisible(active) number:SetVisible(active) suffix:SetVisible(active) status:SetVisible(not active) if active then local text=tostring(math.max(0,math.ceil(r.duration*r.effects.time-r.elapsed))) if text~=lastValue then lastValue=text number:SetText(text) local left=635+UI.MeasureTextWidth("剩余 ",30*k,"home-ink")/k local width=UI.MeasureTextWidth(text,30*k,"biaoju")/k number:SetStyle({left=left*k,width=width*k}) suffix:SetStyle({left=(left+width)*k}) end else status:SetText(r.done and "等待交割" or "途中待决定") end bar:SetValue(math.min(1,r.elapsed/math.max(0.001,r.duration*r.effects.time))) end update(run) a.progressWidgets[run.id]={label=status,bar=bar,update=update} return card end ---@param a any function Screen.OpenRoad(a) 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 ---@param a any ---@param w number ---@param availableHeight number ---@param k number ---@return Widget function Screen.Content(a,w,availableHeight,k) if a.cityPicker then return UI.Panel {width=w,minHeight=availableHeight,gap=0,backgroundColor=false,children={ UI.Panel {height=math.min(300*k,availableHeight*0.28),pointerEvents="none"}, UI.Panel {width="100%",padding=20*k,children={Dispatch.CityPicker(a)}}, }} end local count=math.max(1,#a.state.runs) local fixed=264+34+count*199+(count-1)*34+29+139+21 local height=math.max(availableHeight,(fixed+360)*k) local spacer=height-fixed*k ---@type Widget[] local children={UI.Panel {id="home-scene-space",height=spacer,pointerEvents="none"}, currentOrder(a,k),UI.Panel {height=34*k,pointerEvents="none"}} if #a.state.runs==0 then children[#children+1]=inTransit(a,nil,k) else for i,run in ipairs(a.state.runs) do if i>1 then children[#children+1]=UI.Panel {height=34*k,pointerEvents="none"} end children[#children+1]=inTransit(a,run,k) end end children[#children+1]=UI.Panel {height=29*k,pointerEvents="none"} children[#children+1]=UI.Panel {id="home-shortcuts",width=844*k,height=139*k, flexDirection="row",justifyContent="space-between",children={ Skin.Shortcut("scroll","商路开拓",k,function() Screen.OpenRoad(a) end,{id="home-city-road"}), Skin.Shortcut("steward",a.autoOn and "托管中" or "掌柜托管",k,function() a:Open("auto") end,{id="auto-settings"}), }} children[#children+1]=UI.Panel {height=21*k,pointerEvents="none"} return UI.Panel {id="home-body",width=w,height=height,alignItems="center",gap=0, backgroundColor=false,children=children} end return Screen