Project Zomboid

Project Zomboid

Radial Menu API
 This topic has been pinned, so it's probably important
Browser8  [developer] 29 Jan, 2022 @ 8:18am
Radial Menu API Guide (For Modders)
Added Methods
ISRadialMenu:getSliceIndex(sliceText)
Returns the index of the slice with the given text or nil if it doesnt exist.

ISRadialMenu:getSliceText(sliceIndex)
Returns the text of the slice at the given index.

ISRadialMenu:getSliceTexture(sliceIndex)
Returns the texture of the slice at the given index.

ISRadialMenu:setSliceCommand(sliceIndex, command, arg1, arg2, arg3, arg4, arg5, arg6)
Sets the command of the slice at the given index to the specified one.

ISRadialMenu:display(releaseButton, joypadIgnoreAimUntilCentered)
Utility method to update/render the menu and give it controller support. Receives the button to be pressed to use it on a controller.

ISRadialMenu:createSubMenu(onSubMenu, args)
Utility method to create a sub-menu. Calls the given function when creating the menu so you can add your custom slices to it. Passes it the menu and optionally the args if provided. Creates a back button.
Last edited by Browser8; 4 Feb, 2022 @ 4:53am
< >
Showing 1-3 of 3 comments
Browser8  [developer] 29 Jan, 2022 @ 8:27am 
Registering Slices

Instead of the old method hooking into the corresponding menu's function and having to deal with boilerplate code to get your slice to display it is much simpler now to add a slice to the menu.

You have available the methods:
Vehicle Menu
VehicleMenuAPI.registerSlice(sliceName, sliceFunction)
VehicleMenuAPI.registerSliceOutside(sliceName, sliceFunction)
Emote Menu
EmoteMenuAPI.registerSlice(sliceName, sliceFunction)

An example of their usage is:
local function onExample(player) player:Say("This is a custom slice!") end local function exampleFunction(menu, player, vehicle) menu:addSlice("What's This?", getTexture("media/ui/emotes/shrug.png"), onExample, player) end VehicleMenuAPI.registerSlice("example", exampleFunction)
Your registered function will be called with the arguments menu, player and, for VehicleMenuAPI, vehicle.

Along with these, methods to unregister a slice are also provided in case you want to disable a slice:
VehicleMenuAPI.unregisterSlice(sliceName)
VehicleMenuAPI.unregisterSliceOutside(sliceName)
EmoteMenuAPI.unregisterSlice(sliceName)
Last edited by Browser8; 4 Feb, 2022 @ 4:55am
Browser8  [developer] 29 Jan, 2022 @ 8:50am 
Modifying Existing Slices

Slices are registered with a unique name. Registering another slice with the same name will replace the called function, therefore allowing modification of existing slices.

All base game slices were converted to the new system. Their names are:
VehicleMenuAPI
  • SwitchSeat (Inside Vehicle)
  • StartStopEngine (Inside Vehicle)
  • Hotwire (Inside Vehicle)
  • Headlights (Inside Vehicle)
  • Heater (Inside Vehicle)
  • Horn (Inside Vehicle)
  • Lightbar (Inside Vehicle)
  • Device (Inside Vehicle)
  • Window (Inside Vehicle)
  • Locks (Inside Vehicle)
  • Mechanics (Inside Vehicle)
  • Sleep (Inside Vehicle)
  • ExitVehicle (Inside Vehicle)
  • Mechanics (Outside Vehicle)
  • EnterVehicle (Outside Vehicle)
  • Fuel (Outside Vehicle)
  • OpenCloseLock (Outside Vehicle)
  • SmashWindow (Outside Vehicle)
  • Towing (Outside Vehicle)

EmoteMenuAPI
Due to the way the vanilla menu is coded, to better preserve mod compatibility the default slices were not converted. If you wish to modify them, edit the ISEmoteRadialMenu.menu table.
Last edited by Browser8; 3 Feb, 2022 @ 3:47am
Ryan 2 May, 2024 @ 10:37pm 
could you give an example of nested menus ?
< >
Showing 1-3 of 3 comments
Per page: 1530 50