From 4b972c3ae61b120825eb45a2fdbe45798f995993 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sun, 16 Aug 2026 11:50:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(display):=20=E4=BF=AE=E5=A4=8D=E6=97=B6?= =?UTF-8?q?=E5=88=BB=E8=A1=A8=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=9A=84=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将宽度阈值从 50 降低到 30,适配更小的 monitor - 重构 schedule.entries 解析逻辑:兼容非纯数字索引(用 pairs 收集后排序) - 修复视觉逻辑 bug:已到达站(浅灰) vs 未到达站(白) 颜色搞反 - 增加 schedule 为 nil/invalid 时的错误提示显示 - 增加调试日志输出 monitor 尺寸和提取到的站点数 - 版本号升级至 v1.0.65 --- station_broadcast.lua | 143 +++++++++++++++++++++++++----------------- 1 file changed, 87 insertions(+), 56 deletions(-) diff --git a/station_broadcast.lua b/station_broadcast.lua index 6f04ce9..ebe48c5 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -1,6 +1,6 @@ -- 1. Configuration & Constants -local APP_VERSION_TEXT = "v1.0.64" +local APP_VERSION_TEXT = "v1.0.65" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -1001,16 +1001,30 @@ function Utils.getNextStation(schedule, currentStationName) end function Utils.extractAllStationsFromSchedule(schedule) - if not schedule or not schedule.entries then return {} end - - local maxIdx = 0 - for k, _ in pairs(schedule.entries) do - if type(k) == "number" and k > maxIdx then maxIdx = k end + if not schedule then return {} end + local entries = schedule.entries or (type(schedule) == "table" and schedule) + if not entries or type(entries) ~= "table" then return {} end + + local ordered = {} + local numericKeys = {} + for k, v in pairs(entries) do + if type(k) == "number" then + table.insert(numericKeys, k) + end end - + if #numericKeys > 0 then + table.sort(numericKeys) + for _, k in ipairs(numericKeys) do + table.insert(ordered, entries[k]) + end + else + for _, v in pairs(entries) do + table.insert(ordered, v) + end + end + local stations = {} - for i = 1, maxIdx do - local entry = schedule.entries[i] + for i, entry in ipairs(ordered) do if entry and entry.instruction then local inst = entry.instruction if inst.id == "create:station" or inst.id == "create:destination" then @@ -1025,6 +1039,7 @@ function Utils.extractAllStationsFromSchedule(schedule) end end end + Utils.log("DEBUG", string.format("ExtractStations: found %d stations from %d schedule entries", #stations, #ordered)) return stations end @@ -2495,15 +2510,20 @@ function Display.render() local rightX = nil local rightW = 0 - if hasSchedulePanel and w >= 50 then - rightW = math.min(math.floor(w * 0.4), 40) + if hasSchedulePanel and w >= 30 then + rightW = math.min(math.max(math.floor(w * 0.38), 18), 40) leftW = w - rightW - 1 - sepX = leftW + 1 - rightX = sepX + 1 - leftW = math.max(leftW, 20) - rightW = math.max(rightW, 15) + if leftW < 12 then + leftW = w + rightW = 0 + else + sepX = leftW + 1 + rightX = sepX + 1 + end end + Utils.log("DEBUG", string.format("Monitor size W=%d H=%d, schedulePanel=%s leftW=%d rightW=%d", w, h, tostring(rightX ~= nil), leftW, rightW)) + local function classifyAudioSource(source, priority) local s = tostring(source or ""):lower() if s == "train" or s == "station" or s == "broadcast" then return "Station Announcement" end @@ -2591,53 +2611,64 @@ function Display.render() local scheduleStations = Utils.extractAllStationsFromSchedule(State.currentTrain.schedule) local currentStationBase = Utils.getBaseName(State.stationName) local currentStationCode = Utils.getStationCode(State.stationName) - local passedCurrent = false + local reachedCurrent = false local stationLineY = 4 - local maxStationLines = h - 3 - for idx, st in ipairs(scheduleStations) do - if stationLineY > h then break end - local stBase = Utils.getBaseName(st.name) - local stCode = Utils.getStationCode(st.name) - local isCurrentStation = false - if currentStationBase and currentStationBase ~= "" and stBase == currentStationBase then - isCurrentStation = true - elseif currentStationCode and currentStationCode ~= "" and stCode == currentStationCode then - isCurrentStation = true - elseif Utils.isFuzzyMatch(State.stationName, st.name) then - isCurrentStation = true - end - - local prefix = " " - local lineColor = COLORS.INFO - if isCurrentStation then - prefix = "> " - lineColor = COLORS.SUCCESS - passedCurrent = true - elseif passedCurrent then - prefix = " " - else - prefix = "* " - lineColor = colors.lightGray - end - - local suffix = "" - if st.isDestination then - suffix = " [END]" - lineColor = COLORS.WARNING - end - - local displayName = st.name - if isCurrentStation then - displayName = displayName .. " <<" - end - - drawRight(stationLineY, prefix .. displayName .. suffix, lineColor) + if State.currentTrain.schedule == nil then + drawRight(stationLineY, "Schedule: nil", COLORS.ERROR) + stationLineY = stationLineY + 1 + elseif type(State.currentTrain.schedule) ~= "table" then + drawRight(stationLineY, "Schedule: invalid type", COLORS.ERROR) stationLineY = stationLineY + 1 end if #scheduleStations == 0 then - drawRight(4, "No station data", COLORS.WARNING) + drawRight(stationLineY, "(No station entries)", COLORS.WARNING) + else + for idx, st in ipairs(scheduleStations) do + if stationLineY > h then break end + local stBase = Utils.getBaseName(st.name) + local stCode = Utils.getStationCode(st.name) + local isCurrentStation = false + if currentStationBase and currentStationBase ~= "" and stBase == currentStationBase then + isCurrentStation = true + elseif currentStationCode and currentStationCode ~= "" and stCode == currentStationCode then + isCurrentStation = true + elseif Utils.isFuzzyMatch(State.stationName, st.name) then + isCurrentStation = true + end + + if isCurrentStation then + reachedCurrent = true + end + + local prefix = " " + local lineColor = COLORS.INFO + if isCurrentStation then + prefix = "> " + lineColor = COLORS.SUCCESS + elseif reachedCurrent then + prefix = " " + lineColor = colors.lightGray + else + prefix = "* " + lineColor = COLORS.INFO + end + + local suffix = "" + if st.isDestination then + suffix = " [END]" + lineColor = COLORS.WARNING + end + + local displayName = st.name + if isCurrentStation then + displayName = displayName .. " <<" + end + + drawRight(stationLineY, prefix .. displayName .. suffix, lineColor) + stationLineY = stationLineY + 1 + end end end else