Skip to content

Commit

Permalink
#403 guide lists
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaylaFischler committed Aug 29, 2024
1 parent 097edc5 commit 3c10e28
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 17 deletions.
23 changes: 23 additions & 0 deletions pocket/ui/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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.")
Expand Down
68 changes: 51 additions & 17 deletions pocket/ui/pages/guide_section.lua
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -40,24 +47,51 @@ 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 anchor = TextBox{parent=def_list,text=item.name,anchor=true,fg_bg=cpair(colors.blue,colors.black)}
TextBox{parent=def_list,text=item.desc}
_end = Div{parent=def_list,height=1,can_focus=true}

local function view()
_end.focus()
view_page.nav_to()
anchor.focus()
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}
_end = Div{parent=def_list,height=1,can_focus=true}

local function view()
_end.focus()
view_page.nav_to()
anchor.focus()
end

doc_map[item.key] = view
table.insert(search_db, { string.lower(item.name), item.name, title, view })

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

doc_map[item.key] = view
table.insert(search_db, { string.lower(item.name), item.name, title, view })

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
end

log.debug("guide section " .. title .. " generated with final height ".. _end.get_y())
Expand Down

0 comments on commit 3c10e28

Please sign in to comment.