#403 guide lists

This commit is contained in:
Mikayla 2024-08-29 01:19:26 +00:00
parent 097edc5bf9
commit 3c10e28d03
2 changed files with 72 additions and 15 deletions

View File

@ -2,14 +2,36 @@ local const = require("scada-common.constants")
local docs = {}
---@enum DOC_LIST_TYPE
local DOC_LIST_TYPE = {
BULLET = 1,
NUMBERED = 2,
INDICATOR = 3,
LED = 4
}
docs.DOC_LIST_TYPE = DOC_LIST_TYPE
local target
---@param key string item identifier for linking
---@param name string item name for display
---@param desc string text body
local function doc(key, name, desc)
---@class pocket_doc_item
local item = { key = key, name = name, desc = desc }
table.insert(target, item)
end
---@param type DOC_LIST_TYPE
---@param items table
---@param colors table|nil colors for indicators or nil for normal lists
local function list(type, items, colors)
---@class pocket_doc_list
local list_def = { type = type, items = items, colors = colors }
table.insert(target, list_def)
end
-- important to note in the future: The PLC should always be in a chunk with the reactor to ensure it can protect it on chunk load if you do not keep it all chunk loaded
docs.alarms = {}
@ -110,6 +132,7 @@ doc("fp_status", "STATUS", "This is always lit, except on the Reactor PLC. For t
doc("fp_heartbeat", "HEARTBEAT", "This alternates between lit and unlit as the main loop on the device runs. If this freezes, something is wrong and the logs will indicate why.")
doc("fp_modem", "MODEM", "This lights up if the wireless/ender modem is connected. In parentheses is the unique computer ID of this device, which will show up in places such as the supervisor's connection lists.")
doc("fp_modem", "NETWORK", "This is present when in standard color modes and indicates the network status using multiple colors. Off is no link, green is linked, red is link denied, orange is mismatching comms versions, and yellow is Reactor PLC-specific, indicating a unit ID collision (duplicate unit IDs in use).")
list(DOC_LIST_TYPE.LED, { "not linked", "linked" }, { colors.gray, colors.green })
doc("fp_nt_linked", "NT LINKED", "(color accessibility modes only) This lights up once the device is linked to the supervisor.")
doc("fp_nt_version", "NT VERSION", "(color accessibility modes only) This lights up if the communications versions of the supervisor and this device do not match. Make sure everything is up-to-date.")
doc("fp_fw", "FW", "Firmware application version of this device.")

View File

@ -1,6 +1,8 @@
local log = require("scada-common.log")
local util = require("scada-common.util")
local docs = require("pocket.ui.docs")
local core = require("graphics.core")
local Div = require("graphics.elements.div")
@ -9,9 +11,14 @@ local TextBox = require("graphics.elements.textbox")
local PushButton = require("graphics.elements.controls.push_button")
local IndicatorLight = require("graphics.elements.indicators.light")
local LED = require("graphics.elements.indicators.led")
local ALIGN = core.ALIGN
local cpair = core.cpair
local LIST_TYPE = docs.DOC_LIST_TYPE
-- new guide documentation section
---@param data _guide_section_constructor_data
---@param base_page nav_tree_page
@ -40,7 +47,10 @@ return function (data, base_page, title, items, scroll_height)
local _end
for i = 1, #items do
local item = items[i] ---@type pocket_doc_item
local item = items[i] ---@type pocket_doc_item|pocket_doc_list
if item.type == nil then
---@cast item pocket_doc_item
local anchor = TextBox{parent=def_list,text=item.name,anchor=true,fg_bg=cpair(colors.blue,colors.black)}
TextBox{parent=def_list,text=item.desc}
@ -58,6 +68,30 @@ return function (data, base_page, title, items, scroll_height)
PushButton{parent=name_list,text=item.name,fg_bg=cpair(colors.blue,colors.black),active_fg_bg=btn_active,callback=view}
if i % 12 == 0 then util.nop() end
else
---@cast item pocket_doc_list
if item.type == LIST_TYPE.BULLET then
for _, li in ipairs(item.items) do
TextBox{parent=def_list,x=2,text="\x07 "..li}
end
elseif item.type == LIST_TYPE.NUMBERED then
local width = string.len("" .. #item.items)
for idx, li in ipairs(item.items) do
TextBox{parent=def_list,x=2,text=util.sprintf("%" .. width .. "d. %s", idx, li)}
end
elseif item.type == LIST_TYPE.INDICATOR then
for idx, li in ipairs(item.items) do
local _ = IndicatorLight{parent=def_list,x=2,label=li,colors=cpair(colors.black,item.colors[idx])}
end
elseif item.type == LIST_TYPE.LED then
for idx, li in ipairs(item.items) do
local _ = LED{parent=def_list,x=2,label=li,colors=cpair(colors.black,item.colors[idx])}
end
end
local _ = Div{parent=def_list,height=1}
end
end
log.debug("guide section " .. title .. " generated with final height ".. _end.get_y())