Vehicle Selector – Vehicle Operations
Handles vehicle spawning, replacing, cloning, and management actions in the vehicle selector.
Handles vehicle spawning, replacing, cloning, and management actions in the vehicle selector.
Overview
ui_vehicleSelector_vehicleOperations provides all the action buttons for the vehicle selector: spawning new vehicles, replacing the current one, cloning, removing, resetting, random selection, and saving configs. Uses a fade/waiting screen for smooth transitions.
Extension path: lua/ge/extensions/ui/vehicleSelector/vehicleOperations.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
executeButton | (buttonId, additionalData) | Executes a registered button callback by ID. |
executeDoubleClick | (itemDetails) | Finds and executes the double-click action button. |
makeSpawningButtons | (configDetails) → button[] | Creates Spawn New + Replace Current buttons. |
getManagementDetails | () → table | Returns management buttons + current vehicle info. |
getVehicleName | (veh) → string | Returns formatted vehicle name (Brand Name Config). |
getCurrentVehicleThumb | (veh) → string | Returns preview image path. |
addButton | (...) → button | Registers a new button callback. |
clearButtonFunctions | () | Clears all registered buttons. |
onScreenFadeState | (state) | Executes deferred callback after fade completes. |
setManagementButtonsEnabled | (enabled) | Toggles management buttons. |
setDetailsButtonForFreeroam | (enabled) | Sets freeroam mode. |
setCustomDetailsButtons | (buttons) | Sets custom button definitions. |
getFreeButtonId | (...) | Returns the next available button ID from the button module. |
Data Fields
| Field | Description |
|---|---|
M.managementButtonsEnabled | true - whether management buttons are shown. |
Internals
Spawn/Replace Flow
- User clicks Spawn or Replace button.
- UI state changes to
"play", thenguihooks.trigger("app:waiting", true). - A
callbackAfterFadeis set with the actual spawn/replace logic. - When
onScreenFadeState(1)oronUiWaitingStatefires, the callback runs. - Calls
core_vehicles.spawnNewVehicleorcore_vehicles.replaceVehicle. - Fires appropriate extension hooks and disables waiting state.
Management Buttons
getManagementDetails creates these buttons (when enabled):
- Save as default.pc (dev only) -
core_vehicle_partmgmt.savedefault() - Load default.pc (dev only) -
core_vehicles.spawnDefault() - Save current config - navigates to save UI
- Clone Current -
core_vehicles.cloneCurrent() - Select Random - picks random config passing current filters
- Reset All -
resetGameplay(-1) - Remove All -
core_vehicles.removeAll() - Remove Current -
core_vehicles.removeCurrent() - Remove Others -
core_vehicles.removeAllExceptCurrent()
Paint Handling
When additionalData is provided (paint names), the spawn/replace functions look up paint objects from the model's paint table and pass them as spawn options.
How It Works
makeSpawningButtonscreates "Spawn New" and "Replace Current" (primary, double-click) buttons.- Each button is registered via
buttonInstance.addButton(callback, meta). - On click,
executeButton(id, additionalData)runs the callback. - If
filterResetOnSpawnis enabled, filters are cleared after spawning. - Recent vehicle tracking is called on spawn/replace.
Lua Examples
-- Execute a button by ID
extensions.ui_vehicleSelector_vehicleOperations.executeButton(1, {
paint = "Red", paint2 = "Black"
})
-- Get management details
local mgmt = extensions.ui_vehicleSelector_vehicleOperations.getManagementDetails()
print(mgmt.details.currentVehicleName)Hooks
| Hook | When |
|---|---|
onVehicleSelectorSpawnNew (ext) | New vehicle spawned |
onVehicleSelectorReplaceCurrent (ext) | Vehicle replaced |
onVehicleSelectorCloneCurrent (ext) | Vehicle cloned |
onVehicleSelectorRemoveAll (ext) | All vehicles removed |
onVehicleSelectorRemoveCurrent (ext) | Current vehicle removed |
onVehicleSelectorRemoveOthers (ext) | Other vehicles removed |
onVehicleSelectorResetAll (ext) | All vehicles reset |
onVehicleSelectorSelectRandom (ext) | Random vehicle selected |
onVehicleSelectorSetAsDefault (ext) | Saved as default.pc |
onVehicleSelectorLoadDefault (ext) | Loaded default.pc |
Additional Exports
The following exports are available but not yet documented in detail:
M.addButtonM.clearButtonFunctionsM.customDetailsButtonsM.detailsButtonForFreeroamM.executeButtonM.executeDoubleClickM.getCurrentVehicleThumbM.getFreeButtonIdM.getManagementDetailsM.getVehicleNameM.makeSpawningButtonsM.onScreenFadeStateM.onUiWaitingStateM.setCustomDetailsButtonsM.setDetailsButtonForFreeroamM.setManagementButtonsEnabled