Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Metalhead33

Menusys

Recommended Posts

Hello everyone!
 
This is my very first post on the forum, and ho-boy, have I got some software library for you guys.
MenuSys.
 
So what exactly does MenuSys does, and why am I bragging about it like it's some great invention?
Well, because it's not  great invention at all. Quite the contrary. It is something anyone could have came up with, and in fact, it's entirely possible that someone has already created something similar, and I was just simply too lazy to check.
But okay, okay, enough bad jokes.
MenuSys basically gives programmers an easy way to implement menus by giving them an API that lets them define a bunch of menu options in a table, call the menu, and have a conditional branch based on what did they choose.
 
The best way to get MenuSys is via pastebin, although you'll net an InternetCard in your computer for that.

pastebin get 41g8zs6R menusys.lua

Put it somewhere you will find easily... like /lib or /usr/lib.

So how to use it?
First, you need to
 

local menusys = require("menusys")

Then you'll need a table. If you use only one dimension, you will call on the function displayMenu. If you use a two-dimensional array, you'll gonna use displayMenuMult.
 
Here is some demonstration with single-dimension tables:

local menusys = require("menusys")
local choices = { "1", "2", "3" }
while true do
    local x = menusys.displayMenu(choices,"Intro","Outro",1)
    if x == 0 then
        break
    end
end

Do note that Intro and Outro can be either text or function. Why function? Because that way, you can do graphical things before the menu is displayed.

 

And with two-dimension tables:
Here is some demonstration with single-dimension tables:

local menusys = require("menusys")
choice_state = {
    [1] = { false, false },
    [2] = { false, false },
}
 
 
 
function choice_concat(text,x,y)
if choice_state[x][y] == true then
    return text .. " " .. x .. "-" .. y .. " [ON]"
else
    return text .. " " .. x .. "-" .. y .. " [OFF]"
end
end
 
choices = { }
for xkey,xvalue in ipairs(choice_state) do
    choices[xkey] = { }
    for ykey,yvalue in ipairs(xvalue) do
        choices[xkey][ykey] = function() return choice_concat("NODE",xkey,ykey) end
    end
end
 
x = 1
y = 1
   
while true do
    x,y = menusys.displayMenuMult(choices,"Test Functions","Test Functions",x,y)
    if x == 0 then
        exit()
    else
        if choice_state[x][y] == true then
            choice_state[x][y] = false
            else choice_state[x][y] = true
        end
    end
end

It is also available for ComputerCraft.

MIT License

 

-----------

Copyright © 2016, Zsolt Tóth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.