## [11.2] Litte Menu Engine

Showcase your libraries, tools and other projects that help your fellow love users.
Astorek86
Prole
Posts: 16
Joined: Fri Jul 13, 2018 7:35 pm

### [11.2] Litte Menu Engine

Hello @ all,

I've written a little Menu Engine and thought, it can be useful for others. So I share it here^^.

With this Menu Engine, it is possible to create a *dun dun duuun* Menu, that contains Entries which can be navigated & selected through Keyboard (WASD, Arrow-Keys, NumPad) and Mouse.

I've opened a github-Page for this (including a so-called API-Reference), which can be found here:
https://github.com/Astorek86/love2d-menuengine

Example Screenshot:

Sourcecode for this Example:

Code: Select all

local menuengine = require "menuengine"

local text = "Nothing was selected."

-- Mainmenu
local mainmenu

-- Start Game
local function start_game()
text = "Start Game was selected!"
end

-- Options
local function options()
text = "Options was selected!"
end

-- Quit Game
local function quit_game()
text = "Quit Game was selected!"
end

-- ----------

function love.load()
love.window.setMode(600,400)
love.graphics.setFont(love.graphics.newFont(20))

mainmenu = menuengine.new(200,100)
mainmenu:addEntry("Start Game", start_game)
mainmenu:addEntry("Options", options)
mainmenu:addSep()
mainmenu:addEntry("Quit Game", quit_game)
end

function love.update(dt)
mainmenu:update()
end

function love.draw()
love.graphics.clear()
love.graphics.print(text)
mainmenu:draw()
end

function love.keypressed(key, scancode, isrepeat)
menuengine.keypressed(scancode)

if scancode == "escape" then
love.event.quit()
end
end

function love.mousemoved(x, y, dx, dy, istouch)
menuengine.mousemoved(x, y)
end

More Screens
- Supports different Colors:

- Different Fonts, Sizes...

- ...and Positions for every Entry

- It can handle with LÖVE's scaling-Options:

- It works with Sound-Objects: One for Moving through the Menu, one for Selecting an Entry. Every Entry can have it's own Sound-Object.
- You can hide and unhide Entries on-the-fly as you wish.

Alle Examples can be found in the menu-examples.zip.

Feel free to comment, and if you found bugs, please tell it .
Attachments
menuengine-examples.zip
(48.72 KiB) Downloaded 100 times
love2d-menuengine.love
(7.31 KiB) Downloaded 104 times
Last edited by Astorek86 on Wed Jan 09, 2019 2:02 am, edited 5 times in total.

Мэтю
Prole
Posts: 31
Joined: Mon Jan 06, 2014 1:24 pm
Location: Espírito Santo, Brazil
Contact:

### Re: [11.1] Litte Menu Engine

Really cool and simple, nice work.
Just took a brief look at your code, and I saw you made the table menuengine global. What are the reasons about this choice?
Actually I'm not a very good programmer, I'm just used to use local variables almost all the time.
I'm going to use your library and give a more consistent feedback later
World needs love.

Astorek86
Prole
Posts: 16
Joined: Fri Jul 13, 2018 7:35 pm

### Re: [11.1] Litte Menu Engine

Thanks.
Мэтю wrote:
Wed Jul 18, 2018 1:38 pm
Just took a brief look at your code, and I saw you made the table menuengine global. What are the reasons about this choice?
Actually I'm not a very good programmer, I'm just used to use local variables almost all the time.
To be honest, I didn't fully understand how global and/or local Variable works in Lua (I'm not a beginner in Programming, but I am a Beginner in Lua^^). I've just updated a new version which doesn't use a global menuengine anymore^^. (I also replaced the Attachments on the 1st Post)
I'm going to use your library and give a more consistent feedback later
That's great, looking forward to hear about it.

Мэтю
Prole
Posts: 31
Joined: Mon Jan 06, 2014 1:24 pm
Location: Espírito Santo, Brazil
Contact:

### Re: [11.1] Litte Menu Engine

Quick update:
I used it briefly, and something I missed was passing an argument to the entry function. So, I made a pull request to your repository on github
You might review if it's suitable for your library xD
World needs love.

Astorek86
Prole
Posts: 16
Joined: Fri Jul 13, 2018 7:35 pm

### Re: [11.1] Litte Menu Engine

That's a good idea, I've just updated Github + Attachments; now it supports Arguments.

Code: Select all

-- before:
menu:addEntry(text, [func], [font], [colorNormal], [colorSelected])
-- now:
menu:addEntry(text, [func], [args], [font], [colorNormal], [colorSelected])


Thank you very much . I've totally forgotten that use case^^...

coolphill
Prole
Posts: 1
Joined: Mon Jan 07, 2019 1:59 am

### Re: [11.1] Litte Menu Engine

This menu engine is nice. I've been making my own now for a while. I'm kind of shock how you got the the feel and look I was trying to achieve with mine.

4vZEROv
Prole
Posts: 48
Joined: Wed Jan 02, 2019 8:44 pm

### Re: [11.1] Litte Menu Engine

You don't have to declare local i / local k , v when you do

for i = 0, 10 do ... end
&
for k,v in pairs(tbl) do ... end

### Who is online

Users browsing this forum: Google [Bot] and 6 guests