[Release] WarMenu - Lua Menu Framework

WarMenu

Inspired by Dear ImGui and GTA V menu system

Download the latest version or git clone it

How to Install

  1. Place it to /resources folder
  2. Add ensure warmenu to your server.cfg
  3. Add client_script '@warmenu/warmenu.lua' to your fxmanifest.lua

Features

  • Backward compatibility
  • GTA V-like look’n’feel
  • Rich menu style customization
  • Lots of built-in controls
  • Demo menu

Demo menu

You can read its source code to understand how framework works
To run it, just add client_script @warmenu/warmenu_demo.lua to any of your resources which are using WarMenu

API

--- * - optional parameters
WarMenu.CreateMenu(id, title, subTitle*, style*)
WarMenu.CreateSubMenu(id, parent, subTitle*, style*)

WarMenu.CurrentMenu() -- id

WarMenu.OpenMenu(id)
WarMenu.IsMenuOpened(id)
WarMenu.IsAnyMenuOpened()
WarMenu.IsMenuAboutToBeClosed() -- return true if current menu will be closed in next frame
WarMenu.CloseMenu()

-- Controls
WarMenu.Button(text, subText*)
WarMenu.InputButton(text, windowTitleEntry*, defaultText*, maxLength*, subText*)
WarMenu.SpriteButton(text, dict, name, r*, g*, b*, a*)
WarMenu.MenuButton(text, id, subText*)
WarMenu.CheckBox(text, checked)
WarMenu.ComboBox(text, items, currentIndex)
WarMenu.ToolTip(text, width*, flipHorizontal*)
-- Use them in loop to draw
-- They return true if were selected OR you can use functions below for more granual control
WarMenu.IsItemHovered()
WarMenu.IsItemSelected()
-- See Usage section for more details

WarMenu.End() -- Processing key events and menu logic, use it in loop


-- Customizable options
--- Menu
WarMenu.SetMenuTitle(id, title)
WarMenu.SetMenuSubTitle(id, text) -- it will uppercase automatically

--- Style
--- Property name can be extracted from setter signature, i. e. 'SetMenuTitleColor' -> 'titleColor'
--- Example: local style = { titleColor = { 255, 255, 255 }, maxOptionCountOnScreen = 7, buttonPressedSound = { name = 'name', set = 'set' } }
WarMenu.SetMenuStyle(id, style)

WarMenu.SetMenuX(id, x) -- [0.0..1.0] top left corner
WarMenu.SetMenuY(id, y) -- [0.0..1.0] top
WarMenu.SetMenuWidth(id, width) -- [0.0..1.0]
WarMenu.SetMenuMaxOptionCountOnScreen(id, count) -- 10 by default

WarMenu.SetMenuTitleColor(id, r, g, b, a*)
WarMenu.SetMenuSubTitleColor(id, r, g, b, a*)

WarMenu.SetMenuTitleBackgroundColor(id, r, g, b, a*)
-- or
WarMenu.SetMenuTitleBackgroundSprite(id, dict, name)

WarMenu.SetMenuBackgroundColor(id, r, g, b, a*)
WarMenu.SetMenuTextColor(id, r, g, b, a*)
WarMenu.SetMenuSubTextColor(id, r, g, b, a*)
WarMenu.SetMenuFocusColor(id, r, g, b, a*)
WarMenu.SetMenuFocusTextColor(id, r, g, b, a*)
WarMenu.SetMenuButtonPressedSound(id, name, set) -- https://pastebin.com/0neZdsZ5

Changelog

1.5

  • Added styles support
  • Added WarMenu.SetMenuStyle API
  • Added WarMenu.CreateMenu subTitle parameter
  • Corrected title background aspect ratio
  • Fixed minor bugs

1.4

  • Added WarMenu.InputButton API
  • Improved performance
  • Improved key mapping
  • Marked optional parameters in API section

1.3

  • Added Demo Menu
  • Added WarMenu.SetMenuFocusTextColor API
  • Fixed WarMenu.SetMenuFocusColor API
  • Fixed WarMenu.SpriteButton edge case
  • Improved performance and memory consumption
  • Removed debug prints
  • Improved code style

1.2

  • Added WarMenu.SpriteButton API

1.1

  • Added WarMenu.ToolTip API

1.0

  • Added WarMenu.IsItemHovered and WarMenu.IsItemSelected API
  • Implemented restoring parent menu selected index after closing submenu
  • Improved WarMenu.ComboBox and WarMenu.CheckBox API (without breaking compatibility!)
  • Improved performance and memory consumption
  • Updated Usage section

0.9.15

  • Improved performance and memory consumption
  • Added proper debug getter/setter API
  • Improved API consistency

0.9.14

  • Improved button mapping
  • Improved controller support

0.9.12

  • Introduced significant performance boost
    From ~0.4 ms to ~0.02 ms ( ~20x times faster! )

0.9.11

  • Fixed drawing numbers as button text

0.9.10

  • Added new WarMenu.CurrentOption() API

0.9.9

  • Added new WarMenu.SetTitle() API
  • Added WarMenu.MenuButton subText optional parameter
  • Updated manifest format

0.9.8

  • Added new WarMenu.IsAnyMenuOpened() API
  • Added new WarMenu.SetTitleBackgroundSprite() API

0.9.7

  • Added new WarMenu.SetMenuSubTextColor() API
  • @alberto2345: Added alpha parameters to color functions (with default values, so no worry for existing code)
  • Improved default subText color (see image)
  • Fixed flickering after reopening menu
  • @alberto2345: Fixed button execution after reopening menu
  • Fixed subTitle sub menu initializing
  • Corrected WarMenu.CheckBox usage example

0.9.6

  • Added new WarMenu.IsMenuAboutToBeClosed() API
  • Fixed WarMenu.MenuButton bug with unnecessary attempts to draw it without current menu
  • Fixed WarMenu.ComboBox bug with incorrect current index after reopening menu

0.9.5

  • Changed WarMenu.ComboBox control behavior and look - you need to press SELECT in order to confirm your choice.
    Also, it has two indexes now - for a current displaying item and user-selected one.
    It allows you create more complex menus like Los Santos Customs with Preview Mode.
    And don’t forget to check new sexy arrows. :wink:
    See updated Usage section for more info.
  • Added new SetMenuButtonPressedSound(id, name, set) API
  • Highly improved Debug Mode - more helpful information, better readability
  • SetTitleWrap() and SetTitleScale() APIs were removed due to text alignment complexity
  • Fixed lots of potential bugs with Debug Mode
  • Code cleaning and refactoring as well as bug fixes

0.9

  • Initial release
36 Likes

Nice fork! Looks great too.

3 Likes

Big thanks to you, @MrDaGree!

2 Likes

Update 0.9.5

This update improves almost each aspect of the framework.

Changelog

  • Changed WarMenu.ComboBox control behavior and look - you need to press SELECT in order to confirm your choice.
    Also, it has two indexes now - for a current displaying item and user-selected one.
    It allows you create more complex menus like Los Santos Customs with Preview Mode.
    And don’t forget to check new sexy arrows. :wink:
    See updated Usage section for more info.
  • Added new SetMenuButtonPressedSound(id, name, set) API
  • Highly improved Debug Mode - more helpful information, better readability
  • SetTitleWrap() and SetTitleScale() APIs were removed due to text alignment complexity
  • Fixed lots of potential bugs with Debug Mode
  • Code cleaning and refactoring as well as bug fixes
3 Likes

I will definitely be using this in my RP gamemode, good work on the improvements.

2 Likes

OK, I hope you will find lots of bugs and share your opinion on whether it is convenient to use :upside_down_face:

2 Likes

One thing I would like to request is a small area in the original post for developer documentation, the API wrapper list is very helpful but it would be more clear to myself and others if you detailed how to set up a new instance of the menu, and what each command does.

2 Likes

Well, I supposed Usage section is clear enough about how to use it and function names speak for themselves.
I don’t know what should I add here.

It would be like:
WarMenu.CreateMenu(id, title) function create a menu with specified id and title, which is kinda weird as for me.

2 Likes

Update 0.9.6

Small, but very important addition and fixes.

Changelog

  • Added new WarMenu.IsMenuAboutToBeClosed() API
  • Fixed WarMenu.MenuButton bug with unnecessary attempts to draw it without current menu
  • Fixed WarMenu.ComboBox bug with incorrect current index after reopening menu

DOWNLOAD LINK IS THE SAME AND WILL REMAIN SO IN FUTURE UPDATES

1 Like

If you created a menu using this framework - please, PM me or share your experience and screenshots here.

Thanks.

1 Like

Found a bug with CloseMenu.
tostring needs to be applied to lines 265 and 268 for the debugPrint, otherwise an error occurs when currentMenu variable goes to Nil.
Also I’m not sure if its expected behaviour or a bug, but you have to press Yes twice to close the menu from the example.

1 Like

@alberto2345, could you check the latest version, please? I’m not near my PC right now.

1 Like

Latest version spams log that window is about to close, and it can’t be opened again.

1 Like

OK, thanks. I will fix it a bit later when I will return at home.

Temporary reverted to 0.9.5

2 Likes

Should perhaps look into uploading it to GitHub. There we can all contribute to the script and better documentation can be provided and contributed to. Also reporting bugs and issues can be alot easier.

1 Like

Yes, you’re right, it was developed in one night recently, so I had no time to do it.

1 Like

Project repository was created.


Updated DOWNLOAD link and description.

3 Likes

Back to 0.9.6

Fixed WarMenu.IsMenuAboutToBeClosed() API (thanks @alberto2345 for notice).

See full changelog.

2 Likes

As the PM stated I am interested in possibly porting my scripts over to your menu system. One question I have is would you possibly add in an Alpha option for title background color. I personally like to have my menus with a lower alpha in the titles around 50-75. I changed it in your resource to mess around and see what it looked like but it changed the actual submenu text alpha also and I didn’t feel like debugging that.

Otherwise this looks promising. :slight_smile:

1 Like

You have to use WarMenu.SetTItleBackgroundColor.
In the WarMenu script, change the function, which should start at line 421 to this instead:

function WarMenu.SetTitleBackgroundColor(id, r, g, b, a)
    setMenuProperty(id, 'titleBackgroundColor', { ['r'] = r, ['g'] = g, ['b'] = b, ['a'] = a })
end

EDIT: I made a pull request on github with the changes, so they can be added to the main script.

4 Likes