-- Update the displayMenu function function displayMenu(menu) local cursorX, cursorY =…
- User
-- Update the displayMenu function function displayMenu(menu) local cursorX, cursorY = getCursorPos() -- Current cursor position local isLMBDown = isKeyDown(1) local isRMBDown = isKeyDown(2) local currentDescription = "" local isArrowKeyDown = false local mouseWheelDelta = getMousewheelDelta() local isUArrowDown = isKeyDown(38) local isDArrowDown = isKeyDown(40) local isLArrowDown = isKeyDown(37) local isRArrowDown = isKeyDown(39) local isEnterDown = isKeyDown(13) local isBackspaceDown = isKeyDown(8)
codedrawText(menu.title, MENU_X, MENU_Y, MENU_TITLE_SIZE, MENU_COLOR, false) -- Check for arrow key inputs and update focusIndex accordingly if isUArrowDown and not wasUpArrowDown then focusIndex = math.max(1, focusIndex - 1) isArrowKeyDown = true elseif isDArrowDown and not wasDownArrowDown then focusIndex = math.min(#menu.items, focusIndex + 1) isArrowKeyDown = true end for i, item in ipairs(menu.items) do local itemY = MENU_Y + 10 + (MENU_ITEM_HEIGHT + MENU_ITEM_SPACING) * i local isHovered = isPointInArea(cursorX, cursorY, MENU_X, itemY, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT) -- Update focus based on mouse hover if no arrow keys were pressed if isHovered and not isArrowKeyDown then focusIndex = i end -- Determine whether this item is focused or hovered local isFocused = (i == focusIndex) drawText(item.label, MENU_X, itemY, 1, TEXT_COLOR, isFocused or isHovered) if isFocused then currentDescription = item.description if mouseWheelDelta ~= 0 and item.scrollAction then item.scrollAction(mouseWheelDelta, isShiftDown, isCtrlDown) elseif isLArrowDown and not wasLArrowDown and item.scrollAction then item.scrollAction(-1, isShiftDown, isCtrlDown) elseif isRArrowDown and not wasRArrowDown and item.scrollAction then item.scrollAction(1, isShiftDown, isCtrlDown) end if isLMBDown and not wasLMBDown or isEnterDown and not wasEnterDown then item.action() end end end -- Draw the current description under the last menu item local descriptionY = MENU_Y + 15 + (MENU_ITEM_HEIGHT + MENU_ITEM_SPACING) * (#menu.items + 1) drawText(currentDescription, MENU_X, descriptionY, DESCRIPTION_FONT_SIZE, DESCRIPTION_COLOR, false) -- Switch to parent menu if right mouse button is pressed or Backspace is pressed if (isRMBDown and not wasRMBDown or isBackspaceDown and not wasBackspaceDown) and menu.parent then currentMenu = menu.parent printStringNow("Switching to parent menu", 500) end wasUpArrowDown = isUArrowDown wasDownArrowDown = isDArrowDown wasLArrowDown = isLArrowDown wasRArrowDown = isRArrowDown wasLMBDown = isLMBDown wasRMBDown = isRMBDown wasEnterDown = isEnterDown wasBackspaceDown = isBackspaceDown - Assistant