diff --git a/inc/system/system.ui.lua b/inc/system/system.ui.lua index 5a371b7..e9f0cd4 100644 --- a/inc/system/system.ui.lua +++ b/inc/system/system.ui.lua @@ -12,9 +12,19 @@ end --- @within UI --- @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 x number The x-coordinate for the menu (ignored if centered is true).
--- @param y number The y-coordinate for the menu.
-function UI.draw_menu(items, selected_item, x, y) +--- @param[opt] centered boolean Whether to center the menu block horizontally. Defaults to false.
+function UI.draw_menu(items, selected_item, x, y, centered) + if centered then + local max_w = 0 + for _, item in ipairs(items) do + local w = print(item.label, 0, -10, 0, false, 1, false) + if w > max_w then max_w = w end + end + x = (Config.screen.width - max_w) / 2 + end + for i, item in ipairs(items) do local current_y = y + (i-1)*10 if i == selected_item then diff --git a/inc/window/window.menu.lua b/inc/window/window.menu.lua index dce2118..23517a8 100644 --- a/inc/window/window.menu.lua +++ b/inc/window/window.menu.lua @@ -4,8 +4,15 @@ local _menu_items = {} --- Draws the menu window. --- @within MenuWindow function MenuWindow.draw() - UI.draw_top_bar("Main Menu") - UI.draw_menu(_menu_items, Context.current_menu_item, 108, 70) + UI.draw_top_bar("Definitely not an Impostor") + + local menu_h = #_menu_items * 10 + local y = 10 + (Config.screen.height - 10 - 10 - menu_h) / 2 + UI.draw_menu(_menu_items, Context.current_menu_item, 0, y, true) + + local ttg_text = "TTG" + local ttg_w = print(ttg_text, 0, -10, 0, false, 1, false) + Print.text(ttg_text, Config.screen.width - ttg_w - 5, Config.screen.height - 10, Config.colors.light_blue) end --- Updates the menu window logic.