Finally managed to get some kind of API for creating menus etc through the Lua code.
The way it works is using a few objects as created as part of this PR
Overlay
This is the main thing that contains all of the GUI widgets, and also contains the info about the primitive types that make up the GUI.
Examples of overlays would be the main menu, the settings menu, the player's inventory, and the player's HUD (crosshair, healthbar etc)
OverlayStack
This contains all the current overlays that are being displayed. For example, during gameplay it would store just the HUD, but if the player opens the inventory then it would contain the HUD UI, and also the inventory UI
OverlayDefintion
These are created in the in the Lua code, and are tables that contain a "GUI ID" and a Lua function for creation of the GUI
OverlayFactory
This stores all the OverlayDefintion tables created in the Lua.
It also has an operation for creating a new overlay, which you pass in a "GUI ID" such as "main_menu", and it would look up for the OverlayDefintion with that ID, create the overlay using the lua function, before returning to caller.
GUIRenderer
Does what it says on the tin.
Iterates the OverlayStack, rendering all the GUIs
Etc etc etc
This took a long time and idk, end of the day its just a thing that allows an api in the lua to create menus and such as described below:
I mean the idea is
Define a gui
game.gui.addGui{
id = "menu_thing",
title = "Main Menu",
create = onCreate,
}
Create a function to make the GUI
local function onCreate(gui)
local button = gui:addButton()
button.size = GuiDim.new(0, 50, 0, 50)
button.position = GuiDim.new(0, 50, 0, 50)
button.text = "Click me!"
button.textSize = 40
button.onClick = function() print("Hello world!") end
end
Finally managed to get some kind of API for creating menus etc through the Lua code.
The way it works is using a few objects as created as part of this PR
Overlay
This is the main thing that contains all of the GUI widgets, and also contains the info about the primitive types that make up the GUI.
Examples of overlays would be the main menu, the settings menu, the player's inventory, and the player's HUD (crosshair, healthbar etc)
OverlayStack
This contains all the current overlays that are being displayed. For example, during gameplay it would store just the HUD, but if the player opens the inventory then it would contain the HUD UI, and also the inventory UI
OverlayDefintion
These are created in the in the Lua code, and are tables that contain a "GUI ID" and a Lua function for creation of the GUI
OverlayFactory
This stores all the
OverlayDefintion
tables created in the Lua.It also has an operation for creating a new overlay, which you pass in a "GUI ID" such as "main_menu", and it would look up for the
OverlayDefintion
with that ID, create the overlay using the lua function, before returning to caller.GUIRenderer
Does what it says on the tin.
Iterates the
OverlayStack
, rendering all the GUIsEtc etc etc
This took a long time and idk, end of the day its just a thing that allows an api in the lua to create menus and such as described below:
I mean the idea is
Define a gui
Create a function to make the GUI
Add the GUI to the game when needed