Skip to content

ui_appLayouts

File: lua/ge/extensions/ui/appLayouts.lua · VM: Game Engine (GE) · 721 lines · BeamNG.drive 0.40.5 (buildbot 302427 on GitLab)

Access: extension ui_appLayouts: extensions.load("ui_appLayouts"), then the global ui_appLayouts

Manages the interface app layouts: reading, creating, copying, renaming, deleting and resetting *.uilayout.json files, as well as adding, removing and moving apps in a layout. The original layouts are in /settings/ui_apps/originalLayouts/, the user's in /settings/ui_apps/layouts/. A layout type to file table is stored in /temp/ui-layout-map.json. Used by modders who want to change the displayed apps by code; the Vue editor relies on the same functions.

Example

local layouts = ui_appLayouts.getAvailableLayouts()
for _, l in ipairs(layouts) do print(l.filename, l.type, l.title) end
ui_appLayouts.setUsedLayout('freeroam')

Notes

  • The official apps removed from the game (engineDebug, gravityApp, radioTest, simpleRpmDebug, replayAppV2) are filtered out of all layouts, including custom layouts; the removedApps list of an original layout is also used as an obsolescence list.
  • App indices are 0-based on the JS side: removeApp, applyPlacementPatch and applySettingsPatch convert them to a 1-based Lua index. A string of the form "appName-" is also accepted (0-based idx).
  • getAvailableLayouts updates the user files: if the original layout's version is newer, the user layout is replaced; otherwise the apps whose appVersion is newer are replaced or added. The file is then rewritten to disk.
  • Each returned layout gets the fields filename, resettable, userFileExists and possibly default (if the path contains "default").
  • addApp, removeApp and the patches write to disk without notification (silent write); saveLayout, createLayout, renameLayout, duplicateLayout, deleteLayout, resetLayout and setCurrentLayout notify ui_apps.notifyLayoutsChanged.
  • The onCameraChanged hook sends PlayerCameraModeChanged to the UI; a walking player is reported as camera "unicycle".

Dependencies (loaded first): ui_apps

Functions

Function Description Line
ui_appLayouts.addApp(layoutId, appName, placement) Adds an app at the end of a layout, with optional placement. Refuses obsolete apps. 528
ui_appLayouts.applyPlacementPatch(layoutId, appInstanceIdOrIndex, placement) Replaces the placement of an app in a layout and writes the file. 573
ui_appLayouts.applySettingsPatch(layoutId, appInstanceIdOrIndex, settings) Replaces the settings of an app in a layout and writes the file. 600
ui_appLayouts.clearLayoutForType(layoutType) Clears a type's layout preference. 678
ui_appLayouts.createLayout(data) Creates a new layout. Without filename, a free name is derived from the title in the user folder. Default title "My Layout", default type "custom". 455
ui_appLayouts.deleteLayout(filenameToDelete) Deletes a layout's file, unless it is part of the official content (a message is logged and nothing is deleted). 267
ui_appLayouts.duplicateLayout(filename, newTitle) Copies a layout to a new file (title " copy" by default), removing the <code>default</code> flag.</td> <td>497</td> </tr> <tr> <td><code>ui_appLayouts.getAvailableLayouts()</code></td> <td>Lists all available layouts (originals without a user copy + user files), after updating the user files from the originals and filtering out removed apps.</td> <td>101</td> </tr> <tr> <td><code>ui_appLayouts.getCurrentLayout()</code></td> <td>Returns the currently active layout (after filtering obsolete apps), or nil.</td> <td>355</td> </tr> <tr> <td><code>ui_appLayouts.getLayoutForType(layoutType)</code></td> <td>Returns the layout file stored for a type.</td> <td>687</td> </tr> <tr> <td><code>ui_appLayouts.getPlayerCameraModes()</code></td> <td>Returns the camera mode of each player (multi-seat); "unicycle" if the player is walking.</td> <td>643</td> </tr> <tr> <td><code>ui_appLayouts.getTypeLayoutMap()</code></td> <td>Returns a copy of the layout type to file table.</td> <td>692</td> </tr> <tr> <td><code>ui_appLayouts.isEditing()</code></td> <td>Indicates whether the edit mode is active.</td> <td>634</td> </tr> <tr> <td><code>ui_appLayouts.onCameraChanged(player, camName)</code></td> <td>Hook called when a player's camera changes. Sends <code>PlayerCameraModeChanged</code> to the UI with <code>{player, name}</code>. <em>(internal)</em> <em>(hook)</em></td> <td>657</td> </tr> <tr> <td><code>ui_appLayouts.removeApp(layoutId, appInstanceIdOrIndex)</code></td> <td>Removes an app from a layout by index (0-based) or by "name-index" identifier.</td> <td>548</td> </tr> <tr> <td><code>ui_appLayouts.renameLayout(filename, title)</code></td> <td>Changes a layout's title. Refuses layouts from the official content.</td> <td>482</td> </tr> <tr> <td><code>ui_appLayouts.resetLayout(filenameToReset, layoutType)</code></td> <td>Resets a user layout by deleting its file, which makes the original reappear. Refuses files outside the user folder.</td> <td>299</td> </tr> <tr> <td><code>ui_appLayouts.resetUsedLayout()</code></td> <td>Reloads the layout stored by setUsedLayout as the current layout. Returns the current layout as is if none was chosen.</td> <td>443</td> </tr> <tr> <td><code>ui_appLayouts.saveLayout(data)</code></td> <td>Saves a layout to disk (<code>filename</code> field required) then notifies the consumers.</td> <td>261</td> </tr> <tr> <td><code>ui_appLayouts.setCurrentLayout(layoutOrFilename)</code></td> <td>Sets the current layout from a file name or a layout table, then notifies the change. Returns nil if the file is not found.</td> <td>360</td> </tr> <tr> <td><code>ui_appLayouts.setEditing(enabled)</code></td> <td>Enables or disables the layout edit mode.</td> <td>629</td> </tr> <tr> <td><code>ui_appLayouts.setLayoutForType(layoutType, filename)</code></td> <td>Stores the layout to use for a layout type.</td> <td>665</td> </tr> <tr> <td><code>ui_appLayouts.setUsedLayout(idOrType)</code></td> <td>Chooses the layout to use from a file name or a type. An explicit choice by file is stored as the type's preference, unless it is the type's default layout (the preference is then cleared).</td> <td>415</td> </tr> </tbody> </table> <h3 id="parameter-details">Parameter details<a class="headerlink" href="#parameter-details" title="Permanent link">¶</a></h3> <h4 id="ui_applayoutsaddapplayoutid-appname-placement"><code>ui_appLayouts.addApp(layoutId, appName, placement)</code><a class="headerlink" href="#ui_applayoutsaddapplayoutid-appname-placement" title="Permanent link">¶</a></h4> <p>Adds an app at the end of a layout, with optional placement. Refuses obsolete apps.</p> <ul> <li><code>layoutId</code> (<em>string</em>) : Layout file.</li> <li><code>appName</code> (<em>string</em>) : App name.</li> <li><code>placement</code> (<em>table|nil</em>) : Position and size of the app.</li> <li><strong>returns</strong>: boolean true if added.</li> </ul> <h4 id="ui_applayoutsapplyplacementpatchlayoutid-appinstanceidorindex-placement"><code>ui_appLayouts.applyPlacementPatch(layoutId, appInstanceIdOrIndex, placement)</code><a class="headerlink" href="#ui_applayoutsapplyplacementpatchlayoutid-appinstanceidorindex-placement" title="Permanent link">¶</a></h4> <p>Replaces the placement of an app in a layout and writes the file.</p> <ul> <li><code>layoutId</code> (<em>string</em>) : Layout file.</li> <li><code>appInstanceIdOrIndex</code> (<em>integer|string</em>) : 0-based index or "appName-<idx>".</li> <li><code>placement</code> (<em>table</em>) : New placement.</li> <li><strong>returns</strong>: boolean true if applied.</li> </ul> <h4 id="ui_applayoutsapplysettingspatchlayoutid-appinstanceidorindex-settings"><code>ui_appLayouts.applySettingsPatch(layoutId, appInstanceIdOrIndex, settings)</code><a class="headerlink" href="#ui_applayoutsapplysettingspatchlayoutid-appinstanceidorindex-settings" title="Permanent link">¶</a></h4> <p>Replaces the settings of an app in a layout and writes the file.</p> <ul> <li><code>layoutId</code> (<em>string</em>) : Layout file.</li> <li><code>appInstanceIdOrIndex</code> (<em>integer|string</em>) : 0-based index or "appName-<idx>".</li> <li><code>settings</code> (<em>table</em>) : New app settings.</li> <li><strong>returns</strong>: boolean true if applied.</li> </ul> <h4 id="ui_applayoutsclearlayoutfortypelayouttype"><code>ui_appLayouts.clearLayoutForType(layoutType)</code><a class="headerlink" href="#ui_applayoutsclearlayoutfortypelayouttype" title="Permanent link">¶</a></h4> <p>Clears a type's layout preference.</p> <ul> <li><code>layoutType</code> (<em>string</em>) : Layout type.</li> <li><strong>returns</strong>: boolean true if a preference existed.</li> </ul> <h4 id="ui_applayoutscreatelayoutdata"><code>ui_appLayouts.createLayout(data)</code><a class="headerlink" href="#ui_applayoutscreatelayoutdata" title="Permanent link">¶</a></h4> <p>Creates a new layout. Without <code>filename</code>, a free name is derived from the title in the user folder. Default title "My Layout", default type "custom".</p> <ul> <li><code>data</code> (<em>table|nil</em>) : Optional fields: title, type, apps, description, devonly, version, filename.</li> <li><strong>returns</strong>: string|nil Created file name, nil if no name is available.</li> </ul> <h4 id="ui_applayoutsdeletelayoutfilenametodelete"><code>ui_appLayouts.deleteLayout(filenameToDelete)</code><a class="headerlink" href="#ui_applayoutsdeletelayoutfilenametodelete" title="Permanent link">¶</a></h4> <p>Deletes a layout's file, unless it is part of the official content (a message is logged and nothing is deleted).</p> <ul> <li><code>filenameToDelete</code> (<em>string</em>) : File to delete.</li> <li><strong>returns</strong>: boolean true if the layout was found (even if the deletion was refused), false otherwise.</li> </ul> <h4 id="ui_applayoutsduplicatelayoutfilename-newtitle"><code>ui_appLayouts.duplicateLayout(filename, newTitle)</code><a class="headerlink" href="#ui_applayoutsduplicatelayoutfilename-newtitle" title="Permanent link">¶</a></h4> <p>Copies a layout to a new file (title "<title> copy" by default), removing the <code>default</code> flag.</p> <ul> <li><code>filename</code> (<em>string</em>) : Source layout file.</li> <li><code>newTitle</code> (<em>string|nil</em>) : Title of the copy.</li> <li><strong>returns</strong>: string|nil File name of the copy, nil on failure.</li> </ul> <h4 id="ui_applayoutsgetavailablelayouts"><code>ui_appLayouts.getAvailableLayouts()</code><a class="headerlink" href="#ui_applayoutsgetavailablelayouts" title="Permanent link">¶</a></h4> <p>Lists all available layouts (originals without a user copy + user files), after updating the user files from the originals and filtering out removed apps.</p> <ul> <li><strong>returns</strong>: table<integer, table> Layouts with <code>apps</code>, <code>title</code>, <code>type</code>, <code>filename</code>, <code>resettable</code>, <code>userFileExists</code>, <code>default</code>.</li> </ul> <h4 id="ui_applayoutsgetcurrentlayout"><code>ui_appLayouts.getCurrentLayout()</code><a class="headerlink" href="#ui_applayoutsgetcurrentlayout" title="Permanent link">¶</a></h4> <p>Returns the currently active layout (after filtering obsolete apps), or nil.</p> <ul> <li><strong>returns</strong>: table|nil Current layout.</li> </ul> <h4 id="ui_applayoutsgetlayoutfortypelayouttype"><code>ui_appLayouts.getLayoutForType(layoutType)</code><a class="headerlink" href="#ui_applayoutsgetlayoutfortypelayouttype" title="Permanent link">¶</a></h4> <p>Returns the layout file stored for a type.</p> <ul> <li><code>layoutType</code> (<em>string</em>) : Layout type.</li> <li><strong>returns</strong>: string|nil File name, or nil.</li> </ul> <h4 id="ui_applayoutsgetplayercameramodes"><code>ui_appLayouts.getPlayerCameraModes()</code><a class="headerlink" href="#ui_applayoutsgetplayercameramodes" title="Permanent link">¶</a></h4> <p>Returns the camera mode of each player (multi-seat); "unicycle" if the player is walking.</p> <ul> <li><strong>returns</strong>: table<integer, table> List of <code>{player, name}</code>.</li> </ul> <h4 id="ui_applayoutsgettypelayoutmap"><code>ui_appLayouts.getTypeLayoutMap()</code><a class="headerlink" href="#ui_applayoutsgettypelayoutmap" title="Permanent link">¶</a></h4> <p>Returns a copy of the layout type to file table.</p> <ul> <li><strong>returns</strong>: table<string, string> Preferences by type.</li> </ul> <h4 id="ui_applayoutsisediting"><code>ui_appLayouts.isEditing()</code><a class="headerlink" href="#ui_applayoutsisediting" title="Permanent link">¶</a></h4> <p>Indicates whether the edit mode is active.</p> <ul> <li><strong>returns</strong>: boolean Edit mode state.</li> </ul> <h4 id="ui_applayoutsoncamerachangedplayer-camname"><code>ui_appLayouts.onCameraChanged(player, camName)</code><a class="headerlink" href="#ui_applayoutsoncamerachangedplayer-camname" title="Permanent link">¶</a></h4> <p>Hook called when a player's camera changes. Sends <code>PlayerCameraModeChanged</code> to the UI with <code>{player, name}</code>.</p> <ul> <li><code>player</code> (<em>integer|nil</em>) : Player index (0 by default).</li> <li><code>camName</code> (<em>string|nil</em>) : Camera mode name.</li> </ul> <h4 id="ui_applayoutsremoveapplayoutid-appinstanceidorindex"><code>ui_appLayouts.removeApp(layoutId, appInstanceIdOrIndex)</code><a class="headerlink" href="#ui_applayoutsremoveapplayoutid-appinstanceidorindex" title="Permanent link">¶</a></h4> <p>Removes an app from a layout by index (0-based) or by "name-index" identifier.</p> <ul> <li><code>layoutId</code> (<em>string</em>) : Layout file.</li> <li><code>appInstanceIdOrIndex</code> (<em>integer|string</em>) : 0-based index or "appName-<idx>".</li> <li><strong>returns</strong>: boolean true if removed.</li> </ul> <h4 id="ui_applayoutsrenamelayoutfilename-title"><code>ui_appLayouts.renameLayout(filename, title)</code><a class="headerlink" href="#ui_applayoutsrenamelayoutfilename-title" title="Permanent link">¶</a></h4> <p>Changes a layout's title. Refuses layouts from the official content.</p> <ul> <li><code>filename</code> (<em>string</em>) : Layout file.</li> <li><code>title</code> (<em>string</em>) : New title.</li> <li><strong>returns</strong>: boolean true if renamed.</li> </ul> <h4 id="ui_applayoutsresetlayoutfilenametoreset-layouttype"><code>ui_appLayouts.resetLayout(filenameToReset, layoutType)</code><a class="headerlink" href="#ui_applayoutsresetlayoutfilenametoreset-layouttype" title="Permanent link">¶</a></h4> <p>Resets a user layout by deleting its file, which makes the original reappear. Refuses files outside the user folder.</p> <ul> <li><code>filenameToReset</code> (<em>string|nil</em>) : User file to reset.</li> <li><code>layoutType</code> (<em>string|nil</em>) : Type used to find the original if the file has none.</li> <li><strong>returns</strong>: string|boolean File name of the reset layout, or false on failure.</li> </ul> <h4 id="ui_applayoutsresetusedlayout"><code>ui_appLayouts.resetUsedLayout()</code><a class="headerlink" href="#ui_applayoutsresetusedlayout" title="Permanent link">¶</a></h4> <p>Reloads the layout stored by setUsedLayout as the current layout. Returns the current layout as is if none was chosen.</p> <ul> <li><strong>returns</strong>: table|nil Current layout.</li> </ul> <h4 id="ui_applayoutssavelayoutdata"><code>ui_appLayouts.saveLayout(data)</code><a class="headerlink" href="#ui_applayoutssavelayoutdata" title="Permanent link">¶</a></h4> <p>Saves a layout to disk (<code>filename</code> field required) then notifies the consumers.</p> <ul> <li><code>data</code> (<em>table</em>) : Layout to write, with <code>filename</code>.</li> </ul> <h4 id="ui_applayoutssetcurrentlayoutlayoutorfilename"><code>ui_appLayouts.setCurrentLayout(layoutOrFilename)</code><a class="headerlink" href="#ui_applayoutssetcurrentlayoutlayoutorfilename" title="Permanent link">¶</a></h4> <p>Sets the current layout from a file name or a layout table, then notifies the change. Returns nil if the file is not found.</p> <ul> <li><code>layoutOrFilename</code> (<em>string|table</em>) : Layout file path or layout table.</li> <li><strong>returns</strong>: table|nil The current layout.</li> </ul> <h4 id="ui_applayoutsseteditingenabled"><code>ui_appLayouts.setEditing(enabled)</code><a class="headerlink" href="#ui_applayoutsseteditingenabled" title="Permanent link">¶</a></h4> <p>Enables or disables the layout edit mode.</p> <ul> <li><code>enabled</code> (<em>boolean</em>) : New state.</li> <li><strong>returns</strong>: boolean Stored state.</li> </ul> <h4 id="ui_applayoutssetlayoutfortypelayouttype-filename"><code>ui_appLayouts.setLayoutForType(layoutType, filename)</code><a class="headerlink" href="#ui_applayoutssetlayoutfortypelayouttype-filename" title="Permanent link">¶</a></h4> <p>Stores the layout to use for a layout type.</p> <ul> <li><code>layoutType</code> (<em>string</em>) : Layout type.</li> <li><code>filename</code> (<em>string</em>) : Layout file (must exist).</li> <li><strong>returns</strong>: boolean true if saved.</li> </ul> <h4 id="ui_applayoutssetusedlayoutidortype"><code>ui_appLayouts.setUsedLayout(idOrType)</code><a class="headerlink" href="#ui_applayoutssetusedlayoutidortype" title="Permanent link">¶</a></h4> <p>Chooses the layout to use from a file name or a type. An explicit choice by file is stored as the type's preference, unless it is the type's default layout (the preference is then cleared).</p> <ul> <li><code>idOrType</code> (<em>string</em>) : Layout file name or layout type.</li> <li><strong>returns</strong>: table|nil Activated layout, nil if not found.</li> </ul> <h2 id="fields">Fields<a class="headerlink" href="#fields" title="Permanent link">¶</a></h2> <table> <thead> <tr> <th>Field</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>dependencies</code></td> <td>table<integer, string></td> <td>Extensions loaded before: <code>{'ui_apps'}</code>.</td> </tr> </tbody> </table> <p><strong>UI events (guihooks.trigger):</strong> <code>PlayerCameraModeChanged</code></p> <h2 id="calls-into-the-engine-c">Calls into the engine (C++)<a class="headerlink" href="#calls-into-the-engine-c" title="Permanent link">¶</a></h2> <ul> <li><code>FS:</code> <code>fileExists</code>, <code>findFiles</code>, <code>removeFile</code></li> </ul> <hr /> <p><em>tim19Atlas (Tim0219800) — derived from BeamNG GmbH Lua code (bCDDL 1.1, see LICENSE). Source: <code>lua/ge/extensions/ui/appLayouts.lua</code>.</em></p> </article> </div> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type="button" class="md-top md-icon" data-md-component="top" hidden> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class="md-footer"> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class="md-copyright"> Made with <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener"> Material for MkDocs </a> </div> </div> </div> </footer> </div> <div class="md-dialog" data-md-component="dialog"> <div class="md-dialog__inner md-typeset"></div> </div> <script id="__config" type="application/json">{"annotate": null, "base": "../../../..", "features": ["navigation.indexes", "navigation.top", "search.suggest", "search.highlight", "content.code.copy"], "search": "../../../../assets/javascripts/workers/search.a7633da7.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script> <script src="../../../../assets/javascripts/bundle.a5f9d56c.min.js"></script> </body> </html>