I know there are many people much better than me at coding, but I decided to give it a shot.
I present: ComputerCrafter's Menu API also known as MenuAPI
Other APIs usually have a LOT of complicated features, but mine is very bare-bones, so don't expect much. :P
Here are all the functions and features:
-menu.indented: Selected items are indented+highlighted and the title has its own bar
-menu.notIndented: Selected items are not indented, but still highlighted. Title still has a bar
-menu.basic: Selected items not highlighted or indented, title has no bar and pointer is ">"
-menu.altPointers: Like notIndented() but with ">" as pointer, still highlights selected items
-menu.stallAny/menu.stallEnter: Press any key/enter to continue.
Functions in this API can be taken out and individually used in different files!
Screenshots:
(https://camo.tmpim.com/61c3f793d3213a7ae55e0a632c3489d86af6f022/68747470733a2f2f692e706f7374696d672e63632f706473376a3268742f323032342d30352d30392d31382d35312d31362e706e67)
(https://camo.tmpim.com/2a4c0e97f3bd725d3e5af0b3fb8f174d5f33e4e2/68747470733a2f2f692e706f7374696d672e63632f4d54584c626856662f696d6167652e706e67)
Usage:
os.loadAPI("menu.lua")
choices = {"This is a test of the API", "This API is made by ComputerCrafter", "Fun Fact: This API is over 100 lines long!", "Please use this in your projects to support it! :D"}
title = "menu.indented()"
actions = {}
actions[1] = function()
print("") --Your function
end
actions[2] = function()
print("") --Your function
end
actions[3] = function()
print("") --Your function
end
actions[4] = function()
print("") --Your function
end
menu.indented(title, choices, actions)
Your choices and actions are in tables with arrays going from [1] up.
Choice table array corresponds to actions table (eg. choices[1] executes actions[1])
Title is always written starting from 1, 1. (Bar or no bar depends on function)
Press any key/enter note is always written at last line.
Pastebin codes are here:
-MenuAPI: dv2mwm3V
-Demo: bAg3mDUM
Please leave feedback!
This is my first 'real' project that's longer than 200 lines.
I hope you all enjoy it! :D
PS. If you need help using it reply in the comments, it may be a bug because of my bad code.
Your code is great, however a few indentations might be done so you can better understand the code and how it works.
Overall, this is a great starter for people who want to make their own menu systems! Great work!