MENU_BG_COLOR = "#00009977" MENU_BG_CHARACTER_COLOR = "#0a0a31" MENU_TEXT_COLOR = "#FFFFFF" MENU_SELECTED_BG_COLOR = "#99990077" MENU_SELECTED_TEXT_COLOR = "#FFFFFF" MENU_PAGE_SIZE = 10 MENU_PADDING = 2 clear_screen print_line = function( text, width, alignment, active) ntext = text + " "*(width-text.len-2) text_bg = MENU_BG_COLOR if active then text_bg = MENU_SELECTED_BG_COLOR print ""+ ""+ ""+ "ยท"+ " "+ ""+ ntext+ " "+ ""+ "-"+ "" end function my_clear_screen = function() print " ", 1 end function show_menu = function( title, choices, active_choice) my_clear_screen max_width = title.len active_choice = active_choice % choices.len for choice in choices if choice[1].len > max_width then max_width = choice[1].len end for menu_width = max_width+MENU_PADDING print_line( "", menu_width, "center") print_line( title, menu_width, "center", false) print_line( ""+" "*max_width+"", menu_width, "center", false) for choice in choices print_line( choice[1], menu_width, "center", choices[active_choice] == choice) end for print_line( "", menu_width, "center") print_line( ""+" "*max_width+"", menu_width, "center", false) end function menu = function( title, choices) page = 0 active = 0 max_page = floor(choices.len/10) while true display_title = title if max_page > 0 then display_title = "< "+ title +" ("+(page+1)+"/"+(max_page+1)+") >" end if show_menu( display_title, choices[page*MENU_PAGE_SIZE:(page+1)*MENU_PAGE_SIZE], active) wait 0.03 input = user_input( char(0), false, true) if input == "DownArrow" or input == "2" or input == "s" then active = active + 1 else if input == "UpArrow" or input == "8" or input == "w" then active = active - 1 else if input == "RightArrow" or input == "6" or input == "d" then page = (page + 1)%(max_page+1) else if input == "LeftArrow" or input == "4" or input == "a" then page = (max_page+page)%(max_page+1) else if input=="Escape" then exit else if input == " " or input.len == 0 then break else end if current_page_size = MENU_PAGE_SIZE if page == max_page then current_page_size = (choices.len%MENU_PAGE_SIZE) end if active = (current_page_size+active)%current_page_size last_page_size = (choices.len%MENU_PAGE_SIZE) end while return choices[active + page*MENU_PAGE_SIZE] end function