docs
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful

This commit is contained in:
2026-02-21 23:53:36 +01:00
parent 3b137fd48e
commit 76964f872d
28 changed files with 301 additions and 28 deletions

View File

@@ -1,12 +1,20 @@
--- Draws the top bar.
-- @param title string The title text to display.
function UI.draw_top_bar(title)
rect(0, 0, Config.screen.width, 10, Config.colors.dark_grey)
Print.text(title, 3, 2, Config.colors.green)
end
--- Draws dialog window.
function UI.draw_dialog()
PopupWindow.draw()
end
--- Draws a menu.
-- @param items table A table of menu items.
-- @param selected_item number The index of the currently selected item.
-- @param x number The x-coordinate for the menu.
-- @param y number The y-coordinate for the menu.
function UI.draw_menu(items, selected_item, x, y)
for i, item in ipairs(items) do
local current_y = y + (i-1)*10
@@ -17,6 +25,10 @@ function UI.draw_menu(items, selected_item, x, y)
end
end
--- Updates menu selection.
-- @param items table A table of menu items.
-- @param selected_item number The current index of the selected item.
-- @return number The updated index of the selected item.
function UI.update_menu(items, selected_item)
if Input.up() then
Audio.sfx_beep()
@@ -34,6 +46,10 @@ function UI.update_menu(items, selected_item)
return selected_item
end
--- Wraps text.
-- @param text string The text to wrap.
-- @param max_chars_per_line number The maximum characters per line.
-- @return table A table of wrapped lines.
function UI.word_wrap(text, max_chars_per_line)
if text == nil then return {""} end
local lines = {}
@@ -63,6 +79,15 @@ function UI.word_wrap(text, max_chars_per_line)
return lines
end
--- Creates a numeric stepper.
-- @param label string The label for the stepper.
-- @param value_getter function Function to get the current value.
-- @param value_setter function Function to set the current value.
-- @param min number The minimum value.
-- @param max number The maximum value.
-- @param step number The step increment.
-- @param[opt] format string The format string for displaying the value.
-- @return table A numeric stepper control definition.
function UI.create_numeric_stepper(label, value_getter, value_setter, min, max, step, format)
return {
label = label,
@@ -76,6 +101,10 @@ function UI.create_numeric_stepper(label, value_getter, value_setter, min, max,
}
end
--- Creates an action item.
-- @param label string The label for the action item.
-- @param action function The function to execute when the item is selected.
-- @return table An action item control definition.
function UI.create_action_item(label, action)
return {
label = label,
@@ -84,6 +113,9 @@ function UI.create_action_item(label, action)
}
end
--- Draws decision selector.
-- @param decisions table A table of decision items.
-- @param selected_decision_index number The index of the selected decision.
function UI.draw_decision_selector(decisions, selected_decision_index)
local bar_height = 16
local bar_y = Config.screen.height - bar_height
@@ -97,6 +129,7 @@ function UI.draw_decision_selector(decisions, selected_decision_index)
Print.text(decision_label, text_x, text_y, Config.colors.item) Print.text(">", Config.screen.width - 6, text_y, Config.colors.green) end
end
--- Draws meters.
function UI.draw_meters()
if not Context or not Context.game_in_progress or not Context.meters then return end
if Context.meters.hidden then return end
@@ -129,6 +162,10 @@ function UI.draw_meters()
end
end
--- Updates decision selector.
-- @param decisions table A table of decision items.
-- @param selected_decision_index number The current index of the selected decision.
-- @return number The updated index of the selected decision.
function UI.update_decision_selector(decisions, selected_decision_index)
if Input.left() then
Audio.sfx_beep()
@@ -138,4 +175,4 @@ function UI.update_decision_selector(decisions, selected_decision_index)
selected_decision_index = Util.safeindex(decisions, selected_decision_index + 1)
end
return selected_decision_index
end
end