fix: 发车音乐列表过长时自动换行显示,修复 UI 溢出重叠问题

This commit is contained in:
2026-08-04 13:13:03 +08:00
parent d8eee041c8
commit 8f70c1f1d3
+55 -24
View File
@@ -1,6 +1,6 @@
-- 1. Configuration & Constants -- 1. Configuration & Constants
local APP_VERSION_TEXT = "v1.0.59" local APP_VERSION_TEXT = "v1.0.60"
local CONFIG = { local CONFIG = {
CLOUD_URL = "ws://stabadmin.fse-media.group", CLOUD_URL = "ws://stabadmin.fse-media.group",
@@ -252,8 +252,19 @@ function Utils.promptSlaveIdentity()
State.inConfig = true State.inConfig = true
while true do while true do
local availBeeps = Utils.getAvailableDepartureBeeps() local availBeeps = Utils.getAvailableDepartureBeeps()
local availStr = table.concat(availBeeps, ", ") local availLines = {}
if #availStr > 40 then availStr = availStr:sub(1, 37) .. "..." end local currentLine = ""
for i, beep in ipairs(availBeeps) do
if #currentLine + #beep + 2 > 48 then
table.insert(availLines, currentLine)
currentLine = beep .. ", "
else
currentLine = currentLine .. beep .. ", "
end
end
if #currentLine > 0 then
table.insert(availLines, currentLine:sub(1, -3))
end
term.setBackgroundColor(colors.black) term.setBackgroundColor(colors.black)
term.setTextColor(colors.white) term.setTextColor(colors.white)
@@ -274,10 +285,14 @@ function Utils.promptSlaveIdentity()
term.setCursorPos(1, 10) term.setCursorPos(1, 10)
term.setTextColor(colors.gray) term.setTextColor(colors.gray)
term.write("Available beeps:") term.write("Available beeps:")
term.setCursorPos(1, 11) local nextY = 11
term.write(availStr) for _, l in ipairs(availLines) do
term.setCursorPos(1, nextY)
term.write(l)
nextY = nextY + 1
end
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setCursorPos(1, 13) term.setCursorPos(1, nextY)
term.write("Departure beep (e.g. fc1): ") term.write("Departure beep (e.g. fc1): ")
term.setCursorPos(30, 6) term.setCursorPos(30, 6)
@@ -287,25 +302,25 @@ function Utils.promptSlaveIdentity()
term.setCursorPos(31, 8) term.setCursorPos(31, 8)
local stationPlatform = Utils.trim(read() or "") local stationPlatform = Utils.trim(read() or "")
term.setCursorPos(32, 13) term.setCursorPos(32, nextY)
local departureBeep = Utils.trim(read() or "") local departureBeep = Utils.trim(read() or "")
if departureBeep == "" then departureBeep = "fc1" end if departureBeep == "" then departureBeep = "fc1" end
if stationCode == "" or stationPlatform == "" then if stationCode == "" or stationPlatform == "" then
term.setCursorPos(1, 15) term.setCursorPos(1, nextY + 2)
term.setTextColor(colors.red) term.setTextColor(colors.red)
term.write("Both station code and platform are required.") term.write("Both station code and platform are required.")
term.setCursorPos(1, 16) term.setCursorPos(1, nextY + 3)
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
term.write("Press any key to retry...") term.write("Press any key to retry...")
os.pullEvent("key") os.pullEvent("key")
else else
local ok = Utils.saveStationIdentity(stationCode, stationPlatform, departureBeep) local ok = Utils.saveStationIdentity(stationCode, stationPlatform, departureBeep)
if ok then if ok then
term.setCursorPos(1, 12) term.setCursorPos(1, nextY + 2)
term.setTextColor(colors.green) term.setTextColor(colors.green)
term.write("Saved to " .. CONFIG.STATION_IDENTITY_FILE) term.write("Saved to " .. CONFIG.STATION_IDENTITY_FILE)
term.setCursorPos(1, 14) term.setCursorPos(1, nextY + 3)
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
term.write("Press any key to continue...") term.write("Press any key to continue...")
os.pullEvent("key") os.pullEvent("key")
@@ -315,10 +330,10 @@ function Utils.promptSlaveIdentity()
State.inConfig = false State.inConfig = false
return true return true
end end
term.setCursorPos(1, 12) term.setCursorPos(1, nextY + 2)
term.setTextColor(colors.red) term.setTextColor(colors.red)
term.write("Failed to save " .. CONFIG.STATION_IDENTITY_FILE) term.write("Failed to save " .. CONFIG.STATION_IDENTITY_FILE)
term.setCursorPos(1, 14) term.setCursorPos(1, nextY + 3)
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
term.write("Press any key to retry...") term.write("Press any key to retry...")
os.pullEvent("key") os.pullEvent("key")
@@ -335,8 +350,19 @@ function Utils.promptConfig()
while true do while true do
local availBeeps = Utils.getAvailableDepartureBeeps() local availBeeps = Utils.getAvailableDepartureBeeps()
local availStr = table.concat(availBeeps, ", ") local availLines = {}
if #availStr > 40 then availStr = availStr:sub(1, 37) .. "..." end local currentLine = ""
for i, beep in ipairs(availBeeps) do
if #currentLine + #beep + 2 > 48 then
table.insert(availLines, currentLine)
currentLine = beep .. ", "
else
currentLine = currentLine .. beep .. ", "
end
end
if #currentLine > 0 then
table.insert(availLines, currentLine:sub(1, -3))
end
term.setBackgroundColor(colors.black) term.setBackgroundColor(colors.black)
term.setTextColor(colors.white) term.setTextColor(colors.white)
@@ -362,11 +388,16 @@ function Utils.promptConfig()
term.setCursorPos(1, 10) term.setCursorPos(1, 10)
term.setTextColor(colors.gray) term.setTextColor(colors.gray)
term.write("Available beeps:") term.write("Available beeps:")
term.setCursorPos(1, 11) local nextY = 11
term.write(availStr) for _, l in ipairs(availLines) do
term.setCursorPos(1, nextY)
term.write(l)
nextY = nextY + 1
end
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setCursorPos(1, 13) term.setCursorPos(1, nextY)
term.write("Departure beep [" .. currentBeep .. "]: ") local promptBeepStr = "Departure beep [" .. currentBeep .. "]: "
term.write(promptBeepStr)
term.setCursorPos(30, 6) term.setCursorPos(30, 6)
term.setTextColor(colors.cyan) term.setTextColor(colors.cyan)
@@ -377,17 +408,17 @@ function Utils.promptConfig()
local platformInput = Utils.trim(read() or "") local platformInput = Utils.trim(read() or "")
if platformInput == "" then platformInput = currentPlatform end if platformInput == "" then platformInput = currentPlatform end
term.setCursorPos(32, 13) term.setCursorPos(#promptBeepStr + 1, nextY)
local beepInput = Utils.trim(read() or "") local beepInput = Utils.trim(read() or "")
if beepInput == "" then beepInput = currentBeep end if beepInput == "" then beepInput = currentBeep end
local ok = Utils.saveStationIdentity(codeInput, platformInput, beepInput) local ok = Utils.saveStationIdentity(codeInput, platformInput, beepInput)
if ok then if ok then
Utils.refreshStationIdentity() Utils.refreshStationIdentity()
term.setCursorPos(1, 15) term.setCursorPos(1, nextY + 2)
term.setTextColor(colors.green) term.setTextColor(colors.green)
term.write("Configuration saved.") term.write("Configuration saved.")
term.setCursorPos(1, 16) term.setCursorPos(1, nextY + 3)
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
term.write("Press any key to return...") term.write("Press any key to return...")
os.pullEvent("key") os.pullEvent("key")
@@ -397,10 +428,10 @@ function Utils.promptConfig()
State.inConfig = false State.inConfig = false
break break
else else
term.setCursorPos(1, 15) term.setCursorPos(1, nextY + 2)
term.setTextColor(colors.red) term.setTextColor(colors.red)
term.write("Failed to save configuration.") term.write("Failed to save configuration.")
term.setCursorPos(1, 16) term.setCursorPos(1, nextY + 3)
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
term.write("Press any key to retry...") term.write("Press any key to retry...")
os.pullEvent("key") os.pullEvent("key")