[11.1] Litte Menu Engine

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

[11.1] Litte Menu Engine

Post by Astorek86 » Tue Jul 17, 2018 8:40 pm

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:
Image

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:
Image

- Different Fonts, Sizes...
Image

- ...and Positions for every Entry
Image

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

- 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 25 times
love2d-menuengine.love
(7.31 KiB) Downloaded 27 times
Last edited by Astorek86 on Thu Jul 26, 2018 9:30 pm, edited 4 times in total.

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

Re: [11.1] Litte Menu Engine

Post by Мэтю » Wed Jul 18, 2018 1:38 pm

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: 14
Joined: Fri Jul 13, 2018 7:35 pm

Re: [11.1] Litte Menu Engine

Post by Astorek86 » Thu Jul 19, 2018 2:02 pm

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. :)

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

Re: [11.1] Litte Menu Engine

Post by Мэтю » Tue Jul 24, 2018 2:02 am

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: 14
Joined: Fri Jul 13, 2018 7:35 pm

Re: [11.1] Litte Menu Engine

Post by Astorek86 » Thu Jul 26, 2018 9:37 pm

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^^...

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests