This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
civilwargeeky's profile picture

Civil's Menu Api

Started by civilwargeeky, 01 October 2013 - 06:53 PM
civilwargeeky #1
Posted 01 October 2013 - 08:53 PM
Have you ever wanted to make an awesome program but didn't feel like putting a lot of work into designing a menu? Well now you don't have to! I've done that for you.

This program is an API that allows you to make scrollable menu's including a title, description, and all your options. There are many features that allow you to use the menu to your liking such as alignment and custom choice characters.

When you load this API, the functions it makes are "menu" and "titleize"

Features:
  • Makes well formatted, intuitive menus
  • Correctly handles arrow keys and the enter key
  • Scrollable options list for when you have more options than the size of your screen
  • Text Alignment! Align your text to the left, right, or center
  • Separate alignment options for Title and Options
  • Choice of whether options are numbered or not.
  • Custom left and right right selection indicators
  • Selection indicators can be any length, provided your options fit on the screen
  • Text does not shift around when selecting different options (this was actually really annoying… but I made it work :)/> )
  • Ability to have a different increment/decrement/enter function. You can either change keys or make it use redstone and much much more
  • A fun "title-ize" function
Coming Soon:
  • Text will not shift around when alignment is on center and selection indicators are of different lenghts
  • Ability to change color of text
Use:
Spoilermenu( string title, string description, table options, T/F is numbered, string title alignment, string options alignment, string left choice character, string right choice character, function increment/decrement function )
  1. Title: This is the title that will be displayed at the top of the menu [Necessary]
  2. Description: This will be displayed below the title and can be as big as you want it, provided it still allows for two options to be displayed at the bottom of the screen.
  3. Options: This is a numbered table that contains all the string options to be used by the menu. If you prefer to use text, function pairs to make acting off of this menu more easy, you can use the form "table.text" for your options. The menu function returns the number of item chosen, as well as the text that went along with it.
  4. Is numbered: If set to true (or nil) then it will print numbers before each option. If set to false it will not
  5. Title Alignment: left, right, or center [Default Center] This controls how the title and description will be aligned
  6. Options Alignment: left, right, or center [Default Left] This controls how the options will be aligned
  7. Left Choice Character: [Default "[" ] this is the character(s) that will be put on the left of the selected menu item
  8. Right Choice Character: [Default "]" ] Same as above, but with the right. Either/Both of these can be an empty string if you so desire
  9. Increment Decrement Function: This may be a function that returns "up", "down", or "enter" when called. By default, the function waits for a keypress and returns up if arrow up, down if arrow down, and enter if enter.
The function returns the number of the item chosen, as well as it's string value.

The titleize function takes a string and makes it all caps, surrounded by equal signs to the end of the page.

Download:
Version 1.0.0
http://pastebin.com/E4TJ2uCR


Here is an imgur album of a silly test I used for debugging. Just for you :D/>
http://imgur.com/a/QxvGq
Here is the code used in said album:
Spoiler
list = {"Apples", "Oranges", "Bananas", "Avocadoes",'a','b','c','d','g','u','t','g','y'}
a, b = menu(titleize("Fruit and Letter picker"), "What will you pick today?", list, false, nil, "center", "-->","<--")
term.clear(); term.setCursorPos(1,1)
print("You picked \""..list[a].."\"!!!")
sleep(2)
a,b = menu("Did you pick "..b.."?","Tell the truth now...",{"Yes, I picked "..b,"no"},false,left,center)
term.clear(); term.setCursorPos(1,1)
if b == "no" then print("liar!") else print("Good!") end


Fun video coming soon!
civilwargeeky #2
Posted 06 October 2013 - 10:46 AM
Could I please get some feedback? Or has this already been made before?
TheOddByte #3
Posted 06 October 2013 - 12:23 PM
I haven't tested it, But I thought my indenting was bad.. You should really indent the code since it's very hard to read .-.
civilwargeeky #4
Posted 06 October 2013 - 10:12 PM
I haven't tested it, But I thought my indenting was bad.. You should really indent the code since it's very hard to read .-.
But… But… It is indented. The only thing I do differently with my indenting is that the first block inside a function is not indented. I don't find it unnecessary to indent 100 lines if it's linear with no branching. It may as well be inside the main program.