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